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>
30 using namespace Dali::Internal::Adaptor;
31 void utc_dali_internal_pixel_data_startup()
33 test_return_value = TET_UNDEF;
36 void utc_dali_internal_pixel_data_cleanup()
38 test_return_value = TET_PASS;
41 const char* ChannelToString(Dali::Internal::Adaptor::Channel channel)
60 const char* FormatToString(Dali::Pixel::Format format)
68 case Dali::Pixel::LA88:
70 case Dali::Pixel::RGB565:
72 case Dali::Pixel::BGR565:
74 case Dali::Pixel::RGBA4444:
76 case Dali::Pixel::BGRA4444:
78 case Dali::Pixel::RGBA5551:
80 case Dali::Pixel::BGRA5551:
83 case Dali::Pixel::RGB888:
85 case Dali::Pixel::RGBA8888:
87 case Dali::Pixel::BGRA8888:
95 int UtcDaliPixelManipulation01(void)
97 tet_infoline("Testing Dali::Internal::AdaptorManipulation HasChannel");
99 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::A8, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
100 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::A8, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
102 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::L8, Dali::Internal::Adaptor::LUMINANCE), true, TEST_LOCATION);
103 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::L8, Dali::Internal::Adaptor::ALPHA), false, TEST_LOCATION);
105 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::LUMINANCE), true, TEST_LOCATION);
106 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
107 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::LA88, Dali::Internal::Adaptor::RED), false, TEST_LOCATION);
109 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::RED), true, TEST_LOCATION);
110 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::GREEN), true, TEST_LOCATION);
111 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::BLUE), true, TEST_LOCATION);
112 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGB565, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
114 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::RED), true, TEST_LOCATION);
115 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::GREEN), true, TEST_LOCATION);
116 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::BLUE), true, TEST_LOCATION);
117 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::ALPHA), true, TEST_LOCATION);
118 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::RGBA8888, Dali::Internal::Adaptor::LUMINANCE), false, TEST_LOCATION);
120 DALI_TEST_EQUALS(Dali::Internal::Adaptor::HasChannel(Dali::Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR, Dali::Internal::Adaptor::BLUE), false, TEST_LOCATION);
125 int UtcDaliPixelManipulation02(void)
127 tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
129 unsigned char pixel[4] = {0, 0, 0, 0};
131 for(int formatIdx = 1; formatIdx < Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
138 for(int channelIdx = 0; channelIdx < Dali::Internal::Adaptor::MAX_NUMBER_OF_CHANNELS; ++channelIdx)
140 Dali::Pixel::Format format = static_cast<Dali::Pixel::Format>(formatIdx);
141 Dali::Internal::Adaptor::Channel channel = static_cast<Dali::Internal::Adaptor::Channel>(channelIdx);
142 if(Dali::Internal::Adaptor::HasChannel(format, channel))
144 Dali::Internal::Adaptor::WriteChannel(&pixel[0], format, channel, 0x15);
145 unsigned int value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], format, channel);
147 tet_printf("Testing writing and reading to %s channel in %s format:\n",
148 ChannelToString(channel),
149 FormatToString(format));
151 if(channel == Dali::Internal::Adaptor::ALPHA && (format == Dali::Pixel::RGBA5551 || format == Dali::Pixel::BGRA5551))
153 DALI_TEST_EQUALS(value, 0x1, TEST_LOCATION);
155 else if(format == Dali::Pixel::RGBA4444 || format == Dali::Pixel::BGRA4444)
157 DALI_TEST_EQUALS(value, 0x05, TEST_LOCATION);
161 DALI_TEST_EQUALS(value, 0x15, TEST_LOCATION);
170 int UtcDaliPixelManipulation03N(void)
172 tet_infoline("Testing Dali::Internal::AdaptorManipulation Read/WriteChannel");
174 unsigned char pixel[4] = {0, 0, 0, 0};
176 for(int formatIdx = 1; formatIdx < Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
183 for(int channelIdx = 0; channelIdx < Dali::Internal::Adaptor::MAX_NUMBER_OF_CHANNELS; ++channelIdx)
185 Dali::Pixel::Format format = static_cast<Dali::Pixel::Format>(formatIdx);
186 Dali::Internal::Adaptor::Channel channel = static_cast<Dali::Internal::Adaptor::Channel>(channelIdx);
187 if(!Dali::Internal::Adaptor::HasChannel(format, channel))
189 unsigned int value = Dali::Internal::Adaptor::ReadChannel(&pixel[0], format, channel);
191 tet_printf("Testing reading from %s channel in %s format:\n",
192 ChannelToString(channel),
193 FormatToString(format));
195 DALI_TEST_EQUALS(value, 0x00, TEST_LOCATION);