Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PixelData.cpp
1 /*
2  * Copyright (c) 2016 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 #include <cstdlib>
19 #include <dali-test-suite-utils.h>
20
21 #include <dali/public-api/images/pixel.h>
22 #include <dali/public-api/images/pixel-data.h>
23 #include <dali/devel-api/images/pixel-data-mask.h>
24 #include <dali/public-api/common/dali-vector.h>
25
26 using namespace Dali;
27
28 int UtcDaliPixelData01(void)
29 {
30   TestApplication application;
31
32   unsigned int width = 10u;
33   unsigned int height = 10u;
34   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
35
36   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
37   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
38
39   DALI_TEST_CHECK( pixelData );
40   DALI_TEST_CHECK( pixelData.GetWidth() == width );
41   DALI_TEST_CHECK( pixelData.GetHeight() == height );
42   DALI_TEST_CHECK( pixelData.GetPixelFormat() == Pixel::RGB888 );
43
44   END_TEST;
45 }
46
47 int UtcDaliPixelData02(void)
48 {
49   TestApplication application;
50
51   unsigned int width = 10u;
52   unsigned int height = 10u;
53   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
54   unsigned char* buffer = new unsigned char [ bufferSize ];
55   buffer[0] = 'a';
56
57   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
58
59   DALI_TEST_CHECK( pixelData);
60   DALI_TEST_CHECK( pixelData.GetWidth() == width );
61   DALI_TEST_CHECK( pixelData.GetHeight() == height );
62   DALI_TEST_CHECK( pixelData.GetPixelFormat() == Pixel::L8 );
63
64   END_TEST;
65 }
66
67 int UtcDaliPixelDataCopyConstructor(void)
68 {
69   TestApplication application;
70
71   unsigned int width = 10u;
72   unsigned int height = 10u;
73   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
74   unsigned char* buffer = new unsigned char [ bufferSize ];
75   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
76
77   PixelData pixelDataCopy(pixelData);
78
79   DALI_TEST_EQUALS( (bool)pixelDataCopy, true, TEST_LOCATION );
80   END_TEST;
81 }
82
83 int UtcDaliPixelDataAssignmentOperator(void)
84 {
85   TestApplication application;
86
87   unsigned int width = 10u;
88   unsigned int height = 10u;
89   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
90   unsigned char* buffer = new unsigned char [ bufferSize ];
91   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
92
93   PixelData pixelData2;
94   DALI_TEST_EQUALS( (bool)pixelData2, false, TEST_LOCATION );
95
96   pixelData2 = pixelData;
97   DALI_TEST_EQUALS( (bool)pixelData2, true, TEST_LOCATION );
98
99   END_TEST;
100 }
101
102
103 int UtcDaliPixelDataMask01(void)
104 {
105   TestApplication application;
106
107   unsigned int width = 10u;
108   unsigned int height = 10u;
109   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
110   unsigned char* buffer = new unsigned char [ bufferSize ];
111   PixelData maskData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
112
113   width = 20u;
114   height = 20u;
115   Pixel::Format pixelFormat = Pixel::RGBA5551;
116   bufferSize = width*height*Pixel::GetBytesPerPixel( pixelFormat );
117   buffer = new unsigned char [ bufferSize ];
118   PixelData imageData = PixelData::New( buffer, bufferSize, width, height, pixelFormat, PixelData::DELETE_ARRAY );
119
120   Dali::ApplyMask( imageData, maskData );
121
122   // Test that the pixel format has been promoted to RGBA8888
123   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
124
125   END_TEST;
126 }
127
128 int UtcDaliPixelDataMask02(void)
129 {
130   TestApplication application;
131
132   unsigned int width = 10u;
133   unsigned int height = 10u;
134   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
135   unsigned char* buffer = new unsigned char [ bufferSize ];
136   PixelData maskData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
137
138   width = 20u;
139   height = 20u;
140   Pixel::Format pixelFormat = Pixel::RGBA4444;
141   bufferSize = width*height*Pixel::GetBytesPerPixel( pixelFormat );
142   buffer = new unsigned char [ bufferSize ];
143   PixelData imageData = PixelData::New( buffer, bufferSize, width, height, pixelFormat, PixelData::DELETE_ARRAY );
144
145   Dali::ApplyMask( imageData, maskData );
146
147   // Test that the pixel format has been promoted to RGBA8888
148   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
149
150   END_TEST;
151 }
152
153 int UtcDaliPixelDataMask03(void)
154 {
155   TestApplication application;
156
157   unsigned int width = 20u;
158   unsigned int height = 20u;
159   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
160   unsigned char* buffer = new unsigned char [ bufferSize ];
161   PixelData maskData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
162
163   width = 10u;
164   height = 10u;
165   Pixel::Format format = Pixel::RGB565;
166   bufferSize = width*height*Pixel::GetBytesPerPixel( format );
167   buffer = new unsigned char [ bufferSize ];
168   PixelData imageData = PixelData::New( buffer, bufferSize, width, height, format, PixelData::DELETE_ARRAY );
169
170   Dali::ApplyMask( imageData, maskData );
171
172   // Test that the pixel format has been promoted to RGBA8888
173   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
174
175   // Can't test the final image directly...
176
177   END_TEST;
178 }
179
180
181 int UtcDaliPixelDataMask04(void)
182 {
183   TestApplication application;
184
185   unsigned int width = 10u;
186   unsigned int height = 10u;
187   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
188   unsigned char* buffer = new unsigned char [ bufferSize ];
189   PixelData maskData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
190
191   width = 20u;
192   height = 20u;
193   bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGBA8888 );
194   buffer = new unsigned char [ bufferSize ];
195   PixelData imageData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::DELETE_ARRAY );
196
197   Dali::ApplyMask( imageData, maskData );
198
199   // Test that the pixel format hasn't changed
200   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
201
202   // Can't test the final image directly...
203
204   END_TEST;
205 }
206
207 int UtcDaliPixelDataMask05(void)
208 {
209   TestApplication application;
210
211   unsigned int width = 20u;
212   unsigned int height = 20u;
213   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
214   unsigned char* buffer = new unsigned char [ bufferSize ];
215   PixelData maskData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
216
217   width = 10u;
218   height = 10u;
219   bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGBA8888 );
220   buffer = new unsigned char [ bufferSize ];
221   PixelData imageData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::DELETE_ARRAY );
222
223   Dali::ApplyMask( imageData, maskData );
224
225   // Test that the pixel format hasn't changed
226   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
227
228   // Can't test the final image directly...
229
230   END_TEST;
231 }