c++multidimensional-arraypgm

.pgm images don't fit seem to fit in array


Working on some basic image processing and I need to manipulate a P2 .prg image. If there are no comments then in line two there should be a width and height value. If we take the FEEP example from this website https://people.sc.fsu.edu/~jburkardt/data/pgma/pgma.html then we can see the value given is 24 and the array later in the file is 24 wide. Perfect! However whenever I go to read in any other file from the same website, the width measurement is say 512, but the text data inside the file is only 17 digits wide? Am I looking at this file wrong? How can I parse out this file into a multidimensional array if the width of the lines don't match the width from the header?


Solution

  • In the .pgm formats, one line of text does not correspond to one line of the image.

    The first width numbers are the first row of the image. Then the next width numbers are the second row of the image and so on. How many numbers are on one line of text is inconsequential.

    That means when reading the file, you should ignore newlines and treat them like any other whitespace.