//***************************************
Part of Delphi4 - unit Unit1;
interface
type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
etc...
private
procedure MakeScreen;
Procedure LoadTexture;
procedure MakeMyTable;
end.
var
Form1: TForm1;
ScreenBuffer,TmpBitmap,TmpBitmap2: Tbitmap;
ScreenBufferStart,TmpBufferStart,TextrBufferStart: PByteArray;
MyBuffer: Array[0..8191] of Byte;
MybufferStart: PByteArray;
etc...
implementation
procedure TForm1.MakeScreen;
begin
ScreenBuffer := TBitmap.create;
try
ScreenBuffer.width := 512; //make a screen buffer use
ScreenBuffer.height := 384; //binary sizes and 32bit pixels
ScreenBuffer.PixelFormat:=pf32bit; //for easier and faster addressing.
Image1.height := ScreenBuffer.height; //assign to image1 and get screen
Image1.width := ScreenBuffer.width; //buffer start address
Image1.Picture.Bitmap := ScreenBuffer; //pointer - ScreenBufferStart.
ScreenBufferStart := Image1.Picture.Bitmap.ScanLine[ScreenBuffer.height-1]; //got pointer
finally
ScreenBuffer.free;
end;
end;
procedure TForm1.LoadTexture; //make a texture buffer - same size as bmp but 32bit
begin //pixels for easier addressing - ORGB extra byte is zero.
TmpBitmap := TBitMap.create;
TmpBitmap2 := TBitMap.create;
try
TmpBitmap.LoadFromFile('test.bmp'); //256x256 Windows bmp 24bit rgb.
TmpBufferStart := TmpBitmap.ScanLine[TmpBitmap.height-1];
TmpBitmap2.width := TmpBitmap.width; //create 32bit ORGB array for pic
TmpBitmap2.height := TmpBitmap.height;
TmpBitmap2.PixelFormat:=pf32bit;
Image2.width := TmpBitmap2.width; //assign to image2 and get screen
Image2.height := TmpBitmap2.height; //buffer start address
Image2.Picture.Bitmap := TmpBitmap2; //pointer - TextrBufferStart
TextrBufferStart := Image2.Picture.Bitmap.ScanLine[TmpBitmap2.height-1]; //got pointer
asm //move all 3byte rgb+0 into 4byte array Texture Map
pushad //save registers - push all double
mov esi,TmpBufferStart //load index colour source pointer.
mov edi,TextrBufferStart //load destination pointer.
mov ecx,256*256 //load number of pixels
@Texture_Loop:
mov bx,[esi] //read 1st Green Blue as word (reading the triples...
add esi,2 //set source to 1st Red ...with eax will cause a..
mov al,[esi] //read 1st Red as byte ..read violation on the..
inc esi //set source for next read rgb ..last rgb read)
shl eax,16 //move Red into correct place
mov ax,bx //move Green Blue into correct place=XRGB
and eax,$00ffffff //AND out top byte = 0RGB
mov [edi],eax //write colour to Texture Map
add edi,4 //set dest for next write doubleword
loop @Texture_Loop
popad //restore registers - pop all double.
end;
finally
TmpBitmap.free;
TmpBitmap2.free;
end;
end;
//*******************************