diff options
author | Pierre Ossman <ossman@cendio.se> | 2014-01-29 17:00:36 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2014-07-09 14:55:08 +0200 |
commit | 761fe24089bfe95028b0da02a12650351b244165 (patch) | |
tree | dea109c9ba03b6bc967dec0043316bae2055e4ed /common | |
parent | 2fe68da9e3e7a68102e144464ebcd09f226a446c (diff) | |
download | tigervnc-761fe24089bfe95028b0da02a12650351b244165.tar.gz tigervnc-761fe24089bfe95028b0da02a12650351b244165.zip |
Add ability to directly convert between two pixel formats
This is a lot easier and cheaper than having to set up a complete
PixelTransformer object.
Diffstat (limited to 'common')
-rw-r--r-- | common/rfb/PixelFormat.cxx | 50 | ||||
-rw-r--r-- | common/rfb/PixelFormat.h | 8 |
2 files changed, 58 insertions, 0 deletions
diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx index 366c0a33..53b7ea50 100644 --- a/common/rfb/PixelFormat.cxx +++ b/common/rfb/PixelFormat.cxx @@ -343,6 +343,56 @@ void PixelFormat::rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, } +Pixel PixelFormat::pixelFromPixel(const PixelFormat &srcPF, Pixel src) const +{ + rdr::U16 r, g, b; + srcPF.rgbFromPixel(src, &r, &g, &b); + return pixelFromRGB(r, g, b); +} + + +void PixelFormat::bufferFromBuffer(rdr::U8* dst, const PixelFormat &srcPF, + const rdr::U8* src, int pixels) const +{ + bufferFromBuffer(dst, srcPF, src, pixels, 1, pixels, pixels); +} + +void PixelFormat::bufferFromBuffer(rdr::U8* dst, const PixelFormat &srcPF, + const rdr::U8* src, int w, int h, + int dstStride, int srcStride) const +{ + if (equal(srcPF)) { + // Trivial case + while (h--) { + memcpy(dst, src, w * bpp/8); + dst += dstStride * bpp/8; + src += srcStride * srcPF.bpp/8; + } + } else { + // Generic code + int dstPad = (dstStride - w) * bpp/8; + int srcPad = (srcStride - w) * srcPF.bpp/8; + while (h--) { + int w_ = w; + while (w_--) { + Pixel p; + rdr::U8 r, g, b; + + p = srcPF.pixelFromBuffer(src); + srcPF.rgbFromPixel(p, &r, &g, &b); + p = pixelFromRGB(r, g, b); + bufferFromPixel(dst, p); + + dst += bpp/8; + src += srcPF.bpp/8; + } + dst += dstPad; + src += srcPad; + } + } +} + + void PixelFormat::print(char* str, int len) const { // Unfortunately snprintf is not widely available so we build the string up diff --git a/common/rfb/PixelFormat.h b/common/rfb/PixelFormat.h index db129883..b18045f7 100644 --- a/common/rfb/PixelFormat.h +++ b/common/rfb/PixelFormat.h @@ -75,6 +75,14 @@ namespace rfb { void rgbFromBuffer(rdr::U8* dst, const rdr::U8* src, int w, int stride, int h) const; + Pixel pixelFromPixel(const PixelFormat &srcPF, Pixel src) const; + + void bufferFromBuffer(rdr::U8* dst, const PixelFormat &srcPF, + const rdr::U8* src, int pixels) const; + void bufferFromBuffer(rdr::U8* dst, const PixelFormat &srcPF, + const rdr::U8* src, int w, int h, + int dstStride, int srcStride) const; + void print(char* str, int len) const; bool parse(const char* str); |