Bug-fix for Delphi 3.0 graphics.pas

The ByteSwapColors procedure in graphics.pas uses an incorrect method to test for end of loop.
ByteSwapColors is used various places in graphics.pas to convert an array of RGB values (TPaletteEntry) to BGR values (TRGBQuad) and vice versa. The problem is that the first entry of the array is never converted which results in a palette with a wrong color in the first entry.

The only solution is to modify the ByteSwapColors procedure as indicated below.


  procedure ByteSwapColors
Change the lines marked with red.
 
 
procedure ByteSwapColors(var Colors; Count: Integer);
var
  SysInfo: TSystemInfo;
begin
  GetSystemInfo(SysInfo);
  asm
        MOV   EDX, Colors
        MOV   ECX, Count
        DEC   ECX
        JS    @@END
        LEA   EAX, SysInfo
        CMP   [EAX].TSystemInfo.wProcessorLevel, 3
        JE    @@386
  @@1:  MOV   EAX, [EDX+ECX*4]
        BSWAP EAX
        SHR   EAX,8
        MOV   [EDX+ECX*4],EAX
        DEC   ECX
        JNS   @@1
        JMP   @@END
  @@386:
        PUSH  EBX
  @@2:  XOR   EBX,EBX
        MOV   EAX, [EDX+ECX*4]
        MOV   BH, AL
        MOV   BL, AH
        SHR   EAX,16
        SHL   EBX,8
        MOV   BL, AL
        MOV   [EDX+ECX*4],EBX
        DEC   ECX
        JNS   @@2
        POP   EBX
    @@END:
  end;
end;
 


Copyright © 1999 Anders Melander. All rights reserved.