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 UtcDaliPixelBufferNew01N(void)
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);
208 int UtcDaliPixelBufferConvert(void)
210 TestApplication application;
211 TestGlAbstraction& gl = application.GetGlAbstraction();
212 TraceCallStack& textureTrace = gl.GetTextureTrace();
213 textureTrace.Enable(true);
215 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
216 FillCheckerboard(pixbuf);
219 Devel::PixelBuffer pixbufPrime = pixbuf; // store a second handle to the data
221 Dali::PixelData pixelData = Devel::PixelBuffer::Convert(pixbuf);
222 DALI_TEST_CHECK(!pixbuf);
224 // check the buffer in the second handle is empty
225 DALI_TEST_CHECK(pixbufPrime.GetBuffer() == NULL);
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);
234 Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
236 TextureSet ts = TextureSet::New();
238 Geometry g = CreateQuadGeometry();
239 Shader s = Shader::New("v", "f");
240 Renderer r = Renderer::New(g, s);
242 Actor a = Actor::New();
244 a.SetProperty(Actor::Property::SIZE, Vector2(10, 10));
245 a.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
246 application.GetScene().Add(a);
248 application.SendNotification();
249 application.Render();
250 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
252 // Let secondary scope destroy pixbufPrime
258 int UtcDaliPixelBufferGetWidth(void)
260 TestApplication application;
261 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
262 FillCheckerboard(pixbuf);
264 DALI_TEST_EQUALS(pixbuf.GetWidth(), 10, TEST_LOCATION);
265 DALI_TEST_EQUALS(pixbuf.GetStride(), 10, TEST_LOCATION);
270 int UtcDaliPixelBufferGetHeight(void)
272 TestApplication application;
273 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
274 FillCheckerboard(pixbuf);
276 DALI_TEST_EQUALS(pixbuf.GetHeight(), 10, TEST_LOCATION);
281 int UtcDaliPixelBufferGetPixelFormat(void)
283 TestApplication application;
284 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
285 FillCheckerboard(pixbuf);
287 DALI_TEST_EQUALS(pixbuf.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
292 int UtcDaliPixelBufferMask01(void)
294 TestApplication application;
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);
301 Mask1stQuadrant(maskData);
305 pixelFormat = Pixel::RGBA5551;
307 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
308 FillCheckerboard(imageData);
310 imageData.ApplyMask(maskData, 1.0f, false);
312 // Test that the pixel format has been promoted to RGBA8888
313 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
320 // Test that an even pixel in the second quadrant has a full alpha value
321 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
323 // Test that an odd pixel in the second quadrant has full alpha value
324 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
329 int UtcDaliPixelBufferMask02(void)
331 TestApplication application;
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);
338 Mask1stQuadrant(maskData);
342 pixelFormat = Pixel::RGBA4444;
344 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
345 FillCheckerboard(imageData);
347 imageData.ApplyMask(maskData, 1.0f, false);
349 // Test that the pixel format has been promoted to RGBA8888
350 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
357 // Test that an even pixel in the second quadrant has no alpha value
358 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
360 // Test that an odd pixel in the second quadrant has full alpha value
361 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
366 int UtcDaliPixelBufferMask03(void)
368 TestApplication application;
369 tet_infoline("Test application of alpha mask to smaller RGB565 image");
371 unsigned int width = 20u;
372 unsigned int height = 20u;
373 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
374 Mask1stQuadrant(maskData);
378 Pixel::Format format = Pixel::RGB565;
379 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, format);
380 FillCheckerboard(imageData);
382 imageData.ApplyMask(maskData, 1.0f, false);
384 // Test that the pixel format has been promoted to RGBA8888
385 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
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);
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);
401 int UtcDaliPixelBufferMask04(void)
403 TestApplication application;
404 tet_infoline("Test application of alpha mask to larger RGBA8888 image");
406 unsigned int width = 10u;
407 unsigned int height = 10u;
408 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
409 Mask1stQuadrant(maskData);
413 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
414 FillCheckerboard(imageData);
416 imageData.ApplyMask(maskData, 1.0f, false);
418 // Test that the pixel format has been promoted to RGBA8888
419 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
426 // Test that an even pixel in the second quadrant has no alpha value
427 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
429 // Test that an odd pixel in the second quadrant has full alpha value
430 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
435 int UtcDaliPixelBufferMask05(void)
437 TestApplication application;
438 tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
440 unsigned int width = 20u;
441 unsigned int height = 20u;
442 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
443 Mask1stQuadrant(maskData);
447 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
448 FillCheckerboard(imageData);
450 imageData.ApplyMask(maskData, 1.0f, false);
452 // Test that the pixel format has been promoted to RGBA8888
453 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
460 // Test that an odd pixel in the second quadrant has full alpha value
461 DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
463 // Test that an even pixel in the second quadrant has no alpha value
464 DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
469 int UtcDaliPixelBufferMask06(void)
471 TestApplication application;
472 tet_infoline("Test application of alpha mask to same size RGBA8888 image");
474 unsigned int width = 10u;
475 unsigned int height = 10u;
476 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
477 Mask1stQuadrant(maskData);
481 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
482 FillCheckerboard(imageData);
484 imageData.ApplyMask(maskData, 1.0f, false);
486 // Test that the pixel format has been promoted to RGBA8888
487 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
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);
494 // Test that an odd pixel in the second quadrant has full alpha value
495 DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
497 // Test that an even pixel in the second quadrant has no alpha value
498 DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
503 int UtcDaliPixelBufferMask07(void)
505 TestApplication application;
506 tet_infoline("Test scaling of source image to match alpha mask");
508 unsigned int width = 20u;
509 unsigned int height = 20u;
510 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
511 MaskCenterSquare(maskData);
522 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
523 AlternateQuadrants(imageData);
532 imageData.ApplyMask(maskData, 2.0f, true);
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);
545 tet_infoline("Test that pixels in the outer eighths have no alpha\n");
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);
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);
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);
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);
567 tet_infoline("Test that pixels in the center have full alpha\n");
569 DALI_TEST_EQUALS(GetAlphaAt(imageData, 12, 8), 0xffu, TEST_LOCATION);
570 DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 12), 0xffu, TEST_LOCATION);
575 int UtcDaliPixelBufferMask08(void)
577 TestApplication application;
578 tet_infoline("Test scaling of source image to larger than the alpha mask");
580 unsigned int width = 32u;
581 unsigned int height = 20u;
582 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
583 AlternateQuadrants(maskData);
594 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
595 MaskCenterSquare(imageData);
604 imageData.ApplyMask(maskData, 4.0f, true);
606 // +-----XXXXX+ quadrant
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);
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);
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);
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);
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);
645 int UtcDaliPixelBufferMask09(void)
647 TestApplication application;
648 tet_infoline("Test scaling of large source image to larger than the alpha mask");
650 unsigned int width = 32u;
651 unsigned int height = 20u;
652 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
653 AlternateQuadrants(maskData);
664 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
665 MaskCenterSquare(imageData);
674 imageData.ApplyMask(maskData, 1.6f, true);
676 // +-----XXXXX+ quadrant
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);
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);
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);
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);
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);
715 int UtcDaliPixelBufferGaussianBlur(void)
717 TestApplication application;
719 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
720 FillCheckerboard(imageData);
722 DALI_TEST_EQUALS(imageData.GetWidth(), 10, TEST_LOCATION);
723 DALI_TEST_EQUALS(imageData.GetHeight(), 10, TEST_LOCATION);
725 unsigned char* buffer = imageData.GetBuffer();
727 // Test that an even pixel in the odd row has full alpha value
728 DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
730 // Test that an even pixel in the even row has no alpha value
731 DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
733 imageData.ApplyGaussianBlur(0.0f);
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);
739 imageData.ApplyGaussianBlur(1.0f);
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);