merge commits of 2.2.1 to public
[platform/framework/native/image.git] / src / FMedia_ImageUtilImpl.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_ImageUtilImpl.cpp
20  * @brief  This file contains the implementation of _ImageUtilImpl class.
21  */
22
23 #include <stdlib.h>
24 #include <FGrpDimension.h>
25 #include <FGrpBitmapCommon.h>
26 #include <FMediaTypes.h>
27 #include <FMediaImageTypes.h>
28 #include <FBaseSysLog.h>
29 #include "FMedia_MediaUtil.h"
30 #include "FMedia_ImageUtil.h"
31 #include "FMedia_ImageUtilImpl.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Io;
36
37 namespace Tizen { namespace Media
38 {
39
40 result
41 _ImageUtilImpl::ConvertPixelFormat(const ByteBuffer& srcBuf, ByteBuffer& dstBuf,
42                                                                    MediaPixelFormat srcFormat, MediaPixelFormat dstFormat,
43                                                                    const Dimension& dim)
44 {
45         return _ImageUtil::ConvertPixelFormat(srcBuf, srcFormat, dim.width, dim.height,
46                                                                                   dstBuf, dstFormat);
47 }
48
49
50 result
51 _ImageUtilImpl::Resize(const ByteBuffer& srcBuf, ByteBuffer& dstBuf,
52                                            const Dimension& srcDim, const Dimension& dstDim,
53                                            MediaPixelFormat pixelFormat)
54 {
55         return _ImageUtil::Resize(srcBuf, pixelFormat, srcDim.width, srcDim.height,
56                                                           dstBuf, dstDim.width, dstDim.height);
57 }
58
59
60 result
61 _ImageUtilImpl::Rotate(const ByteBuffer& srcBuf, ByteBuffer& dstBuf,
62                                            const Dimension& dim, ImageRotationType rotate,
63                                            MediaPixelFormat pixelFormat)
64 {
65         return _ImageUtil::Rotate(srcBuf, pixelFormat, dim.width, dim.height,
66                                                           dstBuf, rotate);
67 }
68
69
70 result
71 _ImageUtilImpl::Flip(const ByteBuffer& srcBuf, ByteBuffer& dstBuf, const Dimension& dim,
72                                          ImageFlipType flip, MediaPixelFormat pixelFormat)
73 {
74         return _ImageUtil::Flip(srcBuf, pixelFormat, dim.width, dim.height,
75                                                         dstBuf, flip);
76 }
77
78 Tizen::Media::ImageFormat
79 _ImageUtilImpl::GetImageFormat(const Tizen::Base::String& srcImageFile)
80 {
81         return _ImageUtil::GetImageFormat(srcImageFile);
82 }
83
84
85 bool
86 _ImageUtilImpl::HasAlphaChannel(const Tizen::Base::String& srcImageFile)
87 {
88         return _ImageUtil::HasAlphaChannel(srcImageFile);
89 }
90
91 int
92 _ImageUtilImpl::MinImageFormatLength(void)
93 {
94         return _ImageUtil::MinImageFormatLength();
95 }
96
97 ImageFormat
98 _ImageUtilImpl::GetImageFormat(const Tizen::Base::ByteBuffer& srcBuf)
99 {
100         return _ImageUtil::GetImageFormat(srcBuf);
101 }
102
103 bool
104 _ImageUtilImpl::HasAlphaChannel(const Tizen::Base::ByteBuffer& srcBuf)
105 {
106         return _ImageUtil::HasAlphaChannel(srcBuf);
107 }
108
109 Tizen::Base::ByteBuffer*
110 _ImageUtilImpl::ResizeN(const Tizen::Base::ByteBuffer &srcBuf,
111                                                 const Tizen::Graphics::Dimension& srcDim,
112                                                 MediaPixelFormat pixelFormat,
113                                                 const Tizen::Graphics::Dimension& dstDim)
114 {
115         return _ImageUtil::ResizeN(srcBuf, pixelFormat, srcDim.height, srcDim.width, dstDim.height, dstDim.width);
116 }
117
118
119 MediaPixelFormat
120 _ImageUtilImpl::ToMediaPixelFormat(BitmapPixelFormat bitmapFormat)
121 {
122         static struct
123         {
124                 BitmapPixelFormat key;
125                 MediaPixelFormat value;
126         } map[] = {
127         { BITMAP_PIXEL_FORMAT_RGB565, MEDIA_PIXEL_FORMAT_RGB565LE },
128         { BITMAP_PIXEL_FORMAT_ARGB8888, MEDIA_PIXEL_FORMAT_BGRA8888 },
129         { BITMAP_PIXEL_FORMAT_R8G8B8A8, MEDIA_PIXEL_FORMAT_RGBA8888 },
130         };
131         MediaPixelFormat ret = MEDIA_PIXEL_FORMAT_NONE;
132
133         for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++)
134         {
135                 if (map[i].key == bitmapFormat)
136                 {
137                         return map[i].value;
138                 }
139         }
140
141         return ret;
142 }
143
144 int
145 _ImageUtilImpl::GetBufferSize(const Tizen::Graphics::Dimension& dim, MediaPixelFormat pixelFormat)
146 {
147         return _ImageUtil::GetBufferSize(pixelFormat, dim.width, dim.height);
148 }
149
150 bool
151 _ImageUtilImpl::IsValidDimension(MediaPixelFormat pixelFormat, const Tizen::Graphics::Dimension& dim)
152 {
153         return _ImageUtil::IsValidDimension(pixelFormat, dim.width, dim.height);
154 }
155
156 Tizen::Base::String
157 _ImageUtilImpl::ToString(ImageFormat imgFormat)
158 {
159         static struct
160         {
161                 ImageFormat key;
162                 const wchar_t* value;
163         } map[] = {
164                 { IMG_FORMAT_NONE, L"None"},
165                 { IMG_FORMAT_JPG, L"JPG"},
166                 { IMG_FORMAT_PNG, L"PNG"},
167                 { IMG_FORMAT_GIF, L"GIF"},
168                 { IMG_FORMAT_TIFF, L"TIFF"},
169                 { IMG_FORMAT_BMP, L"BMP"},
170                 { IMG_FORMAT_WBMP, L"WBMP"},
171         };
172         const wchar_t* pStr = L"None";
173
174         for (unsigned int i = 0; i < sizeof(map)/sizeof(map[0]); i++)
175         {
176                 if (map[i].key == imgFormat)
177                 {
178                         pStr = map[i].value;
179                         break;
180                 }
181         }
182
183         return String(pStr);
184 }
185
186 }} // Tizen::Media