Support various yuv formats in jpeg decoder
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-PixelBuffer.cpp
1 /*
2  * Copyright (c) 2022 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-test-suite-utils.h>
18 #include <dali/dali.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 void Mask1stQuadrant(Devel::PixelBuffer maskData)
49 {
50   int           width       = maskData.GetWidth();
51   int           height      = maskData.GetHeight();
52   Pixel::Format pixelFormat = maskData.GetPixelFormat();
53   int           bpp         = Pixel::GetBytesPerPixel(pixelFormat);
54
55   unsigned char* maskBuffer = maskData.GetBuffer();
56   memset(maskBuffer, 0, width * height * bpp);
57   int offset = 0;
58   for(int x = 0; x < width; ++x)
59   {
60     for(int y = 0; y < height; ++y)
61     {
62       if(x >= width / 2 || y >= height / 2)
63       {
64         for(int b = 0; b < bpp; ++b)
65         {
66           maskBuffer[offset + b] = 0xff;
67         }
68       }
69       offset += bpp;
70     }
71   }
72 }
73
74 void MaskCenterSquare(Devel::PixelBuffer maskData)
75 {
76   int           width       = maskData.GetWidth();
77   int           height      = maskData.GetHeight();
78   Pixel::Format pixelFormat = maskData.GetPixelFormat();
79   int           bpp         = Pixel::GetBytesPerPixel(pixelFormat);
80
81   unsigned char* maskBuffer = maskData.GetBuffer();
82   memset(maskBuffer, 0, width * height * bpp);
83   int offset = 0;
84   for(int y = 0; y < height; ++y)
85   {
86     for(int x = 0; x < width; ++x)
87     {
88       if(x >= width / 4 && x < 3 * width / 4 &&
89          y >= height / 4 && y < 3 * height / 4)
90       {
91         for(int b = 0; b < bpp; ++b)
92         {
93           maskBuffer[offset + b] = 0xff;
94         }
95       }
96       offset += bpp;
97     }
98   }
99 }
100
101 void AlternateQuadrants(Devel::PixelBuffer buffer)
102 {
103   int           width       = buffer.GetWidth();
104   int           height      = buffer.GetHeight();
105   Pixel::Format pixelFormat = buffer.GetPixelFormat();
106   int           bpp         = Pixel::GetBytesPerPixel(pixelFormat);
107   int           stride      = width * bpp;
108
109   unsigned char* pixels = buffer.GetBuffer();
110   memset(pixels, 0, width * height * bpp);
111
112   for(int x = 0; x < width; ++x)
113   {
114     for(int y = 0; y < height; ++y)
115     {
116       if((x < width / 2 && y >= height / 2) ||
117          (x >= width / 2 && y < height / 2))
118       {
119         for(int b = 0; b < bpp; ++b)
120         {
121           pixels[y * stride + x * bpp + b] = 0xff;
122         }
123       }
124     }
125   }
126 }
127
128 void FillCheckerboard(Devel::PixelBuffer imageData)
129 {
130   int           width       = imageData.GetWidth();
131   int           height      = imageData.GetHeight();
132   Pixel::Format pixelFormat = imageData.GetPixelFormat();
133   int           bpp         = Pixel::GetBytesPerPixel(pixelFormat);
134
135   unsigned char* imageBuffer = imageData.GetBuffer();
136   memset(imageBuffer, 0, width * height * bpp);
137   int offset = 0;
138   for(int x = 0; x < width; ++x)
139   {
140     for(int y = 0; y < height; ++y)
141     {
142       // on even lines, odd pixels, or on odd lines, even pixels
143       if((x % 2 && y % 2 == 0) || (x % 2 == 0 && y % 2))
144       {
145         switch(pixelFormat)
146         {
147           case Pixel::RGBA5551:
148             imageBuffer[offset]     = 0xFF;
149             imageBuffer[offset + 1] = 0xFF;
150             break;
151           case Pixel::RGBA4444:
152             imageBuffer[offset]     = 0xFF;
153             imageBuffer[offset + 1] = 0xFF;
154             break;
155           case Pixel::RGB565:
156             imageBuffer[offset]     = 0xFF;
157             imageBuffer[offset + 1] = 0xFF;
158             break;
159           case Pixel::RGB888:
160             imageBuffer[offset]     = 0xFF;
161             imageBuffer[offset + 1] = 0xFF;
162             imageBuffer[offset + 2] = 0xFF;
163             break;
164           case Pixel::RGBA8888:
165             imageBuffer[offset]     = 0xFF;
166             imageBuffer[offset + 1] = 0xFF;
167             imageBuffer[offset + 2] = 0xFF;
168             imageBuffer[offset + 3] = 0xFF;
169             break;
170           default:
171             break;
172         }
173       }
174       offset += bpp;
175     }
176   }
177 }
178
179 int GetAlphaAt(Devel::PixelBuffer buffer, int x, int y)
180 {
181   unsigned char* pixels = buffer.GetBuffer();
182   int            bpp    = Pixel::GetBytesPerPixel(buffer.GetPixelFormat());
183   int            stride = buffer.GetWidth() * bpp;
184   int            byteOffset;
185   int            bitMask;
186   GetAlphaOffsetAndMask(buffer.GetPixelFormat(), byteOffset, bitMask);
187   return int(pixels[stride * y + x * bpp + byteOffset]) & bitMask;
188 }
189
190 int UtcDaliPixelBufferNew01P(void)
191 {
192   TestApplication    application;
193   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
194   DALI_TEST_CHECK(pixbuf);
195   DALI_TEST_CHECK(pixbuf.GetBuffer() != NULL);
196   END_TEST;
197 }
198
199 int UtcDaliPixelBufferNew01N(void)
200 {
201   TestApplication    application;
202   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(0, 0, Pixel::RGBA8888);
203   DALI_TEST_CHECK(pixbuf);
204   DALI_TEST_CHECK(pixbuf.GetBuffer() == NULL);
205   END_TEST;
206 }
207
208 int UtcDaliPixelBufferConvert(void)
209 {
210   TestApplication    application;
211   TestGlAbstraction& gl           = application.GetGlAbstraction();
212   TraceCallStack&    textureTrace = gl.GetTextureTrace();
213   textureTrace.Enable(true);
214
215   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
216   FillCheckerboard(pixbuf);
217
218   {
219     Devel::PixelBuffer pixbufPrime = pixbuf; // store a second handle to the data
220
221     Dali::PixelData pixelData = Devel::PixelBuffer::Convert(pixbuf);
222     DALI_TEST_CHECK(!pixbuf);
223
224     // check the buffer in the second handle is empty
225     DALI_TEST_CHECK(pixbufPrime.GetBuffer() == NULL);
226
227     DALI_TEST_CHECK(pixelData);
228     DALI_TEST_EQUALS(pixelData.GetWidth(), 10, TEST_LOCATION);
229     DALI_TEST_EQUALS(pixelData.GetHeight(), 10, TEST_LOCATION);
230     DALI_TEST_EQUALS(pixelData.GetStride(), 10, TEST_LOCATION);
231     DALI_TEST_EQUALS(pixelData.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
232
233     // Try drawing it
234     Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
235     t.Upload(pixelData);
236     TextureSet ts = TextureSet::New();
237     ts.SetTexture(0, t);
238     Geometry g = CreateQuadGeometry();
239     Shader   s = Shader::New("v", "f");
240     Renderer r = Renderer::New(g, s);
241     r.SetTextures(ts);
242     Actor a = Actor::New();
243     a.AddRenderer(r);
244     a.SetProperty(Actor::Property::SIZE, Vector2(10, 10));
245     a.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
246     application.GetScene().Add(a);
247
248     application.SendNotification();
249     application.Render();
250     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
251
252     // Let secondary scope destroy pixbufPrime
253   }
254
255   END_TEST;
256 }
257
258 int UtcDaliPixelBufferGetWidth(void)
259 {
260   TestApplication    application;
261   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
262   FillCheckerboard(pixbuf);
263
264   DALI_TEST_EQUALS(pixbuf.GetWidth(), 10, TEST_LOCATION);
265   DALI_TEST_EQUALS(pixbuf.GetStride(), 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 int UtcDaliPixelBufferMask01(void)
293 {
294   TestApplication application;
295
296   unsigned int       width       = 10u;
297   unsigned int       height      = 10u;
298   Pixel::Format      pixelFormat = Pixel::L8;
299   Devel::PixelBuffer maskData    = Devel::PixelBuffer::New(width, height, pixelFormat);
300
301   Mask1stQuadrant(maskData);
302
303   width       = 20u;
304   height      = 20u;
305   pixelFormat = Pixel::RGBA5551;
306
307   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
308   FillCheckerboard(imageData);
309
310   imageData.ApplyMask(maskData, 1.0f, false);
311
312   // Test that the pixel format has been promoted to RGBA8888
313   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
314
315   // Test that a pixel in the first quadrant has no alpha value
316   unsigned char* buffer = imageData.GetBuffer();
317   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
318   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
319
320   // Test that an even pixel in the second quadrant has a full alpha value
321   DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
322
323   // Test that an odd pixel in the second quadrant has full alpha value
324   DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
325
326   END_TEST;
327 }
328
329 int UtcDaliPixelBufferMask02(void)
330 {
331   TestApplication application;
332
333   unsigned int       width       = 10u;
334   unsigned int       height      = 10u;
335   Pixel::Format      pixelFormat = Pixel::L8;
336   Devel::PixelBuffer maskData    = Devel::PixelBuffer::New(width, height, pixelFormat);
337
338   Mask1stQuadrant(maskData);
339
340   width       = 20u;
341   height      = 20u;
342   pixelFormat = Pixel::RGBA4444;
343
344   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
345   FillCheckerboard(imageData);
346
347   imageData.ApplyMask(maskData, 1.0f, false);
348
349   // Test that the pixel format has been promoted to RGBA8888
350   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
351
352   // Test that a pixel in the first quadrant has no alpha value
353   unsigned char* buffer = imageData.GetBuffer();
354   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
355   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
356
357   // Test that an even pixel in the second quadrant has no alpha value
358   DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
359
360   // Test that an odd pixel in the second quadrant has full alpha value
361   DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
362
363   END_TEST;
364 }
365
366 int UtcDaliPixelBufferMask03(void)
367 {
368   TestApplication application;
369   tet_infoline("Test application of alpha mask to smaller RGB565 image");
370
371   unsigned int       width    = 20u;
372   unsigned int       height   = 20u;
373   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
374   Mask1stQuadrant(maskData);
375
376   width                        = 10u;
377   height                       = 10u;
378   Pixel::Format      format    = Pixel::RGB565;
379   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, format);
380   FillCheckerboard(imageData);
381
382   imageData.ApplyMask(maskData, 1.0f, false);
383
384   // Test that the pixel format has been promoted to RGBA8888
385   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
386
387   // Test that a pixel in the first quadrant has no alpha value
388   unsigned char* buffer = imageData.GetBuffer();
389   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
390   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
391
392   // Test that an odd pixel in the fourth quadrant has full alpha value
393   DALI_TEST_EQUALS(buffer[(6 * 10 + 7) * 4 + 3], 0xffu, TEST_LOCATION);
394
395   // Test that an even pixel in the fourth quadrant has full alpha value
396   DALI_TEST_EQUALS(buffer[(6 * 10 + 8) * 4 + 3], 0xffu, TEST_LOCATION);
397
398   END_TEST;
399 }
400
401 int UtcDaliPixelBufferMask04(void)
402 {
403   TestApplication application;
404   tet_infoline("Test application of alpha mask to larger RGBA8888 image");
405
406   unsigned int       width    = 10u;
407   unsigned int       height   = 10u;
408   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
409   Mask1stQuadrant(maskData);
410
411   width                        = 20u;
412   height                       = 20u;
413   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
414   FillCheckerboard(imageData);
415
416   imageData.ApplyMask(maskData, 1.0f, false);
417
418   // Test that the pixel format has been promoted to RGBA8888
419   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
420
421   // Test that a pixel in the first quadrant has no alpha value
422   unsigned char* buffer = imageData.GetBuffer();
423   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
424   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
425
426   // Test that an even pixel in the second quadrant has no alpha value
427   DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
428
429   // Test that an odd pixel in the second quadrant has full alpha value
430   DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
431
432   END_TEST;
433 }
434
435 int UtcDaliPixelBufferMask05(void)
436 {
437   TestApplication application;
438   tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
439
440   unsigned int       width    = 20u;
441   unsigned int       height   = 20u;
442   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
443   Mask1stQuadrant(maskData);
444
445   width                        = 10u;
446   height                       = 10u;
447   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
448   FillCheckerboard(imageData);
449
450   imageData.ApplyMask(maskData, 1.0f, false);
451
452   // Test that the pixel format has been promoted to RGBA8888
453   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
454
455   // Test that a pixel in the first quadrant has no alpha value
456   unsigned char* buffer = imageData.GetBuffer();
457   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
458   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
459
460   // Test that an odd pixel in the second quadrant has full alpha value
461   DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
462
463   // Test that an even pixel in the second quadrant has no alpha value
464   DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
465
466   END_TEST;
467 }
468
469 int UtcDaliPixelBufferMask06(void)
470 {
471   TestApplication application;
472   tet_infoline("Test application of alpha mask to same size RGBA8888 image");
473
474   unsigned int       width    = 10u;
475   unsigned int       height   = 10u;
476   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
477   Mask1stQuadrant(maskData);
478
479   width                        = 10u;
480   height                       = 10u;
481   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
482   FillCheckerboard(imageData);
483
484   imageData.ApplyMask(maskData, 1.0f, false);
485
486   // Test that the pixel format has been promoted to RGBA8888
487   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
488
489   // Test that a pixel in the first quadrant has no alpha value
490   unsigned char* buffer = imageData.GetBuffer();
491   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
492   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
493
494   // Test that an odd pixel in the second quadrant has full alpha value
495   DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
496
497   // Test that an even pixel in the second quadrant has no alpha value
498   DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
499
500   END_TEST;
501 }
502
503 int UtcDaliPixelBufferMask07(void)
504 {
505   TestApplication application;
506   tet_infoline("Test scaling of source image to match alpha mask");
507
508   unsigned int       width    = 20u;
509   unsigned int       height   = 20u;
510   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
511   MaskCenterSquare(maskData);
512
513   // +----------+
514   // |  XXXXXX  |
515   // |  XXXXXX  |
516   // |  XXXXXX  |
517   // |  XXXXXX  |
518   // *----------+
519
520   width                        = 10u;
521   height                       = 10u;
522   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
523   AlternateQuadrants(imageData);
524
525   // +-----XXXXX+
526   // |     XXXXX|
527   // |     XXXXX|
528   // |XXXXX     |
529   // |XXXXX     |
530   // *XXXXX-----+
531
532   imageData.ApplyMask(maskData, 2.0f, true);
533
534   // +----------+
535   // |     XXX  |
536   // |     XXX  |
537   // |  XXX     |
538   // |  XXX     |
539   // *----------+
540
541   tet_infoline("Test that the image has been scaled to match the alpha mask");
542   DALI_TEST_EQUALS(imageData.GetWidth(), 20, TEST_LOCATION);
543   DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
544
545   tet_infoline("Test that pixels in the outer eighths have no alpha\n");
546
547   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
548   DALI_TEST_EQUALS(GetAlphaAt(imageData, 9, 4), 0x00u, TEST_LOCATION);
549   DALI_TEST_EQUALS(GetAlphaAt(imageData, 15, 4), 0x00u, TEST_LOCATION);
550   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 4), 0x00u, TEST_LOCATION);
551
552   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 19), 0x00u, TEST_LOCATION);
553   DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 18), 0x00u, TEST_LOCATION);
554   DALI_TEST_EQUALS(GetAlphaAt(imageData, 15, 17), 0x00u, TEST_LOCATION);
555   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 16), 0x00u, TEST_LOCATION);
556
557   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 1), 0x00u, TEST_LOCATION);
558   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 7), 0x00u, TEST_LOCATION);
559   DALI_TEST_EQUALS(GetAlphaAt(imageData, 2, 10), 0x00u, TEST_LOCATION);
560   DALI_TEST_EQUALS(GetAlphaAt(imageData, 3, 19), 0x00u, TEST_LOCATION);
561
562   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 1), 0x00u, TEST_LOCATION);
563   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 7), 0x00u, TEST_LOCATION);
564   DALI_TEST_EQUALS(GetAlphaAt(imageData, 17, 10), 0x00u, TEST_LOCATION);
565   DALI_TEST_EQUALS(GetAlphaAt(imageData, 16, 19), 0x00u, TEST_LOCATION);
566
567   tet_infoline("Test that pixels in the center have full alpha\n");
568
569   DALI_TEST_EQUALS(GetAlphaAt(imageData, 12, 8), 0xffu, TEST_LOCATION);
570   DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 12), 0xffu, TEST_LOCATION);
571
572   END_TEST;
573 }
574
575 int UtcDaliPixelBufferMask08(void)
576 {
577   TestApplication application;
578   tet_infoline("Test scaling of source image to larger than the alpha mask");
579
580   unsigned int       width    = 32u;
581   unsigned int       height   = 20u;
582   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
583   AlternateQuadrants(maskData);
584
585   // +-----XXXXX+
586   // |     XXXXX|
587   // |     XXXXX|
588   // |XXXXX     |
589   // |XXXXX     |
590   // *XXXXX-----+
591
592   width                        = 20u;
593   height                       = 16u;
594   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
595   MaskCenterSquare(imageData);
596
597   // +----------+
598   // |  XXXXXX  |
599   // |  XXXXXX  |
600   // |  XXXXXX  |
601   // |  XXXXXX  |
602   // *----------+
603
604   imageData.ApplyMask(maskData, 4.0f, true);
605
606   // +-----XXXXX+   quadrant
607   // |     XXXXX|    1    2
608   // |     XXXXX|
609   // |XXXXX     |    4    3
610   // |XXXXX     |
611   // *XXXXX-----+
612
613   tet_infoline("Test that the image has been scaled and cropped to match the alpha mask");
614   DALI_TEST_EQUALS(imageData.GetWidth(), 32, TEST_LOCATION);
615   DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
616
617   tet_infoline("Test that the image has been resized (the center square should now fill the image)\n");
618   tet_infoline("Test that the first quadrant has no alpha");
619   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
620   DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION);
621   DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION);
622   DALI_TEST_EQUALS(GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION);
623
624   tet_infoline("Test that the second quadrant has alpha and data");
625   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION);
626   DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION);
627   DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION);
628   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION);
629
630   tet_infoline("Test that the third quadrant has no alpha");
631   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION);
632   DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION);
633   DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION);
634   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION);
635
636   tet_infoline("Test that the fourth quadrant has alpha and data");
637   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION);
638   DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION);
639   DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION);
640   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION);
641
642   END_TEST;
643 }
644
645 int UtcDaliPixelBufferMask09(void)
646 {
647   TestApplication application;
648   tet_infoline("Test scaling of large source image to larger than the alpha mask");
649
650   unsigned int       width    = 32u;
651   unsigned int       height   = 20u;
652   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
653   AlternateQuadrants(maskData);
654
655   // +-----XXXXX+
656   // |     XXXXX|
657   // |     XXXXX|
658   // |XXXXX     |
659   // |XXXXX     |
660   // *XXXXX-----+
661
662   width                        = 40u;
663   height                       = 50u;
664   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
665   MaskCenterSquare(imageData);
666
667   // +----------+
668   // |  XXXXXX  |
669   // |  XXXXXX  |
670   // |  XXXXXX  |
671   // |  XXXXXX  |
672   // *----------+
673
674   imageData.ApplyMask(maskData, 1.6f, true);
675
676   // +-----XXXXX+   quadrant
677   // |     XXXXX|    1    2
678   // |     XXXXX|
679   // |XXXXX     |    4    3
680   // |XXXXX     |
681   // *XXXXX-----+
682
683   tet_infoline("Test that the image has been scaled and cropped to match the alpha mask");
684   DALI_TEST_EQUALS(imageData.GetWidth(), 32, TEST_LOCATION);
685   DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
686
687   tet_infoline("Test that the image has been resized (the center square should now fill the image)\n");
688   tet_infoline("Test that the first quadrant has no alpha");
689   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
690   DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION);
691   DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION);
692   DALI_TEST_EQUALS(GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION);
693
694   tet_infoline("Test that the second quadrant has alpha and data");
695   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION);
696   DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION);
697   DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION);
698   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION);
699
700   tet_infoline("Test that the third quadrant has no alpha");
701   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION);
702   DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION);
703   DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION);
704   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION);
705
706   tet_infoline("Test that the fourth quadrant has alpha and data");
707   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION);
708   DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION);
709   DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION);
710   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION);
711
712   END_TEST;
713 }
714
715 int UtcDaliPixelBufferGaussianBlur(void)
716 {
717   TestApplication application;
718
719   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
720   FillCheckerboard(imageData);
721
722   DALI_TEST_EQUALS(imageData.GetWidth(), 10, TEST_LOCATION);
723   DALI_TEST_EQUALS(imageData.GetHeight(), 10, TEST_LOCATION);
724
725   unsigned char* buffer = imageData.GetBuffer();
726
727   // Test that an even pixel in the odd row has full alpha value
728   DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
729
730   // Test that an even pixel in the even row has no alpha value
731   DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
732
733   imageData.ApplyGaussianBlur(0.0f);
734
735   // Test that the pixels' alpha values are not changed because there is no blur
736   DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
737   DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
738
739   imageData.ApplyGaussianBlur(1.0f);
740
741   // Test that the pixels' alpha values are changed after applying gaussian blur
742   DALI_TEST_EQUALS(buffer[43], 0x7Au, TEST_LOCATION);
743   DALI_TEST_EQUALS(buffer[55], 0x7Eu, TEST_LOCATION);
744
745   END_TEST;
746 }