[fpc-pascal] Implementing AggPas with PtcGraph

James Richters james at productionautomation.net
Wed May 31 13:51:48 CEST 2017


I was doing some tests with Putpixel and that seems to be a word in the format of RGBA with 4 bits each.    I would think putimage would use the same format, but I haven't tested that yet.

I'm still a bit confused by putimage, since it only has an X and Y startpoint, how do you define the height and width of the bitmap? Getimage() specifies a rectangle, and imagesize() figures out how much memory you need, but I just don't what defines the size and shape of the image to putimage.

I managed to get the test out of the buffer and onto the screen with :

  function getBufItemAsByte(aDelta: Word): Byte;
  var
    actualY: Integer;
    thing:Byte;
  begin
    actualY := ImageHeight - y - 1;
    thing :=
      byte(buf[x * RGBA_Width + actualY * ImageWidth * RGBA_Width + aDelta]);
    result:=thing shr 4;  //colors channels are reduced to 4 bits each, they are not correct
  end;

for x := 0 to ImageWidth - 1 do
   for y := 0 to ImageHeight - 1 do
       begin
          pixelcolor:=(getBufItemAsbyte(2) shl 12)+(getBufItemAsbyte(1) shl 8) +(getBufItemAsbyte(0) shl 4)+getBufItemAsbyte(3);
          putpixel(x,y,pixelcolor);
      end;


James

-----Original Message-----
From: fpc-pascal [mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of Graeme Geldenhuys
Sent: Tuesday, May 30, 2017 8:19 PM
To: fpc-pascal at lists.freepascal.org
Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph

On 2017-05-30 22:37, James Richters wrote:

> Putimage() takes
> Initial X position
> Initial Y position
> Pointer to beginning of memory bitmap

In that case the AggPas code should be even faster, because PutImage() only want a pointer to the bitmap data - thus no need to go through the slow FPImage code to generate a PNG or BMP image. The pixel-by-pixel conversions for FPImage is very slow.

>    Size := ImageSize(10, 20, 30, 40);
>    GetMem(Q, Size);   { Allocate memory on heap }

So you can do pretty much the same with AggPas then. Allocate the memory you need, and attach that as the rendering buffer or AggPas. As I mentioned before, AggPas just needs to know what memory it can write too, and in what format you want that rendered data to be. AggPas supports many render buffer formats. BGR, BGRA, RGB, RGBA, Gray8, rgb555, rgb565 etc etc. And if an existing render buffer format doesn't exist, it is really easy and quick to add a new one - just a few really simple procedures to implement.

See the pf_*.inc files for plenty of examples. The "pf_" prefix stands for "pixel format definition".


> I'm looking at it and I think getimage / putimage are just one byte per pixel... maybe?

I'll see if I can get graph or ptcgraph working working here under 
FreeBSD, then I'll take a look at what pixel format they use.


Regards,
   Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list