2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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.
21 #include <image_util.h>
25 static image_util_encode_h encode_h = NULL;
26 static image_util_decode_h decode_h = NULL;
28 #define IMAGE_COLORSPACE IMAGE_UTIL_COLORSPACE_I420
30 void controller_image_initialize(void)
32 int error_code = image_util_encode_create(IMAGE_UTIL_JPEG, &encode_h);
33 if (error_code != IMAGE_UTIL_ERROR_NONE) {
34 _E("image_util_encode_create [%s]", get_error_message(error_code));
37 error_code = image_util_decode_create(&decode_h);
38 if (error_code != IMAGE_UTIL_ERROR_NONE) {
39 _E("image_util_decode_create [%s]", get_error_message(error_code));
43 void controller_image_finalize(void)
45 int error_code = image_util_encode_destroy(encode_h);
46 if (error_code != IMAGE_UTIL_ERROR_NONE) {
47 _E("image_util_encode_destroy [%s]", get_error_message(error_code));
50 error_code = image_util_decode_destroy(decode_h);
51 if (error_code != IMAGE_UTIL_ERROR_NONE) {
52 _E("image_util_decode_destroy [%s]", get_error_message(error_code));
56 int controller_image_save_image_file(const char *path,
57 unsigned int width, unsigned int height, const unsigned char *buffer,
58 const char *comment, unsigned int comment_len)
60 unsigned char *encoded = NULL;
61 unsigned long long size = 0;
63 int error_code = image_util_encode_set_resolution(encode_h, width, height);
64 if (error_code != IMAGE_UTIL_ERROR_NONE) {
65 _E("image_util_encode_set_resolution [%s]", get_error_message(error_code));
69 error_code = image_util_encode_set_colorspace(encode_h, IMAGE_COLORSPACE);
70 if (error_code != IMAGE_UTIL_ERROR_NONE) {
71 _E("image_util_encode_set_colorspace [%s]", get_error_message(error_code));
75 error_code = image_util_encode_set_quality(encode_h, 90);
76 if (error_code != IMAGE_UTIL_ERROR_NONE) {
77 _E("image_util_encode_set_quality [%s]", get_error_message(error_code));
81 error_code = image_util_encode_set_input_buffer(encode_h, buffer);
82 if (error_code != IMAGE_UTIL_ERROR_NONE) {
83 _E("image_util_encode_set_input_buffer [%s]", get_error_message(error_code));
87 error_code = image_util_encode_set_output_buffer(encode_h, &encoded);
88 if (error_code != IMAGE_UTIL_ERROR_NONE) {
89 _E("image_util_encode_set_output_buffer [%s]", get_error_message(error_code));
93 error_code = image_util_encode_run(encode_h, &size);
94 if (error_code != IMAGE_UTIL_ERROR_NONE) {
95 _E("image_util_encode_run [%s]", get_error_message(error_code));
99 error_code = exif_write_jpg_file_with_comment(path,
100 encoded, (unsigned int)size, width, height, comment, comment_len);
107 int controller_image_read_image_file(const char *path,
108 unsigned long *width, unsigned long *height, unsigned char *buffer, unsigned long long *size)
110 int error_code = image_util_decode_set_input_path(decode_h, path);
111 if (error_code != IMAGE_UTIL_ERROR_NONE) {
112 _E("image_util_decode_set_input_path [%s] [%s]", path, get_error_message(error_code));
116 error_code = image_util_decode_set_output_buffer(decode_h, &buffer);
117 if (error_code != IMAGE_UTIL_ERROR_NONE) {
118 _E("image_util_decode_set_output_buffer [%s]", get_error_message(error_code));
122 error_code = image_util_decode_set_colorspace(decode_h, IMAGE_UTIL_COLORSPACE_RGBA8888);
123 if (error_code != IMAGE_UTIL_ERROR_NONE) {
124 _E("image_util_decode_set_colorspace [%s]", get_error_message(error_code));
128 error_code = image_util_decode_set_jpeg_downscale(decode_h, IMAGE_UTIL_DOWNSCALE_1_1);
129 if (error_code != IMAGE_UTIL_ERROR_NONE) {
130 _E("image_util_decode_set_jpeg_downscale [%s]", get_error_message(error_code));
134 error_code = image_util_decode_run(decode_h, width, height, size);
135 if (error_code != IMAGE_UTIL_ERROR_NONE) {
136 _E("image_util_decode_run [%s]", get_error_message(error_code));