source: trunk/include/qpixmap.h@ 203

Last change on this file since 203 was 59, checked in by dmik, 20 years ago

Implemented alpha blending for pixmaps.
Improved blitting of masked pixmaps.

  • Property svn:keywords set to Id
File size: 11.1 KB
Line 
1/****************************************************************************
2** $Id: qpixmap.h 59 2006-01-29 19:56:21Z 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#elif defined(Q_WS_PM)
142 HBITMAP hbm() const;
143#endif
144
145 int serialNumber() const;
146
147 Optimization optimization() const;
148 void setOptimization( Optimization );
149 static Optimization defaultOptimization();
150 static void setDefaultOptimization( Optimization );
151
152 virtual void detach();
153
154 bool isQBitmap() const;
155
156#if defined(Q_WS_WIN)
157 // These functions are internal and used by Windows 9x only
158 bool isMultiCellPixmap() const;
159 HDC multiCellHandle() const;
160 HBITMAP multiCellBitmap() const;
161 int multiCellOffset() const;
162 int allocCell();
163 void freeCell( bool = FALSE );
164#elif defined(Q_WS_PM)
165 static HPOINTER createIcon( bool pointer, int hotX, int hotY,
166 const QPixmap *normal, const QPixmap *mini );
167#endif
168
169#if defined(Q_WS_QWS)
170 virtual QGfx * graphicsContext(bool clip_children=TRUE) const;
171 virtual unsigned char * scanLine(int) const;
172 virtual int bytesPerLine() const;
173 QRgb * clut() const;
174 int numCols() const;
175#elif defined(Q_WS_X11)
176 static int x11SetDefaultScreen( int screen );
177 void x11SetScreen( int screen );
178#endif
179
180#ifndef Q_QDOC
181 Q_DUMMY_COMPARISON_OPERATOR(QPixmap)
182#endif
183
184protected:
185 QPixmap( int w, int h, const uchar *data, bool isXbitmap );
186 int metric( int ) const;
187
188#if defined(Q_WS_WIN)
189 struct QMCPI { // mem optim for win9x
190 QMultiCellPixmap *mcp;
191 int offset;
192 };
193#endif
194
195 struct QPixmapData : public QShared { // internal pixmap data
196 QCOORD w, h;
197 short d;
198 uint uninit : 1;
199 uint bitmap : 1;
200 uint selfmask : 1;
201#if defined(Q_WS_WIN)
202 uint mcp : 1;
203#endif
204 int ser_no;
205 QBitmap *mask;
206#if defined(Q_WS_WIN)
207 QPixmap *maskpm;
208 union {
209 HBITMAP hbm; // if mcp == FALSE
210 QMCPI *mcpi; // if mcp == TRUE
211 } hbm_or_mcpi;
212 uchar *realAlphaBits;
213#ifdef Q_OS_TEMP
214 uchar* ppvBits; // Pointer to DIBSection bits
215#endif
216#elif defined(Q_WS_PM)
217 HBITMAP hbm;
218 HBITMAP maskedHbm; // pixmap precomposed for masking
219 bool hasRealAlpha;
220 uchar *realAlphaBits;
221#elif defined(Q_WS_X11)
222 void *ximage;
223 void *maskgc;
224 QPixmap *alphapm;
225#elif defined(Q_WS_MAC)
226 ColorTable *clut;
227 QPixmap *alphapm;
228#elif defined(Q_WS_QWS)
229 int id; // ### should use QPaintDevice::hd, since it is there
230 QRgb * clut;
231 int numcols;
232 int rw;
233 int rh;
234 bool hasAlpha;
235#endif
236 Optimization optim;
237#if defined(Q_WS_WIN)
238 HBITMAP old_hbm;
239#endif
240 } *data;
241private:
242#ifndef QT_NO_IMAGEIO
243 bool doImageIO( QImageIO* io, int quality ) const;
244#endif
245 QPixmap( int w, int h, int depth, bool, Optimization );
246 void init( int, int, int, bool, Optimization );
247 void deref();
248 QPixmap copy( bool ignoreMask = FALSE ) const;
249#if defined(Q_WS_WIN)
250 void initAlphaPixmap( uchar *bytes, int length, struct tagBITMAPINFO *bmi );
251 void convertToAlphaPixmap( bool initAlpha=TRUE );
252 static void bitBltAlphaPixmap( QPixmap *dst, int dx, int dy,
253 const QPixmap *src, int sx, int sy,
254 int sw, int sh, bool useDstAlpha );
255#elif defined(Q_WS_PM)
256 void prepareForMasking( bool prepare, bool force = FALSE );
257 HPOINTER createIcon( bool pointer, int hotX, int hotY, bool mini );
258 void attachHandle( HBITMAP hbm );
259 HBITMAP detachHandle();
260 void unfoldAlphaChannel();
261 void convertToAlpha();
262 static int trueColorDepth();
263 friend class QPMMimeImage;
264#endif
265 static Optimization defOptim;
266 friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
267 const QPaintDevice *,
268 int, int, int, int, RasterOp, bool );
269 friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
270 const QImage* src,
271 int, int, int, int, int conversion_flags );
272 friend Q_EXPORT void copyBlt( QPixmap *dst, int dx, int dy,
273 const QPixmap *src, int sx, int sy,
274 int sw, int sh );
275
276#if defined(Q_WS_MAC)
277 friend void unclippedScaledBitBlt(QPaintDevice *, int, int, int, int,
278 const QPaintDevice *, int, int, int, int,
279 Qt::RasterOp, bool, bool);
280#endif
281
282 friend class QBitmap;
283 friend class QPaintDevice;
284 friend class QPainter;
285 friend class QGLWidget;
286};
287
288
289inline bool QPixmap::isNull() const
290{
291 return data->w == 0;
292}
293
294inline void QPixmap::fill( const QWidget *w, const QPoint &ofs )
295{
296 fill( w, ofs.x(), ofs.y() );
297}
298
299inline void QPixmap::resize( const QSize &s )
300{
301 resize( s.width(), s.height() );
302}
303
304inline const QBitmap *QPixmap::mask() const
305{
306 return data->mask;
307}
308
309inline bool QPixmap::selfMask() const
310{
311 return data->selfmask;
312}
313
314#if defined(Q_WS_WIN)
315inline HBITMAP QPixmap::hbm() const
316{
317 return data->mcp ? 0 : data->hbm_or_mcpi.hbm;
318}
319#elif defined(Q_WS_PM)
320inline HBITMAP QPixmap::hbm() const
321{
322 return data->hbm;
323}
324#endif
325
326inline int QPixmap::serialNumber() const
327{
328 return data->ser_no;
329}
330
331inline QPixmap::Optimization QPixmap::optimization() const
332{
333 return data->optim;
334}
335
336inline bool QPixmap::isQBitmap() const
337{
338 return data->bitmap;
339}
340
341#if defined(Q_WS_WIN)
342inline bool QPixmap::isMultiCellPixmap() const
343{
344 return data->mcp;
345}
346#endif
347
348
349/*****************************************************************************
350 QPixmap stream functions
351 *****************************************************************************/
352
353#if !defined(QT_NO_DATASTREAM) && !defined(QT_NO_IMAGEIO)
354Q_EXPORT QDataStream &operator<<( QDataStream &, const QPixmap & );
355Q_EXPORT QDataStream &operator>>( QDataStream &, QPixmap & );
356#endif
357
358/*****************************************************************************
359 QPixmap (and QImage) helper functions
360 *****************************************************************************/
361
362#ifndef QT_NO_PIXMAP_TRANSFORMATION
363# define QT_XFORM_TYPE_MSBFIRST 0
364# define QT_XFORM_TYPE_LSBFIRST 1
365# if defined(Q_WS_WIN)
366# define QT_XFORM_TYPE_WINDOWSPIXMAP 2
367# endif
368bool qt_xForm_helper( const QWMatrix&, int, int, int, uchar*, int, int, int, uchar*, int, int, int );
369#endif
370
371Q_EXPORT void copyBlt( QPixmap *dst, int dx, int dy,
372 const QPixmap *src, int sx = 0, int sy = 0,
373 int sw = -1, int sh = -1 );
374
375#endif // QPIXMAP_H
Note: See TracBrowser for help on using the repository browser.