Port freeze
This commit is contained in:
parent
a1b12e16b4
commit
d9a2e0bfb9
1 changed files with 23 additions and 22 deletions
|
@ -1,11 +1,11 @@
|
||||||
#include <Magick++.h>
|
|
||||||
#include <napi.h>
|
#include <napi.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <vips/vips8>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Magick;
|
using namespace vips;
|
||||||
|
|
||||||
Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
||||||
Napi::Env env = info.Env();
|
Napi::Env env = info.Env();
|
||||||
|
@ -54,29 +54,30 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
|
||||||
result.Set("data",
|
result.Set("data",
|
||||||
Napi::Buffer<char>::Copy(env, newData, data.Length()));
|
Napi::Buffer<char>::Copy(env, newData, data.Length()));
|
||||||
} else if (frame >= 0 && !loop) {
|
} else if (frame >= 0 && !loop) {
|
||||||
Blob blob;
|
VOption *options = VImage::option()->set("access", "sequential");
|
||||||
|
|
||||||
list<Image> frames;
|
VImage in = VImage::new_from_buffer(
|
||||||
try {
|
data.Data(), data.Length(), "",
|
||||||
readImages(&frames, Blob(data.Data(), data.Length()));
|
type == "gif" ? options->set("n", -1) : options)
|
||||||
} catch (Magick::WarningCoder &warning) {
|
.colourspace(VIPS_INTERPRETATION_sRGB);
|
||||||
cerr << "Coder Warning: " << warning.what() << endl;
|
if (!in.has_alpha()) in = in.bandjoin(255);
|
||||||
} catch (Magick::Warning &warning) {
|
|
||||||
cerr << "Warning: " << warning.what() << endl;
|
|
||||||
}
|
|
||||||
size_t frameSize = frames.size();
|
|
||||||
int framePos = clamp(frame, 0, (int)frameSize);
|
|
||||||
frames.resize(framePos + 1);
|
|
||||||
|
|
||||||
for_each(frames.begin(), frames.end(),
|
int page_height = vips_image_get_page_height(in.get_image());
|
||||||
animationIterationsImage(loop ? 0 : 1));
|
int n_pages = vips_image_get_n_pages(in.get_image());
|
||||||
for_each(frames.begin(), frames.end(), magickImage(type));
|
int framePos = clamp(frame, 0, (int)n_pages);
|
||||||
|
VImage out = in.crop(0, 0, in.width(), page_height * (framePos + 1));
|
||||||
|
out.set(VIPS_META_PAGE_HEIGHT, page_height);
|
||||||
|
out.set("loop", loop ? 0 : 1);
|
||||||
|
|
||||||
if (delay != 0)
|
if (delay) out.set("delay", delay);
|
||||||
for_each(frames.begin(), frames.end(), animationDelayImage(delay));
|
|
||||||
writeImages(frames.begin(), frames.end(), &blob);
|
void *buf;
|
||||||
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
|
size_t length;
|
||||||
blob.length()));
|
out.write_to_buffer(("." + type).c_str(), &buf, &length);
|
||||||
|
|
||||||
|
vips_thread_shutdown();
|
||||||
|
|
||||||
|
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
|
||||||
} else {
|
} else {
|
||||||
lastPos = (char *)memchr(fileData, '\x21', data.Length());
|
lastPos = (char *)memchr(fileData, '\x21', data.Length());
|
||||||
while (lastPos != NULL) {
|
while (lastPos != NULL) {
|
||||||
|
|
Loading…
Reference in a new issue