Recent

Author Topic: More info for PTCGraph users - bitmap data layout  (Read 277 times)

TBMan

  • Sr. Member
  • ****
  • Posts: 355
More info for PTCGraph users - bitmap data layout
« on: November 25, 2025, 05:21:46 am »
I guess I live under a rock, but I took the time tonight to figure out how ptcgraph (on a windows system) stores the bitmap for getimage and put image.

Code: Pascal  [Select][+][-]
  1. type
  2. TPackedsprite= packed record
  3.       width,height,
  4.       extra:dword;
  5.       colors:array of word;
  6.     end;                              
  7.  
  8. var
  9. workingbitmap :pointer = NIL;
  10.  
  11. // and assuming you set the sprite to the size you want and the colors is set to your imagedata...
  12. //  You could probably use a multi dimensional array also, but I didn't work with that
  13.  
  14. procedure namehere(x,y:integer;sprite:TPackedSprite);
  15. begin
  16. if workingbitmap = nil then
  17.   begin
  18.      sz := imagesize(0,0,sprite.width-1,sprite.height-1);
  19.      getmem(Workingbitmap,sz);
  20.      getimage(0,0,sprite.width-1,sprite.height-1,Workingbitmap^);
  21.   end;
  22.  move(sprite.colors,pointer(PtrUint(Workingbitmap)+4*sizeof(dword)-sizeof(word)*2)^, (sprite.height*sprite.width)*sizeof(word));
  23. putimage(x,y,workingbitmap^,0);    
  24. end;
  25.  

So what I do is use the workingbitmap through the app without allocating memory everytime I want to use it. I will just freemem the image at the end of the app. (I make the sz variable global);

I was using this to display my playing cards:

Code: Pascal  [Select][+][-]
  1. index := 0;
  2. for r := 0 to sprite.height-1 do
  3.   for c := 0 to sprite.width-1 do
  4.      begin
  5.         putpixel(x+c,y+r,sprite.colors[index]);
  6.         inc(index);
  7. end;
  8.  

Which is more than 10 times slower than using the putimage example above.
Barry

Newest game (clone),
Missile Commander:
https://www.youtube.com/watch?v=tgKz0cxog-k

 

TinyPortal © 2005-2018