flat assembler
Message board for the users of flat assembler.

Index > Main > rgb 8bit, rgb 16bit, rgb 24bit, rgb 32bit formats

Author
Thread Post new topic Reply to topic
jdawg



Joined: 26 Jun 2005
Posts: 39
jdawg
The pros probably already know about this, but I thought I throw it out since I hadn't seen any posts about it yet. Also if anybody knows a more efficient way of doing this please let me know.

macro rgb16bit555 r,g,b
{
mov eax,b
mov ebx,31
and eax,ebx
mov ecx,g
mov ebx,31
and ecx,ebx
shl ecx,5
add eax,ecx
mov ecx,r
mov ebx,31
and ecx,ebx
add eax,ecx
}
Post 21 Oct 2005, 22:33
View user's profile Send private message Reply with quote
jdawg



Joined: 26 Jun 2005
Posts: 39
jdawg
Actually don't use this one yet. I tried to rewrite it from memory. give me a day or two and I'll post the rgb16bit555 the rgb16bit565 the rgb24bit and rgb32bit(8 bit alpha mode). I can't remember how many spaces to shift left on the previous one, give me until tomorrow and I'll have all the correct posts.

IN OTHER WORDS MY BAD!
Post 21 Oct 2005, 22:36
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
you are really right, there are not much info about this hanging around,
so i share these little codes with you i wrote before, hope one might find them useful, they meant to be fast-small
Code:
; A - Alpha R - Red G - Green B - Blue
;8-bit could be, depends on how you set up the palett:
;RRGGGBBB - 233
;RRRGGBBB - 323
;RRRGGGBB - 332
;RRGGGBB - 232 +1 reserved

;16-bit is RRRRRRGGGGGGBBBBB - 565
;24-bit is RRRRRRRRGGGGGGGGBBBBBBBB - 888
;32-bit is AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB - 8888

mix16bitcolor: ; ah=Red al=Green bl=Blue returns:ax=16bit 565 color
shl al,2
shl ax,3       ; where 5 bit=32, 6 bit=64 !
or al,bl
ret

mix16bitcolor3: ; al=Red bl=Green cl=Blue returns:ax=16bit 565 color
shl ax,6        ; where 5 bit=32, 6 bit=64 !
or al,bl
shl ax,5
or al,cl
ret

mix16bitcolor8: ; ah=Red al=Green bl=Blue returns:ax=16bit 888 (565) color
shr ah,3
shr ax,2
shl ax,5
shr bl,3
or al,bl
ret

get16bitrgb: ;  ax=16bit 565 color returns:ah=Red al=Green bl=Blue
mov bl,al    ; where 5 bit=32, 6 bit=64 !
and bl,11111b
shr ax,3
shl ah,2
shr ax,2
ret

get16bitrgb3: ;  ax=16bit 565 color returns:al=Red bl=Green cl=Blue
mov cl,al    ; where 5 bit=32, 6 bit=64 !
and cl,11111b
shr ax,5
mov bl,al
and bl,111111b
shr ax,6
ret

get16bitrgb8: ;  ax=16bit 888 (565) color returns:ah=Red al=Green bl=Blue
mov bl,al
shl bl,3
shr ax,5
shl ax,2
shl ah,3
ret

mix24bitcolor: ; ah=Red al=Green bl=Blue returns:eax=24bit 888 color
shl eax,8
or al,bl
ret

get24bitrgb: ;  eax=24bit 888 color returns:ah=Red al=Green bl=Blue
mov bl,al
shr eax,8
ret

mix32bitcolor: ; ah=Alpha al=Red bh=Green bl=Blue returns:eax=32bit 8888 color
shl eax,16
or ax,bx
ret

get32bitrgb: ;  eax=32bit 888 color returns:ah=Alpha al=Red bh=Green bl=Blue
mov bx,ax
shr eax,16
ret
    
Post 21 Oct 2005, 23:58
View user's profile Send private message Visit poster's website Reply with quote
Hayden



Joined: 06 Oct 2005
Posts: 132
Hayden
I asume your codeing for DOS since DX has all the macros you need for this.
Anyway it is best to use the VESA func 4F01h int 10h to return the alignment
for the RGB palette. (some cards are 5:5:5 and others are 5:6:5).

func 4F01h returns all the info about a mode in a low DOS user buffer es:di.
All you need to do is SHL each channel by the facter given in the mode info buffer and OR them together.

func 4F01h also returns a mask size for each channel so you can easily create color masks.

for VESA func 4F01h structure info visit www.vesa.org and download vbe30.pdf.

p.s. I'm currently porting a VBE library I wrote in Euphoria to FASM but this is currently on the back burner since I have other priorities. good luck, have fun.

_________________
New User.. Hayden McKay.
Post 24 Oct 2005, 01:22
View user's profile Send private message Reply with quote
jdawg



Joined: 26 Jun 2005
Posts: 39
jdawg
Thanks for adding guys, and sorry I took so long but here are the working macros I said I would post.

;~~This macro builds a 16bit RGB 5.5.5 format color value (1 bit alpha mode)
macro rgb16bit555 r,g,b
{
mov eax,b
mov ebx,31
and eax,ebx
mov ecx,g
mov ebx,31
and ecx,ebx
shl ecx,5
add eax,ecx
mov ecx,r
mov ebx,31
and ecx,ebx
shl ecx,10
add eax,ecx
}

;~~This macro build a 16bit rgb 5.6.5 color value (green dominant mode)
macro rgb16bit565 r,g,b
{
mov eax,b
mov ebx,31
and eax,ebx
mov ecx,g
mov ebx,63
and ecx,ebx
shl ecx,5
add eax,ecx
mov ecx,r
mov ebx,31
and ecx,ebx
shl ecx,11
add eax,ecx
}

;~~This macro builds a 24bit 8.8.8 format color value (ignored alpha mode?)
macro rgb24bit a,r,g,b
{
mov eax,b
mov ecx,g
shl ecx,8
add eax,ecx
mov ecx,r
shl ecx,16
add eax,ecx
}

;~~This macro builds a 32bit A.8.8.8 format color value (8 bit alpha mode)
macro rgb32bitA8 a,r,g,b
{
mov eax,b
mov ecx,g
shl ecx,8
add eax,ecx
mov ecx,r
shl ecx,16
add eax,ecx
mov ecx,a
shl ecx,24
add eax,ecx
}
Post 24 Oct 2005, 23:08
View user's profile Send private message Reply with quote
uri



Joined: 09 Apr 2004
Posts: 44
Location: L'viv, Ukraine
uri
Code:
macro   rgb16bit555 r,g,b { mov eax, (b and 0x1F) or ((g and 0x1F) shl 5) or ((r and 0x1F) shl 10) }
    
Post 28 Oct 2005, 12:31
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.