Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

someone could translate this code?

Status
Not open for further replies.

BlackDaimond

Programmer
Aug 16, 2002
8
0
0
SD
need help!!someone could translate this code please?
for(int ii=0;ii<(128*640);ii++)
{
b=((buffer[ii]>>16)& 0xff);
g=((buffer[ii]>>8)& 0xff);
r=(buffer[ii]& 0xff);
buffer[ii]=RGB(b,g,r);
}
thanks!!
[afro]
 
buffer = 81920 double words probably but only 3 bytes used for r,g,b bytes!

ii loops from zero to 81920 in increments

b=third byte of buffer[ii]
g=second byte of buffer[ii]
r=first byte of buffer[ii]

buffer[ii]=RGB(b,g,r) ;converts the 3 bytes into a RGB code.

(order of b,g,r and not r,g,b - i think red and blue are swapped in this routine!)


&quot;People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!&quot;
 
I think that buffer is an array of 32-Bit integers, and you are working an a 80x86 mashine. The best way is to acess the array by its bytes, so you don't have to do any shifting.
Code:
mov  ecx, 128*640-1
lea  esi, buffer
@@LoopStart:
; read the colors 
mov  al, Byte Ptr [esi+ecx*4][0]; read red
;mov  ah, Byte Ptr [esi+ecx*4][1]; read green
mov  bl, Byte Ptr [esi+ecx*4][2]; read blue
; write them in the other order back
mov  Byte Ptr [esi+ecx*4][2], al; write red
;mov  Byte Ptr [esi+ecx*4][1], ah; write green
mov  Byte Ptr [esi+ecx*4][0], bl; write blue
sub  ecx,1
jae  @@LoopStart
Remark: the green-value is not changed, so we don't need to read and write it.
 
In most compilers you can convert it to Assembly in Borland Free compiler you can do bcc32 -S filename.cpp
I would of converted your code but your missing some type defs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top