Skip to content
Myr

change 3dc name to bc5

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 · parent c390637 · Browse files · 1 file+9 added−8 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+9 added−8 removed

  • other:+9 added−8 removed

1 file+9 added−8 removed

modified:stb_dxt.h+9 added-8 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 lines
8// 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)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 support
13 unmodified lines
30#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.3233void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode);33void stb_compress_3dc_block_rgxx8(unsigned char *dest, const unsigned char *src, int mode);34void stb_compress_bc5_block_rg88(unsigned char *dest, const unsigned char *src, int mode);35#define STB_COMPRESS_DXT_BLOCK3637#ifdef STB_DXT_IMPLEMENTATION38
498 unmodified lines
537 dest[7] = (unsigned char) (mask >> 24);538}539540// Alpha block compression (this is easy for a change)540static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src,int mode)541static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src, int stride)542{543 int i,dist,bias,dist4,dist2,bits,mask;544545 // find min/max color
21 unmodified lines
567 bias -= mn * 7;568 bits = 0,mask=0;569 570 for (i=0;i<16;i++) {570 int a = src[i*4+3]*7 + bias;571 int a = src[i*stride]*7 + bias;572 int ind,t;573574 // select index. this is a "linear scale" lerp factor between 0 (val=min) and 7 (val=max).575 t = (a >= dist4) ? -1 : 0; ind = t & 4; a -= dist4 & t;
42 unmodified lines
618 init=0;619 }620621 if (alpha) {621 stb__CompressAlphaBlock(dest,(unsigned char*) src,mode);622 stb__CompressAlphaBlock(dest,(unsigned char*) src+3, 4);623 dest += 8;624 }625626 stb__CompressColorBlock(dest,(unsigned char*) src,mode);627}628628void stb_compress_3dc_block_rgxx8(unsigned char *dest, const unsigned char *src, int mode)629void stb_compress_bc5_block_rg88(unsigned char *dest, const unsigned char *src)630{630 stb__CompressAlphaBlock(dest,(unsigned char*) src - 3,mode);631 stb__CompressAlphaBlock(dest + 8,(unsigned char*) src - 2,mode);631 stb__CompressAlphaBlock(dest,(unsigned char*) src,2);632 stb__CompressAlphaBlock(dest + 8,(unsigned char*) src+1,2);633}634#endif // STB_DXT_IMPLEMENTATION635#endif // STB_INCLUDE_STB_DXT_H636
41 unmodified lines