1
/***************************************************************************
2
qimagesource.cpp - data source for qimagesources
4
begin : Tue Oct 21 2003
5
copyright : (C) 2003 The University of Toronto
7
***************************************************************************/
9
/***************************************************************************
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
***************************************************************************/
18
#include "qimagesource.h"
22
QimagesourceSource::QimagesourceSource(KConfig *cfg, const QString& filename, const QString& type)
23
: KstDataSource(cfg, filename, type) {
31
QimagesourceSource::~QimagesourceSource() {
35
bool QimagesourceSource::reset() {
41
bool QimagesourceSource::init() {
47
if ( _image.load( _filename ) ) {
48
_fieldList.append("INDEX");
49
_fieldList.append( "GRAY" );
50
_fieldList.append( "RED" );
51
_fieldList.append( "GREEN" );
52
_fieldList.append( "BLUE" );
53
_fieldList.append( "1" );
54
_fieldList.append( "2" );
55
_fieldList.append( "3" );
56
_fieldList.append( "4" );
57
_matrixList.append( "GRAY" );
58
_matrixList.append( "RED" );
59
_matrixList.append( "GREEN" );
60
_matrixList.append( "BLUE" );
61
_matrixList.append( "1" );
62
_matrixList.append( "2" );
63
_matrixList.append( "3" );
64
_matrixList.append( "4" );
65
return update() == KstObject::UPDATE;
72
KstObject::UpdateType QimagesourceSource::update(int u) {
73
if (KstObject::checkUpdateCounter(u)) {
74
return lastUpdateResult();
76
int newNF = _image.width()*_image.height();
77
bool isnew = newNF != _frameCount;
81
updateNumFramesScalar();
82
return setLastUpdateResult(isnew ? KstObject::UPDATE : KstObject::NO_CHANGE);
85
bool QimagesourceSource::matrixDimensions( const QString& matrix,
86
int* xDim, int* yDim) {
87
if ( _image.isNull() ) {
91
if ( !_matrixList.contains( matrix ) ) {
95
*xDim = _image.width();
96
*yDim = _image.height();
100
int QimagesourceSource::readMatrix(KstMatrixData* data,
101
const QString& field, int xStart,
102
int yStart, int xNumSteps,
108
if ( _image.isNull() ) {
113
y1 = yStart+yNumSteps;
116
x1 = xStart+xNumSteps;
121
if ( field=="GRAY" || field == "1") {
122
for ( px = xStart; px<x1; px++ ) {
123
for ( py=y1-1; py>=yStart; py-- ) {
124
z[i] = qGray( _image.pixel( px, py ) );
128
} else if ( field=="RED" || field == "2" ) {
129
for ( px = xStart; px<x1; px++ ) {
130
for ( py=y1-1; py>=yStart; py-- ) {
131
z[i] = qRed( _image.pixel( px, py ) );
135
} else if ( field=="GREEN" || field == "3" ) {
136
for ( px = xStart; px<x1; px++ ) {
137
for ( py=y1-1; py>=yStart; py-- ) {
138
z[i] = qGreen( _image.pixel( px, py ) );
142
} else if ( field=="BLUE" || field == "4" ) {
143
for ( px = xStart; px<x1; px++ ) {
144
for ( py=y1-1; py>=yStart; py-- ) {
145
z[i] = qBlue( _image.pixel( px, py ) );
151
// set the suggested matrix transform params: pixel index....
160
int QimagesourceSource::readField(double *v, const QString& field, int s, int n) {
163
if ( field=="INDEX" ) {
164
for ( i=0; i<n; i++ ) {
167
} else if ( field=="GRAY" || field == "1" ) {
168
for ( i=s; i<s+n; i++ ) {
169
px = i%_image.width();
170
py = i/_image.width();
171
v[i-s] = qGray( _image.pixel( px, py ) );
173
} else if ( field=="RED" || field == "2" ) {
174
for ( i=s; i<s+n; i++ ) {
175
px = i%_image.width();
176
py = i/_image.width();
177
v[i-s] = qRed( _image.pixel( px, py ) );
179
} else if ( field=="GREEN" || field == "3" ) {
180
for ( i=s; i<s+n; i++ ) {
181
px = i%_image.width();
182
py = i/_image.width();
183
v[i-s] = qGreen( _image.pixel( px, py ) );
185
} else if ( field=="BLUE" || field == "4" ) {
186
for ( i=s; i<s+n; i++ ) {
187
px = i%_image.width();
188
py = i/_image.width();
189
v[i-s] = qBlue( _image.pixel( px, py ) );
197
bool QimagesourceSource::isValidField(const QString& field) const {
198
return _fieldList.contains( field );
201
bool QimagesourceSource::isValidMatrix(const QString& field) const {
202
return _matrixList.contains( field );
205
int QimagesourceSource::samplesPerFrame(const QString &field) {
211
int QimagesourceSource::frameCount(const QString& field) const {
217
bool QimagesourceSource::isEmpty() const {
218
return _frameCount < 1;
222
QString QimagesourceSource::fileType() const {
223
return "QImage compatible Image";
227
void QimagesourceSource::save(QTextStream &ts, const QString& indent) {
228
KstDataSource::save(ts, indent);
231
//#include <kdebug.h>
234
KstDataSource *create_qimagesource(KConfig *cfg, const QString& filename, const QString& type) {
235
return new QimagesourceSource(cfg, filename, type);
238
QStringList provides_qimagesource() {
240
rc += "QImage compatible Image";
244
int understands_qimagesource(KConfig*, const QString& filename) {
245
QString ftype( QImage::imageFormat( filename ) );
247
if ( ftype.isEmpty() ) return 0;
249
if ( ftype == "TIFF" ) {
250
if ( ftype.find( ".tif", -5, false )<0 ) return 0;
258
QStringList fieldList_qimagesource(KConfig*, const QString& filename, const QString& type, QString *typeSuggestion, bool *complete) {
260
QStringList fieldList;
266
if (typeSuggestion) {
267
*typeSuggestion = "QImage compatible Image";
269
if ( QImage::imageFormat( filename ) ) {
270
fieldList.append("INDEX");
271
fieldList.append( "GRAY" );
272
fieldList.append( "RED" );
273
fieldList.append( "GREEN" );
274
fieldList.append( "BLUE" );
275
fieldList.append( "1" );
276
fieldList.append( "2" );
277
fieldList.append( "3" );
278
fieldList.append( "4" );
285
KST_KEY_DATASOURCE_PLUGIN(qimagesource)