Implementing AggPas with PtcGraph

classic Classic list List threaded Threaded
96 messages Options
12345
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Implementing AggPas with PtcGraph

Zaaphod
>As I mentioned, AggPas can use allocated memory, array, a memory image etc as its rendering buffer. If you want a graphical console program
>(eg: using Linux Console Framebuffer) using AggPas, then render your application output via AggPas to a memory image, then bitblit that image
>to the console graphics output in whatever paint event you have available.

>Using AggPas with desktop GUI applications works pretty much identical as above, except it bitblit's the memory image to the Window Canvas.

What is the best method for getting the memory image to a ptcgraph window?  I have been trying to figure how to use something like putimage to do this but I'm not sure how to do it or if it's even the best way.    I think I probably need to convert the format of the memory buffer or something, but I can't figure out what to do.

I've re-attached Graeme's sample slightly modified to open the ptcgraph window, and attempt to use putimage on line 103 but when I run it I get 217- access violation

Any advice on how to get the image into the window is greatly appreciated.

James

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Agg2DConsole.dpr (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Graeme Geldenhuys-6
On 2017-05-30 20:20, James Richters wrote:
> I've re-attached Graeme's sample slightly modified to open the
> ptcgraph window, and attempt to use putimage on line 103 but when I
> run it I get 217- access violation

I haven't downloaded or looked at ptcgraph at all. A few questions:

  * What parameters does its putimage() function take?
  * Does in support PNG image format natively?

I would imagine that it probably supports BMP only - comping from DOS
and Windows background. If so, change the example program to use a BMP
image instead of a PNG image. In your code you attached you are actually
pushing the c variable, which is a TFPColor record of the last color
retrieve from the AggPas buffer - so no surprise you are getting a AV error.

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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Zaaphod
>  * What parameters does its putimage() function take?
>  * Does in support PNG image format natively?

Putimage() takes
Initial X position
Initial Y position
Pointer to beginning of memory bitmap
Method to use (copy, AND, OR, XOR)  
See https://www.freepascal.org/docs-html/rtl/graph/putimage.html


Here's an example:
Var Q: Pointer;
   Bar(0, 0, (GetMaxX div 3), GetMaxY);
   Size := ImageSize(10, 20, 30, 40);
   GetMem(Q, Size);   { Allocate memory on heap }
   GetImage(10, 20, 30, 40, Q^);
   Readln;
   ClearDevice;
   PutImage(100, 100, Q^, NormalPut);
   readln;
   putimage(0,0,Q^,normalput);
   readln;

I can get this to work with getimage and putimage, but I have no idea how to build the image in memory and just use putimage.

I don't think it really supports any 'image formats'  it's just the TP compatible graphics thing for DOS style graphics.

I'm looking at it and I think getimage / putimage are just one byte per pixel... maybe?  so probably not what I want.
I'm getting the feeling this is apples and oranges here, TP compatible memory map vs tcolor or tfpcolor or some other scheme with 4 bytes per pixel.
Maybe there just isn't anything canned that can do what I want?  Maybe I need to put the pixels on the screen myself using a nested loop and getpixel / putpixel and do whatever logic on my own.

James

-----Original Message-----
From: fpc-pascal [mailto:[hidden email]] On Behalf Of Graeme Geldenhuys
Sent: Tuesday, May 30, 2017 4:55 PM
To: [hidden email]
Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph

On 2017-05-30 20:20, James Richters wrote:
> I've re-attached Graeme's sample slightly modified to open the
> ptcgraph window, and attempt to use putimage on line 103 but when I
> run it I get 217- access violation

I haven't downloaded or looked at ptcgraph at all. A few questions:

  * What parameters does its putimage() function take?
  * Does in support PNG image format natively?

I would imagine that it probably supports BMP only - comping from DOS and Windows background. If so, change the example program to use a BMP image instead of a PNG image. In your code you attached you are actually pushing the c variable, which is a TFPColor record of the last color retrieve from the AggPas buffer - so no surprise you are getting a AV error.

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  -  [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Graeme Geldenhuys-6
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Zaaphod
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:[hidden email]] On Behalf Of Graeme Geldenhuys
Sent: Tuesday, May 30, 2017 8:19 PM
To: [hidden email]
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Zaaphod
>seems to be a word in the format of RGBA with 4 bits each

Well, it seemed to be RGBA, but it's not...  

It's a word with:
5bits red, 6bits green, and 5bits blue like this:

RRRRRGGGGGGBBBBB

I'm not sure what that's called or how to set up aggpas to use that, but that's what it seems to be if ptcgraph is put in a 16bit color mode.  It doesn't seem to be able to go any higher than that, but that's fine for my purposes.

James




-----Original Message-----
From: fpc-pascal [mailto:[hidden email]] On Behalf Of James Richters
Sent: Wednesday, May 31, 2017 7:52 AM
To: 'FPC-Pascal users discussions' <[hidden email]>
Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph

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:[hidden email]] On Behalf Of Graeme Geldenhuys
Sent: Tuesday, May 30, 2017 8:19 PM
To: [hidden email]
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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Reimar Grabowski
On Wed, 31 May 2017 10:47:40 -0400
"James Richters" <[hidden email]> wrote:

> It's a word with:
> 5bits red, 6bits green, and 5bits blue like this:
>
> RRRRRGGGGGGBBBBB
>
> I'm not sure what that's called
RGB565, maybe?

R.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Graeme Geldenhuys-6
On 2017-05-31 18:03, Reimar Grabowski wrote:
>> I'm not sure what that's called
> RGB565, maybe?

And AggPas already has support for that pixel format.

Regards,
   Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Zaaphod
>And AggPas already has support for that pixel format

How do I define that as the format I want?  I've been looking all through the example and do not see how this is defined.  I've attached a test program, it's basically Graeme's sample but going to screen instead of a file.  I just don't see where the pixel format is defined.  I have it kind of working in a funny way by just forcing the existing pixels to conform to the required format.

-----Original Message-----
From: fpc-pascal [mailto:[hidden email]] On Behalf Of Graeme Geldenhuys
Sent: Wednesday, May 31, 2017 1:17 PM
To: [hidden email]
Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph

On 2017-05-31 18:03, Reimar Grabowski wrote:
>> I'm not sure what that's called
> RGB565, maybe?

And AggPas already has support for that pixel format.

Regards,
   Graeme

_______________________________________________
fpc-pascal maillist  -  [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Graphtest2.pas (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Stefan V. Pantazi
Have a look at the agg_2D unit. The agg_2D uses
..
  agg_pixfmt ,
  agg_pixfmt_rgba ,
..

Therefore, the rgba format is pretty much baked in. That is to say that
the constructor of the main object Agg2D uses the pixfmt_rgba32 to set
the pixel format.

...
{ CONSTRUCT }
constructor Agg2D.Construct;
begin
  m_rbuf.Construct;

  pixfmt_rgba32           (m_pixFormat ,@m_rbuf );
  pixfmt_custom_blend_rgba(m_pixFormatComp ,@m_rbuf
,@comp_op_adaptor_rgba ,rgba_order );
  pixfmt_rgba32           (m_pixFormatPre ,@m_rbuf );
  pixfmt_custom_blend_rgba(m_pixFormatCompPre ,@m_rbuf
,@comp_op_adaptor_rgba ,rgba_order );
...

There is another agg unit agg_pixfmt_rgb_packed that seem to have the
565 format that you need. Add it to the uses list and try to replace the
pixfmt_rgba32 calls with pixfmt_rgb565. That will make agg use that format.

The pixfmt_custom_blend_rgba calls may need further hacking too to make
things work, however, Agg2D should use a 16 bit format if you use
pixfmt_rgb565 callse instead of pixfmt_rgba32. You should also set
RGBA_Width =2; in your program to reflect the change.

Anyway, this will probably still not make

ptcgraph.putimage(0,0,buf[0],0);

work, but that may be a ptcgraph problem.


Hope this helps,

Stefan

On 05/31/2017 02:57 PM, James Richters wrote:

>> And AggPas already has support for that pixel format
>
> How do I define that as the format I want?  I've been looking all through the example and do not see how this is defined.  I've attached a test program, it's basically Graeme's sample but going to screen instead of a file.  I just don't see where the pixel format is defined.  I have it kind of working in a funny way by just forcing the existing pixels to conform to the required format.
>
> -----Original Message-----
> From: fpc-pascal [mailto:[hidden email]] On Behalf Of Graeme Geldenhuys
> Sent: Wednesday, May 31, 2017 1:17 PM
> To: [hidden email]
> Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph
>
> On 2017-05-31 18:03, Reimar Grabowski wrote:
>>> I'm not sure what that's called
>> RGB565, maybe?
>
> And AggPas already has support for that pixel format.
>
> Regards,
>    Graeme
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Zaaphod
Thanks for the help. I was able to make a little progress.

>There is another agg unit agg_pixfmt_rgb_packed that seem to have the
>565 format that you need. Add it to the uses list and try to replace the
>pixfmt_rgba32 calls with pixfmt_rgb565. That will make agg use that format.
>The pixfmt_custom_blend_rgba calls may need further hacking too to make things work, however, Agg2D should use a 16 bit format if you use
>pixfmt_rgb565 callse instead of pixfmt_rgba32. You should also set RGBA_Width =2; in your program to reflect the change.

I did as you suggest here and changed my buffer to be an array of words, and I am able to get a representation of the image to screen by reading elements of the array and using putpixel() to put them on the screen,  however the colors are all wrong.  I am wondering if this m_pixformat variable that shows up everywhere needs to be set also?   The pixfmt_custom_blend_rgba calls may also be the problem with the colors.  There are no corresponding custom blend procedures in agg_pixfmt_rgb_packed.

>Anyway, this will probably still not make
>ptcgraph.putimage(0,0,buf[0],0);
No this still does not work, I am able to use a nested loop and putpixel() but that is very slow.  I still think something is missing with putimage because I don't see how it knows the shape of the image, maybe I need to actually do a getimage() at some point to set the shape of before putimage will work.. I'll do some experiments with it.  

James

-----Original Message-----
From: fpc-pascal [mailto:[hidden email]] On Behalf Of Stefan V. Pantazi
Sent: Thursday, June 01, 2017 9:47 AM
To: FPC-Pascal users discussions <[hidden email]>
Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph

Have a look at the agg_2D unit. The agg_2D uses ..
  agg_pixfmt ,
  agg_pixfmt_rgba ,
..

Therefore, the rgba format is pretty much baked in. That is to say that the constructor of the main object Agg2D uses the pixfmt_rgba32 to set the pixel format.

...
{ CONSTRUCT }
constructor Agg2D.Construct;
begin
  m_rbuf.Construct;

  pixfmt_rgba32           (m_pixFormat ,@m_rbuf );
  pixfmt_custom_blend_rgba(m_pixFormatComp ,@m_rbuf ,@comp_op_adaptor_rgba ,rgba_order );
  pixfmt_rgba32           (m_pixFormatPre ,@m_rbuf );
  pixfmt_custom_blend_rgba(m_pixFormatCompPre ,@m_rbuf ,@comp_op_adaptor_rgba ,rgba_order ); ...

There is another agg unit agg_pixfmt_rgb_packed that seem to have the
565 format that you need. Add it to the uses list and try to replace the
pixfmt_rgba32 calls with pixfmt_rgb565. That will make agg use that format.

The pixfmt_custom_blend_rgba calls may need further hacking too to make things work, however, Agg2D should use a 16 bit format if you use
pixfmt_rgb565 callse instead of pixfmt_rgba32. You should also set RGBA_Width =2; in your program to reflect the change.

Anyway, this will probably still not make

ptcgraph.putimage(0,0,buf[0],0);
work, but that may be a ptcgraph problem.


Hope this helps,

Stefan

On 05/31/2017 02:57 PM, James Richters wrote:

>> And AggPas already has support for that pixel format
>
> How do I define that as the format I want?  I've been looking all through the example and do not see how this is defined.  I've attached a test program, it's basically Graeme's sample but going to screen instead of a file.  I just don't see where the pixel format is defined.  I have it kind of working in a funny way by just forcing the existing pixels to conform to the required format.
>
> -----Original Message-----
> From: fpc-pascal [mailto:[hidden email]] On
> Behalf Of Graeme Geldenhuys
> Sent: Wednesday, May 31, 2017 1:17 PM
> To: [hidden email]
> Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph
>
> On 2017-05-31 18:03, Reimar Grabowski wrote:
>>> I'm not sure what that's called
>> RGB565, maybe?
>
> And AggPas already has support for that pixel format.
>
> Regards,
>    Graeme
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
>
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Nikolay Nikolov-2
In reply to this post by Zaaphod


On 05/31/2017 02:51 PM, James Richters wrote:
> 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.
The structure, used by putimage is as follows:

3 longints (12 bytes):
- image width
- image height
- reserved

followed by width*height 16-bit words. If you're a using a 16-bit color
mode (that's the highest supported - it's a limitation of the graph unit
include files, which ptcgraph reuses from the fpc sources), the color
format is rgb565.

Nikolay
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Stefan V. Pantazi
In reply to this post by Zaaphod
An interesting challenge. It works now. I updated your test program,
made it as minimal as possible (see attached). The key to solving the
problem was the info available here:

http://pascal.net.ru/PutImage+(en)
[...]
"BitMap is an untyped parameter that contains the height and width of
the region, and the bit image that will be put onto the screen."
[...]

Enjoy,

Stefan


On 06/02/2017 07:40 AM, James Richters wrote:

> Thanks for the help. I was able to make a little progress.
>
>> There is another agg unit agg_pixfmt_rgb_packed that seem to have the
>> 565 format that you need. Add it to the uses list and try to replace the
>> pixfmt_rgba32 calls with pixfmt_rgb565. That will make agg use that format.
>> The pixfmt_custom_blend_rgba calls may need further hacking too to make things work, however, Agg2D should use a 16 bit format if you use
>> pixfmt_rgb565 callse instead of pixfmt_rgba32. You should also set RGBA_Width =2; in your program to reflect the change.
>
> I did as you suggest here and changed my buffer to be an array of words, and I am able to get a representation of the image to screen by reading elements of the array and using putpixel() to put them on the screen,  however the colors are all wrong.  I am wondering if this m_pixformat variable that shows up everywhere needs to be set also?   The pixfmt_custom_blend_rgba calls may also be the problem with the colors.  There are no corresponding custom blend procedures in agg_pixfmt_rgb_packed.
>
>> Anyway, this will probably still not make
>> ptcgraph.putimage(0,0,buf[0],0);
> No this still does not work, I am able to use a nested loop and putpixel() but that is very slow.  I still think something is missing with putimage because I don't see how it knows the shape of the image, maybe I need to actually do a getimage() at some point to set the shape of before putimage will work.. I'll do some experiments with it.
>
> James
>
> -----Original Message-----
> From: fpc-pascal [mailto:[hidden email]] On Behalf Of Stefan V. Pantazi
> Sent: Thursday, June 01, 2017 9:47 AM
> To: FPC-Pascal users discussions <[hidden email]>
> Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph
>
> Have a look at the agg_2D unit. The agg_2D uses ..
>   agg_pixfmt ,
>   agg_pixfmt_rgba ,
> ..
>
> Therefore, the rgba format is pretty much baked in. That is to say that the constructor of the main object Agg2D uses the pixfmt_rgba32 to set the pixel format.
>
> ...
> { CONSTRUCT }
> constructor Agg2D.Construct;
> begin
>   m_rbuf.Construct;
>
>   pixfmt_rgba32           (m_pixFormat ,@m_rbuf );
>   pixfmt_custom_blend_rgba(m_pixFormatComp ,@m_rbuf ,@comp_op_adaptor_rgba ,rgba_order );
>   pixfmt_rgba32           (m_pixFormatPre ,@m_rbuf );
>   pixfmt_custom_blend_rgba(m_pixFormatCompPre ,@m_rbuf ,@comp_op_adaptor_rgba ,rgba_order ); ...
>
> There is another agg unit agg_pixfmt_rgb_packed that seem to have the
> 565 format that you need. Add it to the uses list and try to replace the
> pixfmt_rgba32 calls with pixfmt_rgb565. That will make agg use that format.
>
> The pixfmt_custom_blend_rgba calls may need further hacking too to make things work, however, Agg2D should use a 16 bit format if you use
> pixfmt_rgb565 callse instead of pixfmt_rgba32. You should also set RGBA_Width =2; in your program to reflect the change.
>
> Anyway, this will probably still not make
>
> ptcgraph.putimage(0,0,buf[0],0);
> work, but that may be a ptcgraph problem.
>
>
> Hope this helps,
>
> Stefan
>
> On 05/31/2017 02:57 PM, James Richters wrote:
>>> And AggPas already has support for that pixel format
>>
>> How do I define that as the format I want?  I've been looking all through the example and do not see how this is defined.  I've attached a test program, it's basically Graeme's sample but going to screen instead of a file.  I just don't see where the pixel format is defined.  I have it kind of working in a funny way by just forcing the existing pixels to conform to the required format.
>>
>> -----Original Message-----
>> From: fpc-pascal [mailto:[hidden email]] On
>> Behalf Of Graeme Geldenhuys
>> Sent: Wednesday, May 31, 2017 1:17 PM
>> To: [hidden email]
>> Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph
>>
>> On 2017-05-31 18:03, Reimar Grabowski wrote:
>>>> I'm not sure what that's called
>>> RGB565, maybe?
>>
>> And AggPas already has support for that pixel format.
>>
>> Regards,
>>    Graeme
>>
>> _______________________________________________
>> fpc-pascal maillist  -  [hidden email]
>> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>>
>>
>>
>> _______________________________________________
>> fpc-pascal maillist  -  [hidden email]
>> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Agg2DConsole.dpr (3K) Download Attachment
Screenshot from 2017-06-02 20-49-50.png (48K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Stefan V. Pantazi
In reply to this post by Nikolay Nikolov-2
I literally just sent a reply with the solution. I had to guess the
width and height were longints. Your message confirmed it. I attached an
updated version of the test program, the old one had a few typos.

Thank you for your work on the ptcpas, I found it very useful for my
projects.

On 06/02/2017 08:39 PM, Nikolay Nikolov wrote:

>
>
> On 05/31/2017 02:51 PM, James Richters wrote:
>> 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.
> The structure, used by putimage is as follows:
>
> 3 longints (12 bytes):
> - image width
> - image height
> - reserved
>
> followed by width*height 16-bit words. If you're a using a 16-bit color
> mode (that's the highest supported - it's a limitation of the graph unit
> include files, which ptcgraph reuses from the fpc sources), the color
> format is rgb565.
>
> Nikolay
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Agg2DConsole.dpr (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Graeme Geldenhuys-6
In reply to this post by Stefan V. Pantazi
On 2017-06-03 01:56, Stefan V. Pantazi wrote:
> http://pascal.net.ru/PutImage+(en)
> [...]
> "BitMap is an untyped parameter that contains the height and width of
> the region, and the bit image that will be put onto the screen."
> [...]


Could you file a FPC Documentation bug report and ask that this
information be added. As you found out (very difficultly), this is vital
information.


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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Nikolay Nikolov-2


On 06/03/2017 01:52 PM, Graeme Geldenhuys wrote:

> On 2017-06-03 01:56, Stefan V. Pantazi wrote:
>> http://pascal.net.ru/PutImage+(en)
>> [...]
>> "BitMap is an untyped parameter that contains the height and width of
>> the region, and the bit image that will be put onto the screen."
>> [...]
>
>
> Could you file a FPC Documentation bug report and ask that this
> information be added. As you found out (very difficultly), this is
> vital information.
Even though this is the default implementation (and ptcgraph uses it),
there may be different graph unit implementations that use a different
format in some or all of their video modes. Of course, this should also
be mentioned in the documentation.

Nikolay
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Stefan V. Pantazi
In reply to this post by Graeme Geldenhuys-6
I seem to have some problems with logging on the bug tracker. I've used
it in the recent past a couple of time but I am unable to log on for
some reason. I will try later to create a new account and submit a fpc
doc bug report.

At any rate, I attached the updated example based on Nikolay's recent
post which had the correct information. There was a third "reserved"
parameter that had to be added to the bitmap buffer structure. Without
it, the output was slightly clipped to the right. Also, for the example
to work, the agg object constructor must be modified as well, I included
all the info in the example header. I think the example program
(aggpas_ptcgraph_output.pas) fits well together with the other demos in
fpGUI and PtcPas/ptcgraph packages, so adding it to the packages would
help, regardless whether graph.PutImage documentation is updated.

Stefan

On 06/03/2017 06:52 AM, Graeme Geldenhuys wrote:

> On 2017-06-03 01:56, Stefan V. Pantazi wrote:
>> http://pascal.net.ru/PutImage+(en)
>> [...]
>> "BitMap is an untyped parameter that contains the height and width of
>> the region, and the bit image that will be put onto the screen."
>> [...]
>
>
> Could you file a FPC Documentation bug report and ask that this
> information be added. As you found out (very difficultly), this is vital
> information.
>
>
> Regards,
>   Graeme
>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

aggpas_ptcgraph_output.pas (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Graeme Geldenhuys-6
On 2017-06-03 17:45, Stefan V. Pantazi wrote:
> Also, for the example
> to work, the agg object constructor must be modified as well, I included
> all the info in the example header.

I noted the remarks on the image buffer format being hard-coded for the
Agg_2D unit. I'll make a plan for improving that, using some Factory
(design) Pattern to register the pixel buffer format of interest.


> I think the example program
> (aggpas_ptcgraph_output.pas) fits well together with the other demos in
> fpGUI and PtcPas/ptcgraph packages, so adding it to the packages would
> help, regardless whether graph.PutImage documentation is updated.

Thanks. I'll download the ptcgraph unit and give it a test. I'll all the
demo to fpGUI's AggPas demos too. It will be a good addition.

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  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Stefan V. Pantazi
The easiest workaround I could figure was to add a parameter to the
Agg2D object constructor. That should, in theory, allow the use of any
pixel format available in AggPas.

The ptcpas/ptcgraph units I used are the ones that came with fpc 3.0.1,
there was no need to download anything. They worked fine, except for one
48 bytes memory leak reported by heaptrc and that I left unfixed.

Stefan

On 06/03/2017 03:37 PM, Graeme Geldenhuys wrote:

> On 2017-06-03 17:45, Stefan V. Pantazi wrote:
>> Also, for the example
>> to work, the agg object constructor must be modified as well, I included
>> all the info in the example header.
>
> I noted the remarks on the image buffer format being hard-coded for the
> Agg_2D unit. I'll make a plan for improving that, using some Factory
> (design) Pattern to register the pixel buffer format of interest.
>
>
>> I think the example program
>> (aggpas_ptcgraph_output.pas) fits well together with the other demos in
>> fpGUI and PtcPas/ptcgraph packages, so adding it to the packages would
>> help, regardless whether graph.PutImage documentation is updated.
>
> Thanks. I'll download the ptcgraph unit and give it a test. I'll all the
> demo to fpGUI's AggPas demos too. It will be a good addition.
>
> Regards,
>   Graeme
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementing AggPas with PtcGraph

Zaaphod
In reply to this post by Stefan V. Pantazi
Thanks for figuring out how to make this work, I would have never figured it
out with the documentation I was able to find.

I'm out of town this week so I tried to download the sample program to my
laptop and discovered another issue.  While I can normally just compile my
programs on my laptop and run them,  I have noticed that I can't do this
with programs with aggpas in them. They compile successfully but when I try
to run them I get a "system error: The Program can't start because
MSVCR71.dll is missing from your computer.  Try reinstalling the program to
fix this problem"  I suspect I get this because I have never actually
installed free Pascal or something that I happened to install on my
development pc on my laptop, I have always run freepascal it from a backup
made from my development machine.   I have not tried installing freepascal
on my lap top yet because I would like to figure out what I will need to do
on my target installations where freepascal will not be installed.  

Any ideas on what causes this error and advice on how to install what is
needed on client (non-development) systems?

James

-----Original Message-----
From: fpc-pascal [mailto:[hidden email]] On Behalf
Of Stefan V. Pantazi
Sent: Saturday, June 03, 2017 12:45 PM
To: FPC-Pascal users discussions <[hidden email]>
Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph

I seem to have some problems with logging on the bug tracker. I've used it
in the recent past a couple of time but I am unable to log on for some
reason. I will try later to create a new account and submit a fpc doc bug
report.

At any rate, I attached the updated example based on Nikolay's recent post
which had the correct information. There was a third "reserved"
parameter that had to be added to the bitmap buffer structure. Without it,
the output was slightly clipped to the right. Also, for the example to work,
the agg object constructor must be modified as well, I included all the info
in the example header. I think the example program
(aggpas_ptcgraph_output.pas) fits well together with the other demos in
fpGUI and PtcPas/ptcgraph packages, so adding it to the packages would help,
regardless whether graph.PutImage documentation is updated.

Stefan

On 06/03/2017 06:52 AM, Graeme Geldenhuys wrote:

> On 2017-06-03 01:56, Stefan V. Pantazi wrote:
>> http://pascal.net.ru/PutImage+(en)
>> [...]
>> "BitMap is an untyped parameter that contains the height and width of
>> the region, and the bit image that will be put onto the screen."
>> [...]
>
>
> Could you file a FPC Documentation bug report and ask that this
> information be added. As you found out (very difficultly), this is vital
> information.
>
>
> Regards,
>   Graeme
>

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
12345
Loading...