Add PfmImage and PnmImage classes
This commit is contained in:
@@ -84,16 +84,22 @@ namespace openVulkanoCpp
|
|||||||
{
|
{
|
||||||
return GetElementCount() * sizeof(float);
|
return GetElementCount() * sizeof(float);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static std::pair<PfmHeader, std::unique_ptr<float[]>> ReadImage(std::istream& inStream)
|
struct PfmImage
|
||||||
|
{
|
||||||
|
PfmHeader header;
|
||||||
|
std::unique_ptr<float[]> image;
|
||||||
|
|
||||||
|
static PfmImage ReadImage(std::istream& inStream)
|
||||||
{
|
{
|
||||||
std::pair<PfmHeader, std::unique_ptr<float[]>> image;
|
PfmImage image;
|
||||||
inStream >> image.first;
|
inStream >> image.header;
|
||||||
size_t size = image.first.GetElementCount();
|
size_t size = image.header.GetElementCount();
|
||||||
|
|
||||||
if (Utils::IsLittleEndian() != image.first.littleEndian)
|
if (Utils::IsLittleEndian() != image.header.littleEndian)
|
||||||
{
|
{
|
||||||
char* data = reinterpret_cast<char*>(image.second.get());
|
char* data = reinterpret_cast<char*>(image.image.get());
|
||||||
for(size_t i = 0; i < size; i++)
|
for(size_t i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
size_t idx = i * sizeof(float);
|
size_t idx = i * sizeof(float);
|
||||||
@@ -101,9 +107,9 @@ namespace openVulkanoCpp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
image.second = std::make_unique<float[]>(size);
|
image.image = std::make_unique<float[]>(size);
|
||||||
inStream.read(reinterpret_cast<char*>(image.second.get()), size);
|
inStream.read(reinterpret_cast<char*>(image.image.get()), size);
|
||||||
return image;
|
return image;
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -103,19 +103,25 @@ namespace openVulkanoCpp
|
|||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static std::pair<PnmHeader, std::unique_ptr<char[]>> ReadImage(std::istream& inStream)
|
struct PnmImage
|
||||||
|
{
|
||||||
|
PnmHeader header;
|
||||||
|
std::unique_ptr<char[]> image;
|
||||||
|
|
||||||
|
static PnmImage ReadImage(std::istream& inStream)
|
||||||
{
|
{
|
||||||
std::pair<PnmHeader, std::unique_ptr<char[]>> image;
|
PnmImage image;
|
||||||
inStream >> image.first;
|
inStream >> image.header;
|
||||||
|
|
||||||
// TODO handle ascii mode
|
// TODO handle ascii mode
|
||||||
if (image.first.ascii) throw std::runtime_error("ascii mode not supported!");
|
if (image.header.ascii) throw std::runtime_error("ascii mode not supported!");
|
||||||
|
|
||||||
size_t size = image.first.GetImageSize();
|
size_t size = image.header.GetImageSize();
|
||||||
image.second = std::make_unique<char[]>(size);
|
image.image = std::make_unique<char[]>(size);
|
||||||
inStream.read(image.second.get(), size);
|
inStream.read(image.image.get(), size);
|
||||||
return image;
|
return image;
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user