2 * Copyright (c) 2020 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.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
233 Texture t = Texture::New(TextureType::TEXTURE_2D, Pixel::RGB565, 10, 10);
235 TextureSet ts = TextureSet::New();
237 Geometry g = CreateQuadGeometry();
238 Shader s = Shader::New("v", "f");
239 Renderer r = Renderer::New(g, s);
241 Actor a = Actor::New();
243 a.SetProperty(Actor::Property::SIZE, Vector2(10, 10));
244 a.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
245 application.GetScene().Add(a);
247 application.SendNotification();
248 application.Render();
249 DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
251 // Let secondary scope destroy pixbufPrime
257 int UtcDaliPixelBufferGetWidth(void)
259 TestApplication application;
260 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
261 FillCheckerboard(pixbuf);
263 DALI_TEST_EQUALS(pixbuf.GetWidth(), 10, TEST_LOCATION);
268 int UtcDaliPixelBufferGetHeight(void)
270 TestApplication application;
271 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
272 FillCheckerboard(pixbuf);
274 DALI_TEST_EQUALS(pixbuf.GetHeight(), 10, TEST_LOCATION);
279 int UtcDaliPixelBufferGetPixelFormat(void)
281 TestApplication application;
282 Devel::PixelBuffer pixbuf = Devel::PixelBuffer::New(10, 10, Pixel::RGB565);
283 FillCheckerboard(pixbuf);
285 DALI_TEST_EQUALS(pixbuf.GetPixelFormat(), Pixel::RGB565, TEST_LOCATION);
290 int UtcDaliPixelBufferMask01(void)
292 TestApplication application;
294 unsigned int width = 10u;
295 unsigned int height = 10u;
296 Pixel::Format pixelFormat = Pixel::L8;
297 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, pixelFormat);
299 Mask1stQuadrant(maskData);
303 pixelFormat = Pixel::RGBA5551;
305 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
306 FillCheckerboard(imageData);
308 imageData.ApplyMask(maskData, 1.0f, false);
310 // Test that the pixel format has been promoted to RGBA8888
311 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
313 // Test that a pixel in the first quadrant has no alpha value
314 unsigned char* buffer = imageData.GetBuffer();
315 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
316 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
318 // Test that an even pixel in the second quadrant has a full alpha value
319 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
321 // Test that an odd pixel in the second quadrant has full alpha value
322 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
327 int UtcDaliPixelBufferMask02(void)
329 TestApplication application;
331 unsigned int width = 10u;
332 unsigned int height = 10u;
333 Pixel::Format pixelFormat = Pixel::L8;
334 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, pixelFormat);
336 Mask1stQuadrant(maskData);
340 pixelFormat = Pixel::RGBA4444;
342 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, pixelFormat);
343 FillCheckerboard(imageData);
345 imageData.ApplyMask(maskData, 1.0f, false);
347 // Test that the pixel format has been promoted to RGBA8888
348 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
350 // Test that a pixel in the first quadrant has no alpha value
351 unsigned char* buffer = imageData.GetBuffer();
352 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
353 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
355 // Test that an even pixel in the second quadrant has no alpha value
356 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
358 // Test that an odd pixel in the second quadrant has full alpha value
359 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
364 int UtcDaliPixelBufferMask03(void)
366 TestApplication application;
367 tet_infoline("Test application of alpha mask to smaller RGB565 image");
369 unsigned int width = 20u;
370 unsigned int height = 20u;
371 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
372 Mask1stQuadrant(maskData);
376 Pixel::Format format = Pixel::RGB565;
377 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, format);
378 FillCheckerboard(imageData);
380 imageData.ApplyMask(maskData, 1.0f, false);
382 // Test that the pixel format has been promoted to RGBA8888
383 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
385 // Test that a pixel in the first quadrant has no alpha value
386 unsigned char* buffer = imageData.GetBuffer();
387 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
388 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
390 // Test that an odd pixel in the fourth quadrant has full alpha value
391 DALI_TEST_EQUALS(buffer[(6 * 10 + 7) * 4 + 3], 0xffu, TEST_LOCATION);
393 // Test that an even pixel in the fourth quadrant has full alpha value
394 DALI_TEST_EQUALS(buffer[(6 * 10 + 8) * 4 + 3], 0xffu, TEST_LOCATION);
399 int UtcDaliPixelBufferMask04(void)
401 TestApplication application;
402 tet_infoline("Test application of alpha mask to larger RGBA8888 image");
404 unsigned int width = 10u;
405 unsigned int height = 10u;
406 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::L8);
407 Mask1stQuadrant(maskData);
411 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
412 FillCheckerboard(imageData);
414 imageData.ApplyMask(maskData, 1.0f, false);
416 // Test that the pixel format has been promoted to RGBA8888
417 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
419 // Test that a pixel in the first quadrant has no alpha value
420 unsigned char* buffer = imageData.GetBuffer();
421 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
422 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
424 // Test that an even pixel in the second quadrant has no alpha value
425 DALI_TEST_EQUALS(buffer[43], 0x00u, TEST_LOCATION);
427 // Test that an odd pixel in the second quadrant has full alpha value
428 DALI_TEST_EQUALS(buffer[47], 0xffu, TEST_LOCATION);
433 int UtcDaliPixelBufferMask05(void)
435 TestApplication application;
436 tet_infoline("Test application of alpha mask to smaller RGBA8888 image");
438 unsigned int width = 20u;
439 unsigned int height = 20u;
440 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
441 Mask1stQuadrant(maskData);
445 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
446 FillCheckerboard(imageData);
448 imageData.ApplyMask(maskData, 1.0f, false);
450 // Test that the pixel format has been promoted to RGBA8888
451 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
453 // Test that a pixel in the first quadrant has no alpha value
454 unsigned char* buffer = imageData.GetBuffer();
455 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
456 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
458 // Test that an odd pixel in the second quadrant has full alpha value
459 DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
461 // Test that an even pixel in the second quadrant has no alpha value
462 DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
467 int UtcDaliPixelBufferMask06(void)
469 TestApplication application;
470 tet_infoline("Test application of alpha mask to same size RGBA8888 image");
472 unsigned int width = 10u;
473 unsigned int height = 10u;
474 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
475 Mask1stQuadrant(maskData);
479 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
480 FillCheckerboard(imageData);
482 imageData.ApplyMask(maskData, 1.0f, false);
484 // Test that the pixel format has been promoted to RGBA8888
485 DALI_TEST_EQUALS(imageData.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
487 // Test that a pixel in the first quadrant has no alpha value
488 unsigned char* buffer = imageData.GetBuffer();
489 DALI_TEST_EQUALS(buffer[3], 0x00u, TEST_LOCATION);
490 DALI_TEST_EQUALS(buffer[7], 0x00u, TEST_LOCATION);
492 // Test that an odd pixel in the second quadrant has full alpha value
493 DALI_TEST_EQUALS(buffer[39], 0xffu, TEST_LOCATION);
495 // Test that an even pixel in the second quadrant has no alpha value
496 DALI_TEST_EQUALS(buffer[27], 0x00u, TEST_LOCATION);
501 int UtcDaliPixelBufferMask07(void)
503 TestApplication application;
504 tet_infoline("Test scaling of source image to match alpha mask");
506 unsigned int width = 20u;
507 unsigned int height = 20u;
508 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
509 MaskCenterSquare(maskData);
520 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
521 AlternateQuadrants(imageData);
530 imageData.ApplyMask(maskData, 2.0f, true);
539 tet_infoline("Test that the image has been scaled to match the alpha mask");
540 DALI_TEST_EQUALS(imageData.GetWidth(), 20, TEST_LOCATION);
541 DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
543 tet_infoline("Test that pixels in the outer eighths have no alpha\n");
545 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
546 DALI_TEST_EQUALS(GetAlphaAt(imageData, 9, 4), 0x00u, TEST_LOCATION);
547 DALI_TEST_EQUALS(GetAlphaAt(imageData, 15, 4), 0x00u, TEST_LOCATION);
548 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 4), 0x00u, TEST_LOCATION);
550 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 19), 0x00u, TEST_LOCATION);
551 DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 18), 0x00u, TEST_LOCATION);
552 DALI_TEST_EQUALS(GetAlphaAt(imageData, 15, 17), 0x00u, TEST_LOCATION);
553 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 16), 0x00u, TEST_LOCATION);
555 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 1), 0x00u, TEST_LOCATION);
556 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 7), 0x00u, TEST_LOCATION);
557 DALI_TEST_EQUALS(GetAlphaAt(imageData, 2, 10), 0x00u, TEST_LOCATION);
558 DALI_TEST_EQUALS(GetAlphaAt(imageData, 3, 19), 0x00u, TEST_LOCATION);
560 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 1), 0x00u, TEST_LOCATION);
561 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 7), 0x00u, TEST_LOCATION);
562 DALI_TEST_EQUALS(GetAlphaAt(imageData, 17, 10), 0x00u, TEST_LOCATION);
563 DALI_TEST_EQUALS(GetAlphaAt(imageData, 16, 19), 0x00u, TEST_LOCATION);
565 tet_infoline("Test that pixels in the center have full alpha\n");
567 DALI_TEST_EQUALS(GetAlphaAt(imageData, 12, 8), 0xffu, TEST_LOCATION);
568 DALI_TEST_EQUALS(GetAlphaAt(imageData, 8, 12), 0xffu, TEST_LOCATION);
573 int UtcDaliPixelBufferMask08(void)
575 TestApplication application;
576 tet_infoline("Test scaling of source image to larger than the alpha mask");
578 unsigned int width = 32u;
579 unsigned int height = 20u;
580 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
581 AlternateQuadrants(maskData);
592 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
593 MaskCenterSquare(imageData);
602 imageData.ApplyMask(maskData, 4.0f, true);
604 // +-----XXXXX+ quadrant
611 tet_infoline("Test that the image has been scaled and cropped to match the alpha mask");
612 DALI_TEST_EQUALS(imageData.GetWidth(), 32, TEST_LOCATION);
613 DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
615 tet_infoline("Test that the image has been resized (the center square should now fill the image)\n");
616 tet_infoline("Test that the first quadrant has no alpha");
617 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
618 DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION);
619 DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION);
620 DALI_TEST_EQUALS(GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION);
622 tet_infoline("Test that the second quadrant has alpha and data");
623 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION);
624 DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION);
625 DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION);
626 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION);
628 tet_infoline("Test that the third quadrant has no alpha");
629 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION);
630 DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION);
631 DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION);
632 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION);
634 tet_infoline("Test that the fourth quadrant has alpha and data");
635 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION);
636 DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION);
637 DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION);
638 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION);
643 int UtcDaliPixelBufferMask09(void)
645 TestApplication application;
646 tet_infoline("Test scaling of large source image to larger than the alpha mask");
648 unsigned int width = 32u;
649 unsigned int height = 20u;
650 Devel::PixelBuffer maskData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
651 AlternateQuadrants(maskData);
662 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(width, height, Pixel::RGBA8888);
663 MaskCenterSquare(imageData);
672 imageData.ApplyMask(maskData, 1.6f, true);
674 // +-----XXXXX+ quadrant
681 tet_infoline("Test that the image has been scaled and cropped to match the alpha mask");
682 DALI_TEST_EQUALS(imageData.GetWidth(), 32, TEST_LOCATION);
683 DALI_TEST_EQUALS(imageData.GetHeight(), 20, TEST_LOCATION);
685 tet_infoline("Test that the image has been resized (the center square should now fill the image)\n");
686 tet_infoline("Test that the first quadrant has no alpha");
687 DALI_TEST_EQUALS(GetAlphaAt(imageData, 0, 0), 0x00u, TEST_LOCATION);
688 DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 4), 0x00u, TEST_LOCATION);
689 DALI_TEST_EQUALS(GetAlphaAt(imageData, 5, 8), 0x00u, TEST_LOCATION);
690 DALI_TEST_EQUALS(GetAlphaAt(imageData, 14, 8), 0x00u, TEST_LOCATION);
692 tet_infoline("Test that the second quadrant has alpha and data");
693 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 0), 0xffu, TEST_LOCATION);
694 DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 1), 0xffu, TEST_LOCATION);
695 DALI_TEST_EQUALS(GetAlphaAt(imageData, 30, 8), 0xffu, TEST_LOCATION);
696 DALI_TEST_EQUALS(GetAlphaAt(imageData, 19, 8), 0xffu, TEST_LOCATION);
698 tet_infoline("Test that the third quadrant has no alpha");
699 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 12), 0x00u, TEST_LOCATION);
700 DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 12), 0x00u, TEST_LOCATION);
701 DALI_TEST_EQUALS(GetAlphaAt(imageData, 31, 19), 0x00u, TEST_LOCATION);
702 DALI_TEST_EQUALS(GetAlphaAt(imageData, 18, 19), 0x00u, TEST_LOCATION);
704 tet_infoline("Test that the fourth quadrant has alpha and data");
705 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 12), 0xffu, TEST_LOCATION);
706 DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 12), 0xffu, TEST_LOCATION);
707 DALI_TEST_EQUALS(GetAlphaAt(imageData, 7, 19), 0xffu, TEST_LOCATION);
708 DALI_TEST_EQUALS(GetAlphaAt(imageData, 1, 19), 0xffu, TEST_LOCATION);
713 int UtcDaliPixelBufferGaussianBlur(void)
715 TestApplication application;
717 Devel::PixelBuffer imageData = Devel::PixelBuffer::New(10, 10, Pixel::RGBA8888);
718 FillCheckerboard(imageData);
720 DALI_TEST_EQUALS(imageData.GetWidth(), 10, TEST_LOCATION);
721 DALI_TEST_EQUALS(imageData.GetHeight(), 10, TEST_LOCATION);
723 unsigned char* buffer = imageData.GetBuffer();
725 // Test that an even pixel in the odd row has full alpha value
726 DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
728 // Test that an even pixel in the even row has no alpha value
729 DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
731 imageData.ApplyGaussianBlur(0.0f);
733 // Test that the pixels' alpha values are not changed because there is no blur
734 DALI_TEST_EQUALS(buffer[43], 0xffu, TEST_LOCATION);
735 DALI_TEST_EQUALS(buffer[55], 0x00u, TEST_LOCATION);
737 imageData.ApplyGaussianBlur(1.0f);
739 // Test that the pixels' alpha values are changed after applying gaussian blur
740 DALI_TEST_EQUALS(buffer[43], 0x7Au, TEST_LOCATION);
741 DALI_TEST_EQUALS(buffer[55], 0x7Eu, TEST_LOCATION);