EReadError loading PGM files from stream
Original Reporter info from Mantis: leonardorame
-
Reporter name: Leonardo M. Ramé
Original Reporter info from Mantis: leonardorame
- Reporter name: Leonardo M. Ramé
Description:
I'm loading PGM files to a TImage.Picture using its LoadFromFile or LoadFromStream methods.
This works well on small to medium sized images, but I'm getting an
"EReadErrorEReadError" exception if I try to load images of 16mb or more.
After debugging this, I stopped at fpreadpnm.pp, in this method:
procedure TFPReaderPNM.InternalRead(Stream:TStream;Img:TFPCustomImage);
var
Row:Integer;
l: Integer;
begin
ReadHeader(Stream);
Img.SetSize(FWidth,FHeight);
FScanLineSize:=FBitPP*((FWidth+7)shr 3);
GetMem(FScanLine,FScanLineSize);
try
for Row:=0 to img.Height-1 do
begin
ReadScanLine(Row,Stream);
WriteScanLine(Row,Img);
end;
finally
Row := l;
FreeMem(FScanLine);
end;
end;
The ReadScanLine method uses the FScanLineSize to read from a Stream
using Stream.ReadBuffer with a size of FScanLineSize, and it seems like
in my image, in a specific row (4734 to be clear) it has a different line size than the
expected by FScanLineSize.
Maybe the formula used to calculate the scan line size is wrong?.
I can open my image with many viewers like Eye of Gnome, or Gimp without
problems.
Here's the image:
http://www.tarjeta-salud.com.ar/downloads/salida.pgm
I attached a sample Lazarus project to reproduce this.
Hope someone can help me fix this.
Mantis conversion info:
- Mantis ID: 17840
- OS: Linux
- OS Build: 2.6.35
- Platform: x86_64
- Version: 2.5.1
- Fixed in revision: 16313 (#fb13dfc1)
- Target version: 2.5.1