author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
#ifdef QT_DEPRECATED |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
QT_DEPRECATED int numColors() const; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
int colorCount() const; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
172 |
int bitPlaneCount() const; |
0 | 173 |
|
174 |
QRgb color(int i) const; |
|
175 |
void setColor(int i, QRgb c); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
#ifdef QT_DEPRECATED |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
QT_DEPRECATED void setNumColors(int); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
void setColorCount(int); |
0 | 180 |
|
181 |
bool allGray() const; |
|
182 |
bool isGrayscale() const; |
|
183 |
||
184 |
uchar *bits(); |
|
185 |
const uchar *bits() const; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
186 |
const uchar *constBits() const; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
#ifdef QT_DEPRECATED |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
QT_DEPRECATED int numBytes() const; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
int byteCount() const; |
0 | 191 |
|
192 |
uchar *scanLine(int); |
|
193 |
const uchar *scanLine(int) const; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
194 |
const uchar *constScanLine(int) const; |
0 | 195 |
int bytesPerLine() const; |
196 |
||
197 |
bool valid(int x, int y) const; |
|
198 |
bool valid(const QPoint &pt) const; |
|
199 |
||
200 |
int pixelIndex(int x, int y) const; |
|
201 |
int pixelIndex(const QPoint &pt) const; |
|
202 |
||
203 |
QRgb pixel(int x, int y) const; |
|
204 |
QRgb pixel(const QPoint &pt) const; |
|
205 |
||
206 |
void setPixel(int x, int y, uint index_or_rgb); |
|
207 |
void setPixel(const QPoint &pt, uint index_or_rgb); |
|
208 |
||
209 |
QVector<QRgb> colorTable() const; |
|
210 |
void setColorTable(const QVector<QRgb> colors); |
|
211 |
||
212 |
void fill(uint pixel); |
|
213 |
||
214 |
bool hasAlphaChannel() const; |
|
215 |
void setAlphaChannel(const QImage &alphaChannel); |
|
216 |
QImage alphaChannel() const; |
|
217 |
QImage createAlphaMask(Qt::ImageConversionFlags flags = Qt::AutoColor) const; |
|
218 |
#ifndef QT_NO_IMAGE_HEURISTIC_MASK |
|
219 |
QImage createHeuristicMask(bool clipTight = true) const; |
|
220 |
#endif |
|
221 |
QImage createMaskFromColor(QRgb color, Qt::MaskMode mode = Qt::MaskInColor) const; |
|
222 |
||
223 |
inline QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio, |
|
224 |
Qt::TransformationMode mode = Qt::FastTransformation) const |
|
225 |
{ return scaled(QSize(w, h), aspectMode, mode); } |
|
226 |
QImage scaled(const QSize &s, Qt::AspectRatioMode aspectMode = Qt::IgnoreAspectRatio, |
|
227 |
Qt::TransformationMode mode = Qt::FastTransformation) const; |
|
228 |
QImage scaledToWidth(int w, Qt::TransformationMode mode = Qt::FastTransformation) const; |
|
229 |
QImage scaledToHeight(int h, Qt::TransformationMode mode = Qt::FastTransformation) const; |
|
230 |
QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const; |
|
231 |
static QMatrix trueMatrix(const QMatrix &, int w, int h); |
|
232 |
QImage transformed(const QTransform &matrix, Qt::TransformationMode mode = Qt::FastTransformation) const; |
|
233 |
static QTransform trueMatrix(const QTransform &, int w, int h); |
|
234 |
QImage mirrored(bool horizontally = false, bool vertically = true) const; |
|
235 |
QImage rgbSwapped() const; |
|
236 |
void invertPixels(InvertMode = InvertRgb); |
|
237 |
||
238 |
||
239 |
bool load(QIODevice *device, const char* format); |
|
240 |
bool load(const QString &fileName, const char* format=0); |
|
241 |
bool loadFromData(const uchar *buf, int len, const char *format = 0); |
|
242 |
inline bool loadFromData(const QByteArray &data, const char* aformat=0) |
|
243 |
{ return loadFromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), aformat); } |
|
244 |
||
245 |
bool save(const QString &fileName, const char* format=0, int quality=-1) const; |
|
246 |
bool save(QIODevice *device, const char* format=0, int quality=-1) const; |
|
247 |
||
248 |
static QImage fromData(const uchar *data, int size, const char *format = 0); |
|
249 |
inline static QImage fromData(const QByteArray &data, const char *format = 0) |
|
250 |
{ return fromData(reinterpret_cast<const uchar *>(data.constData()), data.size(), format); } |
|
251 |
||
252 |
int serialNumber() const; |
|
253 |
qint64 cacheKey() const; |
|
254 |
||
255 |
QPaintEngine *paintEngine() const; |
|
256 |
||
257 |
// Auxiliary data |
|
258 |
int dotsPerMeterX() const; |
|
259 |
int dotsPerMeterY() const; |
|
260 |
void setDotsPerMeterX(int); |
|
261 |
void setDotsPerMeterY(int); |
|
262 |
QPoint offset() const; |
|
263 |
void setOffset(const QPoint&); |
|
264 |
#ifndef QT_NO_IMAGE_TEXT |
|
265 |
QStringList textKeys() const; |
|
266 |
QString text(const QString &key = QString()) const; |
|
267 |
void setText(const QString &key, const QString &value); |
|
268 |
||
269 |
// The following functions are obsolete as of 4.1 |
|
270 |
QString text(const char* key, const char* lang=0) const; |
|
271 |
QList<QImageTextKeyLang> textList() const; |
|
272 |
QStringList textLanguages() const; |
|
273 |
QString text(const QImageTextKeyLang&) const; |
|
274 |
void setText(const char* key, const char* lang, const QString&); |
|
275 |
#endif |
|
276 |
||
277 |
#ifdef QT3_SUPPORT |
|
278 |
enum Endian { BigEndian, LittleEndian, IgnoreEndian }; |
|
279 |
QT3_SUPPORT_CONSTRUCTOR QImage(int width, int height, int depth, int numColors=0, Endian bitOrder=IgnoreEndian); |
|
280 |
QT3_SUPPORT_CONSTRUCTOR QImage(const QSize&, int depth, int numColors=0, Endian bitOrder=IgnoreEndian); |
|
281 |
QT3_SUPPORT_CONSTRUCTOR QImage(uchar *data, int w, int h, int depth, const QRgb *colortable, int numColors, Endian bitOrder); |
|
282 |
#ifdef Q_WS_QWS |
|
283 |
QT3_SUPPORT_CONSTRUCTOR QImage(uchar *data, int w, int h, int depth, int pbl, const QRgb *colortable, int numColors, Endian bitOrder); |
|
284 |
#endif |
|
285 |
inline QT3_SUPPORT Endian bitOrder() const { |
|
286 |
Format f = format(); |
|
287 |
return f == Format_Mono ? BigEndian : (f == Format_MonoLSB ? LittleEndian : IgnoreEndian); |
|
288 |
} |
|
289 |
QT3_SUPPORT QImage convertDepth(int, Qt::ImageConversionFlags flags = Qt::AutoColor) const; |
|
290 |
QT3_SUPPORT QImage convertDepthWithPalette(int, QRgb* p, int pc, Qt::ImageConversionFlags flags = Qt::AutoColor) const; |
|
291 |
QT3_SUPPORT QImage convertBitOrder(Endian) const; |
|
292 |
QT3_SUPPORT bool hasAlphaBuffer() const; |
|
293 |
QT3_SUPPORT void setAlphaBuffer(bool); |
|
294 |
QT3_SUPPORT uchar **jumpTable(); |
|
295 |
QT3_SUPPORT const uchar * const *jumpTable() const; |
|
296 |
inline QT3_SUPPORT void reset() { *this = QImage(); } |
|
297 |
static inline QT3_SUPPORT Endian systemByteOrder() |
|
298 |
{ return QSysInfo::ByteOrder == QSysInfo::BigEndian ? BigEndian : LittleEndian; } |
|
299 |
inline QT3_SUPPORT QImage swapRGB() const { return rgbSwapped(); } |
|
300 |
inline QT3_SUPPORT QImage mirror(bool horizontally = false, bool vertically = true) const |
|
301 |
{ return mirrored(horizontally, vertically); } |
|
302 |
QT3_SUPPORT bool create(const QSize&, int depth, int numColors=0, Endian bitOrder=IgnoreEndian); |
|
303 |
QT3_SUPPORT bool create(int width, int height, int depth, int numColors=0, Endian bitOrder=IgnoreEndian); |
|
304 |
inline QT3_SUPPORT QImage xForm(const QMatrix &matrix) const { return transformed(QTransform(matrix)); } |
|
305 |
inline QT3_SUPPORT QImage smoothScale(int w, int h, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) const |
|
306 |
{ return scaled(QSize(w, h), mode, Qt::SmoothTransformation); } |
|
307 |
inline QImage QT3_SUPPORT smoothScale(const QSize &s, Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) const |
|
308 |
{ return scaled(s, mode, Qt::SmoothTransformation); } |
|
309 |
inline QT3_SUPPORT QImage scaleWidth(int w) const { return scaledToWidth(w); } |
|
310 |
inline QT3_SUPPORT QImage scaleHeight(int h) const { return scaledToHeight(h); } |
|
311 |
inline QT3_SUPPORT void invertPixels(bool invertAlpha) { invertAlpha ? invertPixels(InvertRgba) : invertPixels(InvertRgb); } |
|
312 |
inline QT3_SUPPORT QImage copy(int x, int y, int w, int h, Qt::ImageConversionFlags) const |
|
313 |
{ return copy(QRect(x, y, w, h)); } |
|
314 |
inline QT3_SUPPORT QImage copy(const QRect &rect, Qt::ImageConversionFlags) const |
|
315 |
{ return copy(rect); } |
|
316 |
static QT3_SUPPORT Endian systemBitOrder(); |
|
317 |
inline QT3_SUPPORT_CONSTRUCTOR QImage(const QByteArray &data) |
|
318 |
{ d = 0; *this = QImage::fromData(data); } |
|
319 |
#endif |
|
320 |
||
321 |
protected: |
|
322 |
virtual int metric(PaintDeviceMetric metric) const; |
|
323 |
||
324 |
private: |
|
325 |
friend class QWSOnScreenSurface; |
|
326 |
QImageData *d; |
|
327 |
||
328 |
friend class QRasterPixmapData; |
|
329 |
friend class QPixmapCacheEntry; |
|
330 |
friend Q_GUI_EXPORT qint64 qt_image_id(const QImage &image); |
|
331 |
friend const QVector<QRgb> *qt_image_colortable(const QImage &image); |
|
332 |
||
333 |
public: |
|
334 |
typedef QImageData * DataPtr; |
|
335 |
inline DataPtr &data_ptr() { return d; } |
|
336 |
}; |
|
337 |
||
338 |
Q_DECLARE_SHARED(QImage) |
|
339 |
Q_DECLARE_TYPEINFO(QImage, Q_MOVABLE_TYPE); |
|
340 |
||
341 |
// Inline functions... |
|
342 |
||
343 |
Q_GUI_EXPORT_INLINE bool QImage::valid(const QPoint &pt) const { return valid(pt.x(), pt.y()); } |
|
344 |
Q_GUI_EXPORT_INLINE int QImage::pixelIndex(const QPoint &pt) const { return pixelIndex(pt.x(), pt.y());} |
|
345 |
Q_GUI_EXPORT_INLINE QRgb QImage::pixel(const QPoint &pt) const { return pixel(pt.x(), pt.y()); } |
|
346 |
Q_GUI_EXPORT_INLINE void QImage::setPixel(const QPoint &pt, uint index_or_rgb) { setPixel(pt.x(), pt.y(), index_or_rgb); } |
|
347 |
||
348 |
// QImage stream functions |
|
349 |
||
350 |
#if !defined(QT_NO_DATASTREAM) |
|
351 |
Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QImage &); |
|
352 |
Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QImage &); |
|
353 |
#endif |
|
354 |
||
355 |
#ifdef QT3_SUPPORT |
|
356 |
Q_GUI_EXPORT QT3_SUPPORT void bitBlt(QImage* dst, int dx, int dy, const QImage* src, |
|
357 |
int sx=0, int sy=0, int sw=-1, int sh=-1, Qt::ImageConversionFlags flags = Qt::AutoColor); |
|
358 |
#endif |
|
359 |
||
360 |
QT_END_NAMESPACE |
|
361 |
||
362 |
QT_END_HEADER |
|
363 |
||
364 |
#endif // QIMAGE_H |