etcpak: We only need the compression code, remove rest of etcpak app

We do our own image loading, threading, and memory management in Godot already,
so the only components we need from etcpak (at least as of now) are the
`Compress*` methods defined in `ProcessDxtc.cpp` and `ProcessRGB.cpp`.

So we don't need to compile or vendor the rest.
This commit is contained in:
Rémi Verschelde 2021-04-14 16:45:14 +02:00
parent 8ce0fb0a94
commit 638cfec853
No known key found for this signature in database
GPG key ID: C3336907360768E1
32 changed files with 6 additions and 4556 deletions

View file

@ -11,31 +11,15 @@ thirdparty_obj = []
thirdparty_dir = "#thirdparty/etcpak/"
thirdparty_sources = [
"Bitmap.cpp",
"BitmapDownsampled.cpp",
"BlockData.cpp",
"ColorSpace.cpp",
"DataProvider.cpp",
"Debug.cpp",
"Dither.cpp",
"Error.cpp",
"mmap.cpp",
"ProcessDxtc.cpp",
"ProcessRGB.cpp",
"System.cpp",
"Tables.cpp",
"TaskDispatch.cpp",
"Timing.cpp",
"lz4/lz4.c",
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env_etcpak.Prepend(CPPPATH=[thirdparty_dir])
# Also requires libpng headers
if env["builtin_libpng"]:
env_etcpak.Prepend(CPPPATH=["#thirdparty/libpng"])
env_thirdparty = env_etcpak.Clone()
env_thirdparty.disable_warnings()
env_thirdparty.add_source_files(thirdparty_obj, thirdparty_sources)

11
thirdparty/README.md vendored
View file

@ -89,15 +89,16 @@ will limit its functionality to IPv4 only.
## etcpak
- Upstream: https://github.com/wolfpld/etcpak
- Version: git (403d38b3f1cb347c196d845d0a05e44a00d17169, 2021)
- Version: git (f27daea656ff77671580f838a889e33049430ebd, 2021)
- License: BSD-3-Clause
Important: Some Godot-made changes, see `patches` folders.
Files extracted from upstream source:
- All `.cpp` and `.hpp` files in the root folder except `Application.cpp`.
- `lz4` folder.
- Only the files relevant for compression (i.e. `Process*.cpp` and their deps):
```
Dither.{cpp,hpp} ForceInline.hpp Math.hpp ProcessCommon.hpp ProcessRGB.{cpp,hpp}
ProcessDxtc.{cpp,hpp} Tables.{cpp,hpp} Vector.hpp
```
- `AUTHORS.txt` and `LICENSE.txt`
## fonts

View file

@ -1,216 +0,0 @@
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <png.h>
#include "lz4/lz4.h"
#include "Bitmap.hpp"
#include "Debug.hpp"
Bitmap::Bitmap( const char* fn, unsigned int lines, bool bgr )
: m_block( nullptr )
, m_lines( lines )
, m_alpha( true )
, m_sema( 0 )
{
FILE* f = fopen( fn, "rb" );
assert( f );
char buf[4];
fread( buf, 1, 4, f );
if( memcmp( buf, "raw4", 4 ) == 0 )
{
uint8_t a;
fread( &a, 1, 1, f );
m_alpha = a == 1;
uint32_t d;
fread( &d, 1, 4, f );
m_size.x = d;
fread( &d, 1, 4, f );
m_size.y = d;
DBGPRINT( "Raw bitmap " << fn << " " << m_size.x << "x" << m_size.y );
assert( m_size.x % 4 == 0 );
assert( m_size.y % 4 == 0 );
int32_t csize;
fread( &csize, 1, 4, f );
char* cbuf = new char[csize];
fread( cbuf, 1, csize, f );
fclose( f );
m_block = m_data = new uint32_t[m_size.x*m_size.y];
m_linesLeft = m_size.y / 4;
LZ4_decompress_fast( cbuf, (char*)m_data, m_size.x*m_size.y*4 );
delete[] cbuf;
for( int i=0; i<m_size.y/4; i++ )
{
m_sema.unlock();
}
}
else
{
fseek( f, 0, SEEK_SET );
unsigned int sig_read = 0;
int bit_depth, color_type, interlace_type;
png_structp png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
png_infop info_ptr = png_create_info_struct( png_ptr );
setjmp( png_jmpbuf( png_ptr ) );
png_init_io( png_ptr, f );
png_set_sig_bytes( png_ptr, sig_read );
png_uint_32 w, h;
png_read_info( png_ptr, info_ptr );
png_get_IHDR( png_ptr, info_ptr, &w, &h, &bit_depth, &color_type, &interlace_type, NULL, NULL );
m_size = v2i( w, h );
png_set_strip_16( png_ptr );
if( color_type == PNG_COLOR_TYPE_PALETTE )
{
png_set_palette_to_rgb( png_ptr );
}
else if( color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8 )
{
png_set_expand_gray_1_2_4_to_8( png_ptr );
}
if( png_get_valid( png_ptr, info_ptr, PNG_INFO_tRNS ) )
{
png_set_tRNS_to_alpha( png_ptr );
}
if( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
{
png_set_gray_to_rgb(png_ptr);
}
if( bgr )
{
png_set_bgr(png_ptr);
}
switch( color_type )
{
case PNG_COLOR_TYPE_PALETTE:
if( !png_get_valid( png_ptr, info_ptr, PNG_INFO_tRNS ) )
{
png_set_filler( png_ptr, 0xff, PNG_FILLER_AFTER );
m_alpha = false;
}
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
png_set_gray_to_rgb( png_ptr );
break;
case PNG_COLOR_TYPE_RGB:
png_set_filler( png_ptr, 0xff, PNG_FILLER_AFTER );
m_alpha = false;
break;
default:
break;
}
DBGPRINT( "Bitmap " << fn << " " << w << "x" << h );
assert( w % 4 == 0 );
assert( h % 4 == 0 );
m_block = m_data = new uint32_t[w*h];
m_linesLeft = h / 4;
m_load = std::async( std::launch::async, [this, f, png_ptr, info_ptr]() mutable
{
auto ptr = m_data;
unsigned int lines = 0;
for( int i=0; i<m_size.y / 4; i++ )
{
for( int j=0; j<4; j++ )
{
png_read_rows( png_ptr, (png_bytepp)&ptr, NULL, 1 );
ptr += m_size.x;
}
lines++;
if( lines >= m_lines )
{
lines = 0;
m_sema.unlock();
}
}
if( lines != 0 )
{
m_sema.unlock();
}
png_read_end( png_ptr, info_ptr );
png_destroy_read_struct( &png_ptr, &info_ptr, NULL );
fclose( f );
} );
}
}
Bitmap::Bitmap( const v2i& size )
: m_data( new uint32_t[size.x*size.y] )
, m_block( nullptr )
, m_lines( 1 )
, m_linesLeft( size.y / 4 )
, m_size( size )
, m_sema( 0 )
{
}
Bitmap::Bitmap( const Bitmap& src, unsigned int lines )
: m_lines( lines )
, m_alpha( src.Alpha() )
, m_sema( 0 )
{
}
Bitmap::~Bitmap()
{
delete[] m_data;
}
void Bitmap::Write( const char* fn )
{
FILE* f = fopen( fn, "wb" );
assert( f );
png_structp png_ptr = png_create_write_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
png_infop info_ptr = png_create_info_struct( png_ptr );
setjmp( png_jmpbuf( png_ptr ) );
png_init_io( png_ptr, f );
png_set_IHDR( png_ptr, info_ptr, m_size.x, m_size.y, 8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE );
png_write_info( png_ptr, info_ptr );
uint32_t* ptr = m_data;
for( int i=0; i<m_size.y; i++ )
{
png_write_rows( png_ptr, (png_bytepp)(&ptr), 1 );
ptr += m_size.x;
}
png_write_end( png_ptr, info_ptr );
png_destroy_write_struct( &png_ptr, &info_ptr );
fclose( f );
}
const uint32_t* Bitmap::NextBlock( unsigned int& lines, bool& done )
{
std::lock_guard<std::mutex> lock( m_lock );
lines = std::min( m_lines, m_linesLeft );
auto ret = m_block;
m_sema.lock();
m_block += m_size.x * 4 * lines;
m_linesLeft -= lines;
done = m_linesLeft == 0;
return ret;
}

View file

@ -1,50 +0,0 @@
#ifndef __DARKRL__BITMAP_HPP__
#define __DARKRL__BITMAP_HPP__
#include <future>
#include <memory>
#include <mutex>
#include <stdint.h>
#include "Semaphore.hpp"
#include "Vector.hpp"
enum class Channels
{
RGB,
Alpha
};
class Bitmap
{
public:
Bitmap( const char* fn, unsigned int lines, bool bgr );
Bitmap( const v2i& size );
virtual ~Bitmap();
void Write( const char* fn );
uint32_t* Data() { if( m_load.valid() ) m_load.wait(); return m_data; }
const uint32_t* Data() const { if( m_load.valid() ) m_load.wait(); return m_data; }
const v2i& Size() const { return m_size; }
bool Alpha() const { return m_alpha; }
const uint32_t* NextBlock( unsigned int& lines, bool& done );
protected:
Bitmap( const Bitmap& src, unsigned int lines );
uint32_t* m_data;
uint32_t* m_block;
unsigned int m_lines;
unsigned int m_linesLeft;
v2i m_size;
bool m_alpha;
Semaphore m_sema;
std::mutex m_lock;
std::future<void> m_load;
};
typedef std::shared_ptr<Bitmap> BitmapPtr;
#endif

View file

@ -1,86 +0,0 @@
#include <string.h>
#include <utility>
#include "BitmapDownsampled.hpp"
#include "Debug.hpp"
BitmapDownsampled::BitmapDownsampled( const Bitmap& bmp, unsigned int lines )
: Bitmap( bmp, lines )
{
m_size.x = std::max( 1, bmp.Size().x / 2 );
m_size.y = std::max( 1, bmp.Size().y / 2 );
int w = std::max( m_size.x, 4 );
int h = std::max( m_size.y, 4 );
DBGPRINT( "Subbitmap " << m_size.x << "x" << m_size.y );
m_block = m_data = new uint32_t[w*h];
if( m_size.x < w || m_size.y < h )
{
memset( m_data, 0, w*h*sizeof( uint32_t ) );
m_linesLeft = h / 4;
unsigned int lines = 0;
for( int i=0; i<h/4; i++ )
{
for( int j=0; j<4; j++ )
{
lines++;
if( lines > m_lines )
{
lines = 0;
m_sema.unlock();
}
}
}
if( lines != 0 )
{
m_sema.unlock();
}
}
else
{
m_linesLeft = h / 4;
m_load = std::async( std::launch::async, [this, &bmp, w, h]() mutable
{
auto ptr = m_data;
auto src1 = bmp.Data();
auto src2 = src1 + bmp.Size().x;
unsigned int lines = 0;
for( int i=0; i<h/4; i++ )
{
for( int j=0; j<4; j++ )
{
for( int k=0; k<m_size.x; k++ )
{
int r = ( ( *src1 & 0x000000FF ) + ( *(src1+1) & 0x000000FF ) + ( *src2 & 0x000000FF ) + ( *(src2+1) & 0x000000FF ) ) / 4;
int g = ( ( ( *src1 & 0x0000FF00 ) + ( *(src1+1) & 0x0000FF00 ) + ( *src2 & 0x0000FF00 ) + ( *(src2+1) & 0x0000FF00 ) ) / 4 ) & 0x0000FF00;
int b = ( ( ( *src1 & 0x00FF0000 ) + ( *(src1+1) & 0x00FF0000 ) + ( *src2 & 0x00FF0000 ) + ( *(src2+1) & 0x00FF0000 ) ) / 4 ) & 0x00FF0000;
int a = ( ( ( ( ( *src1 & 0xFF000000 ) >> 8 ) + ( ( *(src1+1) & 0xFF000000 ) >> 8 ) + ( ( *src2 & 0xFF000000 ) >> 8 ) + ( ( *(src2+1) & 0xFF000000 ) >> 8 ) ) / 4 ) & 0x00FF0000 ) << 8;
*ptr++ = r | g | b | a;
src1 += 2;
src2 += 2;
}
src1 += m_size.x * 2;
src2 += m_size.x * 2;
}
lines++;
if( lines >= m_lines )
{
lines = 0;
m_sema.unlock();
}
}
if( lines != 0 )
{
m_sema.unlock();
}
} );
}
}
BitmapDownsampled::~BitmapDownsampled()
{
}

View file

@ -1,13 +0,0 @@
#ifndef __DARKRL__BITMAPDOWNSAMPLED_HPP__
#define __DARKRL__BITMAPDOWNSAMPLED_HPP__
#include "Bitmap.hpp"
class BitmapDownsampled : public Bitmap
{
public:
BitmapDownsampled( const Bitmap& bmp, unsigned int lines );
~BitmapDownsampled();
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,56 +0,0 @@
#ifndef __BLOCKDATA_HPP__
#define __BLOCKDATA_HPP__
#include <condition_variable>
#include <future>
#include <memory>
#include <mutex>
#include <stdint.h>
#include <stdio.h>
#include <vector>
#include "Bitmap.hpp"
#include "ForceInline.hpp"
#include "Vector.hpp"
class BlockData
{
public:
enum Type
{
Etc1,
Etc2_RGB,
Etc2_RGBA,
Dxt1,
Dxt5
};
BlockData( const char* fn );
BlockData( const char* fn, const v2i& size, bool mipmap, Type type );
BlockData( const v2i& size, bool mipmap, Type type );
~BlockData();
BitmapPtr Decode();
void Process( const uint32_t* src, uint32_t blocks, size_t offset, size_t width, Channels type, bool dither );
void ProcessRGBA( const uint32_t* src, uint32_t blocks, size_t offset, size_t width );
const v2i& Size() const { return m_size; }
private:
etcpak_no_inline BitmapPtr DecodeRGB();
etcpak_no_inline BitmapPtr DecodeRGBA();
etcpak_no_inline BitmapPtr DecodeDxt1();
etcpak_no_inline BitmapPtr DecodeDxt5();
uint8_t* m_data;
v2i m_size;
size_t m_dataOffset;
FILE* m_file;
size_t m_maplen;
Type m_type;
};
typedef std::shared_ptr<BlockData> BlockDataPtr;
#endif

View file

@ -1,114 +0,0 @@
#include <math.h>
#include <stdint.h>
#include "Math.hpp"
#include "ColorSpace.hpp"
namespace Color
{
static const XYZ white( v3b( 255, 255, 255 ) );
static const v3f rwhite( 1.f / white.x, 1.f / white.y, 1.f / white.z );
XYZ::XYZ( float _x, float _y, float _z )
: x( _x )
, y( _y )
, z( _z )
{
}
XYZ::XYZ( const v3b& rgb )
{
const float r = rgb.x / 255.f;
const float g = rgb.y / 255.f;
const float b = rgb.z / 255.f;
const float rl = sRGB2linear( r );
const float gl = sRGB2linear( g );
const float bl = sRGB2linear( b );
x = 0.4124f * rl + 0.3576f * gl + 0.1805f * bl;
y = 0.2126f * rl + 0.7152f * gl + 0.0722f * bl;
z = 0.0193f * rl + 0.1192f * gl + 0.9505f * bl;
}
static float revlab( float t )
{
const float p1 = 6.f/29.f;
const float p2 = 4.f/29.f;
if( t > p1 )
{
return t*t*t;
}
else
{
return 3 * sq( p1 ) * ( t - p2 );
}
}
XYZ::XYZ( const Lab& lab )
{
y = white.y * revlab( 1.f/116.f * ( lab.L + 16 ) );
x = white.x * revlab( 1.f/116.f * ( lab.L + 16 ) + 1.f/500.f * lab.a );
z = white.z * revlab( 1.f/116.f * ( lab.L + 16 ) - 1.f/200.f * lab.b );
}
v3i XYZ::RGB() const
{
const float rl = 3.2406f * x - 1.5372f * y - 0.4986f * z;
const float gl = -0.9689f * x + 1.8758f * y + 0.0415f * z;
const float bl = 0.0557f * x - 0.2040f * y + 1.0570f * z;
const float r = linear2sRGB( rl );
const float g = linear2sRGB( gl );
const float b = linear2sRGB( bl );
return v3i( clampu8( int32_t( r * 255 ) ), clampu8( int32_t( g * 255 ) ), clampu8( int32_t( b * 255 ) ) );
}
Lab::Lab()
: L( 0 )
, a( 0 )
, b( 0 )
{
}
Lab::Lab( float L, float a, float b )
: L( L )
, a( a )
, b( b )
{
}
static float labfunc( float t )
{
const float p1 = (6.f/29.f)*(6.f/29.f)*(6.f/29.f);
const float p2 = (1.f/3.f)*(29.f/6.f)*(29.f/6.f);
const float p3 = (4.f/29.f);
if( t > p1 )
{
return pow( t, 1.f/3.f );
}
else
{
return p2 * t + p3;
}
}
Lab::Lab( const XYZ& xyz )
{
L = 116 * labfunc( xyz.y * rwhite.y ) - 16;
a = 500 * ( labfunc( xyz.x * rwhite.x ) - labfunc( xyz.y * rwhite.y ) );
b = 200 * ( labfunc( xyz.y * rwhite.y ) - labfunc( xyz.z * rwhite.z ) );
}
Lab::Lab( const v3b& rgb )
{
new(this) Lab( XYZ( rgb ) );
}
}

View file

@ -1,36 +0,0 @@
#ifndef __DARKRL__COLORSPACE_HPP__
#define __DARKRL__COLORSPACE_HPP__
#include "Vector.hpp"
namespace Color
{
class Lab;
class XYZ
{
public:
XYZ( float x, float y, float z );
XYZ( const v3b& rgb );
XYZ( const Lab& lab );
v3i RGB() const;
float x, y, z;
};
class Lab
{
public:
Lab();
Lab( float L, float a, float b );
Lab( const XYZ& xyz );
Lab( const v3b& rgb );
float L, a, b;
};
}
#endif

View file

@ -1,77 +0,0 @@
#include <assert.h>
#include <utility>
#include "BitmapDownsampled.hpp"
#include "DataProvider.hpp"
#include "MipMap.hpp"
DataProvider::DataProvider( const char* fn, bool mipmap, bool bgr )
: m_offset( 0 )
, m_mipmap( mipmap )
, m_done( false )
, m_lines( 32 )
{
m_bmp.emplace_back( new Bitmap( fn, m_lines, bgr ) );
m_current = m_bmp[0].get();
}
DataProvider::~DataProvider()
{
}
unsigned int DataProvider::NumberOfParts() const
{
unsigned int parts = ( ( m_bmp[0]->Size().y / 4 ) + m_lines - 1 ) / m_lines;
if( m_mipmap )
{
v2i current = m_bmp[0]->Size();
int levels = NumberOfMipLevels( current );
unsigned int lines = m_lines;
for( int i=1; i<levels; i++ )
{
assert( current.x != 1 || current.y != 1 );
current.x = std::max( 1, current.x / 2 );
current.y = std::max( 1, current.y / 2 );
lines *= 2;
parts += ( ( std::max( 4, current.y ) / 4 ) + lines - 1 ) / lines;
}
assert( current.x == 1 && current.y == 1 );
}
return parts;
}
DataPart DataProvider::NextPart()
{
assert( !m_done );
unsigned int lines = m_lines;
bool done;
const auto ptr = m_current->NextBlock( lines, done );
DataPart ret = {
ptr,
std::max<unsigned int>( 4, m_current->Size().x ),
lines,
m_offset
};
m_offset += m_current->Size().x / 4 * lines;
if( done )
{
if( m_mipmap && ( m_current->Size().x != 1 || m_current->Size().y != 1 ) )
{
m_lines *= 2;
m_bmp.emplace_back( new BitmapDownsampled( *m_current, m_lines ) );
m_current = m_bmp[m_bmp.size()-1].get();
}
else
{
m_done = true;
}
}
return ret;
}

View file

@ -1,41 +0,0 @@
#ifndef __DATAPROVIDER_HPP__
#define __DATAPROVIDER_HPP__
#include <memory>
#include <stdint.h>
#include <vector>
#include "Bitmap.hpp"
struct DataPart
{
const uint32_t* src;
unsigned int width;
unsigned int lines;
unsigned int offset;
};
class DataProvider
{
public:
DataProvider( const char* fn, bool mipmap, bool bgr );
~DataProvider();
unsigned int NumberOfParts() const;
DataPart NextPart();
bool Alpha() const { return m_bmp[0]->Alpha(); }
const v2i& Size() const { return m_bmp[0]->Size(); }
const Bitmap& ImageData() const { return *m_bmp[0]; }
private:
std::vector<std::unique_ptr<Bitmap>> m_bmp;
Bitmap* m_current;
unsigned int m_offset;
unsigned int m_lines;
bool m_mipmap;
bool m_done;
};
#endif

View file

@ -1,31 +0,0 @@
#include <algorithm>
#include <vector>
#include "Debug.hpp"
static std::vector<DebugLog::Callback*> s_callbacks;
void DebugLog::Message( const char* msg )
{
for( auto it = s_callbacks.begin(); it != s_callbacks.end(); ++it )
{
(*it)->OnDebugMessage( msg );
}
}
void DebugLog::AddCallback( Callback* c )
{
const auto it = std::find( s_callbacks.begin(), s_callbacks.end(), c );
if( it == s_callbacks.end() )
{
s_callbacks.push_back( c );
}
}
void DebugLog::RemoveCallback( Callback* c )
{
const auto it = std::find( s_callbacks.begin(), s_callbacks.end(), c );
if( it != s_callbacks.end() )
{
s_callbacks.erase( it );
}
}

View file

@ -1,27 +0,0 @@
#ifndef __DARKRL__DEBUG_HPP__
#define __DARKRL__DEBUG_HPP__
#ifdef DEBUG
# include <sstream>
# define DBGPRINT(msg) { std::stringstream __buf; __buf << msg; DebugLog::Message( __buf.str().c_str() ); }
#else
# define DBGPRINT(msg) ((void)0)
#endif
class DebugLog
{
public:
struct Callback
{
virtual void OnDebugMessage( const char* msg ) = 0;
};
static void Message( const char* msg );
static void AddCallback( Callback* c );
static void RemoveCallback( Callback* c );
private:
DebugLog() {}
};
#endif

View file

@ -1,48 +0,0 @@
#include <stdint.h>
#include "Error.hpp"
#include "Math.hpp"
float CalcMSE3( const Bitmap& bmp, const Bitmap& out )
{
float err = 0;
const uint32_t* p1 = bmp.Data();
const uint32_t* p2 = out.Data();
size_t cnt = bmp.Size().x * bmp.Size().y;
for( size_t i=0; i<cnt; i++ )
{
uint32_t c1 = *p1++;
uint32_t c2 = *p2++;
err += sq( ( c1 & 0x000000FF ) - ( c2 & 0x000000FF ) );
err += sq( ( ( c1 & 0x0000FF00 ) >> 8 ) - ( ( c2 & 0x0000FF00 ) >> 8 ) );
err += sq( ( ( c1 & 0x00FF0000 ) >> 16 ) - ( ( c2 & 0x00FF0000 ) >> 16 ) );
}
err /= cnt * 3;
return err;
}
float CalcMSE1( const Bitmap& bmp, const Bitmap& out )
{
float err = 0;
const uint32_t* p1 = bmp.Data();
const uint32_t* p2 = out.Data();
size_t cnt = bmp.Size().x * bmp.Size().y;
for( size_t i=0; i<cnt; i++ )
{
uint32_t c1 = *p1++;
uint32_t c2 = *p2++;
err += sq( ( c1 >> 24 ) - ( c2 & 0xFF ) );
}
err /= cnt;
return err;
}

View file

@ -1,9 +0,0 @@
#ifndef __ERROR_HPP__
#define __ERROR_HPP__
#include "Bitmap.hpp"
float CalcMSE3( const Bitmap& bmp, const Bitmap& out );
float CalcMSE1( const Bitmap& bmp, const Bitmap& out );
#endif

View file

@ -1,11 +0,0 @@
#ifndef __MIPMAP_HPP__
#define __MIPMAP_HPP__
#include "Vector.hpp"
inline int NumberOfMipLevels( const v2i& size )
{
return (int)floor( log2( std::max( size.x, size.y ) ) ) + 1;
}
#endif

View file

@ -1,46 +0,0 @@
#ifndef __DARKRL__SEMAPHORE_HPP__
#define __DARKRL__SEMAPHORE_HPP__
#include <condition_variable>
#include <mutex>
class Semaphore
{
public:
Semaphore( int count ) : m_count( count ) {}
void lock()
{
std::unique_lock<std::mutex> lock( m_mutex );
m_cv.wait( lock, [this](){ return m_count != 0; } );
m_count--;
}
void unlock()
{
std::lock_guard<std::mutex> lock( m_mutex );
m_count++;
m_cv.notify_one();
}
bool try_lock()
{
std::lock_guard<std::mutex> lock( m_mutex );
if( m_count == 0 )
{
return false;
}
else
{
m_count--;
return true;
}
}
private:
std::mutex m_mutex;
std::condition_variable m_cv;
unsigned int m_count;
};
#endif

View file

@ -1,65 +0,0 @@
#include <algorithm>
#ifdef _WIN32
# include <windows.h>
#else
# include <unistd.h>
#endif
#include "System.hpp"
unsigned int System::CPUCores()
{
static unsigned int cores = 0;
if( cores == 0 )
{
int tmp;
#ifdef _WIN32
SYSTEM_INFO info;
GetSystemInfo( &info );
tmp = (int)info.dwNumberOfProcessors;
#else
# ifndef _SC_NPROCESSORS_ONLN
# ifdef _SC_NPROC_ONLN
# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
# elif defined _SC_CRAY_NCPU
# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
# endif
# endif
tmp = (int)(long)sysconf( _SC_NPROCESSORS_ONLN );
#endif
cores = (unsigned int)std::max( tmp, 1 );
}
return cores;
}
void System::SetThreadName( std::thread& thread, const char* name )
{
#ifdef _MSC_VER
const DWORD MS_VC_EXCEPTION=0x406D1388;
# pragma pack( push, 8 )
struct THREADNAME_INFO
{
DWORD dwType;
LPCSTR szName;
DWORD dwThreadID;
DWORD dwFlags;
};
# pragma pack(pop)
DWORD ThreadId = GetThreadId( static_cast<HANDLE>( thread.native_handle() ) );
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name;
info.dwThreadID = ThreadId;
info.dwFlags = 0;
__try
{
RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
#endif
}

View file

@ -1,15 +0,0 @@
#ifndef __DARKRL__SYSTEM_HPP__
#define __DARKRL__SYSTEM_HPP__
#include <thread>
class System
{
public:
System() = delete;
static unsigned int CPUCores();
static void SetThreadName( std::thread& thread, const char* name );
};
#endif

View file

@ -1,122 +0,0 @@
#include <assert.h>
#include <stdio.h>
#ifndef _MSC_VER
#include <pthread.h>
#endif
#include "Debug.hpp"
#include "System.hpp"
#include "TaskDispatch.hpp"
static TaskDispatch* s_instance = nullptr;
TaskDispatch::TaskDispatch( size_t workers )
: m_exit( false )
, m_jobs( 0 )
{
assert( !s_instance );
s_instance = this;
assert( workers >= 1 );
workers--;
m_workers.reserve( workers );
for( size_t i=0; i<workers; i++ )
{
char tmp[16];
sprintf( tmp, "Worker %zu", i );
#ifdef _MSC_VER
auto worker = std::thread( [this]{ Worker(); } );
System::SetThreadName( worker, tmp );
#else // Using pthread.
auto worker = std::thread( [this, tmp]{
#ifdef __APPLE__
pthread_setname_np( tmp );
#else // Linux or MinGW.
pthread_setname_np( pthread_self(), tmp );
#endif
Worker();
} );
#endif
m_workers.emplace_back( std::move( worker ) );
}
DBGPRINT( "Task dispatcher with " << m_workers.size() + 1 << " workers" );
}
TaskDispatch::~TaskDispatch()
{
m_exit = true;
m_queueLock.lock();
m_cvWork.notify_all();
m_queueLock.unlock();
for( auto& worker : m_workers )
{
worker.join();
}
assert( s_instance );
s_instance = nullptr;
}
void TaskDispatch::Queue( const std::function<void(void)>& f )
{
std::unique_lock<std::mutex> lock( s_instance->m_queueLock );
s_instance->m_queue.emplace_back( f );
const auto size = s_instance->m_queue.size();
lock.unlock();
if( size > 1 )
{
s_instance->m_cvWork.notify_one();
}
}
void TaskDispatch::Queue( std::function<void(void)>&& f )
{
std::unique_lock<std::mutex> lock( s_instance->m_queueLock );
s_instance->m_queue.emplace_back( std::move( f ) );
const auto size = s_instance->m_queue.size();
lock.unlock();
if( size > 1 )
{
s_instance->m_cvWork.notify_one();
}
}
void TaskDispatch::Sync()
{
std::unique_lock<std::mutex> lock( s_instance->m_queueLock );
while( !s_instance->m_queue.empty() )
{
auto f = s_instance->m_queue.back();
s_instance->m_queue.pop_back();
lock.unlock();
f();
lock.lock();
}
s_instance->m_cvJobs.wait( lock, []{ return s_instance->m_jobs == 0; } );
}
void TaskDispatch::Worker()
{
for(;;)
{
std::unique_lock<std::mutex> lock( m_queueLock );
m_cvWork.wait( lock, [this]{ return !m_queue.empty() || m_exit; } );
if( m_exit ) return;
auto f = m_queue.back();
m_queue.pop_back();
m_jobs++;
lock.unlock();
f();
lock.lock();
m_jobs--;
bool notify = m_jobs == 0 && m_queue.empty();
lock.unlock();
if( notify )
{
m_cvJobs.notify_all();
}
}
}

View file

@ -1,34 +0,0 @@
#ifndef __DARKRL__TASKDISPATCH_HPP__
#define __DARKRL__TASKDISPATCH_HPP__
#include <atomic>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <thread>
#include <vector>
class TaskDispatch
{
public:
TaskDispatch( size_t workers );
~TaskDispatch();
static void Queue( const std::function<void(void)>& f );
static void Queue( std::function<void(void)>&& f );
static void Sync();
private:
void Worker();
std::vector<std::function<void(void)>> m_queue;
std::mutex m_queueLock;
std::condition_variable m_cvWork, m_cvJobs;
std::atomic<bool> m_exit;
size_t m_jobs;
std::vector<std::thread> m_workers;
};
#endif

View file

@ -1,8 +0,0 @@
#include <chrono>
#include "Timing.hpp"
uint64_t GetTime()
{
return std::chrono::time_point_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now() ).time_since_epoch().count();
}

View file

@ -1,8 +0,0 @@
#ifndef __DARKRL__TIMING_HPP__
#define __DARKRL__TIMING_HPP__
#include <stdint.h>
uint64_t GetTime();
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,360 +0,0 @@
/*
LZ4 - Fast LZ compression algorithm
Header File
Copyright (C) 2011-2015, Yann Collet.
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
You can contact the author at :
- LZ4 source repository : https://github.com/Cyan4973/lz4
- LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
*/
#pragma once
#if defined (__cplusplus)
extern "C" {
#endif
/*
* lz4.h provides block compression functions, and gives full buffer control to programmer.
* If you need to generate inter-operable compressed data (respecting LZ4 frame specification),
* and can let the library handle its own memory, please use lz4frame.h instead.
*/
/**************************************
* Version
**************************************/
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
#define LZ4_VERSION_MINOR 7 /* for new (non-breaking) interface capabilities */
#define LZ4_VERSION_RELEASE 1 /* for tweaks, bug-fixes, or development */
#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
int LZ4_versionNumber (void);
/**************************************
* Tuning parameter
**************************************/
/*
* LZ4_MEMORY_USAGE :
* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.)
* Increasing memory usage improves compression ratio
* Reduced memory usage can improve speed, due to cache effect
* Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
*/
#define LZ4_MEMORY_USAGE 14
/**************************************
* Simple Functions
**************************************/
int LZ4_compress_default(const char* source, char* dest, int sourceSize, int maxDestSize);
int LZ4_decompress_safe (const char* source, char* dest, int compressedSize, int maxDecompressedSize);
/*
LZ4_compress_default() :
Compresses 'sourceSize' bytes from buffer 'source'
into already allocated 'dest' buffer of size 'maxDestSize'.
Compression is guaranteed to succeed if 'maxDestSize' >= LZ4_compressBound(sourceSize).
It also runs faster, so it's a recommended setting.
If the function cannot compress 'source' into a more limited 'dest' budget,
compression stops *immediately*, and the function result is zero.
As a consequence, 'dest' content is not valid.
This function never writes outside 'dest' buffer, nor read outside 'source' buffer.
sourceSize : Max supported value is LZ4_MAX_INPUT_VALUE
maxDestSize : full or partial size of buffer 'dest' (which must be already allocated)
return : the number of bytes written into buffer 'dest' (necessarily <= maxOutputSize)
or 0 if compression fails
LZ4_decompress_safe() :
compressedSize : is the precise full size of the compressed block.
maxDecompressedSize : is the size of destination buffer, which must be already allocated.
return : the number of bytes decompressed into destination buffer (necessarily <= maxDecompressedSize)
If destination buffer is not large enough, decoding will stop and output an error code (<0).
If the source stream is detected malformed, the function will stop decoding and return a negative result.
This function is protected against buffer overflow exploits, including malicious data packets.
It never writes outside output buffer, nor reads outside input buffer.
*/
/**************************************
* Advanced Functions
**************************************/
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
/*
LZ4_compressBound() :
Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
This function is primarily useful for memory allocation purposes (destination buffer size).
Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
Note that LZ4_compress_default() compress faster when dest buffer size is >= LZ4_compressBound(srcSize)
inputSize : max supported value is LZ4_MAX_INPUT_SIZE
return : maximum output size in a "worst case" scenario
or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE)
*/
int LZ4_compressBound(int inputSize);
/*
LZ4_compress_fast() :
Same as LZ4_compress_default(), but allows to select an "acceleration" factor.
The larger the acceleration value, the faster the algorithm, but also the lesser the compression.
It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed.
An acceleration value of "1" is the same as regular LZ4_compress_default()
Values <= 0 will be replaced by ACCELERATION_DEFAULT (see lz4.c), which is 1.
*/
int LZ4_compress_fast (const char* source, char* dest, int sourceSize, int maxDestSize, int acceleration);
/*
LZ4_compress_fast_extState() :
Same compression function, just using an externally allocated memory space to store compression state.
Use LZ4_sizeofState() to know how much memory must be allocated,
and allocate it on 8-bytes boundaries (using malloc() typically).
Then, provide it as 'void* state' to compression function.
*/
int LZ4_sizeofState(void);
int LZ4_compress_fast_extState (void* state, const char* source, char* dest, int inputSize, int maxDestSize, int acceleration);
/*
LZ4_compress_destSize() :
Reverse the logic, by compressing as much data as possible from 'source' buffer
into already allocated buffer 'dest' of size 'targetDestSize'.
This function either compresses the entire 'source' content into 'dest' if it's large enough,
or fill 'dest' buffer completely with as much data as possible from 'source'.
*sourceSizePtr : will be modified to indicate how many bytes where read from 'source' to fill 'dest'.
New value is necessarily <= old value.
return : Nb bytes written into 'dest' (necessarily <= targetDestSize)
or 0 if compression fails
*/
int LZ4_compress_destSize (const char* source, char* dest, int* sourceSizePtr, int targetDestSize);
/*
LZ4_decompress_fast() :
originalSize : is the original and therefore uncompressed size
return : the number of bytes read from the source buffer (in other words, the compressed size)
If the source stream is detected malformed, the function will stop decoding and return a negative result.
Destination buffer must be already allocated. Its size must be a minimum of 'originalSize' bytes.
note : This function fully respect memory boundaries for properly formed compressed data.
It is a bit faster than LZ4_decompress_safe().
However, it does not provide any protection against intentionally modified data stream (malicious input).
Use this function in trusted environment only (data to decode comes from a trusted source).
*/
int LZ4_decompress_fast (const char* source, char* dest, int originalSize);
/*
LZ4_decompress_safe_partial() :
This function decompress a compressed block of size 'compressedSize' at position 'source'
into destination buffer 'dest' of size 'maxDecompressedSize'.
The function tries to stop decompressing operation as soon as 'targetOutputSize' has been reached,
reducing decompression time.
return : the number of bytes decoded in the destination buffer (necessarily <= maxDecompressedSize)
Note : this number can be < 'targetOutputSize' should the compressed block to decode be smaller.
Always control how many bytes were decoded.
If the source stream is detected malformed, the function will stop decoding and return a negative result.
This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets
*/
int LZ4_decompress_safe_partial (const char* source, char* dest, int compressedSize, int targetOutputSize, int maxDecompressedSize);
/***********************************************
* Streaming Compression Functions
***********************************************/
#define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4)
#define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(long long))
/*
* LZ4_stream_t
* information structure to track an LZ4 stream.
* important : init this structure content before first use !
* note : only allocated directly the structure if you are statically linking LZ4
* If you are using liblz4 as a DLL, please use below construction methods instead.
*/
typedef struct { long long table[LZ4_STREAMSIZE_U64]; } LZ4_stream_t;
/*
* LZ4_resetStream
* Use this function to init an allocated LZ4_stream_t structure
*/
void LZ4_resetStream (LZ4_stream_t* streamPtr);
/*
* LZ4_createStream will allocate and initialize an LZ4_stream_t structure
* LZ4_freeStream releases its memory.
* In the context of a DLL (liblz4), please use these methods rather than the static struct.
* They are more future proof, in case of a change of LZ4_stream_t size.
*/
LZ4_stream_t* LZ4_createStream(void);
int LZ4_freeStream (LZ4_stream_t* streamPtr);
/*
* LZ4_loadDict
* Use this function to load a static dictionary into LZ4_stream.
* Any previous data will be forgotten, only 'dictionary' will remain in memory.
* Loading a size of 0 is allowed.
* Return : dictionary size, in bytes (necessarily <= 64 KB)
*/
int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
/*
* LZ4_compress_fast_continue
* Compress buffer content 'src', using data from previously compressed blocks as dictionary to improve compression ratio.
* Important : Previous data blocks are assumed to still be present and unmodified !
* 'dst' buffer must be already allocated.
* If maxDstSize >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster.
* If not, and if compressed data cannot fit into 'dst' buffer size, compression stops, and function returns a zero.
*/
int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int maxDstSize, int acceleration);
/*
* LZ4_saveDict
* If previously compressed data block is not guaranteed to remain available at its memory location
* save it into a safer place (char* safeBuffer)
* Note : you don't need to call LZ4_loadDict() afterwards,
* dictionary is immediately usable, you can therefore call LZ4_compress_fast_continue()
* Return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error
*/
int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int dictSize);
/************************************************
* Streaming Decompression Functions
************************************************/
#define LZ4_STREAMDECODESIZE_U64 4
#define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
typedef struct { unsigned long long table[LZ4_STREAMDECODESIZE_U64]; } LZ4_streamDecode_t;
/*
* LZ4_streamDecode_t
* information structure to track an LZ4 stream.
* init this structure content using LZ4_setStreamDecode or memset() before first use !
*
* In the context of a DLL (liblz4) please prefer usage of construction methods below.
* They are more future proof, in case of a change of LZ4_streamDecode_t size in the future.
* LZ4_createStreamDecode will allocate and initialize an LZ4_streamDecode_t structure
* LZ4_freeStreamDecode releases its memory.
*/
LZ4_streamDecode_t* LZ4_createStreamDecode(void);
int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
/*
* LZ4_setStreamDecode
* Use this function to instruct where to find the dictionary.
* Setting a size of 0 is allowed (same effect as reset).
* Return : 1 if OK, 0 if error
*/
int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
/*
*_continue() :
These decoding functions allow decompression of multiple blocks in "streaming" mode.
Previously decoded blocks *must* remain available at the memory position where they were decoded (up to 64 KB)
In the case of a ring buffers, decoding buffer must be either :
- Exactly same size as encoding buffer, with same update rule (block boundaries at same positions)
In which case, the decoding & encoding ring buffer can have any size, including very small ones ( < 64 KB).
- Larger than encoding buffer, by a minimum of maxBlockSize more bytes.
maxBlockSize is implementation dependent. It's the maximum size you intend to compress into a single block.
In which case, encoding and decoding buffers do not need to be synchronized,
and encoding ring buffer can have any size, including small ones ( < 64 KB).
- _At least_ 64 KB + 8 bytes + maxBlockSize.
In which case, encoding and decoding buffers do not need to be synchronized,
and encoding ring buffer can have any size, including larger than decoding buffer.
Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer,
and indicate where it is saved using LZ4_setStreamDecode()
*/
int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int compressedSize, int maxDecompressedSize);
int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* source, char* dest, int originalSize);
/*
Advanced decoding functions :
*_usingDict() :
These decoding functions work the same as
a combination of LZ4_setStreamDecode() followed by LZ4_decompress_x_continue()
They are stand-alone. They don't need nor update an LZ4_streamDecode_t structure.
*/
int LZ4_decompress_safe_usingDict (const char* source, char* dest, int compressedSize, int maxDecompressedSize, const char* dictStart, int dictSize);
int LZ4_decompress_fast_usingDict (const char* source, char* dest, int originalSize, const char* dictStart, int dictSize);
/**************************************
* Obsolete Functions
**************************************/
/* Deprecate Warnings */
/* Should these warnings messages be a problem,
it is generally possible to disable them,
with -Wno-deprecated-declarations for gcc
or _CRT_SECURE_NO_WARNINGS in Visual for example.
You can also define LZ4_DEPRECATE_WARNING_DEFBLOCK. */
#ifndef LZ4_DEPRECATE_WARNING_DEFBLOCK
# define LZ4_DEPRECATE_WARNING_DEFBLOCK
# define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
# if (LZ4_GCC_VERSION >= 405) || defined(__clang__)
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
# elif (LZ4_GCC_VERSION >= 301)
# define LZ4_DEPRECATED(message) __attribute__((deprecated))
# elif defined(_MSC_VER)
# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
# else
# pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler")
# define LZ4_DEPRECATED(message)
# endif
#endif /* LZ4_DEPRECATE_WARNING_DEFBLOCK */
/* Obsolete compression functions */
/* These functions are planned to start generate warnings by r131 approximately */
int LZ4_compress (const char* source, char* dest, int sourceSize);
int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize);
int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
/* Obsolete decompression functions */
/* These function names are completely deprecated and must no longer be used.
They are only provided here for compatibility with older programs.
- LZ4_uncompress is the same as LZ4_decompress_fast
- LZ4_uncompress_unknownOutputSize is the same as LZ4_decompress_safe
These function prototypes are now disabled; uncomment them only if you really need them.
It is highly recommended to stop using these prototypes and migrate to maintained ones */
/* int LZ4_uncompress (const char* source, char* dest, int outputSize); */
/* int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); */
/* Obsolete streaming functions; use new streaming interface whenever possible */
LZ4_DEPRECATED("use LZ4_createStream() instead") void* LZ4_create (char* inputBuffer);
LZ4_DEPRECATED("use LZ4_createStream() instead") int LZ4_sizeofStreamState(void);
LZ4_DEPRECATED("use LZ4_resetStream() instead") int LZ4_resetStreamState(void* state, char* inputBuffer);
LZ4_DEPRECATED("use LZ4_saveDict() instead") char* LZ4_slideInputBuffer (void* state);
/* Obsolete streaming decoding functions */
LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
#if defined (__cplusplus)
}
#endif

View file

@ -1,38 +0,0 @@
#include "mmap.hpp"
#ifdef _WIN32
# include <io.h>
# include <windows.h>
void* mmap( void* addr, size_t length, int prot, int flags, int fd, off_t offset )
{
HANDLE hnd;
void* map = nullptr;
switch( prot )
{
case PROT_READ:
if( hnd = CreateFileMapping( HANDLE( _get_osfhandle( fd ) ), nullptr, PAGE_READONLY, 0, DWORD( length ), nullptr ) )
{
map = MapViewOfFile( hnd, FILE_MAP_READ, 0, 0, length );
CloseHandle( hnd );
}
break;
case PROT_WRITE:
if( hnd = CreateFileMapping( HANDLE( _get_osfhandle( fd ) ), nullptr, PAGE_READWRITE, 0, DWORD( length ), nullptr ) )
{
map = MapViewOfFile( hnd, FILE_MAP_WRITE, 0, 0, length );
CloseHandle( hnd );
}
break;
}
return map ? (char*)map + offset : (void*)-1;
}
int munmap( void* addr, size_t length )
{
return UnmapViewOfFile( addr ) != 0 ? 0 : -1;
}
#endif

View file

@ -1,19 +0,0 @@
#ifndef __MMAP_HPP__
#define __MMAP_HPP__
#ifndef _WIN32
# include <sys/mman.h>
#else
# include <string.h>
# include <sys/types.h>
# define PROT_READ 1
# define PROT_WRITE 2
# define MAP_SHARED 0
void* mmap( void* addr, size_t length, int prot, int flags, int fd, off_t offset );
int munmap( void* addr, size_t length );
#endif
#endif

View file

@ -1,13 +0,0 @@
diff --git a/thirdparty/etcpak/Bitmap.cpp b/thirdparty/etcpak/Bitmap.cpp
index 6aa36f5caa..ef318318ac 100644
--- a/thirdparty/etcpak/Bitmap.cpp
+++ b/thirdparty/etcpak/Bitmap.cpp
@@ -3,7 +3,7 @@
#include <string.h>
#include <assert.h>
-#include "libpng/png.h"
+#include <png.h>
#include "lz4/lz4.h"
#include "Bitmap.hpp"

View file

@ -1,64 +0,0 @@
diff --git a/thirdparty/etcpak/BlockData.cpp b/thirdparty/etcpak/BlockData.cpp
index bd738085f3..395b55246b 100644
--- a/thirdparty/etcpak/BlockData.cpp
+++ b/thirdparty/etcpak/BlockData.cpp
@@ -334,10 +334,10 @@ static etcpak_force_inline void DecodeT( uint64_t block, uint32_t* dst, uint32_t
const auto c3b = clampu8( cb1 - table59T58H[codeword] );
const uint32_t col_tab[4] = {
- cr0 | ( cg0 << 8 ) | ( cb0 << 16 ) | 0xFF000000,
- c2r | ( c2g << 8 ) | ( c2b << 16 ) | 0xFF000000,
- cr1 | ( cg1 << 8 ) | ( cb1 << 16 ) | 0xFF000000,
- c3r | ( c3g << 8 ) | ( c3b << 16 ) | 0xFF000000
+ uint32_t(cr0 | ( cg0 << 8 ) | ( cb0 << 16 ) | 0xFF000000),
+ uint32_t(c2r | ( c2g << 8 ) | ( c2b << 16 ) | 0xFF000000),
+ uint32_t(cr1 | ( cg1 << 8 ) | ( cb1 << 16 ) | 0xFF000000),
+ uint32_t(c3r | ( c3g << 8 ) | ( c3b << 16 ) | 0xFF000000)
};
const uint32_t indexes = ( block >> 32 ) & 0xFFFFFFFF;
@@ -389,10 +389,10 @@ static etcpak_force_inline void DecodeTAlpha( uint64_t block, uint64_t alpha, ui
const auto c3b = clampu8( cb1 - table59T58H[codeword] );
const uint32_t col_tab[4] = {
- cr0 | ( cg0 << 8 ) | ( cb0 << 16 ),
- c2r | ( c2g << 8 ) | ( c2b << 16 ),
- cr1 | ( cg1 << 8 ) | ( cb1 << 16 ),
- c3r | ( c3g << 8 ) | ( c3b << 16 )
+ uint32_t(cr0 | ( cg0 << 8 ) | ( cb0 << 16 )),
+ uint32_t(c2r | ( c2g << 8 ) | ( c2b << 16 )),
+ uint32_t(cr1 | ( cg1 << 8 ) | ( cb1 << 16 )),
+ uint32_t(c3r | ( c3g << 8 ) | ( c3b << 16 ))
};
const uint32_t indexes = ( block >> 32 ) & 0xFFFFFFFF;
@@ -436,10 +436,10 @@ static etcpak_force_inline void DecodeH( uint64_t block, uint32_t* dst, uint32_t
const auto codeword = codeword_hi | codeword_lo;
const uint32_t col_tab[] = {
- clampu8( r0 + table59T58H[codeword] ) | ( clampu8( g0 + table59T58H[codeword] ) << 8 ) | ( clampu8( b0 + table59T58H[codeword] ) << 16 ),
- clampu8( r0 - table59T58H[codeword] ) | ( clampu8( g0 - table59T58H[codeword] ) << 8 ) | ( clampu8( b0 - table59T58H[codeword] ) << 16 ),
- clampu8( r1 + table59T58H[codeword] ) | ( clampu8( g1 + table59T58H[codeword] ) << 8 ) | ( clampu8( b1 + table59T58H[codeword] ) << 16 ),
- clampu8( r1 - table59T58H[codeword] ) | ( clampu8( g1 - table59T58H[codeword] ) << 8 ) | ( clampu8( b1 - table59T58H[codeword] ) << 16 )
+ uint32_t(clampu8( r0 + table59T58H[codeword] ) | ( clampu8( g0 + table59T58H[codeword] ) << 8 ) | ( clampu8( b0 + table59T58H[codeword] ) << 16 )),
+ uint32_t(clampu8( r0 - table59T58H[codeword] ) | ( clampu8( g0 - table59T58H[codeword] ) << 8 ) | ( clampu8( b0 - table59T58H[codeword] ) << 16 )),
+ uint32_t(clampu8( r1 + table59T58H[codeword] ) | ( clampu8( g1 + table59T58H[codeword] ) << 8 ) | ( clampu8( b1 + table59T58H[codeword] ) << 16 )),
+ uint32_t(clampu8( r1 - table59T58H[codeword] ) | ( clampu8( g1 - table59T58H[codeword] ) << 8 ) | ( clampu8( b1 - table59T58H[codeword] ) << 16 ))
};
for( uint8_t j = 0; j < 4; j++ )
@@ -483,10 +483,10 @@ static etcpak_force_inline void DecodeHAlpha( uint64_t block, uint64_t alpha, ui
const auto tbl = g_alpha[(alpha >> 48) & 0xF];
const uint32_t col_tab[] = {
- clampu8( r0 + table59T58H[codeword] ) | ( clampu8( g0 + table59T58H[codeword] ) << 8 ) | ( clampu8( b0 + table59T58H[codeword] ) << 16 ),
- clampu8( r0 - table59T58H[codeword] ) | ( clampu8( g0 - table59T58H[codeword] ) << 8 ) | ( clampu8( b0 - table59T58H[codeword] ) << 16 ),
- clampu8( r1 + table59T58H[codeword] ) | ( clampu8( g1 + table59T58H[codeword] ) << 8 ) | ( clampu8( b1 + table59T58H[codeword] ) << 16 ),
- clampu8( r1 - table59T58H[codeword] ) | ( clampu8( g1 - table59T58H[codeword] ) << 8 ) | ( clampu8( b1 - table59T58H[codeword] ) << 16 )
+ uint32_t(clampu8( r0 + table59T58H[codeword] ) | ( clampu8( g0 + table59T58H[codeword] ) << 8 ) | ( clampu8( b0 + table59T58H[codeword] ) << 16 )),
+ uint32_t(clampu8( r0 - table59T58H[codeword] ) | ( clampu8( g0 - table59T58H[codeword] ) << 8 ) | ( clampu8( b0 - table59T58H[codeword] ) << 16 )),
+ uint32_t(clampu8( r1 + table59T58H[codeword] ) | ( clampu8( g1 + table59T58H[codeword] ) << 8 ) | ( clampu8( b1 + table59T58H[codeword] ) << 16 )),
+ uint32_t(clampu8( r1 - table59T58H[codeword] ) | ( clampu8( g1 - table59T58H[codeword] ) << 8 ) | ( clampu8( b1 - table59T58H[codeword] ) << 16 ))
};
for( uint8_t j = 0; j < 4; j++ )

View file

@ -1,66 +0,0 @@
diff --git a/thirdparty/etcpak/System.cpp b/thirdparty/etcpak/System.cpp
index 1383d0ecd0..041f2676e8 100644
--- a/thirdparty/etcpak/System.cpp
+++ b/thirdparty/etcpak/System.cpp
@@ -2,7 +2,6 @@
#ifdef _WIN32
# include <windows.h>
#else
-# include <pthread.h>
# include <unistd.h>
#endif
@@ -35,7 +34,7 @@ unsigned int System::CPUCores()
void System::SetThreadName( std::thread& thread, const char* name )
{
-#ifdef _WIN32
+#ifdef _MSC_VER
const DWORD MS_VC_EXCEPTION=0x406D1388;
# pragma pack( push, 8 )
@@ -62,7 +61,5 @@ void System::SetThreadName( std::thread& thread, const char* name )
__except(EXCEPTION_EXECUTE_HANDLER)
{
}
-#elif !defined(__APPLE__)
- pthread_setname_np( thread.native_handle(), name );
#endif
}
diff --git a/thirdparty/etcpak/TaskDispatch.cpp b/thirdparty/etcpak/TaskDispatch.cpp
index 7287da4de2..b1ba17953b 100644
--- a/thirdparty/etcpak/TaskDispatch.cpp
+++ b/thirdparty/etcpak/TaskDispatch.cpp
@@ -1,5 +1,8 @@
#include <assert.h>
#include <stdio.h>
+#ifndef _MSC_VER
+#include <pthread.h>
+#endif
#include "Debug.hpp"
#include "System.hpp"
@@ -22,15 +25,19 @@ TaskDispatch::TaskDispatch( size_t workers )
{
char tmp[16];
sprintf( tmp, "Worker %zu", i );
-#ifdef __APPLE__
+#ifdef _MSC_VER
+ auto worker = std::thread( [this]{ Worker(); } );
+ System::SetThreadName( worker, tmp );
+#else // Using pthread.
auto worker = std::thread( [this, tmp]{
+#ifdef __APPLE__
pthread_setname_np( tmp );
+#else // Linux or MinGW.
+ pthread_setname_np( pthread_self(), tmp );
+#endif
Worker();
} );
-#else
- auto worker = std::thread( [this]{ Worker(); } );
#endif
- System::SetThreadName( worker, tmp );
m_workers.emplace_back( std::move( worker ) );
}

View file

@ -1,50 +0,0 @@
diff --git a/thirdparty/etcpak/BlockData.cpp b/thirdparty/etcpak/BlockData.cpp
index a2cd032c5b..bd738085f3 100644
--- a/thirdparty/etcpak/BlockData.cpp
+++ b/thirdparty/etcpak/BlockData.cpp
@@ -15,7 +15,7 @@
# include <arm_neon.h>
#endif
-#ifdef __SSE4_1__
+#if defined __SSE4_1__ || defined __AVX2__ || defined _MSC_VER
# ifdef _MSC_VER
# include <intrin.h>
# include <Windows.h>
@@ -24,12 +24,6 @@
# else
# include <x86intrin.h>
# endif
-#else
-# ifndef _MSC_VER
-# include <byteswap.h>
-# define _bswap(x) bswap_32(x)
-# define _bswap64(x) bswap_64(x)
-# endif
#endif
#ifndef _bswap
diff --git a/thirdparty/etcpak/ProcessRGB.cpp b/thirdparty/etcpak/ProcessRGB.cpp
index 220d5c55e2..9dc5a78b67 100644
--- a/thirdparty/etcpak/ProcessRGB.cpp
+++ b/thirdparty/etcpak/ProcessRGB.cpp
@@ -1,5 +1,6 @@
#include <array>
#include <string.h>
+#include <limits>
#ifdef __ARM_NEON
# include <arm_neon.h>
@@ -21,12 +22,6 @@
# else
# include <x86intrin.h>
# endif
-#else
-# ifndef _MSC_VER
-# include <byteswap.h>
-# define _bswap(x) bswap_32(x)
-# define _bswap64(x) bswap_64(x)
-# endif
#endif
#ifndef _bswap