which is the function to make a color in 16 bits an d24 bits?
and
which is the function to separate a color in the 3 values of the colors base in 16 and 24 bits?
Posted on 2004-09-01 23:26:52 by avis_phoenix
There's no such function, since its format is really simple:


_16BIT_Color macro red,green,blue
exitm <((red AND 248) SHL 8) + ((green AND 252) SHL 3) + (blue SHR 3))> ; RRRRR.GGGGGG.BBBBB
endm

In 16-bit color, the least significant 5 bits are Blue, then 6 bits for green and 5 bits for red. This is for the commonly-used 565 format.
The 24-bit is RRRRRRRRGGGGGGGGBBBBBBBB


Make16BitColor proc Red,Green,Blue
shr Red,3
shr Green,2
shr Blue,3
mov eax,Red
shl eax,5
or eax,Green
shl eax,6
or eax,Blue
ret ; color is in eax, or ax
Make16BitColor endp
Make24BitColor proc Red,Green,Blue
mov eax,Red
shl eax,8
or eax,Green
shl eax,8
or eax,Blue
ret ; color is in eax
Make24BitColor endp

GetColorsFrom16bit proc The16bitColor
mov eax,The16bitColor
shl eax,3
movzx eax,ax
mov ebx,The16bitColor
shr ebx,5
shl ebx,2
movzx ebx,bl
mov ecx,The16bitColor
shr ecx,11
shl ecx,3
movzx ecx,cl
ret ; red in ecx, green in ebx, blue in eax
GetColorsFrom16bit endp

GetColorsFrom24bit proc The24bitColor
mov ecx,The24bitColor
movzx ebx,ch
movzx eax,cl
shr ecx,16
ret ; red in ecx, green in ebx, blue in eax
GetColorsFrom24bit endp
Posted on 2004-09-10 05:30:34 by Ultrano
XRRRRRGGGGGBBBBB

and

XXXXRRRRGGGGBBBB

are two other 16-bit image formats you may encounter.

Spara
Posted on 2004-10-21 23:28:43 by Sparafusile
here are my routines :)
taking adventages of registers ( by using them ) for a few extra Mips


; A - Alpha R - Red G - Green B - Blue
;8-bit could be (after setting 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
Posted on 2004-11-09 06:57:40 by >Matrix<
Cool I take it. :-D Do you have another function and you will spread it for free?
Posted on 2004-11-15 07:24:00 by realvampire
of course :)
i used to flood Flat Assembler Board with my advanced codes
Posted on 2004-11-18 23:55:35 by >Matrix<