From 89a5ec74cd9c936ce9fc23ea2d550376e63bb67a Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Mon, 24 Nov 2025 14:56:32 +0100 Subject: [PATCH] plugin/ppm: improved compatibility --- uppsrc/plugin/ppm/ppm.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/uppsrc/plugin/ppm/ppm.cpp b/uppsrc/plugin/ppm/ppm.cpp index 468e81a75..2915a705b 100644 --- a/uppsrc/plugin/ppm/ppm.cpp +++ b/uppsrc/plugin/ppm/ppm.cpp @@ -18,20 +18,27 @@ bool PPMRaster::Create() } try { - if(stream.GetLine() != "P6") + if(stream.Get(2) != "P6") return false; - String h = stream.GetLine(); - CParser p(h); - size.cx = p.ReadInt(); - size.cy = p.ReadInt(); - if(size.cx <= 0 || size.cx > 99999 || size.cy <= 0 || size.cy >= 99999) - return false; - h = stream.GetLine(); - CParser p1(h); - int maxval = p1.ReadInt(); - if(maxval <= 0 || maxval > 65535) - return false; - is16 = maxval > 255; + int ii = 0; + int num[3]; + String line; + CParser p(line); + while(ii < 3) { + while(p.IsEof() || p.Char('#')) { + if(stream.IsEof()) + return false; + line = stream.GetLine(); + p.Set(line); + } + int n = p.ReadInt(); + if(n <= 0 || n > 65535) + return false; + num[ii++] = n; + } + size.cx = num[0]; + size.cy = num[1]; + is16 = num[2] > 255; pixel_pos = stream.GetPos(); return true; }