Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-11

TPicture.LoadFromStream error

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, I'm loading PGM files to an 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.

Does anyone knows how can I workaround this?.

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé
Leonardo M. Ram? wrote 12 lines
Hi, I'm loading PGM files to an 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. Does anyone knows how can I workaround this?. -- Leonardo M. Ram? http://leonardorame.blogspot.com --

The problem is in fpreadpnm.pp (fpc/packages/fcl-image), in the 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.

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé
Leonardo M. Ram? wrote 47 lines
On 2010-11-05 11:46:01 -0300, Leonardo M. Ram? wrote: > Hi, I'm loading PGM files to an 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. > > Does anyone knows how can I workaround this?. > > -- > Leonardo M. Ram? > http://leonardorame.blogspot.com > > -- The problem is in fpreadpnm.pp (fpc/packages/fcl-image), in the 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.

I attached the problematic image here:
http://www.tarjeta-salud.com.ar/downloads/salida.pgm

Reply by email

Mattias Gaertner
to Leonardo M. Ramé
Show quoted text 51 lines
On 2010-11-05 12:39:28 -0300, Leonardo M. Ram? wrote: > On 2010-11-05 11:46:01 -0300, Leonardo M. Ram? wrote: > > Hi, I'm loading PGM files to an 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. > > > > Does anyone knows how can I workaround this?. > > > > -- > > Leonardo M. Ram? > > http://leonardorame.blogspot.com > > > > -- > > The problem is in fpreadpnm.pp (fpc/packages/fcl-image), in the 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. > I attached the problematic image here: http://www.tarjeta-salud.com.ar/downloads/salida.pgm

Can you create a bug report with a small example program and this image attached?

Mattias

Reply by email