2 * Copyright (c) 2017 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.
17 #include <dali/dali.h>
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
20 #include "mesh-builder.h"
23 void utc_dali_pixelbuffer_startup(void)
25 test_return_value = TET_UNDEF;
28 void utc_dali_pixelbuffer_cleanup(void)
30 test_return_value = TET_PASS;
33 int UtcDaliPixelBufferCreatePixelData(void)
35 TestApplication application;
37 unsigned int width = 20u;
38 unsigned int height = 20u;
39 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGB888 );
41 PixelData pixelData = imageData.CreatePixelData();
43 DALI_TEST_EQUALS( true, (bool)pixelData, TEST_LOCATION );
49 void Mask1stQuadrant( Devel::PixelBuffer maskData )
51 int width = maskData.GetWidth();
52 int height = maskData.GetHeight();
53 Pixel::Format pixelFormat = maskData.GetPixelFormat();
54 int bpp = Pixel::GetBytesPerPixel(pixelFormat);
56 unsigned char* maskBuffer = maskData.GetBuffer();
57 memset( maskBuffer, 0, width*height*bpp );
59 for( int x=0; x<width; ++x)
61 for( int y=0; y<height; ++y)
63 if(x>=width/2 || y>=height/2)
65 for(int b=0;b<bpp;++b)
67 maskBuffer[offset+b] = 0xff;
75 void FillCheckerboard( Devel::PixelBuffer imageData )
77 int width = imageData.GetWidth();
78 int height = imageData.GetHeight();
79 Pixel::Format pixelFormat = imageData.GetPixelFormat();
80 int bpp = Pixel::GetBytesPerPixel(pixelFormat);
82 unsigned char* imageBuffer = imageData.GetBuffer();
83 memset( imageBuffer, 0, width*height*bpp );
85 for( int x=0; x<width; ++x)
87 for( int y=0; y<height; ++y)
89 // on even lines, odd pixels, or on odd lines, even pixels
90 if( (x%2 && y%2==0) || (x%2==0 && y%2) )
95 imageBuffer[offset] = 0xFF;
96 imageBuffer[offset+1] = 0xFF;
99 imageBuffer[offset] = 0xFF;
100 imageBuffer[offset+1] = 0xFF;
103 imageBuffer[offset] = 0xFF;
104 imageBuffer[offset+1] = 0xFF;
107 imageBuffer[offset] = 0xFF;
108 imageBuffer[offset+1] = 0xFF;
109 imageBuffer[offset+2] = 0xFF;
111 case Pixel::RGBA8888:
112 imageBuffer[offset] = 0xFF;
113 imageBuffer[offset+1] = 0xFF;
114 imageBuffer[offset+2] = 0xFF;
115 imageBuffer[offset+3] = 0xFF;
126 int UtcDaliPixelBufferNew01P(void)
128 TestApplication application;
129 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGBA8888 );
130 DALI_TEST_CHECK( pixbuf );
131 DALI_TEST_CHECK( pixbuf.GetBuffer() != NULL );
135 int UtcDaliPixelBufferNew01N(void)
137 TestApplication application;
138 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 0, 0, Pixel::RGBA8888 );
139 DALI_TEST_CHECK( pixbuf );
140 DALI_TEST_CHECK( pixbuf.GetBuffer() == NULL );
144 int UtcDaliPixelBufferConvert(void)
146 TestApplication application;
147 TestGlAbstraction& gl=application.GetGlAbstraction();
148 TraceCallStack& textureTrace=gl.GetTextureTrace();
149 textureTrace.Enable(true);
151 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
152 FillCheckerboard(pixbuf);
155 Devel::PixelBuffer pixbufPrime = pixbuf; // store a second handle to the data
157 Dali::PixelData pixelData = Devel::PixelBuffer::Convert( pixbuf );
158 DALI_TEST_CHECK( !pixbuf );
160 // check the buffer in the second handle is empty
161 DALI_TEST_CHECK( pixbufPrime.GetBuffer() == NULL );
163 DALI_TEST_CHECK( pixelData );
164 DALI_TEST_EQUALS( pixelData.GetWidth(), 10, TEST_LOCATION );
165 DALI_TEST_EQUALS( pixelData.GetHeight(), 10, TEST_LOCATION );
166 DALI_TEST_EQUALS( pixelData.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
169 Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
170 t.Upload( pixelData );
171 TextureSet ts = TextureSet::New();
173 Geometry g = CreateQuadGeometry();
174 Shader s = Shader::New("v", "f");
175 Renderer r = Renderer::New( g, s );
177 Actor a = Actor::New();
180 a.SetParentOrigin(ParentOrigin::CENTER);
181 Stage::GetCurrent().Add(a);
183 application.SendNotification();
184 application.Render();
185 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
187 // Let secondary scope destroy pixbufPrime
193 int UtcDaliPixelBufferGetWidth(void)
195 TestApplication application;
196 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
197 FillCheckerboard(pixbuf);
199 DALI_TEST_EQUALS( pixbuf.GetWidth(), 10, TEST_LOCATION ) ;
204 int UtcDaliPixelBufferGetHeight(void)
206 TestApplication application;
207 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
208 FillCheckerboard(pixbuf);
210 DALI_TEST_EQUALS( pixbuf.GetHeight(), 10, TEST_LOCATION ) ;
215 int UtcDaliPixelBufferGetPixelFormat(void)
217 TestApplication application;
218 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
219 FillCheckerboard(pixbuf);
221 DALI_TEST_EQUALS( pixbuf.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION ) ;
228 int UtcDaliPixelBufferMask01(void)
230 TestApplication application;
232 unsigned int width = 10u;
233 unsigned int height = 10u;
234 Pixel::Format pixelFormat = Pixel::L8;
235 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, pixelFormat );
237 Mask1stQuadrant(maskData);
241 pixelFormat = Pixel::RGBA5551;
243 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, pixelFormat );
244 FillCheckerboard(imageData);
246 imageData.ApplyMask( maskData );
248 // Test that the pixel format has been promoted to RGBA8888
249 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
251 // Test that a pixel in the first quadrant has no alpha value
252 unsigned char* buffer = imageData.GetBuffer();
253 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
254 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
256 // Test that an even pixel in the second quadrant has a full alpha value
257 DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
259 // Test that an odd pixel in the second quadrant has full alpha value
260 DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
266 int UtcDaliPixelBufferMask02(void)
268 TestApplication application;
270 unsigned int width = 10u;
271 unsigned int height = 10u;
272 Pixel::Format pixelFormat = Pixel::L8;
273 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, pixelFormat );
275 Mask1stQuadrant(maskData);
279 pixelFormat = Pixel::RGBA4444;
281 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, pixelFormat );
282 FillCheckerboard(imageData);
284 imageData.ApplyMask( maskData );
286 // Test that the pixel format has been promoted to RGBA8888
287 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
289 // Test that a pixel in the first quadrant has no alpha value
290 unsigned char* buffer = imageData.GetBuffer();
291 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
292 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
294 // Test that an even pixel in the second quadrant has no alpha value
295 DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
297 // Test that an odd pixel in the second quadrant has full alpha value
298 DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
303 int UtcDaliPixelBufferMask03(void)
305 TestApplication application;
306 tet_infoline("Test application of alpha mask to smaller RGB565 image");
308 unsigned int width = 20u;
309 unsigned int height = 20u;
310 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::L8 );
311 Mask1stQuadrant(maskData);
315 Pixel::Format format = Pixel::RGB565;
316 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, format );
317 FillCheckerboard(imageData);
319 imageData.ApplyMask( maskData );
321 // Test that the pixel format has been promoted to RGBA8888
322 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
324 // Test that a pixel in the first quadrant has no alpha value
325 unsigned char* buffer = imageData.GetBuffer();
326 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
327 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
329 // Test that an odd pixel in the second quadrant has full alpha value
330 DALI_TEST_EQUALS( buffer[23], 0xffu, TEST_LOCATION );
332 // Test that an even pixel in the second quadrant has full alpha value
333 DALI_TEST_EQUALS( buffer[27], 0xffu, TEST_LOCATION );
339 int UtcDaliPixelBufferMask04(void)
341 TestApplication application;
342 tet_infoline("Test application of alpha mask to larger RGBA8888 image");
344 unsigned int width = 10u;
345 unsigned int height = 10u;
346 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::L8 );
347 Mask1stQuadrant(maskData);
351 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
352 FillCheckerboard(imageData);
354 imageData.ApplyMask( maskData );
356 // Test that the pixel format has been promoted to RGBA8888
357 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
359 // Test that a pixel in the first quadrant has no alpha value
360 unsigned char* buffer = imageData.GetBuffer();
361 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
362 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
364 // Test that an even pixel in the second quadrant has no alpha value
365 DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
367 // Test that an odd pixel in the second quadrant has full alpha value
368 DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
373 int UtcDaliPixelBufferMask05(void)
375 TestApplication application;
376 tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
378 unsigned int width = 20u;
379 unsigned int height = 20u;
380 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::L8 );
381 Mask1stQuadrant(maskData);
385 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
386 FillCheckerboard(imageData);
388 imageData.ApplyMask( maskData );
390 // Test that the pixel format has been promoted to RGBA8888
391 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
393 // Test that a pixel in the first quadrant has no alpha value
394 unsigned char* buffer = imageData.GetBuffer();
395 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
396 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
398 // Test that an odd pixel in the second quadrant has full alpha value
399 DALI_TEST_EQUALS( buffer[23], 0xffu, TEST_LOCATION );
401 // Test that an even pixel in the second quadrant has no alpha value
402 DALI_TEST_EQUALS( buffer[27], 0x00u, TEST_LOCATION );