52 #if defined(Q_OS_WIN32) && defined(QT_MITSHM) 56 #include "qplatformdefs.h" 66 #include <private/qpaintengine_x11_p.h> 67 #include <private/qt_x11_p.h> 69 #include <private/qdrawhelper_p.h> 70 #include <private/qimage_p.h> 71 #include <private/qimagepixmapcleanuphooks_p.h> 75 #if defined(Q_CC_MIPS) 76 # define for if(0){}else for 120 QPixmap::x11SetDefaultScreen(screen);
122 GC gc = XCreateGC(
X11->display, bm.
handle(), 0, 0);
125 XFreeGC(
X11->display, gc);
134 bm.x11SetScreen(screen);
136 Pixmap
mask = XCreatePixmap(
X11->display, RootWindow(
X11->display, screen),
138 GC gc = XCreateGC(
X11->display, mask, 0, 0);
141 XFreeGC(
X11->display, gc);
150 #if defined(QT_MITSHM) 152 static bool xshminit =
false;
153 static XShmSegmentInfo xshminfo;
154 static XImage *xshmimg = 0;
155 static Pixmap xshmpm = 0;
157 static void qt_cleanup_mitshm()
161 Display *dpy = QX11Info::appDisplay();
163 XFreePixmap(dpy, xshmpm);
166 XShmDetach(dpy, &xshminfo); xshmimg->data = 0;
168 shmdt(xshminfo.shmaddr);
169 shmctl(xshminfo.shmid, IPC_RMID, 0);
172 static bool qt_create_mitshm_buffer(
const QPaintDevice* dev,
int w,
int h)
174 static int major, minor;
175 static Bool pixmaps_ok;
176 Display *dpy = dev->data->xinfo->display();
177 int dd = dev->x11Depth();
178 Visual *vis = (Visual*)dev->x11Visual();
183 if (!XShmQueryVersion(dpy, &major, &minor, &pixmaps_ok))
189 xshmimg = XShmCreateImage(dpy, vis, dd, ZPixmap, 0, &xshminfo,
w, h);
194 xshminfo.shmid = shmget(IPC_PRIVATE,
195 xshmimg->bytes_per_line * xshmimg->height,
197 ok = xshminfo.shmid != -1;
199 xshmimg->data = (
char*)shmat(xshminfo.shmid, 0, 0);
200 xshminfo.shmaddr = xshmimg->data;
201 ok = (xshminfo.shmaddr != (
char*)-1);
203 xshminfo.readOnly =
false;
205 ok = XShmAttach(dpy, &xshminfo);
209 if (xshminfo.shmaddr)
210 shmdt(xshminfo.shmaddr);
211 if (xshminfo.shmid != -1)
212 shmctl(xshminfo.shmid, IPC_RMID, 0);
216 xshmpm = XShmCreatePixmap(dpy, DefaultRootWindow(dpy), xshmimg->data,
217 &xshminfo,
w, h, dd);
245 for (i=31; ((b & v) == 0) && i>=0; i--)
256 for (i=0; ((v & lb) == 0) && i<32; i++, lb<<=1) {}
257 return i==32 ? -1 : i;
289 qWarning(
"build_scale_table: internal error, nBits = %i", nBits);
293 static bool firstTable =
true;
298 *table =
new uint[256];
300 int maxVal = (1 << nBits) - 1;
301 int valShift = 8 - nBits;
303 for(i = 0 ; i < maxVal + 1 ; i++)
304 (*table)[i << valShift] = i*255/maxVal;
353 bool make_null = w <= 0 ||
h <= 0;
355 if (make_null ||
d == 0) {
363 qWarning(
"QPixmap: Invalid pixmap parameters");
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);
376 #endif // QT_NO_XRENDER 386 has = image->isNull() ? false :
const_cast<QImage *
>(image)->
data_ptr()->checkForAlphaPixels();
391 if (!
X11->use_xrender)
397 : image(i), checked(false), has(false)
401 has = image->hasAlphaChannel();
411 Qt::ImageConversionFlags
flags)
442 if (
uint(w) >= 32768 ||
uint(
h) >= 32768) {
465 if (
d > 8 && dd <= 8) {
488 if (
d == 1 ||
d == 16 ||
d == 24) {
497 bool trucol = (visual->c_class >= TrueColor);
501 #ifndef QT_NO_XRENDER 503 const QImage &cimage = image;
526 XRenderFindStandardFormat(
X11->display, PictStandardARGB32), 0, 0);
528 xi = XCreateImage(dpy, visual,
d, ZPixmap, 0, 0, w,
h, 32, 0);
530 newbits = (
uchar *)malloc(xi->bytes_per_line*
h);
532 xi->data = (
char *)newbits;
538 for (
int y = 0; y <
h; ++y) {
540 for (
int x = 0; x <
w; ++x) {
541 const QRgb rgb = colorTable[p[x]];
558 for (
int y = 0; y <
h; ++y) {
560 for (
int x = 0; x <
w; ++x)
561 *xidata++ = p[x] | 0xff000000;
567 for (
int y = 0; y <
h; ++y) {
569 for (
int x = 0; x <
w; ++x) {
588 for (
int y = 0; y <
h; ++y) {
590 memcpy(xidata, p, w*
sizeof(
QRgb));
599 if ((xi->byte_order == MSBFirst) != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) {
601 uint *xiend = xidata + w*
h;
602 while (xidata < xiend) {
603 *xidata = (*xidata >> 24)
604 | ((*xidata >> 8) & 0xff00)
605 | ((*xidata << 8) & 0xff0000)
611 GC gc = XCreateGC(dpy,
hd, 0, 0);
612 XPutImage(dpy,
hd, gc, xi, 0, 0, 0, 0, w,
h);
619 #endif // QT_NO_XRENDER 625 const QImage &cimage = image;
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;
632 const int green_shift =
highest_bit(green_mask) - 7;
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);
652 xi = XCreateImage(dpy, visual, dd, ZPixmap, 0, 0, w,
h, 32, 0);
654 newbits = (
uchar *)malloc(xi->bytes_per_line*
h);
658 int bppc = xi->bits_per_pixel;
660 bool contig_bits =
n_bits(red_mask) == rbits &&
661 n_bits(green_mask) == gbits &&
662 n_bits(blue_mask) == bbits;
672 static bool init=
false;
673 static int D[16][16];
674 if (dither_tc && !init) {
696 for (n=2; n<16; n*=2) {
697 for (i=0; i<n; i++) {
698 for (j=0; j<n; j++) {
702 D[i+n][j+n]=D[i][j]+1;
710 BPP16_565, BPP16_555,
711 BPP16_MSB, BPP16_LSB,
713 BPP24_MSB, BPP24_LSB,
718 bool same_msb_lsb = (xi->byte_order == MSBFirst) == (QSysInfo::ByteOrder == QSysInfo::BigEndian);
722 else if(bppc == 16) {
723 if(red_shift == 8 && green_shift == 3 && blue_shift == -3 && !d8 && same_msb_lsb)
725 else if(red_shift == 7 && green_shift == 2 && blue_shift == -3 && !d8 && same_msb_lsb)
728 mode = (xi->byte_order == LSBFirst) ? BPP16_LSB : BPP16_MSB;
729 }
else if(bppc == 24) {
730 if (red_shift == 16 && green_shift == 8 && blue_shift == 0 && !d8 && same_msb_lsb)
733 mode = (xi->byte_order == LSBFirst) ? BPP24_LSB : BPP24_MSB;
734 }
else if(bppc == 32) {
735 if(red_shift == 16 && green_shift == 8 && blue_shift == 0 && !d8 && same_msb_lsb)
738 mode = (xi->byte_order == LSBFirst) ? BPP32_LSB : BPP32_MSB;
744 if (d8) pixel = pix[*src++]; \ 747 int g = qGreen(*p); \ 748 int b = qBlue (*p++); \ 750 ? r << red_shift : r >> -red_shift; \ 751 g = green_shift > 0 \ 752 ? g << green_shift : g >> -green_shift; \ 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); \ 759 #define GET_PIXEL_DITHER_TC \ 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) \ 766 r += (1<<(8-rbits)); \ 767 if (g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \ 769 g += (1<<(8-gbits)); \ 770 if (b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \ 772 b += (1<<(8-bbits)); \ 774 ? r << red_shift : r >> -red_shift; \ 775 g = green_shift > 0 \ 776 ? g << green_shift : g >> -green_shift; \ 778 ? b << blue_shift : b >> -blue_shift; \ 779 uint pixel = (r & red_mask)|(g & green_mask) | (b & blue_mask); 783 #define GET_PIXEL_DITHER_TC_OPT(red_shift,green_shift,blue_shift,red_mask,green_mask,blue_mask, \ 785 const int thres = D[x%16][y%16]; \ 787 if (r <= (255-(1<<(8-rbits))) && ((r<<rbits) & 255) \ 789 r += (1<<(8-rbits)); \ 790 int g = qGreen(*p); \ 791 if (g <= (255-(1<<(8-gbits))) && ((g<<gbits) & 255) \ 793 g += (1<<(8-gbits)); \ 794 int b = qBlue (*p++); \ 795 if (b <= (255-(1<<(8-bbits))) && ((b<<bbits) & 255) \ 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); 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; \ 815 for (
int x=0; x<
w; x++) {
824 for (
int x=0; x<
w; x++) {
832 for (
int x=0; x<
w; x++) {
834 *dst++ = (pixel >> 8);
841 for (
int x=0; x<
w; x++) {
856 for (
int x=0; x<
w; x++)
857 *dst++ = pix[*src++];
863 for (
int x = 0; x <
w; x++) {
864 *dst16++ = ((*p >> 8) & 0xf800)
865 | ((*p >> 5) & 0x7e0)
866 | ((*p >> 3) & 0x1f);
874 for (
int x=0; x<
w; x++) {
875 *dst16++ = ((*p >> 9) & 0x7c00)
876 | ((*p >> 6) & 0x3e0)
877 | ((*p >> 3) & 0x1f);
884 for (
int x=0; x<
w; x++) {
886 *dst++ = (pixel >> 8);
893 for (
int x=0; x<
w; x++) {
902 if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
903 for (
int x=0; x<
w; x++) {
906 *dst++ =
qBlue (*p++);
909 for (
int x=0; x<
w; x++) {
912 *dst++ =
qRed (*p++);
919 for (
int x=0; x<
w; x++) {
921 *dst++ = pixel >> 16;
929 for (
int x=0; x<
w; x++) {
933 *dst++ = pixel >> 16;
939 memcpy(dst, p, w * 4);
944 for (
int x=0; x<
w; x++) {
946 *dst++ = pixel >> 24;
947 *dst++ = pixel >> 16;
955 for (
int x=0; x<
w; x++) {
959 *dst++ = pixel >> 16;
960 *dst++ = pixel >> 24;
968 xi->data = (
char *)newbits;
971 if (
d == 8 && !trucol) {
977 const QImage &cimage = image;
978 memset(pop, 0,
sizeof(
int)*256);
979 for (
int i = 0; i <
h; i++) {
986 newbits = (
uchar *)malloc(nbytes);
991 memcpy(p, cimage.
bits(), nbytes);
1009 for (
int i = cimage.
colorCount(); i < 256; i++)
1018 PIX pixarr_sorted[256];
1019 memset(pixarr, 0, ncols*
sizeof(
PIX));
1020 PIX *px = &pixarr[0];
1025 for (
int i = 0; i < 256; i++) {
1027 px->r =
qRed (ctable[i]);
1028 px->g =
qGreen(ctable[i]);
1029 px->b =
qBlue (ctable[i]);
1032 if (pop[i] > maxpop) {
1037 px->mindist = 1000000;
1042 pixarr_sorted[0] = pixarr[maxpix];
1043 pixarr[maxpix].use = 0;
1045 for (
int i = 1; i < ncols; i++) {
1046 int minpix = -1, mindist = -1;
1047 px = &pixarr_sorted[i-1];
1052 if ((i & 1) || i<10) {
1053 for (
int j=0; j<ncols; j++) {
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)
1061 if (px->mindist > mindist) {
1062 mindist = px->mindist;
1068 for (
int j=0; j<ncols; j++) {
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)
1076 if (px->use > mindist) {
1083 pixarr_sorted[i] = pixarr[minpix];
1084 pixarr[minpix].use = 0;
1089 px = &pixarr_sorted[0];
1090 for (
int i = 0; i < ncols; i++) {
1091 QColor c(px->r, px->g, px->b);
1092 pix[px->index] = cmap.
pixel(c);
1097 for (
int i = 0; i < nbytes; i++) {
1104 xi = XCreateImage(dpy, visual, dd, ZPixmap, 0, 0, w,
h, 32, 0);
1105 if (xi->bits_per_pixel == 16) {
1107 int p2inc = xi->bytes_per_line/
sizeof(
ushort);
1108 ushort *newerbits = (
ushort *)malloc(xi->bytes_per_line *
h);
1113 for (
int y = 0; y <
h; y++) {
1114 p2 = newerbits + p2inc*y;
1115 for (
int x = 0; x <
w; x++)
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);
1124 xi->data = (
char *)newbits;
1131 GC gc = XCreateGC(dpy,
hd, 0, 0);
1132 XPutImage(dpy,
hd, gc, xi, 0, 0, 0, 0, w,
h);
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);
1158 if (img.
color(0) == c0 && img.
color(1) == c1) {
1168 int bpl = (w + 7) / 8;
1171 tmp_bits =
new uchar[bpl*
h];
1172 bits = (
char *)tmp_bits;
1177 for (y = 0; y <
h; y++) {
1183 bits = (
char *)img.
bits();
1201 #ifndef QT_NO_XRENDER 1202 if (
X11->use_xrender)
1204 XRenderFindStandardFormat(
X11->display, PictStandardA1), 0, 0);
1205 #endif // QT_NO_XRENDER 1210 if (fillColor.
alpha() != 255) {
1211 #ifndef QT_NO_XRENDER 1212 if (
X11->use_xrender) {
1217 XRenderComposite(
X11->display, PictOpSrc, src, 0,
picture,
1231 GC gc = XCreateGC(
X11->display,
hd, 0, 0);
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());
1237 XSetForeground(
X11->display, gc,
1241 XFreeGC(
X11->display, gc);
1267 #ifndef QT_NO_XRENDER 1277 #ifndef QT_NO_XRENDER 1282 #endif // QT_NO_XRENDER 1317 #ifndef QT_NO_XRENDER 1356 #ifndef QT_NO_XRENDER 1361 XRenderComposite(
X11->display, PictOpOver,
1363 0, 0, 0, 0, 0, 0,
w,
h);
1380 #ifndef QT_NO_XRENDER 1382 XRenderPictureAttributes attrs;
1383 attrs.alpha_map = 0;
1384 XRenderChangePicture(
X11->display,
picture, CPAlphaMap,
1397 #ifndef QT_NO_XRENDER 1399 XRenderComposite(
X11->display, PictOpSrc,
1400 picture, newmask.x11PictureHandle(),
1406 vals.function = GXand;
1407 GC gc = XCreateGC(
X11->display,
hd, GCFunction, &vals);
1408 XCopyArea(
X11->display, newmask.
handle(),
hd, gc, 0, 0,
1410 XFreeGC(
X11->display, gc);
1415 #ifndef QT_NO_XRENDER 1421 #ifndef QT_NO_XRENDER 1424 XRenderFindStandardFormat(
X11->display, PictStandardA1), 0, 0);
1425 XRenderPictureAttributes attrs;
1427 XRenderChangePicture(
X11->display,
picture, CPAlphaMap, &attrs);
1446 const int mm = DisplayWidthMM(
X11->display, screen) *
w 1447 / DisplayWidth(
X11->display, screen);
1452 const int mm = (DisplayHeightMM(
X11->display, screen) *
h)
1453 / DisplayHeight(
X11->display, screen);
1463 qWarning(
"QX11PixmapData::metric(): Invalid metric");
1475 XImage *xi = xiWrapper.
xi;
1484 if (
depth() == 24 && xi->bits_per_pixel == 32 && visual->red_mask == 0xff0000
1485 && visual->green_mask == 0xff00 && visual->blue_mask == 0xff)
1489 if (
depth() == 16 && xi->bits_per_pixel == 16 && visual->red_mask == 0xf800
1490 && visual->green_mask == 0x7e0 && visual->blue_mask == 0x1f)
1498 XImage *xi = xiWrapper.
xi;
1503 else if (
depth() == 16)
1506 QImage image((
uchar *)xi->data, xi->width, xi->height, xi->bytes_per_line, format);
1512 if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst)
1513 || (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst))
1515 for (
int i=0; i < image.
height(); i++) {
1516 if (
depth() == 16) {
1520 *p = ((*p << 8) & 0xff00) | ((*p >> 8) & 0x00ff);
1527 *p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000)
1528 | ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff);
1538 for (
int y = 0; y < xi->height; ++y) {
1539 for (
int x = 0; x < xi->width; ++x)
1541 p += xi->bytes_per_line / 4;
1553 AllPlanes, (
depth() == 1) ? XYPixmap : ZPixmap);
1589 XImage *xi = xiWrapper.
xi;
1593 bool trucol = (visual->c_class >= TrueColor) && d > 1;
1596 if (d > 1 && d <= 8) {
1603 if (d > 8 || trucol) {
1608 if (d == 1 && xi->bitmap_bit_order == LSBFirst)
1613 QImage image(xi->width, xi->height, format);
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;
1631 const int green_shift =
highest_bit(green_mask) - 7;
1632 const int blue_shift =
highest_bit(blue_mask) - 7;
1638 static uint red_table_bits = 0;
1639 static uint green_table_bits = 0;
1640 static uint blue_table_bits = 0;
1642 if (red_bits < 8 && red_table_bits != red_bits) {
1644 red_table_bits = red_bits;
1646 if (blue_bits < 8 && blue_table_bits != blue_bits) {
1648 blue_table_bits = blue_bits;
1650 if (green_bits < 8 && green_table_bits != green_bits) {
1652 green_table_bits = green_bits;
1660 int bppc = xi->bits_per_pixel;
1662 if (bppc > 8 && xi->byte_order == LSBFirst)
1665 for (
int y = 0; y < xi->height; ++y) {
1668 src = (
uchar *)xi->data + xi->bytes_per_line*y;
1669 for (
int x = 0; x < xi->width; x++) {
1675 pixel = src[1] | (
uint)src[0] << 8;
1679 pixel = src[0] | (
uint)src[1] << 8;
1683 pixel = src[2] | (
uint)src[1] << 8 | (
uint)src[0] << 16;
1687 pixel = src[0] | (
uint)src[1] << 8 | (
uint)src[2] << 16;
1691 pixel = src[3] | (
uint)src[2] << 8 | (
uint)src[1] << 16 | (
uint)src[0] << 24;
1695 pixel = src[0] | (
uint)src[1] << 8 | (
uint)src[2] << 16 | (
uint)src[3] << 24;
1702 qWarning(
"QPixmap::convertToImage: Invalid depth %d", bppc);
1705 r = (pixel & red_mask) >> red_shift;
1707 r = (pixel & red_mask) << -red_shift;
1708 if (green_shift > 0)
1709 g = (pixel & green_mask) >> green_shift;
1711 g = (pixel & green_mask) << -green_shift;
1713 b = (pixel & blue_mask) >> blue_shift;
1715 b = (pixel & blue_mask) << -blue_shift;
1726 *dst++ = (asrc[x >> 3] & (1 << (x & 7))) ?
qRgba(r, g, b, 0xff) : 0;
1728 *dst++ = (asrc[x >> 3] & (0x80 >> (x & 7))) ?
qRgba(r, g, b, 0xff) : 0;
1731 *dst++ =
qRgb(r, g, b);
1735 }
else if (xi->bits_per_pixel == d) {
1736 char *xidata = xi->data;
1738 for (
int y=0; y<xi->height; y++) {
1739 memcpy(image.
scanLine(y), xidata, bpl);
1740 xidata += xi->bytes_per_line;
1744 qWarning(
"QPixmap::convertToImage: Display not supported (bpp=%d)",
1745 xi->bits_per_pixel);
1753 }
else if (!trucol) {
1759 memset(use, 0, 256);
1760 memset(pix, 0, 256);
1764 for (
int i = 0; i < xi->height; i++) {
1768 for (
int x = 0; x < xi->width; x++) {
1769 if (asrc[x >> 3] & (1 << (x & 7)))
1774 for (
int x = 0; x < xi->width; x++) {
1775 if (asrc[x >> 3] & (0x80 >> (x & 7)))
1782 for (
int i = 0; i < xi->height; i++) {
1790 for (
int i = 0; i < 256; i++) {
1794 for (
int i = 0; i < xi->height; i++) {
1814 for (
int i = 0; i < xi->height; i++) {
1818 for (
int x = 0; x < xi->width; x++) {
1819 if (!(asrc[x >> 3] & (1 << (x & 7))))
1824 for (
int x = 0; x < xi->width; x++) {
1825 if (!(asrc[x >> 3] & (1 << (7 -(x & 7)))))
1836 for (
int i=0; i<colors.
size(); i++) {
1879 bool depth1 =
depth() == 1;
1886 transform.
m21(), transform.
m22(), transform.
m23(),
1888 bool complex_xform =
false;
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));
1905 complex_xform =
true;
1910 mat = mat.inverted(&invertible);
1912 if (h == 0 || w == 0 || !invertible
1913 ||
qAbs(scaledWidth) >= 32768 ||
qAbs(scaledHeight) >= 32768 )
1917 #if defined(QT_MITSHM) 1918 static bool try_once =
true;
1922 qt_create_mitshm_buffer(
this, 800, 600);
1925 bool use_mitshm = xshmimg && !depth1 &&
1926 xshmimg->width >= w && xshmimg->height >=
h;
1928 XImage *xi = XGetImage(
X11->display,
handle(), 0, 0, ws, hs, AllPlanes,
1929 depth1 ? XYPixmap : ZPixmap);
1934 sbpl = xi->bytes_per_line;
1935 sptr = (
uchar *)xi->data;
1936 bpp = xi->bits_per_pixel;
1941 dbpl = ((w*bpp+31)/32)*4;
1944 #if defined(QT_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);
1952 dptr = (
uchar *)malloc(dbytes);
1955 memset(dptr, 0, dbytes);
1959 memset(dptr, 0, dbytes);
1960 #if defined(QT_MITSHM) 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);
1980 if (xi->bitmap_bit_order == MSBFirst)
1987 p_inc = dbpl - xbpl;
1990 p_inc = dbpl - xbpl;
1991 #if defined(QT_MITSHM) 1993 p_inc = xshmimg->bytes_per_line - xbpl;
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);
2007 BitmapBitOrder(
X11->display) == MSBFirst
2020 x11Data->
is_null = (w <= 0 || h <= 0);
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);
2033 #endif // QT_NO_XRENDER 2035 GC gc = XCreateGC(
X11->display, x11Data->
hd, 0, 0);
2036 #if defined(QT_MITSHM) 2038 XCopyArea(dpy, xshmpm, x11Data->
hd, gc, 0, 0, w, h, 0, 0);
2042 xi = XCreateImage(dpy, (Visual*)x11Data->
xinfo.
visual(),
2044 ZPixmap, 0, (
char *)dptr, w, h, 32, 0);
2045 XPutImage(dpy, pm.
handle(), gc, xi, 0, 0, 0, 0,
w,
h);
2048 XFreeGC(
X11->display, gc);
2052 }
else if (
d != 32 && complex_xform) {
2061 int QPixmap::x11SetDefaultScreen(
int screen)
2068 void QPixmap::x11SetScreen(
int screen)
2070 if (paintingActive()) {
2071 qWarning(
"QPixmap::x11SetScreen(): Cannot change screens during painting");
2104 x11SetDefaultScreen(screen);
2110 if (
w == 0 || h == 0)
2114 XWindowAttributes window_attr;
2115 if (!XGetWindowAttributes(dpy,
window, &window_attr))
2119 w = window_attr.width - x;
2121 h = window_attr.height - y;
2125 for (scr = 0; scr < ScreenCount(dpy); ++scr) {
2126 if (window_attr.root == RootWindow(dpy, scr))
2129 if (scr >= ScreenCount(dpy))
2134 XWindowAttributes root_attr;
2135 if (!XGetWindowAttributes(dpy, window_attr.root, &root_attr))
2138 if (window_attr.depth == root_attr.depth) {
2145 if (!XTranslateCoordinates(dpy,
window, window_attr.root, x, y,
2149 window = window_attr.root;
2150 window_attr = root_attr;
2163 pm.x11SetScreen(scr);
2165 GC gc = XCreateGC(dpy, pm.
handle(), 0, 0);
2166 XSetSubwindowMode(dpy, gc, IncludeInferiors);
2178 const QX11Info &QPixmap::x11Info()
const 2181 return static_cast<QX11PixmapData*>(
data.data())->
xinfo;
2188 #if !defined(QT_NO_XRENDER) 2192 return XRenderFindStandardFormat(
X11->display, PictStandardA1);
2193 else if (depth == 32)
2194 return XRenderFindStandardFormat(
X11->display, PictStandardARGB32);
2196 return XRenderFindVisualFormat(
X11->display, (Visual *)xinfo.
visual());
2207 ::Pixmap hd_copy = XCreatePixmap(
X11->display, RootWindow(
X11->display,
xinfo.
screen()),
2209 #if !defined(QT_NO_XRENDER) 2211 ::Picture picture_copy = XRenderCreatePicture(
X11->display, hd_copy, format, 0, 0);
2214 XRenderComposite(
X11->display, PictOpSrc,
picture, 0, picture_copy,
2215 0, 0, 0, 0, 0, 0,
w,
h);
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);
2236 #ifndef QT_NO_XRENDER 2238 return static_cast<const QX11PixmapData*>(
data.data())->
picture;
2243 #endif // QT_NO_XRENDER 2248 #ifndef QT_NO_XRENDER 2257 XNone, pic, 0, 0, 0, 0, 0, 0,
w,
h);
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);
2293 #endif // QT_NO_XRENDER 2296 #ifndef QT_NO_XRENDER 2297 if (
X11->use_xrender) {
2299 XRenderFindStandardFormat(
X11->display, PictStandardA1), 0, 0);
2300 XRenderPictureAttributes attrs;
2302 XRenderChangePicture(
X11->display, x11Data->
picture, CPAlphaMap, &attrs);
2307 #if !defined(QT_NO_XRENDER) 2308 if (x11Data->
picture && x11Data->
d == 32) {
2309 XRenderComposite(
X11->display, PictOpSrc,
2311 rect.
x(), rect.
y(), 0, 0, 0, 0,
w,
h);
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);
2321 rect.
x(), rect.
y(),
w,
h, 0, 0);
2322 XFreeGC(
X11->display, monogc);
2324 XFreeGC(
X11->display, gc);
2330 GC gc = XCreateGC(
X11->display,
hd, 0, 0);
2331 XCopyArea(
X11->display,
hd,
hd, gc,
2333 rect.
left() + dx, rect.
top() + dy);
2334 XFreeGC(
X11->display, gc);
2338 #if !defined(QT_NO_XRENDER) 2341 if (!
X11->use_xrender)
2348 Pixmap pm = XCreatePixmap(
X11->display, RootWindow(
X11->display,
xinfo.
screen()),
2350 Picture p = XRenderCreatePicture(
X11->display, pm,
2351 XRenderFindStandardFormat(
X11->display, PictStandardARGB32), 0, 0);
2353 if (preserveContents)
2354 XRenderComposite(
X11->display, PictOpSrc,
picture, 0, p, 0, 0, 0, 0, 0, 0,
w,
h);
2355 if (!(
flags & Readonly))
2358 if (
hd && !(
flags & Readonly))
2359 XFreePixmap(
X11->display,
hd);
2382 XWindowAttributes win_attribs;
2383 int num_screens = ScreenCount(
X11->display);
2386 XGetGeometry(
X11->display, pixmap, &root, &x, &y, &width, &height, &border_width, &depth);
2387 XGetWindowAttributes(
X11->display, root, &win_attribs);
2389 for (; screen < num_screens; ++screen) {
2390 if (win_attribs.screen == ScreenOfDisplay(
X11->display, screen))
2400 data->
is_null = (width <= 0 || height <= 0);
2416 #ifndef QT_NO_XRENDER 2417 if (
X11->use_xrender) {
2419 data->
picture = XRenderCreatePicture(
X11->display, data->
hd, format, 0, 0);
2421 #endif // QT_NO_XRENDER The QColor class provides colors based on RGB, HSV or CMYK values.
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
int depth() const
Returns the color depth (bits per pixel) of the X display.
static Qt::HANDLE createBitmapFromImage(const QImage &image)
QImage toImage() const
Converts the pixmap to a QImage.
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.
Format
The following image formats are available in Qt.
static QColormap instance(int screen=-1)
QImage copy(const QRect &rect=QRect()) const
Returns a sub-area of the image as a new image.
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
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...
#define QT_END_NAMESPACE
This macro expands to.
Q_CORE_EXPORT QTextStream & ws(QTextStream &s)
int width() const
Returns the width of the pixmap.
static int appScreen()
Returns the number of the screen where the application is being displayed.
QX11PaintEngine * pengine
void qAddPostRoutine(QtCleanUpFunction p)
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
static int appDepth(int screen=-1)
Returns the color depth (bits per pixel) used by the application on the given screen.
QPixmap qt_toX11Pixmap(const QImage &image)
void setMask(const QBitmap &)
Sets a mask bitmap.
static bool appDefaultVisual(int screen=-1)
Returns true if the application has a default visual on the given screen; otherwise returns false...
bool isNull() const
Returns true if it is a null image, otherwise returns false.
void fill(uint pixel)
Fills the entire image with the given pixelValue.
static Qt::HANDLE appRootWindow(int screen=-1)
Returns a handle for the applications root window on the given screen.
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.
static int highest_bit(uint v)
int left() const
Returns the x-coordinate of the rectangle's left edge.
int byteCount() const
Returns the number of bytes occupied by the image data.
int width() const
Returns the width of the rectangle.
QPixmapData * createCompatiblePixmapData() const
const uchar * qt_get_bitflip_array()
Qt::HANDLE handle() const
Returns the pixmap's handle to the device context.
int bytesPerLine() const
Returns the number of bytes per image scanline.
long ASN1_INTEGER_get ASN1_INTEGER * a
QPixmap::ShareMode share_mode
static void qSafeXDestroyImage(XImage *x)
QX11AlphaDetector(const QImage *i, Qt::ImageConversionFlags flags)
bool ref()
Atomically increments the value of this QAtomicInt.
static int lowest_bit(uint v)
void resize(int width, int height)
int height() const
Returns the height of the rectangle.
QBasicAtomicInt qt_pixmap_serial
Q_DECL_CONSTEXPR T qAbs(const T &t)
QRectF boundingRect() const
Returns the bounding rectangle of the polygon, or QRectF(0,0,0,0) if the polygon is empty...
#define Q_BASIC_ATOMIC_INITIALIZER(a)
QBitmap transformed(const QMatrix &) const
This convenience function converts the matrix to a QTransform and calls the overloaded function...
void fromImage(const QImage &image, Qt::ImageConversionFlags flags)
void setAlphaChannel(const QPixmap &alphaChannel)
static void executePixmapDataDestructionHooks(QPixmapData *)
Format format() const
Returns the format of the image.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Q_GUI_EXPORT_INLINE int qRed(QRgb rgb)
static uint n_bits(uint v)
Q_CORE_EXPORT void qDebug(const char *,...)
friend class QX11PaintEngine
PixelType pixelType() const
QX11InfoData * getX11Data(bool def=false) const
The QBitmap class provides monochrome (1-bit depth) pixmaps.
QPaintEngine * paintEngine() const
virtual QImage toImage() const =0
void setColorCount(int)
Resizes the color table to contain colorCount entries.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
The QRectF class defines a rectangle in the plane using floating point precision. ...
int metric(QPaintDevice::PaintDeviceMetric metric) const
static Qt::HANDLE bitmap_to_mask(const QBitmap &, int screen)
static uint * blue_scale_table
Qt::HANDLE handle() const
bool scroll(int dx, int dy, const QRect &rect)
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
virtual void fromImage(const QImage &image, Qt::ImageConversionFlags flags)=0
static int appDpiX(int screen=-1)
Returns the horizontal resolution of the given screen in terms of the number of dots per inch...
The QPolygonF class provides a vector of points using floating point precision.
Q_CORE_EXPORT void qWarning(const char *,...)
The QImage class provides a hardware-independent image representation that allows direct access to th...
void convertToARGB32(bool preserveContents=true)
static bool appDefaultColormap(int screen=-1)
Returns true if the application has a default color map on the given screen; otherwise returns false...
static const char * data(const QByteArray &arr)
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...
QImage createAlphaMask(Qt::ImageConversionFlags flags=Qt::AutoColor) const
Builds and returns a 1-bpp mask from the alpha buffer in this image.
#define QT_XFORM_TYPE_MSBFIRST
static uint * green_scale_table
int depth() const
Returns the depth of the image.
static XRenderPictFormat * qt_renderformat_for_depth(const QX11Info &xinfo, int depth)
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...
static Qt::HANDLE appColormap(int screen=-1)
Returns a handle for the application's color map on the given screen.
void copy(const QPixmapData *data, const QRect &rect)
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Q_GUI_EXPORT_INLINE int qBlue(QRgb rgb)
#define QT_XFORM_TYPE_LSBFIRST
uint pixel(const QColor &color) const
QImage alphaChannel() const
Returns the alpha channel of the image as a new grayscale QImage in which each pixel's red...
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...
const T & at(int i) const
Returns the item at index position i in the vector.
QPixmap alphaChannel() const
int Q_GUI_EXPORT qt_x11_preferred_pixmap_depth
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
uchar * bits()
Returns a pointer to the first pixel data.
Q_CORE_EXPORT void qFatal(const char *,...)
static uint * red_scale_table
int top() const
Returns the y-coordinate of the rectangle's top edge.
int width() const
Returns the width of the image.
QImage toImage() const
Converts the pixmap to a QImage.
The QX11Info class provides information about the X display configuration.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
#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.
void fill(const QColor &color)
ushort alpha
Returns the alpha color component of this color.
int y() const
Returns the y-coordinate of the rectangle's top edge.
bool hasAlphaChannel() const
int colorCount() const
Returns the size of the color table for the image.
static void * appVisual(int screen=-1)
Returns the current visual used by the application on the given screen.
void * data_ptr(const QTransform &t)
int x() const
Returns the x-coordinate of the rectangle's left edge.
Q_GUI_EXPORT_INLINE QRgb qRgb(int r, int g, int b)
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)
if(void) toggleToolbarShown
The QRect class defines a rectangle in the plane using integer precision.
int fetchAndAddRelaxed(int valueToAdd)
int height() const
Returns the height of the image.
QImage takeQImageFromXImage(const QXImageWrapper &xi) const
The QPixmap class is an off-screen image representation that can be used as a paint device...
Q_GUI_EXPORT_INLINE int qGreen(QRgb rgb)
static void build_scale_table(uint **table, uint nBits)
Q_STATIC_INLINE_FUNCTION int qt_div_255(int x)
#define GET_PIXEL_DITHER_TC
int height() const
Returns the height of the pixmap.
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...
The QSize class defines the size of a two-dimensional object using integer point precision.
T * data()
Returns a pointer to the data stored in the vector.
static QPixmap grabWindow(WId, int x=0, int y=0, int w=-1, int h=-1)
Creates and returns a pixmap constructed by grabbing the contents of the given window restricted by Q...
void invertPixels(InvertMode=InvertRgb)
Inverts all pixel values in the image.
void setX11Data(const QX11InfoData *)
Makes a shallow copy of the X11-specific data d and assigns it to this class.
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
void setAlphaChannel(const QImage &alphaChannel)
Sets the alpha channel of this image to the given alphaChannel.
void bitmapFromImage(const QImage &image)
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
void setSerialNumber(int serNo)
static const KeyPair *const end
bool hasXRenderAndAlpha() const
bool canTakeQImageFromXImage(const QXImageWrapper &xi) const
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...
int size() const
Returns the number of items in the vector.
Qt::HANDLE x11ConvertToDefaultDepth()
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image's color table, or an empty list if the image does...
QRgb color(int i) const
Returns the color in the color table at index i.
QRgb rgb() const
Returns the RGB value of the color.
static Display * display()
Returns the default display for the application.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
static void cleanup_scale_tables()
int screen() const
Returns the number of the screen currently in use.
QX11PixmapData(PixelType type)
static int appDpiY(int screen=-1)
Returns the vertical resolution of the given screen in terms of the number of dots per inch...