 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jon Lennart Aasenden Guest
|
Posted: Thu Mar 24, 2005 11:55 am Post subject: 15 & 16 BPP color conversion LUT? |
|
|
Hi.
I have heard that you can build a conversion LUT for 15 & 16 BPP colors,
making it very fast to convert 24bit RGB values. Could anyone point me in
the right direction?
Is there somewhere i can download some code, or could someone show me how
its done?
Jon Lennart Aasenden
|
|
| Back to top |
|
 |
Boris Novgorodov Guest
|
Posted: Sat Mar 26, 2005 6:34 am Post subject: Re: 15 & 16 BPP color conversion LUT? |
|
|
| Quote: | I have heard that you can build a conversion LUT for 15 & 16 BPP colors,
making it very fast to convert 24bit RGB values. Could anyone point me in
|
LUT15:array[0..32767] of TColor;
function ColorFrom15(Col15: Word): TColor;
asm
mov ecx,eax
and ecx,$1F //Blue
imul ecx,541052 //Scaling
mov edx,eax
and ecx,$FF0000 //Blue Mask
and edx,$3E0 //Green
imul edx,135263
and eax,$7C00
shr edx,11
imul eax,135263 //Red
and edx,$FF00 //Green Mask
shr eax,24
or eax,ecx
or eax,edx
end;
function ColorFrom16(Col16: Word): TColor;
asm
mov ecx,eax
and ecx,$1F
imul ecx,541052
and ecx,$FF0000
mov edx,eax
and edx,$7E0
imul edx,135263
shr edx,12
and eax,$F800
and edx,$FF00
imul eax,135263
shr eax,24
or eax,ecx
or eax,edx
end;
procedure TForm1.Button1Click(Sender: TObject);
var
w: Word;
r: TRect;
begin
for w := 0 to 32767 do
LUT15[w] := ColorFrom15(w);
for w := 0 to 32767 do begin
Canvas.Brush.Color := LUT15[w];
r.Top := (w div 256) * 3;
r.Left := (w mod 256) * 2;
r.Right := r.Left + 2;
r.Bottom := r.Top + 3;
Canvas.FillRect(r);
end;
end;
--
Regards
Boris Novgorodov
|
|
| Back to top |
|
 |
Jon Lennart Aasenden Guest
|
Posted: Sat Mar 26, 2005 12:03 pm Post subject: Re: 15 & 16 BPP color conversion LUT? |
|
|
Wowy!
eh.. do you have that without assembler?
Im working on a project that is 100% native pascal.
It would mean a lot.
Thank you for a great example!
Jon Lennart Aasenden
"Boris Novgorodov" <mbo (AT) mail (DOT) ru> wrote
| Quote: | I have heard that you can build a conversion LUT for 15 & 16 BPP colors,
making it very fast to convert 24bit RGB values. Could anyone point me
in
LUT15:array[0..32767] of TColor;
function ColorFrom15(Col15: Word): TColor;
asm
mov ecx,eax
and ecx,$1F //Blue
imul ecx,541052 //Scaling
mov edx,eax
and ecx,$FF0000 //Blue Mask
and edx,$3E0 //Green
imul edx,135263
and eax,$7C00
shr edx,11
imul eax,135263 //Red
and edx,$FF00 //Green Mask
shr eax,24
or eax,ecx
or eax,edx
end;
function ColorFrom16(Col16: Word): TColor;
asm
mov ecx,eax
and ecx,$1F
imul ecx,541052
and ecx,$FF0000
mov edx,eax
and edx,$7E0
imul edx,135263
shr edx,12
and eax,$F800
and edx,$FF00
imul eax,135263
shr eax,24
or eax,ecx
or eax,edx
end;
procedure TForm1.Button1Click(Sender: TObject);
var
w: Word;
r: TRect;
begin
for w := 0 to 32767 do
LUT15[w] := ColorFrom15(w);
for w := 0 to 32767 do begin
Canvas.Brush.Color := LUT15[w];
r.Top := (w div 256) * 3;
r.Left := (w mod 256) * 2;
r.Right := r.Left + 2;
r.Bottom := r.Top + 3;
Canvas.FillRect(r);
end;
end;
--
Regards
Boris Novgorodov
|
|
|
| Back to top |
|
 |
Boris Novgorodov Guest
|
Posted: Sun Mar 27, 2005 12:49 pm Post subject: Re: 15 & 16 BPP color conversion LUT? |
|
|
| Quote: | eh.. do you have that without assembler?
|
function ColorFrom15(w:word):TColor;
begin
Result := (((w and $1F) * 541052) and $FF0000) or
(((((w and $3E0) shr 5) * 541052) shr and $FF00) or
((((w and $7C00) shr 10) * 541052) shr 16);
end;
function ColorFrom16(w:word):TColor;
Result := (((w and $1F) * 541052) and $FF0000) or
(((((w and $7E0) shr 5) * 266231) shr and $FF00) or
((((w and $F800) shr 11) * 541052) shr 16);
--
Regards
Boris Novgorodov
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|