Added a way to probe images from a buffer
This commit is contained in:
@@ -77,6 +77,29 @@ namespace lms::image
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageProperties probeImage(std::span<const std::byte> encodedData)
|
||||||
|
{
|
||||||
|
LMS_SCOPED_TRACE_DETAILED("Image", "ProbeBuffer");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Magick::Image image;
|
||||||
|
Magick::Blob blob{ encodedData.data(), encodedData.size() };
|
||||||
|
image.ping(blob);
|
||||||
|
|
||||||
|
ImageProperties properties;
|
||||||
|
properties.width = image.size().width();
|
||||||
|
properties.height = image.size().height();
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
catch (Magick::Exception& e)
|
||||||
|
{
|
||||||
|
LMS_LOG(COVER, ERROR, "Caught Magick exception: " << e.what());
|
||||||
|
throw Exception{ std::string{ "Magick probe error: " } + e.what() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<IRawImage> decodeImage(std::span<const std::byte> encodedData)
|
std::unique_ptr<IRawImage> decodeImage(std::span<const std::byte> encodedData)
|
||||||
{
|
{
|
||||||
LMS_SCOPED_TRACE_DETAILED("Image", "DecodeBuffer");
|
LMS_SCOPED_TRACE_DETAILED("Image", "DecodeBuffer");
|
||||||
|
|||||||
@@ -60,6 +60,24 @@ namespace lms::image
|
|||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageProperties probeImage(std::span<const std::byte> encodedData)
|
||||||
|
{
|
||||||
|
LMS_SCOPED_TRACE_DETAILED("Image", "ProbeBuffer");
|
||||||
|
|
||||||
|
int x{};
|
||||||
|
int y{};
|
||||||
|
int comp{};
|
||||||
|
|
||||||
|
if (::stbi_info_from_memory(reinterpret_cast<const stbi_uc*>(encodedData.data()), static_cast<int>(encodedData.size()), &x, &y, &comp) == 0)
|
||||||
|
throw StbiException{ "Probe failed" };
|
||||||
|
|
||||||
|
ImageProperties properties;
|
||||||
|
properties.width = x;
|
||||||
|
properties.height = y;
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<IRawImage> decodeImage(std::span<const std::byte> encodedData)
|
std::unique_ptr<IRawImage> decodeImage(std::span<const std::byte> encodedData)
|
||||||
{
|
{
|
||||||
LMS_SCOPED_TRACE_DETAILED("Image", "DecodeBuffer");
|
LMS_SCOPED_TRACE_DETAILED("Image", "DecodeBuffer");
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace lms::image
|
|||||||
|
|
||||||
// All these methods may throw Exception
|
// All these methods may throw Exception
|
||||||
ImageProperties probeImage(const std::filesystem::path& path);
|
ImageProperties probeImage(const std::filesystem::path& path);
|
||||||
|
ImageProperties probeImage(std::span<const std::byte> encodedData);
|
||||||
|
|
||||||
std::unique_ptr<IRawImage> decodeImage(std::span<const std::byte> encodedData);
|
std::unique_ptr<IRawImage> decodeImage(std::span<const std::byte> encodedData);
|
||||||
std::unique_ptr<IRawImage> decodeImage(const std::filesystem::path& path);
|
std::unique_ptr<IRawImage> decodeImage(const std::filesystem::path& path);
|
||||||
|
|||||||
Reference in New Issue
Block a user