From c8f399def486df16353768b8dacb89775c8803c6 Mon Sep 17 00:00:00 2001 From: Jiyong Min Date: Wed, 7 Sep 2016 19:33:00 +0900 Subject: [PATCH] Add new header for image-utility internal API Change-Id: I515978613c6715910756558820f84946a214970b Signed-off-by: Jiyong Min --- libdcm-util/dcm_image_codec.cpp | 56 ++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/libdcm-util/dcm_image_codec.cpp b/libdcm-util/dcm_image_codec.cpp index 01ffc39..54c553d 100755 --- a/libdcm-util/dcm_image_codec.cpp +++ b/libdcm-util/dcm_image_codec.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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; -- 2.34.1