Merge "Introduce WindowData" into devel/master
[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 UtcDaliPixelBufferConstructor01P(void)
200 {
201   TestApplication    application;
202   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
203
204   Devel::PixelBuffer copiedBuf = pixbuf;
205   DALI_TEST_CHECK(pixbuf);
206   DALI_TEST_CHECK(copiedBuf);
207   DALI_TEST_CHECK(pixbuf.GetBuffer() != NULL);
208   DALI_TEST_CHECK(copiedBuf.GetBuffer() != NULL);
209
210   Devel::PixelBuffer movedBuf = std::move(pixbuf);
211   DALI_TEST_CHECK(!pixbuf);
212   DALI_TEST_CHECK(movedBuf);
213   DALI_TEST_CHECK(movedBuf.GetBuffer() != NULL);
214   END_TEST;
215 }
216
217 int UtcDaliPixelBufferAssign01P(void)
218 {
219   TestApplication    application;
220   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
221
222   Devel::PixelBuffer copiedBuf;
223   copiedBuf = pixbuf;
224   DALI_TEST_CHECK(pixbuf);
225   DALI_TEST_CHECK(copiedBuf);
226   DALI_TEST_CHECK(pixbuf.GetBuffer() != NULL);
227   DALI_TEST_CHECK(copiedBuf.GetBuffer() != NULL);
228
229   Devel::PixelBuffer movedBuf;
230   DALI_TEST_CHECK(!movedBuf);
231   movedBuf = std::move(pixbuf);
232   DALI_TEST_CHECK(!pixbuf);
233   DALI_TEST_CHECK(movedBuf);
234   DALI_TEST_CHECK(movedBuf.GetBuffer() != NULL);
235   END_TEST;
236 }
237
238 int UtcDaliPixelBufferNew01N(void)
239 {
240   TestApplication    application;
241   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(0, 0, Pixel::RGBA8888);
242   DALI_TEST_CHECK(pixbuf);
243   DALI_TEST_CHECK(pixbuf.GetBuffer() == NULL);
244   END_TEST;
245 }
246
247 int UtcDaliPixelBufferConvert(void)
248 {
249   TestApplication    application;
250   TestGlAbstraction& gl           = application.GetGlAbstraction();
251   TraceCallStack&    textureTrace = gl.GetTextureTrace();
252   textureTrace.Enable(true);
253
254   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
255   FillCheckerboard(pixbuf);
256
257   {
258     Devel::PixelBuffer pixbufPrime = pixbuf; // store a second handle to the data
259
260     Dali::PixelData pixelData = Devel::PixelBuffer::Convert(pixbuf);
261     DALI_TEST_CHECK(!pixbuf);
262
263     // check the buffer in the second handle is empty
264     DALI_TEST_CHECK(pixbufPrime.GetBuffer() == NULL);
265
266     DALI_TEST_CHECK(pixelData);
267     DALI_TEST_EQUALS(pixelData.GetWidth(), 10, TEST_LOCATION);
268     DALI_TEST_EQUALS(pixelData.GetHeight(), 10, TEST_LOCATION);
269     DALI_TEST_EQUALS(pixelData.GetStride(), 10, TEST_LOCATION);
270     DALI_TEST_EQUALS(pixelData.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
271
272     // Try drawing it
273     Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
274     t.Upload(pixelData);
275     TextureSet ts = TextureSet::New();
276     ts.SetTexture(0, t);
277     Geometry g = CreateQuadGeometry();
278     Shader   s = Shader::New("v", "f");
279     Renderer r = Renderer::New(g, s);
280     r.SetTextures(ts);
281     Actor a = Actor::New();
282     a.AddRenderer(r);
283     a.SetProperty(Actor::Property::SIZE, Vector2(10, 10));
284     a.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
285     application.GetScene().Add(a);
286
287     application.SendNotification();
288     application.Render();
289     DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
290
291     // Let secondary scope destroy pixbufPrime
292   }
293
294   END_TEST;
295 }
296
297 int UtcDaliPixelBufferGetWidth(void)
298 {
299   TestApplication    application;
300   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
301   FillCheckerboard(pixbuf);
302
303   DALI_TEST_EQUALS(pixbuf.GetWidth(), 10, TEST_LOCATION);
304   DALI_TEST_EQUALS(pixbuf.GetStride(), 10, TEST_LOCATION);
305
306   END_TEST;
307 }
308
309 int UtcDaliPixelBufferGetHeight(void)
310 {
311   TestApplication    application;
312   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
313   FillCheckerboard(pixbuf);
314
315   DALI_TEST_EQUALS(pixbuf.GetHeight(), 10, TEST_LOCATION);
316
317   END_TEST;
318 }
319
320 int UtcDaliPixelBufferGetPixelFormat(void)
321 {
322   TestApplication    application;
323   Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
324   FillCheckerboard(pixbuf);
325
326   DALI_TEST_EQUALS(pixbuf.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
327
328   END_TEST;
329 }
330
331 int UtcDaliPixelBufferMask01(void)
332 {
333   TestApplication application;
334
335   unsigned int       width       = 10u;
336   unsigned int       height      = 10u;
337   Pixel::Format      pixelFormat = Pixel::L8;
338   Devel::PixelBuffer maskData    = Devel::PixelBuffer::New(width, height, pixelFormat);
339
340   Mask1stQuadrant(maskData);
341
342   width       = 20u;
343   height      = 20u;
344   pixelFormat = Pixel::RGBA5551;
345
346   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
347   FillCheckerboard(imageData);
348
349   imageData.ApplyMask(maskData, 1.0f, false);
350
351   // Test that the pixel format has been promoted to RGBA8888
352   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
353
354   // Test that a pixel in the first quadrant has no alpha value
355   unsigned char* buffer = imageData.GetBuffer();
356   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
357   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
358
359   // Test that an even pixel in the second quadrant has a full alpha value
360   DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
361
362   // Test that an odd pixel in the second quadrant has full alpha value
363   DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
364
365   END_TEST;
366 }
367
368 int UtcDaliPixelBufferMask02(void)
369 {
370   TestApplication application;
371
372   unsigned int       width       = 10u;
373   unsigned int       height      = 10u;
374   Pixel::Format      pixelFormat = Pixel::L8;
375   Devel::PixelBuffer maskData    = Devel::PixelBuffer::New(width, height, pixelFormat);
376
377   Mask1stQuadrant(maskData);
378
379   width       = 20u;
380   height      = 20u;
381   pixelFormat = Pixel::RGBA4444;
382
383   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
384   FillCheckerboard(imageData);
385
386   imageData.ApplyMask(maskData, 1.0f, false);
387
388   // Test that the pixel format has been promoted to RGBA8888
389   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
390
391   // Test that a pixel in the first quadrant has no alpha value
392   unsigned char* buffer = imageData.GetBuffer();
393   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
394   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
395
396   // Test that an even pixel in the second quadrant has no alpha value
397   DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
398
399   // Test that an odd pixel in the second quadrant has full alpha value
400   DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
401
402   END_TEST;
403 }
404
405 int UtcDaliPixelBufferMask03(void)
406 {
407   TestApplication application;
408   tet_infoline("Test application of alpha mask to smaller RGB565 image");
409
410   unsigned int       width    = 20u;
411   unsigned int       height   = 20u;
412   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
413   Mask1stQuadrant(maskData);
414
415   width                        = 10u;
416   height                       = 10u;
417   Pixel::Format      format    = Pixel::RGB565;
418   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, format);
419   FillCheckerboard(imageData);
420
421   imageData.ApplyMask(maskData, 1.0f, false);
422
423   // Test that the pixel format has been promoted to RGBA8888
424   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
425
426   // Test that a pixel in the first quadrant has no alpha value
427   unsigned char* buffer = imageData.GetBuffer();
428   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
429   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
430
431   // Test that an odd pixel in the fourth quadrant has full alpha value
432   DALI_TEST_EQUALS(buffer[(6 * 10 + 7) * 4 + 3], 0xffu, TEST_LOCATION);
433
434   // Test that an even pixel in the fourth quadrant has full alpha value
435   DALI_TEST_EQUALS(buffer[(6 * 10 + 8) * 4 + 3], 0xffu, TEST_LOCATION);
436
437   END_TEST;
438 }
439
440 int UtcDaliPixelBufferMask04(void)
441 {
442   TestApplication application;
443   tet_infoline("Test application of alpha mask to larger RGBA8888 image");
444
445   unsigned int       width    = 10u;
446   unsigned int       height   = 10u;
447   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
448   Mask1stQuadrant(maskData);
449
450   width                        = 20u;
451   height                       = 20u;
452   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
453   FillCheckerboard(imageData);
454
455   imageData.ApplyMask(maskData, 1.0f, false);
456
457   // Test that the pixel format has been promoted to RGBA8888
458   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
459
460   // Test that a pixel in the first quadrant has no alpha value
461   unsigned char* buffer = imageData.GetBuffer();
462   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
463   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
464
465   // Test that an even pixel in the second quadrant has no alpha value
466   DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
467
468   // Test that an odd pixel in the second quadrant has full alpha value
469   DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
470
471   END_TEST;
472 }
473
474 int UtcDaliPixelBufferMask05(void)
475 {
476   TestApplication application;
477   tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
478
479   unsigned int       width    = 20u;
480   unsigned int       height   = 20u;
481   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
482   Mask1stQuadrant(maskData);
483
484   width                        = 10u;
485   height                       = 10u;
486   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
487   FillCheckerboard(imageData);
488
489   imageData.ApplyMask(maskData, 1.0f, false);
490
491   // Test that the pixel format has been promoted to RGBA8888
492   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
493
494   // Test that a pixel in the first quadrant has no alpha value
495   unsigned char* buffer = imageData.GetBuffer();
496   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
497   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
498
499   // Test that an odd pixel in the second quadrant has full alpha value
500   DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
501
502   // Test that an even pixel in the second quadrant has no alpha value
503   DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
504
505   END_TEST;
506 }
507
508 int UtcDaliPixelBufferMask06(void)
509 {
510   TestApplication application;
511   tet_infoline("Test application of alpha mask to same size RGBA8888 image");
512
513   unsigned int       width    = 10u;
514   unsigned int       height   = 10u;
515   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
516   Mask1stQuadrant(maskData);
517
518   width                        = 10u;
519   height                       = 10u;
520   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
521   FillCheckerboard(imageData);
522
523   imageData.ApplyMask(maskData, 1.0f, false);
524
525   // Test that the pixel format has been promoted to RGBA8888
526   DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
527
528   // Test that a pixel in the first quadrant has no alpha value
529   unsigned char* buffer = imageData.GetBuffer();
530   DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
531   DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
532
533   // Test that an odd pixel in the second quadrant has full alpha value
534   DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
535
536   // Test that an even pixel in the second quadrant has no alpha value
537   DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
538
539   END_TEST;
540 }
541
542 int UtcDaliPixelBufferMask07(void)
543 {
544   TestApplication application;
545   tet_infoline("Test scaling of source image to match alpha mask");
546
547   unsigned int       width    = 20u;
548   unsigned int       height   = 20u;
549   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
550   MaskCenterSquare(maskData);
551
552   // +----------+
553   // |  XXXXXX  |
554   // |  XXXXXX  |
555   // |  XXXXXX  |
556   // |  XXXXXX  |
557   // *----------+
558
559   width                        = 10u;
560   height                       = 10u;
561   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
562   AlternateQuadrants(imageData);
563
564   // +-----XXXXX+
565   // |     XXXXX|
566   // |     XXXXX|
567   // |XXXXX     |
568   // |XXXXX     |
569   // *XXXXX-----+
570
571   imageData.ApplyMask(maskData, 2.0f, true);
572
573   // +----------+
574   // |     XXX  |
575   // |     XXX  |
576   // |  XXX     |
577   // |  XXX     |
578   // *----------+
579
580   tet_infoline("Test that the image has been scaled to match the alpha mask");
581   DALI_TEST_EQUALS(imageData.GetWidth(), 20, TEST_LOCATION);
582   DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
583
584   tet_infoline("Test that pixels in the outer eighths have no alpha\n");
585
586   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
587   DALI_TEST_EQUALS(GetAlphaAt(imageData, 9, 4), 0x00u, TEST_LOCATION);
588   DALI_TEST_EQUALS(GetAlphaAt(imageData, 15, 4), 0x00u, TEST_LOCATION);
589   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 4), 0x00u, TEST_LOCATION);
590
591   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 19), 0x00u, TEST_LOCATION);
592   DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 18), 0x00u, TEST_LOCATION);
593   DALI_TEST_EQUALS(GetAlphaAt(imageData, 15, 17), 0x00u, TEST_LOCATION);
594   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 16), 0x00u, TEST_LOCATION);
595
596   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 1), 0x00u, TEST_LOCATION);
597   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 7), 0x00u, TEST_LOCATION);
598   DALI_TEST_EQUALS(GetAlphaAt(imageData, 2, 10), 0x00u, TEST_LOCATION);
599   DALI_TEST_EQUALS(GetAlphaAt(imageData, 3, 19), 0x00u, TEST_LOCATION);
600
601   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 1), 0x00u, TEST_LOCATION);
602   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 7), 0x00u, TEST_LOCATION);
603   DALI_TEST_EQUALS(GetAlphaAt(imageData, 17, 10), 0x00u, TEST_LOCATION);
604   DALI_TEST_EQUALS(GetAlphaAt(imageData, 16, 19), 0x00u, TEST_LOCATION);
605
606   tet_infoline("Test that pixels in the center have full alpha\n");
607
608   DALI_TEST_EQUALS(GetAlphaAt(imageData, 12, 8), 0xffu, TEST_LOCATION);
609   DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 12), 0xffu, TEST_LOCATION);
610
611   END_TEST;
612 }
613
614 int UtcDaliPixelBufferMask08(void)
615 {
616   TestApplication application;
617   tet_infoline("Test scaling of source image to larger than the alpha mask");
618
619   unsigned int       width    = 32u;
620   unsigned int       height   = 20u;
621   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
622   AlternateQuadrants(maskData);
623
624   // +-----XXXXX+
625   // |     XXXXX|
626   // |     XXXXX|
627   // |XXXXX     |
628   // |XXXXX     |
629   // *XXXXX-----+
630
631   width                        = 20u;
632   height                       = 16u;
633   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
634   MaskCenterSquare(imageData);
635
636   // +----------+
637   // |  XXXXXX  |
638   // |  XXXXXX  |
639   // |  XXXXXX  |
640   // |  XXXXXX  |
641   // *----------+
642
643   imageData.ApplyMask(maskData, 4.0f, true);
644
645   // +-----XXXXX+   quadrant
646   // |     XXXXX|    1    2
647   // |     XXXXX|
648   // |XXXXX     |    4    3
649   // |XXXXX     |
650   // *XXXXX-----+
651
652   tet_infoline("Test that the image has been scaled and cropped to match the alpha mask");
653   DALI_TEST_EQUALS(imageData.GetWidth(), 32, TEST_LOCATION);
654   DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
655
656   tet_infoline("Test that the image has been resized (the center square should now fill the image)\n");
657   tet_infoline("Test that the first quadrant has no alpha");
658   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
659   DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION);
660   DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION);
661   DALI_TEST_EQUALS(GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION);
662
663   tet_infoline("Test that the second quadrant has alpha and data");
664   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION);
665   DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION);
666   DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION);
667   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION);
668
669   tet_infoline("Test that the third quadrant has no alpha");
670   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION);
671   DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION);
672   DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION);
673   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION);
674
675   tet_infoline("Test that the fourth quadrant has alpha and data");
676   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION);
677   DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION);
678   DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION);
679   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION);
680
681   END_TEST;
682 }
683
684 int UtcDaliPixelBufferMask09(void)
685 {
686   TestApplication application;
687   tet_infoline("Test scaling of large source image to larger than the alpha mask");
688
689   unsigned int       width    = 32u;
690   unsigned int       height   = 20u;
691   Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
692   AlternateQuadrants(maskData);
693
694   // +-----XXXXX+
695   // |     XXXXX|
696   // |     XXXXX|
697   // |XXXXX     |
698   // |XXXXX     |
699   // *XXXXX-----+
700
701   width                        = 40u;
702   height                       = 50u;
703   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
704   MaskCenterSquare(imageData);
705
706   // +----------+
707   // |  XXXXXX  |
708   // |  XXXXXX  |
709   // |  XXXXXX  |
710   // |  XXXXXX  |
711   // *----------+
712
713   imageData.ApplyMask(maskData, 1.6f, true);
714
715   // +-----XXXXX+   quadrant
716   // |     XXXXX|    1    2
717   // |     XXXXX|
718   // |XXXXX     |    4    3
719   // |XXXXX     |
720   // *XXXXX-----+
721
722   tet_infoline("Test that the image has been scaled and cropped to match the alpha mask");
723   DALI_TEST_EQUALS(imageData.GetWidth(), 32, TEST_LOCATION);
724   DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
725
726   tet_infoline("Test that the image has been resized (the center square should now fill the image)\n");
727   tet_infoline("Test that the first quadrant has no alpha");
728   DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
729   DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION);
730   DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION);
731   DALI_TEST_EQUALS(GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION);
732
733   tet_infoline("Test that the second quadrant has alpha and data");
734   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION);
735   DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION);
736   DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION);
737   DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION);
738
739   tet_infoline("Test that the third quadrant has no alpha");
740   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION);
741   DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION);
742   DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION);
743   DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION);
744
745   tet_infoline("Test that the fourth quadrant has alpha and data");
746   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION);
747   DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION);
748   DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION);
749   DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION);
750
751   END_TEST;
752 }
753
754 int UtcDaliPixelBufferGaussianBlur(void)
755 {
756   TestApplication application;
757
758   Devel::PixelBuffer imageData = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
759   FillCheckerboard(imageData);
760
761   DALI_TEST_EQUALS(imageData.GetWidth(), 10, TEST_LOCATION);
762   DALI_TEST_EQUALS(imageData.GetHeight(), 10, TEST_LOCATION);
763
764   unsigned char* buffer = imageData.GetBuffer();
765
766   // Test that an even pixel in the odd row has full alpha value
767   DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
768
769   // Test that an even pixel in the even row has no alpha value
770   DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
771
772   imageData.ApplyGaussianBlur(0.0f);
773
774   // Test that the pixels' alpha values are not changed because there is no blur
775   DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
776   DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
777
778   imageData.ApplyGaussianBlur(1.0f);
779
780   // Test that the pixels' alpha values are changed after applying gaussian blur
781   DALI_TEST_EQUALS(buffer[43], 0x7Au, TEST_LOCATION);
782   DALI_TEST_EQUALS(buffer[55], 0x7Eu, TEST_LOCATION);
783
784   END_TEST;
785 }