#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>
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,
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;