4#include <QGuiApplication>
6#include <private/qdrawhelper_p.h>
7#include <private/qimage_p.h>
8#include <private/qimagepixmapcleanuphooks_p.h>
17#if QT_POINTER_SIZE == 8
22 t = (
t + ((
t >> 8) & 0xff00ff00ff00ff) + 0x80008000800080) >> 8;
23 t &= 0x000000ff00ff00ff;
32 t = (
t + ((
t >> 8) & 0xff00ff) + 0x800080) >> 8;
35 x = ((
x >> 8) & 0xff) *
a;
36 x = (
x + ((
x >> 8) & 0xff) + 0x80);
93 GC gc = XCreateGC(
x->display(), that->
handle(), 0, 0);
94 XCopyArea(
x->display(), x11_mask, that->
handle(), gc, 0, 0,
96 XFreeGC(
x->display(), gc);
100void QX11PlatformPixmap::bitmapFromImage(
const QImage &
image)
107#if QT_CONFIG(xrender)
108 if (
X11->use_xrender)
110 XRenderFindStandardFormat(xinfo.
display(), PictStandardA1), 0, 0);
114bool QX11PlatformPixmap::canTakeQImageFromXImage(
const QXImageWrapper &xiWrapper)
const
116 XImage *xi = xiWrapper.
xi;
118 if (xi->format != ZPixmap)
126 if (
depth() == 24 && xi->bits_per_pixel == 32 && xi->red_mask == 0xff0000
127 && xi->green_mask == 0xff00 && xi->blue_mask == 0xff)
131 if (
depth() == 16 && xi->bits_per_pixel == 16 && xi->red_mask == 0xf800
132 && xi->green_mask == 0x7e0 && xi->blue_mask == 0x1f)
140 XImage *xi = xiWrapper.
xi;
145 else if (
depth() == 16)
151 image.data_ptr()->own_data =
true;
158 for (
int i=0;
i <
image.height();
i++) {
163 *
p = ((*
p << 8) & 0xff00) | ((*
p >> 8) & 0x00ff);
170 *
p = ((*
p << 24) & 0xff000000) | ((*
p << 8) & 0x00ff0000)
171 | ((*
p >> 8) & 0x0000ff00) | ((*
p >> 24) & 0x000000ff);
181 for (
int y = 0;
y < xi->height; ++
y) {
182 for (
int x = 0;
x < xi->width; ++
x)
184 p += xi->bytes_per_line / 4;
203 GC gc = XCreateGC(
x->display(),
mask, 0, 0);
204 XCopyArea(
x->display(), that->
handle(),
mask, gc, 0, 0,
206 XFreeGC(
x->display(), gc);
233 for (
i=31; ((
b &
v) == 0) &&
i>=0;
i--)
267 qWarning(
"build_scale_table: internal error, nBits = %i", nBits);
271 static bool firstTable =
true;
278 int maxVal = (1 << nBits) - 1;
279 int valShift = 8 - nBits;
281 for (
i = 0 ;
i < maxVal + 1 ;
i++)
282 (*
table)[
i << valShift] =
i*255/maxVal;
296 if (
pixmap.paintingActive()) {
297 qWarning(
"qt_x11SetScreen(): Cannot change screens during painting");
370 int dd = xinfo.
depth();
375 bool make_null =
w <= 0 ||
h <= 0;
377 if (make_null ||
d == 0) {
385 qWarning(
"QPixmap: Invalid pixmap parameters");
388 hd = XCreatePixmap(xinfo.
display(),
391#if QT_CONFIG(xrender)
392 if (
X11->use_xrender) {
393 XRenderPictFormat *
format =
d == 1
394 ? XRenderFindStandardFormat(xinfo.
display(), PictStandardA1)
395 : XRenderFindVisualFormat(xinfo.
display(), (Visual *) xinfo.
visual());
413 if (!
X11->use_xrender)
452 bitmapFromImage(
img);
479 if (
d > 8 && dd <= 8) {
487 if (
image.colorCount() == 2) {
512 Visual *visual = (Visual *)xinfo.
visual();
513 XImage *xi =
nullptr;
514 bool trucol = (visual->c_class >= TrueColor);
515 size_t nbytes =
image.sizeInBytes();
516 uchar *newbits=
nullptr;
518#if QT_CONFIG(xrender)
528 hd = XCreatePixmap(dpy, RootWindow(dpy, xinfo.
screen()),
w,
h,
d);
529 picture = XRenderCreatePicture(dpy, hd,
530 XRenderFindStandardFormat(dpy, PictStandardARGB32), 0, 0);
532 xi = XCreateImage(dpy, visual,
d, ZPixmap, 0, 0,
w,
h, 32, 0);
534 newbits = (
uchar *)malloc(xi->bytes_per_line*
h);
536 xi->data = (
char *)newbits;
538 switch (cimage.
format()) {
542 for (
int y = 0;
y <
h; ++
y) {
544 for (
int x = 0;
x <
w; ++
x) {
562 for (
int y = 0;
y <
h; ++
y) {
564 for (
int x = 0;
x <
w; ++
x)
565 *xidata++ =
p[
x] | 0xff000000;
571 for (
int y = 0;
y <
h; ++
y) {
573 for (
int x = 0;
x <
w; ++
x) {
592 for (
int y = 0;
y <
h; ++
y) {
594 memcpy(xidata,
p,
w*
sizeof(
QRgb));
605 uint *xiend = xidata +
w*
h;
606 while (xidata < xiend) {
607 *xidata = (*xidata >> 24)
608 | ((*xidata >> 8) & 0xff00)
609 | ((*xidata << 8) & 0xff0000)
615 GC gc = XCreateGC(dpy, hd, 0, 0);
616 XPutImage(dpy, hd, gc, xi, 0, 0, 0, 0,
w,
h);
631 const bool d8 = (
d == 8);
632 const uint red_mask = (
uint)visual->red_mask;
633 const uint green_mask = (
uint)visual->green_mask;
634 const uint blue_mask = (
uint)visual->blue_mask;
636 const int green_shift =
highest_bit(green_mask) - 7;
648 r = red_shift > 0 ? r << red_shift : r >> -red_shift;
649 g = green_shift > 0 ? g << green_shift : g >> -green_shift;
650 b = blue_shift > 0 ? b << blue_shift : b >> -blue_shift;
651 pix[
i] = (
b & blue_mask) | (
g & green_mask) | (
r & red_mask)
652 | ~(blue_mask | green_mask | red_mask);
656 xi = XCreateImage(dpy, visual, dd, ZPixmap, 0, 0,
w,
h, 32, 0);
658 newbits = (
uchar *)malloc(xi->bytes_per_line*
h);
662 int bppc = xi->bits_per_pixel;
664 bool contig_bits =
n_bits(red_mask) == rbits &&
665 n_bits(green_mask) == gbits &&
666 n_bits(blue_mask) == bbits;
676 static bool init=
false;
677 static int D[16][16];
678 if (dither_tc && !
init) {
700 for (
n=2;
n<16;
n*=2) {
701 for (
i=0;
i<
n;
i++) {
702 for (
j=0;
j<
n;
j++) {
714 BPP16_565, BPP16_555,
715 BPP16_MSB, BPP16_LSB,
717 BPP24_MSB, BPP24_LSB,
726 else if (bppc == 16) {
727 if (red_shift == 8 && green_shift == 3 && blue_shift == -3 && !d8 && same_msb_lsb)
729 else if (red_shift == 7 && green_shift == 2 && blue_shift == -3 && !d8 && same_msb_lsb)
732 mode = (xi->byte_order == LSBFirst) ? BPP16_LSB : BPP16_MSB;
733 }
else if (bppc == 24) {
734 if (red_shift == 16 && green_shift == 8 && blue_shift == 0 && !d8 && same_msb_lsb)
737 mode = (xi->byte_order == LSBFirst) ? BPP24_LSB : BPP24_MSB;
738 }
else if (bppc == 32) {
739 if (red_shift == 16 && green_shift == 8 && blue_shift == 0 && !d8 && same_msb_lsb)
742 mode = (xi->byte_order == LSBFirst) ? BPP32_LSB : BPP32_MSB;
748 if (d8) pixel = pix[*src++]; \
751 int g = qGreen(*p); \
752 int b = qBlue (*p++); \
754 ? r << red_shift : r >> -red_shift; \
755 g = green_shift > 0 \
756 ? g << green_shift : g >> -green_shift; \
758 ? b << blue_shift : b >> -blue_shift; \
759 pixel = (r & red_mask)|(g & green_mask) | (b & blue_mask) \
760 | ~(blue_mask | green_mask | red_mask); \
763#define GET_PIXEL_DITHER_TC \
765 int g = qGreen(*p); \
766 int b = qBlue (*p++); \
767 const int thres = D[x%16][y%16]; \
768 if (r <= (255-(1<<(8-rbits))) && ((r<<rbits) & 255) \
770 r += (1<<(8-rbits)); \
771 if (g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \
773 g += (1<<(8-gbits)); \
774 if (b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \
776 b += (1<<(8-bbits)); \
778 ? r << red_shift : r >> -red_shift; \
779 g = green_shift > 0 \
780 ? g << green_shift : g >> -green_shift; \
782 ? b << blue_shift : b >> -blue_shift; \
783 uint pixel = (r & red_mask)|(g & green_mask) | (b & blue_mask);
787#define GET_PIXEL_DITHER_TC_OPT(red_shift,green_shift,blue_shift,red_mask,green_mask,blue_mask, \
789 const int thres = D[x%16][y%16]; \
791 if (r <= (255-(1<<(8-rbits))) && ((r<<rbits) & 255) \
793 r += (1<<(8-rbits)); \
794 int g = qGreen(*p); \
795 if (g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \
797 g += (1<<(8-gbits)); \
798 int b = qBlue (*p++); \
799 if (b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \
801 b += (1<<(8-bbits)); \
802 uint pixel = ((r red_shift) & red_mask) \
803 | ((g green_shift) & green_mask) \
804 | ((b blue_shift) & blue_mask);
807 for (int y=0; y<h; y++) { \
808 const uchar* src = cimage.scanLine(y); \
809 uchar* dst = newbits + xi->bytes_per_line*y; \
810 const QRgb* p = (const QRgb *)src; \
819 for (
int x=0;
x<
w;
x++) {
828 for (
int x=0;
x<
w;
x++) {
836 for (
int x=0;
x<
w;
x++) {
838 *
dst++ = (pixel >> 8);
845 for (
int x=0;
x<
w;
x++) {
860 for (
int x=0;
x<
w;
x++)
867 for (
int x = 0;
x <
w;
x++) {
868 *dst16++ = ((*
p >> 8) & 0xf800)
869 | ((*
p >> 5) & 0x7e0)
870 | ((*
p >> 3) & 0x1f);
878 for (
int x=0;
x<
w;
x++) {
879 *dst16++ = ((*
p >> 9) & 0x7c00)
880 | ((*
p >> 6) & 0x3e0)
881 | ((*
p >> 3) & 0x1f);
888 for (
int x=0;
x<
w;
x++) {
890 *
dst++ = (pixel >> 8);
897 for (
int x=0;
x<
w;
x++) {
907 for (
int x=0;
x<
w;
x++) {
913 for (
int x=0;
x<
w;
x++) {
923 for (
int x=0;
x<
w;
x++) {
925 *
dst++ = pixel >> 16;
933 for (
int x=0;
x<
w;
x++) {
937 *
dst++ = pixel >> 16;
943 memcpy(
dst,
p,
w * 4);
948 for (
int x=0;
x<
w;
x++) {
950 *
dst++ = pixel >> 24;
951 *
dst++ = pixel >> 16;
959 for (
int x=0;
x<
w;
x++) {
963 *
dst++ = pixel >> 16;
964 *
dst++ = pixel >> 24;
972 xi->data = (
char *)newbits;
975 if (
d == 8 && !trucol) {
978 if (
image.colorCount() == 0)
979 image.setColorCount(1);
982 memset(pop, 0,
sizeof(
int)*256);
983 for (
int i = 0;
i <
h;
i++) {
990 newbits = (
uchar *)malloc(nbytes);
995 memcpy(
p, cimage.
bits(), nbytes);
1022 PIX pixarr_sorted[256];
1023 memset(pixarr, 0, ncols*
sizeof(
PIX));
1024 PIX *px = &pixarr[0];
1029 for (
int i = 0;
i < 256;
i++) {
1031 px->r =
qRed (ctable[
i]);
1033 px->b =
qBlue (ctable[
i]);
1036 if (pop[
i] > maxpop) {
1041 px->mindist = 1000000;
1046 pixarr_sorted[0] = pixarr[maxpix];
1047 pixarr[maxpix].use = 0;
1049 for (
int i = 1;
i < ncols;
i++) {
1050 int minpix = -1, mindist = -1;
1051 px = &pixarr_sorted[
i-1];
1056 if ((
i & 1) ||
i<10) {
1057 for (
int j=0;
j<ncols;
j++) {
1060 dist = (px->r -
r)*(px->r -
r) +
1061 (px->g -
g)*(px->g -
g) +
1062 (px->b -
b)*(px->b -
b);
1063 if (px->mindist >
dist)
1065 if (px->mindist > mindist) {
1066 mindist = px->mindist;
1072 for (
int j=0;
j<ncols;
j++) {
1075 dist = (px->r -
r)*(px->r -
r) +
1076 (px->g -
g)*(px->g -
g) +
1077 (px->b -
b)*(px->b -
b);
1078 if (px->mindist >
dist)
1080 if (px->use > mindist) {
1087 pixarr_sorted[
i] = pixarr[minpix];
1088 pixarr[minpix].use = 0;
1093 px = &pixarr_sorted[0];
1094 for (
int i = 0;
i < ncols;
i++) {
1095 QColor c(px->r, px->g, px->b);
1101 for (
size_t i = 0;
i < nbytes;
i++) {
1108 xi = XCreateImage(dpy, visual, dd, ZPixmap, 0, 0,
w,
h, 32, 0);
1109 if (xi->bits_per_pixel == 16) {
1111 int p2inc = xi->bytes_per_line/
sizeof(
ushort);
1112 ushort *newerbits = (
ushort *)malloc(xi->bytes_per_line *
h);
1117 for (
int y = 0;
y <
h;
y++) {
1118 p2 = newerbits + p2inc*
y;
1119 for (
int x = 0;
x <
w;
x++)
1123 newbits = (
uchar *)newerbits;
1124 }
else if (xi->bits_per_pixel != 8) {
1125 qWarning(
"QPixmap::fromImage: Display not supported "
1126 "(bpp=%d)", xi->bits_per_pixel);
1128 xi->data = (
char *)newbits;
1131 hd = XCreatePixmap(dpy,
1132 RootWindow(dpy, xinfo.
screen()),
1135 GC gc = XCreateGC(dpy, hd, 0, 0);
1136 XPutImage(dpy, hd, gc, xi, 0, 0, 0, 0,
w,
h);
1142#if QT_CONFIG(xrender)
1143 if (
X11->use_xrender) {
1144 XRenderPictFormat *
format =
d == 1
1145 ? XRenderFindStandardFormat(dpy, PictStandardA1)
1146 : XRenderFindVisualFormat(dpy, (Visual *)xinfo.
visual());
1168 flags &= ~Uninitialized;
1169 xinfo = x11Data->xinfo;
1174 hd = XCreatePixmap(xinfo.
display(),
1177#if QT_CONFIG(xrender)
1178 if (
X11->use_xrender) {
1179 XRenderPictFormat *
format =
d == 32
1180 ? XRenderFindStandardFormat(xinfo.
display(), PictStandardARGB32)
1181 : XRenderFindVisualFormat(xinfo.
display(), (Visual *)xinfo.
visual());
1185 if (x11Data->x11_mask) {
1186 x11_mask = XCreatePixmap(xinfo.
display(), hd,
w,
h, 1);
1187#if QT_CONFIG(xrender)
1188 if (
X11->use_xrender) {
1189 mask_picture = XRenderCreatePicture(xinfo.
display(), x11_mask,
1190 XRenderFindStandardFormat(xinfo.
display(), PictStandardA1), 0, 0);
1191 XRenderPictureAttributes
attrs;
1192 attrs.alpha_map = x11Data->mask_picture;
1193 XRenderChangePicture(xinfo.
display(), x11Data->picture, CPAlphaMap, &
attrs);
1198#if QT_CONFIG(xrender)
1199 if (x11Data->picture && x11Data->
d == 32) {
1200 XRenderComposite(xinfo.
display(), PictOpSrc,
1206 GC gc = XCreateGC(xinfo.
display(), hd, 0, 0);
1207 XCopyArea(xinfo.
display(), x11Data->hd, hd, gc,
1209 if (x11Data->x11_mask) {
1210 GC monogc = XCreateGC(xinfo.
display(), x11_mask, 0, 0);
1211 XCopyArea(xinfo.
display(), x11Data->x11_mask, x11_mask, monogc,
1213 XFreeGC(xinfo.
display(), monogc);
1221 GC gc = XCreateGC(xinfo.
display(), hd, 0, 0);
1222 XCopyArea(xinfo.
display(), hd, hd, gc,
1224 rect.left() + dx,
rect.top() + dy);
1265 qWarning(
"QX11PlatformPixmap::metric(): Invalid metric");
1272 if (fillColor.
alpha() != 255) {
1273#if QT_CONFIG(xrender)
1274 if (
X11->use_xrender) {
1276 convertToARGB32(
false);
1293 GC gc = XCreateGC(xinfo.
display(), hd, 0, 0);
1295 XSetForeground(xinfo.
display(), gc,
qGray(fillColor.
rgb()) > 127 ? 0 : 1);
1296 }
else if (
X11->use_xrender &&
d >= 24) {
1297 XSetForeground(xinfo.
display(), gc, fillColor.
rgba());
1299 XSetForeground(xinfo.
display(), gc,
1309#if QT_CONFIG(xrender)
1327#if QT_CONFIG(xrender)
1332 XRenderComposite(xinfo.
display(), PictOpOver,
1334 0, 0, 0, 0, 0, 0,
w,
h);
1344 newData.x11_mask = 0;
1345 newData.picture = 0;
1346 newData.mask_picture = 0;
1351#if QT_CONFIG(xrender)
1353 XRenderPictureAttributes
attrs;
1354 attrs.alpha_map = 0;
1359 XRenderFreePicture(xinfo.
display(), mask_picture);
1362 XFreePixmap(xinfo.
display(), x11_mask);
1368#if QT_CONFIG(xrender)
1370 XRenderComposite(xinfo.
display(), PictOpSrc,
1377 vals.function = GXand;
1378 GC gc = XCreateGC(xinfo.
display(), hd, GCFunction, &vals);
1385 XFreePixmap(xinfo.
display(), x11_mask);
1386#if QT_CONFIG(xrender)
1388 XRenderFreePicture(xinfo.
display(), mask_picture);
1391 x11_mask = QX11PlatformPixmap::bitmap_to_mask(newmask, xinfo.
screen());
1392#if QT_CONFIG(xrender)
1394 mask_picture = XRenderCreatePicture(xinfo.
display(), x11_mask,
1395 XRenderFindStandardFormat(xinfo.
display(), PictStandardA1), 0, 0);
1396 XRenderPictureAttributes
attrs;
1397 attrs.alpha_map = mask_picture;
1409 if (x11_mask &&
d == 1)
1430 bool depth1 =
depth() == 1;
1439 bool complex_xform =
false;
1447 QRect r =
a.boundingRect().toAlignedRect();
1450 complex_xform =
true;
1457 if (
h == 0 ||
w == 0 || !invertible
1462 XImage *xi = XGetImage(xinfo.
display(),
handle(), 0, 0, ws, hs, AllPlanes,
1463 depth1 ? XYPixmap : ZPixmap);
1468 sbpl = xi->bytes_per_line;
1469 sptr = (
uchar *)xi->data;
1470 bpp = xi->bits_per_pixel;
1475 dbpl = ((
w*bpp+31)/32)*4;
1478 dptr = (
uchar *)malloc(dbytes);
1481 memset(dptr, 0, dbytes);
1483 memset(dptr, WhitePixel(xinfo.
display(), xinfo.
screen()), dbytes);
1485 memset(dptr, 0, dbytes);
1488#if defined(QT_DEBUG_XIMAGE)
1489 qDebug(
"----IMAGE--INFO--------------");
1490 qDebug(
"width............. %d", xi->width);
1491 qDebug(
"height............ %d", xi->height);
1492 qDebug(
"xoffset........... %d", xi->xoffset);
1493 qDebug(
"format............ %d", xi->format);
1494 qDebug(
"byte order........ %d", xi->byte_order);
1495 qDebug(
"bitmap unit....... %d", xi->bitmap_unit);
1496 qDebug(
"bitmap bit order.. %d", xi->bitmap_bit_order);
1497 qDebug(
"depth............. %d", xi->depth);
1498 qDebug(
"bytes per line.... %d", xi->bytes_per_line);
1499 qDebug(
"bits per pixel.... %d", xi->bits_per_pixel);
1503 if (xi->bitmap_bit_order == MSBFirst)
1510 p_inc = dbpl - xbpl;
1513 p_inc = dbpl - xbpl;
1516 if (!
qt_xForm_helper(mat, xi->xoffset,
type, bpp, dptr, xbpl, p_inc,
h, sptr, sbpl, ws, hs)){
1517 qWarning(
"QPixmap::transform: display not supported (bpp=%d)",bpp);
1527 BitmapBitOrder(xinfo.
display()) == MSBFirst
1536 x11Data->xinfo = xinfo;
1541 x11Data->hd = XCreatePixmap(xinfo.
display(),
1546#if QT_CONFIG(xrender)
1547 if (
X11->use_xrender) {
1548 XRenderPictFormat *
format = x11Data->
d == 32
1549 ? XRenderFindStandardFormat(xinfo.
display(), PictStandardARGB32)
1550 : XRenderFindVisualFormat(xinfo.
display(), (Visual *) x11Data->xinfo.
visual());
1551 x11Data->picture = XRenderCreatePicture(xinfo.
display(), x11Data->hd,
format, 0, 0);
1555 GC gc = XCreateGC(xinfo.
display(), x11Data->hd, 0, 0);
1556 xi = XCreateImage(dpy, (Visual*)x11Data->xinfo.
visual(),
1558 ZPixmap, 0, (
char *)dptr,
w,
h, 32, 0);
1565 }
else if (
d != 32 && complex_xform) {
1584 unsigned int width_return;
1585 unsigned int height_return;
1586 unsigned int border_width_return;
1587 unsigned int depth_return;
1589 XGetGeometry(xinfo.
display(), hd, &root_return, &x_return, &y_return, &width_return, &height_return, &border_width_return, &depth_return);
1593 AllPlanes, (
depth() == 1) ? XYPixmap : ZPixmap);
1599 if (!x11_mask && canTakeQImageFromXImage(xiWrapper))
1600 return takeQImageFromXImage(xiWrapper);
1607#if QT_CONFIG(xrender)
1608static XRenderPictFormat *qt_renderformat_for_depth(
const QXcbX11Info &xinfo,
int depth)
1611 return XRenderFindStandardFormat(xinfo.
display(), PictStandardA1);
1612 else if (
depth == 32)
1613 return XRenderFindStandardFormat(xinfo.
display(), PictStandardARGB32);
1615 return XRenderFindVisualFormat(xinfo.
display(), (Visual *)xinfo.
visual());
1625 if ((
flags & Readonly)) {
1630#if QT_CONFIG(xrender)
1632 XRenderPictFormat *
format = qt_renderformat_for_depth(xinfo,
d);
1637 XRenderComposite(xinfo.
display(), PictOpSrc,
picture, 0, picture_copy,
1638 0, 0, 0, 0, 0, 0,
w,
h);
1640 that->picture = picture_copy;
1644 GC gc = XCreateGC(xinfo.
display(), hd_copy, 0, 0);
1645 XCopyArea(xinfo.
display(), hd, hd_copy, gc, 0, 0,
w,
h, 0, 0);
1652 if (qt_x11_paintengine->isActive()) {
1656 return that->pengine;
1659 return qt_x11_paintengine();
1674#if QT_CONFIG(xrender)
1679 XRenderPictFormat *
format = XRenderFindVisualFormat(xinfo.
display(),
1680 (Visual*) xinfo.
visual());
1683 XNone, pic, 0, 0, 0, 0, 0, 0,
w,
h);
1684 XRenderFreePicture(xinfo.
display(), pic);
1697 if (
img.color(0) == c0 &&
img.color(1) == c1) {
1699 img.setColor(0, c1);
1700 img.setColor(1, c0);
1705 int w =
img.width();
1706 int h =
img.height();
1707 int bpl = (
w + 7) / 8;
1710 tmp_bits =
new uchar[bpl*
h];
1711 bits = (
char *)tmp_bits;
1715 p =
img.scanLine(0);
1716 for (
y = 0;
y <
h;
y++) {
1735 return (
flags & IsBackingStore);
1741 flags |= IsBackingStore;
1743 flags &= ~IsBackingStore;
1747#if QT_CONFIG(xrender)
1748void QX11PlatformPixmap::convertToARGB32(
bool preserveContents)
1750 if (!
X11->use_xrender)
1754 if ((
flags & Readonly))
1760 XRenderFindStandardFormat(xinfo.
display(), PictStandardARGB32), 0, 0);
1762 if (preserveContents)
1763 XRenderComposite(xinfo.
display(), PictOpSrc,
picture, 0,
p, 0, 0, 0, 0, 0, 0,
w,
h);
1764 if (!(
flags & Readonly))
1767 if (hd && !(
flags & Readonly))
1768 XFreePixmap(xinfo.
display(), hd);
1770 XFreePixmap(xinfo.
display(), x11_mask);
1772 XRenderFreePicture(xinfo.
display(), mask_picture);
1782 XVisualInfo visinfo;
1783 if (XMatchVisualInfo(xinfo.
display(), xinfo.
screen(), 32, TrueColor, &visinfo))
1788void QX11PlatformPixmap::release()
1800#if QT_CONFIG(xrender)
1802 XRenderFreePicture(xinfo.
display(), mask_picture);
1805 XFreePixmap(xinfo.
display(), x11_mask);
1810#if QT_CONFIG(xrender)
1818 XFreePixmap(xinfo.
display(), hd2);
1821 if (!(
flags & Readonly))
1822 XFreePixmap(xinfo.
display(), hd);
1829 XImage *xi = xiWrapper.
xi;
1832 Visual *visual = (Visual *)xinfo.
visual();
1833 bool trucol = (visual->c_class >= TrueColor) &&
d > 1;
1836 if (
d > 1 &&
d <= 8) {
1843 if (
d > 8 || trucol) {
1848 if (
d == 1 && xi->bitmap_bit_order == LSBFirst)
1868 const uint red_mask = (
uint)visual->red_mask;
1869 const uint green_mask = (
uint)visual->green_mask;
1870 const uint blue_mask = (
uint)visual->blue_mask;
1872 const int green_shift =
highest_bit(green_mask) - 7;
1873 const int blue_shift =
highest_bit(blue_mask) - 7;
1879 static uint red_table_bits = 0;
1880 static uint green_table_bits = 0;
1881 static uint blue_table_bits = 0;
1883 if (red_bits < 8 && red_table_bits != red_bits) {
1885 red_table_bits = red_bits;
1887 if (blue_bits < 8 && blue_table_bits != blue_bits) {
1889 blue_table_bits = blue_bits;
1891 if (green_bits < 8 && green_table_bits != green_bits) {
1893 green_table_bits = green_bits;
1901 int bppc = xi->bits_per_pixel;
1903 if (bppc > 8 && xi->byte_order == LSBFirst)
1906 for (
int y = 0;
y < xi->height; ++
y) {
1909 src = (
uchar *)xi->data + xi->bytes_per_line*
y;
1910 for (
int x = 0;
x < xi->width;
x++) {
1943 qWarning(
"QPixmap::convertToImage: Invalid depth %d", bppc);
1946 r = (pixel & red_mask) >> red_shift;
1948 r = (pixel & red_mask) << -red_shift;
1949 if (green_shift > 0)
1950 g = (pixel & green_mask) >> green_shift;
1952 g = (pixel & green_mask) << -green_shift;
1954 b = (pixel & blue_mask) >> blue_shift;
1956 b = (pixel & blue_mask) << -blue_shift;
1967 *
dst++ = (asrc[
x >> 3] & (1 << (
x & 7))) ?
qRgba(
r,
g,
b, 0xff) : 0;
1969 *
dst++ = (asrc[
x >> 3] & (0x80 >> (
x & 7))) ?
qRgba(
r,
g,
b, 0xff) : 0;
1976 }
else if (xi->bits_per_pixel ==
d) {
1977 char *xidata = xi->data;
1979 for (
int y=0;
y<xi->height;
y++) {
1980 memcpy(
image.scanLine(
y), xidata, bpl);
1981 xidata += xi->bytes_per_line;
1985 qWarning(
"QPixmap::convertToImage: Display not supported (bpp=%d)",
1986 xi->bits_per_pixel);
1991 image.setColorCount(2);
1994 }
else if (!trucol) {
2000 memset(use, 0, 256);
2001 memset(
pix, 0, 256);
2005 for (
int i = 0;
i < xi->height;
i++) {
2009 for (
int x = 0;
x < xi->width;
x++) {
2010 if (asrc[
x >> 3] & (1 << (
x & 7)))
2015 for (
int x = 0;
x < xi->width;
x++) {
2016 if (asrc[
x >> 3] & (0x80 >> (
x & 7)))
2023 for (
int i = 0;
i < xi->height;
i++) {
2031 for (
int i = 0;
i < 256;
i++) {
2035 for (
int i = 0;
i < xi->height;
i++) {
2047 image.setColorCount(ncols);
2048 image.setColor(trans, 0x00000000);
2050 image.setColorCount(ncols);
2053 trans =
image.scanLine(0)[0];
2055 for (
int i = 0;
i < xi->height;
i++) {
2059 for (
int x = 0;
x < xi->width;
x++) {
2060 if (!(asrc[
x >> 3] & (1 << (
x & 7))))
2065 for (
int x = 0;
x < xi->width;
x++) {
2066 if (!(asrc[
x >> 3] & (1 << (7 -(
x & 7)))))
2073 image.setColorCount(ncols);
T fetchAndAddRelaxed(T valueToAdd) noexcept
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.
QBitmap transformed(const QTransform &matrix) const
Returns a copy of this bitmap, transformed according to the given matrix.
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.
The QColor class provides colors based on RGB, HSV or CMYK values.
QRgb rgb() const noexcept
Returns the RGB value of the color.
QRgb rgba() const noexcept
Returns the RGB value of the color, including its alpha.
int alpha() const noexcept
Returns the alpha color component of this color.
static bool closingDown()
Returns true if the application objects are being destroyed; otherwise returns false.
static void executePlatformPixmapDestructionHooks(QPlatformPixmap *)
QList< QRgb > colorTable() const
Returns a list of the colors contained in the image's color table, or an empty list if the image does...
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
uchar * bits()
Returns a pointer to the first pixel data.
Format
The following image formats are available in Qt.
@ Format_ARGB32_Premultiplied
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Format format() const
Returns the format of the image.
int colorCount() const
Returns the depth of the image.
@ PdmDevicePixelRatioScaled
static qreal devicePixelRatioFScale()
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
QImage toImage() const
Converts the pixmap to a QImage.
static QTransform trueMatrix(const QTransform &m, int w, int h)
Returns the actual matrix used for transforming a pixmap with the given width, height and matrix.
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
void setMask(const QBitmap &)
Sets a mask bitmap.
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.
The QPolygonF class provides a list of points using floating point precision.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int width() const noexcept
Returns the width of the rectangle.
const QList< QColor > colormap() const
static QXcbColormap instance(int screen=-1)
uint pixel(const QColor &color) const
static QXcbX11Info fromScreen(int screen)
static Window appRootWindow(int screen=-1)
static int appDepth(int screen=-1)
void setVisual(void *visual)
static Display * display()
static int appDpiY(int screen=-1)
static int appDpiX(int screen=-1)
[Window class with invokable method]
Combined button and popup list for selecting options.
#define Q_BASIC_ATOMIC_INITIALIZER(a)
void qAddPostRoutine(QtCleanUpFunction p)
static constexpr int qt_div_255(int x)
static struct AttrInfo attrs[]
int qRound(qfloat16 d) noexcept
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
bool qt_xForm_helper(const QTransform &trueMat, int xoffset, int type, int depth, uchar *dptr, qsizetype dbpl, int p_inc, int dHeight, const uchar *sptr, qsizetype sbpl, int sWidth, int sHeight)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLint GLenum GLsizei GLsizei GLsizei depth
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
GLuint GLenum GLenum transform
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
GLfloat GLfloat GLfloat alpha
GLenum GLenum GLsizei void * table
const void * data_ptr(const QTransform &t)
#define GET_PIXEL_DITHER_TC
#define GET_PIXEL_DITHER_TC_OPT(red_shift, green_shift, blue_shift, red_mask, green_mask, blue_mask, rbits, gbits, bbits)
void qt_x11SetScreen(QPixmap &pixmap, int screen)
static void build_scale_table(uint **table, uint nBits)
static uint n_bits(uint v)
Drawable qt_x11Handle(const QPixmap &pixmap)
static uint * blue_scale_table
QBasicAtomicInt qt_pixmap_serial
static int highest_bit(uint v)
static uint * red_scale_table
int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth
QPixmap qt_toX11Pixmap(const QImage &image)
static void cleanup_scale_tables()
static uint * green_scale_table
static void qSafeXDestroyImage(XImage *x)
QT_BEGIN_NAMESPACE Q_ALWAYS_INLINE uint PREMUL(uint x)
int qt_x11SetDefaultScreen(int screen)
QX11PlatformPixmap * qt_x11Pixmap(const QPixmap &pixmap)
int qt_x11SetDefaultScreen(int screen)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
static QT_BEGIN_NAMESPACE const QRgb colors[][14]
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
constexpr QRgb qRgb(int r, int g, int b)
constexpr int qRed(QRgb rgb)
constexpr int qGreen(QRgb rgb)
constexpr int qGray(int r, int g, int b)
constexpr QRgb qRgba(int r, int g, int b, int a)
constexpr int qBlue(QRgb rgb)
constexpr int qAlpha(QRgb rgb)
constexpr int lowest_bit(T v) noexcept
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
unsigned long long quint64
QVideoFrameFormat::PixelFormat fmt
Q_CHECK_PTR(a=new int[80])
std::uniform_real_distribution dist(1, 2.5)
[2]
QX11AlphaDetector(const QImage *i, Qt::ImageConversionFlags flags)
bool hasXRenderAndAlpha() const