Merge branch 'h-s-c-stb_dxt-freestanding' into dev
This commit is contained in:
commit
24f2522e00
32
stb_dxt.h
32
stb_dxt.h
@ -19,6 +19,9 @@
|
|||||||
// v1.01 - (stb) fix bug converting to RGB that messed up quality, thanks ryg & cbloom
|
// v1.01 - (stb) fix bug converting to RGB that messed up quality, thanks ryg & cbloom
|
||||||
// v1.00 - (stb) first release
|
// v1.00 - (stb) first release
|
||||||
//
|
//
|
||||||
|
// contributors:
|
||||||
|
// Kevin Schmidt
|
||||||
|
//
|
||||||
// LICENSE
|
// LICENSE
|
||||||
//
|
//
|
||||||
// See end of file for license information.
|
// See end of file for license information.
|
||||||
@ -61,8 +64,23 @@ void stb_compress_bc5_block(unsigned char *dest, const unsigned char *src_rg_two
|
|||||||
// #define STB_DXT_USE_ROUNDING_BIAS
|
// #define STB_DXT_USE_ROUNDING_BIAS
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#if !defined(STBD_ABS) || !defined(STBI_FABS)
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h> // memset
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBD_ABS
|
||||||
|
#define STBD_ABS(i) abs(i)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBD_FABS
|
||||||
|
#define STBD_FABS(x) fabs(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STBD_MEMSET
|
||||||
|
#include <string.h>
|
||||||
|
#define STBD_MEMSET(x) memset(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
static unsigned char stb__Expand5[32];
|
static unsigned char stb__Expand5[32];
|
||||||
static unsigned char stb__Expand6[64];
|
static unsigned char stb__Expand6[64];
|
||||||
@ -127,13 +145,13 @@ static void stb__PrepareOptTable(unsigned char *Table,const unsigned char *expan
|
|||||||
for (mx=0;mx<size;mx++) {
|
for (mx=0;mx<size;mx++) {
|
||||||
int mine = expand[mn];
|
int mine = expand[mn];
|
||||||
int maxe = expand[mx];
|
int maxe = expand[mx];
|
||||||
int err = abs(stb__Lerp13(maxe, mine) - i);
|
int err = STBD_ABS(stb__Lerp13(maxe, mine) - i);
|
||||||
|
|
||||||
// DX10 spec says that interpolation must be within 3% of "correct" result,
|
// DX10 spec says that interpolation must be within 3% of "correct" result,
|
||||||
// add this as error term. (normally we'd expect a random distribution of
|
// add this as error term. (normally we'd expect a random distribution of
|
||||||
// +-1.5% error, but nowhere in the spec does it say that the error has to be
|
// +-1.5% error, but nowhere in the spec does it say that the error has to be
|
||||||
// unbiased - better safe than sorry).
|
// unbiased - better safe than sorry).
|
||||||
err += abs(maxe - mine) * 3 / 100;
|
err += STBD_ABS(maxe - mine) * 3 / 100;
|
||||||
|
|
||||||
if(err < bestErr)
|
if(err < bestErr)
|
||||||
{
|
{
|
||||||
@ -165,7 +183,7 @@ static void stb__DitherBlock(unsigned char *dest, unsigned char *block)
|
|||||||
for (ch=0; ch<3; ++ch) {
|
for (ch=0; ch<3; ++ch) {
|
||||||
unsigned char *bp = block+ch, *dp = dest+ch;
|
unsigned char *bp = block+ch, *dp = dest+ch;
|
||||||
unsigned char *quant = (ch == 1) ? stb__QuantGTab+8 : stb__QuantRBTab+8;
|
unsigned char *quant = (ch == 1) ? stb__QuantGTab+8 : stb__QuantRBTab+8;
|
||||||
memset(err, 0, sizeof(err));
|
STBD_MEMSET(err, 0, sizeof(err));
|
||||||
for(y=0; y<4; ++y) {
|
for(y=0; y<4; ++y) {
|
||||||
dp[ 0] = quant[bp[ 0] + ((3*ep2[1] + 5*ep2[0]) >> 4)];
|
dp[ 0] = quant[bp[ 0] + ((3*ep2[1] + 5*ep2[0]) >> 4)];
|
||||||
ep1[0] = bp[ 0] - dp[ 0];
|
ep1[0] = bp[ 0] - dp[ 0];
|
||||||
@ -349,9 +367,9 @@ static void stb__OptimizeColorsBlock(unsigned char *block, unsigned short *pmax1
|
|||||||
vfb = b;
|
vfb = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
magn = fabs(vfr);
|
magn = STBD_FABS(vfr);
|
||||||
if (fabs(vfg) > magn) magn = fabs(vfg);
|
if (STBD_FABS(vfg) > magn) magn = STBD_FABS(vfg);
|
||||||
if (fabs(vfb) > magn) magn = fabs(vfb);
|
if (STBD_FABS(vfb) > magn) magn = STBD_FABS(vfb);
|
||||||
|
|
||||||
if(magn < 4.0f) { // too small, default to luminance
|
if(magn < 4.0f) { // too small, default to luminance
|
||||||
v_r = 299; // JPEG YCbCr luma coefs, scaled by 1000.
|
v_r = 299; // JPEG YCbCr luma coefs, scaled by 1000.
|
||||||
|
Loading…
Reference in New Issue
Block a user