return TRUE;
}
-static int
-_mm_get_byte_per_pixcel(const char *__format_label)
+static int _mm_get_byte_per_pixcel(mm_util_color_format_e color_format)
{
int byte_per_pixcel = 1;
- if (strcmp(__format_label, "RGB565") == 0) {
+
+ switch (color_format) {
+ case MM_UTIL_COLOR_YUV420:
+ case MM_UTIL_COLOR_YUV422:
+ case MM_UTIL_COLOR_I420:
+ case MM_UTIL_COLOR_NV12:
+ case MM_UTIL_COLOR_UYVY:
+ case MM_UTIL_COLOR_YUYV:
+ byte_per_pixcel = 1;
+ break;
+ case MM_UTIL_COLOR_RGB16:
byte_per_pixcel = 2;
- } else if (strcmp(__format_label, "RGB888") == 0 ||
- strcmp(__format_label, "BGR888") == 0) {
+ break;
+ case MM_UTIL_COLOR_RGB24:
byte_per_pixcel = 3;
- } else if (strcmp(__format_label, "RGBA8888") == 0 ||
- strcmp(__format_label, "ARGB8888") == 0 ||
- strcmp(__format_label, "BGRA8888") == 0 ||
- strcmp(__format_label, "ABGR8888") == 0 ||
- strcmp(__format_label, "RGBX") == 0 ||
- strcmp(__format_label, "XRGB") == 0 ||
- strcmp(__format_label, "BGRX") == 0 ||
- strcmp(__format_label, "XBGR") == 0) {
+ break;
+ case MM_UTIL_COLOR_ARGB:
+ case MM_UTIL_COLOR_BGRA:
+ case MM_UTIL_COLOR_RGBA:
+ case MM_UTIL_COLOR_BGRX:
byte_per_pixcel = 4;
+ break;
+ default:
+ gstcs_error("Not supported format");
+ break;
}
- gstcs_debug("byte per pixcel : %d", byte_per_pixcel);
+ gstcs_debug("color_format [%d] byte per pixcel [%d]", color_format, byte_per_pixcel);
return byte_per_pixcel;
}
g_object_set(pGstreamer_s->appsink, "emit-signals", TRUE, "sync", FALSE, NULL);
}
-static GstVideoFormat _mm_get_video_format(char *format_label)
+static GstVideoFormat _mm_get_video_format(mm_util_color_format_e color_format)
{
GstVideoFormat videoFormat = GST_VIDEO_FORMAT_UNKNOWN;
int _bpp = 0;
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)
+ switch (color_format) {
+ case MM_UTIL_COLOR_YUV420:
videoFormat = GST_VIDEO_FORMAT_YV12;
- else if (strcmp(format_label, "NV12") == 0)
+ break;
+ case MM_UTIL_COLOR_YUV422:
+ videoFormat = GST_VIDEO_FORMAT_Y42B;
+ break;
+ case MM_UTIL_COLOR_I420:
+ videoFormat = GST_VIDEO_FORMAT_I420;
+ break;
+ case MM_UTIL_COLOR_NV12:
videoFormat = GST_VIDEO_FORMAT_NV12;
- else if (strcmp(format_label, "UYVY") == 0)
+ break;
+ case MM_UTIL_COLOR_UYVY:
videoFormat = GST_VIDEO_FORMAT_UYVY;
- else if (strcmp(format_label, "YUYV") == 0)
+ break;
+ case MM_UTIL_COLOR_YUYV:
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) {
+ break;
+ case MM_UTIL_COLOR_RGB16:
_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;
+ break;
+ case MM_UTIL_COLOR_RGB24:
+ _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, "ARGB8888") == 0) { /*[Low Arrary Address] ARGBARGB... [High Array Address]*/
- gstcs_debug("ARGB8888");
+ break;
+ case MM_UTIL_COLOR_ARGB:
_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");
+ break;
+ case MM_UTIL_COLOR_BGRA:
_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");
+ videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
+ break;
+ case MM_UTIL_COLOR_RGBA:
_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***");
+ videoFormat = gst_video_format_from_masks(_depth, _bpp, _endianness, _red_mask, _green_mask, _blue_mask, _alpha_mask);
+ break;
+ case MM_UTIL_COLOR_BGRX:
+ _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);
+ break;
+ default:
+ gstcs_error("Not supported format");
+ break;
}
- gstcs_debug("format_label [%s], Chosen video format [%s]", format_label, gst_video_format_to_string(videoFormat));
+ gstcs_debug("color_format [%d], Chosen video format [%s]", color_format, gst_video_format_to_string(videoFormat));
return videoFormat;
return;
}
- videoFormat = _mm_get_video_format(__format->format_label);
+ videoFormat = _mm_get_video_format(__format->color_format);
__format->caps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, gst_video_format_to_string(videoFormat),
}
}
-static void _mm_set_image_colorspace(image_format_s* __format)
-{
- gstcs_debug("format_label: %s\n", __format->format_label);
-
- 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) || (strcmp(__format->format_label, "YUYV") == 0)) {
- __format->colorspace = g_strdup("YUV");
- } else if ((strcmp(__format->format_label, "RGB888") == 0) || (strcmp(__format->format_label, "BGR888") == 0) || (strcmp(__format->format_label, "RGB565") == 0)) {
- __format->colorspace = g_strdup("RGB");
- } else if ((strcmp(__format->format_label, "ARGB8888") == 0) || (strcmp(__format->format_label, "BGRA8888") == 0) || (strcmp(__format->format_label, "RGBA8888") == 0) || (strcmp(__format->format_label, "ABGR8888") == 0)) {
- __format->colorspace = g_strdup("RGBA");
- } else if ((strcmp(__format->format_label, "BGRX") == 0)) {
- __format->colorspace = g_strdup("BGRX");
- } else {
- gstcs_error("Check your colorspace format label");
- }
-}
-
static int _gstcs_create_image_format(image_format_s **format)
{
int ret = GSTCS_ERROR_NONE;
{
if (format != NULL) {
gst_caps_unref(format->caps);
- GSTCS_FREE(format->format_label);
- GSTCS_FREE(format->colorspace);
GSTCS_FREE(format);
}
}
static void _mm_round_up_widh_height(image_format_s* pFormat)
{
- if (strcmp(pFormat->colorspace, "YUV") == 0) {
+ switch (pFormat->color_format) {
+ case MM_UTIL_COLOR_YUV420:
+ case MM_UTIL_COLOR_YUV422:
+ case MM_UTIL_COLOR_I420:
+ case MM_UTIL_COLOR_NV12:
+ case MM_UTIL_COLOR_UYVY:
+ case MM_UTIL_COLOR_YUYV:
pFormat->stride = pFormat->width;
pFormat->elevation = pFormat->height;
- } else if (strcmp(pFormat->colorspace, "RGB") == 0) {
+ break;
+ case MM_UTIL_COLOR_RGB16:
+ case MM_UTIL_COLOR_RGB24:
pFormat->stride = MM_UTIL_ROUND_UP_4(pFormat->width);
pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
- } else if ((strcmp(pFormat->colorspace, "RGBA") == 0) || (strcmp(pFormat->colorspace, "BGRX") == 0)) {
+ break;
+ case MM_UTIL_COLOR_ARGB:
+ case MM_UTIL_COLOR_BGRA:
+ case MM_UTIL_COLOR_RGBA:
+ case MM_UTIL_COLOR_BGRX:
pFormat->stride = pFormat->width;
pFormat->elevation = MM_UTIL_ROUND_UP_2(pFormat->height);
+ break;
+ default:
+ gstcs_error("Not supported format");
+ break;
}
- gstcs_debug("stride: %d, elevation: %d", pFormat->stride, pFormat->elevation);
+
+ gstcs_debug("color_format [%d] stride [%d], elevation [%d]", pFormat->color_format, pFormat->stride, pFormat->elevation);
}
static image_format_s* _mm_set_input_image_format_s_struct(imgp_info_s* pImgp_info)
return NULL;
}
- __format->format_label = g_strdup(pImgp_info->input_format_label);
- _mm_set_image_colorspace(__format);
-
+ __format->color_format = pImgp_info->src_format;
__format->width = pImgp_info->src_width;
__format->height = pImgp_info->src_height;
_mm_round_up_widh_height(__format);
_mm_set_capabilities(__format);
- gstcs_debug("input_format_label: %s", pImgp_info->input_format_label);
-
return __format;
}
return NULL;
}
- __format->format_label = g_strdup(pImgp_info->output_format_label);
- _mm_set_image_colorspace(__format);
-
+ __format->color_format = pImgp_info->dst_format;
__format->width = pImgp_info->dst_width;
__format->height = pImgp_info->dst_height;
_mm_round_up_widh_height(__format);
pImgp_info->output_stride = __format->stride;
pImgp_info->output_elevation = __format->elevation;
- gstcs_debug("output_format_label: %s", pImgp_info->output_format_label);
-
return __format;
}
-static int _mm_setup_image_size(const char* _format_label, int width, int height)
+static int _mm_setup_image_size(mm_util_color_format_e color_format, int width, int height)
{
int size = 0;
- if (strcmp(_format_label, "I420") == 0)
- size = (MM_UTIL_ROUND_UP_4(width) * MM_UTIL_ROUND_UP_2(height) + MM_UTIL_ROUND_UP_8(width) * MM_UTIL_ROUND_UP_2(height) /2); /*width * height *1.5; */
- else if (strcmp(_format_label, "Y42B") == 0)
- size = (MM_UTIL_ROUND_UP_4(width) * height + MM_UTIL_ROUND_UP_8(width) * height); /*width * height *2; */
- else if (strcmp(_format_label, "YUV422") == 0)
- size = (MM_UTIL_ROUND_UP_4(width) * height + MM_UTIL_ROUND_UP_8(width) * height); /*width * height *2; */
- else if (strcmp(_format_label, "Y444") == 0)
- size = (MM_UTIL_ROUND_UP_4(width) * height * 3); /* width * height *3; */
- else if (strcmp(_format_label, "YV12") == 0)
+ gstcs_debug("color_format: %d", color_format);
+
+ switch (color_format) {
+ case MM_UTIL_COLOR_YUV420:
size = (MM_UTIL_ROUND_UP_4(width) * MM_UTIL_ROUND_UP_2(height) + MM_UTIL_ROUND_UP_8(width) * MM_UTIL_ROUND_UP_2(height) / 2); /* width * height *1; */
- else if (strcmp(_format_label, "NV12") == 0)
+ break;
+ case MM_UTIL_COLOR_YUV422:
+ size = (MM_UTIL_ROUND_UP_4(width) * height + MM_UTIL_ROUND_UP_8(width) * height); /*width * height *2; */
+ break;
+ case MM_UTIL_COLOR_I420:
+ size = (MM_UTIL_ROUND_UP_4(width) * MM_UTIL_ROUND_UP_2(height) + MM_UTIL_ROUND_UP_8(width) * MM_UTIL_ROUND_UP_2(height) /2); /*width * height *1.5; */
+ break;
+ case MM_UTIL_COLOR_NV12:
size = (MM_UTIL_ROUND_UP_4(width) * MM_UTIL_ROUND_UP_2(height) * 1.5); /* width * height *1.5; */
- else if (strcmp(_format_label, "RGB565") == 0)
- size = (MM_UTIL_ROUND_UP_4(width) * 2 * height); /* width * height *2; */
- else if (strcmp(_format_label, "RGB888") == 0)
- size = (MM_UTIL_ROUND_UP_4(width) * 3 * height); /* width * height *3; */
- else if (strcmp(_format_label, "BGR888") == 0)
- size = (MM_UTIL_ROUND_UP_4(width) * 3 * height); /* width * height *3; */
- else if (strcmp(_format_label, "UYVY") == 0)
+ break;
+ case MM_UTIL_COLOR_UYVY:
size = (MM_UTIL_ROUND_UP_2(width) * 2 * height); /* width * height *2; */
- else if (strcmp(_format_label, "YUYV") == 0)
+ break;
+ case MM_UTIL_COLOR_YUYV:
size = (MM_UTIL_ROUND_UP_2(width) * 2 * height); /* width * height *2; */
- else if (strcmp(_format_label, "ARGB8888") == 0)
- size = width * height *4;
- else if (strcmp(_format_label, "BGRA8888") == 0)
- size = width * height *4;
- else if (strcmp(_format_label, "RGBA8888") == 0)
- size = width * height *4;
- else if (strcmp(_format_label, "ABGR8888") == 0)
- size = width * height *4;
- else if (strcmp(_format_label, "BGRX") == 0)
+ break;
+ case MM_UTIL_COLOR_RGB16:
+ size = (MM_UTIL_ROUND_UP_4(width) * 2 * height); /* width * height *2; */
+ break;
+ case MM_UTIL_COLOR_RGB24:
+ size = (MM_UTIL_ROUND_UP_4(width) * 3 * height); /* width * height *3; */
+ break;
+ case MM_UTIL_COLOR_ARGB:
+ case MM_UTIL_COLOR_BGRA:
+ case MM_UTIL_COLOR_RGBA:
+ case MM_UTIL_COLOR_BGRX:
size = width * height *4;
+ break;
+ default:
+ gstcs_error("Not supported format");
+ break;
+ }
+
- gstcs_debug("file_size: %d\n", size);
+ gstcs_debug("Image size: %d", size);
return size;
}
return GSTCS_ERROR_INVALID_PARAMETER;
}
- gsize data_size = _mm_setup_image_size(pImgp_info->input_format_label, pImgp_info->src_width, pImgp_info->src_height);
+ gsize data_size = _mm_setup_image_size(pImgp_info->src_format, pImgp_info->src_width, pImgp_info->src_height);
GstBuffer* gst_buf = gst_buffer_new_wrapped_full(GST_MEMORY_FLAG_READONLY, src, data_size, 0, data_size, NULL, NULL);
if (gst_buf == NULL) {
}
gstcs_debug("stride: %d, elevation: %d", stride, elevation);
- src_size = _mm_setup_image_size(input_format->format_label, stride, elevation);
+ src_size = _mm_setup_image_size(input_format->color_format, stride, elevation);
gstcs_debug("buffer size (src): %d", src_size);
- int byte_per_pixcel = _mm_get_byte_per_pixcel(input_format->format_label);
+ int byte_per_pixcel = _mm_get_byte_per_pixcel(input_format->color_format);
unsigned int src_row = input_format->width * byte_per_pixcel;
unsigned int stride_row = stride * byte_per_pixcel;
unsigned int i = 0, y = 0;
int buffer_size = mapinfo.size;
int calc_buffer_size = 0;
- calc_buffer_size = _mm_setup_image_size(pImgp_info->output_format_label, output_format->stride, output_format->elevation);
+ calc_buffer_size = _mm_setup_image_size(pImgp_info->dst_format, output_format->stride, output_format->elevation);
gstcs_debug("buffer size: %d, calc: %d\n", buffer_size, calc_buffer_size);
if (buffer_size != calc_buffer_size) {