Merge pull request 'Tests for Files/Pfm.hpp, Files/Pnm.hpp' (#139) from tests_files into master
Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/139 Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com>
This commit is contained in:
@@ -96,6 +96,10 @@ namespace OpenVulkano
|
||||
inStream >> header;
|
||||
size_t size = header.GetElementCount();
|
||||
|
||||
image = std::make_unique<float[]>(size);
|
||||
|
||||
inStream.read(reinterpret_cast<char*>(image.get()), size * sizeof(float));
|
||||
|
||||
if ((std::endian::native == std::endian::little) != header.littleEndian)
|
||||
{
|
||||
char* data = reinterpret_cast<char*>(image.get());
|
||||
@@ -105,9 +109,6 @@ namespace OpenVulkano
|
||||
std::reverse(&data[idx], &data[idx + sizeof(float)]);
|
||||
}
|
||||
}
|
||||
|
||||
image = std::make_unique<float[]>(size);
|
||||
inStream.read(reinterpret_cast<char*>(image.get()), size * sizeof(float));
|
||||
}
|
||||
|
||||
static PfmImage ReadImage(std::istream& inStream)
|
||||
|
||||
@@ -87,8 +87,25 @@ namespace OpenVulkano
|
||||
if (val > 6) throw std::runtime_error("Malformed PNM header!");
|
||||
pnmHeader.ascii = val < 4;
|
||||
pnmHeader.color = static_cast<ColorMode>(val - 3);
|
||||
inStream >> pnmHeader.width >> pnmHeader.height;
|
||||
inStream >> pnmHeader.maxValue;
|
||||
|
||||
if (!(inStream >> pnmHeader.width >> pnmHeader.height)) [[unlikely]]
|
||||
{
|
||||
throw std::runtime_error("Malformed PNM header: Unable to read width and height!");
|
||||
}
|
||||
if (pnmHeader.width == 0 || pnmHeader.height == 0) [[unlikely]]
|
||||
{
|
||||
throw std::runtime_error("Malformed PNM header: Width and height must be positive!");
|
||||
}
|
||||
|
||||
if (!(inStream >> pnmHeader.maxValue)) [[unlikely]]
|
||||
{
|
||||
throw std::runtime_error("Malformed PNM header: Unable to read maxValue!");
|
||||
}
|
||||
if (pnmHeader.maxValue == 0 || pnmHeader.maxValue > 65535) [[unlikely]]
|
||||
{
|
||||
throw std::runtime_error("Malformed PNM header: Invalid maxValue (must be between 1 and 65535)!");
|
||||
}
|
||||
|
||||
inStream.get();
|
||||
return inStream;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user