Dali 3D User Interface Engine
utc-Dali-CompressedTextures.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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 // EXTERNAL INCLUDES
19 #include <iostream>
20 #include <stdlib.h>
21 #include <vector>
22 #include <dali-test-suite-utils.h>
25 
26 // INTERNAL INCLUDES
27 #include "image-loaders.h"
28 
29 using namespace Dali;
30 
31 // Pre-define loader functions for each image type being tested (as they are reused in different tests).
34 
41 {
42  public:
43 
49  {
50  }
51 
56  {
57  }
58 
63  struct TestEntry
64  {
66  std::string filename;
69 
70  TestEntry( const LoadFunctions& newLoadFunctions, std::string newFilename, int newExpectedWidth, int newExpectedHeight )
71  : loadFunctions( newLoadFunctions ),
72  filename( newFilename ),
73  expectedWidth( newExpectedWidth ),
74  expectedHeight( newExpectedHeight )
75  {
76  }
77  };
78 
79  private:
80 
81  typedef std::vector< TestEntry > TestContainer;
82 
83  public:
84 
89  void AddTest( TestEntry testEntry )
90  {
91  mTests.push_back( testEntry );
92  }
93 
98  void RunTests()
99  {
100  for( TestContainer::iterator testIterator = mTests.begin(); testIterator != mTests.end(); ++testIterator )
101  {
102  const TestEntry& currentTest = *testIterator;
103 
104  RunTest( currentTest );
105  }
106  }
107 
108  private:
109 
114  void RunTest( const TestEntry& testEntry )
115  {
116  FILE* fileDescriptor = fopen( testEntry.filename.c_str(), "rb" );
117  AutoCloseFile autoClose( fileDescriptor );
118  DALI_TEST_CHECK( fileDescriptor != NULL );
119 
120  // Check the header file.
121  unsigned int width( 0 ), height( 0 );
122  const Dali::TizenPlatform::ImageLoader::Input input( fileDescriptor );
123 
124  // Use the given loader to parse the image header.
125  DALI_TEST_CHECK( testEntry.loadFunctions.header( input, width, height ) );
126 
128  DALI_TEST_EQUALS( height, testEntry.expectedHeight, TEST_LOCATION );
129  }
130 
131  private:
132 
134 
135 };
136 
137 // KTX files (KTX is a wrapper, so can contain different compressed texture types):
138 
140 {
141  KtxTestFixture fixture;
142 
143  fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-ETC1_RGB8_OES-45x80.ktx", 45u, 80u ) );
144  fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGB8_ETC2-45x80.ktx", 45u, 80u ) );
145 
146  fixture.RunTests();
147 
148  END_TEST;
149 }
150 
152 {
153  KtxTestFixture fixture;
154 
155  fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGB_PVRTC_4BPPV1_IMG-32x64.ktx", 32u, 64u ) );
156 
157  fixture.RunTests();
158 
159  END_TEST;
160 }
161 
163 {
164  KtxTestFixture fixture;
165 
166  fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-R11_EAC-45x80.ktx", 45u, 80u ) );
167 
168  fixture.RunTests();
169 
170  END_TEST;
171 }
172 
174 {
175  KtxTestFixture fixture;
176 
177  fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGBA_ASTC_4x4_KHR-32x64.ktx", 32u, 64u ) );
178  fixture.AddTest( KtxTestFixture::TestEntry( KtxLoaders, TEST_IMAGE_DIR "/fractal-compressed-SRBG8_ALPHA8_ASTC_4x4_KHR-32x64.ktx", 32u, 64u ) );
179 
180  fixture.RunTests();
181 
182  END_TEST;
183 }
184 
185 
186 // ASTC (Native) files:
188 {
189  KtxTestFixture fixture;
190 
191  fixture.AddTest( KtxTestFixture::TestEntry( AstcLoaders, TEST_IMAGE_DIR "/fractal-compressed-RGBA_ASTC_4x4_KHR-32x64.astc", 32u, 64u ) );
192 
193  fixture.RunTests();
194 
195  END_TEST;
196 }
197 
Dali Docs Home
Read more about Dali