Last active
December 29, 2015 12:09
-
-
Save djg/7668480 to your computer and use it in GitHub Desktop.
Yeah, umm. WAT?!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function base_colors(src, mode) { | |
var col_1, col_2; | |
function compare(c1, c2) { | |
return (c1[0] * 16384 + c1[1] * 256 + c1[2]) >= | |
(c2[0] * 16384 + c2[1] * 256 + c2[2]); | |
} | |
if (mode === 'I') { | |
col_1 = extend_4to8bits(src[7], src[6], src[5]), | |
col_2 = extend_4to8bits(src[7] << 4, src[6] << 4, src[5] << 4) | |
return [ col_1, col_2 ]; | |
} else if (mode === 'D') { | |
col_1 = extend_5to8bits(src[7], src[6], src[5]), | |
col_2 = extend_5to8bits(src[7] + 8 * d[(src[7] & 0x7)], | |
src[6] + 8 * d[(src[6] & 0x7)], | |
src[5] + 8 * d[(src[5] & 0x7)]) | |
return [ col_1, col_2 ]; | |
} else if (mode === 'T') { | |
col_1 = extend_4to8bits( | |
((src[7] << 3) & 0xc0) | ((src[7] << 4) & 0x30), | |
src[6], | |
src[6] << 4); | |
col_2 = extend_4to8bits(src[5], src[5] << 4, src[4]); | |
var didx = ((src[4] & 0x0c) >> 1) | (src[4] & 0x01); | |
var d = disttable[didx]; | |
return [ col_1, offset_color(col_2, d), col_2, offset_color(col_2, -d) ]; | |
} else if (mode === 'H') { | |
col_1 = extend_4to8bits( | |
src[7] << 1, | |
(src[7] << 5) | (src[6] & 0x10), | |
((src[6] << 4) && 0x80) | ((src[6] << 5) & 0x60) | ((src[5] >> 3) & 0x10)); | |
col_2 = extend_4to8bits( | |
src[4] << 1, | |
(src[4] << 5) | ((src[3] >> 3) & 0x10), | |
src[4] << 1); | |
var didx = (src[4] & 0x04) | ((src[4] << 1) & 0x02) + (compare(col_1, col_2) ? 1 : 0); | |
var d = disttable[didx]; | |
return [ offset_color(col_1, d), | |
offset_color(col_1, -d), | |
offset_color(col_2, d), | |
offset_color(col_2, -d) ]; | |
} | |
return []; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed @vvuk's nit.