709b2c9ad3e3facd0832cf42e8d9c00cfa9c5e12
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-PixelBuffer.cpp
1 /*
2  * Copyright (c) 2017 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 #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"
21 using namespace Dali;
22
23 void utc_dali_pixelbuffer_startup(void)
24 {
25   test_return_value = TET_UNDEF;
26 }
27
28 void utc_dali_pixelbuffer_cleanup(void)
29 {
30   test_return_value = TET_PASS;
31 }
32
33 int UtcDaliPixelBufferCreatePixelData(void)
34 {
35   TestApplication application;
36
37   unsigned int width = 20u;
38   unsigned int height = 20u;
39   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGB888 );
40
41   PixelData pixelData = imageData.CreatePixelData();
42
43   DALI_TEST_EQUALS( true, (bool)pixelData, TEST_LOCATION );
44
45   END_TEST;
46 }
47
48
49 void Mask1stQuadrant( Devel::PixelBuffer maskData )
50 {
51   int width = maskData.GetWidth();
52   int height = maskData.GetHeight();
53   Pixel::Format pixelFormat = maskData.GetPixelFormat();
54   int bpp = Pixel::GetBytesPerPixel(pixelFormat);
55
56   unsigned char* maskBuffer = maskData.GetBuffer();
57   memset( maskBuffer, 0, width*height*bpp );
58   int offset=0;
59   for( int x=0; x<width; ++x)
60   {
61     for( int y=0; y<height; ++y)
62     {
63       if(x>=width/2 || y>=height/2)
64       {
65         for(int b=0;b<bpp;++b)
66         {
67           maskBuffer[offset+b] = 0xff;
68         }
69       }
70       offset+=bpp;
71     }
72   }
73 }
74
75 void MaskCenterSquare( Devel::PixelBuffer maskData )
76 {
77   int width = maskData.GetWidth();
78   int height = maskData.GetHeight();
79   Pixel::Format pixelFormat = maskData.GetPixelFormat();
80   int bpp = Pixel::GetBytesPerPixel(pixelFormat);
81
82   unsigned char* maskBuffer = maskData.GetBuffer();
83   memset( maskBuffer, 0, width*height*bpp );
84   int offset=0;
85   for( int y=0; y<height; ++y)
86   {
87     for( int x=0; x<width; ++x)
88     {
89       if(x>=width/4 && x<3*width/4 &&
90          y>=height/4 && y<3*height/4 )
91       {
92         for(int b=0;b<bpp;++b)
93         {
94           maskBuffer[offset+b] = 0xff;
95         }
96       }
97       offset+=bpp;
98     }
99   }
100 }
101
102 void AlternateQuadrants( Devel::PixelBuffer buffer )
103 {
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;
109
110   unsigned char* pixels = buffer.GetBuffer();
111   memset( pixels, 0, width*height*bpp );
112
113   for( int x=0; x<width; ++x)
114   {
115     for( int y=0; y<height; ++y)
116     {
117       if( ( x < width/2 && y >= height/2 ) ||
118           ( x >= width/2 && y < height/2 ) )
119       {
120         for(int b=0;b<bpp;++b)
121         {
122           pixels[y*stride+x*bpp+b] = 0xff;
123         }
124       }
125     }
126   }
127 }
128
129
130 void FillCheckerboard( Devel::PixelBuffer imageData )
131 {
132   int width = imageData.GetWidth();
133   int height = imageData.GetHeight();
134   Pixel::Format pixelFormat = imageData.GetPixelFormat();
135   int bpp = Pixel::GetBytesPerPixel(pixelFormat);
136
137   unsigned char* imageBuffer = imageData.GetBuffer();
138   memset( imageBuffer, 0, width*height*bpp );
139   int offset=0;
140   for( int x=0; x<width; ++x)
141   {
142     for( int y=0; y<height; ++y)
143     {
144       // on even lines, odd pixels, or on odd lines, even pixels
145       if( (x%2 && y%2==0) || (x%2==0 && y%2) )
146       {
147         switch(pixelFormat)
148         {
149           case Pixel::RGBA5551:
150             imageBuffer[offset] = 0xFF;
151             imageBuffer[offset+1] = 0xFF;
152             break;
153           case Pixel::RGBA4444:
154             imageBuffer[offset] = 0xFF;
155             imageBuffer[offset+1] = 0xFF;
156             break;
157           case Pixel::RGB565:
158             imageBuffer[offset] = 0xFF;
159             imageBuffer[offset+1] = 0xFF;
160             break;
161           case Pixel::RGB888:
162             imageBuffer[offset] = 0xFF;
163             imageBuffer[offset+1] = 0xFF;
164             imageBuffer[offset+2] = 0xFF;
165             break;
166           case Pixel::RGBA8888:
167             imageBuffer[offset] = 0xFF;
168             imageBuffer[offset+1] = 0xFF;
169             imageBuffer[offset+2] = 0xFF;
170             imageBuffer[offset+3] = 0xFF;
171             break;
172           default:
173             break;
174         }
175       }
176       offset+=bpp;
177     }
178   }
179 }
180
181 int GetAlphaAt( Devel::PixelBuffer buffer, int x, int y )
182 {
183   unsigned char* pixels = buffer.GetBuffer();
184   int bpp = Pixel::GetBytesPerPixel(buffer.GetPixelFormat());
185   int stride = buffer.GetWidth() * bpp;
186   int byteOffset;
187   int bitMask;
188   GetAlphaOffsetAndMask( buffer.GetPixelFormat(), byteOffset, bitMask );
189   return int(pixels[stride * y + x*bpp + byteOffset])  & bitMask;
190 }
191
192 int UtcDaliPixelBufferNew01P(void)
193 {
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 );
198   END_TEST;
199 }
200
201 int UtcDaliPixelBufferNew01N(void)
202 {
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 );
207   END_TEST;
208 }
209
210 int UtcDaliPixelBufferConvert(void)
211 {
212   TestApplication application;
213   TestGlAbstraction& gl=application.GetGlAbstraction();
214   TraceCallStack& textureTrace=gl.GetTextureTrace();
215   textureTrace.Enable(true);
216
217   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
218   FillCheckerboard(pixbuf);
219
220   {
221     Devel::PixelBuffer pixbufPrime = pixbuf; // store a second handle to the data
222
223     Dali::PixelData pixelData = Devel::PixelBuffer::Convert( pixbuf );
224     DALI_TEST_CHECK( !pixbuf );
225
226     // check the buffer in the second handle is empty
227     DALI_TEST_CHECK( pixbufPrime.GetBuffer() == NULL );
228
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 );
233
234     // Try drawing it
235     Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
236     t.Upload( pixelData );
237     TextureSet ts = TextureSet::New();
238     ts.SetTexture(0, t);
239     Geometry g = CreateQuadGeometry();
240     Shader s = Shader::New("v", "f");
241     Renderer r = Renderer::New( g, s );
242     r.SetTextures(ts);
243     Actor a = Actor::New();
244     a.AddRenderer(r);
245     a.SetSize(10, 10);
246     a.SetParentOrigin(ParentOrigin::CENTER);
247     Stage::GetCurrent().Add(a);
248
249     application.SendNotification();
250     application.Render();
251     DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
252
253     // Let secondary scope destroy pixbufPrime
254   }
255
256   END_TEST;
257 }
258
259 int UtcDaliPixelBufferGetWidth(void)
260 {
261   TestApplication application;
262   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
263   FillCheckerboard(pixbuf);
264
265   DALI_TEST_EQUALS( pixbuf.GetWidth(), 10, TEST_LOCATION ) ;
266
267   END_TEST;
268 }
269
270 int UtcDaliPixelBufferGetHeight(void)
271 {
272   TestApplication application;
273   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
274   FillCheckerboard(pixbuf);
275
276   DALI_TEST_EQUALS( pixbuf.GetHeight(), 10, TEST_LOCATION ) ;
277
278   END_TEST;
279 }
280
281 int UtcDaliPixelBufferGetPixelFormat(void)
282 {
283   TestApplication application;
284   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New( 10, 10, Pixel::RGB565 );
285   FillCheckerboard(pixbuf);
286
287   DALI_TEST_EQUALS( pixbuf.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION ) ;
288
289   END_TEST;
290 }
291
292
293
294 int UtcDaliPixelBufferMask01(void)
295 {
296   TestApplication application;
297
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 );
302
303   Mask1stQuadrant(maskData);
304
305   width = 20u;
306   height = 20u;
307   pixelFormat = Pixel::RGBA5551;
308
309   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, pixelFormat );
310   FillCheckerboard(imageData);
311
312   imageData.ApplyMask( maskData, 1.0f, false );
313
314   // Test that the pixel format has been promoted to RGBA8888
315   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
316
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 );
321
322   // Test that an even pixel in the second quadrant has a full alpha value
323   DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
324
325   // Test that an odd pixel in the second quadrant has full alpha value
326   DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
327
328   END_TEST;
329 }
330
331
332 int UtcDaliPixelBufferMask02(void)
333 {
334   TestApplication application;
335
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 );
340
341   Mask1stQuadrant(maskData);
342
343   width = 20u;
344   height = 20u;
345   pixelFormat = Pixel::RGBA4444;
346
347   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, pixelFormat );
348   FillCheckerboard(imageData);
349
350   imageData.ApplyMask( maskData, 1.0f, false );
351
352   // Test that the pixel format has been promoted to RGBA8888
353   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
354
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 );
359
360   // Test that an even pixel in the second quadrant has no alpha value
361   DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
362
363   // Test that an odd pixel in the second quadrant has full alpha value
364   DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
365
366   END_TEST;
367 }
368
369 int UtcDaliPixelBufferMask03(void)
370 {
371   TestApplication application;
372   tet_infoline("Test application of alpha mask to smaller RGB565 image");
373
374   unsigned int width = 20u;
375   unsigned int height = 20u;
376   Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::L8 );
377   Mask1stQuadrant(maskData);
378
379   width = 10u;
380   height = 10u;
381   Pixel::Format format = Pixel::RGB565;
382   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, format );
383   FillCheckerboard(imageData);
384
385   imageData.ApplyMask( maskData, 1.0f, false );
386
387   // Test that the pixel format has been promoted to RGBA8888
388   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
389
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 );
394
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 );
397
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 );
400
401   END_TEST;
402 }
403
404
405 int UtcDaliPixelBufferMask04(void)
406 {
407   TestApplication application;
408   tet_infoline("Test application of alpha mask to larger RGBA8888 image");
409
410   unsigned int width = 10u;
411   unsigned int height = 10u;
412   Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::L8 );
413   Mask1stQuadrant(maskData);
414
415   width = 20u;
416   height = 20u;
417   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
418   FillCheckerboard(imageData);
419
420   imageData.ApplyMask( maskData, 1.0f, false );
421
422   // Test that the pixel format has been promoted to RGBA8888
423   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
424
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 );
429
430   // Test that an even pixel in the second quadrant has no alpha value
431   DALI_TEST_EQUALS( buffer[43], 0x00u, TEST_LOCATION );
432
433   // Test that an odd pixel in the second quadrant has full alpha value
434   DALI_TEST_EQUALS( buffer[47], 0xffu, TEST_LOCATION );
435
436   END_TEST;
437 }
438
439 int UtcDaliPixelBufferMask05(void)
440 {
441   TestApplication application;
442   tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
443
444   unsigned int width = 20u;
445   unsigned int height = 20u;
446   Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
447   Mask1stQuadrant(maskData);
448
449   width = 10u;
450   height = 10u;
451   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
452   FillCheckerboard(imageData);
453
454   imageData.ApplyMask( maskData, 1.0f, false );
455
456   // Test that the pixel format has been promoted to RGBA8888
457   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
458
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 );
463
464   // Test that an odd pixel in the second quadrant has full alpha value
465   DALI_TEST_EQUALS( buffer[39], 0xffu, TEST_LOCATION );
466
467   // Test that an even pixel in the second quadrant has no alpha value
468   DALI_TEST_EQUALS( buffer[27], 0x00u, TEST_LOCATION );
469
470   END_TEST;
471 }
472
473 int UtcDaliPixelBufferMask06(void)
474 {
475   TestApplication application;
476   tet_infoline("Test application of alpha mask to same size RGBA8888 image");
477
478   unsigned int width = 10u;
479   unsigned int height = 10u;
480   Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
481   Mask1stQuadrant(maskData);
482
483   width = 10u;
484   height = 10u;
485   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
486   FillCheckerboard(imageData);
487
488   imageData.ApplyMask( maskData, 1.0f, false );
489
490   // Test that the pixel format has been promoted to RGBA8888
491   DALI_TEST_EQUALS( imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
492
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 );
497
498   // Test that an odd pixel in the second quadrant has full alpha value
499   DALI_TEST_EQUALS( buffer[39], 0xffu, TEST_LOCATION );
500
501   // Test that an even pixel in the second quadrant has no alpha value
502   DALI_TEST_EQUALS( buffer[27], 0x00u, TEST_LOCATION );
503
504   END_TEST;
505 }
506
507
508 int UtcDaliPixelBufferMask07(void)
509 {
510   TestApplication application;
511   tet_infoline("Test scaling of source image to match alpha mask" );
512
513   unsigned int width = 20u;
514   unsigned int height = 20u;
515   Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
516   MaskCenterSquare(maskData);
517
518   // +----------+
519   // |  XXXXXX  |
520   // |  XXXXXX  |
521   // |  XXXXXX  |
522   // |  XXXXXX  |
523   // *----------+
524
525   width = 10u;
526   height = 10u;
527   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
528   AlternateQuadrants( imageData );
529
530   // +-----XXXXX+
531   // |     XXXXX|
532   // |     XXXXX|
533   // |XXXXX     |
534   // |XXXXX     |
535   // *XXXXX-----+
536
537   imageData.ApplyMask( maskData, 2.0f, true );
538
539   // +----------+
540   // |     XXX  |
541   // |     XXX  |
542   // |  XXX     |
543   // |  XXX     |
544   // *----------+
545
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 );
549
550   tet_infoline( "Test that pixels in the outer eighths have no alpha\n" );
551
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 );
556
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 );
561
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 );
566
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 );
571
572   tet_infoline( "Test that pixels in the center have full alpha\n" );
573
574   DALI_TEST_EQUALS( GetAlphaAt(imageData, 12, 8), 0xffu, TEST_LOCATION );
575   DALI_TEST_EQUALS( GetAlphaAt(imageData,  8, 12), 0xffu, TEST_LOCATION );
576
577   END_TEST;
578 }
579
580 int UtcDaliPixelBufferMask08(void)
581 {
582   TestApplication application;
583   tet_infoline("Test scaling of source image to larger than the alpha mask" );
584
585   unsigned int width = 32u;
586   unsigned int height = 20u;
587   Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
588   AlternateQuadrants( maskData );
589
590   // +-----XXXXX+
591   // |     XXXXX|
592   // |     XXXXX|
593   // |XXXXX     |
594   // |XXXXX     |
595   // *XXXXX-----+
596
597   width = 20u;
598   height = 16u;
599   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
600   MaskCenterSquare(imageData);
601
602   // +----------+
603   // |  XXXXXX  |
604   // |  XXXXXX  |
605   // |  XXXXXX  |
606   // |  XXXXXX  |
607   // *----------+
608
609   imageData.ApplyMask( maskData, 4.0f, true );
610
611   // +-----XXXXX+   quadrant
612   // |     XXXXX|    1    2
613   // |     XXXXX|
614   // |XXXXX     |    4    3
615   // |XXXXX     |
616   // *XXXXX-----+
617
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 );
621
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 );
628
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 );
634
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 );
640
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 );
646
647   END_TEST;
648 }
649
650
651 int UtcDaliPixelBufferMask09(void)
652 {
653   TestApplication application;
654   tet_infoline("Test scaling of large source image to larger than the alpha mask" );
655
656   unsigned int width = 32u;
657   unsigned int height = 20u;
658   Devel::PixelBuffer maskData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
659   AlternateQuadrants( maskData );
660
661   // +-----XXXXX+
662   // |     XXXXX|
663   // |     XXXXX|
664   // |XXXXX     |
665   // |XXXXX     |
666   // *XXXXX-----+
667
668   width = 40u;
669   height = 50u;
670   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( width, height, Pixel::RGBA8888 );
671   MaskCenterSquare(imageData);
672
673   // +----------+
674   // |  XXXXXX  |
675   // |  XXXXXX  |
676   // |  XXXXXX  |
677   // |  XXXXXX  |
678   // *----------+
679
680   imageData.ApplyMask( maskData, 1.6f, true );
681
682   // +-----XXXXX+   quadrant
683   // |     XXXXX|    1    2
684   // |     XXXXX|
685   // |XXXXX     |    4    3
686   // |XXXXX     |
687   // *XXXXX-----+
688
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 );
692
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 );
699
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 );
705
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 );
711
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 );
717
718   END_TEST;
719 }
720
721 int UtcDaliPixelBufferGaussianBlur(void)
722 {
723   TestApplication application;
724
725   Devel::PixelBuffer imageData = Devel::PixelBuffer::New( 10, 10, Pixel::RGBA8888 );
726   FillCheckerboard(imageData);
727
728   DALI_TEST_EQUALS( imageData.GetWidth(), 10, TEST_LOCATION ) ;
729   DALI_TEST_EQUALS( imageData.GetHeight(), 10, TEST_LOCATION ) ;
730
731   unsigned char* buffer = imageData.GetBuffer();
732
733   // Test that an even pixel in the odd row has full alpha value
734   DALI_TEST_EQUALS( buffer[43], 0xffu, TEST_LOCATION );
735
736   // Test that an even pixel in the even row has no alpha value
737   DALI_TEST_EQUALS( buffer[55], 0x00u, TEST_LOCATION );
738
739   imageData.ApplyGaussianBlur( 0.0f );
740
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 );
744
745   imageData.ApplyGaussianBlur( 1.0f );
746
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 );
750
751   END_TEST;
752 }