diff options
author | Michael Dominic K <mdk@codethink.co.uk> | 2010-10-22 15:48:03 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2010-10-22 15:48:03 (GMT) |
commit | ccfa6f282fc7a4c258c83844433f04a6380e4055 (patch) | |
tree | c3f853feff19287f5e41cb2cb92f1cfea1b60074 /src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp | |
parent | 9d81ddd3da51166a9fc92073cf7ba508cdd22dd1 (diff) | |
download | Qt-ccfa6f282fc7a4c258c83844433f04a6380e4055.zip Qt-ccfa6f282fc7a4c258c83844433f04a6380e4055.tar.gz Qt-ccfa6f282fc7a4c258c83844433f04a6380e4055.tar.bz2 |
For meego graphics system, use floyd-steinberg dithering when converting to 16bit.
Merge-request: 2496
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp')
-rw-r--r-- | src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp b/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp index 0899f2d..02a4273 100644 --- a/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp +++ b/src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp @@ -48,28 +48,14 @@ #include <private/qapplication_p.h> #include <private/qgraphicssystem_runtime_p.h> +// from dithering.cpp +extern unsigned short* convertRGB32_to_RGB565(const unsigned char *in, int width, int height, int stride); +extern unsigned short* convertARGB32_to_RGBA4444(const unsigned char *in, int width, int height, int stride); + static EGLint preserved_image_attribs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE }; QHash <void*, QMeeGoImageInfo*> QMeeGoPixmapData::sharedImagesMap; -// This helper method converts (in place) a QImage::Format_ARGB4444_Premultiplied to -// GL-friendly Format_RGBA4444_Premultiplied. Just swaps the bits around really. -static void qARGBA4ToRGBA4(QImage *image) -{ - unsigned char *raw = static_cast <unsigned char *> (image->data_ptr()->data); - // FIXME image.bytesPerLine() is broken. Returns 512 for 128x128 image while it should - // return 256 - int bytesPerLine = image->width() * 2; - - for (int y = 0; y < image->height(); y++) { - for (int x = 0; x < image->width(); x++) { - unsigned short *target = (unsigned short *) (raw + (y * bytesPerLine + (x * 2))); - // FIXME Oh yeah, that's broken with endianness. - *target = (*target << 4) | (* target >> 12); - } - } -} - /* Public */ QMeeGoPixmapData::QMeeGoPixmapData() : QGLPixmapData(QPixmapData::PixmapType) @@ -160,12 +146,13 @@ Qt::HANDLE QMeeGoPixmapData::imageToEGLSharedImage(const QImage &image) glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); if (image.hasAlphaChannel() && const_cast<QImage &>(image).data_ptr()->checkForAlphaPixels()) { - QImage convertedImage = image.convertToFormat(QImage::Format_ARGB4444_Premultiplied, Qt::DiffuseAlphaDither | Qt::DiffuseDither | Qt::PreferDither); - qARGBA4ToRGBA4(&convertedImage); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, convertedImage.bits()); + void *converted = convertARGB32_to_RGBA4444(image.bits(), image.width(), image.height(), image.bytesPerLine()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, converted); + free(converted); } else { - QImage convertedImage = image.convertToFormat(QImage::Format_RGB16, Qt::DiffuseAlphaDither | Qt::DiffuseDither | Qt::PreferDither); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, convertedImage.bits()); + void *converted = convertRGB32_to_RGB565(image.bits(), image.width(), image.height(), image.bytesPerLine()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, converted); + free(converted); } glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |