diff options
author | Pierre Ossman <ossman@cendio.se> | 2017-01-20 15:57:21 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2017-01-20 15:57:21 +0100 |
commit | 99871831d057337477d406fd48050286fa9833f9 (patch) | |
tree | 8f2149c6b0cfee75bc1109a5f8bb0eef2cd54b8a /common | |
parent | 143f239afac50f88b2e108ca085e32ad90e1e2ff (diff) | |
download | tigervnc-99871831d057337477d406fd48050286fa9833f9.tar.gz tigervnc-99871831d057337477d406fd48050286fa9833f9.zip |
Restore cropping API to maskRect()
We need to restore the previous, more complex API in order to
easily handle masks now that we no longer accept out-of-bounds
operations.
Diffstat (limited to 'common')
-rw-r--r-- | common/rfb/PixelBuffer.cxx | 46 | ||||
-rw-r--r-- | common/rfb/PixelBuffer.h | 8 |
2 files changed, 31 insertions, 23 deletions
diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index f444aa02..e788fcad 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -201,13 +201,15 @@ void ModifiablePixelBuffer::imageRect(const Rect& r, } void ModifiablePixelBuffer::maskRect(const Rect& r, - const void* pixels, const void* mask_) + const void* pixels, + const void* mask_, + const Point& maskPos, + int pStride, int mStride) { int stride; U8* data; U8* mask; - int w, h, bpp, pixelStride, maskStride; - Point offset; + int w, h, bpp; if (!r.enclosed_by(getRect())) throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", @@ -220,45 +222,47 @@ void ModifiablePixelBuffer::maskRect(const Rect& r, w = r.width(); h = r.height(); bpp = getPF().bpp; - pixelStride = r.width(); - maskStride = (r.width() + 7) / 8; + if (pStride == 0) + pStride = r.width(); + if (mStride == 0) + mStride = (r.width() + 7) / 8; - offset = Point(r.tl.x-r.tl.x, r.tl.y-r.tl.y); - mask += offset.y * maskStride; + mask += maskPos.y * mStride; for (int y = 0; y < h; y++) { - int cy = offset.y + y; for (int x = 0; x < w; x++) { - int cx = offset.x + x; + int cx = maskPos.x + x; U8* byte = mask + (cx / 8); int bit = 7 - cx % 8; if ((*byte) & (1 << bit)) { switch (bpp) { case 8: - ((U8*)data)[y * stride + x] = ((U8*)pixels)[cy * pixelStride + cx]; + ((U8*)data)[y * stride + x] = ((U8*)pixels)[y * pStride + x]; break; case 16: - ((U16*)data)[y * stride + x] = ((U16*)pixels)[cy * pixelStride + cx]; + ((U16*)data)[y * stride + x] = ((U16*)pixels)[y * pStride + x]; break; case 32: - ((U32*)data)[y * stride + x] = ((U32*)pixels)[cy * pixelStride + cx]; + ((U32*)data)[y * stride + x] = ((U32*)pixels)[y * pStride + x]; break; } } } - mask += maskStride; + mask += mStride; } commitBufferRW(r); } void ModifiablePixelBuffer::maskRect(const Rect& r, - Pixel pixel, const void* mask_) + Pixel pixel, + const void* mask_, + const Point& maskPos, + int mStride) { int stride; U8* data; U8* mask; - int w, h, bpp, maskStride; - Point offset; + int w, h, bpp; if (!r.enclosed_by(getRect())) throw rfb::Exception("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", @@ -271,13 +275,13 @@ void ModifiablePixelBuffer::maskRect(const Rect& r, w = r.width(); h = r.height(); bpp = getPF().bpp; - maskStride = (r.width() + 7) / 8; + if (mStride == 0) + mStride = (r.width() + 7) / 8; - offset = Point(r.tl.x-r.tl.x, r.tl.y-r.tl.y); - mask += offset.y * maskStride; + mask += maskPos.y * mStride; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { - int cx = offset.x + x; + int cx = maskPos.x + x; U8* byte = mask + (cx / 8); int bit = 7 - cx % 8; if ((*byte) & (1 << bit)) { @@ -294,7 +298,7 @@ void ModifiablePixelBuffer::maskRect(const Rect& r, } } } - mask += maskStride; + mask += mStride; } commitBufferRW(r); diff --git a/common/rfb/PixelBuffer.h b/common/rfb/PixelBuffer.h index ba586b0f..b38999ae 100644 --- a/common/rfb/PixelBuffer.h +++ b/common/rfb/PixelBuffer.h @@ -132,10 +132,14 @@ namespace rfb { // maskPos specifies the pixel offset in the mask to start from. // mask_ is a pointer to the mask bits at (0,0). // pStride and mStride are the strides of the pixel and mask buffers. - void maskRect(const Rect& r, const void* pixels, const void* mask_); + void maskRect(const Rect& r, const void* pixels, const void* mask_, + const Point& maskPos=Point(0, 0), + int pStride=0, int mStride=0); // pixel is the Pixel value to be used where mask_ is set - void maskRect(const Rect& r, Pixel pixel, const void* mask_); + void maskRect(const Rect& r, Pixel pixel, const void* mask_, + const Point& maskPos=Point(0, 0), + int mStride=0); // Render in a specific format // Does the exact same thing as the above methods, but the given |