Fix netpbm parsing

This commit is contained in:
Nikita Lisitsa 2020-09-28 18:51:49 +03:00
parent 631a720e56
commit d40ec7c0ca

View file

@ -34,12 +34,16 @@ namespace psemek::gfx
fail("P1 format is not supported");
std::getline(is, line);
if (!is)
fail("stream error");
std::istringstream sline(line);
std::size_t width, height;
pixmap_monochrome pixmap;
sline >> width >> height;
if (!sline)
fail("stream error");
pixmap.resize({width, height});
@ -89,6 +93,8 @@ namespace psemek::gfx
fail("unknown format " + line);
std::getline(is, line);
if (!is)
fail("stream error");
std::istringstream sline(line);
std::size_t width, height;
@ -96,10 +102,17 @@ namespace psemek::gfx
pixmap_monochrome pixmap;
sline >> width >> height;
if (!sline)
fail("stream error");
std::getline(is, line);
if (!is)
fail("stream error");
sline.clear();
sline.str(line);
sline >> max;
if (!sline)
fail("stream error");
if (max != 255)
fail("max value " + std::to_string(max) + " is not supported");
@ -117,7 +130,7 @@ namespace psemek::gfx
return pixmap;
}
pixmap_rgb load_ppm(std::istream & is)
pixmap_rgb read_ppm(std::istream & is)
{
auto fail = [](std::string str)
{
@ -141,6 +154,8 @@ namespace psemek::gfx
fail("unknown format " + line);
std::getline(is, line);
if (!is)
fail("stream error");
std::istringstream sline(line);
std::size_t width, height;
@ -149,9 +164,17 @@ namespace psemek::gfx
sline >> width >> height;
if (!sline)
fail("stream error");
std::getline(is, line);
if (!is)
fail("stream error");
sline.clear();
sline.str(line);
sline >> max;
if (!sline)
fail("stream error");
if (max != 255)
fail("max value " + std::to_string(max) + " is not supported");