Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Background: Mechanism: RECT
#2
hello Ikran. Nice article, but I have to say it is a little too long. Sorry if I am missing the points of your article, but if you are trying to have a formulation to convert rect numbers to RGB colors, here is a fairly accurate routine I used in F.LF background implementation. The rect code in LF2 is not much a mystery. I am pretty sure it is a RGB 5:5:5 format, each color taking 5bits, the 1bit remaining has special effect.
Code:
var lookup, computed;
switch (rect)
{
    case 4706: lookup='rgb(16,79,16)'; break; //lion forest
    case 40179: lookup='rgb(159,163,159)'; break; //HK Coliseum
    case 29582: lookup='rgb(119,119,119)'; break;
    case 37773: lookup='rgb(151,119,111)'; break;
    case 33580: lookup='rgb(135,107,103)'; break;
    case 25356: lookup='rgb(103,103,103)'; break;
    case 21096: lookup='rgb(90,78,75)'; break; //Stanley Prison
    case 37770: lookup='rgb(154,110,90)'; break; //The Great Wall
    case 16835: lookup='rgb(66,56,24)'; break; //Queen's Island
    case 34816: lookup='rgb(143,7,7)'; break; //Forbidden Tower
}
var r = (rect>>11<<3),
    g = (rect>>6&31)<<3,
    b = ((rect&31)<<3);
computed = 'rgb('+
    (r+(r>64||r===0?7:0))+','+
    (g+(g>64||g===0?7:0)+((rect>>5&1)&&g>80?4:0))+','+
    (b+(b>64||b===0?7:0))+
    ')';
if( lookup && computed!==lookup)
    console.log('error! computed:'+computed,'correct:'+lookup);
if( lookup)
    return lookup;
else
    return computed;
basically bit 1-5 is for B, bit 7-11 is for G, bit 12-16 is for R. thse bits make the 5 most significant bits of the 8-bit channel value. the 3 least significant bits are either 111 or 000. for example 33580, binary is 10000 01100 1 01100, take 10000 and pad 111 gives 10000111 which is 135, 01100111 is 103. which converts 33580 into rgb(135,107,103). note, the G channel value is 103+4=107, which I suspect is due to the magic bit. Anyway, it is possible that LF2 keeps a color table internally, then there may not be a general mathematical formula for this conversion process.

cheers
Reply
Thanks given by: Ikran Ahiyìk , Silverthorn , STM1993


Messages In This Thread
Mechanism: RECT - by Ikran Ahiyìk - 12-31-2013, 02:00 PM
RE: Mechanism: RECT - by tyt2y3 - 01-01-2014, 03:53 AM
RE: Mechanism: RECT - by YinYin - 01-01-2014, 12:20 PM
RE: Mechanism: RECT - by Ikran Ahiyìk - 01-01-2014, 05:36 AM
RE: Mechanism: RECT - by tyt2y3 - 01-01-2014, 06:03 AM
RE: Mechanism: RECT - by Ikran Ahiyìk - 01-01-2014, 01:21 PM
RE: Mechanism: RECT - by YinYin - 01-01-2014, 02:49 PM



Users browsing this thread: 1 Guest(s)