2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali-test-suite-utils.h>
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>
28 int UtcDaliPixelData01(void)
30 TestApplication application;
32 unsigned int width = 10u;
33 unsigned int height = 10u;
34 unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
36 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
37 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
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 );
47 int UtcDaliPixelData02(void)
49 TestApplication application;
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 ];
57 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
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 );
67 int UtcDaliPixelDataCopyConstructor(void)
69 TestApplication application;
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 );
77 PixelData pixelDataCopy(pixelData);
79 DALI_TEST_EQUALS( (bool)pixelDataCopy, true, TEST_LOCATION );
83 int UtcDaliPixelDataAssignmentOperator(void)
85 TestApplication application;
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 );
94 DALI_TEST_EQUALS( (bool)pixelData2, false, TEST_LOCATION );
96 pixelData2 = pixelData;
97 DALI_TEST_EQUALS( (bool)pixelData2, true, TEST_LOCATION );
103 int UtcDaliPixelDataMask01(void)
105 TestApplication application;
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 );
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 );
120 Dali::ApplyMask( imageData, maskData );
122 // Test that the pixel format has been promoted to RGBA8888
123 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
128 int UtcDaliPixelDataMask02(void)
130 TestApplication application;
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 );
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 );
145 Dali::ApplyMask( imageData, maskData );
147 // Test that the pixel format has been promoted to RGBA8888
148 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
153 int UtcDaliPixelDataMask03(void)
155 TestApplication application;
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 );
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 );
170 Dali::ApplyMask( imageData, maskData );
172 // Test that the pixel format has been promoted to RGBA8888
173 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
175 // Can't test the final image directly...
181 int UtcDaliPixelDataMask04(void)
183 TestApplication application;
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 );
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 );
197 Dali::ApplyMask( imageData, maskData );
199 // Test that the pixel format hasn't changed
200 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
202 // Can't test the final image directly...
207 int UtcDaliPixelDataMask05(void)
209 TestApplication application;
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 );
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 );
223 Dali::ApplyMask( imageData, maskData );
225 // Test that the pixel format hasn't changed
226 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
228 // Can't test the final image directly...