Added transparency support in RGB565 bitmap outputs, for gif decoder.
[framework/osp/image-core.git] / src / FMedia_SlpUtil.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file   FMedia_SlpUtil.cpp
20  * @brief  This file contains the implementation of _SlpUtil class.
21  */
22
23 #include <stdlib.h>
24 #include <image_util.h>
25 #include <mmf/mm_util_imgp.h>
26 #include <FBaseSysLog.h>
27 #include <FMediaImageTypes.h>
28 #include "FMedia_MediaUtil.h"
29 #include "FMedia_SlpUtil.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Io;
33
34 namespace Tizen { namespace Media
35 {
36 //
37 //image_util_colorspace_e
38 //_SlpUtil::ToColorspace(Tizen::Graphics::BitmapPixelFormat pixelFormat)
39 //{
40 //      static struct {
41 //              BitmapPixelFormat key;
42 //              image_util_colorspace_e value;
43 //      } map[] = {
44 //      { BITMAP_PIXEL_FORMAT_RGB565, IMAGE_UTIL_COLORSPACE_RGB565 },
45 //      { BITMAP_PIXEL_FORMAT_ARGB8888, IMAGE_UTIL_COLORSPACE_BGRA8888 },
46 //      { BITMAP_PIXEL_FORMAT_R8G8B8A8, IMAGE_UTIL_COLORSPACE_RGBA8888 },
47 //      };
48 //      image_util_colorspace_e ret = (image_util_colorspace_e)0xff;
49 //
50 //      SAFE_FIND_KEY(ret, map, pixelFormat);
51 //
52 //      return ret;
53 //}
54 //
55
56 image_util_colorspace_e
57 _SlpUtil::ToColorspace(MediaPixelFormat pixelFormat)
58 {
59         static struct
60         {
61                 MediaPixelFormat key;
62                 image_util_colorspace_e value;
63         } map[] = {
64         { MEDIA_PIXEL_FORMAT_RGB565LE, IMAGE_UTIL_COLORSPACE_RGB565 },
65         { MEDIA_PIXEL_FORMAT_BGRA8888, IMAGE_UTIL_COLORSPACE_BGRA8888 },
66         { MEDIA_PIXEL_FORMAT_RGBA8888, IMAGE_UTIL_COLORSPACE_RGBA8888 },
67         { MEDIA_PIXEL_FORMAT_RGB565BE, IMAGE_UTIL_COLORSPACE_RGB565 }, // slp does not support
68         { MEDIA_PIXEL_FORMAT_RGB888, IMAGE_UTIL_COLORSPACE_RGB888 },
69         { MEDIA_PIXEL_FORMAT_BGR888, IMAGE_UTIL_COLORSPACE_RGB888 }, // slp does not support
70         { MEDIA_PIXEL_FORMAT_YUV420P, IMAGE_UTIL_COLORSPACE_YV12 },
71         { MEDIA_PIXEL_FORMAT_YUYV422, IMAGE_UTIL_COLORSPACE_YUYV },
72         { MEDIA_PIXEL_FORMAT_NV12, IMAGE_UTIL_COLORSPACE_NV12 },
73         };
74         image_util_colorspace_e ret = (image_util_colorspace_e)0xff;
75
76         for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++)
77         {
78                 if (map[i].key == pixelFormat)
79                 {
80                         return map[i].value;
81                 }
82         }
83
84         return ret;
85 }
86
87 image_util_rotation_e
88 _SlpUtil::ToRotation(ImageRotationType type)
89 {
90         static struct
91         {
92         ImageRotationType key;
93         image_util_rotation_e value;
94         } map[] = {
95         { IMAGE_ROTATION_90, IMAGE_UTIL_ROTATION_90 },
96         { IMAGE_ROTATION_180, IMAGE_UTIL_ROTATION_180 },
97         { IMAGE_ROTATION_270, IMAGE_UTIL_ROTATION_270 },
98         { IMAGE_ROTATION_0, IMAGE_UTIL_ROTATION_FLIP_HORZ },
99         };
100         image_util_rotation_e ret = (image_util_rotation_e)0xff;
101
102         for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++)
103         {
104                 if (map[i].key == type)
105                 {
106                         return map[i].value;
107                 }
108         }
109         return ret;
110 }
111
112 image_util_rotation_e
113 _SlpUtil::ToRotation(ImageFlipType type)
114 {
115         static struct
116         {
117         ImageFlipType key;
118         image_util_rotation_e value;
119         } map[] = {
120         {IMAGE_FLIP_HORIZONTAL, IMAGE_UTIL_ROTATION_FLIP_HORZ },
121         {IMAGE_FLIP_VERTICAL, IMAGE_UTIL_ROTATION_FLIP_VERT }
122         };
123         image_util_rotation_e ret = (image_util_rotation_e)0xff;
124
125         for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++)
126         {
127                 if (map[i].key == type)
128                 {
129                         return map[i].value;
130                 }
131         }
132         return ret;
133 }
134
135 mm_util_img_format
136 _SlpUtil::ToMmUtilImgFormat(Tizen::Media::MediaPixelFormat pixelFormat)
137 {
138         static struct
139         {
140                 MediaPixelFormat key;
141                 mm_util_img_format value;
142         } map[] = {
143         { MEDIA_PIXEL_FORMAT_RGB565LE, MM_UTIL_IMG_FMT_RGB565 },
144         { MEDIA_PIXEL_FORMAT_BGRA8888, MM_UTIL_IMG_FMT_BGRA8888 },
145         { MEDIA_PIXEL_FORMAT_RGBA8888, MM_UTIL_IMG_FMT_ARGB8888 },
146         { MEDIA_PIXEL_FORMAT_RGB565BE, MM_UTIL_IMG_FMT_RGB565 }, // slp does not support
147         { MEDIA_PIXEL_FORMAT_RGB888,   MM_UTIL_IMG_FMT_RGB888 },
148         { MEDIA_PIXEL_FORMAT_BGR888,   MM_UTIL_IMG_FMT_RGB888 }, // slp does not support
149         { MEDIA_PIXEL_FORMAT_YUV420P,  MM_UTIL_IMG_FMT_YUV420 },
150         { MEDIA_PIXEL_FORMAT_YUYV422,  MM_UTIL_IMG_FMT_YUYV },
151         { MEDIA_PIXEL_FORMAT_NV12,       MM_UTIL_IMG_FMT_NV12 },
152         };
153         mm_util_img_format ret = MM_UTIL_IMG_FMT_RGB565;
154
155         for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++)
156         {
157                 if (map[i].key == pixelFormat)
158                 {
159                         return map[i].value;
160                 }
161         }
162         return ret;
163 }
164
165 mm_util_img_rotate_type
166 _SlpUtil::ToMmUtilRotateType(ImageFlipType type)
167 {
168         static struct
169         {
170         ImageFlipType key;
171         mm_util_img_rotate_type value;
172         } map[] = {
173         {IMAGE_FLIP_HORIZONTAL, MM_UTIL_ROTATE_FLIP_HORZ},
174         {IMAGE_FLIP_VERTICAL, MM_UTIL_ROTATE_FLIP_VERT}
175         };
176         mm_util_img_rotate_type ret = (mm_util_img_rotate_type)0xff;
177
178         for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++)
179         {
180                 if (map[i].key == type)
181                 {
182                         return map[i].value;
183                 }
184         }
185         return ret;
186 }
187
188 mm_util_img_rotate_type
189 _SlpUtil::ToMmUtilRotateType(ImageRotationType type)
190 {
191         static struct
192         {
193         ImageRotationType key;
194         mm_util_img_rotate_type value;
195         } map[] = {
196         { IMAGE_ROTATION_90, MM_UTIL_ROTATE_90},
197         { IMAGE_ROTATION_180, MM_UTIL_ROTATE_180 },
198         { IMAGE_ROTATION_270, MM_UTIL_ROTATE_270 },
199         { IMAGE_ROTATION_0, MM_UTIL_ROTATE_0},
200         };
201         mm_util_img_rotate_type ret = (mm_util_img_rotate_type)0xff;
202
203         for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++)
204         {
205                 if (map[i].key == type)
206                 {
207                         return map[i].value;
208                 }
209         }
210         return ret;
211 }
212
213 }} // Tizen::Media