[4.0] DALi version 1.2.79
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor-internal / image-loaders.h
1 /*
2  * Copyright (c) 2018 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 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
24 #include "platform-abstractions/tizen/image-loaders/image-loader-input.h"
25
26 // Simple structure to close the file when finished with it.
27 struct AutoCloseFile
28 {
29   AutoCloseFile( FILE *fp );
30   ~AutoCloseFile();
31   FILE* filePtr;
32 };
33
34 /// Structure to hold image details and the reference buffer.
35 struct ImageDetails
36 {
37   /**
38    * Normal Constructor.
39    *
40    * @param[in]  _name    The name of the image to open.  The reference buffer file should have the same name appended with ".buffer".
41    * @param[in]  _width   The width of the image.
42    * @param[in]  _height  The height of the image.
43    */
44   ImageDetails( const char * const _name, unsigned int _width, unsigned int _height );
45
46   /**
47    * Sometimes an image reports an incorrect size in the header than what it actually is. In such a
48    * scenario, this constructor should be used.
49    *
50    * @param[in]  _name            The name of the image to open.  The reference buffer file should have the same name appended with ".buffer".
51    * @param[in]  _width           The width of the image.
52    * @param[in]  _height          The height of the image.
53    * @param[in]  _reportedWidth   The reported width of the image by reading the header.
54    * @param[in]  _reportedHeight  The reported height of the image by reading the header.
55    */
56   ImageDetails( const char * const _name, unsigned int _width, unsigned int _height, unsigned int _reportedWidth, unsigned int _reportedHeight );
57
58   /**
59    * Destructor
60    */
61   ~ImageDetails();
62
63
64   std::string name;
65   unsigned int width;
66   unsigned int height;
67   unsigned int reportedWidth;
68   unsigned int reportedHeight;
69   unsigned int refBufferSize;
70   Dali::PixelBuffer* refBuffer;
71
72 private:
73
74   /**
75    * Loads the reference buffer file.
76    */
77   void LoadBuffer();
78 };
79
80 /**
81  * A structure storing the methods that should be called when reading an image's header and when
82  * reading the bitmap from the image file.
83  */
84 struct LoadFunctions
85 {
86   typedef bool (*LoadBitmapFunction)( const Dali::TizenPlatform::ImageLoader::Input& input, Dali::Devel::PixelBuffer& );
87   typedef bool (*LoadBitmapHeaderFunction)( const Dali::TizenPlatform::ImageLoader::Input& input, unsigned int& width, unsigned int& height );
88
89   LoadFunctions( LoadBitmapHeaderFunction _header, LoadBitmapFunction _loader );
90   LoadBitmapHeaderFunction header;
91   LoadBitmapFunction loader;
92 };
93
94 // Helper method to test each image file.
95 /**
96  * Use this method to test the header and and bitmap loading of each image.
97  * The loaded bitmap is then checked with the reference bitmap in ImageDetails.
98  *
99  * @param[in]  image         The image details.
100  * @param[in]  functions     The loader functions that need to be called.
101  * @param[in]  bitmapProfile Whether or not the bitmap is raw
102  */
103 void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions, Dali::Integration::Bitmap::Profile bitmapProfile = Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS );
104
105 /**
106  * Helper method to compare the resultant loaded image data of the specified image with a golden master data.
107  *
108  * @param[in] image         The image to load
109  * @param[in] functions     The functions to use to load the image
110  * @param[in] master        Golden master data to compare the resultant loaded image with
111  */
112 void CompareLoadedImageData( const ImageDetails& image, const LoadFunctions& functions, const uint32_t* master );
113
114 /**
115  * Helper function which should be used when first creating a reference buffer file.
116  * Set output file to a file in the /tmp/ directory e.g:
117  *   DumpImageBufferToTempFile( "images/pattern.gif" , "/tmp/pattern.gif.buffer" );
118  *
119  * @param[in]  filename        The path of the image file.
120  * @param[in]  targetFilename  The path of where the buffer should be written to.  This should ideally be in the "/tmp" folder.
121  * @param[in]  functions       The loader functions to call.
122  */
123 void DumpImageBufferToTempFile( std::string filename, std::string targetFilename, const LoadFunctions& functions );
124
125 #endif // __DALI_ADAPTOR_TET_IMAGE_LOADERS_H_