Qt 4.8
Public Functions | Static Public Functions | Public Variables | Protected Functions | Private Types | Private Functions | Static Private Functions | Properties | Friends | List of all members
QX11PixmapData Class Reference

#include <qpixmap_x11_p.h>

Inheritance diagram for QX11PixmapData:
QPixmapData QX11GLPixmapData

Public Functions

QPixmap alphaChannel () const
 
void convertToARGB32 (bool preserveContents=true)
 
void copy (const QPixmapData *data, const QRect &rect)
 
QPixmapDatacreateCompatiblePixmapData () const
 
void fill (const QColor &color)
 
void fromImage (const QImage &image, Qt::ImageConversionFlags flags)
 
Qt::HANDLE handle () const
 
bool hasAlphaChannel () const
 
QBitmap mask () const
 
QPaintEnginepaintEngine () const
 
 QX11PixmapData (PixelType type)
 
void resize (int width, int height)
 
bool scroll (int dx, int dy, const QRect &rect)
 
void setAlphaChannel (const QPixmap &alphaChannel)
 
void setMask (const QBitmap &mask)
 Sets a mask bitmap. More...
 
QImage toImage () const
 Converts the pixmap to a QImage. More...
 
QImage toImage (const QRect &rect) const
 
QPixmap transformed (const QTransform &transform, Qt::TransformationMode mode) const
 Returns a copy of the pixmap that is transformed using the given transformation matrix and transformation mode. More...
 
Qt::HANDLE x11ConvertToDefaultDepth ()
 
 ~QX11PixmapData ()
 
- Public Functions inherited from QPixmapData
virtual QImagebuffer ()
 
qint64 cacheKey () const
 
ClassId classId () const
 
int colorCount () const
 
int depth () const
 
virtual bool fromData (const uchar *buffer, uint len, const char *format, Qt::ImageConversionFlags flags)
 
virtual bool fromFile (const QString &filename, const char *format, Qt::ImageConversionFlags flags)
 
virtual void fromImageReader (QImageReader *imageReader, Qt::ImageConversionFlags flags)
 
int height () const
 
bool isNull () const
 
QT_DEPRECATED int numColors () const
 
PixelType pixelType () const
 
 QPixmapData (PixelType pixelType, int classId)
 
virtual QPixmapDataruntimeData () const
 
int serialNumber () const
 
int width () const
 
virtual ~QPixmapData ()
 

Static Public Functions

static Qt::HANDLE createBitmapFromImage (const QImage &image)
 
- Static Public Functions inherited from QPixmapData
static QPixmapDatacreate (int w, int h, PixelType type)
 

Public Variables

void * gl_surface
 

Protected Functions

int metric (QPaintDevice::PaintDeviceMetric metric) const
 
- Protected Functions inherited from QPixmapData
void setSerialNumber (int serNo)
 

Private Types

enum  Flag {
  NoFlags = 0x0, Uninitialized = 0x1, Readonly = 0x2, InvertedWhenBoundToTexture = 0x4,
  GlSurfaceCreatedWithAlpha = 0x8
}
 

Private Functions

void bitmapFromImage (const QImage &image)
 
bool canTakeQImageFromXImage (const QXImageWrapper &xi) const
 
QBitmap mask_to_bitmap (int screen) const
 
void release ()
 
QImage takeQImageFromXImage (const QXImageWrapper &xi) const
 
QImage toImage (const QXImageWrapper &xi, const QRect &rect) const
 

Static Private Functions

static Qt::HANDLE bitmap_to_mask (const QBitmap &, int screen)
 

Properties

uint flags
 
Qt::HANDLE hd
 
Qt::HANDLE hd2
 
Qt::HANDLE mask_picture
 
QX11PaintEnginepengine
 
Qt::HANDLE picture
 
QPixmap::ShareMode share_mode
 
Qt::HANDLE x11_mask
 
QX11Info xinfo
 

Friends

class QBitmap
 
class QEglContext
 
class QGLContext
 
class QGLContextPrivate
 
class QMeeGoLivePixmapData
 
class QPixmap
 
class QRasterWindowSurface
 
bool qt_createEGLSurfaceForPixmap (QPixmapData *, bool)
 
class QX11GLPixmapData
 
class QX11PaintEngine
 
class QX11WindowSurface
 

Additional Inherited Members

- Public Types inherited from QPixmapData
enum  ClassId {
  RasterClass, X11Class, MacClass, DirectFBClass,
  OpenGLClass, OpenVGClass, RuntimeClass, BlitterClass,
  CustomClass = 1024
}
 
enum  PixelType { PixmapType, BitmapType }
 
- Protected Variables inherited from QPixmapData
int d
 
int h
 
bool is_null
 
int w
 

Detailed Description

Definition at line 67 of file qpixmap_x11_p.h.

Enumerations

◆ Flag

enum QX11PixmapData::Flag
private
Enumerator
NoFlags 
Uninitialized 
Readonly 
InvertedWhenBoundToTexture 
GlSurfaceCreatedWithAlpha 

Definition at line 134 of file qpixmap_x11_p.h.

Constructors and Destructors

◆ QX11PixmapData()

QX11PixmapData::QX11PixmapData ( PixelType  type)

Definition at line 316 of file qpixmap_x11.cpp.

Referenced by convertToARGB32(), createCompatiblePixmapData(), and transformed().

317  : QPixmapData(type, X11Class), gl_surface(0), hd(0),
319  share_mode(QPixmap::ImplicitlyShared), pengine(0)
320 {
321 }
Qt::HANDLE picture
QX11PaintEngine * pengine
Qt::HANDLE hd
QPixmap::ShareMode share_mode
Qt::HANDLE mask_picture
PixelType type
QPixmapData(PixelType pixelType, int classId)
Definition: qpixmapdata.cpp:68
Qt::HANDLE x11_mask
Qt::HANDLE hd2

◆ ~QX11PixmapData()

QX11PixmapData::~QX11PixmapData ( )

Definition at line 1244 of file qpixmap_x11.cpp.

Referenced by paintEngine(), and transformed().

1245 {
1246  // Cleanup hooks have to be called before the handles are freed
1247  if (is_cached) {
1249  is_cached = false;
1250  }
1251 
1252  release();
1253 }
static void executePixmapDataDestructionHooks(QPixmapData *)

Functions

◆ alphaChannel()

QPixmap QX11PixmapData::alphaChannel ( ) const
virtual

Reimplemented from QPixmapData.

Definition at line 1294 of file qpixmap_x11.cpp.

1295 {
1296  if (!hasAlphaChannel()) {
1297  QPixmap pm(w, h);
1298  pm.fill(Qt::white);
1299  return pm;
1300  }
1301  QImage im(toImage());
1302  return QPixmap::fromImage(im.alphaChannel(), Qt::OrderedDither);
1303 }
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage toImage() const
Converts the pixmap to a QImage.
bool hasAlphaChannel() const
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71

◆ bitmap_to_mask()

Qt::HANDLE QX11PixmapData::bitmap_to_mask ( const QBitmap bitmap,
int  screen 
)
staticprivate

Definition at line 129 of file qpixmap_x11.cpp.

Referenced by setMask().

130 {
131  if (bitmap.isNull())
132  return 0;
133  QBitmap bm = bitmap;
134  bm.x11SetScreen(screen);
135 
136  Pixmap mask = XCreatePixmap(X11->display, RootWindow(X11->display, screen),
137  bm.data->width(), bm.data->height(), 1);
138  GC gc = XCreateGC(X11->display, mask, 0, 0);
139  XCopyArea(X11->display, bm.handle(), mask, gc, 0, 0,
140  bm.data->width(), bm.data->height(), 0, 0);
141  XFreeGC(X11->display, gc);
142  return mask;
143 }
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
Qt::HANDLE handle() const
Returns the pixmap&#39;s handle to the device context.
Definition: qpixmap.cpp:1299
#define X11
Definition: qt_x11_p.h:724
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
QBitmap mask() const
struct _XGC * GC
Definition: qwindowdefs.h:117
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615

◆ bitmapFromImage()

void QX11PixmapData::bitmapFromImage ( const QImage image)
private

Definition at line 1194 of file qpixmap_x11.cpp.

Referenced by fromImage().

1195 {
1196  w = image.width();
1197  h = image.height();
1198  d = 1;
1199  is_null = (w <= 0 || h <= 0);
1200  hd = createBitmapFromImage(image);
1201 #ifndef QT_NO_XRENDER
1202  if (X11->use_xrender)
1203  picture = XRenderCreatePicture(X11->display, hd,
1204  XRenderFindStandardFormat(X11->display, PictStandardA1), 0, 0);
1205 #endif // QT_NO_XRENDER
1206 }
static Qt::HANDLE createBitmapFromImage(const QImage &image)
Qt::HANDLE picture
Qt::HANDLE hd
#define X11
Definition: qt_x11_p.h:724
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ canTakeQImageFromXImage()

bool QX11PixmapData::canTakeQImageFromXImage ( const QXImageWrapper xi) const
private

Definition at line 1473 of file qpixmap_x11.cpp.

Referenced by toImage().

1474 {
1475  XImage *xi = xiWrapper.xi;
1476 
1477  // ARGB32_Premultiplied
1478  if (picture && depth() == 32)
1479  return true;
1480 
1481  Visual *visual = (Visual *)xinfo.visual();
1482 
1483  // RGB32
1484  if (depth() == 24 && xi->bits_per_pixel == 32 && visual->red_mask == 0xff0000
1485  && visual->green_mask == 0xff00 && visual->blue_mask == 0xff)
1486  return true;
1487 
1488  // RGB16
1489  if (depth() == 16 && xi->bits_per_pixel == 16 && visual->red_mask == 0xf800
1490  && visual->green_mask == 0x7e0 && visual->blue_mask == 0x1f)
1491  return true;
1492 
1493  return false;
1494 }
Qt::HANDLE picture
void * visual() const
Returns the current visual.
int depth() const

◆ convertToARGB32()

void QX11PixmapData::convertToARGB32 ( bool  preserveContents = true)

Definition at line 2339 of file qpixmap_x11.cpp.

Referenced by QX11PaintEngine::begin(), QEgl::createSurface(), fill(), and QX11PaintEngine::updateBrush().

2340 {
2341  if (!X11->use_xrender)
2342  return;
2343 
2344  // Q_ASSERT(count == 1);
2345  if ((flags & Readonly) && share_mode == QPixmap::ExplicitlyShared)
2346  return;
2347 
2348  Pixmap pm = XCreatePixmap(X11->display, RootWindow(X11->display, xinfo.screen()),
2349  w, h, 32);
2350  Picture p = XRenderCreatePicture(X11->display, pm,
2351  XRenderFindStandardFormat(X11->display, PictStandardARGB32), 0, 0);
2352  if (picture) {
2353  if (preserveContents)
2354  XRenderComposite(X11->display, PictOpSrc, picture, 0, p, 0, 0, 0, 0, 0, 0, w, h);
2355  if (!(flags & Readonly))
2356  XRenderFreePicture(X11->display, picture);
2357  }
2358  if (hd && !(flags & Readonly))
2359  XFreePixmap(X11->display, hd);
2360  if (x11_mask) {
2361  XFreePixmap(X11->display, x11_mask);
2362  if (mask_picture)
2363  XRenderFreePicture(X11->display, mask_picture);
2364  x11_mask = 0;
2365  mask_picture = 0;
2366  }
2367  hd = pm;
2368  picture = p;
2369  d = 32;
2370 }
Qt::HANDLE picture
Qt::HANDLE hd
QPixmap::ShareMode share_mode
#define X11
Definition: qt_x11_p.h:724
Qt::HANDLE mask_picture
unsigned long Picture
Qt::HANDLE x11_mask
int screen() const
Returns the number of the screen currently in use.

◆ copy()

void QX11PixmapData::copy ( const QPixmapData data,
const QRect rect 
)
virtual

Reimplemented from QPixmapData.

Reimplemented in QX11GLPixmapData.

Definition at line 2266 of file qpixmap_x11.cpp.

Referenced by QX11GLPixmapData::copy().

2267 {
2268  if (data->pixelType() == BitmapType) {
2269  fromImage(data->toImage().copy(rect), Qt::AutoColor);
2270  return;
2271  }
2272 
2273  const QX11PixmapData *x11Data = static_cast<const QX11PixmapData*>(data);
2274 
2276 
2277  flags &= ~Uninitialized;
2278  xinfo = x11Data->xinfo;
2279  d = x11Data->d;
2280  w = rect.width();
2281  h = rect.height();
2282  is_null = (w <= 0 || h <= 0);
2283  hd = (Qt::HANDLE)XCreatePixmap(X11->display,
2284  RootWindow(X11->display, x11Data->xinfo.screen()),
2285  w, h, d);
2286 #ifndef QT_NO_XRENDER
2287  if (X11->use_xrender) {
2288  XRenderPictFormat *format = d == 32
2289  ? XRenderFindStandardFormat(X11->display, PictStandardARGB32)
2290  : XRenderFindVisualFormat(X11->display, (Visual *)xinfo.visual());
2291  picture = XRenderCreatePicture(X11->display, hd, format, 0, 0);
2292  }
2293 #endif // QT_NO_XRENDER
2294  if (x11Data->x11_mask) {
2295  x11_mask = XCreatePixmap(X11->display, hd, w, h, 1);
2296 #ifndef QT_NO_XRENDER
2297  if (X11->use_xrender) {
2298  mask_picture = XRenderCreatePicture(X11->display, x11_mask,
2299  XRenderFindStandardFormat(X11->display, PictStandardA1), 0, 0);
2300  XRenderPictureAttributes attrs;
2301  attrs.alpha_map = x11Data->mask_picture;
2302  XRenderChangePicture(X11->display, x11Data->picture, CPAlphaMap, &attrs);
2303  }
2304 #endif
2305  }
2306 
2307 #if !defined(QT_NO_XRENDER)
2308  if (x11Data->picture && x11Data->d == 32) {
2309  XRenderComposite(X11->display, PictOpSrc,
2310  x11Data->picture, 0, picture,
2311  rect.x(), rect.y(), 0, 0, 0, 0, w, h);
2312  } else
2313 #endif
2314  {
2315  GC gc = XCreateGC(X11->display, hd, 0, 0);
2316  XCopyArea(X11->display, x11Data->hd, hd, gc,
2317  rect.x(), rect.y(), w, h, 0, 0);
2318  if (x11Data->x11_mask) {
2319  GC monogc = XCreateGC(X11->display, x11_mask, 0, 0);
2320  XCopyArea(X11->display, x11Data->x11_mask, x11_mask, monogc,
2321  rect.x(), rect.y(), w, h, 0, 0);
2322  XFreeGC(X11->display, monogc);
2323  }
2324  XFreeGC(X11->display, gc);
2325  }
2326 }
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
Qt::HANDLE picture
Qt::HANDLE hd
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QBasicAtomicInt qt_pixmap_serial
#define X11
Definition: qt_x11_p.h:724
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
Qt::HANDLE mask_picture
PixelType pixelType() const
virtual QImage toImage() const =0
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
static const char * data(const QByteArray &arr)
void * HANDLE
Definition: qnamespace.h:1671
Qt::HANDLE x11_mask
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
int fetchAndAddRelaxed(int valueToAdd)
struct _XGC * GC
Definition: qwindowdefs.h:117
void setSerialNumber(int serNo)
int screen() const
Returns the number of the screen currently in use.

◆ createBitmapFromImage()

Qt::HANDLE QX11PixmapData::createBitmapFromImage ( const QImage image)
static

Definition at line 1153 of file qpixmap_x11.cpp.

Referenced by bitmapFromImage(), and QCursor::QCursor().

1154 {
1156  const QRgb c0 = QColor(Qt::black).rgb();
1157  const QRgb c1 = QColor(Qt::white).rgb();
1158  if (img.color(0) == c0 && img.color(1) == c1) {
1159  img.invertPixels();
1160  img.setColor(0, c1);
1161  img.setColor(1, c0);
1162  }
1163 
1164  char *bits;
1165  uchar *tmp_bits;
1166  int w = img.width();
1167  int h = img.height();
1168  int bpl = (w + 7) / 8;
1169  int ibpl = img.bytesPerLine();
1170  if (bpl != ibpl) {
1171  tmp_bits = new uchar[bpl*h];
1172  bits = (char *)tmp_bits;
1173  uchar *p, *b;
1174  int y;
1175  b = tmp_bits;
1176  p = img.scanLine(0);
1177  for (y = 0; y < h; y++) {
1178  memcpy(b, p, bpl);
1179  b += bpl;
1180  p += ibpl;
1181  }
1182  } else {
1183  bits = (char *)img.bits();
1184  tmp_bits = 0;
1185  }
1186  Qt::HANDLE hd = (Qt::HANDLE)XCreateBitmapFromData(X11->display,
1188  bits, w, h);
1189  if (tmp_bits) // Avoid purify complaint
1190  delete [] tmp_bits;
1191  return hd;
1192 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
unsigned int QRgb
Definition: qrgb.h:53
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Definition: qimage.cpp:1850
Qt::HANDLE hd
static Qt::HANDLE appRootWindow(int screen=-1)
Returns a handle for the applications root window on the given screen.
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
#define X11
Definition: qt_x11_p.h:724
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void * HANDLE
Definition: qnamespace.h:1671
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void invertPixels(InvertMode=InvertRgb)
Inverts all pixel values in the image.
Definition: qimage.cpp:2179
QRgb color(int i) const
Returns the color in the color table at index i.
Definition: qimage.cpp:1829
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ createCompatiblePixmapData()

QPixmapData * QX11PixmapData::createCompatiblePixmapData ( ) const
virtual

Reimplemented from QPixmapData.

Definition at line 323 of file qpixmap_x11.cpp.

324 {
325  return new QX11PixmapData(pixelType());
326 }
PixelType pixelType() const
QX11PixmapData(PixelType type)

◆ fill()

void QX11PixmapData::fill ( const QColor color)
virtual

Implements QPixmapData.

Reimplemented in QX11GLPixmapData.

Definition at line 1208 of file qpixmap_x11.cpp.

Referenced by QX11GLPixmapData::fill(), QX11GLSharedContexts::QX11GLSharedContexts(), and setMask().

1209 {
1210  if (fillColor.alpha() != 255) {
1211 #ifndef QT_NO_XRENDER
1212  if (X11->use_xrender) {
1213  if (!picture || d != 32)
1214  convertToARGB32(/*preserveContents = */false);
1215 
1216  ::Picture src = X11->getSolidFill(xinfo.screen(), fillColor);
1217  XRenderComposite(X11->display, PictOpSrc, src, 0, picture,
1218  0, 0, width(), height(),
1219  0, 0, width(), height());
1220  } else
1221 #endif
1222  {
1224  im.fill(PREMUL(fillColor.rgba()));
1225  release();
1227  }
1228  return;
1229  }
1230 
1231  GC gc = XCreateGC(X11->display, hd, 0, 0);
1232  if (depth() == 1) {
1233  XSetForeground(X11->display, gc, qGray(fillColor.rgb()) > 127 ? 0 : 1);
1234  } else if (X11->use_xrender && d >= 24) {
1235  XSetForeground(X11->display, gc, fillColor.rgba());
1236  } else {
1237  XSetForeground(X11->display, gc,
1238  QColormap::instance(xinfo.screen()).pixel(fillColor));
1239  }
1240  XFillRectangle(X11->display, hd, gc, 0, 0, width(), height());
1241  XFreeGC(X11->display, gc);
1242 }
static QColormap instance(int screen=-1)
Qt::HANDLE picture
Qt::HANDLE hd
int width() const
#define X11
Definition: qt_x11_p.h:724
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void convertToARGB32(bool preserveContents=true)
unsigned long Picture
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
Definition: qrgb.h:75
int depth() const
struct _XGC * GC
Definition: qwindowdefs.h:117
int height() const
int screen() const
Returns the number of the screen currently in use.

◆ fromImage()

void QX11PixmapData::fromImage ( const QImage image,
Qt::ImageConversionFlags  flags 
)
virtual

Implements QPixmapData.

Definition at line 410 of file qpixmap_x11.cpp.

Referenced by copy(), fill(), QMeeGoLivePixmapData::QMeeGoLivePixmapData(), and setAlphaChannel().

412 {
414 
415  w = img.width();
416  h = img.height();
417  d = img.depth();
418  is_null = (w <= 0 || h <= 0);
419 
420  if (is_null) {
421  w = h = 0;
422  return;
423  }
424 
425  if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) {
426  QX11InfoData* xd = xinfo.getX11Data(true);
427  xd->screen = defaultScreen;
428  xd->depth = QX11Info::appDepth(xd->screen);
429  xd->cells = QX11Info::appCells(xd->screen);
432  xd->visual = (Visual *)QX11Info::appVisual(xd->screen);
434  xinfo.setX11Data(xd);
435  }
436 
437  if (pixelType() == BitmapType) {
438  bitmapFromImage(img);
439  return;
440  }
441 
442  if (uint(w) >= 32768 || uint(h) >= 32768) {
443  w = h = 0;
444  is_null = true;
445  return;
446  }
447 
448  QX11AlphaDetector alphaCheck(&img, flags);
449  int dd = alphaCheck.hasXRenderAndAlpha() ? 32 : xinfo.depth();
450 
453 
454  QImage image = img;
455 
456  // must be monochrome
457  if (dd == 1 || (flags & Qt::ColorMode_Mask) == Qt::MonoOnly) {
458  if (d != 1) {
459  // dither
461  d = 1;
462  }
463  } else { // can be both
464  bool conv8 = false;
465  if (d > 8 && dd <= 8) { // convert to 8 bit
469  conv8 = true;
470  } else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) {
471  conv8 = (d == 1); // native depth wanted
472  } else if (d == 1) {
473  if (image.colorCount() == 2) {
474  QRgb c0 = image.color(0); // Auto: convert to best
475  QRgb c1 = image.color(1);
476  conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255);
477  } else {
478  // eg. 1-color monochrome images (they do exist).
479  conv8 = true;
480  }
481  }
482  if (conv8) {
484  d = 8;
485  }
486  }
487 
488  if (d == 1 || d == 16 || d == 24) {
490  fromImage(image, Qt::AutoColor);
491  return;
492  }
493 
494  Display *dpy = X11->display;
495  Visual *visual = (Visual *)xinfo.visual();
496  XImage *xi = 0;
497  bool trucol = (visual->c_class >= TrueColor);
498  int nbytes = image.byteCount();
499  uchar *newbits= 0;
500 
501 #ifndef QT_NO_XRENDER
502  if (alphaCheck.hasXRenderAndAlpha()) {
503  const QImage &cimage = image;
504 
505  d = 32;
506 
507  if (QX11Info::appDepth() != d) {
508  if (xinfo.x11data) {
509  xinfo.x11data->depth = d;
510  } else {
511  QX11InfoData *xd = xinfo.getX11Data(true);
512  xd->screen = QX11Info::appScreen();
513  xd->depth = d;
514  xd->cells = QX11Info::appCells();
517  xd->visual = (Visual *)QX11Info::appVisual();
519  xinfo.setX11Data(xd);
520  }
521  }
522 
523  hd = (Qt::HANDLE)XCreatePixmap(dpy, RootWindow(dpy, xinfo.screen()),
524  w, h, d);
525  picture = XRenderCreatePicture(X11->display, hd,
526  XRenderFindStandardFormat(X11->display, PictStandardARGB32), 0, 0);
527 
528  xi = XCreateImage(dpy, visual, d, ZPixmap, 0, 0, w, h, 32, 0);
529  Q_CHECK_PTR(xi);
530  newbits = (uchar *)malloc(xi->bytes_per_line*h);
531  Q_CHECK_PTR(newbits);
532  xi->data = (char *)newbits;
533 
534  switch(cimage.format()) {
536  QVector<QRgb> colorTable = cimage.colorTable();
537  uint *xidata = (uint *)xi->data;
538  for (int y = 0; y < h; ++y) {
539  const uchar *p = cimage.scanLine(y);
540  for (int x = 0; x < w; ++x) {
541  const QRgb rgb = colorTable[p[x]];
542  const int a = qAlpha(rgb);
543  if (a == 0xff)
544  *xidata = rgb;
545  else
546  // RENDER expects premultiplied alpha
547  *xidata = qRgba(qt_div_255(qRed(rgb) * a),
548  qt_div_255(qGreen(rgb) * a),
549  qt_div_255(qBlue(rgb) * a),
550  a);
551  ++xidata;
552  }
553  }
554  }
555  break;
556  case QImage::Format_RGB32: {
557  uint *xidata = (uint *)xi->data;
558  for (int y = 0; y < h; ++y) {
559  const QRgb *p = (const QRgb *) cimage.scanLine(y);
560  for (int x = 0; x < w; ++x)
561  *xidata++ = p[x] | 0xff000000;
562  }
563  }
564  break;
565  case QImage::Format_ARGB32: {
566  uint *xidata = (uint *)xi->data;
567  for (int y = 0; y < h; ++y) {
568  const QRgb *p = (const QRgb *) cimage.scanLine(y);
569  for (int x = 0; x < w; ++x) {
570  const QRgb rgb = p[x];
571  const int a = qAlpha(rgb);
572  if (a == 0xff)
573  *xidata = rgb;
574  else
575  // RENDER expects premultiplied alpha
576  *xidata = qRgba(qt_div_255(qRed(rgb) * a),
577  qt_div_255(qGreen(rgb) * a),
578  qt_div_255(qBlue(rgb) * a),
579  a);
580  ++xidata;
581  }
582  }
583 
584  }
585  break;
587  uint *xidata = (uint *)xi->data;
588  for (int y = 0; y < h; ++y) {
589  const QRgb *p = (const QRgb *) cimage.scanLine(y);
590  memcpy(xidata, p, w*sizeof(QRgb));
591  xidata += w;
592  }
593  }
594  break;
595  default:
596  Q_ASSERT(false);
597  }
598 
599  if ((xi->byte_order == MSBFirst) != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
600  uint *xidata = (uint *)xi->data;
601  uint *xiend = xidata + w*h;
602  while (xidata < xiend) {
603  *xidata = (*xidata >> 24)
604  | ((*xidata >> 8) & 0xff00)
605  | ((*xidata << 8) & 0xff0000)
606  | (*xidata << 24);
607  ++xidata;
608  }
609  }
610 
611  GC gc = XCreateGC(dpy, hd, 0, 0);
612  XPutImage(dpy, hd, gc, xi, 0, 0, 0, 0, w, h);
613  XFreeGC(dpy, gc);
614 
615  qSafeXDestroyImage(xi);
616 
617  return;
618  }
619 #endif // QT_NO_XRENDER
620 
621  if (trucol) { // truecolor display
623  image = image.convertToFormat(QImage::Format_ARGB32);
624 
625  const QImage &cimage = image;
626  QRgb pix[256]; // pixel translation table
627  const bool d8 = (d == 8);
628  const uint red_mask = (uint)visual->red_mask;
629  const uint green_mask = (uint)visual->green_mask;
630  const uint blue_mask = (uint)visual->blue_mask;
631  const int red_shift = highest_bit(red_mask) - 7;
632  const int green_shift = highest_bit(green_mask) - 7;
633  const int blue_shift = highest_bit(blue_mask) - 7;
634  const uint rbits = highest_bit(red_mask) - lowest_bit(red_mask) + 1;
635  const uint gbits = highest_bit(green_mask) - lowest_bit(green_mask) + 1;
636  const uint bbits = highest_bit(blue_mask) - lowest_bit(blue_mask) + 1;
637 
638  if (d8) { // setup pixel translation
639  QVector<QRgb> ctable = cimage.colorTable();
640  for (int i=0; i < cimage.colorCount(); i++) {
641  int r = qRed (ctable[i]);
642  int g = qGreen(ctable[i]);
643  int b = qBlue (ctable[i]);
644  r = red_shift > 0 ? r << red_shift : r >> -red_shift;
645  g = green_shift > 0 ? g << green_shift : g >> -green_shift;
646  b = blue_shift > 0 ? b << blue_shift : b >> -blue_shift;
647  pix[i] = (b & blue_mask) | (g & green_mask) | (r & red_mask)
648  | ~(blue_mask | green_mask | red_mask);
649  }
650  }
651 
652  xi = XCreateImage(dpy, visual, dd, ZPixmap, 0, 0, w, h, 32, 0);
653  Q_CHECK_PTR(xi);
654  newbits = (uchar *)malloc(xi->bytes_per_line*h);
655  Q_CHECK_PTR(newbits);
656  if (!newbits) // no memory
657  return;
658  int bppc = xi->bits_per_pixel;
659 
660  bool contig_bits = n_bits(red_mask) == rbits &&
661  n_bits(green_mask) == gbits &&
662  n_bits(blue_mask) == bbits;
663  bool dither_tc =
664  // Want it?
667  // Need it?
668  bppc < 24 && !d8 &&
669  // Can do it? (Contiguous bits?)
670  contig_bits;
671 
672  static bool init=false;
673  static int D[16][16];
674  if (dither_tc && !init) {
675  // I also contributed this code to XV - WWA.
676  /*
677  The dither matrix, D, is obtained with this formula:
678 
679  D2 = [0 2]
680  [3 1]
681 
682 
683  D2*n = [4*Dn 4*Dn+2*Un]
684  [4*Dn+3*Un 4*Dn+1*Un]
685  */
686  int n,i,j;
687  init=1;
688 
689  /* Set D2 */
690  D[0][0]=0;
691  D[1][0]=2;
692  D[0][1]=3;
693  D[1][1]=1;
694 
695  /* Expand using recursive definition given above */
696  for (n=2; n<16; n*=2) {
697  for (i=0; i<n; i++) {
698  for (j=0; j<n; j++) {
699  D[i][j]*=4;
700  D[i+n][j]=D[i][j]+2;
701  D[i][j+n]=D[i][j]+3;
702  D[i+n][j+n]=D[i][j]+1;
703  }
704  }
705  }
706  init=true;
707  }
708 
709  enum { BPP8,
710  BPP16_565, BPP16_555,
711  BPP16_MSB, BPP16_LSB,
712  BPP24_888,
713  BPP24_MSB, BPP24_LSB,
714  BPP32_8888,
715  BPP32_MSB, BPP32_LSB
716  } mode = BPP8;
717 
718  bool same_msb_lsb = (xi->byte_order == MSBFirst) == (QSysInfo::ByteOrder == QSysInfo::BigEndian);
719 
720  if(bppc == 8) // 8 bit
721  mode = BPP8;
722  else if(bppc == 16) { // 16 bit MSB/LSB
723  if(red_shift == 8 && green_shift == 3 && blue_shift == -3 && !d8 && same_msb_lsb)
724  mode = BPP16_565;
725  else if(red_shift == 7 && green_shift == 2 && blue_shift == -3 && !d8 && same_msb_lsb)
726  mode = BPP16_555;
727  else
728  mode = (xi->byte_order == LSBFirst) ? BPP16_LSB : BPP16_MSB;
729  } else if(bppc == 24) { // 24 bit MSB/LSB
730  if (red_shift == 16 && green_shift == 8 && blue_shift == 0 && !d8 && same_msb_lsb)
731  mode = BPP24_888;
732  else
733  mode = (xi->byte_order == LSBFirst) ? BPP24_LSB : BPP24_MSB;
734  } else if(bppc == 32) { // 32 bit MSB/LSB
735  if(red_shift == 16 && green_shift == 8 && blue_shift == 0 && !d8 && same_msb_lsb)
736  mode = BPP32_8888;
737  else
738  mode = (xi->byte_order == LSBFirst) ? BPP32_LSB : BPP32_MSB;
739  } else
740  qFatal("Logic error 3");
741 
742 #define GET_PIXEL \
743  uint pixel; \
744  if (d8) pixel = pix[*src++]; \
745  else { \
746  int r = qRed (*p); \
747  int g = qGreen(*p); \
748  int b = qBlue (*p++); \
749  r = red_shift > 0 \
750  ? r << red_shift : r >> -red_shift; \
751  g = green_shift > 0 \
752  ? g << green_shift : g >> -green_shift; \
753  b = blue_shift > 0 \
754  ? b << blue_shift : b >> -blue_shift; \
755  pixel = (r & red_mask)|(g & green_mask) | (b & blue_mask) \
756  | ~(blue_mask | green_mask | red_mask); \
757  }
758 
759 #define GET_PIXEL_DITHER_TC \
760  int r = qRed (*p); \
761  int g = qGreen(*p); \
762  int b = qBlue (*p++); \
763  const int thres = D[x%16][y%16]; \
764  if (r <= (255-(1<<(8-rbits))) && ((r<<rbits) & 255) \
765  > thres) \
766  r += (1<<(8-rbits)); \
767  if (g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \
768  > thres) \
769  g += (1<<(8-gbits)); \
770  if (b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \
771  > thres) \
772  b += (1<<(8-bbits)); \
773  r = red_shift > 0 \
774  ? r << red_shift : r >> -red_shift; \
775  g = green_shift > 0 \
776  ? g << green_shift : g >> -green_shift; \
777  b = blue_shift > 0 \
778  ? b << blue_shift : b >> -blue_shift; \
779  uint pixel = (r & red_mask)|(g & green_mask) | (b & blue_mask);
780 
781 // again, optimized case
782 // can't be optimized that much :(
783 #define GET_PIXEL_DITHER_TC_OPT(red_shift,green_shift,blue_shift,red_mask,green_mask,blue_mask, \
784  rbits,gbits,bbits) \
785  const int thres = D[x%16][y%16]; \
786  int r = qRed (*p); \
787  if (r <= (255-(1<<(8-rbits))) && ((r<<rbits) & 255) \
788  > thres) \
789  r += (1<<(8-rbits)); \
790  int g = qGreen(*p); \
791  if (g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \
792  > thres) \
793  g += (1<<(8-gbits)); \
794  int b = qBlue (*p++); \
795  if (b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \
796  > thres) \
797  b += (1<<(8-bbits)); \
798  uint pixel = ((r red_shift) & red_mask) \
799  | ((g green_shift) & green_mask) \
800  | ((b blue_shift) & blue_mask);
801 
802 #define CYCLE(body) \
803  for (int y=0; y<h; y++) { \
804  const uchar* src = cimage.scanLine(y); \
805  uchar* dst = newbits + xi->bytes_per_line*y; \
806  const QRgb* p = (const QRgb *)src; \
807  body \
808  }
809 
810  if (dither_tc) {
811  switch (mode) {
812  case BPP16_565:
813  CYCLE(
814  quint16* dst16 = (quint16*)dst;
815  for (int x=0; x<w; x++) {
816  GET_PIXEL_DITHER_TC_OPT(<<8,<<3,>>3,0xf800,0x7e0,0x1f,5,6,5)
817  *dst16++ = pixel;
818  }
819  )
820  break;
821  case BPP16_555:
822  CYCLE(
823  quint16* dst16 = (quint16*)dst;
824  for (int x=0; x<w; x++) {
825  GET_PIXEL_DITHER_TC_OPT(<<7,<<2,>>3,0x7c00,0x3e0,0x1f,5,5,5)
826  *dst16++ = pixel;
827  }
828  )
829  break;
830  case BPP16_MSB: // 16 bit MSB
831  CYCLE(
832  for (int x=0; x<w; x++) {
834  *dst++ = (pixel >> 8);
835  *dst++ = pixel;
836  }
837  )
838  break;
839  case BPP16_LSB: // 16 bit LSB
840  CYCLE(
841  for (int x=0; x<w; x++) {
843  *dst++ = pixel;
844  *dst++ = pixel >> 8;
845  }
846  )
847  break;
848  default:
849  qFatal("Logic error");
850  }
851  } else {
852  switch (mode) {
853  case BPP8: // 8 bit
854  CYCLE(
855  Q_UNUSED(p);
856  for (int x=0; x<w; x++)
857  *dst++ = pix[*src++];
858  )
859  break;
860  case BPP16_565:
861  CYCLE(
862  quint16* dst16 = (quint16*)dst;
863  for (int x = 0; x < w; x++) {
864  *dst16++ = ((*p >> 8) & 0xf800)
865  | ((*p >> 5) & 0x7e0)
866  | ((*p >> 3) & 0x1f);
867  ++p;
868  }
869  )
870  break;
871  case BPP16_555:
872  CYCLE(
873  quint16* dst16 = (quint16*)dst;
874  for (int x=0; x<w; x++) {
875  *dst16++ = ((*p >> 9) & 0x7c00)
876  | ((*p >> 6) & 0x3e0)
877  | ((*p >> 3) & 0x1f);
878  ++p;
879  }
880  )
881  break;
882  case BPP16_MSB: // 16 bit MSB
883  CYCLE(
884  for (int x=0; x<w; x++) {
885  GET_PIXEL
886  *dst++ = (pixel >> 8);
887  *dst++ = pixel;
888  }
889  )
890  break;
891  case BPP16_LSB: // 16 bit LSB
892  CYCLE(
893  for (int x=0; x<w; x++) {
894  GET_PIXEL
895  *dst++ = pixel;
896  *dst++ = pixel >> 8;
897  }
898  )
899  break;
900  case BPP24_888:
901  CYCLE(
902  if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
903  for (int x=0; x<w; x++) {
904  *dst++ = qRed (*p);
905  *dst++ = qGreen(*p);
906  *dst++ = qBlue (*p++);
907  }
908  } else {
909  for (int x=0; x<w; x++) {
910  *dst++ = qBlue (*p);
911  *dst++ = qGreen(*p);
912  *dst++ = qRed (*p++);
913  }
914  }
915  )
916  break;
917  case BPP24_MSB: // 24 bit MSB
918  CYCLE(
919  for (int x=0; x<w; x++) {
920  GET_PIXEL
921  *dst++ = pixel >> 16;
922  *dst++ = pixel >> 8;
923  *dst++ = pixel;
924  }
925  )
926  break;
927  case BPP24_LSB: // 24 bit LSB
928  CYCLE(
929  for (int x=0; x<w; x++) {
930  GET_PIXEL
931  *dst++ = pixel;
932  *dst++ = pixel >> 8;
933  *dst++ = pixel >> 16;
934  }
935  )
936  break;
937  case BPP32_8888:
938  CYCLE(
939  memcpy(dst, p, w * 4);
940  )
941  break;
942  case BPP32_MSB: // 32 bit MSB
943  CYCLE(
944  for (int x=0; x<w; x++) {
945  GET_PIXEL
946  *dst++ = pixel >> 24;
947  *dst++ = pixel >> 16;
948  *dst++ = pixel >> 8;
949  *dst++ = pixel;
950  }
951  )
952  break;
953  case BPP32_LSB: // 32 bit LSB
954  CYCLE(
955  for (int x=0; x<w; x++) {
956  GET_PIXEL
957  *dst++ = pixel;
958  *dst++ = pixel >> 8;
959  *dst++ = pixel >> 16;
960  *dst++ = pixel >> 24;
961  }
962  )
963  break;
964  default:
965  qFatal("Logic error 2");
966  }
967  }
968  xi->data = (char *)newbits;
969  }
970 
971  if (d == 8 && !trucol) { // 8 bit pixmap
972  int pop[256]; // pixel popularity
973 
974  if (image.colorCount() == 0)
975  image.setColorCount(1);
976 
977  const QImage &cimage = image;
978  memset(pop, 0, sizeof(int)*256); // reset popularity array
979  for (int i = 0; i < h; i++) { // for each scanline...
980  const uchar* p = cimage.scanLine(i);
981  const uchar *end = p + w;
982  while (p < end) // compute popularity
983  pop[*p++]++;
984  }
985 
986  newbits = (uchar *)malloc(nbytes); // copy image into newbits
987  Q_CHECK_PTR(newbits);
988  if (!newbits) // no memory
989  return;
990  uchar* p = newbits;
991  memcpy(p, cimage.bits(), nbytes); // copy image data into newbits
992 
993  /*
994  * The code below picks the most important colors. It is based on the
995  * diversity algorithm, implemented in XV 3.10. XV is (C) by John Bradley.
996  */
997 
998  struct PIX { // pixel sort element
999  uchar r,g,b,n; // color + pad
1000  int use; // popularity
1001  int index; // index in colormap
1002  int mindist;
1003  };
1004  int ncols = 0;
1005  for (int i=0; i< cimage.colorCount(); i++) { // compute number of colors
1006  if (pop[i] > 0)
1007  ncols++;
1008  }
1009  for (int i = cimage.colorCount(); i < 256; i++) // ignore out-of-range pixels
1010  pop[i] = 0;
1011 
1012  // works since we make sure above to have at least
1013  // one color in the image
1014  if (ncols == 0)
1015  ncols = 1;
1016 
1017  PIX pixarr[256]; // pixel array
1018  PIX pixarr_sorted[256]; // pixel array (sorted)
1019  memset(pixarr, 0, ncols*sizeof(PIX));
1020  PIX *px = &pixarr[0];
1021  int maxpop = 0;
1022  int maxpix = 0;
1023  uint j = 0;
1024  QVector<QRgb> ctable = cimage.colorTable();
1025  for (int i = 0; i < 256; i++) { // init pixel array
1026  if (pop[i] > 0) {
1027  px->r = qRed (ctable[i]);
1028  px->g = qGreen(ctable[i]);
1029  px->b = qBlue (ctable[i]);
1030  px->n = 0;
1031  px->use = pop[i];
1032  if (pop[i] > maxpop) { // select most popular entry
1033  maxpop = pop[i];
1034  maxpix = j;
1035  }
1036  px->index = i;
1037  px->mindist = 1000000;
1038  px++;
1039  j++;
1040  }
1041  }
1042  pixarr_sorted[0] = pixarr[maxpix];
1043  pixarr[maxpix].use = 0;
1044 
1045  for (int i = 1; i < ncols; i++) { // sort pixels
1046  int minpix = -1, mindist = -1;
1047  px = &pixarr_sorted[i-1];
1048  int r = px->r;
1049  int g = px->g;
1050  int b = px->b;
1051  int dist;
1052  if ((i & 1) || i<10) { // sort on max distance
1053  for (int j=0; j<ncols; j++) {
1054  px = &pixarr[j];
1055  if (px->use) {
1056  dist = (px->r - r)*(px->r - r) +
1057  (px->g - g)*(px->g - g) +
1058  (px->b - b)*(px->b - b);
1059  if (px->mindist > dist)
1060  px->mindist = dist;
1061  if (px->mindist > mindist) {
1062  mindist = px->mindist;
1063  minpix = j;
1064  }
1065  }
1066  }
1067  } else { // sort on max popularity
1068  for (int j=0; j<ncols; j++) {
1069  px = &pixarr[j];
1070  if (px->use) {
1071  dist = (px->r - r)*(px->r - r) +
1072  (px->g - g)*(px->g - g) +
1073  (px->b - b)*(px->b - b);
1074  if (px->mindist > dist)
1075  px->mindist = dist;
1076  if (px->use > mindist) {
1077  mindist = px->use;
1078  minpix = j;
1079  }
1080  }
1081  }
1082  }
1083  pixarr_sorted[i] = pixarr[minpix];
1084  pixarr[minpix].use = 0;
1085  }
1086 
1088  uint pix[256]; // pixel translation table
1089  px = &pixarr_sorted[0];
1090  for (int i = 0; i < ncols; i++) { // allocate colors
1091  QColor c(px->r, px->g, px->b);
1092  pix[px->index] = cmap.pixel(c);
1093  px++;
1094  }
1095 
1096  p = newbits;
1097  for (int i = 0; i < nbytes; i++) { // translate pixels
1098  *p = pix[*p];
1099  p++;
1100  }
1101  }
1102 
1103  if (!xi) { // X image not created
1104  xi = XCreateImage(dpy, visual, dd, ZPixmap, 0, 0, w, h, 32, 0);
1105  if (xi->bits_per_pixel == 16) { // convert 8 bpp ==> 16 bpp
1106  ushort *p2;
1107  int p2inc = xi->bytes_per_line/sizeof(ushort);
1108  ushort *newerbits = (ushort *)malloc(xi->bytes_per_line * h);
1109  Q_CHECK_PTR(newerbits);
1110  if (!newerbits) // no memory
1111  return;
1112  uchar* p = newbits;
1113  for (int y = 0; y < h; y++) { // OOPS: Do right byte order!!
1114  p2 = newerbits + p2inc*y;
1115  for (int x = 0; x < w; x++)
1116  *p2++ = *p++;
1117  }
1118  free(newbits);
1119  newbits = (uchar *)newerbits;
1120  } else if (xi->bits_per_pixel != 8) {
1121  qWarning("QPixmap::fromImage: Display not supported "
1122  "(bpp=%d)", xi->bits_per_pixel);
1123  }
1124  xi->data = (char *)newbits;
1125  }
1126 
1127  hd = (Qt::HANDLE)XCreatePixmap(X11->display,
1128  RootWindow(X11->display, xinfo.screen()),
1129  w, h, dd);
1130 
1131  GC gc = XCreateGC(dpy, hd, 0, 0);
1132  XPutImage(dpy, hd, gc, xi, 0, 0, 0, 0, w, h);
1133  XFreeGC(dpy, gc);
1134 
1135  qSafeXDestroyImage(xi);
1136  d = dd;
1137 
1138 #ifndef QT_NO_XRENDER
1139  if (X11->use_xrender) {
1140  XRenderPictFormat *format = d == 1
1141  ? XRenderFindStandardFormat(X11->display, PictStandardA1)
1142  : XRenderFindVisualFormat(X11->display, (Visual *)xinfo.visual());
1143  picture = XRenderCreatePicture(X11->display, hd, format, 0, 0);
1144  }
1145 #endif
1146 
1147  if (alphaCheck.hasAlpha()) {
1149  setMask(m);
1150  }
1151 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
int depth() const
Returns the color depth (bits per pixel) of the X display.
static QColormap instance(int screen=-1)
unsigned int QRgb
Definition: qrgb.h:53
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static int defaultScreen
static int appScreen()
Returns the number of the screen where the application is being displayed.
Qt::HANDLE picture
Qt::HANDLE hd
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Definition: qrgb.h:66
static int appDepth(int screen=-1)
Returns the color depth (bits per pixel) used by the application on the given screen.
static bool appDefaultVisual(int screen=-1)
Returns true if the application has a default visual on the given screen; otherwise returns false...
static int highest_bit(uint v)
static QColor cmap[256]
Definition: qgl_mac.mm:760
int byteCount() const
Returns the number of bytes occupied by the image data.
Definition: qimage.cpp:1800
long ASN1_INTEGER_get ASN1_INTEGER * a
static void qSafeXDestroyImage(XImage *x)
static int lowest_bit(uint v)
QBasicAtomicInt qt_pixmap_serial
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define X11
Definition: qt_x11_p.h:724
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
QX11InfoData * x11data
Definition: qx11info_x11.h:105
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
Definition: qrgb.h:57
static uint n_bits(uint v)
#define PIX(x, y)
PixelType pixelType() const
QX11InfoData * getX11Data(bool def=false) const
for(int ii=mo->methodOffset();ii< mo->methodCount();++ii)
unsigned char uchar
Definition: qglobal.h:994
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
void setColorCount(int)
Resizes the color table to contain colorCount entries.
Definition: qimage.cpp:2275
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
Definition: qrgb.h:72
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
#define D(arg)
static bool init
unsigned short quint16
Definition: qglobal.h:936
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static bool appDefaultColormap(int screen=-1)
Returns true if the application has a default color map on the given screen; otherwise returns false...
unsigned int uint
Definition: qglobal.h:996
#define CYCLE(body)
QImage createAlphaMask(Qt::ImageConversionFlags flags=Qt::AutoColor) const
Builds and returns a 1-bpp mask from the alpha buffer in this image.
Definition: qimage.cpp:4720
void * HANDLE
Definition: qnamespace.h:1671
void * visual() const
Returns the current visual.
static Qt::HANDLE appColormap(int screen=-1)
Returns a handle for the application&#39;s color map on the given screen.
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
Definition: qrgb.h:63
Visual * visual
Definition: qt_x11_p.h:318
uint pixel(const QColor &color) const
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
Q_CORE_EXPORT void qFatal(const char *,...)
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
struct _XDisplay Display
Definition: qwindowdefs.h:115
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
#define GET_PIXEL_DITHER_TC_OPT(red_shift, green_shift, blue_shift, red_mask, green_mask, blue_mask, rbits, gbits, bbits)
void setMask(const QBitmap &mask)
Sets a mask bitmap.
int colorCount() const
Returns the size of the color table for the image.
Definition: qimage.cpp:1656
static void * appVisual(int screen=-1)
Returns the current visual used by the application on the given screen.
unsigned short ushort
Definition: qglobal.h:995
Colormap colormap
Definition: qt_x11_p.h:317
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
int fetchAndAddRelaxed(int valueToAdd)
Definition: qnamespace.h:54
quint16 index
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
Definition: qrgb.h:60
Q_STATIC_INLINE_FUNCTION int qt_div_255(int x)
#define GET_PIXEL_DITHER_TC
struct _XGC * GC
Definition: qwindowdefs.h:117
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
T * data()
Returns a pointer to the data stored in the vector.
Definition: qvector.h:152
void setX11Data(const QX11InfoData *)
Makes a shallow copy of the X11-specific data d and assigns it to this class.
void bitmapFromImage(const QImage &image)
bool defaultColormap
Definition: qt_x11_p.h:319
void setSerialNumber(int serNo)
static const KeyPair *const end
static int appCells(int screen=-1)
Returns the number of cells used by the application on the given screen.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define GET_PIXEL
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image&#39;s color table, or an empty list if the image does...
Definition: qimage.cpp:1770
QRgb color(int i) const
Returns the color in the color table at index i.
Definition: qimage.cpp:1829
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
int screen() const
Returns the number of the screen currently in use.
bool defaultVisual
Definition: qt_x11_p.h:320

◆ handle()

Qt::HANDLE QX11PixmapData::handle ( ) const
inline

Definition at line 95 of file qpixmap_x11_p.h.

Referenced by QGLContextPrivate::bindTextureFromNativePixmap(), QEgl::createSurface(), and transformed().

95 { return hd; }
Qt::HANDLE hd

◆ hasAlphaChannel()

bool QX11PixmapData::hasAlphaChannel ( ) const
virtual

◆ mask()

QBitmap QX11PixmapData::mask ( ) const
virtual

Reimplemented from QPixmapData.

Definition at line 1314 of file qpixmap_x11.cpp.

Referenced by bitmap_to_mask(), toImage(), and transformed().

1315 {
1316  QBitmap mask;
1317 #ifndef QT_NO_XRENDER
1318  if (picture && d == 32) {
1319  // #### slow - there must be a better way..
1320  mask = QBitmap::fromImage(toImage().createAlphaMask());
1321  } else
1322 #endif
1323  if (d == 1) {
1324  QX11PixmapData *that = const_cast<QX11PixmapData*>(this);
1325  mask = QPixmap(that);
1326  } else {
1327  mask = mask_to_bitmap(xinfo.screen());
1328  }
1329  return mask;
1330 }
Qt::HANDLE picture
QBitmap mask_to_bitmap(int screen) const
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
QImage toImage() const
Converts the pixmap to a QImage.
QBitmap mask() const
static QBitmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Returns a copy of the given image converted to a bitmap using the specified image conversion flags...
Definition: qbitmap.cpp:281
friend class QPixmap
int screen() const
Returns the number of the screen currently in use.

◆ mask_to_bitmap()

QBitmap QX11PixmapData::mask_to_bitmap ( int  screen) const
private

Definition at line 116 of file qpixmap_x11.cpp.

Referenced by mask(), and transformed().

117 {
118  if (!x11_mask)
119  return QBitmap();
120  QPixmap::x11SetDefaultScreen(screen);
121  QBitmap bm(w, h);
122  GC gc = XCreateGC(X11->display, bm.handle(), 0, 0);
123  XCopyArea(X11->display, x11_mask, bm.handle(), gc, 0, 0,
124  bm.data->width(), bm.data->height(), 0, 0);
125  XFreeGC(X11->display, gc);
126  return bm;
127 }
friend class QBitmap
#define X11
Definition: qt_x11_p.h:724
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
Qt::HANDLE x11_mask
struct _XGC * GC
Definition: qwindowdefs.h:117

◆ metric()

int QX11PixmapData::metric ( QPaintDevice::PaintDeviceMetric  metric) const
protectedvirtual

Implements QPixmapData.

Definition at line 1433 of file qpixmap_x11.cpp.

1434 {
1435  switch (metric) {
1437  return w;
1439  return h;
1441  return 1 << d;
1443  return d;
1444  case QPaintDevice::PdmWidthMM: {
1445  const int screen = xinfo.screen();
1446  const int mm = DisplayWidthMM(X11->display, screen) * w
1447  / DisplayWidth(X11->display, screen);
1448  return mm;
1449  }
1451  const int screen = xinfo.screen();
1452  const int mm = (DisplayHeightMM(X11->display, screen) * h)
1453  / DisplayHeight(X11->display, screen);
1454  return mm;
1455  }
1456  case QPaintDevice::PdmDpiX:
1458  return QX11Info::appDpiX(xinfo.screen());
1459  case QPaintDevice::PdmDpiY:
1461  return QX11Info::appDpiY(xinfo.screen());
1462  default:
1463  qWarning("QX11PixmapData::metric(): Invalid metric");
1464  return 0;
1465  }
1466 }
#define X11
Definition: qt_x11_p.h:724
int metric(QPaintDevice::PaintDeviceMetric metric) const
static int appDpiX(int screen=-1)
Returns the horizontal resolution of the given screen in terms of the number of dots per inch...
Q_CORE_EXPORT void qWarning(const char *,...)
int screen() const
Returns the number of the screen currently in use.
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...

◆ paintEngine()

QPaintEngine * QX11PixmapData::paintEngine ( ) const
virtual

Implements QPixmapData.

Reimplemented in QX11GLPixmapData.

Definition at line 2200 of file qpixmap_x11.cpp.

2201 {
2202  QX11PixmapData *that = const_cast<QX11PixmapData*>(this);
2203 
2204  if ((flags & Readonly) && share_mode == QPixmap::ImplicitlyShared) {
2205  // if someone wants to draw onto us, copy the shared contents
2206  // and turn it into a fully fledged QPixmap
2207  ::Pixmap hd_copy = XCreatePixmap(X11->display, RootWindow(X11->display, xinfo.screen()),
2208  w, h, d);
2209 #if !defined(QT_NO_XRENDER)
2210  XRenderPictFormat *format = qt_renderformat_for_depth(xinfo, d);
2211  ::Picture picture_copy = XRenderCreatePicture(X11->display, hd_copy, format, 0, 0);
2212 
2213  if (picture && d == 32) {
2214  XRenderComposite(X11->display, PictOpSrc, picture, 0, picture_copy,
2215  0, 0, 0, 0, 0, 0, w, h);
2216  XRenderFreePicture(X11->display, picture);
2217  that->picture = picture_copy;
2218  } else
2219 #endif
2220  {
2221  GC gc = XCreateGC(X11->display, hd_copy, 0, 0);
2222  XCopyArea(X11->display, hd, hd_copy, gc, 0, 0, w, h, 0, 0);
2223  XFreeGC(X11->display, gc);
2224  }
2225  that->hd = hd_copy;
2227  }
2228 
2229  if (!that->pengine)
2230  that->pengine = new QX11PaintEngine;
2231  return that->pengine;
2232 }
Qt::HANDLE picture
QX11PaintEngine * pengine
Qt::HANDLE hd
QPixmap::ShareMode share_mode
#define X11
Definition: qt_x11_p.h:724
friend class QX11PaintEngine
static XRenderPictFormat * qt_renderformat_for_depth(const QX11Info &xinfo, int depth)
unsigned long Picture
struct _XGC * GC
Definition: qwindowdefs.h:117
int screen() const
Returns the number of the screen currently in use.

◆ release()

void QX11PixmapData::release ( )
private

Definition at line 1255 of file qpixmap_x11.cpp.

Referenced by fill(), setAlphaChannel(), setMask(), and ~QX11PixmapData().

1256 {
1257  delete pengine;
1258  pengine = 0;
1259 
1260  if (!X11) {
1261  // At this point, the X server will already have freed our resources,
1262  // so there is nothing to do.
1263  return;
1264  }
1265 
1266  if (x11_mask) {
1267 #ifndef QT_NO_XRENDER
1268  if (mask_picture)
1269  XRenderFreePicture(X11->display, mask_picture);
1270  mask_picture = 0;
1271 #endif
1272  XFreePixmap(X11->display, x11_mask);
1273  x11_mask = 0;
1274  }
1275 
1276  if (hd) {
1277 #ifndef QT_NO_XRENDER
1278  if (picture) {
1279  XRenderFreePicture(X11->display, picture);
1280  picture = 0;
1281  }
1282 #endif // QT_NO_XRENDER
1283 
1284  if (hd2) {
1285  XFreePixmap(xinfo.display(), hd2);
1286  hd2 = 0;
1287  }
1288  if (!(flags & Readonly))
1289  XFreePixmap(xinfo.display(), hd);
1290  hd = 0;
1291  }
1292 }
Qt::HANDLE picture
QX11PaintEngine * pengine
Qt::HANDLE hd
#define X11
Definition: qt_x11_p.h:724
Qt::HANDLE mask_picture
Qt::HANDLE x11_mask
Qt::HANDLE hd2
static Display * display()
Returns the default display for the application.

◆ resize()

void QX11PixmapData::resize ( int  width,
int  height 
)
virtual

Implements QPixmapData.

Definition at line 328 of file qpixmap_x11.cpp.

Referenced by QX11GLSharedContexts::QX11GLSharedContexts(), QX11GLWindowSurface::setGeometry(), QX11WindowSurface::setGeometry(), setMask(), and transformed().

329 {
331 
332  w = width;
333  h = height;
334  is_null = (w <= 0 || h <= 0);
335 
336  if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) {
337  QX11InfoData* xd = xinfo.getX11Data(true);
338  xd->screen = defaultScreen;
339  xd->depth = QX11Info::appDepth(xd->screen);
340  xd->cells = QX11Info::appCells(xd->screen);
343  xd->visual = (Visual *)QX11Info::appVisual(xd->screen);
345  xinfo.setX11Data(xd);
346  }
347 
348  int dd = xinfo.depth();
349 
352 
353  bool make_null = w <= 0 || h <= 0; // create null pixmap
354  d = (pixelType() == BitmapType ? 1 : dd);
355  if (make_null || d == 0) {
356  w = 0;
357  h = 0;
358  is_null = true;
359  hd = 0;
360  picture = 0;
361  d = 0;
362  if (!make_null)
363  qWarning("QPixmap: Invalid pixmap parameters");
364  return;
365  }
366  hd = (Qt::HANDLE)XCreatePixmap(X11->display,
367  RootWindow(X11->display, xinfo.screen()),
368  w, h, d);
369 #ifndef QT_NO_XRENDER
370  if (X11->use_xrender) {
371  XRenderPictFormat *format = d == 1
372  ? XRenderFindStandardFormat(X11->display, PictStandardA1)
373  : XRenderFindVisualFormat(X11->display, (Visual *)xinfo.visual());
374  picture = XRenderCreatePicture(X11->display, hd, format, 0, 0);
375  }
376 #endif // QT_NO_XRENDER
377 }
int depth() const
Returns the color depth (bits per pixel) of the X display.
static int defaultScreen
Qt::HANDLE picture
Qt::HANDLE hd
static int appDepth(int screen=-1)
Returns the color depth (bits per pixel) used by the application on the given screen.
static bool appDefaultVisual(int screen=-1)
Returns true if the application has a default visual on the given screen; otherwise returns false...
int width() const
QBasicAtomicInt qt_pixmap_serial
#define X11
Definition: qt_x11_p.h:724
PixelType pixelType() const
QX11InfoData * getX11Data(bool def=false) const
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
Q_CORE_EXPORT void qWarning(const char *,...)
static bool appDefaultColormap(int screen=-1)
Returns true if the application has a default color map on the given screen; otherwise returns false...
void * HANDLE
Definition: qnamespace.h:1671
static Qt::HANDLE appColormap(int screen=-1)
Returns a handle for the application&#39;s color map on the given screen.
Visual * visual
Definition: qt_x11_p.h:318
int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth
static void * appVisual(int screen=-1)
Returns the current visual used by the application on the given screen.
Colormap colormap
Definition: qt_x11_p.h:317
int fetchAndAddRelaxed(int valueToAdd)
int height() const
void setX11Data(const QX11InfoData *)
Makes a shallow copy of the X11-specific data d and assigns it to this class.
bool defaultColormap
Definition: qt_x11_p.h:319
void setSerialNumber(int serNo)
static int appCells(int screen=-1)
Returns the number of cells used by the application on the given screen.
int screen() const
Returns the number of the screen currently in use.
bool defaultVisual
Definition: qt_x11_p.h:320

◆ scroll()

bool QX11PixmapData::scroll ( int  dx,
int  dy,
const QRect rect 
)
virtual

Reimplemented from QPixmapData.

Reimplemented in QX11GLPixmapData.

Definition at line 2328 of file qpixmap_x11.cpp.

Referenced by QX11GLPixmapData::scroll().

2329 {
2330  GC gc = XCreateGC(X11->display, hd, 0, 0);
2331  XCopyArea(X11->display, hd, hd, gc,
2332  rect.left(), rect.top(), rect.width(), rect.height(),
2333  rect.left() + dx, rect.top() + dy);
2334  XFreeGC(X11->display, gc);
2335  return true;
2336 }
Qt::HANDLE hd
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define X11
Definition: qt_x11_p.h:724
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
struct _XGC * GC
Definition: qwindowdefs.h:117

◆ setAlphaChannel()

void QX11PixmapData::setAlphaChannel ( const QPixmap alphaChannel)
virtual

Reimplemented from QPixmapData.

Definition at line 1305 of file qpixmap_x11.cpp.

1306 {
1307  QImage image(toImage());
1308  image.setAlphaChannel(alpha.toImage());
1309  release();
1311 }
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage toImage() const
Converts the pixmap to a QImage.

◆ setMask()

void QX11PixmapData::setMask ( const QBitmap newmask)
virtual

Sets a mask bitmap.

The newmask bitmap defines the clip mask for this pixmap. Every pixel in newmask corresponds to a pixel in this pixmap. Pixel value 1 means opaque and pixel value 0 means transparent. The mask must have the same size as this pixmap.

Warning
Setting the mask on a pixmap will cause any alpha channel data to be cleared. For example:
QPixmap alpha("image-with-alpha.png");
QPixmap alphacopy = alpha;
alphacopy.setMask(alphacopy.mask());
Now, alpha and alphacopy are visually different.

Setting a null mask resets the mask.

The effect of this function is undefined when the pixmap is being painted on.

See also
mask(), {QPixmap::Pixmap Transformations}{Pixmap Transformations}, QBitmap

Reimplemented from QPixmapData.

Definition at line 1353 of file qpixmap_x11.cpp.

Referenced by fromImage().

1354 {
1355  if (newmask.isNull()) { // clear mask
1356 #ifndef QT_NO_XRENDER
1357  if (picture && d == 32) {
1358  QX11PixmapData newData(pixelType());
1359  newData.resize(w, h);
1360  newData.fill(Qt::black);
1361  XRenderComposite(X11->display, PictOpOver,
1362  picture, 0, newData.picture,
1363  0, 0, 0, 0, 0, 0, w, h);
1364  release();
1365  *this = newData;
1366  // the new QX11PixmapData object isn't referenced yet, so
1367  // ref it
1368  ref.ref();
1369 
1370  // the below is to make sure the QX11PixmapData destructor
1371  // doesn't delete our newly created render picture
1372  newData.hd = 0;
1373  newData.x11_mask = 0;
1374  newData.picture = 0;
1375  newData.mask_picture = 0;
1376  newData.hd2 = 0;
1377  } else
1378 #endif
1379  if (x11_mask) {
1380 #ifndef QT_NO_XRENDER
1381  if (picture) {
1382  XRenderPictureAttributes attrs;
1383  attrs.alpha_map = 0;
1384  XRenderChangePicture(X11->display, picture, CPAlphaMap,
1385  &attrs);
1386  }
1387  if (mask_picture)
1388  XRenderFreePicture(X11->display, mask_picture);
1389  mask_picture = 0;
1390 #endif
1391  XFreePixmap(X11->display, x11_mask);
1392  x11_mask = 0;
1393  }
1394  return;
1395  }
1396 
1397 #ifndef QT_NO_XRENDER
1398  if (picture && d == 32) {
1399  XRenderComposite(X11->display, PictOpSrc,
1400  picture, newmask.x11PictureHandle(),
1401  picture, 0, 0, 0, 0, 0, 0, w, h);
1402  } else
1403 #endif
1404  if (depth() == 1) {
1405  XGCValues vals;
1406  vals.function = GXand;
1407  GC gc = XCreateGC(X11->display, hd, GCFunction, &vals);
1408  XCopyArea(X11->display, newmask.handle(), hd, gc, 0, 0,
1409  width(), height(), 0, 0);
1410  XFreeGC(X11->display, gc);
1411  } else {
1412  // ##### should or the masks together
1413  if (x11_mask) {
1414  XFreePixmap(X11->display, x11_mask);
1415 #ifndef QT_NO_XRENDER
1416  if (mask_picture)
1417  XRenderFreePicture(X11->display, mask_picture);
1418 #endif
1419  }
1421 #ifndef QT_NO_XRENDER
1422  if (picture) {
1423  mask_picture = XRenderCreatePicture(X11->display, x11_mask,
1424  XRenderFindStandardFormat(X11->display, PictStandardA1), 0, 0);
1425  XRenderPictureAttributes attrs;
1426  attrs.alpha_map = mask_picture;
1427  XRenderChangePicture(X11->display, picture, CPAlphaMap, &attrs);
1428  }
1429 #endif
1430  }
1431 }
Qt::HANDLE picture
Qt::HANDLE hd
int width() const
Qt::HANDLE handle() const
Returns the pixmap&#39;s handle to the device context.
Definition: qpixmap.cpp:1299
bool ref()
Atomically increments the value of this QAtomicInt.
#define X11
Definition: qt_x11_p.h:724
Qt::HANDLE mask_picture
PixelType pixelType() const
static Qt::HANDLE bitmap_to_mask(const QBitmap &, int screen)
int depth() const
Qt::HANDLE x11_mask
QAtomicInt ref
struct _XGC * GC
Definition: qwindowdefs.h:117
int height() const
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
int screen() const
Returns the number of the screen currently in use.

◆ takeQImageFromXImage()

QImage QX11PixmapData::takeQImageFromXImage ( const QXImageWrapper xi) const
private

Definition at line 1496 of file qpixmap_x11.cpp.

Referenced by toImage().

1497 {
1498  XImage *xi = xiWrapper.xi;
1499 
1501  if (depth() == 24)
1502  format = QImage::Format_RGB32;
1503  else if (depth() == 16)
1504  format = QImage::Format_RGB16;
1505 
1506  QImage image((uchar *)xi->data, xi->width, xi->height, xi->bytes_per_line, format);
1507  // take ownership
1508  image.data_ptr()->own_data = true;
1509  xi->data = 0;
1510 
1511  // we may have to swap the byte order
1512  if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst)
1513  || (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst))
1514  {
1515  for (int i=0; i < image.height(); i++) {
1516  if (depth() == 16) {
1517  ushort *p = (ushort*)image.scanLine(i);
1518  ushort *end = p + image.width();
1519  while (p < end) {
1520  *p = ((*p << 8) & 0xff00) | ((*p >> 8) & 0x00ff);
1521  p++;
1522  }
1523  } else {
1524  uint *p = (uint*)image.scanLine(i);
1525  uint *end = p + image.width();
1526  while (p < end) {
1527  *p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000)
1528  | ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff);
1529  p++;
1530  }
1531  }
1532  }
1533  }
1534 
1535  // fix-up alpha channel
1536  if (format == QImage::Format_RGB32) {
1537  QRgb *p = (QRgb *)image.bits();
1538  for (int y = 0; y < xi->height; ++y) {
1539  for (int x = 0; x < xi->width; ++x)
1540  p[x] |= 0xff000000;
1541  p += xi->bytes_per_line / 4;
1542  }
1543  }
1544 
1545  XDestroyImage(xi);
1546  return image;
1547 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
unsigned int QRgb
Definition: qrgb.h:53
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
int depth() const
unsigned short ushort
Definition: qglobal.h:995
static const KeyPair *const end

◆ toImage() [1/3]

QImage QX11PixmapData::toImage ( ) const
virtual

Converts the pixmap to a QImage.

Returns a null image if the conversion fails.

If the pixmap has 1-bit depth, the returned image will also be 1 bit deep. If the pixmap has 2- to 8-bit depth, the returned image has 8-bit depth. If the pixmap has greater than 8-bit depth, the returned image has 32-bit depth.

Note that for the moment, alpha masks on monochrome images are ignored.

See also
fromImage(), {QImage::Image Formats}{Image Formats}

Implements QPixmapData.

Definition at line 1582 of file qpixmap_x11.cpp.

Referenced by alphaChannel(), mask(), setAlphaChannel(), toImage(), and transformed().

1583 {
1584  return toImage(QRect(0, 0, w, h));
1585 }
QImage toImage() const
Converts the pixmap to a QImage.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58

◆ toImage() [2/3]

QImage QX11PixmapData::toImage ( const QRect rect) const
virtual

Reimplemented from QPixmapData.

Definition at line 1549 of file qpixmap_x11.cpp.

1550 {
1551  QXImageWrapper xiWrapper;
1552  xiWrapper.xi = XGetImage(X11->display, hd, rect.x(), rect.y(), rect.width(), rect.height(),
1553  AllPlanes, (depth() == 1) ? XYPixmap : ZPixmap);
1554 
1555  Q_CHECK_PTR(xiWrapper.xi);
1556  if (!xiWrapper.xi)
1557  return QImage();
1558 
1559  if (!x11_mask && canTakeQImageFromXImage(xiWrapper))
1560  return takeQImageFromXImage(xiWrapper);
1561 
1562  QImage image = toImage(xiWrapper, rect);
1563  qSafeXDestroyImage(xiWrapper.xi);
1564  return image;
1565 }
Qt::HANDLE hd
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
static void qSafeXDestroyImage(XImage *x)
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define X11
Definition: qt_x11_p.h:724
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
QImage toImage() const
Converts the pixmap to a QImage.
int depth() const
Qt::HANDLE x11_mask
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QImage takeQImageFromXImage(const QXImageWrapper &xi) const
bool canTakeQImageFromXImage(const QXImageWrapper &xi) const

◆ toImage() [3/3]

QImage QX11PixmapData::toImage ( const QXImageWrapper xi,
const QRect rect 
) const
private

Definition at line 1587 of file qpixmap_x11.cpp.

1588 {
1589  XImage *xi = xiWrapper.xi;
1590 
1591  int d = depth();
1592  Visual *visual = (Visual *)xinfo.visual();
1593  bool trucol = (visual->c_class >= TrueColor) && d > 1;
1594 
1596  if (d > 1 && d <= 8) {
1597  d = 8;
1598  format = QImage::Format_Indexed8;
1599  }
1600  // we could run into the situation where d == 8 AND trucol is true, which can
1601  // cause problems when converting to and from images. in this case, always treat
1602  // the depth as 32...
1603  if (d > 8 || trucol) {
1604  d = 32;
1605  format = QImage::Format_RGB32;
1606  }
1607 
1608  if (d == 1 && xi->bitmap_bit_order == LSBFirst)
1609  format = QImage::Format_MonoLSB;
1610  if (x11_mask && format == QImage::Format_RGB32)
1611  format = QImage::Format_ARGB32;
1612 
1613  QImage image(xi->width, xi->height, format);
1614  if (image.isNull()) // could not create image
1615  return image;
1616 
1617  QImage alpha;
1618  if (x11_mask) {
1619  if (rect.contains(QRect(0, 0, w, h)))
1620  alpha = mask().toImage();
1621  else
1622  alpha = mask().toImage().copy(rect);
1623  }
1624  bool ale = alpha.format() == QImage::Format_MonoLSB;
1625 
1626  if (trucol) { // truecolor
1627  const uint red_mask = (uint)visual->red_mask;
1628  const uint green_mask = (uint)visual->green_mask;
1629  const uint blue_mask = (uint)visual->blue_mask;
1630  const int red_shift = highest_bit(red_mask) - 7;
1631  const int green_shift = highest_bit(green_mask) - 7;
1632  const int blue_shift = highest_bit(blue_mask) - 7;
1633 
1634  const uint red_bits = n_bits(red_mask);
1635  const uint green_bits = n_bits(green_mask);
1636  const uint blue_bits = n_bits(blue_mask);
1637 
1638  static uint red_table_bits = 0;
1639  static uint green_table_bits = 0;
1640  static uint blue_table_bits = 0;
1641 
1642  if (red_bits < 8 && red_table_bits != red_bits) {
1643  build_scale_table(&red_scale_table, red_bits);
1644  red_table_bits = red_bits;
1645  }
1646  if (blue_bits < 8 && blue_table_bits != blue_bits) {
1647  build_scale_table(&blue_scale_table, blue_bits);
1648  blue_table_bits = blue_bits;
1649  }
1650  if (green_bits < 8 && green_table_bits != green_bits) {
1651  build_scale_table(&green_scale_table, green_bits);
1652  green_table_bits = green_bits;
1653  }
1654 
1655  int r, g, b;
1656 
1657  QRgb *dst;
1658  uchar *src;
1659  uint pixel;
1660  int bppc = xi->bits_per_pixel;
1661 
1662  if (bppc > 8 && xi->byte_order == LSBFirst)
1663  bppc++;
1664 
1665  for (int y = 0; y < xi->height; ++y) {
1666  uchar* asrc = x11_mask ? alpha.scanLine(y) : 0;
1667  dst = (QRgb *)image.scanLine(y);
1668  src = (uchar *)xi->data + xi->bytes_per_line*y;
1669  for (int x = 0; x < xi->width; x++) {
1670  switch (bppc) {
1671  case 8:
1672  pixel = *src++;
1673  break;
1674  case 16: // 16 bit MSB
1675  pixel = src[1] | (uint)src[0] << 8;
1676  src += 2;
1677  break;
1678  case 17: // 16 bit LSB
1679  pixel = src[0] | (uint)src[1] << 8;
1680  src += 2;
1681  break;
1682  case 24: // 24 bit MSB
1683  pixel = src[2] | (uint)src[1] << 8 | (uint)src[0] << 16;
1684  src += 3;
1685  break;
1686  case 25: // 24 bit LSB
1687  pixel = src[0] | (uint)src[1] << 8 | (uint)src[2] << 16;
1688  src += 3;
1689  break;
1690  case 32: // 32 bit MSB
1691  pixel = src[3] | (uint)src[2] << 8 | (uint)src[1] << 16 | (uint)src[0] << 24;
1692  src += 4;
1693  break;
1694  case 33: // 32 bit LSB
1695  pixel = src[0] | (uint)src[1] << 8 | (uint)src[2] << 16 | (uint)src[3] << 24;
1696  src += 4;
1697  break;
1698  default: // should not really happen
1699  x = xi->width; // leave loop
1700  y = xi->height;
1701  pixel = 0; // eliminate compiler warning
1702  qWarning("QPixmap::convertToImage: Invalid depth %d", bppc);
1703  }
1704  if (red_shift > 0)
1705  r = (pixel & red_mask) >> red_shift;
1706  else
1707  r = (pixel & red_mask) << -red_shift;
1708  if (green_shift > 0)
1709  g = (pixel & green_mask) >> green_shift;
1710  else
1711  g = (pixel & green_mask) << -green_shift;
1712  if (blue_shift > 0)
1713  b = (pixel & blue_mask) >> blue_shift;
1714  else
1715  b = (pixel & blue_mask) << -blue_shift;
1716 
1717  if (red_bits < 8)
1718  r = red_scale_table[r];
1719  if (green_bits < 8)
1720  g = green_scale_table[g];
1721  if (blue_bits < 8)
1722  b = blue_scale_table[b];
1723 
1724  if (x11_mask) {
1725  if (ale) {
1726  *dst++ = (asrc[x >> 3] & (1 << (x & 7))) ? qRgba(r, g, b, 0xff) : 0;
1727  } else {
1728  *dst++ = (asrc[x >> 3] & (0x80 >> (x & 7))) ? qRgba(r, g, b, 0xff) : 0;
1729  }
1730  } else {
1731  *dst++ = qRgb(r, g, b);
1732  }
1733  }
1734  }
1735  } else if (xi->bits_per_pixel == d) { // compatible depth
1736  char *xidata = xi->data; // copy each scanline
1737  int bpl = qMin(image.bytesPerLine(),xi->bytes_per_line);
1738  for (int y=0; y<xi->height; y++) {
1739  memcpy(image.scanLine(y), xidata, bpl);
1740  xidata += xi->bytes_per_line;
1741  }
1742  } else {
1743  /* Typically 2 or 4 bits display depth */
1744  qWarning("QPixmap::convertToImage: Display not supported (bpp=%d)",
1745  xi->bits_per_pixel);
1746  return QImage();
1747  }
1748 
1749  if (d == 1) { // bitmap
1750  image.setColorCount(2);
1751  image.setColor(0, qRgb(255,255,255));
1752  image.setColor(1, qRgb(0,0,0));
1753  } else if (!trucol) { // pixmap with colormap
1754  register uchar *p;
1755  uchar *end;
1756  uchar use[256]; // pixel-in-use table
1757  uchar pix[256]; // pixel translation table
1758  int ncols, bpl;
1759  memset(use, 0, 256);
1760  memset(pix, 0, 256);
1761  bpl = image.bytesPerLine();
1762 
1763  if (x11_mask) { // which pixels are used?
1764  for (int i = 0; i < xi->height; i++) {
1765  uchar* asrc = alpha.scanLine(i);
1766  p = image.scanLine(i);
1767  if (ale) {
1768  for (int x = 0; x < xi->width; x++) {
1769  if (asrc[x >> 3] & (1 << (x & 7)))
1770  use[*p] = 1;
1771  ++p;
1772  }
1773  } else {
1774  for (int x = 0; x < xi->width; x++) {
1775  if (asrc[x >> 3] & (0x80 >> (x & 7)))
1776  use[*p] = 1;
1777  ++p;
1778  }
1779  }
1780  }
1781  } else {
1782  for (int i = 0; i < xi->height; i++) {
1783  p = image.scanLine(i);
1784  end = p + bpl;
1785  while (p < end)
1786  use[*p++] = 1;
1787  }
1788  }
1789  ncols = 0;
1790  for (int i = 0; i < 256; i++) { // build translation table
1791  if (use[i])
1792  pix[i] = ncols++;
1793  }
1794  for (int i = 0; i < xi->height; i++) { // translate pixels
1795  p = image.scanLine(i);
1796  end = p + bpl;
1797  while (p < end) {
1798  *p = pix[*p];
1799  p++;
1800  }
1801  }
1802  if (x11_mask) {
1803  int trans;
1804  if (ncols < 256) {
1805  trans = ncols++;
1806  image.setColorCount(ncols); // create color table
1807  image.setColor(trans, 0x00000000);
1808  } else {
1809  image.setColorCount(ncols); // create color table
1810  // oh dear... no spare "transparent" pixel.
1811  // use first pixel in image (as good as any).
1812  trans = image.scanLine(0)[0];
1813  }
1814  for (int i = 0; i < xi->height; i++) {
1815  uchar* asrc = alpha.scanLine(i);
1816  p = image.scanLine(i);
1817  if (ale) {
1818  for (int x = 0; x < xi->width; x++) {
1819  if (!(asrc[x >> 3] & (1 << (x & 7))))
1820  *p = trans;
1821  ++p;
1822  }
1823  } else {
1824  for (int x = 0; x < xi->width; x++) {
1825  if (!(asrc[x >> 3] & (1 << (7 -(x & 7)))))
1826  *p = trans;
1827  ++p;
1828  }
1829  }
1830  }
1831  } else {
1832  image.setColorCount(ncols); // create color table
1833  }
1834  QVector<QColor> colors = QColormap::instance(xinfo.screen()).colormap();
1835  int j = 0;
1836  for (int i=0; i<colors.size(); i++) { // translate pixels
1837  if (use[i])
1838  image.setColor(j++, 0xff000000 | colors.at(i).rgb());
1839  }
1840  }
1841 
1842  return image;
1843 }
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
Format
The following image formats are available in Qt.
Definition: qimage.h:91
static QColormap instance(int screen=-1)
unsigned int QRgb
Definition: qrgb.h:53
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
Definition: qimage.cpp:1410
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static int highest_bit(uint v)
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
static uint n_bits(uint v)
for(int ii=mo->methodOffset();ii< mo->methodCount();++ii)
unsigned char uchar
Definition: qglobal.h:994
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
Definition: qrgb.h:72
static uint * blue_scale_table
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
static uint * green_scale_table
void * visual() const
Returns the current visual.
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
static uint * red_scale_table
int depth() const
QBitmap mask() const
Qt::HANDLE x11_mask
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
Definition: qrgb.h:69
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static void build_scale_table(uint **table, uint nBits)
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137
QRgb rgb() const
Returns the RGB value of the color.
Definition: qcolor.cpp:1051
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
int screen() const
Returns the number of the screen currently in use.

◆ transformed()

QPixmap QX11PixmapData::transformed ( const QTransform transform,
Qt::TransformationMode  mode 
) const
virtual

Returns a copy of the pixmap that is transformed using the given transformation matrix and transformation mode.

The original pixmap is not changed.

The transformation matrix is internally adjusted to compensate for unwanted translation; i.e. the pixmap produced is the smallest pixmap that contains all the transformed points of the original pixmap. Use the trueMatrix() function to retrieve the actual matrix used for transforming the pixmap.

This function is slow because it involves transformation to a QImage, non-trivial computations and a transformation back to a QPixmap.

See also
trueMatrix(), {QPixmap::Pixmap Transformations}{Pixmap Transformations}

Reimplemented from QPixmapData.

Definition at line 1863 of file qpixmap_x11.cpp.

1865 {
1866  if (mode == Qt::SmoothTransformation || transform.type() >= QTransform::TxProject) {
1867  QImage image = toImage();
1868  return QPixmap::fromImage(image.transformed(transform, mode));
1869  }
1870 
1871  uint w = 0;
1872  uint h = 0; // size of target pixmap
1873  uint ws, hs; // size of source pixmap
1874  uchar *dptr; // data in target pixmap
1875  uint dbpl, dbytes; // bytes per line/bytes total
1876  uchar *sptr; // data in original pixmap
1877  int sbpl; // bytes per line in original
1878  int bpp; // bits per pixel
1879  bool depth1 = depth() == 1;
1880  Display *dpy = X11->display;
1881 
1882  ws = width();
1883  hs = height();
1884 
1885  QTransform mat(transform.m11(), transform.m12(), transform.m13(),
1886  transform.m21(), transform.m22(), transform.m23(),
1887  0., 0., 1);
1888  bool complex_xform = false;
1889  qreal scaledWidth;
1890  qreal scaledHeight;
1891 
1892  if (mat.type() <= QTransform::TxScale) {
1893  scaledHeight = qAbs(mat.m22()) * hs + 0.9999;
1894  scaledWidth = qAbs(mat.m11()) * ws + 0.9999;
1895  h = qAbs(int(scaledHeight));
1896  w = qAbs(int(scaledWidth));
1897  } else { // rotation or shearing
1898  QPolygonF a(QRectF(0, 0, ws, hs));
1899  a = mat.map(a);
1900  QRect r = a.boundingRect().toAlignedRect();
1901  w = r.width();
1902  h = r.height();
1903  scaledWidth = w;
1904  scaledHeight = h;
1905  complex_xform = true;
1906  }
1907  mat = QPixmap::trueMatrix(mat, ws, hs); // true matrix
1908 
1909  bool invertible;
1910  mat = mat.inverted(&invertible); // invert matrix
1911 
1912  if (h == 0 || w == 0 || !invertible
1913  || qAbs(scaledWidth) >= 32768 || qAbs(scaledHeight) >= 32768 )
1914  // error, return null pixmap
1915  return QPixmap();
1916 
1917 #if defined(QT_MITSHM)
1918  static bool try_once = true;
1919  if (try_once) {
1920  try_once = false;
1921  if (!xshminit)
1922  qt_create_mitshm_buffer(this, 800, 600);
1923  }
1924 
1925  bool use_mitshm = xshmimg && !depth1 &&
1926  xshmimg->width >= w && xshmimg->height >= h;
1927 #endif
1928  XImage *xi = XGetImage(X11->display, handle(), 0, 0, ws, hs, AllPlanes,
1929  depth1 ? XYPixmap : ZPixmap);
1930 
1931  if (!xi)
1932  return QPixmap();
1933 
1934  sbpl = xi->bytes_per_line;
1935  sptr = (uchar *)xi->data;
1936  bpp = xi->bits_per_pixel;
1937 
1938  if (depth1)
1939  dbpl = (w+7)/8;
1940  else
1941  dbpl = ((w*bpp+31)/32)*4;
1942  dbytes = dbpl*h;
1943 
1944 #if defined(QT_MITSHM)
1945  if (use_mitshm) {
1946  dptr = (uchar *)xshmimg->data;
1947  uchar fillbyte = bpp == 8 ? white.pixel() : 0xff;
1948  for (int y=0; y<h; y++)
1949  memset(dptr + y*xshmimg->bytes_per_line, fillbyte, dbpl);
1950  } else {
1951 #endif
1952  dptr = (uchar *)malloc(dbytes); // create buffer for bits
1953  Q_CHECK_PTR(dptr);
1954  if (depth1) // fill with zeros
1955  memset(dptr, 0, dbytes);
1956  else if (bpp == 8) // fill with background color
1957  memset(dptr, WhitePixel(X11->display, xinfo.screen()), dbytes);
1958  else
1959  memset(dptr, 0, dbytes);
1960 #if defined(QT_MITSHM)
1961  }
1962 #endif
1963 
1964  // #define QT_DEBUG_XIMAGE
1965 #if defined(QT_DEBUG_XIMAGE)
1966  qDebug("----IMAGE--INFO--------------");
1967  qDebug("width............. %d", xi->width);
1968  qDebug("height............ %d", xi->height);
1969  qDebug("xoffset........... %d", xi->xoffset);
1970  qDebug("format............ %d", xi->format);
1971  qDebug("byte order........ %d", xi->byte_order);
1972  qDebug("bitmap unit....... %d", xi->bitmap_unit);
1973  qDebug("bitmap bit order.. %d", xi->bitmap_bit_order);
1974  qDebug("depth............. %d", xi->depth);
1975  qDebug("bytes per line.... %d", xi->bytes_per_line);
1976  qDebug("bits per pixel.... %d", xi->bits_per_pixel);
1977 #endif
1978 
1979  int type;
1980  if (xi->bitmap_bit_order == MSBFirst)
1981  type = QT_XFORM_TYPE_MSBFIRST;
1982  else
1983  type = QT_XFORM_TYPE_LSBFIRST;
1984  int xbpl, p_inc;
1985  if (depth1) {
1986  xbpl = (w+7)/8;
1987  p_inc = dbpl - xbpl;
1988  } else {
1989  xbpl = (w*bpp)/8;
1990  p_inc = dbpl - xbpl;
1991 #if defined(QT_MITSHM)
1992  if (use_mitshm)
1993  p_inc = xshmimg->bytes_per_line - xbpl;
1994 #endif
1995  }
1996 
1997  if (!qt_xForm_helper(mat, xi->xoffset, type, bpp, dptr, xbpl, p_inc, h, sptr, sbpl, ws, hs)){
1998  qWarning("QPixmap::transform: display not supported (bpp=%d)",bpp);
1999  QPixmap pm;
2000  return pm;
2001  }
2002 
2003  qSafeXDestroyImage(xi);
2004 
2005  if (depth1) { // mono bitmap
2006  QBitmap bm = QBitmap::fromData(QSize(w, h), dptr,
2007  BitmapBitOrder(X11->display) == MSBFirst
2010  free(dptr);
2011  return bm;
2012  } else { // color pixmap
2014  QPixmap pm(x11Data);
2016  x11Data->xinfo = xinfo;
2017  x11Data->d = d;
2018  x11Data->w = w;
2019  x11Data->h = h;
2020  x11Data->is_null = (w <= 0 || h <= 0);
2021  x11Data->hd = (Qt::HANDLE)XCreatePixmap(X11->display,
2022  RootWindow(X11->display, xinfo.screen()),
2023  w, h, d);
2025 
2026 #ifndef QT_NO_XRENDER
2027  if (X11->use_xrender) {
2028  XRenderPictFormat *format = x11Data->d == 32
2029  ? XRenderFindStandardFormat(X11->display, PictStandardARGB32)
2030  : XRenderFindVisualFormat(X11->display, (Visual *) x11Data->xinfo.visual());
2031  x11Data->picture = XRenderCreatePicture(X11->display, x11Data->hd, format, 0, 0);
2032  }
2033 #endif // QT_NO_XRENDER
2034 
2035  GC gc = XCreateGC(X11->display, x11Data->hd, 0, 0);
2036 #if defined(QT_MITSHM)
2037  if (use_mitshm) {
2038  XCopyArea(dpy, xshmpm, x11Data->hd, gc, 0, 0, w, h, 0, 0);
2039  } else
2040 #endif
2041  {
2042  xi = XCreateImage(dpy, (Visual*)x11Data->xinfo.visual(),
2043  x11Data->d,
2044  ZPixmap, 0, (char *)dptr, w, h, 32, 0);
2045  XPutImage(dpy, pm.handle(), gc, xi, 0, 0, 0, 0, w, h);
2046  qSafeXDestroyImage(xi);
2047  }
2048  XFreeGC(X11->display, gc);
2049 
2050  if (x11_mask) { // xform mask, too
2051  pm.setMask(mask_to_bitmap(xinfo.screen()).transformed(transform));
2052  } else if (d != 32 && complex_xform) { // need a mask!
2053  QBitmap mask(ws, hs);
2054  mask.fill(Qt::color1);
2055  pm.setMask(mask.transformed(transform));
2056  }
2057  return pm;
2058  }
2059 }
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
double qreal
Definition: qglobal.h:1193
static QMatrix trueMatrix(const QMatrix &m, int w, int h)
This convenience function loads the matrix m into a QTransform and calls the overloaded function with...
Definition: qpixmap.cpp:584
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
Qt::HANDLE picture
Qt::HANDLE hd
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
QBitmap mask_to_bitmap(int screen) const
static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB)
Constructs a bitmap with the given size, and sets the contents to the bits supplied.
Definition: qbitmap.cpp:318
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
int width() const
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
long ASN1_INTEGER_get ASN1_INTEGER * a
static void qSafeXDestroyImage(XImage *x)
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QBasicAtomicInt qt_pixmap_serial
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
TransformationType type() const
Returns the transformation type of this matrix.
QBitmap transformed(const QMatrix &) const
This convenience function converts the matrix to a QTransform and calls the overloaded function...
Definition: qbitmap.cpp:356
#define X11
Definition: qt_x11_p.h:724
Q_CORE_EXPORT void qDebug(const char *,...)
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
unsigned char uchar
Definition: qglobal.h:994
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
Qt::HANDLE handle() const
Definition: qpixmap_x11_p.h:95
The QPolygonF class provides a vector of points using floating point precision.
Definition: qpolygon.h:134
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
QPixmap transformed(const QTransform &transform, Qt::TransformationMode mode) const
Returns a copy of the pixmap that is transformed using the given transformation matrix and transforma...
#define QT_XFORM_TYPE_MSBFIRST
void * HANDLE
Definition: qnamespace.h:1671
void * visual() const
Returns the current visual.
QImage transformed(const QMatrix &matrix, Qt::TransformationMode mode=Qt::FastTransformation) const
Returns a copy of the image that is transformed using the given transformation matrix and transformat...
Definition: qimage.cpp:4698
PixelType type
#define QT_XFORM_TYPE_LSBFIRST
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
#define Q_CHECK_PTR(p)
Definition: qglobal.h:1853
struct _XDisplay Display
Definition: qwindowdefs.h:115
QImage toImage() const
Converts the pixmap to a QImage.
int depth() const
QBitmap mask() const
Qt::HANDLE x11_mask
qreal m23() const
Returns the vertical projection factor.
Definition: qtransform.h:257
bool qt_xForm_helper(const QTransform &trueMat, int xoffset, int type, int depth, uchar *dptr, int dbpl, int p_inc, int dHeight, const uchar *sptr, int sbpl, int sWidth, int sHeight)
Definition: qimage.cpp:6100
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int fetchAndAddRelaxed(int valueToAdd)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
struct _XGC * GC
Definition: qwindowdefs.h:117
int height() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
qreal m13() const
Returns the horizontal projection factor.
Definition: qtransform.h:245
void setSerialNumber(int serNo)
friend class QPixmap
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
int screen() const
Returns the number of the screen currently in use.
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QX11PixmapData(PixelType type)

◆ x11ConvertToDefaultDepth()

Qt::HANDLE QX11PixmapData::x11ConvertToDefaultDepth ( )

Definition at line 2246 of file qpixmap_x11.cpp.

2247 {
2248 #ifndef QT_NO_XRENDER
2249  if (d == QX11Info::appDepth() || !X11->use_xrender)
2250  return hd;
2251  if (!hd2) {
2252  hd2 = XCreatePixmap(xinfo.display(), hd, w, h, QX11Info::appDepth());
2253  XRenderPictFormat *format = XRenderFindVisualFormat(xinfo.display(),
2254  (Visual*) xinfo.visual());
2255  Picture pic = XRenderCreatePicture(xinfo.display(), hd2, format, 0, 0);
2256  XRenderComposite(xinfo.display(), PictOpSrc, picture,
2257  XNone, pic, 0, 0, 0, 0, 0, 0, w, h);
2258  XRenderFreePicture(xinfo.display(), pic);
2259  }
2260  return hd2;
2261 #else
2262  return hd;
2263 #endif
2264 }
Qt::HANDLE picture
Qt::HANDLE hd
static int appDepth(int screen=-1)
Returns the color depth (bits per pixel) used by the application on the given screen.
#define X11
Definition: qt_x11_p.h:724
void * visual() const
Returns the current visual.
unsigned long Picture
Qt::HANDLE hd2
static Display * display()
Returns the default display for the application.

Friends and Related Functions

◆ QBitmap

friend class QBitmap
friend

Definition at line 110 of file qpixmap_x11_p.h.

Referenced by mask_to_bitmap().

◆ QEglContext

friend class QEglContext
friend

Definition at line 115 of file qpixmap_x11_p.h.

◆ QGLContext

friend class QGLContext
friend

Definition at line 116 of file qpixmap_x11_p.h.

Referenced by QX11GLPixmapData::paintEngine().

◆ QGLContextPrivate

friend class QGLContextPrivate
friend

Definition at line 114 of file qpixmap_x11_p.h.

◆ QMeeGoLivePixmapData

friend class QMeeGoLivePixmapData
friend

Definition at line 118 of file qpixmap_x11_p.h.

◆ QPixmap

friend class QPixmap
friend

Definition at line 109 of file qpixmap_x11_p.h.

Referenced by convertToARGB32(), mask(), and transformed().

◆ QRasterWindowSurface

friend class QRasterWindowSurface
friend

Definition at line 113 of file qpixmap_x11_p.h.

◆ qt_createEGLSurfaceForPixmap

bool qt_createEGLSurfaceForPixmap ( QPixmapData ,
bool   
)
friend

◆ QX11GLPixmapData

friend class QX11GLPixmapData
friend

Definition at line 117 of file qpixmap_x11_p.h.

◆ QX11PaintEngine

friend class QX11PaintEngine
friend

Definition at line 111 of file qpixmap_x11_p.h.

Referenced by paintEngine().

◆ QX11WindowSurface

friend class QX11WindowSurface
friend

Definition at line 112 of file qpixmap_x11_p.h.

Properties

◆ flags

uint QX11PixmapData::flags
private

◆ gl_surface

void* QX11PixmapData::gl_surface

◆ hd

Qt::HANDLE QX11PixmapData::hd
private

◆ hd2

Qt::HANDLE QX11PixmapData::hd2
private

Definition at line 147 of file qpixmap_x11_p.h.

Referenced by QPixmap::detach(), release(), setMask(), and x11ConvertToDefaultDepth().

◆ mask_picture

Qt::HANDLE QX11PixmapData::mask_picture
private

Definition at line 146 of file qpixmap_x11_p.h.

Referenced by convertToARGB32(), copy(), release(), and setMask().

◆ pengine

QX11PaintEngine* QX11PixmapData::pengine
private

Definition at line 150 of file qpixmap_x11_p.h.

Referenced by paintEngine(), and release().

◆ picture

Qt::HANDLE QX11PixmapData::picture
private

◆ share_mode

QPixmap::ShareMode QX11PixmapData::share_mode
private

Definition at line 148 of file qpixmap_x11_p.h.

Referenced by convertToARGB32(), and paintEngine().

◆ x11_mask

Qt::HANDLE QX11PixmapData::x11_mask
private

◆ xinfo

QX11Info QX11PixmapData::xinfo
private

The documentation for this class was generated from the following files: