1 /****************************************************************************
3 ** This file is based on sources of the Qt GUI Toolkit, used under the terms
4 ** of the GNU General Public License version 2 (see the original copyright
6 ** All further contributions to this file are (and are required to be)
7 ** licensed under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
11 ** The original Qt license header follows:
14 ** Definition of QImage and QImageIO classes
18 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
20 ** This file is part of the kernel module of the Qt GUI Toolkit.
22 ** This file may be distributed under the terms of the Q Public License
23 ** as defined by Trolltech AS of Norway and appearing in the file
24 ** LICENSE.QPL included in the packaging of this file.
26 ** This file may be distributed and/or modified under the terms of the
27 ** GNU General Public License version 2 as published by the Free Software
28 ** Foundation and appearing in the file LICENSE.GPL included in the
29 ** packaging of this file.
31 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
32 ** licenses may use this file in accordance with the Qt Commercial License
33 ** Agreement provided with the Software.
35 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
36 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
38 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
39 ** information about Qt Commercial License Agreements.
40 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
41 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
43 ** Contact info@trolltech.com if any conditions of this licensing are
46 **********************************************************************/
54 class QImageDataMisc
; // internal
56 #ifndef QT_NO_IMAGE_TEXT
57 class Q_EXPORT QImageTextKeyLang
{
59 QImageTextKeyLang(const char* k
, const char* l
) : key(k
), lang(l
) { }
60 QImageTextKeyLang() { }
65 bool operator< (const QImageTextKeyLang
& other
) const
66 { return key
< other
.key
|| key
==other
.key
&& lang
< other
.lang
; }
67 bool operator== (const QImageTextKeyLang
& other
) const
68 { return key
==other
.key
&& lang
==other
.lang
; }
70 #endif //QT_NO_IMAGE_TEXT
76 enum Endian
{ IgnoreEndian
, BigEndian
, LittleEndian
};
79 QImage( int width
, int height
, int depth
, int numColors
=0,
80 Endian bitOrder
=IgnoreEndian
);
81 QImage( const QSize
&, int depth
, int numColors
=0,
82 Endian bitOrder
=IgnoreEndian
);
84 explicit QImage( const QString
&fileName
, const char* format
=0 );
85 explicit QImage( const char * const xpm
[] );
86 explicit QImage( const QByteArray
&data
);
88 QImage( uchar
* data
, int w
, int h
, int depth
,
89 QRgb
* colortable
, int numColors
,
92 QImage( uchar
* data
, int w
, int h
, int depth
, int pbl
,
93 QRgb
* colortable
, int numColors
,
96 QImage( const QImage
& );
99 QImage
&operator=( const QImage
& );
100 QImage
&operator=( const QPixmap
& );
101 bool operator==( const QImage
& ) const;
102 bool operator!=( const QImage
& ) const;
105 QImage
copy(int x
, int y
, int w
, int h
, int conversion_flags
=0) const;
106 QImage
copy(const QRect
&) const;
108 static QImage
fromMimeSource( const QString
& abs_name
);
110 bool isNull() const { return data
->bits
== 0; }
112 int width() const { return data
->w
; }
113 int height() const { return data
->h
; }
114 QSize
size() const { return QSize(data
->w
,data
->h
); }
115 QRect
rect() const { return QRect(0,0,data
->w
,data
->h
); }
116 int depth() const { return data
->d
; }
117 int numColors() const { return data
->ncols
; }
118 Endian
bitOrder() const { return (Endian
) data
->bitordr
; }
120 QRgb
color( int i
) const;
121 void setColor( int i
, QRgb c
);
122 void setNumColors( int );
124 bool hasAlphaBuffer() const;
125 void setAlphaBuffer( bool );
127 bool allGray() const;
128 bool isGrayscale() const;
131 uchar
*scanLine( int ) const;
132 uchar
**jumpTable() const;
133 QRgb
*colorTable() const;
134 int numBytes() const;
135 int bytesPerLine() const;
138 QGfx
* graphicsContext();
141 bool create( int width
, int height
, int depth
, int numColors
=0,
142 Endian bitOrder
=IgnoreEndian
);
143 bool create( const QSize
&, int depth
, int numColors
=0,
144 Endian bitOrder
=IgnoreEndian
);
147 void fill( uint pixel
);
148 void invertPixels( bool invertAlpha
= true );
150 QImage
convertDepth( int ) const;
151 #ifndef QT_NO_IMAGE_TRUECOLOR
152 QImage
convertDepthWithPalette( int, QRgb
* p
, int pc
, int cf
=0 ) const;
154 QImage
convertDepth( int, int conversion_flags
) const;
155 QImage
convertBitOrder( Endian
) const;
162 #ifndef QT_NO_IMAGE_SMOOTHSCALE
163 QImage
smoothScale( int w
, int h
, ScaleMode mode
=ScaleFree
) const;
164 QImage
smoothScale( const QSize
& s
, ScaleMode mode
=ScaleFree
) const;
166 #ifndef QT_NO_IMAGE_TRANSFORMATION
167 QImage
scale( int w
, int h
, ScaleMode mode
=ScaleFree
) const;
168 QImage
scale( const QSize
& s
, ScaleMode mode
=ScaleFree
) const;
169 QImage
scaleWidth( int w
) const;
170 QImage
scaleHeight( int h
) const;
171 QImage
xForm( const QWMatrix
&matrix
) const;
174 #ifndef QT_NO_IMAGE_DITHER_TO_1
175 QImage
createAlphaMask( int conversion_flags
=0 ) const;
177 #ifndef QT_NO_IMAGE_HEURISTIC_MASK
178 QImage
createHeuristicMask( bool clipTight
=true ) const;
180 #ifndef QT_NO_IMAGE_MIRROR
181 QImage
mirror() const;
182 QImage
mirror(bool horizontally
, bool vertically
) const;
184 QImage
swapRGB() const;
186 static Endian
systemBitOrder();
187 static Endian
systemByteOrder();
189 #ifndef QT_NO_IMAGEIO
190 static const char* imageFormat( const QString
&fileName
);
191 static QStrList
inputFormats();
192 static QStrList
outputFormats();
193 #ifndef QT_NO_STRINGLIST
194 static QStringList
inputFormatList();
195 static QStringList
outputFormatList();
197 bool load( const QString
&fileName
, const char* format
=0 );
198 bool loadFromData( const uchar
*buf
, uint len
,
199 const char *format
=0 );
200 bool loadFromData( QByteArray data
, const char* format
=0 );
201 bool save( const QString
&fileName
, const char* format
,
202 int quality
=-1 ) const;
203 bool save( QIODevice
* device
, const char* format
,
204 int quality
=-1 ) const;
205 #endif //QT_NO_IMAGEIO
207 bool valid( int x
, int y
) const;
208 int pixelIndex( int x
, int y
) const;
209 QRgb
pixel( int x
, int y
) const;
210 void setPixel( int x
, int y
, uint index_or_rgb
);
213 int dotsPerMeterX() const;
214 int dotsPerMeterY() const;
215 void setDotsPerMeterX(int);
216 void setDotsPerMeterY(int);
217 QPoint
offset() const;
218 void setOffset(const QPoint
&);
219 #ifndef QT_NO_IMAGE_TEXT
220 QValueList
<QImageTextKeyLang
> textList() const;
221 QStringList
textLanguages() const;
222 QStringList
textKeys() const;
223 QString
text(const char* key
, const char* lang
=0) const;
224 QString
text(const QImageTextKeyLang
&) const;
225 void setText(const char* key
, const char* lang
, const QString
&);
231 static void warningIndexRange( const char *, int );
233 struct QImageData
: public QShared
{ // internal image data
234 int w
; // image width
235 int h
; // image height
236 int d
; // image depth
237 int ncols
; // number of colors
238 int nbytes
; // number of bytes data
239 int bitordr
; // bit order (1 bit depth)
240 QRgb
*ctbl
; // color table
241 uchar
**bits
; // image data
242 bool alpha
; // alpha buffer
243 int dpmx
; // dots per meter X (or 0)
244 int dpmy
; // dots per meter Y (or 0)
245 QPoint offset
; // offset in pixels
246 #ifndef QT_NO_IMAGE_TEXT
247 QImageDataMisc
* misc
; // less common stuff
249 bool ctbl_mine
; // this allocated ctbl
251 #ifndef QT_NO_IMAGE_TEXT
252 QImageDataMisc
& misc() const;
254 #ifndef QT_NO_IMAGEIO
255 bool doImageIO( QImageIO
* io
, int quality
) const;
257 friend Q_EXPORT
void bitBlt( QImage
* dst
, int dx
, int dy
,
258 const QImage
* src
, int sx
, int sy
,
259 int sw
, int sh
, int conversion_flags
);
263 // QImage stream functions
265 #if !defined(QT_NO_DATASTREAM) && !defined(QT_NO_IMAGEIO)
266 Q_EXPORT QDataStream
&operator<<( QDataStream
&, const QImage
& );
267 Q_EXPORT QDataStream
&operator>>( QDataStream
&, QImage
& );
270 #ifndef QT_NO_IMAGEIO
272 typedef void (*image_io_handler
)( QImageIO
* ); // image IO handler
278 class Q_EXPORT QImageIO
282 QImageIO( QIODevice
*ioDevice
, const char *format
);
283 QImageIO( const QString
&fileName
, const char* format
);
287 const QImage
&image() const { return im
; }
288 int status() const { return iostat
; }
289 const char *format() const { return frmt
; }
290 QIODevice
*ioDevice() const { return iodev
; }
291 QString
fileName() const { return fname
; }
293 QString
description() const { return descr
; }
294 const char *parameters() const;
297 void setImage( const QImage
& );
298 void setStatus( int );
299 void setFormat( const char * );
300 void setIODevice( QIODevice
* );
301 void setFileName( const QString
& );
302 void setQuality( int );
303 void setDescription( const QString
& );
304 void setParameters( const char * );
305 void setGamma( float );
310 static const char* imageFormat( const QString
&fileName
);
311 static const char *imageFormat( QIODevice
* );
312 static QStrList
inputFormats();
313 static QStrList
outputFormats();
315 static void defineIOHandler( const char *format
,
318 image_io_handler read_image
,
319 image_io_handler write_image
);
325 int iostat
; // IO status
326 QCString frmt
; // image format
327 QIODevice
*iodev
; // IO device
328 QString fname
; // file name
329 char *params
; // image parameters //### change to QImageIOData *d in 3.0
330 QString descr
; // image description
333 private: // Disabled copy constructor and operator=
334 #if defined(Q_DISABLE_COPY)
335 QImageIO( const QImageIO
& );
336 QImageIO
&operator=( const QImageIO
& );
340 #endif //QT_NO_IMAGEIO
342 Q_EXPORT
void bitBlt( QImage
* dst
, int dx
, int dy
, const QImage
* src
,
343 int sx
=0, int sy
=0, int sw
=-1, int sh
=-1,
344 int conversion_flags
=0 );
347 /*****************************************************************************
348 QImage member functions
349 *****************************************************************************/
351 inline bool QImage::hasAlphaBuffer() const
356 inline uchar
*QImage::bits() const
358 return data
->bits
? data
->bits
[0] : 0;
361 inline uchar
**QImage::jumpTable() const
366 inline QRgb
*QImage::colorTable() const
371 inline int QImage::numBytes() const
376 inline int QImage::bytesPerLine() const
378 return data
->h
? data
->nbytes
/data
->h
: 0;
381 inline QImage
QImage::copy(const QRect
& r
) const
383 return copy(r
.x(), r
.y(), r
.width(), r
.height());
386 inline QRgb
QImage::color( int i
) const
388 #if defined(QT_CHECK_RANGE)
389 if ( i
>= data
->ncols
)
390 warningIndexRange( "color", i
);
392 return data
->ctbl
? data
->ctbl
[i
] : (QRgb
)-1;
395 inline void QImage::setColor( int i
, QRgb c
)
397 #if defined(QT_CHECK_RANGE)
398 if ( i
>= data
->ncols
)
399 warningIndexRange( "setColor", i
);
405 inline uchar
*QImage::scanLine( int i
) const
407 #if defined(QT_CHECK_RANGE)
409 warningIndexRange( "scanLine", i
);
411 return data
->bits
? data
->bits
[i
] : 0;
414 inline int QImage::dotsPerMeterX() const
419 inline int QImage::dotsPerMeterY() const
424 inline QPoint
QImage::offset() const