~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksplash/ksplashx/qimage.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
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
 
5
** notice below).
 
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.
 
10
**
 
11
** The original Qt license header follows:
 
12
** 
 
13
**
 
14
** Definition of QImage and QImageIO classes
 
15
**
 
16
** Created : 950207
 
17
**
 
18
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
 
19
**
 
20
** This file is part of the kernel module of the Qt GUI Toolkit.
 
21
**
 
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.
 
25
**
 
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.
 
30
**
 
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.
 
34
**
 
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.
 
37
**
 
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.
 
42
**
 
43
** Contact info@trolltech.com if any conditions of this licensing are
 
44
** not clear to you.
 
45
**
 
46
**********************************************************************/
 
47
 
 
48
#ifndef QIMAGE_H
 
49
#define QIMAGE_H
 
50
 
 
51
#include "qrect.h"
 
52
#include "qshared.h"
 
53
 
 
54
class QImageDataMisc; // internal
 
55
class QPixmap;
 
56
#ifndef QT_NO_IMAGE_TEXT
 
57
class Q_EXPORT QImageTextKeyLang {
 
58
public:
 
59
    QImageTextKeyLang(const char* k, const char* l) : key(k), lang(l) { }
 
60
    QImageTextKeyLang() { }
 
61
 
 
62
    QCString key;
 
63
    QCString lang;
 
64
 
 
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; }
 
69
};
 
70
#endif //QT_NO_IMAGE_TEXT
 
71
 
 
72
 
 
73
class Q_EXPORT QImage
 
74
{
 
75
public:
 
76
    enum Endian { IgnoreEndian, BigEndian, LittleEndian };
 
77
 
 
78
    QImage();
 
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 );
 
83
#ifndef QT_NO_IMAGEIO
 
84
    explicit QImage( const QString &fileName, const char* format=0 );
 
85
    explicit QImage( const char * const xpm[] );
 
86
    explicit QImage( const QByteArray &data );
 
87
#endif
 
88
    QImage( uchar* data, int w, int h, int depth,
 
89
                QRgb* colortable, int numColors,
 
90
                Endian bitOrder );
 
91
#ifdef Q_WS_QWS
 
92
    QImage( uchar* data, int w, int h, int depth, int pbl,
 
93
                QRgb* colortable, int numColors,
 
94
                Endian bitOrder );
 
95
#endif
 
96
    QImage( const QImage & );
 
97
   ~QImage();
 
98
 
 
99
    QImage     &operator=( const QImage & );
 
100
    QImage     &operator=( const QPixmap & );
 
101
    bool        operator==( const QImage & ) const;
 
102
    bool        operator!=( const QImage & ) const;
 
103
    void        detach();
 
104
    QImage      copy()          const;
 
105
    QImage      copy(int x, int y, int w, int h, int conversion_flags=0) const;
 
106
    QImage      copy(const QRect&)      const;
 
107
#ifndef QT_NO_MIME
 
108
    static QImage fromMimeSource( const QString& abs_name );
 
109
#endif
 
110
    bool        isNull()        const   { return data->bits == 0; }
 
111
 
 
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; }
 
119
 
 
120
    QRgb        color( int i )  const;
 
121
    void        setColor( int i, QRgb c );
 
122
    void        setNumColors( int );
 
123
 
 
124
    bool        hasAlphaBuffer() const;
 
125
    void        setAlphaBuffer( bool );
 
126
 
 
127
    bool        allGray() const;
 
128
    bool        isGrayscale() const;
 
129
 
 
130
    uchar      *bits()          const;
 
131
    uchar      *scanLine( int ) const;
 
132
    uchar     **jumpTable()     const;
 
133
    QRgb       *colorTable()    const;
 
134
    int         numBytes()      const;
 
135
    int         bytesPerLine()  const;
 
136
 
 
137
#ifdef Q_WS_QWS
 
138
    QGfx * graphicsContext();
 
139
#endif
 
140
 
 
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 );
 
145
    void        reset();
 
146
 
 
147
    void        fill( uint pixel );
 
148
    void        invertPixels( bool invertAlpha = true );
 
149
 
 
150
    QImage      convertDepth( int ) const;
 
151
#ifndef QT_NO_IMAGE_TRUECOLOR
 
152
    QImage      convertDepthWithPalette( int, QRgb* p, int pc, int cf=0 ) const;
 
153
#endif
 
154
    QImage      convertDepth( int, int conversion_flags ) const;
 
155
    QImage      convertBitOrder( Endian ) const;
 
156
 
 
157
    enum ScaleMode {
 
158
        ScaleFree,
 
159
        ScaleMin,
 
160
        ScaleMax
 
161
    };
 
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;
 
165
#endif
 
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;
 
172
#endif
 
173
 
 
174
#ifndef QT_NO_IMAGE_DITHER_TO_1
 
175
    QImage      createAlphaMask( int conversion_flags=0 ) const;
 
176
#endif
 
177
#ifndef QT_NO_IMAGE_HEURISTIC_MASK
 
178
    QImage      createHeuristicMask( bool clipTight=true ) const;
 
179
#endif
 
180
#ifndef QT_NO_IMAGE_MIRROR
 
181
    QImage      mirror() const;
 
182
    QImage      mirror(bool horizontally, bool vertically) const;
 
183
#endif
 
184
    QImage      swapRGB() const;
 
185
 
 
186
    static Endian systemBitOrder();
 
187
    static Endian systemByteOrder();
 
188
 
 
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();
 
196
#endif
 
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
 
206
 
 
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 );
 
211
 
 
212
    // Auxiliary data
 
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&);
 
226
#endif
 
227
private:
 
228
    void        init();
 
229
    void        reinit();
 
230
    void        freeBits();
 
231
    static void warningIndexRange( const char *, int );
 
232
 
 
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
 
248
#endif
 
249
        bool    ctbl_mine;                      // this allocated ctbl
 
250
    } *data;
 
251
#ifndef QT_NO_IMAGE_TEXT
 
252
    QImageDataMisc& misc() const;
 
253
#endif
 
254
#ifndef QT_NO_IMAGEIO
 
255
    bool doImageIO( QImageIO* io, int quality ) const;
 
256
#endif
 
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 );
 
260
};
 
261
 
 
262
 
 
263
// QImage stream functions
 
264
 
 
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 & );
 
268
#endif
 
269
 
 
270
#ifndef QT_NO_IMAGEIO
 
271
class QIODevice;
 
272
typedef void (*image_io_handler)( QImageIO * ); // image IO handler
 
273
 
 
274
 
 
275
struct QImageIOData;
 
276
 
 
277
 
 
278
class Q_EXPORT QImageIO
 
279
{
 
280
public:
 
281
    QImageIO();
 
282
    QImageIO( QIODevice  *ioDevice, const char *format );
 
283
    QImageIO( const QString &fileName, const char* format );
 
284
   ~QImageIO();
 
285
 
 
286
 
 
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; }
 
292
    int         quality()       const;
 
293
    QString     description()   const   { return descr; }
 
294
    const char *parameters()    const;
 
295
    float gamma() const;
 
296
 
 
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 );
 
306
 
 
307
    bool        read();
 
308
    bool        write();
 
309
 
 
310
    static const char* imageFormat( const QString &fileName );
 
311
    static const char *imageFormat( QIODevice * );
 
312
    static QStrList inputFormats();
 
313
    static QStrList outputFormats();
 
314
 
 
315
    static void defineIOHandler( const char *format,
 
316
                                 const char *header,
 
317
                                 const char *flags,
 
318
                                 image_io_handler read_image,
 
319
                                 image_io_handler write_image );
 
320
 
 
321
private:
 
322
    void        init();
 
323
 
 
324
    QImage      im;                             // 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
 
331
    QImageIOData *d;
 
332
 
 
333
private:        // Disabled copy constructor and operator=
 
334
#if defined(Q_DISABLE_COPY)
 
335
    QImageIO( const QImageIO & );
 
336
    QImageIO &operator=( const QImageIO & );
 
337
#endif
 
338
};
 
339
 
 
340
#endif //QT_NO_IMAGEIO
 
341
 
 
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 );
 
345
 
 
346
 
 
347
/*****************************************************************************
 
348
  QImage member functions
 
349
 *****************************************************************************/
 
350
 
 
351
inline bool QImage::hasAlphaBuffer() const
 
352
{
 
353
    return data->alpha;
 
354
}
 
355
 
 
356
inline uchar *QImage::bits() const
 
357
{
 
358
    return data->bits ? data->bits[0] : 0;
 
359
}
 
360
 
 
361
inline uchar **QImage::jumpTable() const
 
362
{
 
363
    return data->bits;
 
364
}
 
365
 
 
366
inline QRgb *QImage::colorTable() const
 
367
{
 
368
    return data->ctbl;
 
369
}
 
370
 
 
371
inline int QImage::numBytes() const
 
372
{
 
373
    return data->nbytes;
 
374
}
 
375
 
 
376
inline int QImage::bytesPerLine() const
 
377
{
 
378
    return data->h ? data->nbytes/data->h : 0;
 
379
}
 
380
 
 
381
inline QImage QImage::copy(const QRect& r) const
 
382
{
 
383
    return copy(r.x(), r.y(), r.width(), r.height());
 
384
}
 
385
 
 
386
inline QRgb QImage::color( int i ) const
 
387
{
 
388
#if defined(QT_CHECK_RANGE)
 
389
    if ( i >= data->ncols )
 
390
        warningIndexRange( "color", i );
 
391
#endif
 
392
    return data->ctbl ? data->ctbl[i] : (QRgb)-1;
 
393
}
 
394
 
 
395
inline void QImage::setColor( int i, QRgb c )
 
396
{
 
397
#if defined(QT_CHECK_RANGE)
 
398
    if ( i >= data->ncols )
 
399
        warningIndexRange( "setColor", i );
 
400
#endif
 
401
    if ( data->ctbl )
 
402
        data->ctbl[i] = c;
 
403
}
 
404
 
 
405
inline uchar *QImage::scanLine( int i ) const
 
406
{
 
407
#if defined(QT_CHECK_RANGE)
 
408
    if ( i >= data->h )
 
409
        warningIndexRange( "scanLine", i );
 
410
#endif
 
411
    return data->bits ? data->bits[i] : 0;
 
412
}
 
413
 
 
414
inline int QImage::dotsPerMeterX() const
 
415
{
 
416
    return data->dpmx;
 
417
}
 
418
 
 
419
inline int QImage::dotsPerMeterY() const
 
420
{
 
421
    return data->dpmy;
 
422
}
 
423
 
 
424
inline QPoint QImage::offset() const
 
425
{
 
426
    return data->offset;
 
427
}
 
428
 
 
429
 
 
430
#endif // QIMAGE_H