Skip to content
Myr

Merge branch 'master' of https://github.com/haferburg/stb into work2

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 95dc062, 905d05a · Browse files · 1 file+19 added−19 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+19 added−19 removed

  • other:+19 added−19 removed

1 file+19 added−19 removed

modified:stb_dxt.h+19 added-19 removed
119 unmodified lines
120}121122static unsigned short stb__As16Bit(int r, int g, int b)123{124 return (stb__Mul8Bit(r,31) << 11) + (stb__Mul8Bit(g,63) << 5) + stb__Mul8Bit(b,31);124 return (unsigned short)((stb__Mul8Bit(r,31) << 11) + (stb__Mul8Bit(g,63) << 5) + stb__Mul8Bit(b,31));125}126127// linear interpolation at 1/3 point between a and b, using desired rounding type128static int stb__Lerp13(int a, int b)
10 unmodified lines
139140// lerp RGB color141static void stb__Lerp13RGB(unsigned char *out, unsigned char *p1, unsigned char *p2)142{143 out[0] = stb__Lerp13(p1[0], p2[0]);144 out[1] = stb__Lerp13(p1[1], p2[1]);145 out[2] = stb__Lerp13(p1[2], p2[2]);143 out[0] = (unsigned char)stb__Lerp13(p1[0], p2[0]);144 out[1] = (unsigned char)stb__Lerp13(p1[1], p2[1]);145 out[2] = (unsigned char)stb__Lerp13(p1[2], p2[2]);146}147148/****************************************************************************/149
13 unmodified lines
163 // add this as error term. (normally we'd expect a random distribution of164 // +-1.5% error, but nowhere in the spec does it say that the error has to be165 // unbiased - better safe than sorry).166 err += STBD_ABS(maxe - mine) * 3 / 100;167 167168 if(err < bestErr)169 { 170 Table[i*2+0] = mx;171 Table[i*2+1] = mn;169 {170 Table[i*2+0] = (unsigned char)mx;171 Table[i*2+1] = (unsigned char)mn;172 bestErr = err;173 }174 }175 }
312 unmodified lines
488 frb = 3.0f * 31.0f / 255.0f / (xx*yy - xy*xy);489 fg = frb * 63.0f / 31.0f;490491 // solve.492 max16 = stb__sclamp((At1_r*yy - At2_r*xy)*frb+0.5f,0,31) << 11;493 max16 |= stb__sclamp((At1_g*yy - At2_g*xy)*fg +0.5f,0,63) << 5;494 max16 |= stb__sclamp((At1_b*yy - At2_b*xy)*frb+0.5f,0,31) << 0;492 max16 = (unsigned short)(stb__sclamp((At1_r*yy - At2_r*xy)*frb+0.5f,0,31) << 11);493 max16 |= (unsigned short)(stb__sclamp((At1_g*yy - At2_g*xy)*fg +0.5f,0,63) << 5);494 max16 |= (unsigned short)(stb__sclamp((At1_b*yy - At2_b*xy)*frb+0.5f,0,31) << 0);495496 min16 = stb__sclamp((At2_r*xx - At1_r*xy)*frb+0.5f,0,31) << 11;497 min16 |= stb__sclamp((At2_g*xx - At1_g*xy)*fg +0.5f,0,63) << 5;498 min16 |= stb__sclamp((At2_b*xx - At1_b*xy)*frb+0.5f,0,31) << 0;496 min16 = (unsigned short)(stb__sclamp((At2_r*xx - At1_r*xy)*frb+0.5f,0,31) << 11);497 min16 |= (unsigned short)(stb__sclamp((At2_g*xx - At1_g*xy)*fg +0.5f,0,63) << 5);498 min16 |= (unsigned short)(stb__sclamp((At2_b*xx - At1_b*xy)*frb+0.5f,0,31) << 0);499 }500501 *pmin16 = min16;502 *pmax16 = max16;
89 unmodified lines
592 else if (src[i*stride] > mx) mx = src[i*stride];593 }594595 // encode them596 ((unsigned char *)dest)[0] = mx;597 ((unsigned char *)dest)[1] = mn;596 dest[0] = (unsigned char)mx;597 dest[1] = (unsigned char)mn;598 dest += 2;599600 // determine bias and emit color indices601 // given the choice of mx/mn, these indices are optimal:
20 unmodified lines
622623 // write index624 mask |= ind << bits;625 if((bits += 3) >= 8) {626 *dest++ = mask;626 *dest++ = (unsigned char)mask;627 mask >>= 8;628 bits -= 8;629 }630 }
2 unmodified lines
633static void stb__InitDXT()634{635 int i;636 for(i=0;i<32;i++)637 stb__Expand5[i] = (i<<3)|(i>>2);637 stb__Expand5[i] = (unsigned char)((i<<3)|(i>>2));638639 for(i=0;i<64;i++)640 stb__Expand6[i] = (i<<2)|(i>>4);640 stb__Expand6[i] = (unsigned char)((i<<2)|(i>>4));641642 for(i=0;i<256+16;i++)643 {644 int v = i-8 < 0 ? 0 : i-8 > 255 ? 255 : i-8;
85 unmodified lines