View Issue Details

IDProjectCategoryView StatusLast Update
0036943FPCFCLpublic2020-05-02 18:16
Reportercircular Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.0.4 
Fixed in Version3.3.1 
Summary0036943: PNM reader is slow
DescriptionFPReadPNM is slow as it reads each character one by one.

It could be optimized by using a read buffer, for example TReadBufStream of bufstream unit.
Steps To ReproduceLoad the attached image using FPReadPPM. See sample program below.
Additional Informationprogram ptestpnm;

uses Classes, SysUtils, FPImage, FPReadPNM;

var
  s: TFileStream;
  img: TFPMemoryImage;
  reader: TFPReaderPNM;
begin
  writeln(TimeToStr(Now),' - Starting to load...');
  img := TFPMemoryImage.Create(0,0);
  reader := TFPReaderPNM.Create;
  s := TFileStream.Create('B&W (ASCII).pbm', fmOpenRead);
  img.LoadFromStream(s, reader);
  s.Free;
  reader.Free;
  writeln(TimeToStr(Now),' - Done.');
  img.Free;
end.
TagsNo tags attached.
Fixed in Revision45226
FPCOldBugId
FPCTarget4.0.0
Attached Files

Activities

circular

2020-04-21 14:23

reporter  

B&W (ASCII).pbm (943,518 bytes)

Marco van de Voort

2020-04-21 15:02

manager   ~0122318

You create the stream yourself?!?

Just instantiate TBufferedFileStream from bufstream instead of tfilestream. (possibly 3.2+)

circular

2020-04-25 15:05

reporter   ~0122415

I am not sure what emotion or thoughts you are expressing with "?!?".

Indeed one can instantiate a buffered stream by themselves, that can solve the problem.

Though that doesn't seem like the right approach to me. It is up to the reader to know that it is going to read byte by byte, that's not the case of most image readers.

If you're going to do LoadFromStream without specifying the reader, would you then create a buffered stream in all cases, just in case it is the PNM reader that is used?

Michael Van Canneyt

2020-04-25 15:48

administrator   ~0122416

I follow the reader of the OP. I will add a small buffer in the reader itself.

circular

2020-04-25 18:05

reporter   ~0122420

Thank you

Michael Van Canneyt

2020-05-02 18:16

administrator   ~0122600

Added a 1k read buffer, results in much better speed.

Issue History

Date Modified Username Field Change
2020-04-21 14:23 circular New Issue
2020-04-21 14:23 circular File Added: B&W (ASCII).pbm
2020-04-21 15:02 Marco van de Voort Note Added: 0122318
2020-04-24 16:08 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-04-24 16:08 Michael Van Canneyt Status new => assigned
2020-04-25 15:05 circular Note Added: 0122415
2020-04-25 15:48 Michael Van Canneyt Note Added: 0122416
2020-04-25 18:05 circular Note Added: 0122420
2020-05-02 18:16 Michael Van Canneyt Status assigned => resolved
2020-05-02 18:16 Michael Van Canneyt Resolution open => fixed
2020-05-02 18:16 Michael Van Canneyt Fixed in Version => 3.3.1
2020-05-02 18:16 Michael Van Canneyt Fixed in Revision => 45226
2020-05-02 18:16 Michael Van Canneyt FPCTarget => 4.0.0
2020-05-02 18:16 Michael Van Canneyt Note Added: 0122600