| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QIMAGE_H
|
|---|
| 43 | #define QIMAGE_H
|
|---|
| 44 |
|
|---|
| 45 | #include <QtGui/qtransform.h>
|
|---|
| 46 | #include <QtGui/qpaintdevice.h>
|
|---|
| 47 | #include <QtGui/qrgb.h>
|
|---|
| 48 | #include <QtCore/qbytearray.h>
|
|---|
| 49 | #include <QtCore/qrect.h>
|
|---|
| 50 | #include <QtCore/qstring.h>
|
|---|
| 51 |
|
|---|
| 52 | QT_BEGIN_HEADER
|
|---|
| 53 |
|
|---|
| 54 | QT_BEGIN_NAMESPACE
|
|---|
| 55 |
|
|---|
| 56 | QT_MODULE(Gui)
|
|---|
| 57 |
|
|---|
| 58 | class QIODevice;
|
|---|
| 59 | class QStringList;
|
|---|
| 60 | class QMatrix;
|
|---|
| 61 | class QTransform;
|
|---|
| 62 | class QVariant;
|
|---|
| 63 | template <class T> class QList;
|
|---|
| 64 | template <class T> class QVector;
|
|---|
| 65 |
|
|---|
| 66 | struct QImageData;
|
|---|
| 67 | class QImageDataMisc; // internal
|
|---|
| 68 | #ifndef QT_NO_IMAGE_TEXT
|
|---|
| 69 | class Q_GUI_EXPORT QImageTextKeyLang {
|
|---|
| 70 | public:
|
|---|
| 71 | QImageTextKeyLang(const char* k, const char* l) : key(k), lang(l) { }
|
|---|
| 72 | QImageTextKeyLang() { }
|
|---|
| 73 |
|
|---|
| 74 | QByteArray key;
|
|---|
| 75 | QByteArray lang;
|
|---|
| 76 |
|
|---|
| 77 | bool operator< (const QImageTextKeyLang& other) const
|
|---|
| 78 | { return key < other.key || (key==other.key && lang < other.lang); }
|
|---|
| 79 | bool operator== (const QImageTextKeyLang& other) const
|
|---|
| 80 | { return key==other.key && lang==other.lang; }
|
|---|
| 81 | inline bool operator!= (const QImageTextKeyLang &other) const
|
|---|
| 82 | { return !operator==(other); }
|
|---|
| 83 | };
|
|---|
| 84 | #endif //QT_NO_IMAGE_TEXT
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | class Q_GUI_EXPORT QImage : public QPaintDevice
|
|---|
| 88 | {
|
|---|
| 89 | public:
|
|---|
| 90 | enum InvertMode { InvertRgb, InvertRgba };
|
|---|
| 91 | enum Format {
|
|---|
| 92 | Format_Invalid,
|
|---|
| 93 | Format_Mono,
|
|---|
| 94 | Format_MonoLSB,
|
|---|
| 95 | Format_Indexed8,
|
|---|
| 96 | Format_RGB32,
|
|---|
| 97 | Format_ARGB32,
|
|---|
| 98 | Format_ARGB32_Premultiplied,
|
|---|
| 99 | Format_RGB16,
|
|---|
| 100 | Format_ARGB8565_Premultiplied,
|
|---|
| 101 | Format_RGB666,
|
|---|
| 102 | Format_ARGB6666_Premultiplied,
|
|---|
| 103 | Format_RGB555,
|
|---|
| 104 | Format_ARGB8555_Premultiplied,
|
|---|
| 105 | Format_RGB888,
|
|---|
| 106 | Format_RGB444,
|
|---|
| 107 | Format_ARGB4444_Premultiplied,
|
|---|
| 108 | #if 0
|
|---|
| 109 | // reserved for future use
|
|---|
| 110 | Format_RGB15,
|
|---|
| 111 | Format_Grayscale16,
|
|---|
| 112 | Format_Grayscale8,
|
|---|
| 113 | Format_Grayscale4,
|
|---|
| 114 | Format_Grayscale4LSB,
|
|---|
| 115 | Format_Grayscale2,
|
|---|
| 116 | Format_Grayscale2LSB
|
|---|
| 117 | #endif
|
|---|
| 118 | #ifndef qdoc
|
|---|
| 119 | NImageFormats
|
|---|
| 120 | #endif
|
|---|
| 121 | };
|
|---|
| 122 |
|
|---|
| 123 | QImage();
|
|---|
| 124 | QImage(const QSize &size, Format format);
|
|---|
| 125 | QImage(int width, int height, Format format);
|
|---|
| 126 | QImage(uchar *data, int width, int height, Format format);
|
|---|
| 127 | QImage(const uchar *data, int width, int height, Format format);
|
|---|
| 128 | QImage(uchar *data, int width, int height, int bytesPerLine, Format format);
|
|---|
| 129 | QImage(const uchar *data, int width, int height, int bytesPerLine, Format format);
|
|---|
| 130 |
|
|---|
| 131 | #ifndef QT_NO_IMAGEFORMAT_XPM
|
|---|
| 132 | explicit QImage(const char * const xpm[]);
|
|---|
| 133 | #endif
|
|---|
| 134 | explicit QImage(const QString &fileName, const char *format = 0);
|
|---|
| 135 | #ifndef QT_NO_CAST_FROM_ASCII
|
|---|
| 136 | explicit QImage(const char *fileName, const char *format = 0);
|
|---|
| 137 | #endif
|
|---|
| 138 |
|
|---|
| 139 | QImage(const QImage &);
|
|---|
| 140 | ~QImage();
|
|---|
| 141 |
|
|---|
| 142 | QImage &operator=(const QImage &);
|
|---|
| 143 | bool isNull() const;
|
|---|
| 144 |
|
|---|
| 145 | int devType() const;
|
|---|
| 146 |
|
|---|
| 147 | bool operator==(const QImage &) const;
|
|---|
| 148 | bool operator!=(const QImage &) const;
|
|---|
| 149 | operator QVariant() const;
|
|---|
| 150 | void detach();
|
|---|
| 151 | bool isDetached() const;
|
|---|
| 152 |
|
|---|
| 153 | QImage copy(const QRect &rect = QRect()) const;
|
|---|
| 154 | inline QImage copy(int x, int y, int w, int h) const
|
|---|
| 155 | { return copy(QRect(x, y, w, h)); }
|
|---|
| 156 |
|
|---|
| 157 | Format format() const;
|
|---|
| 158 |
|
|---|
| 159 | QImage convertToFormat(Format f, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
|
|---|
| 160 | QImage convertToFormat(Format f, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags = Qt::AutoColor) const Q_REQUIRED_RESULT;
|
|---|
| 161 |
|
|---|
| 162 | int width() const;
|
|---|
| 163 | int height() const;
|
|---|
| 164 | QSize size() const;
|
|---|
| 165 | QRect rect() const;
|
|---|
| 166 |
|
|---|
| 167 | int depth() const;
|
|---|
| 168 | int numColors() const;
|
|---|
| 169 |
|
|---|
| 170 | QRgb color(int i) const;
|
|---|
| 171 | void setColor(int i, QRgb c);
|
|---|
| 172 | void setNumColors(int);
|
|---|
| 173 |
|
|---|
| 174 | bool allGray() const;
|
|---|
| 175 | bool isGrayscale() const;
|
|---|
| 176 |
|
|---|
| 177 | uchar *bits();
|
|---|
| 178 | const uchar *bits() const;
|
|---|
| 179 | int numBytes() const;
|
|---|
| 180 |
|
|---|
| 181 | uchar *scanLine(int);
|
|---|
| 182 | const uchar *scanLine(int) const;
|
|---|
| 183 | int bytesPerLine() const;
|
|---|
| 184 |
|
|---|
| 185 | bool valid(int x, int y) const;
|
|---|
| 186 | bool valid(const QPoint &pt) const;
|
|---|
| 187 |
|
|---|
| 188 | int pixelIndex(int x, int y) const;
|
|---|
| 189 | int pixelIndex(const QPoint &pt) const;
|
|---|
| 190 |
|
|---|
| 191 | QRgb pixel(int x, int y) const;
|
|---|
| 192 | QRgb pixel(const QPoint &pt) const;
|
|---|
| 193 |
|
|---|
| 194 | void setPixel(int x, int y, uint index_or_rgb);
|
|---|
| 195 | void setPixel(const QPoint &pt, uint index_or_rgb);
|
|---|
| 196 |
|
|---|
| 197 | QVector<QRgb> colorTable() const;
|
|---|
| 198 | void setColorTable(const QVector<QRgb> colors);
|
|---|
| 199 |
|
|---|
| 200 | void fill(uint pixel);
|
|---|
| 201 |
|
|---|
| 202 | bool hasAlphaChannel() const;
|
|---|
| 203 | void setAlphaChannel(const QImage &alphaChannel);
|
|---|
| 204 | QImage alphaChannel() const;
|
|---|
| 205 | QImage createAlphaMask(Qt::ImageConversionFlags flags = Qt::AutoColor) const;
|
|---|
| 206 | #ifndef QT_NO_IMAGE_HEURISTIC_MASK
|
|---|
| 207 | QImage createHeuristicMask(bool clipTight = true) const;
|
|---|
| 208 | #endif
|
|---|
| 209 | QImage createMaskFromColor(QRgb color, Qt::MaskMode mode = Qt::MaskInColor) const;
|
|---|
| 210 |
|
|---|
| 211 | inline QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
|---|
| 212 | Qt::TransformationMode mode = Qt::FastTransformation) const
|
|---|
| 213 | { return scaled(QSize(w, h), aspectMode, mode); }
|
|---|
| 214 | QImage scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio,
|
|---|
| 215 | Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 216 | QImage scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 217 | QImage scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 218 | QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 219 | static QMatrix trueMatrix(const QMatrix &, int w, int h);
|
|---|
| 220 | QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const;
|
|---|
| 221 | static QTransform trueMatrix(const QTransform &, int w, int h);
|
|---|
| 222 | QImage mirrored(bool horizontally = false, bool vertically = true) const;
|
|---|
| 223 | QImage rgbSwapped() const;
|
|---|
| 224 | void invertPixels(InvertMode = InvertRgb);
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 | bool load(QIODevice *device, const char* format);
|
|---|
| 228 | bool load(const QString &fileName, const char* format=0);
|
|---|
| 229 | bool loadFromData(const uchar *buf, int len, const char *format = 0);
|
|---|
| 230 | inline bool loadFromData(const QByteArray &data, const char* aformat=0)
|
|---|
| 231 | { return loadFromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), aformat); }
|
|---|
| 232 |
|
|---|
| 233 | bool save(const QString &fileName, const char* format=0, int quality=-1) const;
|
|---|
| 234 | bool save(QIODevice *device, const char* format=0, int quality=-1) const;
|
|---|
| 235 |
|
|---|
| 236 | static QImage fromData(const uchar *data, int size, const char *format = 0);
|
|---|
| 237 | inline static QImage fromData(const QByteArray &data, const char *format = 0)
|
|---|
| 238 | { return fromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), format); }
|
|---|
| 239 |
|
|---|
| 240 | int serialNumber() const;
|
|---|
| 241 | qint64 cacheKey() const;
|
|---|
| 242 |
|
|---|
| 243 | QPaintEngine *paintEngine() const;
|
|---|
| 244 |
|
|---|
| 245 | // Auxiliary data
|
|---|
| 246 | int dotsPerMeterX() const;
|
|---|
| 247 | int dotsPerMeterY() const;
|
|---|
| 248 | void setDotsPerMeterX(int);
|
|---|
| 249 | void setDotsPerMeterY(int);
|
|---|
| 250 | QPoint offset() const;
|
|---|
| 251 | void setOffset(const QPoint&);
|
|---|
| 252 | #ifndef QT_NO_IMAGE_TEXT
|
|---|
| 253 | QStringList textKeys() const;
|
|---|
| 254 | QString text(const QString &key = QString()) const;
|
|---|
| 255 | void setText(const QString &key, const QString &value);
|
|---|
| 256 |
|
|---|
| 257 | // The following functions are obsolete as of 4.1
|
|---|
| 258 | QString text(const char* key, const char* lang=0) const;
|
|---|
| 259 | QList<QImageTextKeyLang> textList() const;
|
|---|
| 260 | QStringList textLanguages() const;
|
|---|
| 261 | QString text(const QImageTextKeyLang&) const;
|
|---|
| 262 | void setText(const char* key, const char* lang, const QString&);
|
|---|
| 263 | #endif
|
|---|
| 264 |
|
|---|
| 265 | #ifdef QT3_SUPPORT
|
|---|
| 266 | enum Endian { BigEndian, LittleEndian, IgnoreEndian };
|
|---|
| 267 | QT3_SUPPORT_CONSTRUCTOR QImage(int width, int height, int depth, int numColors=0, Endian bitOrder=IgnoreEndian);
|
|---|
| 268 | QT3_SUPPORT_CONSTRUCTOR QImage(const QSize&, int depth, int numColors=0, Endian bitOrder=IgnoreEndian);
|
|---|
| 269 | QT3_SUPPORT_CONSTRUCTOR QImage(uchar *data, int w, int h, int depth, const QRgb *colortable, int numColors, Endian bitOrder);
|
|---|
| 270 | #ifdef Q_WS_QWS
|
|---|
| 271 | QT3_SUPPORT_CONSTRUCTOR QImage(uchar *data, int w, int h, int depth, int pbl, const QRgb *colortable, int numColors, Endian bitOrder);
|
|---|
| 272 | #endif
|
|---|
| 273 | inline QT3_SUPPORT Endian bitOrder() const {
|
|---|
| 274 | Format f = format();
|
|---|
| 275 | return f == Format_Mono ? BigEndian : (f == Format_MonoLSB ? LittleEndian : IgnoreEndian);
|
|---|
| 276 | }
|
|---|
| 277 | QT3_SUPPORT QImage convertDepth(int, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
|
|---|
| 278 | QT3_SUPPORT QImage convertDepthWithPalette(int, QRgb* p, int pc, Qt::ImageConversionFlags flags = Qt::AutoColor) const;
|
|---|
| 279 | QT3_SUPPORT QImage convertBitOrder(Endian) const;
|
|---|
| 280 | QT3_SUPPORT bool hasAlphaBuffer() const;
|
|---|
| 281 | QT3_SUPPORT void setAlphaBuffer(bool);
|
|---|
| 282 | QT3_SUPPORT uchar **jumpTable();
|
|---|
| 283 | QT3_SUPPORT const uchar * const *jumpTable() const;
|
|---|
| 284 | inline QT3_SUPPORT void reset() { *this = QImage(); }
|
|---|
| 285 | static inline QT3_SUPPORT Endian systemByteOrder()
|
|---|
| 286 | { return QSysInfo::ByteOrder == QSysInfo::BigEndian ? BigEndian : LittleEndian; }
|
|---|
| 287 | inline QT3_SUPPORT QImage swapRGB() const { return rgbSwapped(); }
|
|---|
| 288 | inline QT3_SUPPORT QImage mirror(bool horizontally = false, bool vertically = true) const
|
|---|
| 289 | { return mirrored(horizontally, vertically); }
|
|---|
| 290 | QT3_SUPPORT bool create(const QSize&, int depth, int numColors=0, Endian bitOrder=IgnoreEndian);
|
|---|
| 291 | QT3_SUPPORT bool create(int width, int height, int depth, int numColors=0, Endian bitOrder=IgnoreEndian);
|
|---|
| 292 | inline QT3_SUPPORT QImage xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); }
|
|---|
| 293 | inline QT3_SUPPORT QImage smoothScale(int w, int h, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) const
|
|---|
| 294 | { return scaled(QSize(w, h), mode, Qt::SmoothTransformation); }
|
|---|
| 295 | inline QImage QT3_SUPPORT smoothScale(const QSize &s, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) const
|
|---|
| 296 | { return scaled(s, mode, Qt::SmoothTransformation); }
|
|---|
| 297 | inline QT3_SUPPORT QImage scaleWidth(int w) const { return scaledToWidth(w); }
|
|---|
| 298 | inline QT3_SUPPORT QImage scaleHeight(int h) const { return scaledToHeight(h); }
|
|---|
| 299 | inline QT3_SUPPORT void invertPixels(bool invertAlpha) { invertAlpha ? invertPixels(InvertRgba) : invertPixels(InvertRgb); }
|
|---|
| 300 | inline QT3_SUPPORT QImage copy(int x, int y, int w, int h, Qt::ImageConversionFlags) const
|
|---|
| 301 | { return copy(QRect(x, y, w, h)); }
|
|---|
| 302 | inline QT3_SUPPORT QImage copy(const QRect &rect, Qt::ImageConversionFlags) const
|
|---|
| 303 | { return copy(rect); }
|
|---|
| 304 | static QT3_SUPPORT Endian systemBitOrder();
|
|---|
| 305 | inline QT3_SUPPORT_CONSTRUCTOR QImage(const QByteArray &data)
|
|---|
| 306 | { d = 0; *this = QImage::fromData(data); }
|
|---|
| 307 | #endif
|
|---|
| 308 |
|
|---|
| 309 | protected:
|
|---|
| 310 | virtual int metric(PaintDeviceMetric metric) const;
|
|---|
| 311 |
|
|---|
| 312 | private:
|
|---|
| 313 | friend class QWSOnScreenSurface;
|
|---|
| 314 | QImageData *d;
|
|---|
| 315 |
|
|---|
| 316 | friend class QRasterPixmapData;
|
|---|
| 317 | friend class QDetachedPixmap;
|
|---|
| 318 | friend Q_GUI_EXPORT qint64 qt_image_id(const QImage &image);
|
|---|
| 319 | friend const QVector<QRgb> *qt_image_colortable(const QImage &image);
|
|---|
| 320 |
|
|---|
| 321 | public:
|
|---|
| 322 | typedef QImageData * DataPtr;
|
|---|
| 323 | inline DataPtr &data_ptr() { return d; }
|
|---|
| 324 | };
|
|---|
| 325 |
|
|---|
| 326 | Q_DECLARE_SHARED(QImage)
|
|---|
| 327 | Q_DECLARE_TYPEINFO(QImage, Q_MOVABLE_TYPE);
|
|---|
| 328 |
|
|---|
| 329 | // Inline functions...
|
|---|
| 330 |
|
|---|
| 331 | Q_GUI_EXPORT_INLINE bool QImage::valid(const QPoint &pt) const { return valid(pt.x(), pt.y()); }
|
|---|
| 332 | Q_GUI_EXPORT_INLINE int QImage::pixelIndex(const QPoint &pt) const { return pixelIndex(pt.x(), pt.y());}
|
|---|
| 333 | Q_GUI_EXPORT_INLINE QRgb QImage::pixel(const QPoint &pt) const { return pixel(pt.x(), pt.y()); }
|
|---|
| 334 | Q_GUI_EXPORT_INLINE void QImage::setPixel(const QPoint &pt, uint index_or_rgb) { setPixel(pt.x(), pt.y(), index_or_rgb); }
|
|---|
| 335 |
|
|---|
| 336 | // QImage stream functions
|
|---|
| 337 |
|
|---|
| 338 | #if !defined(QT_NO_DATASTREAM)
|
|---|
| 339 | Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QImage &);
|
|---|
| 340 | Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QImage &);
|
|---|
| 341 | #endif
|
|---|
| 342 |
|
|---|
| 343 | #ifdef QT3_SUPPORT
|
|---|
| 344 | Q_GUI_EXPORT QT3_SUPPORT void bitBlt(QImage* dst, int dx, int dy, const QImage* src,
|
|---|
| 345 | int sx=0, int sy=0, int sw=-1, int sh=-1, Qt::ImageConversionFlags flags = Qt::AutoColor);
|
|---|
| 346 | #endif
|
|---|
| 347 |
|
|---|
| 348 | QT_END_NAMESPACE
|
|---|
| 349 |
|
|---|
| 350 | QT_END_HEADER
|
|---|
| 351 |
|
|---|
| 352 | #endif // QIMAGE_H
|
|---|