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:fpc-pascal-boun...@lists.freepascal.org] On Behalf Of
Stefan V. Pantazi
Sent: Thursday, June 01, 2017 9:47 AM
To: FPC-Pascal users discussions <fpc-pascal@lists.freepascal.org>
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:fpc-pascal-boun...@lists.freepascal.org] On
Behalf Of Graeme Geldenhuys
Sent: Wednesday, May 31, 2017 1:17 PM
To: fpc-pascal@lists.freepascal.org
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 - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
{
This is a console application demo. It uses the Agg2D object,
which has a much friendlier API, to do all the drawing.
The drawing buffer is then displayed in a window using ptcgraph and 16 bit
656 RGB color format.
Requires modification of Agg2D object to use the 16 bit color format.
Uses a GraphBitmapBuffer type that includes contains the width and height of
the image per the info at this URL:
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."
[...]
}
program console_aggpas_2;
{$mode objfpc}{$H+}
uses
ptcgraph,
ptccrt,
agg_2D,
agg_basics;
const
IMAGE_WIDTH = 800;
IMAGE_HEIGHT = 600;
RGBA_WIDTH =2; //16bit 656 format
LINE_COUNT = 30;
{$IFDEF Unix}
FontFile = '../../arial.ttf';
{$ENDIF}
{$IFDEF Windows}
FontFile = 'Arial';
{$ENDIF}
type
TGraphBitmapBuffer=packed record
width,
height: longint;
data: array[0..2*600*800-1] of Byte;
end;
var
gd,gm : smallint;
graph_buffer: TGraphBitmapBuffer;
procedure DrawStuff(agg: Agg2D_ptr);
var
i: Integer;
x, y, px, py, d: Double;
c1, c2: Color;
begin
// draw a full screen graph with grid
agg^.clearAll(0, 0, 0);
agg^.lineColor(0, 0, 0, 255);
agg^.lineWidth(3);
agg^.rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);
agg^.lineWidth(1);
agg^.lineColor(0, 155, 0, 255);
agg^.rectangle(10, 10, 50, 50);
// agg^.font(fontfile, 16);
d := IMAGE_WIDTH / LINE_COUNT;
agg^.lineColor(0, 0, 0, 100);
agg^.lineWidth(1);
for i := 1 to LINE_COUNT - 1 do
begin
x := i * d;
agg^.line(x, 0, x, IMAGE_HEIGHT);
end;
for i := 1 to trunc(IMAGE_HEIGHT / d) do
begin
y := i * d;
agg^.line(0, y, IMAGE_WIDTH, y);
end;
x := 0;
y := IMAGE_HEIGHT / 2;
px := x;
py := y;
agg^.lineColor(255, 0, 0, 200);
agg^.fillColor(0, 0, 0, 200);
agg^.lineWidth(1);
for i := 0 to LINE_COUNT - 1 do
begin
x := x + d;
y := y + Random(Round(IMAGE_HEIGHT / 3)) - IMAGE_HEIGHT / 6;
if y < 0 then
y := IMAGE_HEIGHT / 6;
if y >= IMAGE_HEIGHT then
y := IMAGE_HEIGHT - IMAGE_HEIGHT / 6;
agg^.line(px, py, x, y);
// agg^.text(x, y, char_ptr(IntToStr(i) + ' point'));
px := x;
py := y;
end;
// Star shape
agg^.LineCap(CapRound);
agg^.LineWidth(5);
agg^.LineColor($32 ,$cd ,$32 );
c1.Construct(0, 0 , 255, 200);
c2.Construct(0, 0, 255, 50);
agg^.FillLinearGradient(100, 100, 150, 150, c1, c2);
agg^.Star(100 ,150 ,30 ,70 ,55 ,5 );
// Draw Arc from 45 degrees to 270 degrees
agg^.LineColor($4C, $6C, $9C);
agg^.LineWidth(5 );
agg^.Arc(300 ,320 ,80 ,50 ,Deg2Rad(45 ) ,Deg2Rad(270 ) );
end;
procedure HandlePlug;
var
agg: Agg2D_ptr;
begin
graph_buffer.width:=IMAGE_WIDTH;
graph_buffer.height:=IMAGE_HEIGHT;
New(agg, Construct);
agg^.attach(@graph_buffer.data, IMAGE_WIDTH, IMAGE_HEIGHT, -(IMAGE_WIDTH *
RGBA_WIDTH));
DrawStuff(agg);
Dispose(agg, Destruct); // not necessary to keep it after rendering is
finished
//display on ptc surface
ptcgraph.putimage(0,0,graph_buffer,NormalPut);
ptcgraph.Rectangle(10,10,100,100);
ptcgraph.PieSlice(100,100,0,25,30);
ptcgraph.OutTextXY(80,80,'It works!');
end;
begin
gd:=d16Bit;
gm:=m800x600;
//Windowtitle:='ptcgraph';
ptcgraph.Initgraph(gd,gm,'');
Randomize;
HandlePlug;
readkey;
end.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal