2 * Copyright (c) 2024 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-test-suite-utils.h>
18 #include <dali/dali.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);
48 void Mask1stQuadrant(Devel::PixelBuffer maskData)
50 int width = maskData.GetWidth();
51 int height = maskData.GetHeight();
52 Pixel::Format pixelFormat = maskData.GetPixelFormat();
53 int bpp = Pixel::GetBytesPerPixel(pixelFormat);
55 unsigned char* maskBuffer = maskData.GetBuffer();
56 memset(maskBuffer, 0, width * height * bpp);
58 for(int x = 0; x < width; ++x)
60 for(int y = 0; y < height; ++y)
62 if(x >= width / 2 || y >= height / 2)
64 for(int b = 0; b < bpp; ++b)
66 maskBuffer[offset + b] = 0xff;
74 void MaskCenterSquare(Devel::PixelBuffer maskData)
76 int width = maskData.GetWidth();
77 int height = maskData.GetHeight();
78 Pixel::Format pixelFormat = maskData.GetPixelFormat();
79 int bpp = Pixel::GetBytesPerPixel(pixelFormat);
81 unsigned char* maskBuffer = maskData.GetBuffer();
82 memset(maskBuffer, 0, width * height * bpp);
84 for(int y = 0; y < height; ++y)
86 for(int x = 0; x < width; ++x)
88 if(x >= width / 4 && x < 3 * width / 4 &&
89 y >= height / 4 && y < 3 * height / 4)
91 for(int b = 0; b < bpp; ++b)
93 maskBuffer[offset + b] = 0xff;
101 void AlternateQuadrants(Devel::PixelBuffer buffer)
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;
109 unsigned char* pixels = buffer.GetBuffer();
110 memset(pixels, 0, width * height * bpp);
112 for(int x = 0; x < width; ++x)
114 for(int y = 0; y < height; ++y)
116 if((x < width / 2 && y >= height / 2) ||
117 (x >= width / 2 && y < height / 2))
119 for(int b = 0; b < bpp; ++b)
121 pixels[y * stride + x * bpp + b] = 0xff;
128 void FillCheckerboard(Devel::PixelBuffer imageData)
130 int width = imageData.GetWidth();
131 int height = imageData.GetHeight();
132 Pixel::Format pixelFormat = imageData.GetPixelFormat();
133 int bpp = Pixel::GetBytesPerPixel(pixelFormat);
135 unsigned char* imageBuffer = imageData.GetBuffer();
136 memset(imageBuffer, 0, width * height * bpp);
138 for(int x = 0; x < width; ++x)
140 for(int y = 0; y < height; ++y)
142 // on even lines, odd pixels, or on odd lines, even pixels
143 if((x % 2 && y % 2 == 0) || (x % 2 == 0 && y % 2))
147 case Pixel::RGBA5551:
148 imageBuffer[offset] = 0xFF;
149 imageBuffer[offset + 1] = 0xFF;
151 case Pixel::RGBA4444:
152 imageBuffer[offset] = 0xFF;
153 imageBuffer[offset + 1] = 0xFF;
156 imageBuffer[offset] = 0xFF;
157 imageBuffer[offset + 1] = 0xFF;
160 imageBuffer[offset] = 0xFF;
161 imageBuffer[offset + 1] = 0xFF;
162 imageBuffer[offset + 2] = 0xFF;
164 case Pixel::RGBA8888:
165 imageBuffer[offset] = 0xFF;
166 imageBuffer[offset + 1] = 0xFF;
167 imageBuffer[offset + 2] = 0xFF;
168 imageBuffer[offset + 3] = 0xFF;
179 int GetAlphaAt(Devel::PixelBuffer buffer, int x, int y)
181 unsigned char* pixels = buffer.GetBuffer();
182 int bpp = Pixel::GetBytesPerPixel(buffer.GetPixelFormat());
183 int stride = buffer.GetWidth() * bpp;
186 GetAlphaOffsetAndMask(buffer.GetPixelFormat(), byteOffset, bitMask);
187 return int(pixels[stride * y + x * bpp + byteOffset]) & bitMask;
190 int UtcDaliPixelBufferNew01P(void)
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);
199 int UtcDaliPixelBufferConstructor01P(void)
201 TestApplication application;
202 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
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);
210 Devel::PixelBuffer movedBuf = std::move(pixbuf);
211 DALI_TEST_CHECK(!pixbuf);
212 DALI_TEST_CHECK(movedBuf);
213 DALI_TEST_CHECK(movedBuf.GetBuffer() != NULL);
217 int UtcDaliPixelBufferAssign01P(void)
219 TestApplication application;
220 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
222 Devel::PixelBuffer copiedBuf;
224 DALI_TEST_CHECK(pixbuf);
225 DALI_TEST_CHECK(copiedBuf);
226 DALI_TEST_CHECK(pixbuf.GetBuffer() != NULL);
227 DALI_TEST_CHECK(copiedBuf.GetBuffer() != NULL);
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);
238 int UtcDaliPixelBufferNew01N(void)
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);
247 int UtcDaliPixelBufferConvert01(void)
249 TestApplication application;
250 TestGlAbstraction& gl = application.GetGlAbstraction();
251 TraceCallStack& textureTrace = gl.GetTextureTrace();
252 textureTrace.Enable(true);
254 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
255 FillCheckerboard(pixbuf);
258 Devel::PixelBuffer pixbufPrime = pixbuf; // store a second handle to the data
260 Dali::PixelData pixelData = Devel::PixelBuffer::Convert(pixbuf);
261 DALI_TEST_CHECK(!pixbuf);
263 // check the buffer in the second handle is empty
264 DALI_TEST_CHECK(pixbufPrime.GetBuffer() == NULL);
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);
273 Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
275 TextureSet ts = TextureSet::New();
277 Geometry g = CreateQuadGeometry();
278 Shader s = Shader::New("v", "f");
279 Renderer r = Renderer::New(g, s);
281 Actor a = Actor::New();
283 a.SetProperty(Actor::Property::SIZE, Vector2(10, 10));
284 a.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
285 application.GetScene().Add(a);
287 application.SendNotification();
288 application.Render();
289 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
291 // Let secondary scope destroy pixbufPrime
297 int UtcDaliPixelBufferConvert02(void)
299 TestApplication application;
300 TestGlAbstraction& gl = application.GetGlAbstraction();
301 TraceCallStack& textureTrace = gl.GetTextureTrace();
302 textureTrace.Enable(true);
304 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
305 FillCheckerboard(pixbuf);
308 Devel::PixelBuffer pixbufPrime = pixbuf; // store a second handle to the data
310 Dali::PixelData pixelData = Devel::PixelBuffer::Convert(pixbuf, true);
311 DALI_TEST_CHECK(!pixbuf);
313 // check the buffer in the second handle is empty
314 DALI_TEST_CHECK(pixbufPrime.GetBuffer() == NULL);
316 DALI_TEST_CHECK(pixelData);
317 DALI_TEST_EQUALS(pixelData.GetWidth(), 10, TEST_LOCATION);
318 DALI_TEST_EQUALS(pixelData.GetHeight(), 10, TEST_LOCATION);
319 DALI_TEST_EQUALS(pixelData.GetStride(), 10, TEST_LOCATION);
320 DALI_TEST_EQUALS(pixelData.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
323 Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
325 TextureSet ts = TextureSet::New();
327 Geometry g = CreateQuadGeometry();
328 Shader s = Shader::New("v", "f");
329 Renderer r = Renderer::New(g, s);
331 Actor a = Actor::New();
333 a.SetProperty(Actor::Property::SIZE, Vector2(10, 10));
334 a.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
335 application.GetScene().Add(a);
337 application.SendNotification();
338 application.Render();
339 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
341 // Let secondary scope destroy pixbufPrime
347 int UtcDaliPixelBufferGetWidth(void)
349 TestApplication application;
350 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
351 FillCheckerboard(pixbuf);
353 DALI_TEST_EQUALS(pixbuf.GetWidth(), 10, TEST_LOCATION);
354 DALI_TEST_EQUALS(pixbuf.GetStride(), 10, TEST_LOCATION);
359 int UtcDaliPixelBufferGetHeight(void)
361 TestApplication application;
362 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
363 FillCheckerboard(pixbuf);
365 DALI_TEST_EQUALS(pixbuf.GetHeight(), 10, TEST_LOCATION);
370 int UtcDaliPixelBufferGetPixelFormat(void)
372 TestApplication application;
373 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
374 FillCheckerboard(pixbuf);
376 DALI_TEST_EQUALS(pixbuf.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
381 int UtcDaliPixelBufferMask01(void)
383 TestApplication application;
385 unsigned int width = 10u;
386 unsigned int height = 10u;
387 Pixel::Format pixelFormat = Pixel::L8;
388 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, pixelFormat);
390 Mask1stQuadrant(maskData);
394 pixelFormat = Pixel::RGBA5551;
396 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
397 FillCheckerboard(imageData);
399 imageData.ApplyMask(maskData, 1.0f, false);
401 // Test that the pixel format has been promoted to RGBA8888
402 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
404 // Test that a pixel in the first quadrant has no alpha value
405 unsigned char* buffer = imageData.GetBuffer();
406 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
407 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
409 // Test that an even pixel in the second quadrant has a full alpha value
410 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
412 // Test that an odd pixel in the second quadrant has full alpha value
413 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
418 int UtcDaliPixelBufferMask02(void)
420 TestApplication application;
422 unsigned int width = 10u;
423 unsigned int height = 10u;
424 Pixel::Format pixelFormat = Pixel::L8;
425 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, pixelFormat);
427 Mask1stQuadrant(maskData);
431 pixelFormat = Pixel::RGBA4444;
433 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
434 FillCheckerboard(imageData);
436 imageData.ApplyMask(maskData, 1.0f, false);
438 // Test that the pixel format has been promoted to RGBA8888
439 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
441 // Test that a pixel in the first quadrant has no alpha value
442 unsigned char* buffer = imageData.GetBuffer();
443 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
444 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
446 // Test that an even pixel in the second quadrant has no alpha value
447 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
449 // Test that an odd pixel in the second quadrant has full alpha value
450 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
455 int UtcDaliPixelBufferMask03(void)
457 TestApplication application;
458 tet_infoline("Test application of alpha mask to smaller RGB565 image");
460 unsigned int width = 20u;
461 unsigned int height = 20u;
462 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
463 Mask1stQuadrant(maskData);
467 Pixel::Format format = Pixel::RGB565;
468 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, format);
469 FillCheckerboard(imageData);
471 imageData.ApplyMask(maskData, 1.0f, false);
473 // Test that the pixel format has been promoted to RGBA8888
474 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
476 // Test that a pixel in the first quadrant has no alpha value
477 unsigned char* buffer = imageData.GetBuffer();
478 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
479 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
481 // Test that an odd pixel in the fourth quadrant has full alpha value
482 DALI_TEST_EQUALS(buffer[(6 * 10 + 7) * 4 + 3], 0xffu, TEST_LOCATION);
484 // Test that an even pixel in the fourth quadrant has full alpha value
485 DALI_TEST_EQUALS(buffer[(6 * 10 + 8) * 4 + 3], 0xffu, TEST_LOCATION);
490 int UtcDaliPixelBufferMask04(void)
492 TestApplication application;
493 tet_infoline("Test application of alpha mask to larger RGBA8888 image");
495 unsigned int width = 10u;
496 unsigned int height = 10u;
497 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
498 Mask1stQuadrant(maskData);
502 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
503 FillCheckerboard(imageData);
505 imageData.ApplyMask(maskData, 1.0f, false);
507 // Test that the pixel format has been promoted to RGBA8888
508 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
510 // Test that a pixel in the first quadrant has no alpha value
511 unsigned char* buffer = imageData.GetBuffer();
512 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
513 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
515 // Test that an even pixel in the second quadrant has no alpha value
516 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
518 // Test that an odd pixel in the second quadrant has full alpha value
519 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
524 int UtcDaliPixelBufferMask05(void)
526 TestApplication application;
527 tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
529 unsigned int width = 20u;
530 unsigned int height = 20u;
531 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
532 Mask1stQuadrant(maskData);
536 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
537 FillCheckerboard(imageData);
539 imageData.ApplyMask(maskData, 1.0f, false);
541 // Test that the pixel format has been promoted to RGBA8888
542 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
544 // Test that a pixel in the first quadrant has no alpha value
545 unsigned char* buffer = imageData.GetBuffer();
546 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
547 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
549 // Test that an odd pixel in the second quadrant has full alpha value
550 DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
552 // Test that an even pixel in the second quadrant has no alpha value
553 DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
558 int UtcDaliPixelBufferMask06(void)
560 TestApplication application;
561 tet_infoline("Test application of alpha mask to same size RGBA8888 image");
563 unsigned int width = 10u;
564 unsigned int height = 10u;
565 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
566 Mask1stQuadrant(maskData);
570 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
571 FillCheckerboard(imageData);
573 imageData.ApplyMask(maskData, 1.0f, false);
575 // Test that the pixel format has been promoted to RGBA8888
576 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
578 // Test that a pixel in the first quadrant has no alpha value
579 unsigned char* buffer = imageData.GetBuffer();
580 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
581 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
583 // Test that an odd pixel in the second quadrant has full alpha value
584 DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
586 // Test that an even pixel in the second quadrant has no alpha value
587 DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
592 int UtcDaliPixelBufferMask07(void)
594 TestApplication application;
595 tet_infoline("Test scaling of source image to match alpha mask");
597 unsigned int width = 20u;
598 unsigned int height = 20u;
599 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
600 MaskCenterSquare(maskData);
611 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
612 AlternateQuadrants(imageData);
621 imageData.ApplyMask(maskData, 2.0f, true);
630 tet_infoline("Test that the image has been scaled to match the alpha mask");
631 DALI_TEST_EQUALS(imageData.GetWidth(), 20, TEST_LOCATION);
632 DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
634 tet_infoline("Test that pixels in the outer eighths have no alpha\n");
636 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
637 DALI_TEST_EQUALS(GetAlphaAt(imageData, 9, 4), 0x00u, TEST_LOCATION);
638 DALI_TEST_EQUALS(GetAlphaAt(imageData, 15, 4), 0x00u, TEST_LOCATION);
639 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 4), 0x00u, TEST_LOCATION);
641 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 19), 0x00u, TEST_LOCATION);
642 DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 18), 0x00u, TEST_LOCATION);
643 DALI_TEST_EQUALS(GetAlphaAt(imageData, 15, 17), 0x00u, TEST_LOCATION);
644 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 16), 0x00u, TEST_LOCATION);
646 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 1), 0x00u, TEST_LOCATION);
647 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 7), 0x00u, TEST_LOCATION);
648 DALI_TEST_EQUALS(GetAlphaAt(imageData, 2, 10), 0x00u, TEST_LOCATION);
649 DALI_TEST_EQUALS(GetAlphaAt(imageData, 3, 19), 0x00u, TEST_LOCATION);
651 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 1), 0x00u, TEST_LOCATION);
652 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 7), 0x00u, TEST_LOCATION);
653 DALI_TEST_EQUALS(GetAlphaAt(imageData, 17, 10), 0x00u, TEST_LOCATION);
654 DALI_TEST_EQUALS(GetAlphaAt(imageData, 16, 19), 0x00u, TEST_LOCATION);
656 tet_infoline("Test that pixels in the center have full alpha\n");
658 DALI_TEST_EQUALS(GetAlphaAt(imageData, 12, 8), 0xffu, TEST_LOCATION);
659 DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 12), 0xffu, TEST_LOCATION);
664 int UtcDaliPixelBufferMask08(void)
666 TestApplication application;
667 tet_infoline("Test scaling of source image to larger than the alpha mask");
669 unsigned int width = 32u;
670 unsigned int height = 20u;
671 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
672 AlternateQuadrants(maskData);
683 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
684 MaskCenterSquare(imageData);
693 imageData.ApplyMask(maskData, 4.0f, true);
695 // +-----XXXXX+ quadrant
702 tet_infoline("Test that the image has been scaled and cropped to match the alpha mask");
703 DALI_TEST_EQUALS(imageData.GetWidth(), 32, TEST_LOCATION);
704 DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
706 tet_infoline("Test that the image has been resized (the center square should now fill the image)\n");
707 tet_infoline("Test that the first quadrant has no alpha");
708 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
709 DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION);
710 DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION);
711 DALI_TEST_EQUALS(GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION);
713 tet_infoline("Test that the second quadrant has alpha and data");
714 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION);
715 DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION);
716 DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION);
717 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION);
719 tet_infoline("Test that the third quadrant has no alpha");
720 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION);
721 DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION);
722 DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION);
723 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION);
725 tet_infoline("Test that the fourth quadrant has alpha and data");
726 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION);
727 DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION);
728 DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION);
729 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION);
734 int UtcDaliPixelBufferMask09(void)
736 TestApplication application;
737 tet_infoline("Test scaling of large source image to larger than the alpha mask");
739 unsigned int width = 32u;
740 unsigned int height = 20u;
741 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
742 AlternateQuadrants(maskData);
753 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
754 MaskCenterSquare(imageData);
763 imageData.ApplyMask(maskData, 1.6f, true);
765 // +-----XXXXX+ quadrant
772 tet_infoline("Test that the image has been scaled and cropped to match the alpha mask");
773 DALI_TEST_EQUALS(imageData.GetWidth(), 32, TEST_LOCATION);
774 DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
776 tet_infoline("Test that the image has been resized (the center square should now fill the image)\n");
777 tet_infoline("Test that the first quadrant has no alpha");
778 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
779 DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION);
780 DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION);
781 DALI_TEST_EQUALS(GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION);
783 tet_infoline("Test that the second quadrant has alpha and data");
784 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION);
785 DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION);
786 DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION);
787 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION);
789 tet_infoline("Test that the third quadrant has no alpha");
790 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION);
791 DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION);
792 DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION);
793 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION);
795 tet_infoline("Test that the fourth quadrant has alpha and data");
796 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION);
797 DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION);
798 DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION);
799 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION);
804 int UtcDaliPixelBufferGaussianBlur(void)
806 TestApplication application;
808 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
809 FillCheckerboard(imageData);
811 DALI_TEST_EQUALS(imageData.GetWidth(), 10, TEST_LOCATION);
812 DALI_TEST_EQUALS(imageData.GetHeight(), 10, TEST_LOCATION);
814 unsigned char* buffer = imageData.GetBuffer();
816 // Test that an even pixel in the odd row has full alpha value
817 DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
819 // Test that an even pixel in the even row has no alpha value
820 DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
822 imageData.ApplyGaussianBlur(0.0f);
824 // Test that the pixels' alpha values are not changed because there is no blur
825 DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
826 DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
828 imageData.ApplyGaussianBlur(1.0f);
830 // Test that the pixels' alpha values are changed after applying gaussian blur
831 DALI_TEST_EQUALS(buffer[43], 0x7Au, TEST_LOCATION);
832 DALI_TEST_EQUALS(buffer[55], 0x7Eu, TEST_LOCATION);