mirror of
https://github.com/matrix-construct/construct
synced 2025-03-13 21:10:32 +01:00
ircd::magick: Add interface for shave operation.
This commit is contained in:
parent
c80bc298d0
commit
500e3938f6
2 changed files with 64 additions and 0 deletions
|
@ -17,6 +17,7 @@ namespace ircd::magick
|
|||
IRCD_EXCEPTION(ircd::error, error)
|
||||
|
||||
struct crop;
|
||||
struct shave;
|
||||
struct thumbnail;
|
||||
|
||||
std::tuple<ulong, string_view> version();
|
||||
|
@ -32,6 +33,18 @@ struct ircd::magick::thumbnail
|
|||
const result_closure &);
|
||||
};
|
||||
|
||||
struct ircd::magick::shave
|
||||
{
|
||||
using offset = std::pair<ssize_t, ssize_t>; // x, y
|
||||
using dimensions = std::pair<size_t, size_t>; // x, y
|
||||
using result_closure = std::function<void (const const_buffer &)>;
|
||||
|
||||
shave(const const_buffer &in,
|
||||
const dimensions &,
|
||||
const offset &,
|
||||
const result_closure &);
|
||||
};
|
||||
|
||||
struct ircd::magick::crop
|
||||
{
|
||||
using offset = std::pair<ssize_t, ssize_t>; // x, y
|
||||
|
|
|
@ -180,6 +180,57 @@ ircd::magick::thumbnail::thumbnail(const const_buffer &in,
|
|||
closure(result);
|
||||
}
|
||||
|
||||
//
|
||||
// shave
|
||||
//
|
||||
|
||||
ircd::magick::shave::shave(const const_buffer &in,
|
||||
const dimensions &dim,
|
||||
const offset &off,
|
||||
const result_closure &closure)
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
const ::RectangleInfo geometry
|
||||
{
|
||||
dim.first, // width
|
||||
dim.second, // height
|
||||
off.first, // x
|
||||
off.second, // y
|
||||
};
|
||||
|
||||
const custom_ptr<::Image> output
|
||||
{
|
||||
callex<::Image *>(::ShaveImage, input.get(), &geometry), ::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
|
||||
};
|
||||
|
||||
closure(result);
|
||||
}
|
||||
|
||||
//
|
||||
// crop
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue