From 9cbdec67c9973faf950c0eb6ba56f927dfccaf6f Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Wed, 12 Feb 2014 13:24:15 +0100 Subject: [PATCH] Add convenience variant of getImage() --- common/rfb/PixelBuffer.cxx | 20 ++++++++++++++++++++ common/rfb/PixelBuffer.h | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index ed74a874..3f7f3019 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -60,6 +60,26 @@ PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) { } } +void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf, + const Rect& r, int stride) +{ + const rdr::U8* srcBuffer; + int srcStride; + + if (format.equal(pf)) { + getImage(imageBuf, r, stride); + return; + } + + if (stride == 0) + stride = r.width(); + + srcBuffer = getBuffer(r, &srcStride); + + pf.bufferFromBuffer((U8*)imageBuf, format, srcBuffer, r.width(), r.height(), + stride, srcStride); +} + // -=- Modifiable generic pixel buffer class ModifiablePixelBuffer::ModifiablePixelBuffer(const PixelFormat& pf, diff --git a/common/rfb/PixelBuffer.h b/common/rfb/PixelBuffer.h index 7060a014..5bc06c29 100644 --- a/common/rfb/PixelBuffer.h +++ b/common/rfb/PixelBuffer.h @@ -72,6 +72,11 @@ namespace rfb { // stride. Try to avoid using this though as getBuffer() will in // most cases avoid the extra memory copy. void getImage(void* imageBuf, const Rect& r, int stride=0); + // Get pixel data in a given format + // Works just the same as getImage(), but guaranteed to be in a + // specific format. + void getImage(const PixelFormat& pf, void* imageBuf, + const Rect& r, int stride=0); /////////////////////////////////////////////// // Framebuffer update methods -- 2.39.5