License conversion from Flora to Apache 2.0
[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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
18 #ifndef __DALI_ADAPTOR_TET_IMAGE_LOADERS_H_
19 #define __DALI_ADAPTOR_TET_IMAGE_LOADERS_H_
20
21 #include <dali/dali.h>
22 #include <dali/integration-api/bitmap.h>
23
24 // Simple structure to close the file when finished with it.
25 struct AutoCloseFile
26 {
27   AutoCloseFile( FILE *fp );
28   ~AutoCloseFile();
29   FILE* filePtr;
30 };
31
32 /// Structure to hold image details and the reference buffer.
33 struct ImageDetails
34 {
35   /**
36    * Normal Constructor.
37    *
38    * @param[in]  _name    The name of the image to open.  The reference buffer file should have the same name appended with ".buffer".
39    * @param[in]  _width   The width of the image.
40    * @param[in]  _height  The height of the image.
41    */
42   ImageDetails( const char * const _name, unsigned int _width, unsigned int _height );
43
44   /**
45    * Sometimes an image reports an incorrect size in the header than what it actually is. In such a
46    * scenario, this constructor should be used.
47    *
48    * @param[in]  _name            The name of the image to open.  The reference buffer file should have the same name appended with ".buffer".
49    * @param[in]  _width           The width of the image.
50    * @param[in]  _height          The height of the image.
51    * @param[in]  _reportedWidth   The reported width of the image by reading the header.
52    * @param[in]  _reportedHeight  The reported height of the image by reading the header.
53    */
54   ImageDetails( const char * const _name, unsigned int _width, unsigned int _height, unsigned int _reportedWidth, unsigned int _reportedHeight );
55
56   /**
57    * Destructor
58    */
59   ~ImageDetails();
60
61
62   std::string name;
63   unsigned int width;
64   unsigned int height;
65   unsigned int reportedWidth;
66   unsigned int reportedHeight;
67   unsigned int refBufferSize;
68   Dali::PixelBuffer* const refBuffer;
69
70 private:
71
72   /**
73    * Loads the reference buffer file.
74    */
75   void LoadBuffer();
76 };
77
78 /**
79  * A structure storing the methods that should be called when reading an image's header and when
80  * reading the bitmap from the image file.
81  */
82 struct LoadFunctions
83 {
84   typedef bool (*LoadBitmapFunction)(FILE*, Dali::Integration::Bitmap&, Dali::ImageAttributes&);
85   typedef bool (*LoadBitmapHeaderFunction)(FILE*, const Dali::ImageAttributes& attrs, unsigned int& width, unsigned int& height );
86
87   LoadFunctions( LoadBitmapHeaderFunction _header, LoadBitmapFunction _loader );
88   LoadBitmapHeaderFunction header;
89   LoadBitmapFunction loader;
90 };
91
92 // Helper method to test each image file.
93 /**
94  * Use this method to test the header and and bitmap loading of each image.
95  * The loaded bitmap is then checked with the reference bitmap in ImageDetails.
96  *
97  * @param[in]  image      The image details.
98  * @param[in]  functions  The loader functions that need to be called.
99  */
100 void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions );
101
102 /**
103  * Helper function which should be used when first creating a reference buffer file.
104  * Set output file to a file in the /tmp/ directory e.g:
105  *   DumpImageBufferToTempFile( "images/pattern.gif" , "/tmp/pattern.gif.buffer" );
106  *
107  * @param[in]  filename        The path of the image file.
108  * @param[in]  targetFilename  The path of where the buffer should be written to.  This should ideally be in the "/tmp" folder.
109  * @param[in]  functions       The loader functions to call.
110  */
111 void DumpImageBufferToTempFile( std::string filename, std::string targetFilename, const LoadFunctions& functions );
112
113 #endif // __DALI_ADAPTOR_TET_IMAGE_LOADERS_H_