Modify converting to capi error and simplify error type use
[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_MEDIA_IMAGE_UTIL_PRIVATE_H__
18 #define __TIZEN_MEDIA_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 <gmodule.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
40 #define image_util_debug(fmt, arg...) do { \
41                 LOGD(FONT_COLOR_RESET""fmt""FONT_COLOR_RESET, ##arg);     \
42         } while (0)
43
44 #define image_util_error(fmt, arg...) do { \
45                 LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
46         } while (0)
47
48 #define image_util_warning(fmt, arg...) do { \
49                 LOGW(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
50         } while (0)
51
52 #define image_util_retm_if(expr, fmt, arg...) do { \
53                 if (expr) { \
54                         LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
55                         return; \
56                 } \
57         } while (0)
58
59 #define image_util_retvm_if(expr, val, fmt, arg...) do { \
60                 if (expr) { \
61                         LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
62                         return (val); \
63                 } \
64         } while (0)
65
66 #define DEPRECATION_LOGW(deprecated, instead) do { \
67                 image_util_warning("DEPRECATION WARNING: %s is deprecated and will be removed from next release. Use %s instead.", deprecated, instead);     \
68         } while (0)
69
70 #define IMAGE_UTIL_STRING_VALID(str)    \
71         ((str != NULL && strlen(str) > 0) ? true : false)
72
73 #define IMAGE_UTIL_SAFE_FREE(src)       { if (src) {free(src); src = NULL; } }
74
75 #define IMGCV_FUNC_NAME "mm_util_cv_extract_representative_color"
76 #define PATH_MMUTIL_IMGCV_LIB PATH_LIBDIR"/libmmutil_imgcv.so"
77
78 #define _NOT_SUPPORTED_COLORSPACE       (-1)
79
80 #define TYPECAST_COLOR(c)                       convert_type_of_colorspace(c)
81 #define TYPECAST_COLOR_BY_TYPE(c, t)    convert_type_of_colorspace_with_image_type(c, t)
82
83 #define NUM_OF_COLORSPACE       get_number_of_colorspace()
84
85 typedef gboolean(*ModuleFunc)(void *, int, int, unsigned char *, unsigned char *, unsigned char *);
86
87 typedef struct {
88         void *user_data;
89         media_packet_h dst;
90         image_util_transform_completed_cb image_processing_completed_cb;
91 } image_util_cb_s;
92
93 typedef struct {
94         media_packet_h src;
95         media_packet_h dst;
96         image_util_colorspace_e colorspace;
97         image_util_rotation_e dest_rotation;
98         bool hardware_acceleration;
99         void *image_h;
100         image_util_cb_s *_util_cb;
101         unsigned int width;
102         unsigned int height;
103         image_util_rotation_e rotation;
104         unsigned int start_x;
105         unsigned int start_y;
106         unsigned int end_x;
107         unsigned int end_y;
108         bool set_convert;
109         bool set_resize;
110         bool set_rotate;
111         bool set_crop;
112 } transformation_s;
113
114 typedef struct {
115         void *user_data;
116         image_util_decode_completed_cb image_decode_completed_cb;
117 } decode_cb_s;
118
119 typedef struct {
120         void *user_data;
121         image_util_encode_completed_cb image_encode_completed_cb;
122 } encode_cb_s;
123
124 typedef struct {
125         image_util_type_e image_type;
126         void **src_buffer;
127         unsigned long long src_size;
128         void **dst_buffer;
129         unsigned long long dst_size;
130         unsigned long gif_encode_size;
131         char *path;
132         void *image_h;
133         unsigned long width;
134         unsigned long height;
135         bool is_decode;
136         bool is_encoded;
137         int quality;
138         unsigned int current_buffer_count;
139         unsigned int current_resolution_count;
140         unsigned int current_delay_count;
141         image_util_colorspace_e colorspace;
142         image_util_scale_e down_scale;
143         decode_cb_s *_decode_cb;
144         encode_cb_s *_encode_cb;
145
146         /* for async */
147         GThread *thread;
148 } decode_encode_s;
149
150 typedef struct {
151         void *frame_h;
152 } frame_s;
153
154 typedef enum {
155         ERR_TYPE_COMMON,
156         ERR_TYPE_TRANSFORM,
157         ERR_TYPE_DECODE,
158         ERR_TYPE_ENCODE,
159 } image_util_error_type_e;
160
161 gboolean is_valid_colorspace(image_util_colorspace_e colorspace);
162 gboolean is_supported_colorspace(image_util_colorspace_e colorspace, image_util_type_e type);
163
164 unsigned int get_number_of_colorspace(void);
165 int convert_type_of_colorspace(const image_util_colorspace_e colorspace);
166 int convert_type_of_colorspace_with_image_type(const image_util_colorspace_e colorspace, const image_util_type_e type);
167 int _image_error_capi(image_util_error_type_e error_type, int error_code);
168 bool _image_util_check_resolution(int width, int height);
169
170 /**
171 * @}
172 */
173
174 #ifdef __cplusplus
175 }
176 #endif
177
178 #endif /* __TIZEN_MEDIA_IMAGE_UTIL_PRIVATE_H__ */