const uint32 R16MASK = 0xf800;
const uint32 G16MASK = 0x07e0;
const uint32 B16MASK = 0x001f;
const uint32 RB16MASK = R16MASK | B16MASK;
const uint32 RB16ROUND= 0x8010;
const uint32 G16ROUND = 0x0400;
// faster blending
// in: 2 muls, 7 adds
uint32 blend16fast( uint32 p1, uint32 p2, uint32 a )
{
const uint32 rbdst = p2 & RB16MASK;
uint32 res = (rbdst + (((p1 & RB16MASK - rbdst) * a + RB16ROUND) >> 5)) & RB16MASK;
const uint32 gdst = p2 & G16MASK;
res += (gdst + (((p1 & G16MASK - gdst) * a + G16ROUND) >> 5)) & G16MASK;
return res;
}
uint32 blend16naive( uint32 a, uint32 b, uint32 alpha )
{
uint32 sb = a & 0x1f;
uint32 sg = (a >> 5) & 0x3f;
uint32 sr = (a >> 11) & 0x1f;
uint32 db = b & 0x1f;
uint32 dg = (b >> 5) & 0x3f;
uint32 dr = (b >> 11) & 0x1f;
return ((((alpha * (sb-db)) >> 8) + db)
| (((alpha * (sg-dg)) >> 8) + dg) << 5
| (((alpha * (sr-dr)) >> 8) + dr) << 11);
}
// this blends 3/4 of p1 with 1/4 of p2 (fixed proportion)
// little less instr. count as full fledged version, but has no (muls, mlas) in it
uint32 blend16quarter( uint32 p1, uint32 p2 )
{
const uint32 a = 8;
const uint32 rbdst = p2 & RB16MASK;
uint32 res = (rbdst + (((p1 & RB16MASK - rbdst) * a + RB16ROUND) >> 5)) & RB16MASK;
const uint32 gdst = p2 & G16MASK;
res += (gdst + (((p1 & G16MASK - gdst) * a + G16ROUND) >> 5)) & G16MASK;
return res;
}
How to start javascript as a .cmd file?
@cc_on /* 2>NUL
@goto BOOTSTRAP */
WScript.echo("Im in a script!");
WScript.Quit(1);
WScript.echo("aaa!!!");
/* ***************************************
@echo "Not supposed to be here"
@exit
:BOOTSTRAP
@cscript //E:JavaScript %~nx0 %*
@rem */