summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/activeqt/shared/qaxtypes.cpp2
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp2
-rw-r--r--src/gui/kernel/qstandardgestures.cpp19
-rw-r--r--src/opengl/qgl.cpp2
-rw-r--r--src/opengl/qgl_egl.cpp4
-rw-r--r--src/opengl/qgl_p.h2
-rw-r--r--src/opengl/qwindowsurface_gl.cpp139
-rw-r--r--src/opengl/qwindowsurface_gl_p.h1
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp36
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbscreen.h1
-rw-r--r--src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp9
-rw-r--r--src/plugins/graphicssystems/meego/dithering.cpp267
-rw-r--r--src/plugins/graphicssystems/meego/meego.pro2
-rw-r--r--src/plugins/graphicssystems/meego/qmeegopixmapdata.cpp33
14 files changed, 405 insertions, 114 deletions
diff --git a/src/activeqt/shared/qaxtypes.cpp b/src/activeqt/shared/qaxtypes.cpp
index ff21a9f..88f408e 100644
--- a/src/activeqt/shared/qaxtypes.cpp
+++ b/src/activeqt/shared/qaxtypes.cpp
@@ -547,7 +547,7 @@ bool QVariantToVARIANT(const QVariant &var, VARIANT &arg, const QByteArray &type
SAFEARRAY *array = 0;
bool is2D = false;
// If the first element in the array is a list the whole list is
- // treated as a 2D array. The colum count is taken from the 1st element.
+ // treated as a 2D array. The column count is taken from the 1st element.
if (count) {
QVariantList col = list.at(0).toList();
int maxColumns = col.count();
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index d83f7ee..69e9219 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -695,7 +695,7 @@ bool QFSFileEnginePrivate::doStat() const
} else if (fd == -1) {
// ### actually covers two cases: d->fh and when the file is not open
#if defined(Q_OS_SYMBIAN)
- // Optimisation for Symbian where fileFlags() calls both doStat() and isSymlink(), but rarely on real links.
+ // Optimization for Symbian where fileFlags() calls both doStat() and isSymlink(), but rarely on real links.
// When the filename is not a link, lstat will return the same info as stat, but this also removes
// any need for a further call to lstat to check if the file is a link.
need_lstat = false;
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp
index 893ba2b..1821c3d 100644
--- a/src/gui/kernel/qstandardgestures.cpp
+++ b/src/gui/kernel/qstandardgestures.cpp
@@ -198,25 +198,22 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
d->startPosition[0] = p1.screenPos();
d->startPosition[1] = p2.screenPos();
}
- QLineF line(p1.screenPos(), p2.screenPos());
- QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
- QLineF tmp(line);
- tmp.setLength(line.length() / 2.);
- QPointF centerPoint = tmp.p2();
d->lastCenterPoint = d->centerPoint;
- d->centerPoint = centerPoint;
- d->changeFlags |= QPinchGesture::CenterPointChanged;
+ d->centerPoint = (p1.screenPos() + p2.screenPos()) / 2.0;
- const qreal scaleFactor = line.length() / lastLine.length();
+ d->changeFlags |= QPinchGesture::CenterPointChanged;
if (d->isNewSequence) {
- d->lastScaleFactor = scaleFactor;
+ d->scaleFactor = 1.0;
+ d->lastScaleFactor = 1.0;
} else {
d->lastScaleFactor = d->scaleFactor;
+ QLineF line(p1.screenPos(), p2.screenPos());
+ QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
+ d->scaleFactor = line.length() / lastLine.length();
}
- d->scaleFactor = scaleFactor;
- d->totalScaleFactor = d->totalScaleFactor * scaleFactor;
+ d->totalScaleFactor = d->totalScaleFactor * d->scaleFactor;
d->changeFlags |= QPinchGesture::ScaleFactorChanged;
qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle();
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 62eff6e..dbd295f 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -2104,7 +2104,7 @@ void QGLContextPrivate::syncGlState()
#undef ctx
#ifdef QT_NO_EGL
-void QGLContextPrivate::swapRegion(const QRegion *)
+void QGLContextPrivate::swapRegion(const QRegion &)
{
Q_Q(QGLContext);
q->swapBuffers();
diff --git a/src/opengl/qgl_egl.cpp b/src/opengl/qgl_egl.cpp
index c79c4cd..27f7ad9 100644
--- a/src/opengl/qgl_egl.cpp
+++ b/src/opengl/qgl_egl.cpp
@@ -276,12 +276,12 @@ EGLSurface QGLContextPrivate::eglSurfaceForDevice() const
return eglSurface;
}
-void QGLContextPrivate::swapRegion(const QRegion *region)
+void QGLContextPrivate::swapRegion(const QRegion &region)
{
if (!valid || !eglContext)
return;
- eglContext->swapBuffersRegion2NOK(eglSurfaceForDevice(), region);
+ eglContext->swapBuffersRegion2NOK(eglSurfaceForDevice(), &region);
}
void QGLWidget::setMouseTracking(bool enable)
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index 6c494ee..f86c77f 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -343,7 +343,7 @@ public:
void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true);
void syncGlState(); // Makes sure the GL context's state is what we think it is
- void swapRegion(const QRegion *region);
+ void swapRegion(const QRegion &region);
#if defined(Q_WS_WIN)
void updateFormatVersion();
diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp
index 68d444e..bbb98d0 100644
--- a/src/opengl/qwindowsurface_gl.cpp
+++ b/src/opengl/qwindowsurface_gl.cpp
@@ -275,6 +275,8 @@ struct QGLWindowSurfacePrivate
QRegion paintedRegion;
QSize size;
+ QSize textureSize;
+
QList<QImage> buffers;
QGLWindowSurfaceGLPaintDevice glDevice;
QGLWindowSurface* q_ptr;
@@ -316,6 +318,7 @@ QGLWindowSurface::QGLWindowSurface(QWidget *window)
d_ptr->pb = 0;
d_ptr->fbo = 0;
d_ptr->ctx = 0;
+ d_ptr->tex_id = 0;
#if defined (QT_OPENGL_ES_2)
d_ptr->tried_fbo = true;
d_ptr->tried_pb = true;
@@ -433,7 +436,7 @@ static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize,
void QGLWindowSurface::beginPaint(const QRegion &)
{
- if (! context())
+ if (!context())
return;
int clearFlags = 0;
@@ -457,13 +460,42 @@ void QGLWindowSurface::endPaint(const QRegion &rgn)
d_ptr->buffers.clear();
}
-void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
+static void blitTexture(QGLContext *ctx, GLuint texture, const QSize &viewport, const QSize &texSize, const QRect &targetRect, const QRect &sourceRect)
{
- if (context() && widget != window()) {
- qWarning("No native child widget support in GL window surface without FBOs or pixel buffers");
- return;
- }
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_SCISSOR_TEST);
+ glDisable(GL_BLEND);
+
+ glViewport(0, 0, viewport.width(), viewport.height());
+
+ QGLShaderProgram *blitProgram =
+ QGLEngineSharedShaders::shadersForContext(ctx)->blitProgram();
+ blitProgram->bind();
+ blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/);
+
+ // The shader manager's blit program does not multiply the
+ // vertices by the pmv matrix, so we need to do the effect
+ // of the orthographic projection here ourselves.
+ QRectF r;
+ qreal w = viewport.width();
+ qreal h = viewport.height();
+ r.setLeft((targetRect.left() / w) * 2.0f - 1.0f);
+ if (targetRect.right() == (viewport.width() - 1))
+ r.setRight(1.0f);
+ else
+ r.setRight((targetRect.right() / w) * 2.0f - 1.0f);
+ r.setBottom((targetRect.top() / h) * 2.0f - 1.0f);
+ if (targetRect.bottom() == (viewport.height() - 1))
+ r.setTop(1.0f);
+ else
+ r.setTop((targetRect.bottom() / w) * 2.0f - 1.0f);
+
+ drawTexture(r, texture, texSize, sourceRect);
+}
+
+void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
+{
//### Find out why d_ptr->geometry_updated isn't always false.
// flush() should not be called when d_ptr->geometry_updated is true. It assumes that either
// d_ptr->fbo or d_ptr->pb is allocated and has the correct size.
@@ -534,12 +566,29 @@ void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &
}
}
#endif
- if (hasPartialUpdateSupport() &&
- d_ptr->paintedRegion.boundingRect().width() * d_ptr->paintedRegion.boundingRect().height() <
- geometry().width() * geometry().height() * 0.2) {
- context()->d_func()->swapRegion(&d_ptr->paintedRegion);
- } else
- context()->swapBuffers();
+ bool doingPartialUpdate = hasPartialUpdateSupport() && br.width() * br.height() < parent->geometry().width() * parent->geometry().height() * 0.2;
+ QGLContext *ctx = reinterpret_cast<QGLContext *>(parent->d_func()->extraData()->glContext);
+ if (widget != window()) {
+ if (initializeOffscreenTexture(window()->size()))
+ qWarning() << "QGLWindowSurface: Flushing to native child widget, may lead to significant performance loss";
+ glBindTexture(target, d_ptr->tex_id);
+
+ const uint bottom = window()->height() - (br.y() + br.height());
+ glCopyTexSubImage2D(target, 0, br.x(), bottom, br.x(), bottom, br.width(), br.height());
+
+ glBindTexture(target, 0);
+
+ ctx->makeCurrent();
+ if (doingPartialUpdate)
+ blitTexture(ctx, d_ptr->tex_id, parent->size(), window()->size(), rect, br);
+ else
+ blitTexture(ctx, d_ptr->tex_id, parent->size(), window()->size(), parent->rect(), parent->rect().translated(offset + wOffset));
+ }
+
+ if (doingPartialUpdate)
+ ctx->d_func()->swapRegion(br);
+ else
+ ctx->swapBuffers();
d_ptr->paintedRegion = QRegion();
} else {
@@ -665,38 +714,10 @@ void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &
else if (d_ptr->fbo) {
Q_UNUSED(target);
- GLuint texture = d_ptr->fbo->texture();
-
- glDisable(GL_DEPTH_TEST);
-
if (d_ptr->fbo->isBound())
d_ptr->fbo->release();
- glViewport(0, 0, size.width(), size.height());
-
- QGLShaderProgram *blitProgram =
- QGLEngineSharedShaders::shadersForContext(ctx)->blitProgram();
- blitProgram->bind();
- blitProgram->setUniformValue("imageTexture", 0 /*QT_IMAGE_TEXTURE_UNIT*/);
-
- // The shader manager's blit program does not multiply the
- // vertices by the pmv matrix, so we need to do the effect
- // of the orthographic projection here ourselves.
- QRectF r;
- qreal w = size.width() ? size.width() : 1.0f;
- qreal h = size.height() ? size.height() : 1.0f;
- r.setLeft((rect.left() / w) * 2.0f - 1.0f);
- if (rect.right() == (size.width() - 1))
- r.setRight(1.0f);
- else
- r.setRight((rect.right() / w) * 2.0f - 1.0f);
- r.setBottom((rect.top() / h) * 2.0f - 1.0f);
- if (rect.bottom() == (size.height() - 1))
- r.setTop(1.0f);
- else
- r.setTop((rect.bottom() / w) * 2.0f - 1.0f);
-
- drawTexture(r, texture, window()->size(), br);
+ blitTexture(ctx, d_ptr->fbo->texture(), size, window()->size(), rect, br);
}
#endif
@@ -719,7 +740,6 @@ void QGLWindowSurface::updateGeometry() {
return;
d_ptr->geometry_updated = false;
-
QRect rect = geometry();
hijackWindow(window());
QGLContext *ctx = reinterpret_cast<QGLContext *>(window()->d_func()->extraData()->glContext);
@@ -740,11 +760,8 @@ void QGLWindowSurface::updateGeometry() {
if (d_ptr->ctx) {
#ifndef QT_OPENGL_ES_2
- if (d_ptr->destructive_swap_buffers) {
- glBindTexture(target, d_ptr->tex_id);
- glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
- glBindTexture(target, 0);
- }
+ if (d_ptr->destructive_swap_buffers)
+ initializeOffscreenTexture(rect.size());
#endif
return;
}
@@ -824,15 +841,8 @@ void QGLWindowSurface::updateGeometry() {
ctx->makeCurrent();
#ifndef QT_OPENGL_ES_2
- if (d_ptr->destructive_swap_buffers) {
- glGenTextures(1, &d_ptr->tex_id);
- glBindTexture(target, d_ptr->tex_id);
- glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
-
- glTexParameterf(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glBindTexture(target, 0);
- }
+ if (d_ptr->destructive_swap_buffers)
+ initializeOffscreenTexture(rect.size());
#endif
qDebug() << "QGLWindowSurface: Using plain widget as window surface" << this;;
@@ -840,6 +850,23 @@ void QGLWindowSurface::updateGeometry() {
d_ptr->ctx->d_ptr->internal_context = true;
}
+bool QGLWindowSurface::initializeOffscreenTexture(const QSize &size)
+{
+ if (size == d_ptr->textureSize)
+ return false;
+
+ glGenTextures(1, &d_ptr->tex_id);
+ glBindTexture(GL_TEXTURE_2D, d_ptr->tex_id);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.width(), size.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ d_ptr->textureSize = size;
+ return true;
+}
+
bool QGLWindowSurface::scroll(const QRegion &area, int dx, int dy)
{
// this code randomly fails currently for unknown reasons
diff --git a/src/opengl/qwindowsurface_gl_p.h b/src/opengl/qwindowsurface_gl_p.h
index ffc2e86..6906f35 100644
--- a/src/opengl/qwindowsurface_gl_p.h
+++ b/src/opengl/qwindowsurface_gl_p.h
@@ -107,6 +107,7 @@ private slots:
private:
void hijackWindow(QWidget *widget);
+ bool initializeOffscreenTexture(const QSize &size);
QGLWindowSurfacePrivate *d_ptr;
};
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
index bf6164d..f2ee6ae 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.cpp
@@ -1554,9 +1554,8 @@ void QDirectFBScreen::exposeRegion(QRegion r, int)
: (DSBLIT_BLEND_ALPHACHANNEL|DSBLIT_BLEND_COLORALPHA);
}
}
- if (!region.isEmpty()) {
- solidFill(d_ptr->backgroundColor, region);
- }
+
+ solidFill(d_ptr->backgroundColor, region);
while (idx > 0) {
const PaintCommand &cmd = commands[--idx];
@@ -1629,29 +1628,34 @@ void QDirectFBScreen::solidFill(const QColor &color, const QRegion &region)
Q_UNUSED(color);
Q_UNUSED(region);
#else
+ QDirectFBScreen::solidFill(d_ptr->primarySurface, color, region);
+#endif
+}
+
+static inline void clearRect(IDirectFBSurface *surface, const QColor &color, const QRect &rect)
+{
+ Q_ASSERT(surface);
+ const DFBRegion region = { rect.left(), rect.top(), rect.right(), rect.bottom() };
+ // could just reinterpret_cast this to a DFBRegion
+ surface->SetClip(surface, &region);
+ surface->Clear(surface, color.red(), color.green(), color.blue(), color.alpha());
+}
+
+void QDirectFBScreen::solidFill(IDirectFBSurface *surface, const QColor &color, const QRegion &region)
+{
if (region.isEmpty())
return;
- d_ptr->primarySurface->SetColor(d_ptr->primarySurface,
- color.red(), color.green(), color.blue(),
- color.alpha());
const int n = region.rectCount();
if (n == 1) {
- const QRect r = region.boundingRect();
- d_ptr->primarySurface->FillRectangle(d_ptr->primarySurface, r.x(), r.y(), r.width(), r.height());
+ clearRect(surface, color, region.boundingRect());
} else {
const QVector<QRect> rects = region.rects();
- QVarLengthArray<DFBRectangle, 32> rectArray(n);
for (int i=0; i<n; ++i) {
- const QRect &r = rects.at(i);
- rectArray[i].x = r.x();
- rectArray[i].y = r.y();
- rectArray[i].w = r.width();
- rectArray[i].h = r.height();
+ clearRect(surface, color, rects.at(i));
}
- d_ptr->primarySurface->FillRectangles(d_ptr->primarySurface, rectArray.constData(), n);
}
-#endif
+ surface->SetClip(surface, 0);
}
QImage::Format QDirectFBScreen::alphaPixmapFormat() const
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
index c483020..1085423 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbscreen.h
@@ -159,6 +159,7 @@ public:
void exposeRegion(QRegion r, int changing);
void solidFill(const QColor &color, const QRegion &region);
+ static void solidFill(IDirectFBSurface *surface, const QColor &color, const QRegion &region);
void setMode(int width, int height, int depth);
void blank(bool on);
diff --git a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp
index 51969fc..2eeee24 100644
--- a/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp
+++ b/src/plugins/gfxdrivers/directfb/qdirectfbwindowsurface.cpp
@@ -380,11 +380,18 @@ void QDirectFBWindowSurface::flush(QWidget *widget, const QRegion &region,
flushPending = false;
}
-void QDirectFBWindowSurface::beginPaint(const QRegion &)
+void QDirectFBWindowSurface::beginPaint(const QRegion &region)
{
if (!engine) {
engine = new QDirectFBPaintEngine(this);
}
+
+ if (dfbSurface) {
+ const QWidget *win = window();
+ if (win && win->testAttribute(Qt::WA_NoSystemBackground)) {
+ QDirectFBScreen::solidFill(dfbSurface, Qt::transparent, region);
+ }
+ }
flushPending = true;
}
diff --git a/src/plugins/graphicssystems/meego/dithering.cpp b/src/plugins/graphicssystems/meego/dithering.cpp
new file mode 100644
index 0000000..ba6b99b
--- /dev/null
+++ b/src/plugins/graphicssystems/meego/dithering.cpp
@@ -0,0 +1,267 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// This is an implementation of the 32bit => 16bit Floyd-Steinberg dithering.
+// The alghorithm used here is not the fastest possible but it's prolly fast enough:
+// uses look-up tables, integer-only arthmetics and works in one pass on two lines
+// at a time. It's a high-quality dithering using 1/8 diffusion precission.
+// Two functions here to look at:
+//
+// * convertRGBA32_to_RGB565
+// * convertRGBA32_to_RGBA4444
+//
+// Each channel (RGBA) is diffused independently and alpha is dithered too.
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+// Gets a component (red = 1, green = 2...) from a RGBA data structure.
+// data is unsigned char. stride is the number of bytes per line.
+#define GET_RGBA_COMPONENT(data, x, y, stride, c) (data[(y * stride) + (x << 2) + c])
+
+// Writes a new pixel with r, g, b to data in 565 16bit format. Data is a short.
+#define PUT_565(data, x, y, width, r, g, b) (data[(y * width) + x] = (r << 11) | (g << 5) | b)
+
+// Writes a new pixel with r, g, b, a to data in 4444 RGBA 16bit format. Data is a short.
+#define PUT_4444(data, x, y, width, r, g, b, a) (data[(y * width) + x] = (r << 12) | (g << 8) | (b << 4) | a)
+
+// Writes(ads) a new value to the diffusion accumulator. accumulator is a short.
+// x, y is a position in the accumulation buffer. y can be 0 or 1 -- we operate on two lines at time.
+#define ACCUMULATE(accumulator, x, y, width, v) if (x < width && x > 0) accumulator[(y * width) + x] += v
+
+// Clamps a value to be in 0..255 range.
+#define CLAMP_256(v) if (v > 255) v = 255; if (v < 0) v = 0;
+
+// Converts incoming RGB32 (QImage::Format_RGB32) to RGB565. Returns the newly allocated data.
+unsigned short* convertRGB32_to_RGB565(const unsigned char *in, int width, int height, int stride)
+{
+ // Will store output
+ unsigned short *out = (unsigned short *) malloc(width * height * 2);
+
+ // Lookup tables for the 8bit => 6bit and 8bit => 5bit conversion
+ unsigned char lookup_8bit_to_5bit[256];
+ short lookup_8bit_to_5bit_diff[256];
+ unsigned char lookup_8bit_to_6bit[256];
+ short lookup_8bit_to_6bit_diff[256];
+
+ // Macros for the conversion using the lookup table.
+ #define CONVERT_8BIT_TO_5BIT(v) (lookup_8bit_to_5bit[v])
+ #define DIFF_8BIT_TO_5BIT(v) (lookup_8bit_to_5bit_diff[v])
+
+ #define CONVERT_8BIT_TO_6BIT(v) (lookup_8bit_to_6bit[v])
+ #define DIFF_8BIT_TO_6BIT(v) (lookup_8bit_to_6bit_diff[v])
+
+ int i;
+ int x, y, c; // Pixel we're processing. c is component number (0, 1, 2 for r, b, b)
+ short component[3]; // Stores the new components (r, g, b) for pixel produced during conversion
+ short diff; // The difference between the converted value and the original one. To be accumulated.
+ short accumulator[3][width * 2]; // Three acumulators for r, g, b. Each accumulator is two lines.
+
+ // Produce the conversion lookup tables.
+ for (i = 0; i < 256; i++) {
+ lookup_8bit_to_5bit[i] = round(i / 8.0);
+ if (lookup_8bit_to_5bit[i] > 31)
+ lookup_8bit_to_5bit[i] -= 1;
+
+ // Before bitshifts: (i * 8) - (... * 8 * 8)
+ lookup_8bit_to_5bit_diff[i] = (i << 3) - (lookup_8bit_to_5bit[i] << 6);
+
+ lookup_8bit_to_6bit[i] = round(i / 4.0);
+ if (lookup_8bit_to_6bit[i] > 63)
+ lookup_8bit_to_6bit[i] -= 1;
+
+ // Before bitshifts: (i * 8) - (... * 4 * 8)
+ lookup_8bit_to_6bit_diff[i] = (i << 3) - (lookup_8bit_to_6bit[i] << 5);
+ }
+
+ // Clear the accumulators
+ memset(accumulator[0], 0, width * 4);
+ memset(accumulator[1], 0, width * 4);
+ memset(accumulator[2], 0, width * 4);
+
+ // For each line...
+ for (y = 0; y < height; y++) {
+
+ // For each accumulator, move the second line (index 1) to replace the first line (index 0).
+ // Clear the second line (index 1)
+ memcpy(accumulator[0], accumulator[0] + width, width * 2);
+ memset(accumulator[0] + width, 0, width * 2);
+
+ memcpy(accumulator[1], accumulator[1] + width, width * 2);
+ memset(accumulator[1] + width, 0, width * 2);
+
+ memcpy(accumulator[2], accumulator[2] + width, width * 2);
+ memset(accumulator[2] + width, 0, width * 2);
+
+ // For each column....
+ for (x = 0; x < width; x++) {
+
+ // For each component (r, g, b)...
+ for (c = 0; c < 3; c++) {
+
+ // Get the 8bit value from the original image
+ component[c] = GET_RGBA_COMPONENT(in, x, y, stride, c);
+
+ // Add the diffusion for this pixel we stored in the accumulator.
+ // >> 7 because the values in accumulator are stored * 128
+ component[c] += accumulator[c][x] >> 7;
+
+ // Make sure we're not over the boundaries.
+ CLAMP_256(component[c]);
+
+ // For green component we use 6 bits. Otherwise 5 bits.
+ // Store the difference from converting 8bit => 6 bit and the orig pixel.
+ // Convert 8bit => 6(5) bit.
+ if (c == 1) {
+ diff = DIFF_8BIT_TO_6BIT(component[c]);
+ component[c] = CONVERT_8BIT_TO_6BIT(component[c]);
+ } else {
+ diff = DIFF_8BIT_TO_5BIT(component[c]);
+ component[c] = CONVERT_8BIT_TO_5BIT(component[c]);
+ }
+
+ // Distribute the difference according to the matrix in the
+ // accumulation bufffer.
+ ACCUMULATE(accumulator[c], x + 1, 0, width, diff * 7);
+ ACCUMULATE(accumulator[c], x - 1, 1, width, diff * 3);
+ ACCUMULATE(accumulator[c], x, 1, width, diff * 5);
+ ACCUMULATE(accumulator[c], x + 1, 1, width, diff * 1);
+ }
+
+ // Write the newly produced pixel
+ PUT_565(out, x, y, width, component[2], component[1], component[0]);
+ }
+ }
+
+ return out;
+}
+
+// Converts incoming RGBA32 (QImage::Format_ARGB32_Premultiplied) to RGB565. Returns the newly allocated data.
+// This function is similar (yet different) to the _565 variant but it makes sense to duplicate it here for simplicity.
+unsigned short* convertARGB32_to_RGBA4444(const unsigned char *in, int width, int height, int stride)
+{
+ // Will store output
+ unsigned short *out = (unsigned short *) malloc(width * height * 2);
+
+ // Lookup tables for the 8bit => 4bit conversion
+ unsigned char lookup_8bit_to_4bit[256];
+ short lookup_8bit_to_4bit_diff[256];
+
+ // Macros for the conversion using the lookup table.
+ #define CONVERT_8BIT_TO_4BIT(v) (lookup_8bit_to_4bit[v])
+ #define DIFF_8BIT_TO_4BIT(v) (lookup_8bit_to_4bit_diff[v])
+
+ int i;
+ int x, y, c; // Pixel we're processing. c is component number (0, 1, 2, 3 for r, b, b, a)
+ short component[4]; // Stores the new components (r, g, b, a) for pixel produced during conversion
+ short diff; // The difference between the converted value and the original one. To be accumulated.
+ short accumulator[4][width * 2]; // Four acumulators for r, g, b, a. Each accumulator is two lines.
+
+ // Produce the conversion lookup tables.
+ for (i = 0; i < 256; i++) {
+ lookup_8bit_to_4bit[i] = round(i / 16.0);
+ if (lookup_8bit_to_4bit[i] > 15)
+ lookup_8bit_to_4bit[i] -= 1;
+
+ // Before bitshifts: (i * 8) - (... * 16 * 8)
+ lookup_8bit_to_4bit_diff[i] = (i << 3) - (lookup_8bit_to_4bit[i] << 7);
+ }
+
+ // Clear the accumulators
+ memset(accumulator[0], 0, width * 4);
+ memset(accumulator[1], 0, width * 4);
+ memset(accumulator[2], 0, width * 4);
+ memset(accumulator[3], 0, width * 4);
+
+ // For each line...
+ for (y = 0; y < height; y++) {
+
+ // For each component (r, g, b, a)...
+ memcpy(accumulator[0], accumulator[0] + width, width * 2);
+ memset(accumulator[0] + width, 0, width * 2);
+
+ memcpy(accumulator[1], accumulator[1] + width, width * 2);
+ memset(accumulator[1] + width, 0, width * 2);
+
+ memcpy(accumulator[2], accumulator[2] + width, width * 2);
+ memset(accumulator[2] + width, 0, width * 2);
+
+ memcpy(accumulator[3], accumulator[3] + width, width * 2);
+ memset(accumulator[3] + width, 0, width * 2);
+
+ // For each column....
+ for (x = 0; x < width; x++) {
+
+ // For each component (r, g, b, a)...
+ for (c = 0; c < 4; c++) {
+
+ // Get the 8bit value from the original image
+ component[c] = GET_RGBA_COMPONENT(in, x, y, stride, c);
+
+ // Add the diffusion for this pixel we stored in the accumulator.
+ // >> 7 because the values in accumulator are stored * 128
+ component[c] += accumulator[c][x] >> 7;
+
+ // Make sure we're not over the boundaries.
+ CLAMP_256(component[c]);
+
+ // Store the difference from converting 8bit => 4bit and the orig pixel.
+ // Convert 8bit => 4bit.
+ diff = DIFF_8BIT_TO_4BIT(component[c]);
+ component[c] = CONVERT_8BIT_TO_4BIT(component[c]);
+
+ // Distribute the difference according to the matrix in the
+ // accumulation bufffer.
+ ACCUMULATE(accumulator[c], x + 1, 0, width, diff * 7);
+ ACCUMULATE(accumulator[c], x - 1, 1, width, diff * 3);
+ ACCUMULATE(accumulator[c], x, 1, width, diff * 5);
+ ACCUMULATE(accumulator[c], x + 1, 1, width, diff * 1);
+ }
+
+ // Write the newly produced pixel
+ PUT_4444(out, x, y, width, component[0], component[1], component[2], component[3]);
+ }
+ }
+
+ return out;
+}
diff --git a/src/plugins/graphicssystems/meego/meego.pro b/src/plugins/graphicssystems/meego/meego.pro
index 0b157fa..0d3cce6 100644
--- a/src/plugins/graphicssystems/meego/meego.pro
+++ b/src/plugins/graphicssystems/meego/meego.pro
@@ -6,7 +6,7 @@ QT += gui opengl
QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/graphicssystems
HEADERS = qmeegographicssystem.h qmeegopixmapdata.h qmeegoextensions.h qmeegorasterpixmapdata.h qmeegolivepixmapdata.h
-SOURCES = qmeegographicssystem.cpp qmeegographicssystem.h qmeegographicssystemplugin.h qmeegographicssystemplugin.cpp qmeegopixmapdata.h qmeegopixmapdata.cpp qmeegoextensions.h qmeegoextensions.cpp qmeegorasterpixmapdata.h qmeegorasterpixmapdata.cpp qmeegolivepixmapdata.cpp qmeegolivepixmapdata.h
+SOURCES = qmeegographicssystem.cpp qmeegographicssystem.h qmeegographicssystemplugin.h qmeegographicssystemplugin.cpp qmeegopixmapdata.h qmeegopixmapdata.cpp qmeegoextensions.h qmeegoextensions.cpp qmeegorasterpixmapdata.h qmeegorasterpixmapdata.cpp qmeegolivepixmapdata.cpp qmeegolivepixmapdata.h dithering.cpp
target.path += $$[QT_INSTALL_PLUGINS]/graphicssystems
INSTALLS += target
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);