plugin/ppm: improved compatibility

This commit is contained in:
Mirek Fidler 2025-11-24 14:56:32 +01:00
parent 86853f1194
commit 89a5ec74cd

View file

@ -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;
}