Skip to content

Commit

Permalink
Add thirdparty library etcpak.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed May 4, 2019
1 parent 84401e8 commit 61e2c93
Show file tree
Hide file tree
Showing 51 changed files with 7,680 additions and 0 deletions.
5 changes: 5 additions & 0 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ Comment: Etc2Comp
Copyright: 2015, Etc2Comp Authors
License: Apache-2.0

Files: ./thirdparty/etcpak/
Comment: etcpak
Copyright: 2013, Bartosz Taudul <[email protected]>
License: BSD-3-clause

Files: ./thirdparty/fonts/DroidSans*.ttf
Comment: DroidSans font
Copyright: 2008, The Android Open Source Project
Expand Down
9 changes: 9 additions & 0 deletions thirdparty/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ They are marked with `// -- GODOT start --` and `// -- GODOT end --`
comments.


## etcpak

- Upstream: https://bitbucket.org/wolfpld/etcpak/src
- Version: git (1f69f20, 2018)
- License: BSD-3 license

Imporant: Some Godot-made changes.


## fonts

### Noto Sans
Expand Down
8 changes: 8 additions & 0 deletions thirdparty/etcpak/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build/Debug
build/Release
build/x64
build/*sdf
build/*.suo
build/*.vcxproj.user
*.o
*.d
2 changes: 2 additions & 0 deletions thirdparty/etcpak/AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bartosz Taudul <[email protected]>
Daniel Jungmann <[email protected]>
282 changes: 282 additions & 0 deletions thirdparty/etcpak/Application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
#include <future>
#include <stdio.h>
#include <limits>
#include <math.h>
#include <memory>
#include <string.h>

#include "Bitmap.hpp"
#include "BlockData.hpp"
#include "CpuArch.hpp"
#include "DataProvider.hpp"
#include "Debug.hpp"
#include "Dither.hpp"
#include "Error.hpp"
#include "System.hpp"
#include "TaskDispatch.hpp"
#include "Timing.hpp"

struct DebugCallback_t : public DebugLog::Callback
{
void OnDebugMessage( const char* msg ) override
{
fprintf( stderr, "%s\n", msg );
}
} DebugCallback;

void Usage()
{
fprintf( stderr, "Usage: etcpak input.png [options]\n" );
#ifdef __SSE4_1__
if( can_use_intel_core_4th_gen_features() )
{
fprintf( stderr, " Using AVX 2 instructions.\n" );
}
else
{
fprintf( stderr, " Using SSE 4.1 instructions.\n" );
}
#else
fprintf( stderr, " SIMD not available.\n" );
#endif
fprintf( stderr, " Options:\n" );
fprintf( stderr, " -v view mode (loads pvr/ktx file, decodes it and saves to png)\n" );
fprintf( stderr, " -o 1 output selection (sum of: 1 - save pvr file; 2 - save png file)\n" );
fprintf( stderr, " note: pvr files are written regardless of this option\n" );
fprintf( stderr, " -a disable alpha channel processing\n" );
fprintf( stderr, " -s display image quality measurements\n" );
fprintf( stderr, " -b benchmark mode\n" );
fprintf( stderr, " -m generate mipmaps\n" );
fprintf( stderr, " -d enable dithering\n" );
fprintf( stderr, " -debug dissect ETC texture\n" );
fprintf( stderr, " -etc2 enable ETC2 mode\n" );
fprintf( stderr, " -rgba enable ETC2 RGBA mode\n" );
}

int main( int argc, char** argv )
{
DebugLog::AddCallback( &DebugCallback );

bool viewMode = false;
int save = 1;
bool alpha = true;
bool stats = false;
bool benchmark = false;
bool mipmap = false;
bool dither = false;
bool debug = false;
bool etc2 = false;
bool rgba = false;

if( argc < 2 )
{
Usage();
return 1;
}

#define CSTR(x) strcmp( argv[i], x ) == 0
for( int i=2; i<argc; i++ )
{
if( CSTR( "-v" ) )
{
viewMode = true;
}
else if( CSTR( "-o" ) )
{
i++;
save = atoi( argv[i] );
assert( ( save & 0x3 ) != 0 );
}
else if( CSTR( "-a" ) )
{
alpha = false;
}
else if( CSTR( "-s" ) )
{
stats = true;
}
else if( CSTR( "-b" ) )
{
benchmark = true;
}
else if( CSTR( "-m" ) )
{
mipmap = true;
}
else if( CSTR( "-d" ) )
{
dither = true;
}
else if( CSTR( "-debug" ) )
{
debug = true;
}
else if( CSTR( "-etc2" ) )
{
etc2 = true;
}
else if( CSTR( "-rgba" ) )
{
rgba = true;
etc2 = true;
}
else
{
Usage();
return 1;
}
}
#undef CSTR

if( dither )
{
InitDither();
}

TaskDispatch taskDispatch( System::CPUCores() );

if( benchmark )
{
auto start = GetTime();
auto bmp = std::make_shared<Bitmap>( argv[1], std::numeric_limits<unsigned int>::max() );
auto data = bmp->Data();
auto end = GetTime();
printf( "Image load time: %0.3f ms\n", ( end - start ) / 1000.f );

const int NumTasks = System::CPUCores() * 10;
start = GetTime();
for( int i=0; i<NumTasks; i++ )
{
TaskDispatch::Queue( [&bmp, &dither, i, etc2, rgba]()
{
const BlockData::Type type = rgba ? BlockData::Etc2_RGBA : ( etc2 ? BlockData::Etc2_RGB : BlockData::Etc1 );
auto bd = std::make_shared<BlockData>( bmp->Size(), false, type );
if( rgba )
{
bd->ProcessRGBA( bmp->Data(), bmp->Size().x * bmp->Size().y / 16, 0, bmp->Size().x, dither );
}
else
{
bd->Process( bmp->Data(), bmp->Size().x * bmp->Size().y / 16, 0, bmp->Size().x, Channels::RGB, dither );
}
} );
}
TaskDispatch::Sync();
end = GetTime();
printf( "Mean compression time for %i runs: %0.3f ms\n", NumTasks, ( end - start ) / ( NumTasks * 1000.f ) );
}
else if( viewMode )
{
auto bd = std::make_shared<BlockData>( argv[1] );
auto out = bd->Decode();
out->Write( "out.png" );
}
else if( debug )
{
auto bd = std::make_shared<BlockData>( argv[1] );
bd->Dissect();
}
else
{
DataProvider dp( argv[1], mipmap );
auto num = dp.NumberOfParts();

BlockData::Type type;
if( etc2 )
{
if( rgba && dp.Alpha() )
{
type = BlockData::Etc2_RGBA;
}
else
{
type = BlockData::Etc2_RGB;
}
}
else
{
type = BlockData::Etc1;
}

auto bd = std::make_shared<BlockData>( "out.pvr", dp.Size(), mipmap, type );
BlockDataPtr bda;
if( alpha && dp.Alpha() && !rgba )
{
bda = std::make_shared<BlockData>( "outa.pvr", dp.Size(), mipmap, type );
}

if( bda )
{
for( int i=0; i<num; i++ )
{
auto part = dp.NextPart();

TaskDispatch::Queue( [part, i, &bd, &dither]()
{
bd->Process( part.src, part.width / 4 * part.lines, part.offset, part.width, Channels::RGB, dither );
} );
TaskDispatch::Queue( [part, i, &bda]()
{
bda->Process( part.src, part.width / 4 * part.lines, part.offset, part.width, Channels::Alpha, false );
} );
}
}
else
{
for( int i=0; i<num; i++ )
{
auto part = dp.NextPart();

if( type == BlockData::Etc2_RGBA )
{
TaskDispatch::Queue( [part, i, &bd, &dither]()
{
bd->ProcessRGBA( part.src, part.width / 4 * part.lines, part.offset, part.width, dither );
} );
}
else
{
TaskDispatch::Queue( [part, i, &bd, &dither]()
{
bd->Process( part.src, part.width / 4 * part.lines, part.offset, part.width, Channels::RGB, dither );
} );
}
}
}

TaskDispatch::Sync();

if( stats )
{
auto out = bd->Decode();
float mse = CalcMSE3( dp.ImageData(), *out );
printf( "RGB data\n" );
printf( " RMSE: %f\n", sqrt( mse ) );
printf( " PSNR: %f\n", 20 * log10( 255 ) - 10 * log10( mse ) );
if( bda )
{
auto out = bda->Decode();
float mse = CalcMSE1( dp.ImageData(), *out );
printf( "A data\n" );
printf( " RMSE: %f\n", sqrt( mse ) );
printf( " PSNR: %f\n", 20 * log10( 255 ) - 10 * log10( mse ) );
}
}

if( save & 0x2 )
{
auto out = bd->Decode();
out->Write( "out.png" );
if( bda )
{
auto outa = bda->Decode();
outa->Write( "outa.png" );
}
}

bd.reset();
bda.reset();
}

return 0;
}
Loading

0 comments on commit 61e2c93

Please sign in to comment.