equal
deleted
inserted
replaced
414 w = img.width(); |
414 w = img.width(); |
415 h = img.height(); |
415 h = img.height(); |
416 d = img.depth(); |
416 d = img.depth(); |
417 is_null = (w <= 0 || h <= 0); |
417 is_null = (w <= 0 || h <= 0); |
418 |
418 |
|
419 if (is_null) { |
|
420 w = h = 0; |
|
421 return; |
|
422 } |
|
423 |
419 if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { |
424 if (defaultScreen >= 0 && defaultScreen != xinfo.screen()) { |
420 QX11InfoData* xd = xinfo.getX11Data(true); |
425 QX11InfoData* xd = xinfo.getX11Data(true); |
421 xd->screen = defaultScreen; |
426 xd->screen = defaultScreen; |
422 xd->depth = QX11Info::appDepth(xd->screen); |
427 xd->depth = QX11Info::appDepth(xd->screen); |
423 xd->cells = QX11Info::appCells(xd->screen); |
428 xd->cells = QX11Info::appCells(xd->screen); |
462 | Qt::PreferDither; |
467 | Qt::PreferDither; |
463 conv8 = true; |
468 conv8 = true; |
464 } else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) { |
469 } else if ((flags & Qt::ColorMode_Mask) == Qt::ColorOnly) { |
465 conv8 = (d == 1); // native depth wanted |
470 conv8 = (d == 1); // native depth wanted |
466 } else if (d == 1) { |
471 } else if (d == 1) { |
467 if (image.numColors() == 2) { |
472 if (image.colorCount() == 2) { |
468 QRgb c0 = image.color(0); // Auto: convert to best |
473 QRgb c0 = image.color(0); // Auto: convert to best |
469 QRgb c1 = image.color(1); |
474 QRgb c1 = image.color(1); |
470 conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255); |
475 conv8 = qMin(c0,c1) != qRgb(0,0,0) || qMax(c0,c1) != qRgb(255,255,255); |
471 } else { |
476 } else { |
472 // eg. 1-color monochrome images (they do exist). |
477 // eg. 1-color monochrome images (they do exist). |
487 |
492 |
488 Display *dpy = X11->display; |
493 Display *dpy = X11->display; |
489 Visual *visual = (Visual *)xinfo.visual(); |
494 Visual *visual = (Visual *)xinfo.visual(); |
490 XImage *xi = 0; |
495 XImage *xi = 0; |
491 bool trucol = (visual->c_class >= TrueColor); |
496 bool trucol = (visual->c_class >= TrueColor); |
492 int nbytes = image.numBytes(); |
497 int nbytes = image.byteCount(); |
493 uchar *newbits= 0; |
498 uchar *newbits= 0; |
494 |
499 |
495 #ifndef QT_NO_XRENDER |
500 #ifndef QT_NO_XRENDER |
496 if (alphaCheck.hasXRenderAndAlpha()) { |
501 if (alphaCheck.hasXRenderAndAlpha()) { |
497 const QImage &cimage = image; |
502 const QImage &cimage = image; |
629 const uint gbits = highest_bit(green_mask) - lowest_bit(green_mask) + 1; |
634 const uint gbits = highest_bit(green_mask) - lowest_bit(green_mask) + 1; |
630 const uint bbits = highest_bit(blue_mask) - lowest_bit(blue_mask) + 1; |
635 const uint bbits = highest_bit(blue_mask) - lowest_bit(blue_mask) + 1; |
631 |
636 |
632 if (d8) { // setup pixel translation |
637 if (d8) { // setup pixel translation |
633 QVector<QRgb> ctable = cimage.colorTable(); |
638 QVector<QRgb> ctable = cimage.colorTable(); |
634 for (int i=0; i < cimage.numColors(); i++) { |
639 for (int i=0; i < cimage.colorCount(); i++) { |
635 int r = qRed (ctable[i]); |
640 int r = qRed (ctable[i]); |
636 int g = qGreen(ctable[i]); |
641 int g = qGreen(ctable[i]); |
637 int b = qBlue (ctable[i]); |
642 int b = qBlue (ctable[i]); |
638 r = red_shift > 0 ? r << red_shift : r >> -red_shift; |
643 r = red_shift > 0 ? r << red_shift : r >> -red_shift; |
639 g = green_shift > 0 ? g << green_shift : g >> -green_shift; |
644 g = green_shift > 0 ? g << green_shift : g >> -green_shift; |
955 } |
960 } |
956 |
961 |
957 if (d == 8 && !trucol) { // 8 bit pixmap |
962 if (d == 8 && !trucol) { // 8 bit pixmap |
958 int pop[256]; // pixel popularity |
963 int pop[256]; // pixel popularity |
959 |
964 |
960 if (image.numColors() == 0) |
965 if (image.colorCount() == 0) |
961 image.setNumColors(1); |
966 image.setColorCount(1); |
962 |
967 |
963 const QImage &cimage = image; |
968 const QImage &cimage = image; |
964 memset(pop, 0, sizeof(int)*256); // reset popularity array |
969 memset(pop, 0, sizeof(int)*256); // reset popularity array |
965 for (int i = 0; i < h; i++) { // for each scanline... |
970 for (int i = 0; i < h; i++) { // for each scanline... |
966 const uchar* p = cimage.scanLine(i); |
971 const uchar* p = cimage.scanLine(i); |
986 int use; // popularity |
991 int use; // popularity |
987 int index; // index in colormap |
992 int index; // index in colormap |
988 int mindist; |
993 int mindist; |
989 }; |
994 }; |
990 int ncols = 0; |
995 int ncols = 0; |
991 for (int i=0; i< cimage.numColors(); i++) { // compute number of colors |
996 for (int i=0; i< cimage.colorCount(); i++) { // compute number of colors |
992 if (pop[i] > 0) |
997 if (pop[i] > 0) |
993 ncols++; |
998 ncols++; |
994 } |
999 } |
995 for (int i = cimage.numColors(); i < 256; i++) // ignore out-of-range pixels |
1000 for (int i = cimage.colorCount(); i < 256; i++) // ignore out-of-range pixels |
996 pop[i] = 0; |
1001 pop[i] = 0; |
997 |
1002 |
998 // works since we make sure above to have at least |
1003 // works since we make sure above to have at least |
999 // one color in the image |
1004 // one color in the image |
1000 if (ncols == 0) |
1005 if (ncols == 0) |
1649 xi->bits_per_pixel); |
1654 xi->bits_per_pixel); |
1650 return QImage(); |
1655 return QImage(); |
1651 } |
1656 } |
1652 |
1657 |
1653 if (d == 1) { // bitmap |
1658 if (d == 1) { // bitmap |
1654 image.setNumColors(2); |
1659 image.setColorCount(2); |
1655 image.setColor(0, qRgb(255,255,255)); |
1660 image.setColor(0, qRgb(255,255,255)); |
1656 image.setColor(1, qRgb(0,0,0)); |
1661 image.setColor(1, qRgb(0,0,0)); |
1657 } else if (!trucol) { // pixmap with colormap |
1662 } else if (!trucol) { // pixmap with colormap |
1658 register uchar *p; |
1663 register uchar *p; |
1659 uchar *end; |
1664 uchar *end; |
1705 } |
1710 } |
1706 if (x11_mask) { |
1711 if (x11_mask) { |
1707 int trans; |
1712 int trans; |
1708 if (ncols < 256) { |
1713 if (ncols < 256) { |
1709 trans = ncols++; |
1714 trans = ncols++; |
1710 image.setNumColors(ncols); // create color table |
1715 image.setColorCount(ncols); // create color table |
1711 image.setColor(trans, 0x00000000); |
1716 image.setColor(trans, 0x00000000); |
1712 } else { |
1717 } else { |
1713 image.setNumColors(ncols); // create color table |
1718 image.setColorCount(ncols); // create color table |
1714 // oh dear... no spare "transparent" pixel. |
1719 // oh dear... no spare "transparent" pixel. |
1715 // use first pixel in image (as good as any). |
1720 // use first pixel in image (as good as any). |
1716 trans = image.scanLine(0)[0]; |
1721 trans = image.scanLine(0)[0]; |
1717 } |
1722 } |
1718 for (int i = 0; i < h; i++) { |
1723 for (int i = 0; i < h; i++) { |
1731 ++p; |
1736 ++p; |
1732 } |
1737 } |
1733 } |
1738 } |
1734 } |
1739 } |
1735 } else { |
1740 } else { |
1736 image.setNumColors(ncols); // create color table |
1741 image.setColorCount(ncols); // create color table |
1737 } |
1742 } |
1738 QVector<QColor> colors = QColormap::instance(xinfo.screen()).colormap(); |
1743 QVector<QColor> colors = QColormap::instance(xinfo.screen()).colormap(); |
1739 int j = 0; |
1744 int j = 0; |
1740 for (int i=0; i<colors.size(); i++) { // translate pixels |
1745 for (int i=0; i<colors.size(); i++) { // translate pixels |
1741 if (use[i]) |
1746 if (use[i]) |
1914 ? QImage::Format_Mono |
1919 ? QImage::Format_Mono |
1915 : QImage::Format_MonoLSB); |
1920 : QImage::Format_MonoLSB); |
1916 free(dptr); |
1921 free(dptr); |
1917 return bm; |
1922 return bm; |
1918 } else { // color pixmap |
1923 } else { // color pixmap |
1919 QPixmap pm; |
1924 QX11PixmapData *x11Data = new QX11PixmapData(QPixmapData::PixmapType); |
1920 QX11PixmapData *x11Data = static_cast<QX11PixmapData*>(pm.data.data()); |
1925 QPixmap pm(x11Data); |
1921 x11Data->flags &= ~QX11PixmapData::Uninitialized; |
1926 x11Data->flags &= ~QX11PixmapData::Uninitialized; |
1922 x11Data->xinfo = xinfo; |
1927 x11Data->xinfo = xinfo; |
1923 x11Data->d = d; |
1928 x11Data->d = d; |
1924 x11Data->w = w; |
1929 x11Data->w = w; |
1925 x11Data->h = h; |
1930 x11Data->h = h; |
1974 if (paintingActive()) { |
1979 if (paintingActive()) { |
1975 qWarning("QPixmap::x11SetScreen(): Cannot change screens during painting"); |
1980 qWarning("QPixmap::x11SetScreen(): Cannot change screens during painting"); |
1976 return; |
1981 return; |
1977 } |
1982 } |
1978 |
1983 |
|
1984 if (isNull()) |
|
1985 return; |
|
1986 |
1979 if (data->classId() != QPixmapData::X11Class) |
1987 if (data->classId() != QPixmapData::X11Class) |
1980 return; |
1988 return; |
1981 |
1989 |
1982 if (screen < 0) |
1990 if (screen < 0) |
1983 screen = QX11Info::appScreen(); |
1991 screen = QX11Info::appScreen(); |
2076 return d == 32; |
2084 return d == 32; |
2077 } |
2085 } |
2078 |
2086 |
2079 const QX11Info &QPixmap::x11Info() const |
2087 const QX11Info &QPixmap::x11Info() const |
2080 { |
2088 { |
2081 if (data->classId() == QPixmapData::X11Class) |
2089 if (data && data->classId() == QPixmapData::X11Class) |
2082 return static_cast<QX11PixmapData*>(data.data())->xinfo; |
2090 return static_cast<QX11PixmapData*>(data.data())->xinfo; |
2083 else { |
2091 else { |
2084 static QX11Info nullX11Info; |
2092 static QX11Info nullX11Info; |
2085 return nullX11Info; |
2093 return nullX11Info; |
2086 } |
2094 } |
2133 } |
2141 } |
2134 |
2142 |
2135 Qt::HANDLE QPixmap::x11PictureHandle() const |
2143 Qt::HANDLE QPixmap::x11PictureHandle() const |
2136 { |
2144 { |
2137 #ifndef QT_NO_XRENDER |
2145 #ifndef QT_NO_XRENDER |
2138 if (data->classId() == QPixmapData::X11Class) |
2146 if (data && data->classId() == QPixmapData::X11Class) |
2139 return static_cast<const QX11PixmapData*>(data.data())->picture; |
2147 return static_cast<const QX11PixmapData*>(data.data())->picture; |
2140 else |
2148 else |
2141 return 0; |
2149 return 0; |
2142 #else |
2150 #else |
2143 return 0; |
2151 return 0; |