fix UIHV screenshot of object placed out of screen 86/92986/3 submit/tizen/20161026.151724
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Wed, 19 Oct 2016 17:49:20 +0000 (20:49 +0300)
committerVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 20 Oct 2016 11:08:14 +0000 (04:08 -0700)
Change-Id: Ib2bf26aae6284f604c635352d87a69bde7fb9202
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
ui_viewer/ui_viewer_screenshot.c

index 73501bf..b202b24 100644 (file)
@@ -268,35 +268,65 @@ static void  __set_buffer_size(struct efl_data *data)
        }
 }
 
+static int min(int a, int b)
+{
+       if (a < b)
+               return a;
+       return b;
+}
+
+static int max(int a, int b)
+{
+       if (a > b)
+               return a;
+       return b;
+}
+
 static void *__tbm_surface_to_buf(unsigned char *src, uint32_t src_stride,
                                  uint32_t src_size, int x, int y,
                                  int width, int height)
 {
        int dest_stride;
+       int dest_copy_size;
        void *data, *dest;
-       uint32_t dest_size, n;
+       uint32_t dest_size;
+       int n;
 
-       dest_stride = width * 4;
-       dest_size = dest_stride * height;
+       int dest_x, dest_y, dest_width, dest_height;
+       int src_x, src_y, src_width, src_height;
 
-       if (dest_size > src_size)
-               return NULL;
 
-       data = malloc(dest_size);
+       src_x = max(x, 0);
+       src_y = max(y, 0);
+
+       src_width = src_stride / 4;
+       src_height = src_size / src_stride;
+
+       src_width = max(0, min(x + width, src_width) - src_x);
+       src_height = max(0, min(y + height, src_height) - src_y);
+
+       dest_x = -min(x, 0);
+       dest_y = -min(y, 0);
+       dest_width = width;
+       dest_height = height;
+       dest_stride = dest_width * 4;
+       dest_size = dest_stride * dest_height;
+
+       data = calloc(1, dest_size);
        if (!data)
                return NULL;
 
        dest = data;
-       src = src + y * src_stride + x * 4;
 
-       n = 0;
-       while (n < dest_size) {
-               memcpy(dest, src, dest_stride);
-               n += dest_stride;
+       dest = data + dest_x * 4 + dest_y * dest_stride;
+       src = src + src_x * 4 + src_y * src_stride;
+       dest_copy_size = src_width * 4;
+
+       for (n = 0; n < src_height; n++) {
+               memcpy(dest, src, dest_copy_size);
                dest += dest_stride;
                src += src_stride;
        }
-
        return data;
 }