Unify Code of getting color space 83/169783/2
authorhj kim <backto.kim@samsung.com>
Fri, 9 Feb 2018 04:48:04 +0000 (13:48 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 9 Feb 2018 04:54:11 +0000 (13:54 +0900)
Change-Id: I5a913b125a2c87d94c2db35913ecff47f5dfe2be

gstcs/mm_util_gstcs.c

index df2b293..6e92c5d 100755 (executable)
@@ -188,11 +188,9 @@ _mm_link_pipeline(gstreamer_s* pGstreamer_s, int value)
        g_object_set(pGstreamer_s->appsink, "emit-signals", TRUE, "sync", FALSE, NULL);
 }
 
-static void
-_mm_set_image_input_format_s_capabilities(image_format_s* __format) /*_format_label: I420 _colorsapace: YUV */
+static GstVideoFormat _mm_get_video_format(char *format_label)
 {
-       char _format_name[sizeof(GST_VIDEO_FORMATS_ALL)] = {'\0'};
-       GstVideoFormat videoFormat;
+       GstVideoFormat videoFormat = GST_VIDEO_FORMAT_UNKNOWN;
        int _bpp = 0;
        int _depth = 0;
        int _red_mask = 0;
@@ -201,28 +199,77 @@ _mm_set_image_input_format_s_capabilities(image_format_s* __format) /*_format_la
        int _alpha_mask = 0;
        int _endianness = 0;
 
+       if (format_label == NULL) {
+               gstcs_error("Wrong format label");
+               return videoFormat;
+       }
+
+       if (strcmp(format_label, "I420") == 0)
+               videoFormat = GST_VIDEO_FORMAT_I420;
+       else if (strcmp(format_label, "Y42B") == 0)
+               videoFormat = GST_VIDEO_FORMAT_Y42B;
+       else if (strcmp(format_label, "Y444") == 0)
+               videoFormat = GST_VIDEO_FORMAT_Y444;
+       else if (strcmp(format_label, "YV12") == 0)
+               videoFormat = GST_VIDEO_FORMAT_YV12;
+       else if (strcmp(format_label, "NV12") == 0)
+               videoFormat = GST_VIDEO_FORMAT_NV12;
+       else if (strcmp(format_label, "UYVY") == 0)
+               videoFormat = GST_VIDEO_FORMAT_UYVY;
+       else if (strcmp(format_label, "YUYV") == 0)
+               videoFormat = GST_VIDEO_FORMAT_YVYU;
+       else if (strcmp(format_label, "RGB888") == 0) {
+               _bpp = 24; _depth = 24; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _endianness = 4321; _alpha_mask = 0;
+               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
+       } else if (strcmp(format_label, "BGR888") == 0) {
+               _bpp = 24; _depth = 24; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _endianness = 4321; _alpha_mask = 0;
+               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
+       } else if (strcmp(format_label, "RGB565") == 0) {
+               _bpp = 16; _depth = 16; _red_mask = 63488; _green_mask = 2016; _blue_mask = 31; _endianness = 1234; _alpha_mask = 0;
+               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
+       } else if ((strcmp(format_label, "BGRX") == 0)) {
+               _bpp = 32; _depth = 24; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _endianness = 4321; _alpha_mask = 0;
+               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
+       } else if (strcmp(format_label, "ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
+               gstcs_debug("ARGB8888");
+               _bpp = 32; _depth = 32; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _alpha_mask = -16777216; _endianness = 4321;
+               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
+       } else if (strcmp(format_label, "BGRA8888") == 0) { /*[Low Arrary Address] BGRABGRA...[High Array Address]*/
+               gstcs_debug("BGRA8888");
+               _bpp = 32; _depth = 32; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _alpha_mask = 255; _endianness = 4321;
+       } else if (strcmp(format_label, "RGBA8888") == 0) { /*[Low Arrary Address] RGBARGBA...[High Array Address]*/
+               gstcs_debug("RGBA8888");
+               _bpp = 32; _depth = 32; _red_mask = -16777216; _green_mask = 16711680; _blue_mask = 65280; _alpha_mask = 255; _endianness = 4321;
+       } else if (strcmp(format_label, "ABGR8888") == 0) { /*[Low Arrary Address] ABGRABGR...[High Array Address]*/
+               gstcs_debug("ABGR8888");
+               _bpp = 32; _depth = 32; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _alpha_mask = -16777216; _endianness = 4321;
+       } else {
+               gstcs_error("***Wrong format cs type***");
+       }
+
+       gstcs_debug("format_label [%s], Chosen video format [%s]", format_label, gst_video_format_to_string(videoFormat));
+
+       return videoFormat;
+
+}
+
+static void
+_mm_set_image_input_format_s_capabilities(image_format_s* __format) /*_format_label: I420 _colorsapace: YUV */
+{
+       GstVideoFormat videoFormat = GST_VIDEO_FORMAT_UNKNOWN;
+
        if (__format == NULL) {
                gstcs_error("Image format is NULL\n");
                return;
        }
 
        gstcs_debug("colorspace: %s(%d)\n", __format->colorspace, strlen(__format->colorspace));
-       memset(_format_name, 0, sizeof(_format_name));
+
+       videoFormat = _mm_get_video_format(__format->format_label);
 
        if (strcmp(__format->colorspace, "YUV") == 0) {
-               if (strcmp(__format->format_label, "I420") == 0
-               || strcmp(__format->format_label, "Y42B") == 0
-               || strcmp(__format->format_label, "Y444") == 0
-               || strcmp(__format->format_label, "YV12") == 0
-               || strcmp(__format->format_label, "NV12") == 0
-               || strcmp(__format->format_label, "UYVY") == 0) {
-                       SAFE_STRCPY(_format_name, __format->format_label, sizeof(_format_name));
-               } else if (strcmp(__format->format_label, "YUYV") == 0) {
-                       SAFE_STRCPY(_format_name, "YVYU", sizeof(_format_name));
-               }
-               gstcs_debug("Chosen video format: %s", _format_name);
                __format->caps = gst_caps_new_simple("video/x-raw",
-                       "format", G_TYPE_STRING, _format_name,
+                       "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
                        "framerate", GST_TYPE_FRACTION, 25, 1,
                        "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
                        "width", G_TYPE_INT, __format->width,
@@ -232,19 +279,6 @@ _mm_set_image_input_format_s_capabilities(image_format_s* __format) /*_format_la
        }
 
        else if (strcmp(__format->colorspace, "RGB") == 0 || strcmp(__format->colorspace, "BGRX") == 0) {
-               if (strcmp(__format->format_label, "RGB888") == 0) {
-                       _bpp = 24; _depth = 24; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "BGR888") == 0) {
-                       _bpp = 24; _depth = 24; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "RGB565") == 0) {
-                       _bpp = 16; _depth = 16; _red_mask = 63488; _green_mask = 2016; _blue_mask = 31; _endianness = 1234;
-               } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
-                       _bpp = 32; _depth = 24; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _endianness = 4321;
-               }
-
-               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, 0);
-               gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
-
                __format->caps = gst_caps_new_simple("video/x-raw",
                        "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
                        "width", G_TYPE_INT, __format->stride,
@@ -253,25 +287,6 @@ _mm_set_image_input_format_s_capabilities(image_format_s* __format) /*_format_la
        }
 
        else if (strcmp(__format->colorspace, "RGBA") == 0) {
-               if (strcmp(__format->format_label, "ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
-                       gstcs_debug("ARGB8888");
-                       _bpp = 32; _depth = 32; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _alpha_mask = -16777216; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "BGRA8888") == 0) { /*[Low Arrary Address] BGRABGRA...[High Array Address]*/
-                       gstcs_debug("BGRA8888");
-                       _bpp = 32; _depth = 32; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _alpha_mask = 255; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "RGBA8888") == 0) { /*[Low Arrary Address] RGBARGBA...[High Array Address]*/
-                       gstcs_debug("RGBA8888");
-                       _bpp = 32; _depth = 32; _red_mask = -16777216; _green_mask = 16711680; _blue_mask = 65280; _alpha_mask = 255; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "ABGR8888") == 0) { /*[Low Arrary Address] ABGRABGR...[High Array Address]*/
-                       gstcs_debug("ABGR8888");
-                       _bpp = 32; _depth = 32; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _alpha_mask = -16777216; _endianness = 4321;
-               } else {
-                       gstcs_error("***Wrong format cs type***\n");
-               }
-
-               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
-               gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
-
                __format->caps = gst_caps_new_simple("video/x-raw",
                        "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
                        "width", G_TYPE_INT, __format->width,
@@ -290,32 +305,20 @@ _mm_set_image_input_format_s_capabilities(image_format_s* __format) /*_format_la
 static void
 _mm_set_image_output_format_s_capabilities(image_format_s* __format) /*_format_label: I420 _colorsapace: YUV */
 {
-       char _format_name[sizeof(GST_VIDEO_FORMATS_ALL)] = {'\0'};
-       GstVideoFormat videoFormat;
-       int _bpp = 0; int _depth = 0; int _red_mask = 0; int _green_mask = 0; int _blue_mask = 0; int _alpha_mask = 0; int _endianness = 0;
+       GstVideoFormat videoFormat = GST_VIDEO_FORMAT_UNKNOWN;
 
        if (__format == NULL) {
                gstcs_error("Image format is NULL\n");
                return;
        }
 
-       gstcs_debug("colorspace: %s(%d), w: %d, h: %d\n", __format->colorspace, strlen(__format->colorspace), __format->width, __format->height);
-       memset(_format_name, 0, sizeof(_format_name));
+       gstcs_debug("colorspace: %s(%d)\n", __format->colorspace, strlen(__format->colorspace));
+
+       videoFormat = _mm_get_video_format(__format->format_label);
 
        if (strcmp(__format->colorspace, "YUV") == 0) {
-               if (strcmp(__format->format_label, "I420") == 0
-               || strcmp(__format->format_label, "Y42B") == 0
-               || strcmp(__format->format_label, "Y444") == 0
-               || strcmp(__format->format_label, "YV12") == 0
-               || strcmp(__format->format_label, "NV12") == 0
-               || strcmp(__format->format_label, "UYVY") == 0) {
-                       SAFE_STRCPY(_format_name, __format->format_label, sizeof(_format_name));
-               } else if (strcmp(__format->format_label, "YUYV") == 0) {
-                       SAFE_STRCPY(_format_name, "YVYU", sizeof(_format_name));
-               }
-               gstcs_debug("Chosen video format: %s", _format_name);
                __format->caps = gst_caps_new_simple("video/x-raw",
-                       "format", G_TYPE_STRING, _format_name,
+                       "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
                        "width", G_TYPE_INT, __format->width,
                        "height", G_TYPE_INT, __format->height,
                        "framerate", GST_TYPE_FRACTION, 1, 1,
@@ -323,19 +326,6 @@ _mm_set_image_output_format_s_capabilities(image_format_s* __format) /*_format_l
        }
 
        else if (strcmp(__format->colorspace, "RGB") == 0 || strcmp(__format->colorspace, "BGRX") == 0) {
-               if (strcmp(__format->format_label, "RGB888") == 0) {
-                       _bpp = 24; _depth = 24; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "BGR888") == 0) {
-                       _bpp = 24; _depth = 24; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "RGB565") == 0) {
-                       _bpp = 16; _depth = 16; _red_mask = 63488; _green_mask = 2016; _blue_mask = 31; _endianness = 1234;
-               } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
-                       _bpp = 32; _depth = 24; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _endianness = 4321;
-               }
-
-               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, 0);
-               gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
-
                __format->caps = gst_caps_new_simple("video/x-raw",
                        "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
                        "width", G_TYPE_INT, __format->width,
@@ -344,25 +334,6 @@ _mm_set_image_output_format_s_capabilities(image_format_s* __format) /*_format_l
        }
 
        else if (strcmp(__format->colorspace, "RGBA") == 0) {
-               if (strcmp(__format->format_label, "ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
-                       gstcs_debug("ARGB8888");
-                       _bpp = 32; _depth = 32; _red_mask = 16711680; _green_mask = 65280; _blue_mask = 255; _alpha_mask = -16777216; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "BGRA8888") == 0) { /*[Low Arrary Address] BGRABGRA...[High Array Address]*/
-                       gstcs_debug("BGRA8888");
-                       _bpp = 32; _depth = 32; _red_mask = 65280; _green_mask = 16711680; _blue_mask = -16777216; _alpha_mask = 255; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "RGBA8888") == 0) { /*[Low Arrary Address] RGBARGBA...[High Array Address]*/
-                       gstcs_debug("RGBA8888");
-                       _bpp = 32; _depth = 32; _red_mask = -16777216; _green_mask = 16711680; _blue_mask = 65280; _alpha_mask = 255; _endianness = 4321;
-               } else if (strcmp(__format->format_label, "ABGR8888") == 0) { /*[Low Arrary Address] ABGRABGR...[High Array Address]*/
-                       gstcs_debug("ABGR8888");
-                       _bpp = 32; _depth = 32; _red_mask = 255; _green_mask = 65280; _blue_mask = 16711680; _alpha_mask = -16777216; _endianness = 4321;
-               } else {
-                       gstcs_error("***Wrong format cs type***\n");
-               }
-
-               videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
-               gstcs_debug("Chosen video format: %s", gst_video_format_to_string(videoFormat));
-
                __format->caps = gst_caps_new_simple("video/x-raw",
                        "format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
                        "width", G_TYPE_INT, __format->width,