d8f7672dccdfd27de71951de9deec916d103c561
[platform/core/api/image-util.git] / include / image_util_private.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #ifndef __TIZEN_MULTIMEDIA_IMAGE_UTIL_PRIVATE_H__
18 #define __TIZEN_MULTIMEDIA_IMAGE_UTIL_PRIVATE_H__
19
20 #include <image_util_type.h>
21 #include <dlog.h>
22 #include <stdlib.h>
23 #include <glib.h>
24 #include <mm_util_imgp.h>
25
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34
35 #define LOG_TAG "CAPI_MEDIA_IMAGE_UTIL"
36
37 #define FONT_COLOR_RESET    "\033[0m"
38 #define FONT_COLOR_RED      "\033[31m"
39 #define FONT_COLOR_YELLOW   "\033[33m"
40
41 #define image_util_debug(fmt, arg...) do { \
42                 LOGD(FONT_COLOR_RESET""fmt""FONT_COLOR_RESET, ##arg);     \
43         } while (0)
44
45 #define image_util_error(fmt, arg...) do { \
46                 LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
47         } while (0)
48
49 #define image_util_warning(fmt, arg...) do { \
50                 LOGW(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
51         } while (0)
52
53 #define image_util_fenter() do { \
54                 LOGD(FONT_COLOR_YELLOW"<ENTER>"FONT_COLOR_RESET); \
55         } while (0)
56
57 #define image_util_fleave() do { \
58                 LOGD(FONT_COLOR_YELLOW"<LEAVE>"FONT_COLOR_RESET); \
59         } while (0)
60
61 #define image_util_retm_if(expr, fmt, arg...) do { \
62                 if (expr) { \
63                         LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
64                         return; \
65                 } \
66         } while (0)
67
68 #define image_util_retvm_if(expr, val, fmt, arg...) do { \
69                 if (expr) { \
70                         LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
71                         return (val); \
72                 } \
73         } while (0)
74
75
76 #define IMAGE_UTIL_STRING_VALID(str)    \
77         ((str != NULL && strlen(str) > 0) ? true : false)
78
79 #define IMAGE_UTIL_SAFE_FREE(src)       { if (src) {free(src); src = NULL; } }
80
81 #define _NOT_SUPPORTED_COLORSPACE       (-1)
82
83 #define MODE_DECODE             1
84 #define MODE_ENCODE             2
85
86 #define DECODE_ENCODE_CAST(obj) ((decode_encode_s *)(obj))
87 #define IS_DECODE_MODE(x)               (x == MODE_DECODE)
88 #define IS_ENCODE_MODE(x)               (x == MODE_ENCODE)
89
90 #define IMGCV_FUNC_NAME "mm_util_cv_extract_representative_color"
91 #define PATH_MMUTIL_IMGCV_LIB PATH_LIBDIR"/libmmutil_imgcv.so"
92
93 #define TYPECAST_COLOR(c)                       convert_type_of_colorspace(c)
94 #define TYPECAST_COLOR_BY_TYPE(c, t)    convert_type_of_colorspace_with_image_type(c, t)
95
96 #define NUM_OF_COLORSPACE       get_number_of_colorspace()
97
98 typedef gboolean(*ModuleFunc)(void *, int, int, unsigned char *, unsigned char *, unsigned char *);
99
100 typedef struct {
101         void *user_data;
102         image_util_transform_completed_cb completed_cb;
103 } image_util_cb_s;
104
105 typedef struct {
106         mm_image_info_s *src;
107         mm_image_info_s *dst;
108
109         /* for converting colorspace */
110         mm_util_color_format_e dst_format;
111         /* for image crop */
112         /* for resize */
113         unsigned int start_x;
114         unsigned int start_y;
115         unsigned int dst_width;
116         unsigned int dst_height;
117
118         /* for rotation */
119         mm_util_img_rotate_type rotation;
120
121         bool set_convert;
122         bool set_crop;
123         bool set_resize;
124         bool set_rotate;
125
126         /* for multi instance */
127         image_util_cb_s *_util_cb;
128         gboolean is_finish;
129         GThread* thread;
130         GAsyncQueue *queue;
131 } transformation_s;
132
133 typedef struct {
134         void *user_data;
135         image_util_decode_completed_cb image_decode_completed_cb;
136 } decode_cb_s;
137
138 typedef struct {
139         void *user_data;
140         image_util_encode_completed_cb image_encode_completed_cb;
141 } encode_cb_s;
142
143 typedef struct {
144         image_util_type_e image_type;
145         void **src_buffer;
146         size_t src_size;
147         void **dst_buffer;
148         size_t dst_size;
149         size_t gif_encode_size;
150         char *path;
151         void *image_h;
152         unsigned long width;
153         unsigned long height;
154         unsigned int mode;
155         int quality;
156         image_util_png_compression_e compression;
157         unsigned int current_buffer_count;
158         unsigned int current_resolution_count;
159         unsigned int current_delay_count;
160         image_util_colorspace_e colorspace;
161         image_util_scale_e down_scale;
162         decode_cb_s *_decode_cb;
163         encode_cb_s *_encode_cb;
164
165         /* for async */
166         GThread *thread;
167 } decode_encode_s;
168
169 typedef struct {
170         void *frame_h;
171 } frame_s;
172
173 typedef enum {
174         ERR_TYPE_COMMON,
175         ERR_TYPE_TRANSFORM,
176         ERR_TYPE_DECODE,
177         ERR_TYPE_ENCODE,
178 } image_util_error_type_e;
179
180 #define IMAGE_UTIL_TYPE_CHECK(type) \
181         image_util_retvm_if((type < IMAGE_UTIL_JPEG || type > IMAGE_UTIL_BMP), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter")
182
183 #define IMAGE_UTIL_SUPPORT_TYPE_CHECK(value, support) \
184         image_util_retvm_if((value != support), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "Not supported format")
185
186 #define IMAGE_UTIL_DECODE_HANDLE_CHECK(obj) do { \
187                 image_util_retvm_if(obj == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid decode handle"); \
188                 image_util_retvm_if(!IS_DECODE_MODE(DECODE_ENCODE_CAST(obj)->mode), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid decode handle"); \
189         } while(0)
190
191 #define IMAGE_UTIL_ENCODE_HANDLE_CHECK(obj) do { \
192                 image_util_retvm_if(obj == NULL, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid encode handle"); \
193                 image_util_retvm_if(!IS_ENCODE_MODE(DECODE_ENCODE_CAST(obj)->mode), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid encode handle"); \
194         } while(0)
195
196 gboolean is_valid_colorspace(image_util_colorspace_e colorspace);
197 gboolean is_supported_colorspace(image_util_colorspace_e colorspace, image_util_type_e type);
198
199 unsigned int get_number_of_colorspace(void);
200 int convert_type_of_colorspace(const image_util_colorspace_e colorspace);
201 int convert_type_of_colorspace_with_image_type(const image_util_colorspace_e colorspace, const image_util_type_e type);
202 int _image_error_capi(image_util_error_type_e error_type, int error_code);
203 bool _image_util_check_resolution(int width, int height);
204
205 /**
206 * @}
207 */
208
209 #ifdef __cplusplus
210 }
211 #endif
212
213 #endif /* __TIZEN_MULTIMEDIA_IMAGE_UTIL_PRIVATE_H__ */