procedure tfrmmain.readsprites;
var h, i : integer; fo : cardinal; num : word;
data: array[0..10239] of byte;
tam, n, s, c, r, g, b, y, x : integer;
t : boolean;
bmp : tbitmap;
bmpdata : array[0..3071] of byte; // byte = unsigned char
bi : bitmapinfo; // como no editor de fandoras... para economizar velocidade e memoria
procedure initil;
var il : TImageList;
begin
inc(nvimgs);
if vimgs[nvimgs] <> nil then begin
il := vimgs[nvimgs];
vimgs[nvimgs] := nil;
il.Free;
end;
vimgs[nvimgs] := TImageList.Create(nil);
vimgs[nvimgs].AllocBy := 10;
vimgs[nvimgs].Width := 32;
vimgs[nvimgs].Height := 32;
vimgs[nvimgs].BlendColor := clnone;
vimgs[nvimgs].BkColor := clnone;
vimgs[nvimgs].Masked := true;
end;
begin
// verifica se o arquivo existe
if not fileexists( extractfilepath(paramstr(0)) + 'Tibia.spr') then begin
application.MessageBox('Tibia.spr not found! Exiting...','Ooops',mbokerror);
application.Terminate;
end;
ststatus.Caption := 'Loading Tibia.spr...';
//prepara o primeiro imagelist
nvimgs := 0;
initil;
// prepara o bitmap q servirá de via entre o bmpdata e o il
bmp := tbitmap.Create;
bmp.PixelFormat := pf24bit;
bmp.Height := 32;
bmp.Width := 32;
bmp.Canvas.Brush.Color := clblack;
// carrega o sprite file
h := fileopen(extractfilepath(paramstr(0)) + 'tibia.spr',fmopenread);
fileseek(h,4,0);
fileread(h,num,2);
{$IFDEF DEBUG}
showmessage('Num sprites: ' + inttostr(num));
{$ENDIF}
// pega todos os sprites
i := 0;
while i < num do begin
//a := 6 + i * 4;
fileseek(h,6 + i * 4,0);
fileread(h,fo,4);
// fo = imagem vazia
if fo = 0 then begin
inc(i,1);
bmp.Canvas.FillRect( rect(0,0,32,32) );
if vimgs[nvimgs].Count = MAX_IMAGES_PER_IL then initil;
if vimgs[nvimgs].AddMasked(bmp, clblack ) = -1 then
showmessage(format('error at addmask (sprload): %d (wme?)',[i]));
continue;
end;
fileseek(h,fo,0);
fileread(h,data,10240);
tam := data[3] or data[4] shl 8;
n := 0;
s := 0;
c := 0;
r := 0;
g := 0;
b := 0;
t := false;
fillchar(bmpdata,3072,0); // pinta de preto
// carrega cada pixel
y := 0;
while y < 32 do begin
x := 0;
while x < 32 do begin
// o inicio, quando nao há pixels
// pr fandoras:
// s = pixels transparentes
// c = o numero de pixels na imagem
// t = controla se o pixel é transparente ou nao
if (s = 0) and (c = 0) then begin
s := data[5+n];
inc(n,1);
s := s + (data[5+n] * 256);
inc(n,1);
c := data[5+n];
inc(n,1);
c := c + (data[5+n] * 256);
inc(n,1);
end;
if (s <> 0) or (n >= tam) then begin
r := 0; g := 0; b := 0;
t := false;
if s <> 0 then dec(s,1);
end else
if c <> 0 then begin
// fandoras sugeriu usar max() ao chamar cada cor do sistema rgb ;D
// assim, valores menores que 8 n passam, deixando o preto real para transparencias
r := max(8,data[5+n]);
inc(n,1);
g := max(8,data[5+n]);
inc(n,1);
b := max(8,data[5+n]);
inc(n,1);
dec(c,1);
t := true;
end;
if t then begin
// se n for transparente pinta
bmpdata[(31-y)*96+x*3] := b;
bmpdata[(31-y)*96+x*3+1] := g;
bmpdata[(31-y)*96+x*3+2] := r;
bmp.Canvas.Pixels[x,y] := rgb(r,g,b);
end;
inc(x,1);
end;
inc(y,1);
end;
// estrutura para carregar o bmpdata
bi.bmiHeader.biSize := sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth := 32;
bi.bmiHeader.biHeight := 32;
bi.bmiHeader.biPlanes := 1;
bi.bmiHeader.biBitCount := 24;
bi.bmiHeader.biCompression := BI_RGB;
bi.bmiHeader.biSizeImage := 0;
bi.bmiHeader.biXPelsPerMeter := 32;
bi.bmiHeader.biYPelsPerMeter := 32;
bi.bmiHeader.biClrUsed := 0;
bi.bmiHeader.biClrImportant := 0;
SetDIBitsToDevice(bmp.Canvas.Handle,0,0,32,32,0,0,0,32,@bmpdata,bi,dib_rgb_colors);
// se estiver cheio cria um novo il
if vimgs[nvimgs].Count = MAX_IMAGES_PER_IL then initil;
if vimgs[nvimgs].AddMasked(bmp, clblack ) = -1 then
showmessage(format('error at addmask (sprload): %d (wme?)',[i]));
inc(i,1);
end;
fileclose(h);
bmp.Free;
end;
0
0
a więc znalazłem taki oto edytor mapek i jest w nim taka oto funkcja ładowania obrazków. Ładują się one do imagelistów ale ładowanie jest trochę wolne. CZy wie ktoś co by tu należało zmienić by to przyspeiszyc??