Add new header for image-utility internal API 27/87327/1 accepted/tizen/common/20160909.114739 accepted/tizen/ivi/20160909.062503 accepted/tizen/mobile/20160909.062410 accepted/tizen/tv/20160909.062423 accepted/tizen/wearable/20160909.062444 submit/tizen/20160909.003012
authorJiyong Min <jiyong.min@samsung.com>
Wed, 7 Sep 2016 10:33:00 +0000 (19:33 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Wed, 7 Sep 2016 10:33:35 +0000 (19:33 +0900)
Change-Id: I515978613c6715910756558820f84946a214970b
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
libdcm-util/dcm_image_codec.cpp

index 01ffc396db1f507a5c1fb6d61c7c963840221ae5..54c553d70cc6d72e78bc57b93646683b5119edff 100755 (executable)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <image_util.h>
+#include <image_util_internal.h>
 #include <mm_util_imgp.h>
 #include <dcm_image_debug_utils.h>
 #include <dcm_image_codec.h>
@@ -144,6 +145,54 @@ static int _dcm_rotate_image(const unsigned char *source, const dcm_image_format
        return DCM_SUCCESS;
 }
 
+int _dcm_rotate_rgb(unsigned char *source, const unsigned int size, int format, unsigned int *ori_width, unsigned int *ori_height)
+{
+       unsigned int dpp = 0; /* data per pixel */
+       unsigned int x = 0, y = 0;
+       unsigned int i = 0;
+       unsigned int width = 0, height = 0;
+       unsigned char *temp_buf = NULL;
+
+       if (format == DCM_IMAGE_FORMAT_RGBA) {
+               dpp = 4;
+       } else if (format == DCM_IMAGE_FORMAT_RGB) {
+               dpp = 3;
+       } else {
+               dcm_error("Invalid parameter");
+               return DCM_ERROR_INVALID_PARAMETER;
+       }
+
+       temp_buf = malloc(size);
+       if (temp_buf == NULL) {
+               dcm_error("Failed to allocate memory");
+               return DCM_ERROR_OUT_OF_MEMORY;
+       }
+       /* initialize */
+       memset(temp_buf, 0x00, size);
+       width = *ori_width;
+       height = *ori_height;
+
+       /* rotate image to 90 degree clockwise */
+       for (y = 0; y < height; y++)
+       {
+               for (x = 0; x < width; x++) {
+                       for (i = 0; i < dpp; i++) {
+                               temp_buf[(x * height + (height - y - 1)) * dpp + i] = source[(y * width + x) * dpp + i];
+                       }
+               }
+       }
+
+       /* copy image from temp buffer to original buffer */
+       memcpy(source, temp_buf, size);
+       DCM_SAFE_FREE(temp_buf);
+
+       /* swap width & height due to rotate 90 degree */
+       *ori_width = height;
+       *ori_height = width;
+
+       return DCM_SUCCESS;
+}
+
 int dcm_decode_image(const char *file_path, const dcm_image_format_e format,
        const char* mimne_type, const int orientation, const bool resize,
        unsigned char **image_buffer, unsigned long long *size,
@@ -241,7 +290,12 @@ int dcm_decode_image(const char *file_path, const dcm_image_format_e format,
        if (orientation == 0) {
                *image_buffer = resize_buffer;
        } else {
-               ret = _dcm_rotate_image(resize_buffer, format, orientation, image_buffer, size, buff_width, buff_height);
+               if ((format == DCM_IMAGE_FORMAT_RGBA) || (format == DCM_IMAGE_FORMAT_RGB)) {
+                       ret = _dcm_rotate_rgb(resize_buffer, size, format, buff_width, buff_height);
+                       *image_buffer = resize_buffer;
+               } else {
+                       ret = _dcm_rotate_image(resize_buffer, format, orientation, image_buffer, size, buff_width, buff_height);
+               }
                if (ret != DCM_SUCCESS) {
                        dcm_error("Failed to rotate image buffer! err: %d", ret);
                        return DCM_ERROR_CODEC_DECODE_FAILED;