2 * Copyright (c) 2014 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.
20 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
25 // Internal headers are allowed here
27 #include <dali/internal/imaging/common/pixel-manipulation.h>
28 #include <dali/devel-api/adaptor-framework/image-loading.h>
31 using namespace Dali::Internal::Adaptor;
36 // resolution: 96*96, pixel format: LA88
37 const char* TEST_IMAGE_LA88 = TEST_IMAGE_DIR "/circle1-LA88.png";
41 void utc_dali_internal_pixel_data_startup()
43 test_return_value = TET_UNDEF;
46 void utc_dali_internal_pixel_data_cleanup()
48 test_return_value = TET_PASS;
51 const char* ChannelToString(Dali::Internal::Adaptor::Channel channel)
70 const char* FormatToString(Dali::Pixel::Format format)
78 case Dali::Pixel::LA88:
80 case Dali::Pixel::RGB565:
82 case Dali::Pixel::BGR565:
84 case Dali::Pixel::RGBA4444:
86 case Dali::Pixel::BGRA4444:
88 case Dali::Pixel::RGBA5551:
90 case Dali::Pixel::BGRA5551:
93 case Dali::Pixel::RGB888:
95 case Dali::Pixel::RGBA8888:
97 case Dali::Pixel::BGRA8888:
105 int UtcDaliPixelManipulation01(void)
107 tet_infoline("Testing Dali::Internal::AdaptorManipulation HasChannel");
109 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::A8, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
110 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::A8, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
112 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::L8, Dali::Internal::Adaptor::LUMINANCE), true, TEST_LOCATION);
113 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::L8, Dali::Internal::Adaptor::ALPHA), false, TEST_LOCATION);
115 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE), true, TEST_LOCATION);
116 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
117 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::RED), false, TEST_LOCATION);
119 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::RED), true, TEST_LOCATION);
120 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::GREEN), true, TEST_LOCATION);
121 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::BLUE), true, TEST_LOCATION);
122 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
124 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::RED), true, TEST_LOCATION);
125 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::GREEN), true, TEST_LOCATION);
126 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::BLUE), true, TEST_LOCATION);
127 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
128 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
130 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR, Dali::Internal::Adaptor::BLUE), false, TEST_LOCATION);
135 int UtcDaliPixelManipulation02(void)
137 tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
139 unsigned char pixel[4] = {0, 0, 0, 0};
141 for(int formatIdx = 1; formatIdx < Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
148 for(int channelIdx = 0; channelIdx < Dali::Internal::Adaptor::MAX_NUMBER_OF_CHANNELS; ++channelIdx)
150 Dali::Pixel::Format format = static_cast<Dali::Pixel::Format>(formatIdx);
151 Dali::Internal::Adaptor::Channel channel = static_cast<Dali::Internal::Adaptor::Channel>(channelIdx);
152 if(Dali::Internal::Adaptor::HasChannel(format, channel))
154 Dali::Internal::Adaptor::WriteChannel(&pixel[0], format, channel, 0x15);
155 unsigned int value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], format, channel);
157 tet_printf("Testing writing and reading to %s channel in %s format:\n",
158 ChannelToString(channel),
159 FormatToString(format));
161 if(channel == Dali::Internal::Adaptor::ALPHA && (format == Dali::Pixel::RGBA5551 || format == Dali::Pixel::BGRA5551))
163 DALI_TEST_EQUALS(value, 0x1, TEST_LOCATION);
165 else if(format == Dali::Pixel::RGBA4444 || format == Dali::Pixel::BGRA4444)
167 DALI_TEST_EQUALS(value, 0x05, TEST_LOCATION);
171 DALI_TEST_EQUALS(value, 0x15, TEST_LOCATION);
180 int UtcDaliPixelManipulationLA88(void)
182 tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel - LA88 format");
184 Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile(TEST_IMAGE_LA88);
185 DALI_TEST_CHECK(pixelBuffer);
187 unsigned int width = pixelBuffer.GetWidth();
188 unsigned int height = pixelBuffer.GetHeight();
189 DALI_TEST_EQUALS(width, 96u, TEST_LOCATION);
190 DALI_TEST_EQUALS(height, 96u, TEST_LOCATION);
191 DALI_TEST_EQUALS(pixelBuffer.GetPixelFormat(), Pixel::LA88, TEST_LOCATION);
193 unsigned char* pixel = pixelBuffer.GetBuffer();
196 value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE);
197 DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
198 value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA);
199 DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
202 unsigned int stride = width * Pixel::GetBytesPerPixel(Dali::Pixel::LA88);
203 unsigned int center = height / 2 * stride + width / 2 * Pixel::GetBytesPerPixel(Dali::Pixel::LA88);
204 value = Dali::Internal::Adaptor::ReadChannel(&pixel[center], Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE);
205 DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
206 value = Dali::Internal::Adaptor::ReadChannel(&pixel[center], Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA);
207 DALI_TEST_EQUALS(value, 0xFF, TEST_LOCATION);
212 int UtcDaliPixelManipulation03N(void)
214 tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
216 unsigned char pixel[4] = {0, 0, 0, 0};
218 for(int formatIdx = 1; formatIdx < Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
225 for(int channelIdx = 0; channelIdx < Dali::Internal::Adaptor::MAX_NUMBER_OF_CHANNELS; ++channelIdx)
227 Dali::Pixel::Format format = static_cast<Dali::Pixel::Format>(formatIdx);
228 Dali::Internal::Adaptor::Channel channel = static_cast<Dali::Internal::Adaptor::Channel>(channelIdx);
229 if(!Dali::Internal::Adaptor::HasChannel(format, channel))
231 unsigned int value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], format, channel);
233 tet_printf("Testing reading from %s channel in %s format:\n",
234 ChannelToString(channel),
235 FormatToString(format));
237 DALI_TEST_EQUALS(value, 0x00, TEST_LOCATION);