I'm trying to read a PGM binary file (http://netpbm.sourceforge.net/doc/pgm.html) to fill a 0-based 2D matrix of integers (16-bit grayscale values).
The file may be 50 megs, so I'm trying to fill a buffer in one call.
I've never done anything with Streams before, but the Google results on Delphi streams going back 20 years and are a cluttered mess in which I couldn't find my way.
I've managed to lock up Delphi (first time in 15 years!) while running some code that uses pointers and buffers (and probably is based on my misunderstanding of an antiquated approach.)
Here's my pseudo code, doing it integer by integer. Is there a way to do the read and fill of the matrix with a single Stream call? (Assuming the file was created on the same machine, so byte-sex is the same.)
TMatrix: Array of Array of Integer;
procedure ReadMatrix( const AFileName: String;
const AStartingByte: Integer;
const AMaxRow: Integer;
const AMaxCol: Integer;
const AMatrix: TMatrix)
SetLength(AMatrix, aMaxRow, aMaxCol);
for Row := 0 to aMaxCol do
for Col := 0 to aMaxCol do
AMatrix[Row, Col] := ReadWord
And, no, this isn't a homework assignment! :-)