2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <image_util_private.h>
19 #include <mm_util_imgp.h>
20 #include <mm_util_jpeg.h>
21 #include <mm_util_png.h>
22 #include <mm_util_gif.h>
23 #include <mm_util_bmp.h>
25 static int _convert_colorspace_tbl[] = {
26 MM_UTIL_IMG_FMT_YUV420, /* IMAGE_UTIL_COLORSPACE_YUV420 */
27 MM_UTIL_IMG_FMT_YUV422, /* IMAGE_UTIL_COLORSPACE_YUV422 */
28 MM_UTIL_IMG_FMT_I420, /* IMAGE_UTIL_COLORSPACE_I420 */
29 MM_UTIL_IMG_FMT_NV12, /* IMAGE_UTIL_COLORSPACE_NV12 */
30 MM_UTIL_IMG_FMT_UYVY, /* IMAGE_UTIL_COLORSPACE_UYVY */
31 MM_UTIL_IMG_FMT_YUYV, /* IMAGE_UTIL_COLORSPACE_YUYV */
32 MM_UTIL_IMG_FMT_RGB565, /* IMAGE_UTIL_COLORSPACE_RGB565 */
33 MM_UTIL_IMG_FMT_RGB888, /* IMAGE_UTIL_COLORSPACE_RGB888 */
34 MM_UTIL_IMG_FMT_ARGB8888, /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
35 MM_UTIL_IMG_FMT_BGRA8888, /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
36 MM_UTIL_IMG_FMT_RGBA8888, /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
37 MM_UTIL_IMG_FMT_BGRX8888, /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
38 MM_UTIL_JPEG_FMT_NV21, /* IMAGE_UTIL_COLORSPACE_NV12 */
39 MM_UTIL_JPEG_FMT_NV16, /* IMAGE_UTIL_COLORSPACE_NV16 */
40 MM_UTIL_JPEG_FMT_NV61, /* IMAGE_UTIL_COLORSPACE_NV61 */
43 static int _convert_jpeg_colorspace_tbl[] = {
44 MM_UTIL_JPEG_FMT_YUV420, /* IMAGE_UTIL_COLORSPACE_YUV420 */
45 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUV422 */
46 MM_UTIL_JPEG_FMT_YUV420, /* IMAGE_UTIL_COLORSPACE_I420 */
47 MM_UTIL_JPEG_FMT_NV12, /* IMAGE_UTIL_COLORSPACE_NV12 */
48 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_UYVY */
49 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUYV */
50 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_RGB565 */
51 MM_UTIL_JPEG_FMT_RGB888, /* IMAGE_UTIL_COLORSPACE_RGB888 */
52 MM_UTIL_JPEG_FMT_ARGB8888, /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
53 MM_UTIL_JPEG_FMT_BGRA8888, /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
54 MM_UTIL_JPEG_FMT_RGBA8888, /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
55 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
56 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV21 */
57 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV16 */
58 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV61 */
61 static int _convert_png_colorspace_tbl[] = {
62 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUV420 */
63 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUV422 */
64 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_I420 */
65 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV12 */
66 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_UYVY */
67 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUYV */
68 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_RGB565 */
69 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_RGB888 */
70 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
71 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
72 MM_UTIL_PNG_COLOR_TYPE_RGB_ALPHA, /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
73 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
74 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV21 */
75 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV16 */
76 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV61 */
79 static int _convert_gif_colorspace_tbl[] = {
80 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUV420 */
81 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUV422 */
82 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_I420 */
83 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV12 */
84 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_UYVY */
85 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUYV */
86 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_RGB565 */
87 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_RGB888 */
88 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
89 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
90 MM_UTIL_GIF_FMT_RGBA8888, /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
91 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
92 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV21 */
93 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV16 */
94 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV61 */
97 static int _convert_bmp_colorspace_tbl[] = {
98 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUV420 */
99 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUV422 */
100 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_I420 */
101 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV12 */
102 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_UYVY */
103 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_YUYV */
104 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_RGB565 */
105 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_RGB888 */
106 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
107 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
108 MM_UTIL_BMP_FMT_RGBA8888, /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
109 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
110 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV21 */
111 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV16 */
112 _NOT_SUPPORTED_COLORSPACE, /* IMAGE_UTIL_COLORSPACE_NV61 */
115 unsigned int get_number_of_colorspace(void)
117 return (unsigned int)(sizeof(_convert_colorspace_tbl)/sizeof(int));
120 gboolean is_valid_colorspace(image_util_colorspace_e colorspace)
122 if ((colorspace < IMAGE_UTIL_COLORSPACE_YV12) || (colorspace >= NUM_OF_COLORSPACE))
128 gboolean is_supported_colorspace(image_util_colorspace_e colorspace, image_util_type_e type)
131 case IMAGE_UTIL_JPEG:
132 image_util_retvm_if((_convert_jpeg_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[jpeg] %d not supported format", colorspace);
135 image_util_retvm_if((_convert_png_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[png] %d not supported format", colorspace);
138 image_util_retvm_if((_convert_gif_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[gif] %d not supported format", colorspace);
141 image_util_retvm_if((_convert_bmp_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[bmp] %d not supported format", colorspace);
144 image_util_retvm_if(TRUE, FALSE, "Invalid image type");
149 int convert_type_of_colorspace(const image_util_colorspace_e colorspace)
151 if (is_valid_colorspace(colorspace) == FALSE) {
152 return _NOT_SUPPORTED_COLORSPACE;
155 return _convert_colorspace_tbl[colorspace];
158 int convert_type_of_colorspace_with_image_type(const image_util_colorspace_e colorspace, const image_util_type_e type)
160 int new_colorspace = _NOT_SUPPORTED_COLORSPACE;
162 if (is_valid_colorspace(colorspace) == FALSE) {
163 return _NOT_SUPPORTED_COLORSPACE;
166 if (is_supported_colorspace(colorspace, type) == FALSE) {
167 return _NOT_SUPPORTED_COLORSPACE;
171 case IMAGE_UTIL_JPEG:
172 new_colorspace = _convert_jpeg_colorspace_tbl[colorspace];
175 new_colorspace = _convert_png_colorspace_tbl[colorspace];
178 new_colorspace = _convert_gif_colorspace_tbl[colorspace];
181 new_colorspace = _convert_bmp_colorspace_tbl[colorspace];
184 image_util_error("Invalid image type");
187 return new_colorspace;
190 int _image_error_capi(image_util_error_type_e error_type, int error_code)
192 if (error_code != MM_UTIL_ERROR_NONE)
193 image_util_error("[type : %d] error : %d ", error_type, error_code);
196 if (error_code == MM_UTIL_ERROR_NONE)
197 return IMAGE_UTIL_ERROR_NONE;
199 /* Invalid parameter error*/
200 else if (error_code == MM_UTIL_ERROR_INVALID_PARAMETER)
201 return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
203 else if (error_code == MM_UTIL_ERROR_OUT_OF_MEMORY)
204 return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
206 /* No such file error*/
207 else if (error_code == MM_UTIL_ERROR_NO_SUCH_FILE)
208 return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
210 /* Internal operation error*/
211 else if (error_code == MM_UTIL_ERROR_INVALID_OPERATION)
212 return IMAGE_UTIL_ERROR_INVALID_OPERATION;
214 /* Not supported format error*/
215 else if (error_code == MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
216 return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
219 return IMAGE_UTIL_ERROR_INVALID_OPERATION;
223 bool _image_util_check_resolution(int width, int height)
226 image_util_error("invalid width [%d]", width);
231 image_util_error("invalid height [%d]", height);