2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FMedia_ImageUtil.h
20 * @brief This is the header file for the _ImageUtil.
23 #ifndef _FMEDIA_INTERNAL_IMAGE_UTIL_H_
24 #define _FMEDIA_INTERNAL_IMAGE_UTIL_H_
27 #include <FBaseTypes.h>
28 #include <FMediaImageTypes.h>
29 namespace Tizen { namespace Base {
35 namespace Tizen { namespace Media
40 * @brief This class provides internal APIs for image files, such as alpha channel check.
42 * This class provides internal methods for image files. @n@n
44 class _OSP_EXPORT_ _ImageUtil
48 * Checks whether the specified image file has alpha channel. @n
49 * Currently, only 32-bit PNG images are supported.
51 * @return @c true if the image has alpha channel, @n
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.
61 static bool HasAlphaChannel(const Tizen::Base::String& srcImagePath);
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);
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);
75 static result ResizeBuffer(const byte* pInBuf, MediaPixelFormat pixelFormat,
76 int srcWidth, int srcHeight,
77 byte* pOutBuf, int dstWidth, int dstHeight);
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);
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);
91 static result Flip(const Tizen::Base::ByteBuffer& srcBuf,
92 MediaPixelFormat pixelFormat, int width, int height,
93 Tizen::Base::ByteBuffer& destBuf,
96 static result FlipBuffer(const byte* srcBuf,
97 MediaPixelFormat pixelFormat, int width, int height,
101 static int MinImageFormatLength(void);
103 static ImageFormat GetImageFormat(const Tizen::Base::ByteBuffer& srcImageBuf);
105 static ImageFormat GetImageFormat(const Tizen::Base::String& srcImageFile);
107 static bool HasAlphaChannel(const Tizen::Base::ByteBuffer& srcImageBuf);
109 static Tizen::Base::ByteBuffer* ResizeN(const Tizen::Base::ByteBuffer &srcBuf,
110 MediaPixelFormat pixelFormat,
111 int srcWidth, int srcHeight,
112 int dstWidth, int dstHeight);
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);
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);
125 static result CropBuffer(const byte* srcBuf,
126 MediaPixelFormat pixelFormat,
127 int srcWidth, int srcHeight,
129 int dstX, int dstY, int dstWidth, int dstHeight);
131 static int GetBufferSize(MediaPixelFormat pixelFormat, int width, int height);
133 static bool IsValidDimension(MediaPixelFormat pixelFormat, int width, int height);
135 static int ToFfmpegPixelFormat(MediaPixelFormat pixelFmt);
137 static MediaPixelFormat ToMediaPixelFormatFromFfmpeg(int pixelFormat);
139 static byte* CropN(const byte *srcBuf,
140 MediaPixelFormat pixelFormat,
141 int srcWidth, int srcHeight,
142 int dstX, int dstY, int dstWidth, int dstHeight);
144 static byte* RotateN(const byte *srcBuf,
145 MediaPixelFormat pixelFormat,
146 int srcWidth, int srcHeight,
147 ImageRotationType rotate,
148 int &dstWidth, int &dstHeight);
150 static byte* FlipN(const byte* srcBuf,
151 MediaPixelFormat pixelFormat, int width, int height,
154 static result GetResizedDimension(int srcWidth, int srcHeight,
155 float dstWidth, float dstHeight,
156 float &outWidth, float &outHeight);
161 static result Resize8888(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
163 static result ResizeRGB888(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
165 static result ResizeRGB565(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
167 static result ResizeYUV444(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
169 static result ResizeYUYV422(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
171 static result ResizeYUV420P(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);
173 static result ResizeNV12(const byte* pDataIn, byte* pDataOut, int inWidth, int inHeight, int outWidth, int outHeight);