Skip to content
Myr

stb_dxt: fix bug with constant color & varying alpha

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 76ec599 · Browse files · 2 files+13 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−6 removed

  • other:+13 added−6 removed

2 files+13 added−6 removed

modified:stb_dxt.h+11 added-2 removed
1// stb_dxt.h - v1.07 - DXT1/DXT5 compressor - public domain1// stb_dxt.h - v1.08 - 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.08 - (sbt) fix bug in dxt-with-alpha block12// v1.07 - bc4; allow not using libc; add STB_DXT_STATIC13// v1.07 - (stb) bc4; allow not using libc; add STB_DXT_STATIC14// v1.06 - (stb) fix to known-broken 1.0515// v1.05 - (stb) support bc5/3dc (Arvids Kokins), use extern "C" in C++ (Pavel Krajcevski)16// v1.04 - (ryg) default to no rounding bias for lerped colors (as per S3TC/DX10 spec);17// single color match fix (allow for inexact color interpolation);
631 unmodified lines
649}650651void stb_compress_dxt_block(unsigned char *dest, const unsigned char *src, int alpha, int mode)652{653 unsigned char *data[16][4];654 static int init=1;655 if (init) {656 stb__InitDXT();657 init=0;658 }659660 if (alpha) {661 int i;662 stb__CompressAlphaBlock(dest,(unsigned char*) src+3, 4);663 dest += 8;664 // make a new copy of the data in which alpha is opaque,665 // because code uses a fast test for color constancy666 memcpy(data, src, 4*16);667 for (i=0; i < 16; ++i)668 data[i][3] = 255;669 src = &data[0][0];670 }671672 stb__CompressColorBlock(dest,(unsigned char*) src,mode);673}
55 unmodified lines
modified:stb_image.h+2 added-4 removed
1/* stb_image - v2.17 - public domain image loader - http://nothings.org/stb_image.h2 no warranty implied; use at your own risk1/* stb_image - v2.17 - public domain image loader - http://nothings.org/stb2 no warranty implied; use at your own risk34 Do this:5 #define STB_IMAGE_IMPLEMENTATION6 before you include this file in *one* C or C++ file to create the implementation.
99 unmodified lines
106107// DOCUMENTATION108//109// Limitations:110// - no 16-bit-per-channel PNG110// - no 12-bit-per-channel JPEG111// - no JPEGs with arithmetic coding113// - no 1-bit BMP112// - GIF always returns *comp=4113//114// Basic usage (see HDR discussion below for HDR usage):115// int x,y,n;
7336 unmodified lines