implement getting image size without reading the whole image
This commit is contained in:
@@ -31,6 +31,32 @@ namespace OpenVulkano::Image
|
||||
return loadJpeg(buffer.data(), buffer.size());
|
||||
}
|
||||
|
||||
bool ImageLoaderJpeg::GetImageDimensions(const std::string& filename, int& width, int& height)
|
||||
{
|
||||
#if __has_include("turbojpeg.h")
|
||||
auto image = Utils::ReadFile(filename);
|
||||
tjhandle jpegDecompressor = tjInitDecompress();
|
||||
if (!jpegDecompressor)
|
||||
{
|
||||
Logger::FILESYS->error("Failed to read jpeg header. Error: {}", tjGetErrorStr());
|
||||
return false;
|
||||
}
|
||||
int size = 0, jpegSubsamp = 0;
|
||||
int status = tjDecompressHeader2(jpegDecompressor, reinterpret_cast<unsigned char*>(image.Data()), image.Size(),
|
||||
&width, &height, &jpegSubsamp);
|
||||
if (status != 0)
|
||||
{
|
||||
Logger::FILESYS->error("Failed to read jpeg header. Error: {}", tjGetErrorStr());
|
||||
tjDestroy(jpegDecompressor);
|
||||
return false;
|
||||
}
|
||||
tjDestroy(jpegDecompressor);
|
||||
return true;
|
||||
#else
|
||||
return IImageLoader::GetDimensionsInternal(filename, width, height);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::unique_ptr<Image> ImageLoaderJpeg::loadJpeg(const uint8_t* data, size_t size)
|
||||
{
|
||||
#if __has_include("turbojpeg.h")
|
||||
|
||||
Reference in New Issue
Block a user