[fpc-pascal] Implementing AggPas with PtcGraph

James Richters james at productionautomation.net
Mon Jun 19 02:35:42 CEST 2017


>When you use the Windows GDI font engine, you don't have to specify the location of the font - that is done for you in the font engine.
> Also you specify the font name like windows programs do, you don't specify the font filename.

Thank you the information

I finally partially figured out the red / blue color problem.   
After single stepping through tons of the aggpas code for hours (it's quite complicated even to draw a line) with a sample program that just made a red line at the top, I discovered that it's actually doing everything exactly correct!   The problem is not with rendering with rgb565,  the problem is something in the original that was patched with the setcolor function:

Line 122 of agg_color pas has:
constructor rgba8.Construct;
begin
 b{*}:=int8u(r_ );
 g:=int8u(g_ );
 r:=int8u(b_ );
 a:=int8u(a_ );

end;

This switches red and blue... if I correct it to:
constructor rgba8.Construct;
begin
 b{*}:=int8u(b_ );
 g:=int8u(g_ );
 r:=int8u(r_ );
 a:=int8u(a_ );

end;

now my colors with rgb565 are correct.     Since this is no logical reason to make b:=R_ and r:=B_ it seems more likely that with the rgba format somewhere along the way someone got lazy and just switched red and blue instead of fixing the pixelformat.

It became obvious that the original was the thing that was backwards, not the RGB565 patch because I kept stepping through things like:
constructor aggclr.Construct(rgba : rgba8 );
begin
 v:=(rgba.r * 77 + rgba.g * 150 + rgba.b * 29 ) shr 8;
 r:=rgba.r;
 g:=rgba.g;
 b:=rgba.b;
 a:=rgba.a;

end;
When I evaluated the variables 
R=0
G=0
B=255
A=255

But I defined a RED line, not a blue one.  

I used 
agg^.lineColor($FF, 0, 0, 255);

and according to:

procedure Agg2D.lineColor(r ,g ,b : unsigned; a : unsigned = 255 );
var
 clr : Color;

begin
 clr.Construct(r ,g ,b ,a );
 lineColor    (clr );

end;

This should be red.

Every other function or procedure I came across with elements for red, green and blue kept coming up like this, so technically are incorrect.   Where the inconsistency come from to fix it properly.  For now I just made a compiler directive {$DEFINE AGG2D_USE_RGB565 } and use it to fix things in both agg_2D and agg_color.

I've committed these to a custom branch on my github fork of fpGUI at:
https://github.com/Zaaphod/fpGUI/tree/Zaaphod_Custom

I looked at the file history  in fpGUI and it looks like red and blue have been reversed like this since the initial import of aggpas into fpGUI,  when I look at the original example agg2dconsole.dpr, it has in it:
      c.red := getBufItemAsWord(2);
      c.green := getBufItemAsWord(1);
      c.blue := getBufItemAsWord(0);
      c.alpha := getBufItemAsWord(3);

but it should have been 

      c.red := getBufItemAsWord(0);
      c.green := getBufItemAsWord(1);
      c.blue := getBufItemAsWord(2);
      c.alpha := getBufItemAsWord(3);

and would have been if constructor rgba8.Construct; was correct... instead it was just re-reversed to compensate for the error in agg_color.pas.   My point here is that it may be too late to just correct it now, because then everyone who has programs that already 'fix' the problem will then all be wrong, so I'm not sure what the best way to fix this is.

James





-----Original Message-----
From: fpc-pascal [mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of Graeme Geldenhuys
Sent: Sunday, June 18, 2017 12:32 PM
To: fpc-pascal at lists.freepascal.org
Subject: Re: [fpc-pascal] Implementing AggPas with PtcGraph

On 2017-06-16 18:49, James Richters wrote:
> agg^.Font('C:\Windows\Fonts\ConsolaB.ttf' ,45 ) works fine, but as I  
> mentioned I can't be sure windows is installed in C:\Windows 

When you use the Windows GDI font engine, you don't have to specify the location of the font - that is done for you in the font engine. Also you specify the font name like windows programs do, you don't specify the font filename.

For example:

   agg^.LineWidth(1);
   agg^.Font('Consola' ,45, True); // Bold
   agg^.Text(300 ,100 ,'Consola font here.' );
   agg^.Font('Courier New' ,45, False, True );  // Italics
   agg^.Text(300 ,150 ,'Courier New font here.' );


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