Re: [fpc-pascal] JSON SAX-based reader

2017-06-23 Thread Stefan V. Pantazi

Thank you for this, Michael. I think it is wonderful work.

I've done some old tests of the new implementation and it looks very 
good. The only failed tests were related to date and time 
representation. This appears to be fixed in the new version. Most 
importantly, I see no memory leaks when parsing fails due to malformed 
JSON, and that is great!


The only fixes I had to do to my own software to accommodate the new 
implementation, were:


1) comment out the "Strict" property of the TJSONParser (it appears it 
no longer exists); I used to set it to false, to allow for more 
flexibility in JSON syntax.


2) add the missing procedure SetKey(obj:TJSONObject); to TJSONConfig 
since it was removed from the new version of jsonconf.pp; anyway, in 
this particular case, it may be me that has to rethink and simplify my 
use of the json config component that does not need SetKey.


Hope this helps,

Stefan


On 06/23/2017 02:48 AM, Michael Van Canneyt wrote:


Hello,

I have changed the JSON parser, it is now written on top of a SAX-like JSON
reader (which is available separately). All unit tests work fine, and the
few extra tests which I did also, but I would like to hear if someone has
code that no longer works.

The change is committed in trunk. The new JSON reader is available in the
unit jsonreader. Useful if you want to process large amounts of JSON data
without building the whole JSON document in memory.

Michael.
___
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

Re: [fpc-pascal] Implementing AggPas with PtcGraph

2017-06-23 Thread James Richters
> lineto is meant to be used multiple times, as part of a draw path. So, lineto 
> does not really draw, 
>it just adds a vertex to a vertex storage object. To draw a path, you need to 
>use the drawPath(option):

Thank you for the information!  I thought I was missing something.

James

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Implementing AggPas with PtcGraph

2017-06-23 Thread Stefan V. Pantazi
When in doubt, have a look at the source code of the graphical 
primitives to determine the semantics of each one. Unlike line primitive 
which draws a path immediately, lineto is meant to be used multiple 
times, as part of a draw path. So, lineto does not really draw, it just 
adds a vertex to a vertex storage object. To draw a path, you need to 
use the drawPath(option):


  agg^.lineWidth(4);
  agg^.lineColor(0, 155, 0, 255);
  agg^.rectangle(10, 10, 50, 50);
  agg^.lineColor(155, 0, 0, 255);
  agg^.line(60, 10, 60, 50);
  agg^.lineto(100,50);   //no line drawn here, just adds to 
vertex storage

  agg^.drawPath(StrokeOnly);   //draw path
  agg^.lineColor(0, 0, 155, 255);
  agg^.moveto(100, 10);
  agg^.lineto(100,50);   //no line drawn here, just adds to 
vertex storage

  agg^.drawPath(StrokeOnly);   //draw path
  agg^.lineColor(155, 0, 155, 255);
  agg^.line(120, 10, 120, 50);


On 06/23/2017 01:27 PM, James Richters wrote:

I'm trying to switch over a program to use aggpas but I'm not getting any 
results from moveto or lineto am I missing something?

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Implementing AggPas with PtcGraph

2017-06-23 Thread James Richters
I'm trying to switch over a program to use aggpas but I'm not getting any 
results from moveto or lineto am I missing something?

I made a little demo that illustrates what's happening

  agg^.lineWidth(4);
  agg^.lineColor(0, 155, 0, 255);
  agg^.rectangle(10, 10, 50, 50);
  agg^.lineColor(155, 0, 0, 255);
  agg^.line(60, 10, 60, 50);
  agg^.lineto(100,50);   //no line drawn here
  agg^.lineColor(0, 0, 155, 255);
  agg^.moveto(100, 10);
  agg^.lineto(100,50);//no line drawn  here
  agg^.lineColor(155, 0, 155, 255);
  agg^.line(120, 10, 120, 50);

James

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Can't close and reopen ptcgraph

2017-06-23 Thread James Richters
>As a workaround, you can manually take care of the ptcwrapper object like 
>this, in between closegraph and initgraph calls, but first ask yourself, do 
>you really need this?

Thanks for figuring out what is going on.  I don't really need to close it and 
reopen it. I can work around by just hiding the window with 
ShowWindow(graphwindow,SW_hide);

To get back to my console window, then when needed I can clear it and show it 
again with.
ShowWindow(graphwindow,SW_show);

James


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Can't close and reopen ptcgraph

2017-06-23 Thread Stefan V. Pantazi
I think I figured it out. It hink ptcgraph was not designed with that 
functionality in mind. If you take a look at the ptcgraph unit, it has 
initialization and finalization sections where the ptc wrapper object is 
created and freed. That happens only at application start and finish not 
during run, as you require.


As a workaround, you can manually take care of the ptcwrapper object 
like this, in between closegraph and initgraph calls, but first ask 
yourself, do you really need this?


[...]
//close graph window
ptcgraph.Closegraph;

//manually terminate the ptcwrapper thread and free object
PTCWrapperObject.Terminate;
PTCWrapperObject.WaitFor;
PTCWrapperObject.Free;

//manually create the ptcwrapper thread
PTCWrapperObject := TPTCWrapperThread.Create;

//init graph windows as usual
ptcgraph.Initgraph(gd,gm,'');
[...]

Stefan

On 06/23/2017 11:20 AM, James Richters wrote:

I ran into an unexpected issue with ptcgraph.  If I use closegraph, I
cannot re-open a new ptcgraph window with Initgraph.  It looks like it
opens the second graph window but then closes it immediately after.. my
program is then appears to be locked up after this happens.. no errors,
just locked up.   test program is below.  If I comment out ptcgraph and
ptccrt and uncomment graph and wincrt, it works as expected.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Can't close and reopen ptcgraph

2017-06-23 Thread Stefan V. Pantazi
On Linux 64bit, reopening of a second window works fine, as expected. On 
Windows it does not, and behaves as you reported. This is most likely 
related to the use of a separate thread (TPTCWrapperThread) in ptcgraph. 
As far as I know graph and wincrt do not use threads. I suspect that on 
windows, the ptc thread is not properly terminating for some reason.


Stefan

On 06/23/2017 11:20 AM, James Richters wrote:

I ran into an unexpected issue with ptcgraph.  If I use closegraph, I
cannot re-open a new ptcgraph window with Initgraph.  It looks like it
opens the second graph window but then closes it immediately after.. my
program is then appears to be locked up after this happens.. no errors,
just locked up.   test program is below.  If I comment out ptcgraph and
ptccrt and uncomment graph and wincrt, it works as expected.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Implementing AggPas with PtcGraph

2017-06-23 Thread Martin Schreiber
On Thursday 22 June 2017 18:47:40 James Richters wrote:
> I squeezed a little more out of putimage by doing as little math as
> possible with a couple of variables to store j*ptcwidth and i+j*ptcwidth  I
> got my 1000x test loop down to 1.013 seconds.  Here is what it looks like
> at the moment, any ideas on how to optimize it further?
>
"
var
  pixels:Pword;
  k: longint;
  i, j, y1, x1, deltaX, deltaX1, deltaY: smallint;
  JxW, I_JxW: Longword;
  sourcepo,destpo,endpo: pcard16;
[...]
XORPut:
  Begin
for j:=Y to Y1 do
  Begin
JxW:=j*PTCWidth;
inc(k,deltaX);

sourcepo:= @pt(bitmap)[k];
destpo:= @pixels[jxw+x];
endpo:= destpo+x1-x;
inc(k,x1-x+1);
while destpo <= endpo do begin
 destpo^:= destpo^ xor sourcepo^ and colormask;
 inc(sourcepo);
 inc(destpo);
end;
{
for i:=X to X1 do
  begin
I_JxW:=i+JxW;
pixels[I_JxW] := pixels[I_JxW] xor (pt(bitmap)[k] and 
ColorMask);
inc(k);
  end;
}
inc(k,deltaX1);
  End;
  End;
"
On 32 bit Linux with 1024x768 screen and bitmap:

FPC 3.0.3 -O-:
1001 runs
origin  2.2167833261452355E+000 ms per put
mse  2.0649356462366574E+000 ms per put

FPC 3.0.3 -O3:
1001 runs
origin  2.2787212782151454E+000 ms per put
mse  6.0739260367848180E-001 ms per put

MSElang with LLVM 3.8.0 backend no optimisation:
1001 runs
origin 1.97338 ms per put
mse 2.03776 ms per put

MSElang with LLVM 3.8.0 backend -O3:
1001 runs
origin 0.406554 ms per put
mse 0.454978 ms per put

The project is here:
https://gitlab.com/mseide-msegui/mselang/tree/master/mselang/benchmark/putimage

Martin
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] JSON SAX-based reader

2017-06-23 Thread Michael Van Canneyt



On Fri, 23 Jun 2017, Benito van der Zander wrote:


Hi,


Useful if you want to process large amounts of JSON data
without building the whole JSON document in memory. 



I have always used jsonscanner for that...


Well, JSONScanner does not do structural JSON validation. 
JSONReader does.

JSONReader of course uses JSONScanner to get the tokens.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] JSON SAX-based reader

2017-06-23 Thread Benito van der Zander

Hi,


Useful if you want to process large amounts of JSON data
without building the whole JSON document in memory. 



I have always used jsonscanner for that...



Best,
Benito



On 06/23/2017 08:48 AM, Michael Van Canneyt wrote:


Hello,

I have changed the JSON parser, it is now written on top of a SAX-like 
JSON

reader (which is available separately). All unit tests work fine, and the
few extra tests which I did also, but I would like to hear if someone has
code that no longer works.

The change is committed in trunk. The new JSON reader is available in the
unit jsonreader. Useful if you want to process large amounts of JSON data
without building the whole JSON document in memory.

Michael.
___
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] Can't close and reopen ptcgraph

2017-06-23 Thread James Richters
I ran into an unexpected issue with ptcgraph.  If I use closegraph, I cannot
re-open a new ptcgraph window with Initgraph.  It looks like it opens the
second graph window but then closes it immediately after.. my program is
then appears to be locked up after this happens.. no errors, just locked up.
test program is below.  If I comment out ptcgraph and ptccrt and uncomment
graph and wincrt, it works as expected.

 

James

 

 

program ReOpenGraph.pas;

 

{$mode objfpc}{$H+}

 

uses

  ptcgraph,ptccrt;

//  graph,wincrt;

 

var

  gd,gm : smallint;

 

begin

  gd:=d8Bit;

  gm:=m800x600;

  Writeln('Opening Graphics Window');

  Initgraph(gd,gm,'');

  Writeln('Graphics Window Open');

  setcolor($4A);

  settextstyle(Defaultfont,HORIZDIR,2);

  outtextxy(30,30,'Graphics Window Open');

  readkey;

  Closegraph;

  Writeln('Closing Graphics Window');

  readln;

  Writeln('Re-Opening Graphics Window');

  Initgraph(gd,gm,''); // window opens then closes immediately with ptcgraph

  Writeln('Graphics Window Open Again'); // this never happens with ptcgraph

  setcolor($4A);

  settextstyle(Defaultfont,HORIZDIR,2);

  outtextxy(30,30,'Graphics Window Open Again');

  Readln;

  Closegraph;

end.

 

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Serial to TCP gateway in FPC?

2017-06-23 Thread Michael Schnell

On 22.06.2017 00:30, Bo Berglund wrote:


1) How do I enter a loop in a GUI application? In a command line
application it is just going to be part of he main program code.

Use a Thread.


2) How do I stop the program from running at 100% CPU utilization (on
Windows)?


Blocking read.

-Michael
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal