2 * Copyright (c) 2020 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 MaskCenterSquare( Devel::PixelBuffer maskData )
77 int width = maskData.GetWidth();
78 int height = maskData.GetHeight();
79 Pixel::Format pixelFormat = maskData.GetPixelFormat();
80 int bpp = Pixel::GetBytesPerPixel(pixelFormat);
82 unsigned char* maskBuffer = maskData.GetBuffer();
83 memset( maskBuffer, 0, width*height*bpp );
85 for( int y=0; y<height; ++y)
87 for( int x=0; x<width; ++x)
89 if(x>=width/4 && x<3*width/4 &&
90 y>=height/4 && y<3*height/4 )
92 for(int b=0;b<bpp;++b)
94 maskBuffer[offset+b] = 0xff;
102 void AlternateQuadrants( Devel::PixelBuffer buffer )
104 int width = buffer.GetWidth();
105 int height = buffer.GetHeight();
106 Pixel::Format pixelFormat = buffer.GetPixelFormat();
107 int bpp = Pixel::GetBytesPerPixel(pixelFormat);
108 int stride=width*bpp;
110 unsigned char* pixels = buffer.GetBuffer();
111 memset( pixels, 0, width*height*bpp );
113 for( int x=0; x<width; ++x)
115 for( int y=0; y<height; ++y)
117 if( ( x < width/2 && y >= height/2 ) ||
118 ( x >= width/2 && y < height/2 ) )
120 for(int b=0;b<bpp;++b)
122 pixels[y*stride+x*bpp+b] = 0xff;
130 void FillCheckerboard( Devel::PixelBuffer imageData )
132 int width = imageData.GetWidth();
133 int height = imageData.GetHeight();
134 Pixel::Format pixelFormat = imageData.GetPixelFormat();
135 int bpp = Pixel::GetBytesPerPixel(pixelFormat);
137 unsigned char* imageBuffer = imageData.GetBuffer();
138 memset( imageBuffer, 0, width*height*bpp );
140 for( int x=0; x<width; ++x)
142 for( int y=0; y<height; ++y)
144 // on even lines, odd pixels, or on odd lines, even pixels
145 if( (x%2 && y%2==0) || (x%2==0 && y%2) )
149 case Pixel::RGBA5551:
150 imageBuffer[offset] = 0xFF;
151 imageBuffer[offset+1] = 0xFF;
153 case Pixel::RGBA4444:
154 imageBuffer[offset] = 0xFF;
155 imageBuffer[offset+1] = 0xFF;
158 imageBuffer[offset] = 0xFF;
159 imageBuffer[offset+1] = 0xFF;
162 imageBuffer[offset] = 0xFF;
163 imageBuffer[offset+1] = 0xFF;
164 imageBuffer[offset+2] = 0xFF;
166 case Pixel::RGBA8888:
167 imageBuffer[offset] = 0xFF;
168 imageBuffer[offset+1] = 0xFF;
169 imageBuffer[offset+2] = 0xFF;
170 imageBuffer[offset+3] = 0xFF;
181 int GetAlphaAt( Devel::PixelBuffer buffer, int x, int y )
183 unsigned char* pixels = buffer.GetBuffer();
184 int bpp = Pixel::GetBytesPerPixel(buffer.GetPixelFormat());
185 int stride = buffer.GetWidth() * bpp;
188 GetAlphaOffsetAndMask( buffer.GetPixelFormat(), byteOffset, bitMask );
189 return int(pixels[stride * y + x*bpp + byteOffset]) & bitMask;
192 int UtcDaliPixelBufferNew01P(void)
194 TestApplication application;
195 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGBA8888 );
196 DALI_TEST_CHECK( pixbuf );
197 DALI_TEST_CHECK( pixbuf.GetBuffer() != NULL );
201 int UtcDaliPixelBufferNew01N(void)
203 TestApplication application;
204 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 0, 0, Pixel::RGBA8888 );
205 DALI_TEST_CHECK( pixbuf );
206 DALI_TEST_CHECK( pixbuf.GetBuffer() == NULL );
210 int UtcDaliPixelBufferConvert(void)
212 TestApplication application;
213 TestGlAbstraction& gl=application.GetGlAbstraction();
214 TraceCallStack& textureTrace=gl.GetTextureTrace();
215 textureTrace.Enable(true);
217 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
218 FillCheckerboard(pixbuf);
221 Devel::PixelBuffer pixbufPrime = pixbuf; // store a second handle to the data
223 Dali::PixelData pixelData = Devel::PixelBuffer::Convert( pixbuf );
224 DALI_TEST_CHECK( !pixbuf );
226 // check the buffer in the second handle is empty
227 DALI_TEST_CHECK( pixbufPrime.GetBuffer() == NULL );
229 DALI_TEST_CHECK( pixelData );
230 DALI_TEST_EQUALS( pixelData.GetWidth(), 10, TEST_LOCATION );
231 DALI_TEST_EQUALS( pixelData.GetHeight(), 10, TEST_LOCATION );
232 DALI_TEST_EQUALS( pixelData.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION );
235 Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
236 t.Upload( pixelData );
237 TextureSet ts = TextureSet::New();
239 Geometry g = CreateQuadGeometry();
240 Shader s = Shader::New("v", "f");
241 Renderer r = Renderer::New( g, s );
243 Actor a = Actor::New();
245 a.SetProperty( Actor::Property::SIZE, Vector2(10, 10) );
246 a.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
247 application.GetScene().Add(a);
249 application.SendNotification();
250 application.Render();
251 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
253 // Let secondary scope destroy pixbufPrime
259 int UtcDaliPixelBufferGetWidth(void)
261 TestApplication application;
262 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
263 FillCheckerboard(pixbuf);
265 DALI_TEST_EQUALS( pixbuf.GetWidth(), 10, TEST_LOCATION ) ;
270 int UtcDaliPixelBufferGetHeight(void)
272 TestApplication application;
273 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
274 FillCheckerboard(pixbuf);
276 DALI_TEST_EQUALS( pixbuf.GetHeight(), 10, TEST_LOCATION ) ;
281 int UtcDaliPixelBufferGetPixelFormat(void)
283 TestApplication application;
284 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
285 FillCheckerboard(pixbuf);
287 DALI_TEST_EQUALS( pixbuf.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION ) ;
294 int UtcDaliPixelBufferMask01(void)
296 TestApplication application;
298 unsigned int width = 10u;
299 unsigned int height = 10u;
300 Pixel::Format pixelFormat = Pixel::L8;
301 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, pixelFormat );
303 Mask1stQuadrant(maskData);
307 pixelFormat = Pixel::RGBA5551;
309 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, pixelFormat );
310 FillCheckerboard(imageData);
312 imageData.ApplyMask( maskData, 1.0f, false );
314 // Test that the pixel format has been promoted to RGBA8888
315 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
317 // Test that a pixel in the first quadrant has no alpha value
318 unsigned char* buffer = imageData.GetBuffer();
319 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
320 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
322 // Test that an even pixel in the second quadrant has a full alpha value
323 DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
325 // Test that an odd pixel in the second quadrant has full alpha value
326 DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
332 int UtcDaliPixelBufferMask02(void)
334 TestApplication application;
336 unsigned int width = 10u;
337 unsigned int height = 10u;
338 Pixel::Format pixelFormat = Pixel::L8;
339 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, pixelFormat );
341 Mask1stQuadrant(maskData);
345 pixelFormat = Pixel::RGBA4444;
347 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, pixelFormat );
348 FillCheckerboard(imageData);
350 imageData.ApplyMask( maskData, 1.0f, false );
352 // Test that the pixel format has been promoted to RGBA8888
353 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
355 // Test that a pixel in the first quadrant has no alpha value
356 unsigned char* buffer = imageData.GetBuffer();
357 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
358 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
360 // Test that an even pixel in the second quadrant has no alpha value
361 DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
363 // Test that an odd pixel in the second quadrant has full alpha value
364 DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
369 int UtcDaliPixelBufferMask03(void)
371 TestApplication application;
372 tet_infoline("Test application of alpha mask to smaller RGB565 image");
374 unsigned int width = 20u;
375 unsigned int height = 20u;
376 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::L8 );
377 Mask1stQuadrant(maskData);
381 Pixel::Format format = Pixel::RGB565;
382 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, format );
383 FillCheckerboard(imageData);
385 imageData.ApplyMask( maskData, 1.0f, false );
387 // Test that the pixel format has been promoted to RGBA8888
388 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
390 // Test that a pixel in the first quadrant has no alpha value
391 unsigned char* buffer = imageData.GetBuffer();
392 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
393 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
395 // Test that an odd pixel in the fourth quadrant has full alpha value
396 DALI_TEST_EQUALS( buffer[(6*10+7)*4+3], 0xffu, TEST_LOCATION );
398 // Test that an even pixel in the fourth quadrant has full alpha value
399 DALI_TEST_EQUALS( buffer[(6*10+8)*4+3], 0xffu, TEST_LOCATION );
405 int UtcDaliPixelBufferMask04(void)
407 TestApplication application;
408 tet_infoline("Test application of alpha mask to larger RGBA8888 image");
410 unsigned int width = 10u;
411 unsigned int height = 10u;
412 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::L8 );
413 Mask1stQuadrant(maskData);
417 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
418 FillCheckerboard(imageData);
420 imageData.ApplyMask( maskData, 1.0f, false );
422 // Test that the pixel format has been promoted to RGBA8888
423 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
425 // Test that a pixel in the first quadrant has no alpha value
426 unsigned char* buffer = imageData.GetBuffer();
427 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
428 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
430 // Test that an even pixel in the second quadrant has no alpha value
431 DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
433 // Test that an odd pixel in the second quadrant has full alpha value
434 DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
439 int UtcDaliPixelBufferMask05(void)
441 TestApplication application;
442 tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
444 unsigned int width = 20u;
445 unsigned int height = 20u;
446 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
447 Mask1stQuadrant(maskData);
451 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
452 FillCheckerboard(imageData);
454 imageData.ApplyMask( maskData, 1.0f, false );
456 // Test that the pixel format has been promoted to RGBA8888
457 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
459 // Test that a pixel in the first quadrant has no alpha value
460 unsigned char* buffer = imageData.GetBuffer();
461 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
462 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
464 // Test that an odd pixel in the second quadrant has full alpha value
465 DALI_TEST_EQUALS( buffer[39], 0xffu, TEST_LOCATION );
467 // Test that an even pixel in the second quadrant has no alpha value
468 DALI_TEST_EQUALS( buffer[27], 0x00u, TEST_LOCATION );
473 int UtcDaliPixelBufferMask06(void)
475 TestApplication application;
476 tet_infoline("Test application of alpha mask to same size RGBA8888 image");
478 unsigned int width = 10u;
479 unsigned int height = 10u;
480 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
481 Mask1stQuadrant(maskData);
485 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
486 FillCheckerboard(imageData);
488 imageData.ApplyMask( maskData, 1.0f, false );
490 // Test that the pixel format has been promoted to RGBA8888
491 DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
493 // Test that a pixel in the first quadrant has no alpha value
494 unsigned char* buffer = imageData.GetBuffer();
495 DALI_TEST_EQUALS( buffer[3], 0x00u, TEST_LOCATION );
496 DALI_TEST_EQUALS( buffer[7], 0x00u, TEST_LOCATION );
498 // Test that an odd pixel in the second quadrant has full alpha value
499 DALI_TEST_EQUALS( buffer[39], 0xffu, TEST_LOCATION );
501 // Test that an even pixel in the second quadrant has no alpha value
502 DALI_TEST_EQUALS( buffer[27], 0x00u, TEST_LOCATION );
508 int UtcDaliPixelBufferMask07(void)
510 TestApplication application;
511 tet_infoline("Test scaling of source image to match alpha mask" );
513 unsigned int width = 20u;
514 unsigned int height = 20u;
515 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
516 MaskCenterSquare(maskData);
527 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
528 AlternateQuadrants( imageData );
537 imageData.ApplyMask( maskData, 2.0f, true );
546 tet_infoline("Test that the image has been scaled to match the alpha mask" );
547 DALI_TEST_EQUALS( imageData.GetWidth(), 20, TEST_LOCATION );
548 DALI_TEST_EQUALS( imageData.GetHeight(), 20, TEST_LOCATION );
550 tet_infoline( "Test that pixels in the outer eighths have no alpha\n" );
552 DALI_TEST_EQUALS( GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION );
553 DALI_TEST_EQUALS( GetAlphaAt(imageData, 9, 4), 0x00u, TEST_LOCATION );
554 DALI_TEST_EQUALS( GetAlphaAt(imageData, 15, 4), 0x00u, TEST_LOCATION );
555 DALI_TEST_EQUALS( GetAlphaAt(imageData, 19, 4), 0x00u, TEST_LOCATION );
557 DALI_TEST_EQUALS( GetAlphaAt(imageData, 0, 19), 0x00u, TEST_LOCATION );
558 DALI_TEST_EQUALS( GetAlphaAt(imageData, 8, 18), 0x00u, TEST_LOCATION );
559 DALI_TEST_EQUALS( GetAlphaAt(imageData, 15,17), 0x00u, TEST_LOCATION );
560 DALI_TEST_EQUALS( GetAlphaAt(imageData, 19,16), 0x00u, TEST_LOCATION );
562 DALI_TEST_EQUALS( GetAlphaAt(imageData, 0, 1), 0x00u, TEST_LOCATION );
563 DALI_TEST_EQUALS( GetAlphaAt(imageData, 1, 7), 0x00u, TEST_LOCATION );
564 DALI_TEST_EQUALS( GetAlphaAt(imageData, 2, 10), 0x00u, TEST_LOCATION );
565 DALI_TEST_EQUALS( GetAlphaAt(imageData, 3, 19), 0x00u, TEST_LOCATION );
567 DALI_TEST_EQUALS( GetAlphaAt(imageData, 19, 1), 0x00u, TEST_LOCATION );
568 DALI_TEST_EQUALS( GetAlphaAt(imageData, 18, 7), 0x00u, TEST_LOCATION );
569 DALI_TEST_EQUALS( GetAlphaAt(imageData, 17, 10), 0x00u, TEST_LOCATION );
570 DALI_TEST_EQUALS( GetAlphaAt(imageData, 16, 19), 0x00u, TEST_LOCATION );
572 tet_infoline( "Test that pixels in the center have full alpha\n" );
574 DALI_TEST_EQUALS( GetAlphaAt(imageData, 12, 8), 0xffu, TEST_LOCATION );
575 DALI_TEST_EQUALS( GetAlphaAt(imageData, 8, 12), 0xffu, TEST_LOCATION );
580 int UtcDaliPixelBufferMask08(void)
582 TestApplication application;
583 tet_infoline("Test scaling of source image to larger than the alpha mask" );
585 unsigned int width = 32u;
586 unsigned int height = 20u;
587 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
588 AlternateQuadrants( maskData );
599 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
600 MaskCenterSquare(imageData);
609 imageData.ApplyMask( maskData, 4.0f, true );
611 // +-----XXXXX+ quadrant
618 tet_infoline("Test that the image has been scaled and cropped to match the alpha mask" );
619 DALI_TEST_EQUALS( imageData.GetWidth(), 32, TEST_LOCATION );
620 DALI_TEST_EQUALS( imageData.GetHeight(), 20, TEST_LOCATION );
622 tet_infoline( "Test that the image has been resized (the center square should now fill the image)\n");
623 tet_infoline( "Test that the first quadrant has no alpha");
624 DALI_TEST_EQUALS( GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION );
625 DALI_TEST_EQUALS( GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION );
626 DALI_TEST_EQUALS( GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION );
627 DALI_TEST_EQUALS( GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION );
629 tet_infoline( "Test that the second quadrant has alpha and data");
630 DALI_TEST_EQUALS( GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION );
631 DALI_TEST_EQUALS( GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION );
632 DALI_TEST_EQUALS( GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION );
633 DALI_TEST_EQUALS( GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION );
635 tet_infoline( "Test that the third quadrant has no alpha");
636 DALI_TEST_EQUALS( GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION );
637 DALI_TEST_EQUALS( GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION );
638 DALI_TEST_EQUALS( GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION );
639 DALI_TEST_EQUALS( GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION );
641 tet_infoline( "Test that the fourth quadrant has alpha and data");
642 DALI_TEST_EQUALS( GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION );
643 DALI_TEST_EQUALS( GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION );
644 DALI_TEST_EQUALS( GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION );
645 DALI_TEST_EQUALS( GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION );
651 int UtcDaliPixelBufferMask09(void)
653 TestApplication application;
654 tet_infoline("Test scaling of large source image to larger than the alpha mask" );
656 unsigned int width = 32u;
657 unsigned int height = 20u;
658 Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
659 AlternateQuadrants( maskData );
670 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
671 MaskCenterSquare(imageData);
680 imageData.ApplyMask( maskData, 1.6f, true );
682 // +-----XXXXX+ quadrant
689 tet_infoline("Test that the image has been scaled and cropped to match the alpha mask" );
690 DALI_TEST_EQUALS( imageData.GetWidth(), 32, TEST_LOCATION );
691 DALI_TEST_EQUALS( imageData.GetHeight(), 20, TEST_LOCATION );
693 tet_infoline( "Test that the image has been resized (the center square should now fill the image)\n");
694 tet_infoline( "Test that the first quadrant has no alpha");
695 DALI_TEST_EQUALS( GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION );
696 DALI_TEST_EQUALS( GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION );
697 DALI_TEST_EQUALS( GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION );
698 DALI_TEST_EQUALS( GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION );
700 tet_infoline( "Test that the second quadrant has alpha and data");
701 DALI_TEST_EQUALS( GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION );
702 DALI_TEST_EQUALS( GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION );
703 DALI_TEST_EQUALS( GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION );
704 DALI_TEST_EQUALS( GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION );
706 tet_infoline( "Test that the third quadrant has no alpha");
707 DALI_TEST_EQUALS( GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION );
708 DALI_TEST_EQUALS( GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION );
709 DALI_TEST_EQUALS( GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION );
710 DALI_TEST_EQUALS( GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION );
712 tet_infoline( "Test that the fourth quadrant has alpha and data");
713 DALI_TEST_EQUALS( GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION );
714 DALI_TEST_EQUALS( GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION );
715 DALI_TEST_EQUALS( GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION );
716 DALI_TEST_EQUALS( GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION );
721 int UtcDaliPixelBufferGaussianBlur(void)
723 TestApplication application;
725 Devel::PixelBuffer imageData = Devel::PixelBuffer::New( 10, 10, Pixel::RGBA8888 );
726 FillCheckerboard(imageData);
728 DALI_TEST_EQUALS( imageData.GetWidth(), 10, TEST_LOCATION ) ;
729 DALI_TEST_EQUALS( imageData.GetHeight(), 10, TEST_LOCATION ) ;
731 unsigned char* buffer = imageData.GetBuffer();
733 // Test that an even pixel in the odd row has full alpha value
734 DALI_TEST_EQUALS( buffer[43], 0xffu, TEST_LOCATION );
736 // Test that an even pixel in the even row has no alpha value
737 DALI_TEST_EQUALS( buffer[55], 0x00u, TEST_LOCATION );
739 imageData.ApplyGaussianBlur( 0.0f );
741 // Test that the pixels' alpha values are not changed because there is no blur
742 DALI_TEST_EQUALS( buffer[43], 0xffu, TEST_LOCATION );
743 DALI_TEST_EQUALS( buffer[55], 0x00u, TEST_LOCATION );
745 imageData.ApplyGaussianBlur( 1.0f );
747 // Test that the pixels' alpha values are changed after applying gaussian blur
748 DALI_TEST_EQUALS( buffer[43], 0x7Au, TEST_LOCATION );
749 DALI_TEST_EQUALS( buffer[55], 0x7Eu, TEST_LOCATION );