PDA

View Full Version : TCanvas.Pixels palette entries



Crisp_N_Dry
23-03-2006, 11:56 PM
Seems like a simple question but Canvas.Pixels[X,Y] has been causing me problems. I have loaded an 8 bit bitmap into a TBitmap. It has loaded correctly and the PixelFormat value is showing as pf8Bit. Only problem is, when I go to access the pixels and try to retrieve the palette entry for a particular pixel it is returning the actual colour value for that pixel rather than the palette index that the pixel contains. I need the palette index, not the colour. Any tips?

tpascal
25-03-2006, 04:11 PM
Hi,

Use tbitmap.scanline[row]. which returns a pointer to a complete row of pixels raw data. For 256 color bitmaps each byte in that block memory represet the index color into the pallete for every pixel in that line.


Btw, this is a old function i have:

procedure xGetBitmapBits(var bitmap:tbitmap; size:longint; buf:pointer);

It gets the whole bitmap into a memory block so i can do faster low level proccesing to the picture. Then i can put back edited pixel info using similar xSetbitmapbits procedure.

good luck.



procedure xGetBitmapBits(var bitmap:tbitmap; size:longint; buf:pointer);
var
p:pointer;
bpp:integer;
lsize:integer;
y,k:integer;
buf2:longint;

begin

bpp:=2;
case bitmap.pixelformat of
pf8bit : bpp:=1;
pf15bit,pf16bit: bpp:=2;
pf24bit : bpp:=3;
pf32bit : bpp:=4;
end;
lsize:=bitmap.width*bpp;
k:=size div lsize; if k=0 then k:=1;
if lsize>size then lsize:=size;
buf2:=longint(buf);

for y:=1 to k do
begin
p:=bitmap.scanline[y-1];
move(p^,pointer(buf2)^,lsize);
buf2:=buf2+lsize;
end;


end;
//----------------

Crisp_N_Dry
26-03-2006, 08:52 PM
Dammit, completely forgot about Scanline. It's been a while. Cheers.