aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-qt/qt4/qt4-4.8.5/0012-Add-2bpp-support.patch
blob: 8402eab63577b5121c14839efb6bffe5a8fbe2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
From 8744273fc452eb54bbeeb7d15823009ce926c6fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= <jeremy.laine@m4x.org>
Date: Wed, 26 Sep 2012 20:39:21 +0200
Subject: [PATCH 12/21] Add 2bpp support

Submitted upstream but rejected as being "out of scope":
http://bugreports.qt.nokia.com/browse/QTBUG-3468

Upstream-Status: Denied

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 configure                               |   5 +-
 src/gui/embedded/qscreen_qws.cpp        | 211 ++++++++++++++++++++++++++++++++
 src/gui/embedded/qscreenlinuxfb_qws.cpp |   4 +-
 3 files changed, 216 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 35a8fe7..79c1c7b 100755
--- a/configure
+++ b/configure
@@ -7063,6 +7063,7 @@ if [ "$CFG_QWS_DEPTHS" = "prompted" -a "$PROMPT_FOR_DEPTHS" = "yes" ]; then
     echo "Choose pixel-depths to support:"
     echo
     echo "   1. 1bpp, black/white"
+    echo "   2. 2bpp, grayscale"
     echo "   4. 4bpp, grayscale"
     echo "   8. 8bpp, paletted"
     echo "  12. 12bpp, rgb 4-4-4"
@@ -7081,11 +7082,11 @@ if [ "$CFG_QWS_DEPTHS" = "prompted" -a "$PROMPT_FOR_DEPTHS" = "yes" ]; then
 fi
 if [ -n "$CFG_QWS_DEPTHS" -a "$PLATFORM_QWS" = "yes" ]; then
     if [ "$CFG_QWS_DEPTHS" = "all" ]; then
-        CFG_QWS_DEPTHS="1 4 8 12 15 16 18 24 32 generic"
+        CFG_QWS_DEPTHS="1 2 4 8 12 15 16 18 24 32 generic"
     fi
     for D in `echo "$CFG_QWS_DEPTHS" | sed -e 's/,/ /g'`; do
 	case $D in
-	    1|4|8|12|15|16|18|24|32) QCONFIG_FLAGS="$QCONFIG_FLAGS QT_QWS_DEPTH_$D";;
+	    1|2|4|8|12|15|16|18|24|32) QCONFIG_FLAGS="$QCONFIG_FLAGS QT_QWS_DEPTH_$D";;
 	    generic) QCONFIG_FLAGS="$QCONFIG_FLAGS QT_QWS_DEPTH_GENERIC";;
 	esac
     done
diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp
index b307bf2..88950b3 100644
--- a/src/gui/embedded/qscreen_qws.cpp
+++ b/src/gui/embedded/qscreen_qws.cpp
@@ -469,6 +469,58 @@ static void solidFill_gray4(QScreen *screen, const QColor &color,
 }
 #endif // QT_QWS_DEPTH_4
 
+#ifdef QT_QWS_DEPTH_2
+static inline void qt_rectfill_gray2(quint8 *dest, quint8 value,
+                                     int x, int y, int width, int height,
+                                     int stride)
+{
+    const int pixelsPerByte = 4;
+    const int alignWidth = qMin(width, (4 - (x & 3)) & 3);
+    const int doAlign = (alignWidth > 0 ? 1 : 0);
+    const int alignStart = pixelsPerByte - 1 - (x & 3);
+    const int alignStop = alignStart - (alignWidth - 1);
+    const quint8 alignMask = ((1 << (2 * alignWidth)) - 1) << (2 * alignStop);
+    const int tailWidth = (width - alignWidth) & 3;
+    const int doTail = (tailWidth > 0 ? 1 : 0);
+    const quint8 tailMask = (1 << (2 * (pixelsPerByte - tailWidth))) - 1;
+    const int width8 = (width - alignWidth) / pixelsPerByte;
+
+    dest += y * stride + x / pixelsPerByte;
+    stride -= (doAlign + width8);
+
+    for (int j = 0; j < height; ++j) {
+        if (doAlign) {
+            *dest = (*dest & ~alignMask) | (value & alignMask);
+            ++dest;
+        }
+        if (width8) {
+            qt_memfill<quint8>(dest, value, width8);
+            dest += width8;
+        }
+        if (doTail)
+            *dest = (*dest & tailMask) | (value & ~tailMask);
+        dest += stride;
+    }
+}
+
+static void solidFill_gray2(QScreen *screen, const QColor &color,
+                            const QRegion &region)
+{
+    quint8 *dest = reinterpret_cast<quint8*>(screen->base());
+    const quint8 c = qGray(color.rgba()) >> 6;
+    const quint8 c8 = (c << 6) | (c << 4) | (c << 2) | c;
+
+    const int stride = screen->linestep();
+    const QVector<QRect> rects = region.rects();
+
+    for (int i = 0; i < rects.size(); ++i) {
+        const QRect r = rects.at(i);
+        qt_rectfill_gray2(dest, c8, r.x(), r.y(), r.width(), r.height(),
+                          stride);
+    }
+}
+#endif // QT_QWS_DEPTH_2
+
 #ifdef QT_QWS_DEPTH_1
 static inline void qt_rectfill_mono(quint8 *dest, quint8 value,
                                     int x, int y, int width, int height,
@@ -576,6 +628,11 @@ void qt_solidFill_setup(QScreen *screen, const QColor &color,
         screen->d_ptr->solidFill = solidFill_gray4;
         break;
 #endif
+#ifdef QT_QWS_DEPTH_2
+    case 2:
+        screen->d_ptr->solidFill = solidFill_gray2;
+        break;
+#endif
 #ifdef QT_QWS_DEPTH_1
     case 1:
         screen->d_ptr->solidFill = solidFill_mono;
@@ -1006,6 +1063,149 @@ static void blit_4(QScreen *screen, const QImage &image,
 }
 #endif // QT_QWS_DEPTH_4
 
+#ifdef QT_QWS_DEPTH_2
+
+struct qgray2 { quint8 dummy; } Q_PACKED;
+
+template <typename SRC>
+static inline quint8 qt_convertToGray2(SRC color);
+
+template <>
+inline quint8 qt_convertToGray2(quint32 color)
+{
+    return qGray(color) >> 6;
+}
+
+template <>
+inline quint8 qt_convertToGray2(quint16 color)
+{
+    const int r = (color & 0xf800) >> 11;
+    const int g = (color & 0x07e0) >> 6; // only keep 5 bit
+    const int b = (color & 0x001f);
+    return (r * 11 + g * 16 + b * 5) >> 8;
+}
+
+template <>
+inline quint8 qt_convertToGray2(qrgb444 color)
+{
+    return qt_convertToGray2(quint32(color));
+}
+
+template <>
+inline quint8 qt_convertToGray2(qargb4444 color)
+{
+    return qt_convertToGray2(quint32(color));
+}
+
+template <typename SRC>
+static inline void qt_rectconvert_gray2(qgray2 *dest2, const SRC *src,
+                                        int x, int y, int width, int height,
+                                        int dstStride, int srcStride)
+{
+    const int pixelsPerByte = 4;
+    quint8 *dest8 = reinterpret_cast<quint8*>(dest2)
+                    + y * dstStride + x / pixelsPerByte;
+    const int alignWidth = qMin(width, (4 - (x & 3)) & 3);
+    const int doAlign = (alignWidth > 0 ? 1 : 0);
+    const int alignStart = pixelsPerByte - 1 - (x & 3);
+    const int alignStop = alignStart - (alignWidth - 1);
+    const quint8 alignMask = ((1 << (2 * alignWidth)) - 1) << (2 * alignStop);
+    const int tailWidth = (width - alignWidth) & 3;
+    const int doTail = (tailWidth > 0 ? 1 : 0);
+    const quint8 tailMask = (1 << (2 * (pixelsPerByte - tailWidth))) - 1;
+    const int width8 = (width - alignWidth) / pixelsPerByte;
+
+    srcStride = srcStride / sizeof(SRC) - (width8 * pixelsPerByte + alignWidth);
+    dstStride -= (width8 + doAlign);
+
+    for (int j = 0;  j < height; ++j) {
+        if (doAlign) {
+            quint8 d = *dest8 & ~alignMask;
+            for (int i = alignStart; i >= alignStop; --i)
+                d |= qt_convertToGray2<SRC>(*src++) << (2 * i);
+            *dest8++ = d;
+        }
+        for (int i = 0; i < width8; ++i) {
+            *dest8 = (qt_convertToGray2<SRC>(src[0]) << 6)
+                     | (qt_convertToGray2<SRC>(src[1]) << 4)
+                     | (qt_convertToGray2<SRC>(src[2]) << 2)
+                     | (qt_convertToGray2<SRC>(src[3]));
+            src += 4;
+            ++dest8;
+        }
+        if (doTail) {
+            quint8 d = *dest8 & tailMask;
+            switch (tailWidth) {
+            case 3: d |= qt_convertToGray2<SRC>(src[2]) << 2;
+            case 2: d |= qt_convertToGray2<SRC>(src[1]) << 4;
+            case 1: d |= qt_convertToGray2<SRC>(src[0]) << 6;
+            }
+            *dest8 = d;
+        }
+
+        dest8 += dstStride;
+        src += srcStride;
+    }
+}
+
+template <>
+void qt_rectconvert(qgray2 *dest, const quint32 *src,
+                    int x, int y, int width, int height,
+                    int dstStride, int srcStride)
+{
+    qt_rectconvert_gray2<quint32>(dest, src, x, y, width, height,
+                                  dstStride, srcStride);
+}
+
+template <>
+void qt_rectconvert(qgray2 *dest, const quint16 *src,
+                    int x, int y, int width, int height,
+                    int dstStride, int srcStride)
+{
+    qt_rectconvert_gray2<quint16>(dest, src, x, y, width, height,
+                                  dstStride, srcStride);
+}
+
+template <>
+void qt_rectconvert(qgray2 *dest, const qrgb444 *src,
+                    int x, int y, int width, int height,
+                    int dstStride, int srcStride)
+{
+    qt_rectconvert_gray2<qrgb444>(dest, src, x, y, width, height,
+                                  dstStride, srcStride);
+}
+
+template <>
+void qt_rectconvert(qgray2 *dest, const qargb4444 *src,
+                    int x, int y, int width, int height,
+                    int dstStride, int srcStride)
+{
+    qt_rectconvert_gray2<qargb4444>(dest, src, x, y, width, height,
+                                    dstStride, srcStride);
+}
+
+static void blit_2(QScreen *screen, const QImage &image,
+                   const QPoint &topLeft, const QRegion &region)
+{
+    switch (image.format()) {
+    case QImage::Format_ARGB32_Premultiplied:
+        blit_template<qgray2, quint32>(screen, image, topLeft, region);
+        return;
+    case QImage::Format_RGB16:
+        blit_template<qgray2, quint16>(screen, image, topLeft, region);
+        return;
+    case QImage::Format_RGB444:
+        blit_template<qgray2, qrgb444>(screen, image, topLeft, region);
+        return;
+    case QImage::Format_ARGB4444_Premultiplied:
+        blit_template<qgray2, qargb4444>(screen, image, topLeft, region);
+        return;
+    default:
+        qCritical("blit_2(): Image format %d not supported!", image.format());
+    }
+}
+#endif // QT_QWS_DEPTH_2
+
 #ifdef QT_QWS_DEPTH_1
 
 struct qmono { quint8 dummy; } Q_PACKED;
@@ -1259,6 +1459,11 @@ void qt_blit_setup(QScreen *screen, const QImage &image,
         screen->d_ptr->blit = blit_4;
         break;
 #endif
+#ifdef QT_QWS_DEPTH_2
+    case 2:
+        screen->d_ptr->blit = blit_2;
+        break;
+#endif
 #ifdef QT_QWS_DEPTH_1
     case 1:
         screen->d_ptr->blit = blit_1;
@@ -2146,6 +2351,8 @@ int QScreen::alloc(unsigned int r,unsigned int g,unsigned int b)
         }
     } else if (d == 4) {
         ret = qGray(r, g, b) >> 4;
+    } else if (d == 2) {
+        ret = qGray(r, g, b) >> 6;
     } else if (d == 1) {
         ret = qGray(r, g, b) >= 128;
     } else {
@@ -2216,6 +2423,10 @@ bool QScreen::supportsDepth(int d) const
     } else if(d==1) {
         return true;
 #endif
+#ifdef QT_QWS_DEPTH_2
+    } else if(d==2) {
+        return true;
+#endif
 #ifdef QT_QWS_DEPTH_4
     } else if(d==4) {
         return true;
diff --git a/src/gui/embedded/qscreenlinuxfb_qws.cpp b/src/gui/embedded/qscreenlinuxfb_qws.cpp
index 6f3caad..14159ee 100644
--- a/src/gui/embedded/qscreenlinuxfb_qws.cpp
+++ b/src/gui/embedded/qscreenlinuxfb_qws.cpp
@@ -466,8 +466,8 @@ bool QLinuxFbScreen::connect(const QString &displaySpec)
         setupOffScreen();
 
     // Now read in palette
-    if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) {
-        screencols= (vinfo.bits_per_pixel==8) ? 256 : 16;
+    if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4) || (vinfo.bits_per_pixel==2)) {
+        screencols= 1 << vinfo.bits_per_pixel;
         int loopc;
         ::fb_cmap startcmap;
         startcmap.start=0;
-- 
1.8.0