Merge branch 'tizen' into sandbox/cyeon/devel
[platform/core/uifw/libtdm.git] / tools / buffers.c
index 805383b..ea88179 100644 (file)
@@ -37,8 +37,8 @@
 #include <tbm_bufmgr.h>
 #include <tbm_surface.h>
 
-#include <tdm_log.h>
-#include "tdm_macro.h"
+/* LCOV_EXCL_START */
+
 #include "buffers.h"
 
 #define ALPHA_VALUE  100
@@ -125,7 +125,7 @@ static const struct format_info format_info[] = {
        { TBM_FORMAT_RGB888, "RG24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
        /* RGB32 */
        { TBM_FORMAT_ARGB8888, "AR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 8, 24) },
-       { TBM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 0) },
+       { TBM_FORMAT_XRGB8888, "XR24", MAKE_RGB_INFO(8, 16, 8, 8, 8, 0, 0, 24) },
        { TBM_FORMAT_ABGR8888, "AB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 8, 24) },
        { TBM_FORMAT_XBGR8888, "XB24", MAKE_RGB_INFO(8, 0, 8, 8, 8, 16, 0, 0) },
        { TBM_FORMAT_RGBA8888, "RA24", MAKE_RGB_INFO(8, 24, 8, 16, 8, 8, 8, 0) },
@@ -159,7 +159,7 @@ unsigned int format_fourcc(const char *name)
  */
 
 struct color_rgb24 {
-       unsigned int value: 24;
+       unsigned int value:24;
 } __attribute__((__packed__));
 
 struct color_yuv {
@@ -169,7 +169,7 @@ struct color_yuv {
 };
 
 #define MAKE_YUV_601_Y(r, g, b) \
-       ((( 66 * (r) + 129 * (g) +  25 * (b) + 128) >> 8) + 16)
+       (((66 * (r) + 129 * (g) +  25 * (b) + 128) >> 8) + 16)
 #define MAKE_YUV_601_U(r, g, b) \
        (((-38 * (r) -  74 * (g) + 112 * (b) + 128) >> 8) + 128)
 #define MAKE_YUV_601_V(r, g, b) \
@@ -186,6 +186,12 @@ struct color_yuv {
         (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
         (((a) >> (8 - (rgb)->alpha.length)) << (rgb)->alpha.offset))
 
+#define MAKE_RGBX(rgb, r, g, b) \
+               ((((r) >> (8 - (rgb)->red.length)) << (rgb)->red.offset) | \
+                (((g) >> (8 - (rgb)->green.length)) << (rgb)->green.offset) | \
+                (((b) >> (8 - (rgb)->blue.length)) << (rgb)->blue.offset) | \
+                (255 << (rgb)->alpha.offset))
+
 #define MAKE_RGB24(rgb, r, g, b) \
        { .value = MAKE_RGBA(rgb, r, g, b, 0) }
 
@@ -248,8 +254,12 @@ fill_smpte_yuv_planar(const struct yuv_info *yuv,
                for (; x < width * 6 / 7; ++x)
                        y_mem[x] = colors_bottom[(x - width * 5 / 7) * 3
                                                                         / (width / 7) + 4].y;
-               for (; x < width; ++x)
-                       y_mem[x] = colors_bottom[7].y;
+               for (; x < width; ++x) {
+                       if (rand_r(&rand_seed) % 2)
+                               y_mem[x] = colors_bottom[1].y;
+                       else
+                               y_mem[x] = colors_bottom[7].y;
+               }
                y_mem += stride;
        }
 
@@ -286,8 +296,13 @@ fill_smpte_yuv_planar(const struct yuv_info *yuv,
                                                                                                 3 / (width / 7) + 4].v;
                }
                for (; x < width; x += xsub) {
-                       u_mem[x * cs / xsub] = colors_bottom[7].u;
-                       v_mem[x * cs / xsub] = colors_bottom[7].v;
+                       if (rand_r(&rand_seed) % 2) {
+                               u_mem[x * cs / xsub] = colors_bottom[1].u;
+                               v_mem[x * cs / xsub] = colors_bottom[1].v;
+                       } else {
+                               u_mem[x * cs / xsub] = colors_bottom[7].u;
+                               v_mem[x * cs / xsub] = colors_bottom[7].v;
+                       }
                }
                u_mem += stride * cs / xsub;
                v_mem += stride * cs / xsub;
@@ -585,9 +600,72 @@ fill_smpte_rgb32(const struct rgb_info *rgb, unsigned char *mem,
                        ((uint32_t *)mem)[x] =
                                colors_bottom[(x - width * 5 / 7) * 3
                                                          / (width / 7) + 4];
-               for (; x < width; ++x) {
+               for (; x < width; ++x)
                        ((uint32_t *)mem)[x] = (rand_r(&rand_seed) % 2) ? MAKE_RGBA(rgb, 255, 255, 255, ALPHA_VALUE) : MAKE_RGBA(rgb, 0, 0, 0, ALPHA_VALUE);
-               }
+               mem += stride;
+       }
+}
+
+static void
+fill_smpte_rgb32_dont_care_alpha(const struct rgb_info *rgb, unsigned char *mem,
+                                                                unsigned int width, unsigned int height, unsigned int stride)
+{
+       const uint32_t colors_top[] = {
+               MAKE_RGBX(rgb, 192, 192, 192),  /* grey */
+               MAKE_RGBX(rgb, 192, 192, 0),    /* yellow */
+               MAKE_RGBX(rgb, 0, 192, 192),    /* cyan */
+               MAKE_RGBX(rgb, 0, 192, 0),              /* green */
+               MAKE_RGBX(rgb, 192, 0, 192),    /* magenta */
+               MAKE_RGBX(rgb, 192, 0, 0),              /* red */
+               MAKE_RGBX(rgb, 0, 0, 192),              /* blue */
+       };
+       const uint32_t colors_middle[] = {
+               MAKE_RGBX(rgb, 0, 0, 192),              /* blue */
+               MAKE_RGBX(rgb, 19, 19, 19),     /* black */
+               MAKE_RGBX(rgb, 192, 0, 192),    /* magenta */
+               MAKE_RGBX(rgb, 19, 19, 19),     /* black */
+               MAKE_RGBX(rgb, 0, 192, 192),    /* cyan */
+               MAKE_RGBX(rgb, 19, 19, 19),     /* black */
+               MAKE_RGBX(rgb, 192, 192, 192),  /* grey */
+       };
+       const uint32_t colors_bottom[] = {
+               MAKE_RGBX(rgb, 0, 33, 76),              /* in-phase */
+               MAKE_RGBX(rgb, 255, 255, 255),  /* super white */
+               MAKE_RGBX(rgb, 50, 0, 106),     /* quadrature */
+               MAKE_RGBX(rgb, 19, 19, 19),     /* black */
+               MAKE_RGBX(rgb, 9, 9, 9),                /* 3.5% */
+               MAKE_RGBX(rgb, 19, 19, 19),     /* 7.5% */
+               MAKE_RGBX(rgb, 29, 29, 29),     /* 11.5% */
+               MAKE_RGBX(rgb, 19, 19, 19),     /* black */
+       };
+       unsigned int x;
+       unsigned int y;
+
+       if (width < 8)
+               return;
+
+       for (y = 0; y < height * 6 / 9; ++y) {
+               for (x = 0; x < width; ++x)
+                       ((uint32_t *)mem)[x] = colors_top[x * 7 / width];
+               mem += stride;
+       }
+
+       for (; y < height * 7 / 9; ++y) {
+               for (x = 0; x < width; ++x)
+                       ((uint32_t *)mem)[x] = colors_middle[x * 7 / width];
+               mem += stride;
+       }
+
+       for (; y < height; ++y) {
+               for (x = 0; x < width * 5 / 7; ++x)
+                       ((uint32_t *)mem)[x] =
+                               colors_bottom[x * 4 / (width * 5 / 7)];
+               for (; x < width * 6 / 7; ++x)
+                       ((uint32_t *)mem)[x] =
+                               colors_bottom[(x - width * 5 / 7) * 3
+                                                         / (width / 7) + 4];
+               for (; x < width; ++x)
+                       ((uint32_t *)mem)[x] = (rand_r(&rand_seed) % 2) ? MAKE_RGBX(rgb, 255, 255, 255) : MAKE_RGBX(rgb, 0, 0, 0);
                mem += stride;
        }
 }
@@ -649,7 +727,6 @@ fill_smpte(const struct format_info *info, void *planes[3], unsigned int width,
                return fill_smpte_rgb24(&info->rgb, planes[0],
                                                                width, height, stride);
        case TBM_FORMAT_ARGB8888:
-       case TBM_FORMAT_XRGB8888:
        case TBM_FORMAT_ABGR8888:
        case TBM_FORMAT_XBGR8888:
        case TBM_FORMAT_RGBA8888:
@@ -666,6 +743,9 @@ fill_smpte(const struct format_info *info, void *planes[3], unsigned int width,
        case TBM_FORMAT_BGRX1010102:
                return fill_smpte_rgb32(&info->rgb, planes[0],
                                                                width, height, stride);
+       case TBM_FORMAT_XRGB8888:
+               return fill_smpte_rgb32_dont_care_alpha(&info->rgb, planes[0],
+                                                                                               width, height, stride);
        }
 }
 
@@ -945,7 +1025,7 @@ tdm_test_buffer_fill(tbm_surface_h buffer, int pattern)
                rand_seed = time(NULL);
 
        ret = tbm_surface_map(buffer, TBM_OPTION_WRITE, &info);
-       TDM_EXIT_IF_FAIL(ret == 0);
+       assert(ret == 0);
 
        plane[0] = info.planes[0].ptr;
        plane[1] = info.planes[1].ptr;
@@ -953,3 +1033,5 @@ tdm_test_buffer_fill(tbm_surface_h buffer, int pattern)
        fill_pattern(info.format, pattern, plane, info.width, info.height, info.planes[0].stride);
        tbm_surface_unmap(buffer);
 }
+
+/* LCOV_EXCL_END */