Properly clear vips error data

This commit is contained in:
Essem 2022-06-27 22:50:53 -05:00
parent 207d950a6c
commit 4ccaea7c91
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
33 changed files with 259 additions and 222 deletions

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Blur(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -31,15 +32,15 @@ Napi::Value Blur(const Napi::CallbackInfo &info) {
size_t length;
out.write_to_buffer(("." + type).c_str(), &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,8 @@ using namespace vips;
Napi::Value Caption(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
@ -20,7 +22,8 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
VImage::new_from_buffer(data.Data(), data.Length(), "",
type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
if (!in.has_alpha())
in = in.bandjoin(255);
int width = in.width();
int size = width / 10;
@ -62,17 +65,18 @@ Napi::Value Caption(const Napi::CallbackInfo &info) {
size_t length;
final.write_to_buffer(
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::New(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -22,7 +23,8 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
VImage::new_from_buffer(data.Data(), data.Length(), "",
type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
if (!in.has_alpha())
in = in.bandjoin(255);
int width = in.width();
int size = width / 13;
@ -66,17 +68,18 @@ Napi::Value CaptionTwo(const Napi::CallbackInfo &info) {
size_t length;
final.write_to_buffer(
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Circle(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -46,14 +47,14 @@ Napi::Value Circle(const Napi::CallbackInfo &info) {
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
return result;
}

View file

@ -10,6 +10,7 @@ VImage sepia = VImage::new_matrixv(3, 3, 0.3588, 0.7044, 0.1368, 0.2990, 0.5870,
Napi::Value Colors(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -36,15 +37,15 @@ Napi::Value Colors(const Napi::CallbackInfo &info) {
size_t length;
out.write_to_buffer(("." + type).c_str(), &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Crop(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -48,17 +49,18 @@ Napi::Value Crop(const Napi::CallbackInfo &info) {
size_t length;
final.write_to_buffer(
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,14 +7,13 @@ using namespace vips;
Napi::Value Deepfry(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
string type = obj.Get("type").As<Napi::String>().Utf8Value();
Napi::Object result = Napi::Object::New(env);
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
@ -34,20 +33,20 @@ Napi::Value Deepfry(const Napi::CallbackInfo &info) {
VImage final;
if (totalHeight > 65500 && type == "gif") {
vector<VImage> img;
for (int i = 0; i < nPages; i++) {
VImage img_frame = in.crop(0, i * pageHeight, width, pageHeight);
void *jpgBuf;
size_t jpgLength;
img_frame.write_to_buffer(
".jpg", &jpgBuf, &jpgLength,
VImage::option()->set("Q", 1)->set("strip", true));
VImage jpeged = VImage::new_from_buffer(jpgBuf, jpgLength, "");
jpeged.set(VIPS_META_PAGE_HEIGHT, pageHeight);
jpeged.set("delay", in.get_array_int("delay"));
img.push_back(jpeged);
}
final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
for (int i = 0; i < nPages; i++) {
VImage img_frame = in.crop(0, i * pageHeight, width, pageHeight);
void *jpgBuf;
size_t jpgLength;
img_frame.write_to_buffer(
".jpg", &jpgBuf, &jpgLength,
VImage::option()->set("Q", 1)->set("strip", true));
VImage jpeged = VImage::new_from_buffer(jpgBuf, jpgLength, "");
jpeged.set(VIPS_META_PAGE_HEIGHT, pageHeight);
jpeged.set("delay", in.get_array_int("delay"));
img.push_back(jpeged);
}
final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
} else {
void *jpgBuf;
size_t jpgLength;
@ -65,14 +64,15 @@ Napi::Value Deepfry(const Napi::CallbackInfo &info) {
type == "gif" ? VImage::option()->set("dither", 0)
: 0);
vips_thread_shutdown();
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Flag(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -58,13 +59,15 @@ Napi::Value Flag(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Flip(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -46,15 +47,15 @@ Napi::Value Flip(const Napi::CallbackInfo &info) {
size_t length;
out.write_to_buffer(("." + type).c_str(), &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Freeze(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -18,8 +19,6 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
? obj.Get("frame").As<Napi::Number>().Int32Value()
: -1;
Napi::Object result = Napi::Object::New(env);
char *fileData = data.Data();
char *match = (char *)"\x21\xFF\x0BNETSCAPE2.0\x03\x01";
char *descriptor = (char *)"\x2C\x00\x00\x00\x00";
@ -69,8 +68,6 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
size_t 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 {
lastPos = (char *)memchr(fileData, '\x21', data.Length());
@ -93,10 +90,13 @@ Napi::Value Freeze(const Napi::CallbackInfo &info) {
}
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -51,15 +52,15 @@ Napi::Value Gamexplain(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Globe(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -77,13 +78,15 @@ Napi::Value Globe(const Napi::CallbackInfo &info) {
size_t length;
final.write_to_buffer(".gif", &buf, &length);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", "gif");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Homebrew(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -34,15 +35,15 @@ Napi::Value Homebrew(const Napi::CallbackInfo &info) {
size_t length;
out.write_to_buffer(".png", &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", "png");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Invert(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -30,15 +31,15 @@ Napi::Value Invert(const Napi::CallbackInfo &info) {
size_t length;
out.write_to_buffer(("." + type).c_str(), &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Jpeg(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -16,8 +17,6 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
: 0;
string type = obj.Get("type").As<Napi::String>().Utf8Value();
Napi::Object result = Napi::Object::New(env);
if (type == "gif") {
VImage in =
VImage::new_from_buffer(
@ -67,8 +66,6 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
type == "gif" ? VImage::option()->set("dither", 0)
: 0);
vips_thread_shutdown();
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
} else {
@ -79,16 +76,16 @@ Napi::Value Jpeg(const Napi::CallbackInfo &info) {
".jpg", &buf, &length,
VImage::option()->set("Q", quality)->set("strip", true));
vips_thread_shutdown();
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", "jpg");
}
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Magik(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -48,14 +49,14 @@ Napi::Value Magik(const Napi::CallbackInfo &info) {
writeImages(blurred.begin(), blurred.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Meme(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -130,15 +131,15 @@ Napi::Value Meme(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Mirror(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -69,15 +70,15 @@ Napi::Value Mirror(const Napi::CallbackInfo &info) {
size_t length;
out.write_to_buffer(("." + type).c_str(), &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Motivate(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -108,13 +109,15 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 1) : 0);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,8 @@ using namespace vips;
Napi::Value Reddit(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
Napi::Buffer<char> data = obj.Get("data").As<Napi::Buffer<char>>();
@ -61,15 +63,15 @@ Napi::Value Reddit(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Resize(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -59,15 +60,15 @@ Napi::Value Resize(const Napi::CallbackInfo &info) {
size_t length;
out.write_to_buffer(("." + type).c_str(), &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Reverse(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -57,15 +58,15 @@ Napi::Value Reverse(const Napi::CallbackInfo &info) {
final.write_to_buffer(".gif", &buf, &length,
VImage::option()->set("dither", 0));
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", "gif");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Scott(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -59,14 +60,14 @@ Napi::Value Scott(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Snapchat(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -69,15 +70,15 @@ Napi::Value Snapchat(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Sonic(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -33,15 +34,15 @@ Napi::Value Sonic(const Napi::CallbackInfo &info) {
size_t length;
out.write_to_buffer(".png", &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", "png");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -37,13 +37,12 @@ void vipsRemove(Napi::Env *env, Napi::Object *result, Napi::Buffer<char> data,
size_t length;
out.write_to_buffer(".gif", &buf, &length);
vips_thread_shutdown();
result->Set("data", Napi::Buffer<char>::Copy(*env, (char *)buf, length));
}
Napi::Value Speed(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -54,8 +53,6 @@ Napi::Value Speed(const Napi::CallbackInfo &info) {
int speed =
obj.Has("speed") ? obj.Get("speed").As<Napi::Number>().Int32Value() : 2;
Napi::Object result = Napi::Object::New(env);
char *fileData = data.Data();
char *match = (char *)"\x00\x21\xF9\x04";
@ -106,10 +103,13 @@ Napi::Value Speed(const Napi::CallbackInfo &info) {
if (removeFrames) vipsRemove(&env, &result, data, speed);
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Tile(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -61,14 +62,14 @@ Napi::Value Tile(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value ToGif(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -14,30 +15,28 @@ Napi::Value ToGif(const Napi::CallbackInfo &info) {
string type = obj.Get("type").As<Napi::String>().Utf8Value();
if (type == "gif") {
Napi::Object result = Napi::Object::New(env);
result.Set("data", data);
result.Set("type", "gif");
return result;
} else {
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(data.Data(), data.Length(), "", options);
void *buf;
size_t length;
in.write_to_buffer(".gif", &buf, &length);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", "gif");
}
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(data.Data(), data.Length(), "", options);
void *buf;
size_t length;
in.write_to_buffer(".gif", &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", "gif");
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Uncaption(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -54,15 +55,15 @@ Napi::Value Uncaption(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -9,6 +9,7 @@ using namespace Magick;
Napi::Value Wall(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -54,14 +55,14 @@ Napi::Value Wall(const Napi::CallbackInfo &info) {
writeImages(mid.begin(), mid.end(), &blob);
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)blob.data(),
blob.length()));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Watermark(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -156,15 +157,15 @@ Napi::Value Watermark(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Whisper(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -83,15 +84,15 @@ Napi::Value Whisper(const Napi::CallbackInfo &info) {
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}

View file

@ -7,6 +7,7 @@ using namespace vips;
Napi::Value Zamn(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
Napi::Object obj = info[0].As<Napi::Object>();
@ -47,15 +48,15 @@ Napi::Value Zamn(const Napi::CallbackInfo &info) {
size_t length;
final.write_to_buffer(("." + type).c_str(), &buf, &length);
vips_thread_shutdown();
Napi::Object result = Napi::Object::New(env);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);
return result;
} catch (std::exception const &err) {
throw Napi::Error::New(env, err.what());
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
throw Napi::Error::New(env, "Unknown error");
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
}
vips_error_clear();
vips_thread_shutdown();
return result;
}