Hi, I've been trying to convert a 24 bit RGB value to it's 16bit equivalent. I've written this macro and would like for anyone interested to see if it produces expected results for them.
It seems to do the job but I'm still not too certain about the output format(especially the bit fields for the green component.) have I got it right.
Can it be done faster?



rt_eaxtoRGB16 macro
;;24bit RGB to 16 bit RGB. The input order of the colors is xxBBGGRR
shr eax,3 ;;required to scale rgb components from 24 to 16bit
rol al,2
ror eax,5
ror ah,3
rol eax,3
exitm <ax> ;;BGR(5-6-5)(BBBBB-GGGGG0-RRRRR)
endm
Posted on 2002-08-05 19:51:30 by MArtial_Code
shr eax,3
shl al,2
shl ax,3
shr eax,5

Does the same as your code, and the least bit of green is wrong.
Posted on 2002-08-05 21:28:01 by bitRAKE
Hi bitRake

I had used a mask of 001F3F1FH to clear the upper bits of each byte after the initial shr eax,3
that's why I had the output as (BBBBB-GGGGG0-RRRRR)
Without the masking the lsb of green is 1 or 0 depending on what red was.
The thing is, it works on all of the images I've used so far. When i use the full six bits for the green then the images turn out wrong.

I've tried googling for the info but there's alot of stuff to go thru.

If no one has a better way then i'll use the bitRake version until i come against an image which it displays incorrectly

cheers bitRake
Posted on 2002-08-06 04:27:51 by MArtial_Code
This code from Direct X library. Here another 16-bit format 0bbbbbgggggrrrrr.


label Mode16
dq 00F800F800F800F8h ; mask Red & Blue
dq 0000FC000000FC00h ; mask Green
dq 2000000420000004h ; scale
label Mode15
dq 00F800F800F800F8h
dq 0000F8000000F800h
dq 2000000820000008h

macro PageShowHicolor ProcName,Mode,Shift
align PAL
proc ProcName
call PageLock
lea eax,[Mode]
movq mm4,[eax+0]
movq mm5,[eax+8]
movq mm6,[eax+16]
mov ecx,[ebx+sMP.ScrSizeX]
mov eax,[ebx+sMP.ScrSizeY]
mov ebx,ecx
@@: movq mm0,[esi+0]
movq mm2,[esi+8]
add esi,16
movq mm1,mm0
movq mm3,mm2
pand mm0,mm4
pand mm1,mm5
pmaddwd mm0,mm6
pand mm2,mm4
pand mm3,mm5
pmaddwd mm2,mm6
paddd mm0,mm1
paddd mm2,mm3
psrld mm0,Shift
psrld mm2,Shift
packssdw mm0,mm2
movq [edi],mm0
add edi,2*4
sub ecx,4
jg @B
add edi,edx
dec eax
mov ecx,ebx
jne @B
emms
jmp PageUnlock
endp
endm

PageShowHicolor PageShow16,Mode15,6
PageShowHicolor PageShow15,Mode16,5

Posted on 2002-08-08 10:16:52 by Nexo