2014-02-07 00:44:01 -08:00
// File: rg_etc1.h - Fast, high quality ETC1 block packer/unpacker - Rich Geldreich <richgel99@gmail.com>
// Please see ZLIB license at the end of this file.
2014-02-12 17:13:29 -08:00
# ifndef __RG_ETC1_H__
# define __RG_ETC1_H__
2014-02-07 00:44:01 -08:00
2014-02-12 17:13:29 -08:00
typedef unsigned char bool ;
// Unpacks an 8-byte ETC1 compressed block to a block of 4x4 32bpp RGBA pixels.
// Returns false if the block is invalid. Invalid blocks will still be unpacked with clamping.
// This function is thread safe, and does not dynamically allocate any memory.
// If preserve_alpha is true, the alpha channel of the destination pixels will not be overwritten. Otherwise, alpha will be set to 255.
bool rg_etc1_unpack_block ( const void * pETC1_block , unsigned int * pDst_pixels_rgba , bool preserve_alpha ) ;
2014-02-07 00:44:01 -08:00
2014-02-12 17:13:29 -08:00
// Quality setting = the higher the quality, the slower.
// To pack large textures, it is highly recommended to call pack_etc1_block() in parallel, on different blocks, from multiple threads (particularly when using cHighQuality).
typedef enum {
rg_etc1_low_quality ,
rg_etc1_medium_quality ,
rg_etc1_high_quality
} rg_etc1_quality ;
2014-02-07 00:44:01 -08:00
2014-02-12 17:13:29 -08:00
typedef struct
{
rg_etc1_quality m_quality ;
bool m_dithering ;
2014-05-07 18:48:35 -07:00
} rg_etc1_pack_params ;
2014-02-12 17:13:29 -08:00
2014-05-07 18:48:35 -07:00
// pack_etc1_block_init() should be called before calling pack_etc1_block(),
// Otherwise rg_etc1_pack_block() will call rg_etc1_pack_block_init() for you.
2015-11-26 08:27:01 -08:00
void rg_etc1_pack_block_init ( void ) ;
2014-02-07 00:44:01 -08:00
2014-05-07 18:48:35 -07:00
// Packs a 4x4 block of 32bpp BGRA pixels to an 8-byte ETC1 block.
// 32-bit BGRA pixels must always be arranged as (B,G,R,A) (B first, A last) in memory, independent of platform endianness. A should always be 255.
2014-02-12 17:13:29 -08:00
// Returns squared error of result.
// This function is thread safe, and does not dynamically allocate any memory.
// pack_etc1_block() does not currently support "perceptual" colorspace metrics - it primarily optimizes for RGB RMSE.
2014-05-07 18:48:35 -07:00
unsigned int rg_etc1_pack_block ( void * pETC1_block , const unsigned int * pSrc_pixels_BGRA , rg_etc1_pack_params * pack_params ) ;
2014-02-07 00:44:01 -08:00
2014-05-26 23:02:23 -07:00
// Pack a 4x4 block of 32bpp BGRA pixels to a 16-byte RGBA8_ETC2_EAC block (supports alpha).
unsigned int etc2_rgba8_block_pack ( unsigned char * etc2 , const unsigned int * bgra , rg_etc1_pack_params * params ) ;
// Pack a 4x4 block of 32bpp BGRA pixels to a 8-byte RGB8_ETC2 block (opaque).
unsigned int etc2_rgb8_block_pack ( unsigned char * etc2 , const unsigned int * bgra , rg_etc1_pack_params * params ) ;
2014-04-29 22:10:33 -07:00
// ETC2 support: RGB8_ETC2
2014-05-27 20:04:36 -07:00
void rg_etc2_rgb8_decode_block ( const unsigned char * etc_block , unsigned int * bgra ) ;
2014-04-29 22:10:33 -07:00
// ETC2 support: RGBA8_ETC2_EAC
2014-05-27 20:04:36 -07:00
void rg_etc2_rgba8_decode_block ( const unsigned char * etc_block , unsigned int * bgra ) ;
2014-04-29 22:10:33 -07:00
2014-02-07 00:44:01 -08:00
//------------------------------------------------------------------------------
//
// rg_etc1 uses the ZLIB license:
// http://opensource.org/licenses/Zlib
//
// Copyright (c) 2012 Rich Geldreich
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
//------------------------------------------------------------------------------
2014-02-12 17:13:29 -08:00
# endif // __RG_ETC1_H__