Skip to content
Myr

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

1 file+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 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), 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 support
12 unmodified lines
29#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.3233#ifdef __cplusplus34extern "C" {35#endif3632void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode);37void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src_rgba_four_bytes_per_pixel, int alpha, int mode);38void stb_compress_bc5_block(unsigned char *dest, const unsigned char *src_rg_two_byte_per_pixel, int mode);3940#ifdef __cplusplus41}42#endif4344#define STB_COMPRESS_DXT_BLOCK4546#ifdef STB_DXT_IMPLEMENTATION47
498 unmodified lines
546 dest[7] = (unsigned char) (mask >> 24);547}548549// Alpha block compression (this is easy for a change)539static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src,int mode)550static void stb__CompressAlphaBlock(unsigned char *dest,unsigned char *src, int stride)551{552 int i,dist,bias,dist4,dist2,bits,mask;553554 // find min/max color
21 unmodified lines
576 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;582583 // 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 lines
627 init=0;628 }629630 if (alpha) {620 stb__CompressAlphaBlock(dest,(unsigned char*) src,mode);631 stb__CompressAlphaBlock(dest,(unsigned char*) src+3, 4);632 dest += 8;633 }634635 stb__CompressColorBlock(dest,(unsigned char*) src,mode);636}637638void 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_H645646/*
40 unmodified lines