Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | From 8744273fc452eb54bbeeb7d15823009ce926c6fa Mon Sep 17 00:00:00 2001 |
| 2 | From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= <jeremy.laine@m4x.org> |
| 3 | Date: Wed, 26 Sep 2012 20:39:21 +0200 |
| 4 | Subject: [PATCH 12/21] Add 2bpp support |
| 5 | |
| 6 | Submitted upstream but rejected as being "out of scope": |
| 7 | https://bugreports.qt-project.org/browse/QTBUG-3468 |
| 8 | |
| 9 | Upstream-Status: Denied |
| 10 | |
| 11 | Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> |
| 12 | --- |
| 13 | configure | 5 +- |
| 14 | src/gui/embedded/qscreen_qws.cpp | 211 ++++++++++++++++++++++++++++++++ |
| 15 | src/gui/embedded/qscreenlinuxfb_qws.cpp | 4 +- |
| 16 | 3 files changed, 216 insertions(+), 4 deletions(-) |
| 17 | |
| 18 | diff --git a/configure b/configure |
| 19 | index 35a8fe7..79c1c7b 100755 |
| 20 | --- a/configure |
| 21 | +++ b/configure |
| 22 | @@ -7063,6 +7063,7 @@ if [ "$CFG_QWS_DEPTHS" = "prompted" -a "$PROMPT_FOR_DEPTHS" = "yes" ]; then |
| 23 | echo "Choose pixel-depths to support:" |
| 24 | echo |
| 25 | echo " 1. 1bpp, black/white" |
| 26 | + echo " 2. 2bpp, grayscale" |
| 27 | echo " 4. 4bpp, grayscale" |
| 28 | echo " 8. 8bpp, paletted" |
| 29 | echo " 12. 12bpp, rgb 4-4-4" |
| 30 | @@ -7081,11 +7082,11 @@ if [ "$CFG_QWS_DEPTHS" = "prompted" -a "$PROMPT_FOR_DEPTHS" = "yes" ]; then |
| 31 | fi |
| 32 | if [ -n "$CFG_QWS_DEPTHS" -a "$PLATFORM_QWS" = "yes" ]; then |
| 33 | if [ "$CFG_QWS_DEPTHS" = "all" ]; then |
| 34 | - CFG_QWS_DEPTHS="1 4 8 12 15 16 18 24 32 generic" |
| 35 | + CFG_QWS_DEPTHS="1 2 4 8 12 15 16 18 24 32 generic" |
| 36 | fi |
| 37 | for D in `echo "$CFG_QWS_DEPTHS" | sed -e 's/,/ /g'`; do |
| 38 | case $D in |
| 39 | - 1|4|8|12|15|16|18|24|32) QCONFIG_FLAGS="$QCONFIG_FLAGS QT_QWS_DEPTH_$D";; |
| 40 | + 1|2|4|8|12|15|16|18|24|32) QCONFIG_FLAGS="$QCONFIG_FLAGS QT_QWS_DEPTH_$D";; |
| 41 | generic) QCONFIG_FLAGS="$QCONFIG_FLAGS QT_QWS_DEPTH_GENERIC";; |
| 42 | esac |
| 43 | done |
| 44 | diff --git a/src/gui/embedded/qscreen_qws.cpp b/src/gui/embedded/qscreen_qws.cpp |
| 45 | index b307bf2..88950b3 100644 |
| 46 | --- a/src/gui/embedded/qscreen_qws.cpp |
| 47 | +++ b/src/gui/embedded/qscreen_qws.cpp |
| 48 | @@ -469,6 +469,58 @@ static void solidFill_gray4(QScreen *screen, const QColor &color, |
| 49 | } |
| 50 | #endif // QT_QWS_DEPTH_4 |
| 51 | |
| 52 | +#ifdef QT_QWS_DEPTH_2 |
| 53 | +static inline void qt_rectfill_gray2(quint8 *dest, quint8 value, |
| 54 | + int x, int y, int width, int height, |
| 55 | + int stride) |
| 56 | +{ |
| 57 | + const int pixelsPerByte = 4; |
| 58 | + const int alignWidth = qMin(width, (4 - (x & 3)) & 3); |
| 59 | + const int doAlign = (alignWidth > 0 ? 1 : 0); |
| 60 | + const int alignStart = pixelsPerByte - 1 - (x & 3); |
| 61 | + const int alignStop = alignStart - (alignWidth - 1); |
| 62 | + const quint8 alignMask = ((1 << (2 * alignWidth)) - 1) << (2 * alignStop); |
| 63 | + const int tailWidth = (width - alignWidth) & 3; |
| 64 | + const int doTail = (tailWidth > 0 ? 1 : 0); |
| 65 | + const quint8 tailMask = (1 << (2 * (pixelsPerByte - tailWidth))) - 1; |
| 66 | + const int width8 = (width - alignWidth) / pixelsPerByte; |
| 67 | + |
| 68 | + dest += y * stride + x / pixelsPerByte; |
| 69 | + stride -= (doAlign + width8); |
| 70 | + |
| 71 | + for (int j = 0; j < height; ++j) { |
| 72 | + if (doAlign) { |
| 73 | + *dest = (*dest & ~alignMask) | (value & alignMask); |
| 74 | + ++dest; |
| 75 | + } |
| 76 | + if (width8) { |
| 77 | + qt_memfill<quint8>(dest, value, width8); |
| 78 | + dest += width8; |
| 79 | + } |
| 80 | + if (doTail) |
| 81 | + *dest = (*dest & tailMask) | (value & ~tailMask); |
| 82 | + dest += stride; |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +static void solidFill_gray2(QScreen *screen, const QColor &color, |
| 87 | + const QRegion ®ion) |
| 88 | +{ |
| 89 | + quint8 *dest = reinterpret_cast<quint8*>(screen->base()); |
| 90 | + const quint8 c = qGray(color.rgba()) >> 6; |
| 91 | + const quint8 c8 = (c << 6) | (c << 4) | (c << 2) | c; |
| 92 | + |
| 93 | + const int stride = screen->linestep(); |
| 94 | + const QVector<QRect> rects = region.rects(); |
| 95 | + |
| 96 | + for (int i = 0; i < rects.size(); ++i) { |
| 97 | + const QRect r = rects.at(i); |
| 98 | + qt_rectfill_gray2(dest, c8, r.x(), r.y(), r.width(), r.height(), |
| 99 | + stride); |
| 100 | + } |
| 101 | +} |
| 102 | +#endif // QT_QWS_DEPTH_2 |
| 103 | + |
| 104 | #ifdef QT_QWS_DEPTH_1 |
| 105 | static inline void qt_rectfill_mono(quint8 *dest, quint8 value, |
| 106 | int x, int y, int width, int height, |
| 107 | @@ -576,6 +628,11 @@ void qt_solidFill_setup(QScreen *screen, const QColor &color, |
| 108 | screen->d_ptr->solidFill = solidFill_gray4; |
| 109 | break; |
| 110 | #endif |
| 111 | +#ifdef QT_QWS_DEPTH_2 |
| 112 | + case 2: |
| 113 | + screen->d_ptr->solidFill = solidFill_gray2; |
| 114 | + break; |
| 115 | +#endif |
| 116 | #ifdef QT_QWS_DEPTH_1 |
| 117 | case 1: |
| 118 | screen->d_ptr->solidFill = solidFill_mono; |
| 119 | @@ -1006,6 +1063,149 @@ static void blit_4(QScreen *screen, const QImage &image, |
| 120 | } |
| 121 | #endif // QT_QWS_DEPTH_4 |
| 122 | |
| 123 | +#ifdef QT_QWS_DEPTH_2 |
| 124 | + |
| 125 | +struct qgray2 { quint8 dummy; } Q_PACKED; |
| 126 | + |
| 127 | +template <typename SRC> |
| 128 | +static inline quint8 qt_convertToGray2(SRC color); |
| 129 | + |
| 130 | +template <> |
| 131 | +inline quint8 qt_convertToGray2(quint32 color) |
| 132 | +{ |
| 133 | + return qGray(color) >> 6; |
| 134 | +} |
| 135 | + |
| 136 | +template <> |
| 137 | +inline quint8 qt_convertToGray2(quint16 color) |
| 138 | +{ |
| 139 | + const int r = (color & 0xf800) >> 11; |
| 140 | + const int g = (color & 0x07e0) >> 6; // only keep 5 bit |
| 141 | + const int b = (color & 0x001f); |
| 142 | + return (r * 11 + g * 16 + b * 5) >> 8; |
| 143 | +} |
| 144 | + |
| 145 | +template <> |
| 146 | +inline quint8 qt_convertToGray2(qrgb444 color) |
| 147 | +{ |
| 148 | + return qt_convertToGray2(quint32(color)); |
| 149 | +} |
| 150 | + |
| 151 | +template <> |
| 152 | +inline quint8 qt_convertToGray2(qargb4444 color) |
| 153 | +{ |
| 154 | + return qt_convertToGray2(quint32(color)); |
| 155 | +} |
| 156 | + |
| 157 | +template <typename SRC> |
| 158 | +static inline void qt_rectconvert_gray2(qgray2 *dest2, const SRC *src, |
| 159 | + int x, int y, int width, int height, |
| 160 | + int dstStride, int srcStride) |
| 161 | +{ |
| 162 | + const int pixelsPerByte = 4; |
| 163 | + quint8 *dest8 = reinterpret_cast<quint8*>(dest2) |
| 164 | + + y * dstStride + x / pixelsPerByte; |
| 165 | + const int alignWidth = qMin(width, (4 - (x & 3)) & 3); |
| 166 | + const int doAlign = (alignWidth > 0 ? 1 : 0); |
| 167 | + const int alignStart = pixelsPerByte - 1 - (x & 3); |
| 168 | + const int alignStop = alignStart - (alignWidth - 1); |
| 169 | + const quint8 alignMask = ((1 << (2 * alignWidth)) - 1) << (2 * alignStop); |
| 170 | + const int tailWidth = (width - alignWidth) & 3; |
| 171 | + const int doTail = (tailWidth > 0 ? 1 : 0); |
| 172 | + const quint8 tailMask = (1 << (2 * (pixelsPerByte - tailWidth))) - 1; |
| 173 | + const int width8 = (width - alignWidth) / pixelsPerByte; |
| 174 | + |
| 175 | + srcStride = srcStride / sizeof(SRC) - (width8 * pixelsPerByte + alignWidth); |
| 176 | + dstStride -= (width8 + doAlign); |
| 177 | + |
| 178 | + for (int j = 0; j < height; ++j) { |
| 179 | + if (doAlign) { |
| 180 | + quint8 d = *dest8 & ~alignMask; |
| 181 | + for (int i = alignStart; i >= alignStop; --i) |
| 182 | + d |= qt_convertToGray2<SRC>(*src++) << (2 * i); |
| 183 | + *dest8++ = d; |
| 184 | + } |
| 185 | + for (int i = 0; i < width8; ++i) { |
| 186 | + *dest8 = (qt_convertToGray2<SRC>(src[0]) << 6) |
| 187 | + | (qt_convertToGray2<SRC>(src[1]) << 4) |
| 188 | + | (qt_convertToGray2<SRC>(src[2]) << 2) |
| 189 | + | (qt_convertToGray2<SRC>(src[3])); |
| 190 | + src += 4; |
| 191 | + ++dest8; |
| 192 | + } |
| 193 | + if (doTail) { |
| 194 | + quint8 d = *dest8 & tailMask; |
| 195 | + switch (tailWidth) { |
| 196 | + case 3: d |= qt_convertToGray2<SRC>(src[2]) << 2; |
| 197 | + case 2: d |= qt_convertToGray2<SRC>(src[1]) << 4; |
| 198 | + case 1: d |= qt_convertToGray2<SRC>(src[0]) << 6; |
| 199 | + } |
| 200 | + *dest8 = d; |
| 201 | + } |
| 202 | + |
| 203 | + dest8 += dstStride; |
| 204 | + src += srcStride; |
| 205 | + } |
| 206 | +} |
| 207 | + |
| 208 | +template <> |
| 209 | +void qt_rectconvert(qgray2 *dest, const quint32 *src, |
| 210 | + int x, int y, int width, int height, |
| 211 | + int dstStride, int srcStride) |
| 212 | +{ |
| 213 | + qt_rectconvert_gray2<quint32>(dest, src, x, y, width, height, |
| 214 | + dstStride, srcStride); |
| 215 | +} |
| 216 | + |
| 217 | +template <> |
| 218 | +void qt_rectconvert(qgray2 *dest, const quint16 *src, |
| 219 | + int x, int y, int width, int height, |
| 220 | + int dstStride, int srcStride) |
| 221 | +{ |
| 222 | + qt_rectconvert_gray2<quint16>(dest, src, x, y, width, height, |
| 223 | + dstStride, srcStride); |
| 224 | +} |
| 225 | + |
| 226 | +template <> |
| 227 | +void qt_rectconvert(qgray2 *dest, const qrgb444 *src, |
| 228 | + int x, int y, int width, int height, |
| 229 | + int dstStride, int srcStride) |
| 230 | +{ |
| 231 | + qt_rectconvert_gray2<qrgb444>(dest, src, x, y, width, height, |
| 232 | + dstStride, srcStride); |
| 233 | +} |
| 234 | + |
| 235 | +template <> |
| 236 | +void qt_rectconvert(qgray2 *dest, const qargb4444 *src, |
| 237 | + int x, int y, int width, int height, |
| 238 | + int dstStride, int srcStride) |
| 239 | +{ |
| 240 | + qt_rectconvert_gray2<qargb4444>(dest, src, x, y, width, height, |
| 241 | + dstStride, srcStride); |
| 242 | +} |
| 243 | + |
| 244 | +static void blit_2(QScreen *screen, const QImage &image, |
| 245 | + const QPoint &topLeft, const QRegion ®ion) |
| 246 | +{ |
| 247 | + switch (image.format()) { |
| 248 | + case QImage::Format_ARGB32_Premultiplied: |
| 249 | + blit_template<qgray2, quint32>(screen, image, topLeft, region); |
| 250 | + return; |
| 251 | + case QImage::Format_RGB16: |
| 252 | + blit_template<qgray2, quint16>(screen, image, topLeft, region); |
| 253 | + return; |
| 254 | + case QImage::Format_RGB444: |
| 255 | + blit_template<qgray2, qrgb444>(screen, image, topLeft, region); |
| 256 | + return; |
| 257 | + case QImage::Format_ARGB4444_Premultiplied: |
| 258 | + blit_template<qgray2, qargb4444>(screen, image, topLeft, region); |
| 259 | + return; |
| 260 | + default: |
| 261 | + qCritical("blit_2(): Image format %d not supported!", image.format()); |
| 262 | + } |
| 263 | +} |
| 264 | +#endif // QT_QWS_DEPTH_2 |
| 265 | + |
| 266 | #ifdef QT_QWS_DEPTH_1 |
| 267 | |
| 268 | struct qmono { quint8 dummy; } Q_PACKED; |
| 269 | @@ -1259,6 +1459,11 @@ void qt_blit_setup(QScreen *screen, const QImage &image, |
| 270 | screen->d_ptr->blit = blit_4; |
| 271 | break; |
| 272 | #endif |
| 273 | +#ifdef QT_QWS_DEPTH_2 |
| 274 | + case 2: |
| 275 | + screen->d_ptr->blit = blit_2; |
| 276 | + break; |
| 277 | +#endif |
| 278 | #ifdef QT_QWS_DEPTH_1 |
| 279 | case 1: |
| 280 | screen->d_ptr->blit = blit_1; |
| 281 | @@ -2146,6 +2351,8 @@ int QScreen::alloc(unsigned int r,unsigned int g,unsigned int b) |
| 282 | } |
| 283 | } else if (d == 4) { |
| 284 | ret = qGray(r, g, b) >> 4; |
| 285 | + } else if (d == 2) { |
| 286 | + ret = qGray(r, g, b) >> 6; |
| 287 | } else if (d == 1) { |
| 288 | ret = qGray(r, g, b) >= 128; |
| 289 | } else { |
| 290 | @@ -2216,6 +2423,10 @@ bool QScreen::supportsDepth(int d) const |
| 291 | } else if(d==1) { |
| 292 | return true; |
| 293 | #endif |
| 294 | +#ifdef QT_QWS_DEPTH_2 |
| 295 | + } else if(d==2) { |
| 296 | + return true; |
| 297 | +#endif |
| 298 | #ifdef QT_QWS_DEPTH_4 |
| 299 | } else if(d==4) { |
| 300 | return true; |
| 301 | diff --git a/src/gui/embedded/qscreenlinuxfb_qws.cpp b/src/gui/embedded/qscreenlinuxfb_qws.cpp |
| 302 | index 6f3caad..14159ee 100644 |
| 303 | --- a/src/gui/embedded/qscreenlinuxfb_qws.cpp |
| 304 | +++ b/src/gui/embedded/qscreenlinuxfb_qws.cpp |
| 305 | @@ -466,8 +466,8 @@ bool QLinuxFbScreen::connect(const QString &displaySpec) |
| 306 | setupOffScreen(); |
| 307 | |
| 308 | // Now read in palette |
| 309 | - if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4)) { |
| 310 | - screencols= (vinfo.bits_per_pixel==8) ? 256 : 16; |
| 311 | + if((vinfo.bits_per_pixel==8) || (vinfo.bits_per_pixel==4) || (vinfo.bits_per_pixel==2)) { |
| 312 | + screencols= 1 << vinfo.bits_per_pixel; |
| 313 | int loopc; |
| 314 | ::fb_cmap startcmap; |
| 315 | startcmap.start=0; |
| 316 | -- |
| 317 | 1.8.0 |
| 318 | |