From cd93a5de110c2045278606cee37829304ed36689 Mon Sep 17 00:00:00 2001 From: snake5 Date: Sat, 26 Nov 2016 16:45:40 +0200 Subject: [PATCH 1/4] added basic 3Dc support --- stb_dxt.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/stb_dxt.h b/stb_dxt.h index 0a8b34a..31b36d4 100644 --- a/stb_dxt.h +++ b/stb_dxt.h @@ -32,6 +32,7 @@ #define STB_DXT_HIGHQUAL 2 // high quality mode, does two refinement steps instead of 1. ~30-40% slower. void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode); +void stb_compress_3dc_block_rgxx8(unsigned char *dest, const unsigned char *src, int mode); #define STB_COMPRESS_DXT_BLOCK #ifdef STB_DXT_IMPLEMENTATION @@ -625,6 +626,12 @@ void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int a stb__CompressColorBlock(dest,(unsigned char*) src,mode); } + +void stb_compress_3dc_block_rgxx8(unsigned char *dest, const unsigned char *src, int mode) +{ + stb__CompressAlphaBlock(dest,(unsigned char*) src - 3,mode); + stb__CompressAlphaBlock(dest + 8,(unsigned char*) src - 2,mode); +} #endif // STB_DXT_IMPLEMENTATION #endif // STB_INCLUDE_STB_DXT_H From a217948c16b939b1491ae1776da5440c9230d1fa Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Fri, 3 Mar 2017 08:49:08 -0800 Subject: [PATCH 2/4] change 3dc name to bc5 --- stb_dxt.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/stb_dxt.h b/stb_dxt.h index ebe445c..2bc5831 100644 --- a/stb_dxt.h +++ b/stb_dxt.h @@ -1,4 +1,4 @@ -// stb_dxt.h - v1.04 - DXT1/DXT5 compressor - public domain +// stb_dxt.h - v1.05 - DXT1/DXT5 compressor - public domain // original by fabian "ryg" giesen - ported to C by stb // use '#define STB_DXT_IMPLEMENTATION' before including to create the implementation // @@ -9,6 +9,7 @@ // and "high quality" using mode. // // version history: +// v1.05 - (stb) support bc5/3dc (Arvids Kokins) // v1.04 - (ryg) default to no rounding bias for lerped colors (as per S3TC/DX10 spec); // single color match fix (allow for inexact color interpolation); // optimal DXT5 index finder; "high quality" mode that runs multiple refinement steps. @@ -30,7 +31,7 @@ #define STB_DXT_HIGHQUAL 2 // high quality mode, does two refinement steps instead of 1. ~30-40% slower. void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode); -void stb_compress_3dc_block_rgxx8(unsigned char *dest, const unsigned char *src, int mode); +void stb_compress_bc5_block_rg88(unsigned char *dest, const unsigned char *src, int mode); #define STB_COMPRESS_DXT_BLOCK #ifdef STB_DXT_IMPLEMENTATION @@ -537,7 +538,7 @@ static void stb__CompressColorBlock(unsigned char *dest, unsigned char *block, i } // Alpha block compression (this is easy for a change) -static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src,int mode) +static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src, int stride) { int i,dist,bias,dist4,dist2,bits,mask; @@ -567,7 +568,7 @@ static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src,int m bits = 0,mask=0; for (i=0;i<16;i++) { - int a = src[i*4+3]*7 + bias; + int a = src[i*stride]*7 + bias; int ind,t; // select index. this is a "linear scale" lerp factor between 0 (val=min) and 7 (val=max). @@ -618,17 +619,17 @@ void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int a } if (alpha) { - stb__CompressAlphaBlock(dest,(unsigned char*) src,mode); + stb__CompressAlphaBlock(dest,(unsigned char*) src+3, 4); dest += 8; } stb__CompressColorBlock(dest,(unsigned char*) src,mode); } -void stb_compress_3dc_block_rgxx8(unsigned char *dest, const unsigned char *src, int mode) +void stb_compress_bc5_block_rg88(unsigned char *dest, const unsigned char *src) { - stb__CompressAlphaBlock(dest,(unsigned char*) src - 3,mode); - stb__CompressAlphaBlock(dest + 8,(unsigned char*) src - 2,mode); + stb__CompressAlphaBlock(dest,(unsigned char*) src,2); + stb__CompressAlphaBlock(dest + 8,(unsigned char*) src+1,2); } #endif // STB_DXT_IMPLEMENTATION #endif // STB_INCLUDE_STB_DXT_H From 4ce23da44aeca01bc70a87b4913bd986383f05c9 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Fri, 3 Mar 2017 08:54:44 -0800 Subject: [PATCH 3/4] rename 3dc to bc5, tweaks to clean stuff up --- stb_dxt.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stb_dxt.h b/stb_dxt.h index 2bc5831..bcf44b8 100644 --- a/stb_dxt.h +++ b/stb_dxt.h @@ -30,8 +30,8 @@ #define STB_DXT_DITHER 1 // use dithering. dubious win. never use for normal maps and the like! #define STB_DXT_HIGHQUAL 2 // high quality mode, does two refinement steps instead of 1. ~30-40% slower. -void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode); -void stb_compress_bc5_block_rg88(unsigned char *dest, const unsigned char *src, int mode); +void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src_rgba_four_bytes_per_pixel, int alpha, int mode); +void stb_compress_bc5_block(unsigned char *dest, const unsigned char *src_rg_two_byte_per_pixel, int mode); #define STB_COMPRESS_DXT_BLOCK #ifdef STB_DXT_IMPLEMENTATION @@ -626,7 +626,7 @@ void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int a stb__CompressColorBlock(dest,(unsigned char*) src,mode); } -void stb_compress_bc5_block_rg88(unsigned char *dest, const unsigned char *src) +void stb_compress_bc5_block(unsigned char *dest, const unsigned char *src) { stb__CompressAlphaBlock(dest,(unsigned char*) src,2); stb__CompressAlphaBlock(dest + 8,(unsigned char*) src+1,2); From 6ba52a370c27e024bb451f2f28ad3f58c4007190 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Fri, 3 Mar 2017 08:57:34 -0800 Subject: [PATCH 4/4] stb_dxt: extern "C" --- stb_dxt.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stb_dxt.h b/stb_dxt.h index bcf44b8..55384bd 100644 --- a/stb_dxt.h +++ b/stb_dxt.h @@ -9,7 +9,7 @@ // and "high quality" using mode. // // version history: -// v1.05 - (stb) support bc5/3dc (Arvids Kokins) +// v1.05 - (stb) support bc5/3dc (Arvids Kokins), use extern "C" in C++ (Pavel Krajcevski) // v1.04 - (ryg) default to no rounding bias for lerped colors (as per S3TC/DX10 spec); // single color match fix (allow for inexact color interpolation); // optimal DXT5 index finder; "high quality" mode that runs multiple refinement steps. @@ -30,8 +30,17 @@ #define STB_DXT_DITHER 1 // use dithering. dubious win. never use for normal maps and the like! #define STB_DXT_HIGHQUAL 2 // high quality mode, does two refinement steps instead of 1. ~30-40% slower. +#ifdef __cplusplus +extern "C" { +#endif + void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src_rgba_four_bytes_per_pixel, int alpha, int mode); void stb_compress_bc5_block(unsigned char *dest, const unsigned char *src_rg_two_byte_per_pixel, int mode); + +#ifdef __cplusplus +} +#endif + #define STB_COMPRESS_DXT_BLOCK #ifdef STB_DXT_IMPLEMENTATION