source: trunk/include/qpixmap.h@ 35

Last change on this file since 35 was 8, checked in by dmik, 20 years ago

Transferred Qt for OS/2 version 3.3.1-rc5 sources from the CVS

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