00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QIMAGE_H
00043 #define QIMAGE_H
00044
00045 #include <QtGui/qtransform.h>
00046 #include <QtGui/qpaintdevice.h>
00047 #include <QtGui/qrgb.h>
00048 #include <QtCore/qbytearray.h>
00049 #include <QtCore/qrect.h>
00050 #include <QtCore/qstring.h>
00051
00052 QT_BEGIN_HEADER
00053
00054 QT_BEGIN_NAMESPACE
00055
00056 QT_MODULE(Gui)
00057
00058 class QIODevice;
00059 class QStringList;
00060 class QMatrix;
00061 class QTransform;
00062 class QVariant;
00063 template <class T> class QList;
00064 template <class T> class QVector;
00065
00066 struct QImageData;
00067 class QImageDataMisc;
00068 #ifndef QT_NO_IMAGE_TEXT
00069 class Q_GUI_EXPORT QImageTextKeyLang {
00070 public:
00071 QImageTextKeyLang(const char* k, const char* l) : key(k), lang(l) { }
00072 QImageTextKeyLang() { }
00073
00074 QByteArray key;
00075 QByteArray lang;
00076
00077 bool operator< (const QImageTextKeyLang& other) const
00078 { return key < other.key || (key==other.key && lang < other.lang); }
00079 bool operator== (const QImageTextKeyLang& other) const
00080 { return key==other.key && lang==other.lang; }
00081 inline bool operator!= (const QImageTextKeyLang &other) const
00082 { return !operator==(other); }
00083 };
00084 #endif //QT_NO_IMAGE_TEXT
00085
00086
00087 class Q_GUI_EXPORT QImage : public QPaintDevice
00088 {
00089 public:
00090 enum InvertMode { InvertRgb, InvertRgba };
00091 enum Format {
00092 Format_Invalid,
00093 Format_Mono,
00094 Format_MonoLSB,
00095 Format_Indexed8,
00096 Format_RGB32,
00097 Format_ARGB32,
00098 Format_ARGB32_Premultiplied,
00099 Format_RGB16,
00100 Format_ARGB8565_Premultiplied,
00101 Format_RGB666,
00102 Format_ARGB6666_Premultiplied,
00103 Format_RGB555,
00104 Format_ARGB8555_Premultiplied,
00105 Format_RGB888,
00106 Format_RGB444,
00107 Format_ARGB4444_Premultiplied,
00108 #if 0
00109
00110 Format_RGB15,
00111 Format_Grayscale16,
00112 Format_Grayscale8,
00113 Format_Grayscale4,
00114 Format_Grayscale4LSB,
00115 Format_Grayscale2,
00116 Format_Grayscale2LSB
00117 #endif
00118 #ifndef qdoc
00119 NImageFormats
00120 #endif
00121 };
00122
00123 QImage();
00124 QImage(const QSize &size, Format format);
00125 QImage(int width, int height, Format format);
00126 QImage(uchar *data, int width, int height, Format format);
00127 QImage(const uchar *data, int width, int height, Format format);
00128 QImage(uchar *data, int width, int height, int bytesPerLine, Format format);
00129 QImage(const uchar *data, int width, int height, int bytesPerLine, Format format);
00130
00131 #ifndef QT_NO_IMAGEFORMAT_XPM
00132 explicit QImage(const char * const xpm[]);
00133 #endif
00134 explicit QImage(const QString &fileName, const char *format = 0);
00135 #ifndef QT_NO_CAST_FROM_ASCII
00136 explicit QImage(const char *fileName, const char *format = 0);
00137 #endif
00138
00139 QImage(const QImage &);
00140 ~QImage();
00141
00142 QImage &operator=(const QImage &);
00143 bool isNull() const;
00144
00145 int devType() const;
00146
00147 bool operator==(const QImage &) const;
00148 bool operator!=(const QImage &) const;
00149 operator QVariant() const;
00150 void detach();
00151 bool isDetached() const;
00152
00153 QImage copy(const QRect &rect = QRect()) const;
00154 inline QImage copy(int x, int y, int w, int h) const
00155 { return copy(QRect(x, y, w, h)); }
00156
00157 Format format() const;
00158
00159 QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
00160 QImage convertToFormat(Format f, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
00161
00162 int width() const;
00163 int height() const;
00164 QSize size() const;
00165 QRect rect() const;
00166
00167 int depth() const;
00168 #ifdef QT_DEPRECATED
00169 QT_DEPRECATED int numColors() const;
00170 #endif
00171 int colorCount() const;
00172 int bitPlaneCount() const;
00173
00174 QRgb color(int i) const;
00175 void setColor(int i, QRgb c);
00176 #ifdef QT_DEPRECATED
00177 QT_DEPRECATED void setNumColors(int);
00178 #endif
00179 void setColorCount(int);
00180
00181 bool allGray() const;
00182 bool isGrayscale() const;
00183
00184 uchar *bits();
00185 const uchar *bits() const;
00186 const uchar *constBits() const;
00187 #ifdef QT_DEPRECATED
00188 QT_DEPRECATED int numBytes() const;
00189 #endif
00190 int byteCount() const;
00191
00192 uchar *scanLine(int);
00193 const uchar *scanLine(int) const;
00194 const uchar *constScanLine(int) const;
00195 int bytesPerLine() const;
00196
00197 bool valid(int x, int y) const;
00198 bool valid(const QPoint &pt) const;
00199
00200 int pixelIndex(int x, int y) const;
00201 int pixelIndex(const QPoint &pt) const;
00202
00203 QRgb pixel(int x, int y) const;
00204 QRgb pixel(const QPoint &pt) const;
00205
00206 void setPixel(int x, int y, uint index_or_rgb);
00207 void setPixel(const QPoint &pt, uint index_or_rgb);
00208
00209 QVector<QRgb> colorTable() const;
00210 void setColorTable(const QVector<QRgb> colors);
00211
00212 void fill(uint pixel);
00213
00214 bool hasAlphaChannel() const;
00215 void setAlphaChannel(const QImage &alphaChannel);
00216 QImage alphaChannel() const;
00217 QImage createAlphaMask(Qt::ImageConversionFlags flags = Qt::AutoColor) const;
00218 #ifndef QT_NO_IMAGE_HEURISTIC_MASK
00219 QImage createHeuristicMask(bool clipTight = true) const;
00220 #endif
00221 QImage createMaskFromColor(QRgb color, Qt::MaskMode mode = Qt::MaskInColor) const;
00222
00223 inline QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
00224 Qt::TransformationMode mode = Qt::FastTransformation) const
00225 { return scaled(QSize(w, h), aspectMode, mode); }
00226 QImage scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
00227 Qt::TransformationMode mode = Qt::FastTransformation) const;
00228 QImage scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
00229 QImage scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
00230 QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const;
00231 static QMatrix trueMatrix(const QMatrix &, int w, int h);
00232 QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const;
00233 static QTransform trueMatrix(const QTransform &, int w, int h);
00234 QImage mirrored(bool horizontally = false, bool vertically = true) const;
00235 QImage rgbSwapped() const;
00236 void invertPixels(InvertMode = InvertRgb);
00237
00238
00239 bool load(QIODevice *device, const char* format);
00240 bool load(const QString &fileName, const char* format=0);
00241 bool loadFromData(const uchar *buf, int len, const char *format = 0);
00242 inline bool loadFromData(const QByteArray &data, const char* aformat=0)
00243 { return loadFromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), aformat); }
00244
00245 bool save(const QString &fileName, const char* format=0, int quality=-1) const;
00246 bool save(QIODevice *device, const char* format=0, int quality=-1) const;
00247
00248 static QImage fromData(const uchar *data, int size, const char *format = 0);
00249 inline static QImage fromData(const QByteArray &data, const char *format = 0)
00250 { return fromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), format); }
00251
00252 int serialNumber() const;
00253 qint64 cacheKey() const;
00254
00255 QPaintEngine *paintEngine() const;
00256
00257
00258 int dotsPerMeterX() const;
00259 int dotsPerMeterY() const;
00260 void setDotsPerMeterX(int);
00261 void setDotsPerMeterY(int);
00262 QPoint offset() const;
00263 void setOffset(const QPoint&);
00264 #ifndef QT_NO_IMAGE_TEXT
00265 QStringList textKeys() const;
00266 QString text(const QString &key = QString()) const;
00267 void setText(const QString &key, const QString &value);
00268
00269
00270 QString text(const char* key, const char* lang=0) const;
00271 QList<QImageTextKeyLang> textList() const;
00272 QStringList textLanguages() const;
00273 QString text(const QImageTextKeyLang&) const;
00274 void setText(const char* key, const char* lang, const QString&);
00275 #endif
00276
00277 #ifdef QT3_SUPPORT
00278 enum Endian { BigEndian, LittleEndian, IgnoreEndian };
00279 QT3_SUPPORT_CONSTRUCTOR QImage(int width, int height, int depth, int numColors=0, Endian bitOrder=IgnoreEndian);
00280 QT3_SUPPORT_CONSTRUCTOR QImage(const QSize&, int depth, int numColors=0, Endian bitOrder=IgnoreEndian);
00281 QT3_SUPPORT_CONSTRUCTOR QImage(uchar *data, int w, int h, int depth, const QRgb *colortable, int numColors, Endian bitOrder);
00282 #ifdef Q_WS_QWS
00283 QT3_SUPPORT_CONSTRUCTOR QImage(uchar *data, int w, int h, int depth, int pbl, const QRgb *colortable, int numColors, Endian bitOrder);
00284 #endif
00285 inline QT3_SUPPORT Endian bitOrder() const {
00286 Format f = format();
00287 return f == Format_Mono ? BigEndian : (f == Format_MonoLSB ? LittleEndian : IgnoreEndian);
00288 }
00289 QT3_SUPPORT QImage convertDepth(int, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
00290 QT3_SUPPORT QImage convertDepthWithPalette(int, QRgb* p, int pc, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
00291 QT3_SUPPORT QImage convertBitOrder(Endian) const;
00292 QT3_SUPPORT bool hasAlphaBuffer() const;
00293 QT3_SUPPORT void setAlphaBuffer(bool);
00294 QT3_SUPPORT uchar **jumpTable();
00295 QT3_SUPPORT const uchar * const *jumpTable() const;
00296 inline QT3_SUPPORT void reset() { *this = QImage(); }
00297 static inline QT3_SUPPORT Endian systemByteOrder()
00298 { return QSysInfo::ByteOrder == QSysInfo::BigEndian ? BigEndian : LittleEndian; }
00299 inline QT3_SUPPORT QImage swapRGB() const { return rgbSwapped(); }
00300 inline QT3_SUPPORT QImage mirror(bool horizontally = false, bool vertically = true) const
00301 { return mirrored(horizontally, vertically); }
00302 QT3_SUPPORT bool create(const QSize&, int depth, int numColors=0, Endian bitOrder=IgnoreEndian);
00303 QT3_SUPPORT bool create(int width, int height, int depth, int numColors=0, Endian bitOrder=IgnoreEndian);
00304 inline QT3_SUPPORT QImage xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); }
00305 inline QT3_SUPPORT QImage smoothScale(int w, int h, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) const
00306 { return scaled(QSize(w, h), mode, Qt::SmoothTransformation); }
00307 inline QImage QT3_SUPPORT smoothScale(const QSize &s, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) const
00308 { return scaled(s, mode, Qt::SmoothTransformation); }
00309 inline QT3_SUPPORT QImage scaleWidth(int w) const { return scaledToWidth(w); }
00310 inline QT3_SUPPORT QImage scaleHeight(int h) const { return scaledToHeight(h); }
00311 inline QT3_SUPPORT void invertPixels(bool invertAlpha) { invertAlpha ? invertPixels(InvertRgba) : invertPixels(InvertRgb); }
00312 inline QT3_SUPPORT QImage copy(int x, int y, int w, int h, Qt::ImageConversionFlags) const
00313 { return copy(QRect(x, y, w, h)); }
00314 inline QT3_SUPPORT QImage copy(const QRect &rect, Qt::ImageConversionFlags) const
00315 { return copy(rect); }
00316 static QT3_SUPPORT Endian systemBitOrder();
00317 inline QT3_SUPPORT_CONSTRUCTOR QImage(const QByteArray &data)
00318 { d = 0; *this = QImage::fromData(data); }
00319 #endif
00320
00321 protected:
00322 virtual int metric(PaintDeviceMetric metric) const;
00323
00324 private:
00325 friend class QWSOnScreenSurface;
00326 QImageData *d;
00327
00328 friend class QRasterPixmapData;
00329 friend class QPixmapCacheEntry;
00330 friend Q_GUI_EXPORT qint64 qt_image_id(const QImage &image);
00331 friend const QVector<QRgb> *qt_image_colortable(const QImage &image);
00332
00333 public:
00334 typedef QImageData * DataPtr;
00335 inline DataPtr &data_ptr() { return d; }
00336 };
00337
00338 Q_DECLARE_SHARED(QImage)
00339 Q_DECLARE_TYPEINFO(QImage, Q_MOVABLE_TYPE);
00340
00341
00342
00343 Q_GUI_EXPORT_INLINE bool QImage::valid(const QPoint &pt) const { return valid(pt.x(), pt.y()); }
00344 Q_GUI_EXPORT_INLINE int QImage::pixelIndex(const QPoint &pt) const { return pixelIndex(pt.x(), pt.y());}
00345 Q_GUI_EXPORT_INLINE QRgb QImage::pixel(const QPoint &pt) const { return pixel(pt.x(), pt.y()); }
00346 Q_GUI_EXPORT_INLINE void QImage::setPixel(const QPoint &pt, uint index_or_rgb) { setPixel(pt.x(), pt.y(), index_or_rgb); }
00347
00348
00349
00350 #if !defined(QT_NO_DATASTREAM)
00351 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QImage &);
00352 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QImage &);
00353 #endif
00354
00355 #ifdef QT3_SUPPORT
00356 Q_GUI_EXPORT QT3_SUPPORT void bitBlt(QImage* dst, int dx, int dy, const QImage* src,
00357 int sx=0, int sy=0, int sw=-1, int sh=-1, Qt::ImageConversionFlags flags = Qt::AutoColor);
00358 #endif
00359
00360 QT_END_NAMESPACE
00361
00362 QT_END_HEADER
00363
00364 #endif // QIMAGE_H