mirror of
https://github.com/matrix-construct/construct
synced 2024-06-02 18:18:56 +02:00
ircd::magick: Add a thumbnailer.
This commit is contained in:
parent
16f6fbc352
commit
2e14bfe337
|
@ -16,5 +16,15 @@ namespace ircd::magick
|
|||
{
|
||||
IRCD_EXCEPTION(ircd::error, error)
|
||||
|
||||
struct thumbnail;
|
||||
|
||||
std::tuple<ulong, string_view> version();
|
||||
}
|
||||
|
||||
struct ircd::magick::thumbnail
|
||||
:const_buffer
|
||||
{
|
||||
thumbnail(const const_buffer &in,
|
||||
const mutable_buffer &out,
|
||||
const std::pair<size_t, size_t> &xy);
|
||||
};
|
||||
|
|
|
@ -98,6 +98,54 @@ ircd::magick::version()
|
|||
return { number, string };
|
||||
}
|
||||
|
||||
//
|
||||
// thumbnail
|
||||
//
|
||||
|
||||
ircd::magick::thumbnail::thumbnail(const const_buffer &in,
|
||||
const mutable_buffer &out,
|
||||
const std::pair<size_t, size_t> &xy)
|
||||
:const_buffer{[&in, &out, &xy]
|
||||
{
|
||||
const custom_ptr<::ImageInfo> input_info
|
||||
{
|
||||
::CloneImageInfo(nullptr), ::DestroyImageInfo
|
||||
};
|
||||
|
||||
const custom_ptr<::ImageInfo> output_info
|
||||
{
|
||||
::CloneImageInfo(nullptr), ::DestroyImageInfo
|
||||
};
|
||||
|
||||
const custom_ptr<::Image> input
|
||||
{
|
||||
callex<::Image *>(::BlobToImage, input_info.get(), data(in), size(in)), ::DestroyImage // pollock
|
||||
};
|
||||
|
||||
const custom_ptr<::Image> output
|
||||
{
|
||||
callex<::Image *>(::ThumbnailImage, input.get(), xy.first, xy.second), ::DestroyImage
|
||||
};
|
||||
|
||||
size_t output_size(0);
|
||||
const auto output_data
|
||||
{
|
||||
callex<void *>(::ImageToBlob, output_info.get(), output.get(), &output_size)
|
||||
};
|
||||
|
||||
const const_buffer result
|
||||
{
|
||||
reinterpret_cast<char *>(output_data), output_size
|
||||
};
|
||||
|
||||
return const_buffer
|
||||
{
|
||||
data(out), copy(out, result)
|
||||
};
|
||||
}()}
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// util
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue