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
Provenance
- Commit
fd4f1f7- Tree
46a9343- Author
Sean Barrett <sean@nothings.org>- Committer
Sean Barrett <sean@nothings.org>- Parent 1
95dc062- Parent 2
905d05a
1 file changed+19 added−19 removed
modified:stb_dxt.h+19 added-19 removed
119 unmodified lines120 }121 122 static 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 }126 127 // linear interpolation at 1/3 point between a and b, using desired rounding type128 static int stb__Lerp13(int a, int b)10 unmodified lines139 140 // lerp RGB color141 static 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 }147 148 /****************************************************************************/149 13 unmodified lines163 // 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- 167+168 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 lines488 frb = 3.0f * 31.0f / 255.0f / (xx*yy - xy*xy);489 fg = frb * 63.0f / 31.0f;490 491 // 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);495 496- 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 }500 501 *pmin16 = min16;502 *pmax16 = max16;89 unmodified lines592 else if (src[i*stride] > mx) mx = src[i*stride];593 }594 595 // 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;599 600 // determine bias and emit color indices601 // given the choice of mx/mn, these indices are optimal:20 unmodified lines622 623 // 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 lines633 static 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));638 639 for(i=0;i<64;i++)640- stb__Expand6[i] = (i<<2)|(i>>4);640+ stb__Expand6[i] = (unsigned char)((i<<2)|(i>>4));641 642 for(i=0;i<256+16;i++)643 {644 int v = i-8 < 0 ? 0 : i-8 > 255 ? 255 : i-8;85 unmodified lines