MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / unpack_dxt

Function unpack_dxt

tools/fshtool.c:396–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394/* unpack a DXT packed color */
395
396void unpack_dxt(unsigned char mask, unsigned short col1, unsigned short col2,
397 unsigned char *target)
398{
399 unsigned short r1,g1,b1,r2,g2,b2;
400 r1=8*(col1&31); g1=4*((col1>>5)&63); b1=8*(col1>>11);
401 r2=8*(col2&31); g2=4*((col2>>5)&63); b2=8*(col2>>11);
402
403 switch (mask) {
404 case 0: target[0]=r1; target[1]=g1; target[2]=b1; break;
405 case 1: target[0]=r2; target[1]=g2; target[2]=b2; break;
406 case 2:
407 if (col1>col2) {
408 target[0]=(2*r1+r2)/3; target[1]=(2*g1+g2)/3; target[2]=(2*b1+b2)/3;
409 } else {
410 target[0]=(r1+r2)/2; target[1]=(g1+g2)/2; target[2]=(b1+b2)/2;
411 } break;
412 case 3:
413 if (col1>col2) {
414 target[0]=(r1+2*r2)/3; target[1]=(g1+2*g2)/3; target[2]=(b1+2*b2)/3;
415 } else {
416 target[0]=target[1]=target[2]=0;
417 } break;
418 }
419}
420
421/* pack a DXT 4x4 cell; px = 16 RGB colors; nstep = 2 or 3; dest = 8 bytes */
422

Callers 1

fsh_to_bmpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected