Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added more reference material

  • Loading branch information...
commit 46a8f31855a96d0d841b7d7d14db4e8fff2efec5 1 parent 864886f
AJ ONeal authored
BIN  test/reference.rgb565
Binary file not shown
BIN  test/reference.rgb888
Binary file not shown
31 test/rgba-test.js
... ... @@ -0,0 +1,31 @@
  1 + function rgba2short(rgba, i) {
  2 + var r = rgba[i + 0] >> 3 // 5
  3 + , g = rgba[i + 1] >> 2 // 6 (3, 3)
  4 + , g1 = (g >> 3) // 3 higher bits
  5 + , g2 = (g & 0x7) // 3 lower bits
  6 + , b = rgba[i + 2] >> 3 // 5
  7 + , a = rgba[i + 3] >> 8 // n/a
  8 + , one
  9 + , two
  10 + ;
  11 +
  12 + var one = (r << 3) | g1;
  13 + var two = (g2 << 5) | b;
  14 + return [one, two];
  15 + }
  16 +
  17 + // 248 252 248
  18 + rgba2short([255, 0, 0, 255], 0); // 248, 0
  19 + rgba2short([0, 0, 255, 255], 0); // 0, 31
  20 + rgba2short([0, 255, 0, 255], 0); // 7, 224
  21 +
  22 + rgba2short([128, 0, 0, 255], 0);
  23 + rgba2short([0, 128, 0, 255], 0);
  24 + rgba2short([0, 0, 128, 255], 0);
  25 +
  26 + function short2rgba(rg, gb) {
  27 + var red = (rg & ~0x7); // knock of the last 3 green bits, leave red bits high values
  28 + var green = ((((rg & 0x7) << 3) | (gb & 0xE0) >> 5)) << 2; // good luck understanding this
  29 + var blue = (gb & ~0xE0) << 3;
  30 + return [red, green, blue, 255];
  31 + }

0 comments on commit 46a8f31

Please sign in to comment.
Something went wrong with that request. Please try again.