diff options
author | Paul Olav Tvete <paul.tvete@nokia.com> | 2009-03-18 17:29:19 +0100 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@nokia.com> | 2009-04-23 11:12:57 +0200 |
commit | 74934cba48910e366d96e4e596e8676d8434fe24 (patch) | |
tree | 4a117c85b5766ce21e728498d68e5218cb8b8bc3 /tools/qvfb/qvfbview.cpp | |
parent | be3916b7e4e8007394cbed40484ef6b696e90f2b (diff) | |
download | qt4-tools-74934cba48910e366d96e4e596e8676d8434fe24.tar.gz |
Adding 2bpp support to qvfb
Diffstat (limited to 'tools/qvfb/qvfbview.cpp')
-rw-r--r-- | tools/qvfb/qvfbview.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/qvfb/qvfbview.cpp b/tools/qvfb/qvfbview.cpp index 53a5360e52..c2df8fd7ed 100644 --- a/tools/qvfb/qvfbview.cpp +++ b/tools/qvfb/qvfbview.cpp @@ -457,6 +457,67 @@ QImage QVFbView::getBuffer(const QRect &r, int &leading) const } break; } + + case 2: { + if (requiredSize > buffer.size()) + buffer.resize(requiredSize); + + // XXX: hw: replace by drawhelper functionality + + const int pixelsPerByte = 4; + quint8 *src = reinterpret_cast<quint8*>(mView->data()) + + r.y() * mView->linestep() + r.x() / pixelsPerByte; + const int align = qMin(r.width(), (4 - (r.x() & 3)) & 3); + const int doAlign = (align > 0 ? 1 : 0); + const int tail = qMin(r.width(), (r.width() - align) & 3); + const int doTail = (tail > 0 ? 1 : 0); + const int width8 = (r.width() - align) / pixelsPerByte; + const int stride = mView->linestep() - (width8 + doAlign); + + uchar *b = reinterpret_cast<uchar*>(buffer.data()); + img = QImage(b, r.width(), r.height(), QImage::Format_RGB32); + for (int y = 0; y < r.height(); ++y) { + quint32 *dest = reinterpret_cast<quint32*>(img.scanLine(y)); + quint8 c; + + if (doAlign) { + switch (align) { + case 3: c = ((*src & 0x30) >> 4) * 0x55; + *dest++ = qRgb(c, c, c); + case 2: c = ((*src & 0x0c) >> 2) * 0x55; + *dest++ = qRgb(c, c, c); + case 1: c = ((*src & 0x03)) * 0x55; + *dest++ = qRgb(c, c, c); + } + ++src; + } + for (int i = 0; i < width8; ++i) { + c = ((*src & 0xc0) >> 6) * 0x55; + *dest++ = qRgb(c, c, c); + c = ((*src & 0x30) >> 4) * 0x55; + *dest++ = qRgb(c, c, c); + c = ((*src & 0x0c) >> 2) * 0x55; + *dest++ = qRgb(c, c, c); + c = ((*src & 0x03)) * 0x55; + *dest++ = qRgb(c, c, c); + + ++src; + } + if (doTail) { + switch (tail) { + case 3: c = ((*src & 0x0c) >> 2) * 0x55; + dest[2] = qRgb(c, c, c); + case 2: c = ((*src & 0x30) >> 4) * 0x55; + dest[1] = qRgb(c, c, c); + case 1: c = ((*src & 0xc0) >> 6) * 0x55; + dest[0] = qRgb(c, c, c); + } + } + src += stride; + } + break; + } + case 4: { if (requiredSize > buffer.size()) buffer.resize(requiredSize); |