qWarning("setPixel: Out of memory");
return;
}
- const quint32 p = index_or_rgb;
switch(d->format) {
- case Format_Mono:
- case Format_MonoLSB:
- if (Q_UNLIKELY(index_or_rgb > 1)) {
- qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);
- } else if (format() == Format_MonoLSB) {
- if (index_or_rgb==0)
- *(s + (x >> 3)) &= ~(1 << (x & 7));
- else
- *(s + (x >> 3)) |= (1 << (x & 7));
- } else {
- if (index_or_rgb==0)
- *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
- else
- *(s + (x >> 3)) |= (1 << (7-(x & 7)));
+ case Format_Mono:
+ case Format_MonoLSB: {
+ if (Q_UNLIKELY(index_or_rgb > 1)) {
+ qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);
+ } else if (format() == Format_MonoLSB) {
+ if (index_or_rgb==0)
+ *(s + (x >> 3)) &= ~(1 << (x & 7));
+ else
+ *(s + (x >> 3)) |= (1 << (x & 7));
+ } else {
+ if (index_or_rgb==0)
+ *(s + (x >> 3)) &= ~(1 << (7-(x & 7)));
+ else
+ *(s + (x >> 3)) |= (1 << (7-(x & 7)));
+ }
+ break;
}
- break;
- case Format_Indexed8:
- if (Q_UNLIKELY(index_or_rgb >= (uint)d->colortable.size())) {
- qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);
- return;
+ case Format_Indexed8: {
+ if (Q_UNLIKELY(index_or_rgb >= (uint)d->colortable.size())) {
+ qWarning("QImage::setPixel: Index %d out of range", index_or_rgb);
+ return;
+ }
+ s[x] = index_or_rgb;
+ break;
+ }
+ case Format_RGB32: {
+ //make sure alpha is 255, we depend on it in qdrawhelper for cases
+ // when image is set as a texture pattern on a qbrush
+ ((uint *)s)[x] = uint(255 << 24) | index_or_rgb;
+ break;
+ }
+ case Format_ARGB32:
+ case Format_ARGB32_Premultiplied: {
+ ((uint *)s)[x] = index_or_rgb;
+ break;
+ }
+ case Format_RGB16: {
+ const quint32 p = index_or_rgb;
+ ((quint16 *)s)[x] = qt_colorConvert<quint16, quint32>(p, 0);
+ break;
+ }
+ case Format_Invalid:
+ case NImageFormats: {
+ Q_ASSERT(false);
}
- s[x] = index_or_rgb;
- break;
- case Format_RGB32:
- //make sure alpha is 255, we depend on it in qdrawhelper for cases
- // when image is set as a texture pattern on a qbrush
- ((uint *)s)[x] = uint(255 << 24) | index_or_rgb;
- break;
- case Format_ARGB32:
- case Format_ARGB32_Premultiplied:
- ((uint *)s)[x] = index_or_rgb;
- break;
- case Format_RGB16:
- ((quint16 *)s)[x] = qt_colorConvert<quint16, quint32>(p, 0);
- break;
- case Format_Invalid:
- case NImageFormats:
- Q_ASSERT(false);
}
}
}
}
#else
-
const int w = image.width();
const int h = image.height();
switch(image.format()) {
void QX11Data::copyXImageToQImage(XImage *ximage, QImage &image)
{
Q_ASSERT(ximage);
-
- for (int h = 0; h < ximage->height; h++) {
- for (int w = 0; w < ximage->width; w++) {
- const unsigned long xpixel = XGetPixel(ximage, w, h);
- image.setPixel(w, h, xpixel);
+ Q_ASSERT(ximage->width == image.width);
+ Q_ASSERT(ximage->height == image.height);
+
+ switch (image.format()) {
+ case QImage::Format_RGB32: {
+ uchar *imagedata = image.bits();
+ const int imagebpl = image.bytesPerLine();
+ for (int h = 0; h < ximage->height; h++) {
+ uchar* imageline = QFAST_SCAN_LINE(imagedata, imagebpl, h);
+ for (int w = 0; w < ximage->width; w++) {
+ const uint xpixel = XGetPixel(ximage, w, h);
+ //make sure alpha is 255, we depend on it in qdrawhelper for cases
+ // when image is set as a texture pattern on a qbrush
+ ((uint *)imageline)[w] = uint(255 << 24) | xpixel;
+ }
+ }
+ break;
+ }
+ case QImage::Format_ARGB32:
+ case QImage::Format_ARGB32_Premultiplied: {
+ uchar *imagedata = image.bits();
+ const int imagebpl = image.bytesPerLine();
+ for (int h = 0; h < ximage->height; h++) {
+ uchar* imageline = QFAST_SCAN_LINE(imagedata, imagebpl, h);
+ for (int w = 0; w < ximage->width; w++) {
+ const uint xpixel = XGetPixel(ximage, w, h);
+ ((uint *)imageline)[w] = xpixel;
+ }
+ }
+ break;
+ }
+ case QImage::Format_RGB16: {
+ uchar *imagedata = image.bits();
+ const int imagebpl = image.bytesPerLine();
+ for (int h = 0; h < ximage->height; h++) {
+ uchar* imageline = QFAST_SCAN_LINE(imagedata, imagebpl, h);
+ for (int w = 0; w < ximage->width; w++) {
+ const quint32 xpixel = XGetPixel(ximage, w, h);
+ ((quint16 *)imageline)[w] = qt_colorConvert<quint16, quint32>(xpixel, 0);
+ }
+ }
+ break;
+ }
+ default: {
+ for (int h = 0; h < ximage->height; h++) {
+ for (int w = 0; w < ximage->width; w++) {
+ const unsigned long xpixel = XGetPixel(ximage, w, h);
+ image.setPixel(w, h, xpixel);
+ }
+ }
+ break;
}
}
}