2 * Copyright (c) 2022 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 UtcDaliPixelBufferConvert(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 UtcDaliPixelBufferGetWidth(void)
299 TestApplication application;
300 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
301 FillCheckerboard(pixbuf);
303 DALI_TEST_EQUALS(pixbuf.GetWidth(), 10, TEST_LOCATION);
304 DALI_TEST_EQUALS(pixbuf.GetStride(), 10, TEST_LOCATION);
309 int UtcDaliPixelBufferGetHeight(void)
311 TestApplication application;
312 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
313 FillCheckerboard(pixbuf);
315 DALI_TEST_EQUALS(pixbuf.GetHeight(), 10, TEST_LOCATION);
320 int UtcDaliPixelBufferGetPixelFormat(void)
322 TestApplication application;
323 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
324 FillCheckerboard(pixbuf);
326 DALI_TEST_EQUALS(pixbuf.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
331 int UtcDaliPixelBufferMask01(void)
333 TestApplication application;
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);
340 Mask1stQuadrant(maskData);
344 pixelFormat = Pixel::RGBA5551;
346 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
347 FillCheckerboard(imageData);
349 imageData.ApplyMask(maskData, 1.0f, false);
351 // Test that the pixel format has been promoted to RGBA8888
352 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
359 // Test that an even pixel in the second quadrant has a full alpha value
360 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
362 // Test that an odd pixel in the second quadrant has full alpha value
363 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
368 int UtcDaliPixelBufferMask02(void)
370 TestApplication application;
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);
377 Mask1stQuadrant(maskData);
381 pixelFormat = Pixel::RGBA4444;
383 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
384 FillCheckerboard(imageData);
386 imageData.ApplyMask(maskData, 1.0f, false);
388 // Test that the pixel format has been promoted to RGBA8888
389 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
396 // Test that an even pixel in the second quadrant has no alpha value
397 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
399 // Test that an odd pixel in the second quadrant has full alpha value
400 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
405 int UtcDaliPixelBufferMask03(void)
407 TestApplication application;
408 tet_infoline("Test application of alpha mask to smaller RGB565 image");
410 unsigned int width = 20u;
411 unsigned int height = 20u;
412 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
413 Mask1stQuadrant(maskData);
417 Pixel::Format format = Pixel::RGB565;
418 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, format);
419 FillCheckerboard(imageData);
421 imageData.ApplyMask(maskData, 1.0f, false);
423 // Test that the pixel format has been promoted to RGBA8888
424 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
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);
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);
440 int UtcDaliPixelBufferMask04(void)
442 TestApplication application;
443 tet_infoline("Test application of alpha mask to larger RGBA8888 image");
445 unsigned int width = 10u;
446 unsigned int height = 10u;
447 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
448 Mask1stQuadrant(maskData);
452 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
453 FillCheckerboard(imageData);
455 imageData.ApplyMask(maskData, 1.0f, false);
457 // Test that the pixel format has been promoted to RGBA8888
458 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
465 // Test that an even pixel in the second quadrant has no alpha value
466 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
468 // Test that an odd pixel in the second quadrant has full alpha value
469 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
474 int UtcDaliPixelBufferMask05(void)
476 TestApplication application;
477 tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
479 unsigned int width = 20u;
480 unsigned int height = 20u;
481 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
482 Mask1stQuadrant(maskData);
486 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
487 FillCheckerboard(imageData);
489 imageData.ApplyMask(maskData, 1.0f, false);
491 // Test that the pixel format has been promoted to RGBA8888
492 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
499 // Test that an odd pixel in the second quadrant has full alpha value
500 DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
502 // Test that an even pixel in the second quadrant has no alpha value
503 DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
508 int UtcDaliPixelBufferMask06(void)
510 TestApplication application;
511 tet_infoline("Test application of alpha mask to same size RGBA8888 image");
513 unsigned int width = 10u;
514 unsigned int height = 10u;
515 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
516 Mask1stQuadrant(maskData);
520 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
521 FillCheckerboard(imageData);
523 imageData.ApplyMask(maskData, 1.0f, false);
525 // Test that the pixel format has been promoted to RGBA8888
526 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
533 // Test that an odd pixel in the second quadrant has full alpha value
534 DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
536 // Test that an even pixel in the second quadrant has no alpha value
537 DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
542 int UtcDaliPixelBufferMask07(void)
544 TestApplication application;
545 tet_infoline("Test scaling of source image to match alpha mask");
547 unsigned int width = 20u;
548 unsigned int height = 20u;
549 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
550 MaskCenterSquare(maskData);
561 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
562 AlternateQuadrants(imageData);
571 imageData.ApplyMask(maskData, 2.0f, true);
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);
584 tet_infoline("Test that pixels in the outer eighths have no alpha\n");
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);
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);
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);
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);
606 tet_infoline("Test that pixels in the center have full alpha\n");
608 DALI_TEST_EQUALS(GetAlphaAt(imageData, 12, 8), 0xffu, TEST_LOCATION);
609 DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 12), 0xffu, TEST_LOCATION);
614 int UtcDaliPixelBufferMask08(void)
616 TestApplication application;
617 tet_infoline("Test scaling of source image to larger than the alpha mask");
619 unsigned int width = 32u;
620 unsigned int height = 20u;
621 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
622 AlternateQuadrants(maskData);
633 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
634 MaskCenterSquare(imageData);
643 imageData.ApplyMask(maskData, 4.0f, true);
645 // +-----XXXXX+ quadrant
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);
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);
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);
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);
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);
684 int UtcDaliPixelBufferMask09(void)
686 TestApplication application;
687 tet_infoline("Test scaling of large source image to larger than the alpha mask");
689 unsigned int width = 32u;
690 unsigned int height = 20u;
691 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
692 AlternateQuadrants(maskData);
703 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
704 MaskCenterSquare(imageData);
713 imageData.ApplyMask(maskData, 1.6f, true);
715 // +-----XXXXX+ quadrant
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);
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);
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);
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);
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);
754 int UtcDaliPixelBufferGaussianBlur(void)
756 TestApplication application;
758 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
759 FillCheckerboard(imageData);
761 DALI_TEST_EQUALS(imageData.GetWidth(), 10, TEST_LOCATION);
762 DALI_TEST_EQUALS(imageData.GetHeight(), 10, TEST_LOCATION);
764 unsigned char* buffer = imageData.GetBuffer();
766 // Test that an even pixel in the odd row has full alpha value
767 DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
769 // Test that an even pixel in the even row has no alpha value
770 DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
772 imageData.ApplyGaussianBlur(0.0f);
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);
778 imageData.ApplyGaussianBlur(1.0f);
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);