48ce65c5ff95fb1412324b456bb47ce82b94d965
[platform/framework/native/image.git] / src / inc / FMedia_ImageImpl.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_ImageImpl.h
20  * @brief  This is the header file for the _ImageImpl.
21  */
22 #ifndef _FMEDIA_INTERNAL_IMAGE_IMPL_H_
23 #define _FMEDIA_INTERNAL_IMAGE_IMPL_H_
24
25 #include <FBase.h>
26 #include <FGraphics.h>
27
28 #include <FMediaImageTypes.h>
29 #include <FMediaTypes.h>
30
31
32 namespace Tizen { namespace Media
33 {
34
35 class Image;
36 class _ImageEncoder;
37 class IImageDecodeUrlEventListener;
38
39 class _OSP_EXPORT_ _ImageImpl
40         : public Tizen::Base::Object
41 {
42 public:
43         _ImageImpl(void);
44
45         virtual ~_ImageImpl(void);
46
47 public:
48         result Construct(void);
49
50         /**
51          * Decodes an image file into the decoded bitmap container. @n
52          * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
53          *
54          * @see Image::DecodeToBitmapN()
55          */
56         static Tizen::Graphics::Bitmap*
57                 DecodeToBitmapN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat);
58
59         static Tizen::Graphics::Bitmap*
60                 DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf, Tizen::Graphics::BitmapPixelFormat pixelFormat);
61
62         /**
63          * Decodes an image data into the decoded bitmap container with resizing. @n
64          * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
65          * This method retains the aspect ratio of the original image.
66          *
67          * @see Image::DecodeToBitmapN()
68          */
69         /*static Tizen::Graphics::Bitmap*
70                 DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf,
71                                                 Tizen::Graphics::BitmapPixelFormat pixelFormat = Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888,
72                                                 const Tizen::Graphics::Dimension &dim = Tizen::Graphics::Dimension(0, 0),
73                                                 Tizen::Graphics::BufferScaling bufferScaling = Tizen::Graphics::BUFFER_SCALING_AUTO,
74                                                 ImageFormat imgFormat = IMG_FORMAT_NONE, bool keepAspectRatio = true);*/
75
76         static Tizen::Graphics::Bitmap*
77                 DecodeToBitmapN(const Tizen::Base::String& srcImagePath,
78                                                 Tizen::Graphics::BitmapPixelFormat pixelFormat,
79                                                 const Tizen::Graphics::Dimension &destDim,
80                                                 Tizen::Graphics::BufferScaling bufferScaling = Tizen::Graphics::BUFFER_SCALING_AUTO);
81
82         static Tizen::Graphics::Bitmap*
83                 DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf,
84                                                 Tizen::Graphics::BitmapPixelFormat pixelFormat,
85                                                 const Tizen::Graphics::Dimension &destDim,
86                                                 Tizen::Graphics::BufferScaling bufferScaling = Tizen::Graphics::BUFFER_SCALING_AUTO);
87
88         static Tizen::Graphics::Bitmap*
89                 DecodeToBitmapN(const Tizen::Base::ByteBuffer& srcImageBuf,
90                                                 Tizen::Graphics::BitmapPixelFormat pixelFormat,
91                                                 const Tizen::Graphics::FloatDimension &destDim);
92
93         static Tizen::Graphics::Bitmap*
94                 DecodeToBitmapN(const Tizen::Base::String& srcImagePath,
95                                                 Tizen::Graphics::BitmapPixelFormat pixelFormat,
96                                                 const Tizen::Graphics::FloatDimension &destDim);
97
98
99         /**
100          * Decodes an image data into the decoded byte buffer container without resizing. @n
101          * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
102          *
103          * @see Image::DecodeToBufferN()
104          */
105         static Tizen::Base::ByteBuffer*
106                 DecodeToBufferN(const Tizen::Base::ByteBuffer& srcImageBuf,
107                                                 Tizen::Graphics::Dimension &restDim,
108                                                 const Tizen::Graphics::Dimension &destDim = Tizen::Graphics::Dimension(0,0),
109                                                 Tizen::Graphics::BitmapPixelFormat pixelFormat = Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888,
110                                                 ImageFormat imgFormat = IMG_FORMAT_NONE, bool keepAspectRatio = true);
111
112         /**
113          * Decodes an image file into the decoded byte buffer container without resizing. @n
114          * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
115          *
116          * @see Image::DecodeToBufferN()
117          */
118         static Tizen::Base::ByteBuffer*
119                 DecodeToBufferN(const Tizen::Base::String& srcImagePath,
120                                                 Tizen::Graphics::Dimension &restDim,
121                                                 const Tizen::Graphics::Dimension &destDim = Tizen::Graphics::Dimension(0,0),
122                                                 Tizen::Graphics::BitmapPixelFormat pixelFormat = Tizen::Graphics::BITMAP_PIXEL_FORMAT_ARGB8888,
123                                                 ImageFormat imgFormat = IMG_FORMAT_NONE, bool keepAspectRatio = true);
124
125         /**
126          * @deprecated
127          * Decodes an image file into the decoded byte buffer container without resizing. @n
128          * The currently supported decoding formats are JPEG, GIF, PNG, BMP, TIFF, and WBMP.
129          *
130          * @see Image::DecodeToBufferN()
131          */
132         static Tizen::Base::ByteBuffer*
133                 DecodeToBufferN(const Tizen::Base::String& srcImagePath,
134                                                 Tizen::Graphics::BitmapPixelFormat pixelFormat,
135                                                 int& imageWidth, int& imageHeight, bool keepAspectRatio = true);
136
137         /**
138          * Converts the image file to the specified image format. @n
139          * This is a synchronous method. The converting formats currently supported are JPEG, BMP, and PNG.
140          *
141          * @see Image::ConvertToBufferN()
142          */
143         static Tizen::Base::ByteBuffer*
144                 ConvertToBufferN(const Tizen::Base::String& srcImagePath, ImageFormat destImageFormat);
145
146         /**
147          * Encodes the specified bitmap data into a byte buffer. @n
148          * The currently supported encoding formats are JPEG, BMP, and PNG.
149          *
150          * @see Image::EncodeToBufferN()
151          */
152         static Tizen::Base::ByteBuffer*
153                 EncodeToBufferN(const Tizen::Graphics::Bitmap& srcBitmap, ImageFormat destImageFormat);
154
155
156         /**
157          * Encodes the specified bitmap data into a file. @n
158          * The currently supported encoding formats are JPEG, BMP, and PNG.
159          *
160          * @see Image::EncodeToFile()
161          */
162         static result EncodeToFile(const Tizen::Graphics::Bitmap& srcBitmap,
163                                                            ImageFormat destImageFormat, const Tizen::Base::String& destImagePath,
164                                                            bool overwrite);
165
166         /**
167          * Recompresses an encoded image file to reduce its size as per the specified limit. @n
168          * The only supported compression format is JPEG.
169          *
170          * @see Image::CompressJpeg()
171          */
172         static result CompressJpeg(const Tizen::Base::String& srcImagePath,
173                                                            const Tizen::Base::String& destImagePath, int limitSize);
174
175         /**
176          * Recompresses an encoded image data to the byte buffer to reduce its data size as per the specified limit. @n
177          * The only supported compression format is JPEG.
178          *
179          * @see Image::CompressJpegN()
180          */
181         static Tizen::Base::ByteBuffer* CompressJpegN(const Tizen::Base::ByteBuffer& srcImageBuf,
182                                                                                                 int limitSize);
183
184         /**
185          * Get image informations
186          *
187          * @see Image::GetImageInfo()
188          */
189         static result GetImageInfo(const Tizen::Base::String& imagePath, ImageFormat &imgFormat,
190                                                            Tizen::Graphics::Dimension &dim);
191
192 public:
193
194         /**
195          * @deprecated Use DecodeToBufferN
196          */
197         static Tizen::Base::ByteBuffer*
198                 DecodeN(const Tizen::Base::String& srcImagePath, Tizen::Graphics::BitmapPixelFormat pixelFormat,
199                                 int destWidth, int destHeight, bool keepAspectRatio=false);
200
201
202         result DecodeUrl(const Tizen::Base::Utility::Uri& srcImageUrl,
203                                          Tizen::Graphics::BitmapPixelFormat pixelFormat,
204                                          int destWidth, int destHeight, RequestId& reqId,
205                                          const IImageDecodeUrlEventListener& listener, long timeout);
206
207 protected:
208 //
209 //      static Tizen::Base::ByteBuffer* DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf,
210 //                                                                                ImageFormat srcImageFormat,
211 //                                                                                Tizen::Graphics::BitmapPixelFormat pixelFormat,
212 //                                                                                Tizen::Graphics::Dimension& destDim);
213 //
214 //      static Tizen::Base::ByteBuffer* DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf,
215 //                                                                                ImageFormat srcImageFormat,
216 //                                                                                Tizen::Graphics::BitmapPixelFormat pixelFormat,
217 //                                                                                int destWidth, int destHeight);
218 //
219 //      static result DecodeN(const Tizen::Base::ByteBuffer& srcImageBuf,
220 //                                                ImageFormat imgFormat, Tizen::Graphics::BitmapPixelFormat pixelFormat,
221 //                                                byte*&outBuf, int &outLength, Tizen::Graphics::Dimension &dim);
222 //
223
224         static Tizen::Base::ByteBuffer*
225                 EncodeToBufferLimitN(const Tizen::Base::ByteBuffer &srcBuf, const Tizen::Graphics::Dimension& dim,
226                                                          MediaPixelFormat pixelFormat, ImageFormat imgFormat, int limit);
227
228         static Tizen::Base::ByteBuffer*
229                 EncodeToBufferQualityN(const Tizen::Base::ByteBuffer &srcBuf,
230                                                            const Tizen::Graphics::Dimension& dim,
231                                                            MediaPixelFormat pixelFormat, ImageFormat imgFormat, int quality);
232
233 public:
234         static _ImageImpl* GetInstance(Image* pImage);
235         static const _ImageImpl* GetInstance(const Image* pImage);
236
237 private:
238 //
239 //      static Tizen::Base::ByteBuffer* DecodeToBufferN(const Tizen::Base::String& srcImagePath,
240 //                                                                                Tizen::Graphics::BitmapPixelFormat pixelFormat,
241 //                                                                                Tizen::Graphics::Dimension& destDim);
242 //
243 //
244 //      static int GetFilesizeWithLowestQuality(_ImageEncoder &enc, Tizen::Base::ByteBuffer& pOutBuf,
245 //                                                                                      Tizen::Graphics::Dimension& destDim);
246 //
247
248         _ImageImpl(const _ImageImpl& impl);
249         _ImageImpl& operator =(const _ImageImpl& impl);
250
251 }; // class _ImageImpl
252
253 };
254 };
255
256 #endif