Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qimage.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of QImage and QImageIO classes 00005 ** 00006 ** Created : 950207 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the kernel module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 00035 ** 00036 **********************************************************************/ 00037 00038 #ifndef QIMAGE_H 00039 #define QIMAGE_H 00040 00041 #ifndef QT_H 00042 #include "qpixmap.h" 00043 #include "qstrlist.h" 00044 #include "qstringlist.h" 00045 #endif // QT_H 00046 00047 class QImageDataMisc; // internal 00048 #ifndef QT_NO_IMAGE_TEXT 00049 class Q_EXPORT QImageTextKeyLang { 00050 public: 00051 QImageTextKeyLang(const char* k, const char* l) : key(k), lang(l) { } 00052 QImageTextKeyLang() { } 00053 00054 QCString key; 00055 QCString lang; 00056 00057 bool operator< (const QImageTextKeyLang& other) const 00058 { return key < other.key || (key==other.key && lang < other.lang); } 00059 bool operator== (const QImageTextKeyLang& other) const 00060 { return key==other.key && lang==other.lang; } 00061 }; 00062 #endif //QT_NO_IMAGE_TEXT 00063 00064 00065 class Q_EXPORT QImage 00066 { 00067 public: 00068 enum Endian { IgnoreEndian, BigEndian, LittleEndian }; 00069 00070 QImage(); 00071 QImage( int width, int height, int depth, int numColors=0, 00072 Endian bitOrder=IgnoreEndian ); 00073 QImage( const QSize&, int depth, int numColors=0, 00074 Endian bitOrder=IgnoreEndian ); 00075 #ifndef QT_NO_IMAGEIO 00076 QImage( const QString &fileName, const char* format=0 ); 00077 QImage( const char * const xpm[] ); 00078 QImage( const QByteArray &data ); 00079 #endif 00080 QImage( uchar* data, int w, int h, int depth, 00081 QRgb* colortable, int numColors, 00082 Endian bitOrder ); 00083 #ifdef Q_WS_QWS 00084 QImage( uchar* data, int w, int h, int depth, int pbl, 00085 QRgb* colortable, int numColors, 00086 Endian bitOrder ); 00087 #endif 00088 QImage( const QImage & ); 00089 ~QImage(); 00090 00091 QImage &operator=( const QImage & ); 00092 QImage &operator=( const QPixmap & ); 00093 bool operator==( const QImage & ) const; 00094 bool operator!=( const QImage & ) const; 00095 void detach(); 00096 QImage copy() const; 00097 QImage copy(int x, int y, int w, int h, int conversion_flags=0) const; 00098 QImage copy(const QRect&) const; 00099 #ifndef QT_NO_MIME 00100 static QImage fromMimeSource( const QString& abs_name ); 00101 #endif 00102 bool isNull() const { return data->bits == 0; } 00103 00104 int width() const { return data->w; } 00105 int height() const { return data->h; } 00106 QSize size() const { return QSize(data->w,data->h); } 00107 QRect rect() const { return QRect(0,0,data->w,data->h); } 00108 int depth() const { return data->d; } 00109 int numColors() const { return data->ncols; } 00110 Endian bitOrder() const { return (Endian) data->bitordr; } 00111 00112 QRgb color( int i ) const; 00113 void setColor( int i, QRgb c ); 00114 void setNumColors( int ); 00115 00116 bool hasAlphaBuffer() const; 00117 void setAlphaBuffer( bool ); 00118 00119 bool allGray() const; 00120 bool isGrayscale() const; 00121 00122 uchar *bits() const; 00123 uchar *scanLine( int ) const; 00124 uchar **jumpTable() const; 00125 QRgb *colorTable() const; 00126 int numBytes() const; 00127 int bytesPerLine() const; 00128 00129 #ifdef Q_WS_QWS 00130 QGfx * graphicsContext(); 00131 #endif 00132 00133 bool create( int width, int height, int depth, int numColors=0, 00134 Endian bitOrder=IgnoreEndian ); 00135 bool create( const QSize&, int depth, int numColors=0, 00136 Endian bitOrder=IgnoreEndian ); 00137 void reset(); 00138 00139 void fill( uint pixel ); 00140 void invertPixels( bool invertAlpha = TRUE ); 00141 00142 QImage convertDepth( int ) const; 00143 #ifndef QT_NO_IMAGE_TRUECOLOR 00144 QImage convertDepthWithPalette( int, QRgb* p, int pc, int cf=0 ) const; 00145 #endif 00146 QImage convertDepth( int, int conversion_flags ) const; 00147 QImage convertBitOrder( Endian ) const; 00148 00149 enum ScaleMode { 00150 ScaleFree, 00151 ScaleMin, 00152 ScaleMax 00153 }; 00154 #ifndef QT_NO_IMAGE_SMOOTHSCALE 00155 QImage smoothScale( int w, int h, ScaleMode mode=ScaleFree ) const; 00156 QImage smoothScale( const QSize& s, ScaleMode mode=ScaleFree ) const; 00157 #endif 00158 #ifndef QT_NO_IMAGE_TRANSFORMATION 00159 QImage scale( int w, int h, ScaleMode mode=ScaleFree ) const; 00160 QImage scale( const QSize& s, ScaleMode mode=ScaleFree ) const; 00161 QImage scaleWidth( int w ) const; 00162 QImage scaleHeight( int h ) const; 00163 QImage xForm( const QWMatrix &matrix ) const; 00164 #endif 00165 00166 #ifndef QT_NO_IMAGE_DITHER_TO_1 00167 QImage createAlphaMask( int conversion_flags=0 ) const; 00168 #endif 00169 #ifndef QT_NO_IMAGE_HEURISTIC_MASK 00170 QImage createHeuristicMask( bool clipTight=TRUE ) const; 00171 #endif 00172 #ifndef QT_NO_IMAGE_MIRROR 00173 QImage mirror() const; 00174 QImage mirror(bool horizontally, bool vertically) const; 00175 #endif 00176 QImage swapRGB() const; 00177 00178 static Endian systemBitOrder(); 00179 static Endian systemByteOrder(); 00180 00181 #ifndef QT_NO_IMAGEIO 00182 static const char* imageFormat( const QString &fileName ); 00183 static QStrList inputFormats(); 00184 static QStrList outputFormats(); 00185 #ifndef QT_NO_STRINGLIST 00186 static QStringList inputFormatList(); 00187 static QStringList outputFormatList(); 00188 #endif 00189 bool load( const QString &fileName, const char* format=0 ); 00190 bool loadFromData( const uchar *buf, uint len, 00191 const char *format=0 ); 00192 bool loadFromData( QByteArray data, const char* format=0 ); 00193 bool save( const QString &fileName, const char* format, 00194 int quality=-1 ) const; 00195 bool save( QIODevice * device, const char* format, 00196 int quality=-1 ) const; 00197 #endif //QT_NO_IMAGEIO 00198 00199 bool valid( int x, int y ) const; 00200 int pixelIndex( int x, int y ) const; 00201 QRgb pixel( int x, int y ) const; 00202 void setPixel( int x, int y, uint index_or_rgb ); 00203 00204 // Auxiliary data 00205 int dotsPerMeterX() const; 00206 int dotsPerMeterY() const; 00207 void setDotsPerMeterX(int); 00208 void setDotsPerMeterY(int); 00209 QPoint offset() const; 00210 void setOffset(const QPoint&); 00211 #ifndef QT_NO_IMAGE_TEXT 00212 QValueList<QImageTextKeyLang> textList() const; 00213 QStringList textLanguages() const; 00214 QStringList textKeys() const; 00215 QString text(const char* key, const char* lang=0) const; 00216 QString text(const QImageTextKeyLang&) const; 00217 void setText(const char* key, const char* lang, const QString&); 00218 #endif 00219 private: 00220 void init(); 00221 void reinit(); 00222 void freeBits(); 00223 static void warningIndexRange( const char *, int ); 00224 00225 struct QImageData : public QShared { // internal image data 00226 int w; // image width 00227 int h; // image height 00228 int d; // image depth 00229 int ncols; // number of colors 00230 int nbytes; // number of bytes data 00231 int bitordr; // bit order (1 bit depth) 00232 QRgb *ctbl; // color table 00233 uchar **bits; // image data 00234 bool alpha; // alpha buffer 00235 int dpmx; // dots per meter X (or 0) 00236 int dpmy; // dots per meter Y (or 0) 00237 QPoint offset; // offset in pixels 00238 #ifndef QT_NO_IMAGE_TEXT 00239 QImageDataMisc* misc; // less common stuff 00240 #endif 00241 bool ctbl_mine; // this allocated ctbl 00242 } *data; 00243 #ifndef QT_NO_IMAGE_TEXT 00244 QImageDataMisc& misc() const; 00245 #endif 00246 #ifndef QT_NO_IMAGEIO 00247 bool doImageIO( QImageIO* io, int quality ) const; 00248 #endif 00249 friend Q_EXPORT void bitBlt( QImage* dst, int dx, int dy, 00250 const QImage* src, int sx, int sy, 00251 int sw, int sh, int conversion_flags ); 00252 }; 00253 00254 00255 // QImage stream functions 00256 00257 #if !defined(QT_NO_DATASTREAM) && !defined(QT_NO_IMAGEIO) 00258 Q_EXPORT QDataStream &operator<<( QDataStream &, const QImage & ); 00259 Q_EXPORT QDataStream &operator>>( QDataStream &, QImage & ); 00260 #endif 00261 00262 #ifndef QT_NO_IMAGEIO 00263 class QIODevice; 00264 typedef void (*image_io_handler)( QImageIO * ); // image IO handler 00265 00266 00267 struct QImageIOData; 00268 00269 00270 class Q_EXPORT QImageIO 00271 { 00272 public: 00273 QImageIO(); 00274 QImageIO( QIODevice *ioDevice, const char *format ); 00275 QImageIO( const QString &fileName, const char* format ); 00276 ~QImageIO(); 00277 00278 00279 const QImage &image() const { return im; } 00280 int status() const { return iostat; } 00281 const char *format() const { return frmt; } 00282 QIODevice *ioDevice() const { return iodev; } 00283 QString fileName() const { return fname; } 00284 int quality() const; 00285 QString description() const { return descr; } 00286 const char *parameters() const; 00287 float gamma() const; 00288 00289 void setImage( const QImage & ); 00290 void setStatus( int ); 00291 void setFormat( const char * ); 00292 void setIODevice( QIODevice * ); 00293 void setFileName( const QString & ); 00294 void setQuality( int ); 00295 void setDescription( const QString & ); 00296 void setParameters( const char * ); 00297 void setGamma( float ); 00298 00299 bool read(); 00300 bool write(); 00301 00302 static const char* imageFormat( const QString &fileName ); 00303 static const char *imageFormat( QIODevice * ); 00304 static QStrList inputFormats(); 00305 static QStrList outputFormats(); 00306 00307 static void defineIOHandler( const char *format, 00308 const char *header, 00309 const char *flags, 00310 image_io_handler read_image, 00311 image_io_handler write_image ); 00312 00313 private: 00314 void init(); 00315 00316 QImage im; // image 00317 int iostat; // IO status 00318 QCString frmt; // image format 00319 QIODevice *iodev; // IO device 00320 QString fname; // file name 00321 char *params; // image parameters //### change to QImageIOData *d in 3.0 00322 QString descr; // image description 00323 QImageIOData *d; 00324 00325 private: // Disabled copy constructor and operator= 00326 #if defined(Q_DISABLE_COPY) 00327 QImageIO( const QImageIO & ); 00328 QImageIO &operator=( const QImageIO & ); 00329 #endif 00330 }; 00331 00332 #endif //QT_NO_IMAGEIO 00333 00334 Q_EXPORT void bitBlt( QImage* dst, int dx, int dy, const QImage* src, 00335 int sx=0, int sy=0, int sw=-1, int sh=-1, 00336 int conversion_flags=0 ); 00337 00338 00339 /***************************************************************************** 00340 QImage member functions 00341 *****************************************************************************/ 00342 00343 inline bool QImage::hasAlphaBuffer() const 00344 { 00345 return data->alpha; 00346 } 00347 00348 inline uchar *QImage::bits() const 00349 { 00350 return data->bits ? data->bits[0] : 0; 00351 } 00352 00353 inline uchar **QImage::jumpTable() const 00354 { 00355 return data->bits; 00356 } 00357 00358 inline QRgb *QImage::colorTable() const 00359 { 00360 return data->ctbl; 00361 } 00362 00363 inline int QImage::numBytes() const 00364 { 00365 return data->nbytes; 00366 } 00367 00368 inline int QImage::bytesPerLine() const 00369 { 00370 return data->h ? data->nbytes/data->h : 0; 00371 } 00372 00373 inline QImage QImage::copy(const QRect& r) const 00374 { 00375 return copy(r.x(), r.y(), r.width(), r.height()); 00376 } 00377 00378 inline QRgb QImage::color( int i ) const 00379 { 00380 #if defined(QT_CHECK_RANGE) 00381 if ( i >= data->ncols ) 00382 warningIndexRange( "color", i ); 00383 #endif 00384 return data->ctbl ? data->ctbl[i] : (QRgb)-1; 00385 } 00386 00387 inline void QImage::setColor( int i, QRgb c ) 00388 { 00389 #if defined(QT_CHECK_RANGE) 00390 if ( i >= data->ncols ) 00391 warningIndexRange( "setColor", i ); 00392 #endif 00393 if ( data->ctbl ) 00394 data->ctbl[i] = c; 00395 } 00396 00397 inline uchar *QImage::scanLine( int i ) const 00398 { 00399 #if defined(QT_CHECK_RANGE) 00400 if ( i >= data->h ) 00401 warningIndexRange( "scanLine", i ); 00402 #endif 00403 return data->bits ? data->bits[i] : 0; 00404 } 00405 00406 inline int QImage::dotsPerMeterX() const 00407 { 00408 return data->dpmx; 00409 } 00410 00411 inline int QImage::dotsPerMeterY() const 00412 { 00413 return data->dpmy; 00414 } 00415 00416 inline QPoint QImage::offset() const 00417 { 00418 return data->offset; 00419 } 00420 00421 00422 #endif // QIMAGE_H