merge with master
[framework/osp/image-core.git] / src / inc / FMedia_ImageUtil.h
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_ImageUtil.h
20  * @brief  This is the header file for the _ImageUtil.
21  */
22
23 #ifndef _FMEDIA_INTERNAL_IMAGE_UTIL_H_
24 #define _FMEDIA_INTERNAL_IMAGE_UTIL_H_
25
26
27 #include <FBaseTypes.h>
28 #include <FMediaImageTypes.h>
29 namespace Tizen { namespace Base {
30 class ByteBuffer;
31 class String;
32 } }
33
34
35 namespace Tizen { namespace Media
36 {
37
38 /**
39  * @class  _ImageUtil
40  * @brief  This class provides internal APIs for image files, such as alpha channel check.
41  *
42  * This class provides internal methods for image files. @n@n
43  */
44 class _OSP_EXPORT_ _ImageUtil
45 {
46 public:
47         /**
48          * Checks whether the specified image file has alpha channel. @n
49          * Currently, only 32-bit PNG images are supported.
50          *
51          * @return      @c true if the image has alpha channel, @n
52          *              else @c false
53          * @param[in]   srcImagePath          The local file path of the image file
54          * @exception   E_SUCCESS             The method is successful.
55          * @exception   E_UNSUPPORTED_FORMAT  The image format is not supported.
56          * @exception   E_FILE_NOT_FOUND      The specified image file cannot be found.
57          * @exception   E_OUT_OF_MEMORY       The memory is insufficient.
58          * @exception   E_SYSTEM              A system error has occurred.
59          * @remarks     The specific error code can be accessed using the GetLastResult() method.
60          */
61         static bool HasAlphaChannel(const Tizen::Base::String& srcImagePath);
62
63 // DO NOT USE these APIs outside of Tizen::Media
64         static result ConvertPixelFormat(const Tizen::Base::ByteBuffer& srcBuf,
65                                                                          MediaPixelFormat srcPixelFormat,
66                                                                          int width, int height,
67                                                                          Tizen::Base::ByteBuffer& destBuf,
68                                                                          MediaPixelFormat destPixelFormat);
69
70         static result Resize(const Tizen::Base::ByteBuffer& srcBuf,  MediaPixelFormat srcPixelFormat,
71                                                  int srcWidth, int srcHeight,
72                                                  Tizen::Base::ByteBuffer& destBuf,
73                                                  int destWidth, int destHeight);
74
75         static result ResizeBuffer(const byte* pInBuf, MediaPixelFormat pixelFormat,
76                                                 int srcWidth, int srcHeight,
77                                                 byte* pOutBuf, int dstWidth, int dstHeight);
78
79         static result Rotate(const Tizen::Base::ByteBuffer& srcBuf,
80                                                  MediaPixelFormat pixelFormat,
81                                                  int width, int height,
82                                                  Tizen::Base::ByteBuffer& destBuf,
83                                                  ImageRotationType rotate);
84
85         static result RotateBuffer(const byte* srcBuf,
86                                                  MediaPixelFormat pixelFormat,
87                                                  int width, int height,
88                                                  byte* destBuf, int& outWidth, int& outHeight,
89                                                  ImageRotationType rotate);
90
91         static result Flip(const Tizen::Base::ByteBuffer& srcBuf,
92                                            MediaPixelFormat pixelFormat, int width, int height,
93                                            Tizen::Base::ByteBuffer& destBuf,
94                                            ImageFlipType flip);
95
96         static result FlipBuffer(const byte* srcBuf,
97                                            MediaPixelFormat pixelFormat, int width, int height,
98                                            byte* destBuf,
99                                            ImageFlipType flip);
100
101         static int MinImageFormatLength(void);
102
103         static ImageFormat GetImageFormat(const Tizen::Base::ByteBuffer& srcImageBuf);
104
105         static ImageFormat GetImageFormat(const Tizen::Base::String& srcImageFile);
106
107         static bool HasAlphaChannel(const Tizen::Base::ByteBuffer& srcImageBuf);
108
109         static Tizen::Base::ByteBuffer* ResizeN(const Tizen::Base::ByteBuffer &srcBuf,
110                                                                                   MediaPixelFormat pixelFormat,
111                                                                                   int srcWidth, int srcHeight,
112                                                                                   int dstWidth, int dstHeight);
113
114         static Tizen::Base::ByteBuffer* CropN(const Tizen::Base::ByteBuffer &srcBuf,
115                                                                                 MediaPixelFormat pixelFormat,
116                                                                                 int srcWidth, int srcHeight,
117                                                                                 int dstX, int dstY, int dstWidth, int dstHeight);
118
119         static result Crop(const Tizen::Base::ByteBuffer &srcBuf,
120                                                 MediaPixelFormat pixelFormat,
121                                                 int srcWidth, int srcHeight,
122                                                 Tizen::Base::ByteBuffer &dstBuf,
123                                                 int dstX, int dstY, int dstWidth, int dstHeight);
124
125         static result CropBuffer(const byte* srcBuf,
126                                                 MediaPixelFormat pixelFormat,
127                                                 int srcWidth, int srcHeight,
128                                                 byte* dstBuf,
129                                                 int dstX, int dstY, int dstWidth, int dstHeight);
130
131         static int GetBufferSize(MediaPixelFormat pixelFormat, int width, int height);
132
133         static bool IsValidDimension(MediaPixelFormat pixelFormat, int width, int height);
134
135         static int ToFfmpegPixelFormat(MediaPixelFormat pixelFmt);
136
137         static MediaPixelFormat ToMediaPixelFormatFromFfmpeg(int pixelFormat);
138
139         static byte* CropN(const byte *srcBuf,
140                                                 MediaPixelFormat pixelFormat,
141                                                 int srcWidth, int srcHeight,
142                                                 int dstX, int dstY, int dstWidth, int dstHeight);
143
144         static byte* RotateN(const byte *srcBuf,
145                                                  MediaPixelFormat pixelFormat,
146                                                  int srcWidth, int srcHeight,
147                                                  ImageRotationType rotate,
148                                                  int &dstWidth, int &dstHeight);
149
150         static byte* FlipN(const byte* srcBuf,
151                                            MediaPixelFormat pixelFormat, int width, int height,
152                                            ImageFlipType flip);
153
154         static result GetResizedDimension(int srcWidth, int srcHeight,
155                                                                           float dstWidth, float dstHeight,
156                                                                           float &outWidth, float &outHeight);
157
158 private:
159         _ImageUtil();
160
161         static result Resize8888(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
162
163         static result ResizeRGB888(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
164
165         static result ResizeRGB565(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
166
167         static result ResizeYUV444(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
168
169         static result ResizeYUYV422(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
170
171         static result ResizeYUV420P(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
172
173         static result ResizeNV12(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
174 };
175
176 }
177 }
178
179 #endif