tbm_surface_internal: Support XBGR, ABGR format in capture 90/260090/1
authorChangyeon Lee <cyeon.lee@samsung.com>
Fri, 18 Jun 2021 08:58:11 +0000 (17:58 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Fri, 18 Jun 2021 09:21:01 +0000 (18:21 +0900)
Change-Id: I19bad30aa8ee6931a7d48495d052d0aab5543cd7

src/tbm_surface_internal.c

index 5089c60..0ed6da8 100644 (file)
@@ -2091,15 +2091,28 @@ _tbm_surface_internal_dump_file_png(const char *file, const void *data, int widt
                for (x = 0; x < width; ++x) {
                        unsigned int curBlock = blocks[(y * (stride >> 2)) + x];
 
-                       if (pixel_size == 3) { // XRGB8888
-                               row[x * pixel_size] = (curBlock & 0xFF);
-                               row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
-                               row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
-                       } else { // ARGB8888
-                               row[x * pixel_size] = (curBlock & 0xFF);
-                               row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
-                               row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
-                               row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
+                       if (pixel_size == 3) { // XRGB8888 or XBGR8888
+                               if (format == TBM_FORMAT_XRGB8888) {
+                                       row[x * pixel_size] = (curBlock & 0xFF);
+                                       row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
+                                       row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
+                               } else {
+                                       row[x * pixel_size] = (curBlock >> 16) & 0xFF;
+                                       row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
+                                       row[2 + x * pixel_size] = (curBlock & 0xFF);
+                               }
+                       } else { // ARGB8888 or ABGR8888
+                               if (format == TBM_FORMAT_ARGB8888) {
+                                       row[x * pixel_size] = (curBlock & 0xFF);
+                                       row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
+                                       row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
+                                       row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
+                               } else {
+                                       row[x * pixel_size] = (curBlock >> 16) & 0xFF;
+                                       row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
+                                       row[2 + x * pixel_size] =  (curBlock & 0xFF);
+                                       row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
+                               }
                        }
                }
        }
@@ -2271,6 +2284,20 @@ tbm_surface_internal_dump_end(void)
                                                        buf_info->info.planes[0].stride,
                                                        TBM_FORMAT_XRGB8888);
                                break;
+                       case TBM_FORMAT_ABGR8888:
+                               _tbm_surface_internal_dump_file_png(file, bo_handle.ptr,
+                                                       buf_info->info.planes[0].stride >> 2,
+                                                       buf_info->info.height,
+                                                       buf_info->info.planes[0].stride,
+                                                       TBM_FORMAT_ABGR8888);
+                               break;
+                       case TBM_FORMAT_XBGR8888:
+                               _tbm_surface_internal_dump_file_png(file, bo_handle.ptr,
+                                                       buf_info->info.planes[0].stride >> 2,
+                                                       buf_info->info.height,
+                                                       buf_info->info.planes[0].stride,
+                                                       TBM_FORMAT_XBGR8888);
+                               break;
                        case TBM_FORMAT_YVU420:
                        case TBM_FORMAT_YUV420:
                                ptr1 = bo_handle.ptr + buf_info->info.planes[0].stride * buf_info->info.height;
@@ -2324,8 +2351,10 @@ _tbm_surface_internal_pixman_format_get(tbm_format format)
 {
        switch (format) {
        case TBM_FORMAT_ARGB8888:
+       case TBM_FORMAT_ABGR8888:
                return PIXMAN_a8r8g8b8;
        case TBM_FORMAT_XRGB8888:
+       case TBM_FORMAT_XBGR8888:
                return PIXMAN_x8r8g8b8;
        default:
                return 0;
@@ -2338,6 +2367,8 @@ _tbm_surface_internal_pixman_format_get(tbm_format format)
  * This function supports only if a buffer has below formats.
  * - TBM_FORMAT_ARGB8888
  * - TBM_FORMAT_XRGB8888
+ * - TBM_FORMAT_ABGR8888
+ * - TBM_FORMAT_XBGR8888
  */
 static tbm_surface_error_e
 _tbm_surface_internal_buffer_scale(void *src_ptr, void *dst_ptr,
@@ -2472,7 +2503,8 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        if (scale_factor > 0.0) {
                const int bpp = 4;
 
-               if (info.format != TBM_FORMAT_ARGB8888 && info.format != TBM_FORMAT_XRGB8888) {
+               if ((info.format != TBM_FORMAT_ARGB8888) && (info.format != TBM_FORMAT_XRGB8888) &&
+                   (info.format != TBM_FORMAT_ABGR8888) && (info.format != TBM_FORMAT_XBGR8888)) {
                        TBM_WRN("Dump with scale skip. unsupported format(%s)\n",
                                          _tbm_surface_internal_format_to_str(info.format));
                        tbm_surface_unmap(surface);
@@ -2512,7 +2544,8 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
                memcpy(&buf_info->info, &info, sizeof(tbm_surface_info_s));
        }
 
-       if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888) {
+       if ((info.format == TBM_FORMAT_ARGB8888) || (info.format == TBM_FORMAT_XRGB8888) ||
+               (info.format == TBM_FORMAT_ABGR8888) || (info.format == TBM_FORMAT_XBGR8888)) {
                postfix = dump_postfix[0];
                format = _tbm_surface_internal_format_to_str(info.format);
        } else
@@ -2538,6 +2571,8 @@ tbm_surface_internal_dump_buffer(tbm_surface_h surface, const char *type)
        switch (info.format) {
        case TBM_FORMAT_ARGB8888:
        case TBM_FORMAT_XRGB8888:
+       case TBM_FORMAT_ABGR8888:
+       case TBM_FORMAT_XBGR8888:
                snprintf(buf_info->name, sizeof(buf_info->name),
                                "%10.3f_%03d%s_%p_%s-%s.%s",
                                 _tbm_surface_internal_get_time(),
@@ -2719,7 +2754,8 @@ tbm_surface_internal_capture_buffer(tbm_surface_h surface, const char *path, con
        ret = tbm_surface_map(surface, TBM_SURF_OPTION_READ|TBM_SURF_OPTION_WRITE, &info);
        TBM_RETURN_VAL_IF_FAIL(ret == TBM_SURFACE_ERROR_NONE, 0);
 
-       if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888)
+       if ((info.format == TBM_FORMAT_ARGB8888) || (info.format == TBM_FORMAT_XRGB8888) ||
+           (info.format == TBM_FORMAT_ABGR8888) || (info.format == TBM_FORMAT_XBGR8888))
                postfix = dump_postfix[0];
        else
                postfix = dump_postfix[1];
@@ -2753,6 +2789,20 @@ tbm_surface_internal_capture_buffer(tbm_surface_h surface, const char *path, con
                                                        info.planes[0].stride,
                                                        TBM_FORMAT_XRGB8888);
                break;
+       case TBM_FORMAT_ABGR8888:
+               _tbm_surface_internal_dump_file_png(file, info.planes[0].ptr,
+                                                       info.width,
+                                                       info.height,
+                                                       info.planes[0].stride,
+                                                       TBM_FORMAT_ABGR8888);
+               break;
+       case TBM_FORMAT_XBGR8888:
+               _tbm_surface_internal_dump_file_png(file, info.planes[0].ptr,
+                                                       info.width,
+                                                       info.height,
+                                                       info.planes[0].stride,
+                                                       TBM_FORMAT_XBGR8888);
+               break;
        case TBM_FORMAT_YVU420:
        case TBM_FORMAT_YUV420:
                _tbm_surface_internal_dump_file_raw(file, info.planes[0].ptr,