source: trunk/include/qpixmap.h@ 7

Last change on this file since 7 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 10.3 KB
Line 
1/****************************************************************************
2** $Id: qpixmap.h 2 2005-11-16 15:49:26Z dmik $
3**
4** Definition of QPixmap class
5**
6** Created : 940501
7**
8** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QPIXMAP_H
39#define QPIXMAP_H
40
41#ifndef QT_H
42#include "qpaintdevice.h"
43#include "qcolor.h" // char*->QColor conversion
44#include "qstring.h" // char*->QString conversion
45#include "qnamespace.h"
46#endif // QT_H
47
48class QGfx;
49class QPixmapPrivate;
50
51#if defined(Q_WS_WIN)
52// Internal pixmap memory optimization class for Windows 9x
53class QMultiCellPixmap;
54#endif
55
56
57class Q_EXPORT QPixmap : public QPaintDevice, public Qt
58{
59public:
60 enum ColorMode { Auto, Color, Mono };
61 enum Optimization { DefaultOptim, NoOptim, MemoryOptim=NoOptim,
62 NormalOptim, BestOptim };
63
64 QPixmap();
65 QPixmap( const QImage& image );
66 QPixmap( int w, int h, int depth = -1, Optimization = DefaultOptim );
67 QPixmap( const QSize &, int depth = -1, Optimization = DefaultOptim );
68#ifndef QT_NO_IMAGEIO
69 QPixmap( const QString& fileName, const char *format=0,
70 ColorMode mode=Auto );
71 QPixmap( const QString& fileName, const char *format,
72 int conversion_flags );
73 QPixmap( const char *xpm[] ); // ### in 4.0, 'const char * const xpm[]'?
74 QPixmap( const QByteArray &data );
75#endif
76 QPixmap( const QPixmap & );
77 ~QPixmap();
78
79 QPixmap &operator=( const QPixmap & );
80 QPixmap &operator=( const QImage & );
81
82 bool isNull() const;
83
84 int width() const { return data->w; }
85 int height() const { return data->h; }
86 QSize size() const { return QSize(data->w,data->h); }
87 QRect rect() const { return QRect(0,0,data->w,data->h); }
88 int depth() const { return data->d; }
89 static int defaultDepth();
90
91 void fill( const QColor &fillColor = Qt::white );
92 void fill( const QWidget *, int xofs, int yofs );
93 void fill( const QWidget *, const QPoint &ofs );
94 void resize( int width, int height );
95 void resize( const QSize & );
96
97 const QBitmap *mask() const;
98 void setMask( const QBitmap & );
99 bool selfMask() const;
100 bool hasAlpha() const;
101 bool hasAlphaChannel() const;
102#ifndef QT_NO_IMAGE_HEURISTIC_MASK
103 QBitmap createHeuristicMask( bool clipTight = TRUE ) const;
104#endif
105#ifndef QT_NO_MIME
106 static QPixmap fromMimeSource( const QString& abs_name );
107#endif
108 static QPixmap grabWindow( WId, int x=0, int y=0, int w=-1, int h=-1 );
109 static QPixmap grabWidget( QWidget * widget,
110 int x=0, int y=0, int w=-1, int h=-1 );
111
112#ifndef QT_NO_PIXMAP_TRANSFORMATION
113 QPixmap xForm( const QWMatrix & ) const;
114 static QWMatrix trueMatrix( const QWMatrix &, int w, int h );
115#endif
116
117 QImage convertToImage() const;
118 bool convertFromImage( const QImage &, ColorMode mode=Auto );
119 bool convertFromImage( const QImage &, int conversion_flags );
120#ifndef QT_NO_IMAGEIO
121 static const char* imageFormat( const QString &fileName );
122 bool load( const QString& fileName, const char *format=0,
123 ColorMode mode=Auto );
124 bool load( const QString& fileName, const char *format,
125 int conversion_flags );
126 bool loadFromData( const uchar *buf, uint len,
127 const char* format=0,
128 ColorMode mode=Auto );
129 bool loadFromData( const uchar *buf, uint len,
130 const char* format,
131 int conversion_flags );
132 bool loadFromData( const QByteArray &data,
133 const char* format=0,
134 int conversion_flags=0 );
135 bool save( const QString& fileName, const char* format, int quality = -1 ) const;
136 bool save( QIODevice* device, const char* format, int quality = -1 ) const;
137#endif
138
139#if defined(Q_WS_WIN)
140 HBITMAP hbm() const;
141#endif
142
143 int serialNumber() const;
144
145 Optimization optimization() const;
146 void setOptimization( Optimization );
147 static Optimization defaultOptimization();
148 static void setDefaultOptimization( Optimization );
149
150 virtual void detach();
151
152 bool isQBitmap() const;
153
154#if defined(Q_WS_WIN)
155 // These functions are internal and used by Windows 9x only
156 bool isMultiCellPixmap() const;
157 HDC multiCellHandle() const;
158 HBITMAP multiCellBitmap() const;
159 int multiCellOffset() const;
160 int allocCell();
161 void freeCell( bool = FALSE );
162#endif
163
164#if defined(Q_WS_QWS)
165 virtual QGfx * graphicsContext(bool clip_children=TRUE) const;
166 virtual unsigned char * scanLine(int) const;
167 virtual int bytesPerLine() const;
168 QRgb * clut() const;
169 int numCols() const;
170#elif defined(Q_WS_X11)
171 static int x11SetDefaultScreen( int screen );
172 void x11SetScreen( int screen );
173#endif
174
175#ifndef Q_QDOC
176 Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
177#endif
178
179protected:
180 QPixmap( int w, int h, const uchar *data, bool isXbitmap );
181 int metric( int ) const;
182
183#if defined(Q_WS_WIN)
184 struct QMCPI { // mem optim for win9x
185 QMultiCellPixmap *mcp;
186 int offset;
187 };
188#endif
189
190 struct QPixmapData : public QShared { // internal pixmap data
191 QCOORD w, h;
192 short d;
193 uint uninit : 1;
194 uint bitmap : 1;
195 uint selfmask : 1;
196#if defined(Q_WS_WIN)
197 uint mcp : 1;
198#endif
199 int ser_no;
200 QBitmap *mask;
201#if defined(Q_WS_WIN)
202 QPixmap *maskpm;
203 union {
204 HBITMAP hbm; // if mcp == FALSE
205 QMCPI *mcpi; // if mcp == TRUE
206 } hbm_or_mcpi;
207 uchar *realAlphaBits;
208#ifdef Q_OS_TEMP
209 uchar* ppvBits; // Pointer to DIBSection bits
210#endif
211#elif defined(Q_WS_X11)
212 void *ximage;
213 void *maskgc;
214 QPixmap *alphapm;
215#elif defined(Q_WS_MAC)
216 ColorTable *clut;
217 QPixmap *alphapm;
218#elif defined(Q_WS_QWS)
219 int id; // ### should use QPaintDevice::hd, since it is there
220 QRgb * clut;
221 int numcols;
222 int rw;
223 int rh;
224 bool hasAlpha;
225#endif
226 Optimization optim;
227#if defined(Q_WS_WIN)
228 HBITMAP old_hbm;
229#endif
230 } *data;
231private:
232#ifndef QT_NO_IMAGEIO
233 bool doImageIO( QImageIO* io, int quality ) const;
234#endif
235 QPixmap( int w, int h, int depth, bool, Optimization );
236 void init( int, int, int, bool, Optimization );
237 void deref();
238 QPixmap copy( bool ignoreMask = FALSE ) const;
239#if defined(Q_WS_WIN)
240 void initAlphaPixmap( uchar *bytes, int length, struct tagBITMAPINFO *bmi );
241 void convertToAlphaPixmap( bool initAlpha=TRUE );
242 static void bitBltAlphaPixmap( QPixmap *dst, int dx, int dy,
243 const QPixmap *src, int sx, int sy,
244 int sw, int sh, bool useDstAlpha );
245#endif
246 static Optimization defOptim;
247 friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
248 const QPaintDevice *,
249 int, int, int, int, RasterOp, bool );
250 friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
251 const QImage* src,
252 int, int, int, int, int conversion_flags );
253 friend Q_EXPORT void copyBlt( QPixmap *dst, int dx, int dy,
254 const QPixmap *src, int sx, int sy,
255 int sw, int sh );
256
257#if defined(Q_WS_MAC)
258 friend void unclippedScaledBitBlt(QPaintDevice *, int, int, int, int,
259 const QPaintDevice *, int, int, int, int,
260 Qt::RasterOp, bool, bool);
261#endif
262
263 friend class QBitmap;
264 friend class QPaintDevice;
265 friend class QPainter;
266 friend class QGLWidget;
267};
268
269
270inline bool QPixmap::isNull() const
271{
272 return data->w == 0;
273}
274
275inline void QPixmap::fill( const QWidget *w, const QPoint &ofs )
276{
277 fill( w, ofs.x(), ofs.y() );
278}
279
280inline void QPixmap::resize( const QSize &s )
281{
282 resize( s.width(), s.height() );
283}
284
285inline const QBitmap *QPixmap::mask() const
286{
287 return data->mask;
288}
289
290inline bool QPixmap::selfMask() const
291{
292 return data->selfmask;
293}
294
295#if defined(Q_WS_WIN)
296inline HBITMAP QPixmap::hbm() const
297{
298 return data->mcp ? 0 : data->hbm_or_mcpi.hbm;
299}
300#endif
301
302inline int QPixmap::serialNumber() const
303{
304 return data->ser_no;
305}
306
307inline QPixmap::Optimization QPixmap::optimization() const
308{
309 return data->optim;
310}
311
312inline bool QPixmap::isQBitmap() const
313{
314 return data->bitmap;
315}
316
317#if defined(Q_WS_WIN)
318inline bool QPixmap::isMultiCellPixmap() const
319{
320 return data->mcp;
321}
322#endif
323
324
325/*****************************************************************************
326 QPixmap stream functions
327 *****************************************************************************/
328
329#if !defined(QT_NO_DATASTREAM) && !defined(QT_NO_IMAGEIO)
330Q_EXPORT QDataStream &operator<<( QDataStream &, const QPixmap & );
331Q_EXPORT QDataStream &operator>>( QDataStream &, QPixmap & );
332#endif
333
334/*****************************************************************************
335 QPixmap (and QImage) helper functions
336 *****************************************************************************/
337
338#ifndef QT_NO_PIXMAP_TRANSFORMATION
339# define QT_XFORM_TYPE_MSBFIRST 0
340# define QT_XFORM_TYPE_LSBFIRST 1
341# if defined(Q_WS_WIN)
342# define QT_XFORM_TYPE_WINDOWSPIXMAP 2
343# endif
344bool qt_xForm_helper( const QWMatrix&, int, int, int, uchar*, int, int, int, uchar*, int, int, int );
345#endif
346
347Q_EXPORT void copyBlt( QPixmap *dst, int dx, int dy,
348 const QPixmap *src, int sx = 0, int sy = 0,
349 int sw = -1, int sh = -1 );
350
351#endif // QPIXMAP_H
Note: See TracBrowser for help on using the repository browser.