Merge branch 'working'
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sean Barrett · committed by Sean Barrett · parents 8879908, 6ba52a3 · Browse files · 1 file·+22 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+22 added−5 removed
- other:+22 added−5 removed
Provenance
- Commit
eab4930- Tree
e22def5- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent 1
8879908- Parent 2
6ba52a3
1 file changed+22 added−5 removed
modified:stb_dxt.h+22 added-5 removed
1-// stb_dxt.h - v1.04 - DXT1/DXT5 compressor - public domain1+// stb_dxt.h - v1.05 - DXT1/DXT5 compressor - public domain2 // original by fabian "ryg" giesen - ported to C by stb3 // use '#define STB_DXT_IMPLEMENTATION' before including to create the implementation4 //5 // USAGE:2 unmodified lines8 // A is ignored if you specify alpha=0; you can turn on dithering9 // and "high quality" using mode.10 //11 // version history:12+// v1.05 - (stb) support bc5/3dc (Arvids Kokins), use extern "C" in C++ (Pavel Krajcevski)13 // v1.04 - (ryg) default to no rounding bias for lerped colors (as per S3TC/DX10 spec);14 // single color match fix (allow for inexact color interpolation);15 // optimal DXT5 index finder; "high quality" mode that runs multiple refinement steps.16 // v1.03 - (stb) endianness support12 unmodified lines29 #define STB_DXT_NORMAL 030 #define STB_DXT_DITHER 1 // use dithering. dubious win. never use for normal maps and the like!31 #define STB_DXT_HIGHQUAL 2 // high quality mode, does two refinement steps instead of 1. ~30-40% slower.32 33+#ifdef __cplusplus34+extern "C" {35+#endif36+32-void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode);37+void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src_rgba_four_bytes_per_pixel, int alpha, int mode);38+void stb_compress_bc5_block(unsigned char *dest, const unsigned char *src_rg_two_byte_per_pixel, int mode);39+40+#ifdef __cplusplus41+}42+#endif43+44 #define STB_COMPRESS_DXT_BLOCK45 46 #ifdef STB_DXT_IMPLEMENTATION47 498 unmodified lines546 dest[7] = (unsigned char) (mask >> 24);547 }548 549 // Alpha block compression (this is easy for a change)539-static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src,int mode)550+static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src, int stride)551 {552 int i,dist,bias,dist4,dist2,bits,mask;553 554 // find min/max color21 unmodified lines576 bias -= mn * 7;577 bits = 0,mask=0;578 579 for (i=0;i<16;i++) {569- int a = src[i*4+3]*7 + bias;580+ int a = src[i*stride]*7 + bias;581 int ind,t;582 583 // select index. this is a "linear scale" lerp factor between 0 (val=min) and 7 (val=max).584 t = (a >= dist4) ? -1 : 0; ind = t & 4; a -= dist4 & t;42 unmodified lines627 init=0;628 }629 630 if (alpha) {620- stb__CompressAlphaBlock(dest,(unsigned char*) src,mode);631+ stb__CompressAlphaBlock(dest,(unsigned char*) src+3, 4);632 dest += 8;633 }634 635 stb__CompressColorBlock(dest,(unsigned char*) src,mode);636 }637+638+void stb_compress_bc5_block(unsigned char *dest, const unsigned char *src)639+{640+ stb__CompressAlphaBlock(dest,(unsigned char*) src,2);641+ stb__CompressAlphaBlock(dest + 8,(unsigned char*) src+1,2);642+}643 #endif // STB_DXT_IMPLEMENTATION644 #endif // STB_INCLUDE_STB_DXT_H645 646 /*40 unmodified lines