File U_tigervnc-restore-cropping-API-to-maskRect.patch of Package tigervnc.openSUSE_Leap_42.2_Update

From 99871831d057337477d406fd48050286fa9833f9 Mon Sep 17 00:00:00 2001
From: Pierre Ossman <ossman@cendio.se>
Date: Fri, 20 Jan 2017 15:57:21 +0100
Subject: [PATCH] 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.

diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx
index f444aa0..e788fca 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 ba586b0..b38999a 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
openSUSE Build Service is sponsored by