mirror of
https://github.com/lovell/sharp.git
synced 2026-02-10 00:26:15 +01:00
Add support for input array to join or animate #1580
This commit is contained in:
@@ -42,7 +42,39 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
// Open input
|
||||
vips::VImage image;
|
||||
sharp::ImageType inputImageType;
|
||||
std::tie(image, inputImageType) = sharp::OpenInput(baton->input);
|
||||
if (baton->join.empty()) {
|
||||
std::tie(image, inputImageType) = sharp::OpenInput(baton->input);
|
||||
} else {
|
||||
std::vector<VImage> images;
|
||||
bool hasAlpha = false;
|
||||
for (auto &join : baton->join) {
|
||||
std::tie(image, inputImageType) = sharp::OpenInput(join);
|
||||
image = sharp::EnsureColourspace(image, baton->colourspacePipeline);
|
||||
images.push_back(image);
|
||||
hasAlpha |= sharp::HasAlpha(image);
|
||||
}
|
||||
if (hasAlpha) {
|
||||
for (auto &image : images) {
|
||||
if (!sharp::HasAlpha(image)) {
|
||||
image = sharp::EnsureAlpha(image, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
baton->input->joinBackground.pop_back();
|
||||
}
|
||||
inputImageType = sharp::ImageType::PNG;
|
||||
image = VImage::arrayjoin(images, VImage::option()
|
||||
->set("across", baton->input->joinAcross)
|
||||
->set("shim", baton->input->joinShim)
|
||||
->set("background", baton->input->joinBackground)
|
||||
->set("halign", baton->input->joinHalign)
|
||||
->set("valign", baton->input->joinValign));
|
||||
if (baton->input->joinAnimated) {
|
||||
image = image.copy();
|
||||
image.set(VIPS_META_N_PAGES, static_cast<int>(images.size()));
|
||||
image.set(VIPS_META_PAGE_HEIGHT, static_cast<int>(image.height() / images.size()));
|
||||
}
|
||||
}
|
||||
VipsAccess access = baton->input->access;
|
||||
image = sharp::EnsureColourspace(image, baton->colourspacePipeline);
|
||||
|
||||
@@ -1069,6 +1101,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
||||
// Unsupported output format
|
||||
(baton->err).append("Unsupported output format ");
|
||||
if (baton->formatOut == "input") {
|
||||
(baton->err).append("when trying to match input format of ");
|
||||
(baton->err).append(ImageTypeId(inputImageType));
|
||||
} else {
|
||||
(baton->err).append(baton->formatOut);
|
||||
@@ -1495,6 +1528,14 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
|
||||
|
||||
// Input
|
||||
baton->input = sharp::CreateInputDescriptor(options.Get("input").As<Napi::Object>());
|
||||
// Join images together
|
||||
if (sharp::HasAttr(options, "join")) {
|
||||
Napi::Array join = options.Get("join").As<Napi::Array>();
|
||||
for (unsigned int i = 0; i < join.Length(); i++) {
|
||||
baton->join.push_back(
|
||||
sharp::CreateInputDescriptor(join.Get(i).As<Napi::Object>()));
|
||||
}
|
||||
}
|
||||
// Extract image options
|
||||
baton->topOffsetPre = sharp::AttrAsInt32(options, "topOffsetPre");
|
||||
baton->leftOffsetPre = sharp::AttrAsInt32(options, "leftOffsetPre");
|
||||
|
||||
Reference in New Issue
Block a user