Removed forward declaration of (removed) FrameBufferTexture
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-PixelData.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22
23 #include <dali-test-suite-utils.h>
24
25 // Internal headers are allowed here
26
27 #include <dali/internal/event/images/pixel-manipulation.h>
28
29 using namespace Dali;
30 using namespace Dali::Internal::Pixel;
31 void utc_dali_internal_pixel_data_startup()
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_internal_pixel_data_cleanup()
37 {
38   test_return_value = TET_PASS;
39 }
40
41 const char* ChannelToString( Dali::Internal::Pixel::Channel channel )
42 {
43   switch(channel)
44   {
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";
50     default:
51       return "Unknown";
52   }
53 }
54
55 const char* FormatToString( Dali::Pixel::Format format )
56 {
57   switch(format)
58   {
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";
68
69     case Dali::Pixel::RGB888: return "RGB888";
70     case Dali::Pixel::RGBA8888: return "RGBA8888";
71     case Dali::Pixel::BGRA8888: return "BGRA8888";
72
73     default:
74       return "Unknown";
75   }
76 }
77
78
79 int UtcDaliPixelManipulation01(void)
80 {
81   tet_infoline("Testing Dali::Internal::PixelManipulation HasChannel");
82
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 );
85
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 );
88
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 );
92
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 );
97
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 );
103
104   DALI_TEST_EQUALS( Dali::Internal::Pixel::HasChannel( Dali::Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR, Dali::Internal::Pixel::BLUE ), false, TEST_LOCATION );
105
106   END_TEST;
107 }
108
109
110
111 int UtcDaliPixelManipulation02(void)
112 {
113   tet_infoline("Testing Dali::Internal::PixelManipulation Read/WriteChannel");
114
115   unsigned char pixel[4] = {0,0,0,0};
116
117   for( int formatIdx=1; formatIdx<Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
118   {
119     pixel[0] = 0xFF;
120     pixel[1] = 0xFF;
121     pixel[2] = 0xFF;
122     pixel[3] = 0xFF;
123
124     for( int channelIdx=0; channelIdx < Dali::Internal::Pixel::MAX_NUMBER_OF_CHANNELS; ++channelIdx )
125     {
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 ) )
129       {
130         Dali::Internal::Pixel::WriteChannel( &pixel[0], format, channel, 0x15);
131         unsigned int value = Dali::Internal::Pixel::ReadChannel( &pixel[0], format, channel );
132
133         tet_printf( "Testing writing and reading to %s channel in %s format:\n",
134                       ChannelToString(channel), FormatToString(format) );
135
136         if( channel == Dali::Internal::Pixel::ALPHA && (format == Dali::Pixel::RGBA5551 || format == Dali::Pixel::BGRA5551 ) )
137         {
138           DALI_TEST_EQUALS( value, 0x1, TEST_LOCATION );
139         }
140         else if( format == Dali::Pixel::RGBA4444 || format == Dali::Pixel::BGRA4444 )
141         {
142           DALI_TEST_EQUALS( value, 0x05, TEST_LOCATION );
143         }
144         else
145         {
146           DALI_TEST_EQUALS( value, 0x15, TEST_LOCATION );
147         }
148       }
149     }
150   }
151
152   END_TEST;
153 }
154
155
156 int UtcDaliPixelManipulation03N(void)
157 {
158   tet_infoline("Testing Dali::Internal::PixelManipulation Read/WriteChannel");
159
160   unsigned char pixel[4] = {0,0,0,0};
161
162   for( int formatIdx=1; formatIdx<Dali::Pixel::COMPRESSED_R11_EAC; ++formatIdx)
163   {
164     pixel[0] = 0xFF;
165     pixel[1] = 0xFF;
166     pixel[2] = 0xFF;
167     pixel[3] = 0xFF;
168
169     for( int channelIdx=0; channelIdx < Dali::Internal::Pixel::MAX_NUMBER_OF_CHANNELS; ++channelIdx )
170     {
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 ) )
174       {
175         unsigned int value = Dali::Internal::Pixel::ReadChannel( &pixel[0], format, channel );
176
177         tet_printf( "Testing reading from %s channel in %s format:\n",
178                       ChannelToString(channel), FormatToString(format) );
179
180         DALI_TEST_EQUALS( value, 0x00, TEST_LOCATION );
181       }
182     }
183   }
184
185   END_TEST;
186 }