public static short rgb64ToGbc(long color) {
    long r = color >> 32 & 0xFFFF;
    long g = color >> 16 & 0xFFFF;
    long b = color       & 0xFFFF;
    
    long gbR = (31 * r -  5 * g -      b) / 51200;
    long gbG = (3  * r + 35 * g - 13 * b) / 51200;
    long gbB = (-9 * r -  5 * g + 39 * b) / 51200;

    if (gbR > 0x1f) gbR = 0x1f;
    if (gbR < 0) gbR = 0;
    if (gbG > 0x1f) gbG = 0x1f;
    if (gbG < 0) gbG = 0;
    if (gbB > 0x1f) gbB = 0x1f;
    if (gbB < 0) gbB = 0;

    return (short) (gbB << 10 | gbG << 5 | gbR);
  }