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/devel-api/adaptor-framework/image-loading.h>
28 #include <dali/internal/imaging/common/pixel-manipulation.h>
31 using namespace Dali::Internal::Adaptor;
35 // resolution: 96*96, pixel format: LA88
36 const char* TEST_IMAGE_LA88 = TEST_IMAGE_DIR "/circle1-LA88.png";
40 void utc_dali_internal_pixel_data_startup()
42 test_return_value = TET_UNDEF;
45 void utc_dali_internal_pixel_data_cleanup()
47 test_return_value = TET_PASS;
50 const char* ChannelToString(Dali::Internal::Adaptor::Channel channel)
69 const char* FormatToString(Dali::Pixel::Format format)
77 case Dali::Pixel::LA88:
79 case Dali::Pixel::RGB565:
81 case Dali::Pixel::BGR565:
83 case Dali::Pixel::RGBA4444:
85 case Dali::Pixel::BGRA4444:
87 case Dali::Pixel::RGBA5551:
89 case Dali::Pixel::BGRA5551:
92 case Dali::Pixel::RGB888:
94 case Dali::Pixel::RGBA8888:
96 case Dali::Pixel::BGRA8888:
104 int UtcDaliPixelManipulation01(void)
106 tet_infoline("Testing Dali::Internal::AdaptorManipulation HasChannel");
108 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::A8, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
109 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::A8, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
111 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::L8, Dali::Internal::Adaptor::LUMINANCE), true, TEST_LOCATION);
112 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::L8, Dali::Internal::Adaptor::ALPHA), false, TEST_LOCATION);
114 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE), true, TEST_LOCATION);
115 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
116 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::RED), false, TEST_LOCATION);
118 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::RED), true, TEST_LOCATION);
119 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::GREEN), true, TEST_LOCATION);
120 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::BLUE), true, TEST_LOCATION);
121 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
123 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::RED), true, TEST_LOCATION);
124 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::GREEN), true, TEST_LOCATION);
125 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::BLUE), true, TEST_LOCATION);
126 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
127 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
129 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR, Dali::Internal::Adaptor::BLUE), false, TEST_LOCATION);
134 int UtcDaliPixelManipulation02(void)
136 tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
138 unsigned char pixel[4] = {0, 0, 0, 0};
140 for(int formatIdx = 1; formatIdx < Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
147 for(int channelIdx = 0; channelIdx < Dali::Internal::Adaptor::MAX_NUMBER_OF_CHANNELS; ++channelIdx)
149 Dali::Pixel::Format format = static_cast<Dali::Pixel::Format>(formatIdx);
150 Dali::Internal::Adaptor::Channel channel = static_cast<Dali::Internal::Adaptor::Channel>(channelIdx);
151 if(Dali::Internal::Adaptor::HasChannel(format, channel))
153 Dali::Internal::Adaptor::WriteChannel(&pixel[0], format, channel, 0x15);
154 unsigned int value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], format, channel);
156 tet_printf("Testing writing and reading to %s channel in %s format:\n",
157 ChannelToString(channel),
158 FormatToString(format));
160 if(channel == Dali::Internal::Adaptor::ALPHA && (format == Dali::Pixel::RGBA5551 || format == Dali::Pixel::BGRA5551))
162 DALI_TEST_EQUALS(value, 0x1, TEST_LOCATION);
164 else if(format == Dali::Pixel::RGBA4444 || format == Dali::Pixel::BGRA4444)
166 DALI_TEST_EQUALS(value, 0x05, TEST_LOCATION);
170 DALI_TEST_EQUALS(value, 0x15, TEST_LOCATION);
179 int UtcDaliPixelManipulationLA88(void)
181 tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel - LA88 format");
183 Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile(TEST_IMAGE_LA88);
184 DALI_TEST_CHECK(pixelBuffer);
186 unsigned int width = pixelBuffer.GetWidth();
187 unsigned int height = pixelBuffer.GetHeight();
188 DALI_TEST_EQUALS(width, 96u, TEST_LOCATION);
189 DALI_TEST_EQUALS(height, 96u, TEST_LOCATION);
190 DALI_TEST_EQUALS(pixelBuffer.GetPixelFormat(), Pixel::LA88, TEST_LOCATION);
192 unsigned char* pixel = pixelBuffer.GetBuffer();
195 value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE);
196 DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
197 value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA);
198 DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
201 unsigned int stride = width * Pixel::GetBytesPerPixel(Dali::Pixel::LA88);
202 unsigned int center = height / 2 * stride + width / 2 * Pixel::GetBytesPerPixel(Dali::Pixel::LA88);
203 value = Dali::Internal::Adaptor::ReadChannel(&pixel[center], Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE);
204 DALI_TEST_EQUALS(value, 0x0, TEST_LOCATION);
205 value = Dali::Internal::Adaptor::ReadChannel(&pixel[center], Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA);
206 DALI_TEST_EQUALS(value, 0xFF, TEST_LOCATION);
211 int UtcDaliPixelManipulation03N(void)
213 tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
215 unsigned char pixel[4] = {0, 0, 0, 0};
217 for(int formatIdx = 1; formatIdx < Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
224 for(int channelIdx = 0; channelIdx < Dali::Internal::Adaptor::MAX_NUMBER_OF_CHANNELS; ++channelIdx)
226 Dali::Pixel::Format format = static_cast<Dali::Pixel::Format>(formatIdx);
227 Dali::Internal::Adaptor::Channel channel = static_cast<Dali::Internal::Adaptor::Channel>(channelIdx);
228 if(!Dali::Internal::Adaptor::HasChannel(format, channel))
230 unsigned int value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], format, channel);
232 tet_printf("Testing reading from %s channel in %s format:\n",
233 ChannelToString(channel),
234 FormatToString(format));
236 DALI_TEST_EQUALS(value, 0x00, TEST_LOCATION);