Revert "[SRUK] Bitmap adaptor patch 1 of 1 - Replace all uses of the Bitmap class...
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor-internal / image-loaders.h
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #ifndef __DALI_ADAPTOR_TET_IMAGE_LOADERS_H_
18 #define __DALI_ADAPTOR_TET_IMAGE_LOADERS_H_
19
20 #include <dali/dali.h>
21 #include <dali/integration-api/bitmap.h>
22
23 // Simple structure to close the file when finished with it.
24 struct AutoCloseFile
25 {
26   AutoCloseFile( FILE *fp );
27   ~AutoCloseFile();
28   FILE* filePtr;
29 };
30
31 /// Structure to hold image details and the reference buffer.
32 struct ImageDetails
33 {
34   /**
35    * Normal Constructor.
36    *
37    * @param[in]  _name    The name of the image to open.  The reference buffer file should have the same name appended with ".buffer".
38    * @param[in]  _width   The width of the image.
39    * @param[in]  _height  The height of the image.
40    */
41   ImageDetails( const char * const _name, unsigned int _width, unsigned int _height );
42
43   /**
44    * Sometimes an image reports an incorrect size in the header than what it actually is. In such a
45    * scenario, this constructor should be used.
46    *
47    * @param[in]  _name            The name of the image to open.  The reference buffer file should have the same name appended with ".buffer".
48    * @param[in]  _width           The width of the image.
49    * @param[in]  _height          The height of the image.
50    * @param[in]  _reportedWidth   The reported width of the image by reading the header.
51    * @param[in]  _reportedHeight  The reported height of the image by reading the header.
52    */
53   ImageDetails( const char * const _name, unsigned int _width, unsigned int _height, unsigned int _reportedWidth, unsigned int _reportedHeight );
54
55   /**
56    * Destructor
57    */
58   ~ImageDetails();
59
60
61   std::string name;
62   unsigned int width;
63   unsigned int height;
64   unsigned int reportedWidth;
65   unsigned int reportedHeight;
66   unsigned int refBufferSize;
67   Dali::PixelBuffer* const refBuffer;
68
69 private:
70
71   /**
72    * Loads the reference buffer file.
73    */
74   void LoadBuffer();
75 };
76
77 /**
78  * A structure storing the methods that should be called when reading an image's header and when
79  * reading the bitmap from the image file.
80  */
81 struct LoadFunctions
82 {
83   typedef bool (*LoadBitmapFunction)(FILE*, Dali::Integration::Bitmap&, Dali::ImageAttributes&);
84   typedef bool (*LoadBitmapHeaderFunction)(FILE*, const Dali::ImageAttributes& attrs, unsigned int& width, unsigned int& height );
85
86   LoadFunctions( LoadBitmapHeaderFunction _header, LoadBitmapFunction _loader );
87   LoadBitmapHeaderFunction header;
88   LoadBitmapFunction loader;
89 };
90
91 // Helper method to test each image file.
92 /**
93  * Use this method to test the header and and bitmap loading of each image.
94  * The loaded bitmap is then checked with the reference bitmap in ImageDetails.
95  *
96  * @param[in]  image      The image details.
97  * @param[in]  functions  The loader functions that need to be called.
98  */
99 void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions );
100
101 /**
102  * Helper function which should be used when first creating a reference buffer file.
103  * Set output file to a file in the /tmp/ directory e.g:
104  *   DumpImageBufferToTempFile( "images/pattern.gif" , "/tmp/pattern.gif.buffer" );
105  *
106  * @param[in]  filename        The path of the image file.
107  * @param[in]  targetFilename  The path of where the buffer should be written to.  This should ideally be in the "/tmp" folder.
108  * @param[in]  functions       The loader functions to call.
109  */
110 void DumpImageBufferToTempFile( std::string filename, std::string targetFilename, const LoadFunctions& functions );
111
112 #endif // __DALI_ADAPTOR_TET_IMAGE_LOADERS_H_