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.
21 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
25 // Internal headers are allowed here
27 #include <dali/internal/event/images/pixel-manipulation.h>
30 using namespace Dali::Internal::Pixel;
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::Pixel::Channel channel )
45 case LUMINANCE: return "Luminance";
46 case RED: return "Red";
47 case GREEN: return "Green";
48 case BLUE: return "Blue";
49 case ALPHA: return "Alpha";
55 const char* FormatToString( Dali::Pixel::Format format )
59 case Dali::Pixel::A8: return "A8";
60 case Dali::Pixel::L8: return "L8";
61 case Dali::Pixel::LA88: return "LA88";
62 case Dali::Pixel::RGB565: return "RGB565";
63 case Dali::Pixel::BGR565: return "BGR565";
64 case Dali::Pixel::RGBA4444: return "RGBA4444";
65 case Dali::Pixel::BGRA4444: return "BGRA4444";
66 case Dali::Pixel::RGBA5551: return "RGBA5551";
67 case Dali::Pixel::BGRA5551: return "BGRA5551";
69 case Dali::Pixel::RGB888: return "RGB888";
70 case Dali::Pixel::RGBA8888: return "RGBA8888";
71 case Dali::Pixel::BGRA8888: return "BGRA8888";
79 int UtcDaliPixelManipulation01(void)
81 tet_infoline("Testing Dali::Internal::PixelManipulation HasChannel");
83 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::A8, Dali::Internal::Pixel::ALPHA ), true, TEST_LOCATION );
84 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::A8, Dali::Internal::Pixel::LUMINANCE ), false, TEST_LOCATION );
86 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::L8, Dali::Internal::Pixel::LUMINANCE ), true, TEST_LOCATION );
87 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::L8, Dali::Internal::Pixel::ALPHA ), false, TEST_LOCATION );
89 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::LA88, Dali::Internal::Pixel::LUMINANCE ), true, TEST_LOCATION );
90 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::LA88, Dali::Internal::Pixel::ALPHA ), true, TEST_LOCATION );
91 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::LA88, Dali::Internal::Pixel::RED ), false, TEST_LOCATION );
93 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGB565, Dali::Internal::Pixel::RED ), true, TEST_LOCATION );
94 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGB565, Dali::Internal::Pixel::GREEN ), true, TEST_LOCATION );
95 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGB565, Dali::Internal::Pixel::BLUE ), true, TEST_LOCATION );
96 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGB565, Dali::Internal::Pixel::LUMINANCE ), false, TEST_LOCATION );
98 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGBA8888, Dali::Internal::Pixel::RED ), true, TEST_LOCATION );
99 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGBA8888, Dali::Internal::Pixel::GREEN ), true, TEST_LOCATION );
100 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGBA8888, Dali::Internal::Pixel::BLUE ), true, TEST_LOCATION );
101 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGBA8888, Dali::Internal::Pixel::ALPHA ), true, TEST_LOCATION );
102 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::RGBA8888, Dali::Internal::Pixel::LUMINANCE ), false, TEST_LOCATION );
104 DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR, Dali::Internal::Pixel::BLUE ), false, TEST_LOCATION );
111 int UtcDaliPixelManipulation02(void)
113 tet_infoline("Testing Dali::Internal::PixelManipulation Read/WriteChannel");
115 unsigned char pixel[4] = {0,0,0,0};
117 for( int formatIdx=1; formatIdx<Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
124 for( int channelIdx=0; channelIdx < Dali::Internal::Pixel::MAX_NUMBER_OF_CHANNELS; ++channelIdx )
126 Dali::Pixel::Format format = static_cast<Dali::Pixel::Format>(formatIdx);
127 Dali::Internal::Pixel::Channel channel = static_cast<Dali::Internal::Pixel::Channel>(channelIdx);
128 if( Dali::Internal::Pixel::HasChannel( format, channel ) )
130 Dali::Internal::Pixel::WriteChannel( &pixel[0], format, channel, 0x15);
131 unsigned int value = Dali::Internal::Pixel::ReadChannel( &pixel[0], format, channel );
133 tet_printf( "Testing writing and reading to %s channel in %s format:\n",
134 ChannelToString(channel), FormatToString(format) );
136 if( channel == Dali::Internal::Pixel::ALPHA && (format == Dali::Pixel::RGBA5551 || format == Dali::Pixel::BGRA5551 ) )
138 DALI_TEST_EQUALS( value, 0x1, TEST_LOCATION );
140 else if( format == Dali::Pixel::RGBA4444 || format == Dali::Pixel::BGRA4444 )
142 DALI_TEST_EQUALS( value, 0x05, TEST_LOCATION );
146 DALI_TEST_EQUALS( value, 0x15, TEST_LOCATION );
156 int UtcDaliPixelManipulation03N(void)
158 tet_infoline("Testing Dali::Internal::PixelManipulation Read/WriteChannel");
160 unsigned char pixel[4] = {0,0,0,0};
162 for( int formatIdx=1; formatIdx<Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
169 for( int channelIdx=0; channelIdx < Dali::Internal::Pixel::MAX_NUMBER_OF_CHANNELS; ++channelIdx )
171 Dali::Pixel::Format format = static_cast<Dali::Pixel::Format>(formatIdx);
172 Dali::Internal::Pixel::Channel channel = static_cast<Dali::Internal::Pixel::Channel>(channelIdx);
173 if( ! Dali::Internal::Pixel::HasChannel( format, channel ) )
175 unsigned int value = Dali::Internal::Pixel::ReadChannel( &pixel[0], format, channel );
177 tet_printf( "Testing reading from %s channel in %s format:\n",
178 ChannelToString(channel), FormatToString(format) );
180 DALI_TEST_EQUALS( value, 0x00, TEST_LOCATION );