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.h>
18 #include <image_util_internal.h>
19 #include <image_util_private.h>
21 int image_util_frame_create(void *decode_encode_h, image_util_frame_h *frame_h)
23 int ret = IMAGE_UTIL_ERROR_NONE;
25 image_util_retvm_if((decode_encode_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
26 image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
28 decode_encode_s *image = (decode_encode_s *)decode_encode_h;
29 image_util_retvm_if((image->image_h == NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong");
30 image_util_retvm_if((image->width == 0) || (image->height == 0), MM_UTIL_ERROR_INVALID_OPERATION, "The resolution is wrong");
32 frame_s *frame = calloc(1, sizeof(frame_s));
34 image_util_error("Memory allocation is failed.");
35 return MM_UTIL_ERROR_OUT_OF_MEMORY;
38 if (image->image_type == IMAGE_UTIL_GIF) {
39 mm_gif_file_h gif_data = (mm_gif_file_h)image->image_h;
40 mm_gif_image_h gif_frame = NULL;
42 ret = mm_util_gif_image_create(gif_data, &gif_frame);
43 if (ret != IMAGE_UTIL_ERROR_NONE) {
44 image_util_error("mm_util_gif_image_create is failed(%d).", ret);
45 IMAGE_UTIL_SAFE_FREE(frame);
46 return MM_UTIL_ERROR_INVALID_OPERATION;
48 frame->frame_h = gif_frame;
50 image_util_error("The image type(%d) is not supported.", image->image_type);
51 IMAGE_UTIL_SAFE_FREE(frame);
52 return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
57 return IMAGE_UTIL_ERROR_NONE;
60 int image_util_frame_set_resolution(image_util_frame_h frame_h, const int width, const int height)
62 int ret = IMAGE_UTIL_ERROR_NONE;
64 image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
65 image_util_retvm_if((width <= 0) || (height <= 0), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Width or Height");
67 frame_s *frame = (frame_s *)frame_h;
69 ret = mm_util_gif_image_set_position(frame->frame_h, 0, 0, width, height);
70 if (ret != IMAGE_UTIL_ERROR_NONE) {
71 image_util_error("mm_util_gif_image_set_position is failed(%d).", ret);
72 return MM_UTIL_ERROR_INVALID_OPERATION;
75 return IMAGE_UTIL_ERROR_NONE;
78 int image_util_frame_set_gif_delay(image_util_frame_h frame_h, const int delay_time)
80 int ret = IMAGE_UTIL_ERROR_NONE;
82 image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
83 image_util_retvm_if((delay_time <= 0), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Delay Time");
85 frame_s *frame = (frame_s *)frame_h;
87 ret = mm_util_gif_image_set_delay_time(frame->frame_h, delay_time);
88 if (ret != IMAGE_UTIL_ERROR_NONE) {
89 image_util_error("mm_util_gif_image_set_delay_time is failed(%d).", ret);
90 return MM_UTIL_ERROR_INVALID_OPERATION;
93 return IMAGE_UTIL_ERROR_NONE;
96 int image_util_frame_set_frame(image_util_frame_h frame_h, unsigned char *buffer, const unsigned long size)
98 int ret = IMAGE_UTIL_ERROR_NONE;
100 image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
101 image_util_retvm_if((buffer == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Buffer");
102 image_util_retvm_if((size == 0), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Buffer Size");
104 frame_s *frame = (frame_s *)frame_h;
106 ret = mm_util_gif_image_set_image(frame->frame_h, buffer, size);
107 if (ret != IMAGE_UTIL_ERROR_NONE) {
108 image_util_error("mm_util_gif_image_set_image is failed(%d).", ret);
109 return MM_UTIL_ERROR_INVALID_OPERATION;
112 return IMAGE_UTIL_ERROR_NONE;
115 void image_util_frame_destroy(image_util_frame_h frame_h)
117 image_util_retm_if((frame_h == NULL), "Invalid Handle");
119 frame_s *frame = (frame_s *)frame_h;
120 mm_util_gif_image_destory(frame->frame_h);
123 int image_util_encode_add_frame(image_util_encode_h encode_h, image_util_frame_h frame_h)
125 int ret = IMAGE_UTIL_ERROR_NONE;
127 image_util_retvm_if((encode_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
128 image_util_retvm_if((frame_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
130 decode_encode_s *encode = (decode_encode_s *)encode_h;
131 frame_s *frame = (frame_s *)frame_h;
132 image_util_retvm_if((encode->image_h == NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong");
133 image_util_retvm_if((frame->frame_h == NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The frame handle is wrong");
135 if (encode->image_type == IMAGE_UTIL_GIF) {
136 mm_gif_file_h gif_data = (mm_gif_file_h)encode->image_h;
138 ret = mm_util_gif_encode_add_image(gif_data, (mm_gif_image_h)frame->frame_h);
139 if (ret != IMAGE_UTIL_ERROR_NONE) {
140 image_util_error("mm_util_gif_encode_add_image is failed(%d).", ret);
141 mm_util_gif_encode_destroy(gif_data);
142 return MM_UTIL_ERROR_INVALID_OPERATION;
145 image_util_error("The image type(%d) is not supported.", encode->image_type);
146 return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
149 return IMAGE_UTIL_ERROR_NONE;
152 int image_util_encode_save(image_util_encode_h encode_h)
154 int ret = IMAGE_UTIL_ERROR_NONE;
156 image_util_retvm_if((encode_h == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
158 decode_encode_s *encode = (decode_encode_s *)encode_h;
159 image_util_retvm_if((encode->image_h == NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The image handle is wrong");
161 if (encode->image_type == IMAGE_UTIL_GIF) {
162 mm_gif_file_h gif_data = (mm_gif_file_h)encode->image_h;
164 ret = mm_util_gif_encode_save(gif_data);
165 if (ret != IMAGE_UTIL_ERROR_NONE) {
166 image_util_error("mm_util_gif_encode_save is failed(%d).", ret);
167 mm_util_gif_encode_destroy(gif_data);
168 return MM_UTIL_ERROR_INVALID_OPERATION;
171 image_util_error("The image type(%d) is not supported.", encode->image_type);
172 return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
175 return IMAGE_UTIL_ERROR_NONE;