From 3c16599126aef3c70907f22b2a722bfbe99a522a Mon Sep 17 00:00:00 2001 From: Essem Date: Wed, 28 Dec 2022 17:01:50 -0600 Subject: [PATCH] Deduplicate vips shutdown, reformat natives, remove soos alias --- .clang-format | 1 + commands/image-editing/soos.js | 2 +- config/messages.json | 1 + natives/blur.cc | 10 +- natives/blur.h | 5 +- natives/bounce.cc | 12 +-- natives/bounce.h | 3 +- natives/caption.cc | 14 +-- natives/caption.h | 5 +- natives/caption2.cc | 13 +-- natives/caption2.h | 5 +- natives/circle.cc | 6 +- natives/circle.h | 5 +- natives/colors.cc | 8 +- natives/colors.h | 5 +- natives/common.h | 24 ++--- natives/crop.cc | 9 +- natives/crop.h | 5 +- natives/deepfry.cc | 18 ++-- natives/deepfry.h | 5 +- natives/explode.h | 5 +- natives/flag.cc | 16 ++-- natives/flag.h | 5 +- natives/flip.cc | 13 +-- natives/flip.h | 5 +- natives/freeze.cc | 31 ++----- natives/freeze.h | 3 +- natives/gamexplain.cc | 13 +-- natives/gamexplain.h | 3 +- natives/globe.cc | 28 +++--- natives/globe.h | 3 +- natives/homebrew.cc | 6 +- natives/homebrew.h | 2 +- natives/image.cc | 161 +++++++++++++++++---------------- natives/invert.cc | 10 +- natives/invert.h | 3 +- natives/jpeg.cc | 16 ++-- natives/jpeg.h | 3 +- natives/magik.cc | 4 +- natives/magik.h | 3 +- natives/meme.cc | 20 ++-- natives/meme.h | 3 +- natives/mirror.cc | 9 +- natives/mirror.h | 3 +- natives/motivate.cc | 17 ++-- natives/motivate.h | 3 +- natives/reddit.cc | 12 +-- natives/reddit.h | 3 +- natives/resize.cc | 6 +- natives/resize.h | 3 +- natives/reverse.cc | 6 +- natives/reverse.h | 3 +- natives/scott.cc | 5 +- natives/scott.h | 3 +- natives/snapchat.cc | 11 +-- natives/snapchat.h | 3 +- natives/sonic.cc | 6 +- natives/sonic.h | 2 +- natives/speed.cc | 15 +-- natives/speed.h | 3 +- natives/spin.h | 3 +- natives/squish.cc | 9 +- natives/squish.h | 3 +- natives/swirl.cc | 10 +- natives/swirl.h | 3 +- natives/tile.cc | 4 +- natives/tile.h | 3 +- natives/togif.cc | 16 +--- natives/togif.h | 3 +- natives/uncanny.cc | 13 +-- natives/uncanny.h | 3 +- natives/uncaption.cc | 14 +-- natives/uncaption.h | 5 +- natives/wall.cc | 4 +- natives/wall.h | 3 +- natives/watermark.cc | 60 ++++++------ natives/watermark.h | 5 +- natives/whisper.cc | 9 +- natives/whisper.h | 3 +- natives/zamn.cc | 23 ++--- natives/zamn.h | 3 +- 81 files changed, 360 insertions(+), 464 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..5371cb6 --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: google \ No newline at end of file diff --git a/commands/image-editing/soos.js b/commands/image-editing/soos.js index 14f12a8..9f70dda 100644 --- a/commands/image-editing/soos.js +++ b/commands/image-editing/soos.js @@ -6,7 +6,7 @@ class SooSCommand extends ImageCommand { }; static description = "\"Loops\" an image sequence by reversing it when it's finished"; - static aliases = ["bounce", "boomerang"]; + static aliases = ["boomerang"]; static requiresGIF = true; static noImage = "You need to provide an image/GIF to loop!"; diff --git a/config/messages.json b/config/messages.json index e4cec8d..d6d5d25 100644 --- a/config/messages.json +++ b/config/messages.json @@ -195,6 +195,7 @@ "Pizza Tower", "ANTONBLAST", "[object Object]", + "Xonotic", "The clock is ticking." ] } diff --git a/natives/blur.cc b/natives/blur.cc index 3ce0257..8cdebd4 100644 --- a/natives/blur.cc +++ b/natives/blur.cc @@ -1,9 +1,9 @@ -#include "common.h" - #include #include #include +#include "common.h" + using namespace std; using namespace vips; @@ -17,8 +17,7 @@ char *Blur(string *type, char *BufferData, size_t BufferLength, *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); // TODO: find a better way to calculate the intensity for GIFs without // splitting frames @@ -28,8 +27,5 @@ char *Blur(string *type, char *BufferData, size_t BufferLength, void *buf; out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); - return (char *)buf; } diff --git a/natives/blur.h b/natives/blur.h index 1092fc3..8b017e2 100644 --- a/natives/blur.h +++ b/natives/blur.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Blur(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Blur(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/bounce.cc b/natives/bounce.cc index f179e72..7faad55 100644 --- a/natives/bounce.cc +++ b/natives/bounce.cc @@ -1,14 +1,14 @@ -#include "common.h" #include #include +#include "common.h" + using namespace std; using namespace vips; char *Bounce(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - VOption *options = VImage::option(); VImage in = @@ -17,8 +17,7 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength, *type == "gif" ? options->set("n", -1)->set("access", "sequential") : 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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -31,7 +30,8 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength, VImage img_frame = *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; double height = halfHeight * ((abs(sin(i * mult)) * -1) + 1); - VImage embedded = img_frame.embed(0, height, width, pageHeight + halfHeight); + VImage embedded = + img_frame.embed(0, height, width, pageHeight + halfHeight); img.push_back(embedded); } VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1)); @@ -46,7 +46,5 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength, *type = "gif"; - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/bounce.h b/natives/bounce.h index ab77b54..44a329f 100644 --- a/natives/bounce.h +++ b/natives/bounce.h @@ -4,4 +4,5 @@ using std::string; -char* Bounce(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Bounce(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/caption.cc b/natives/caption.cc index d1afdbf..d1824af 100644 --- a/natives/caption.cc +++ b/natives/caption.cc @@ -1,15 +1,13 @@ -#include "common.h" - #include - #include +#include "common.h" + using namespace std; using namespace vips; char *Caption(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - string caption = GetArgument(Arguments, "caption"); string font = GetArgument(Arguments, "font"); string basePath = GetArgument(Arguments, "basePath"); @@ -21,8 +19,7 @@ char *Caption(string *type, char *BufferData, size_t BufferLength, *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; @@ -73,10 +70,7 @@ char *Caption(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); - - vips_error_clear(); - vips_thread_shutdown(); + : 0); return (char *)buf; } diff --git a/natives/caption.h b/natives/caption.h index 1792125..a84ccb1 100644 --- a/natives/caption.h +++ b/natives/caption.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Caption(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Caption(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/caption2.cc b/natives/caption2.cc index 2adb365..a7bf181 100644 --- a/natives/caption2.cc +++ b/natives/caption2.cc @@ -1,15 +1,14 @@ -#include "common.h" - #include #include #include +#include "common.h" + using namespace std; using namespace vips; char *CaptionTwo(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - bool top = GetArgument(Arguments, "top"); string caption = GetArgument(Arguments, "caption"); string font = GetArgument(Arguments, "font"); @@ -22,8 +21,7 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength, *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; @@ -76,10 +74,7 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); - - vips_error_clear(); - vips_thread_shutdown(); + : 0); return (char *)buf; } diff --git a/natives/caption2.h b/natives/caption2.h index 7719f4a..d45e2d2 100644 --- a/natives/caption2.h +++ b/natives/caption2.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* CaptionTwo(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* CaptionTwo(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/circle.cc b/natives/circle.cc index d0e0232..3834be3 100644 --- a/natives/circle.cc +++ b/natives/circle.cc @@ -1,4 +1,3 @@ -#include "common.h" #include #include @@ -7,12 +6,13 @@ #include #include +#include "common.h" + using namespace std; using namespace Magick; char *Circle(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - Blob blob; list frames; @@ -45,7 +45,7 @@ char *Circle(string *type, char *BufferData, size_t BufferLength, writeImages(blurred.begin(), blurred.end(), &blob); *DataSize = blob.length(); - + // workaround because the data is tied to the blob char *data = (char *)malloc(*DataSize); memcpy(data, blob.data(), *DataSize); diff --git a/natives/circle.h b/natives/circle.h index cc577e8..283ca79 100644 --- a/natives/circle.h +++ b/natives/circle.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Circle(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Circle(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/colors.cc b/natives/colors.cc index 757d1c3..6c8fa62 100644 --- a/natives/colors.cc +++ b/natives/colors.cc @@ -1,9 +1,9 @@ -#include "common.h" - #include #include #include +#include "common.h" + using namespace std; using namespace vips; @@ -12,7 +12,6 @@ VImage sepia = VImage::new_matrixv(3, 3, 0.3588, 0.7044, 0.1368, 0.2990, 0.5870, char *Colors(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - string color = GetArgument(Arguments, "color"); VOption *options = VImage::option()->set("access", "sequential"); @@ -33,8 +32,5 @@ char *Colors(string *type, char *BufferData, size_t BufferLength, void *buf; out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); - return (char *)buf; } diff --git a/natives/colors.h b/natives/colors.h index 8106b65..d0bddf5 100644 --- a/natives/colors.h +++ b/natives/colors.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Colors(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Colors(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/common.h b/natives/common.h index 68b6f8e..2099433 100644 --- a/natives/common.h +++ b/natives/common.h @@ -1,13 +1,13 @@ #pragma once -#include -#include #include +#include #include +#include +using std::map; using std::string; using std::variant; -using std::map; typedef variant ArgumentVariant; typedef map ArgumentMap; @@ -25,19 +25,21 @@ template T GetArgumentWithFallback(ArgumentMap map, string key, T fallback) { try { return std::get(map.at(key)); - } catch (...) { // this is, not great... + } catch (...) { // this is, not great... return fallback; } } #define MAP_HAS(ARRAY, KEY) (ARRAY.count(KEY) > 0) -#define MAP_GET(ARRAY, KEY, TYPE) (MAP_HAS(ARRAY, KEY) ? get(ARRAY.at(KEY)) : NULL) // C++ has forced my hand -#define MAP_GET_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) (MAP_HAS(ARRAY, KEY) ? get(ARRAY.at(KEY)) : FALLBACK) +#define MAP_GET(ARRAY, KEY, TYPE) \ + (MAP_HAS(ARRAY, KEY) ? get(ARRAY.at(KEY)) \ + : NULL) // C++ has forced my hand +#define MAP_GET_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) \ + (MAP_HAS(ARRAY, KEY) ? get(ARRAY.at(KEY)) : FALLBACK) #define ARG_TYPES std::variant -const std::unordered_map fontPaths { - {"futura", "assets/fonts/caption.otf"}, - {"helvetica", "assets/fonts/caption2.ttf"}, - {"roboto", "assets/fonts/reddit.ttf"} -}; \ No newline at end of file +const std::unordered_map fontPaths{ + {"futura", "assets/fonts/caption.otf"}, + {"helvetica", "assets/fonts/caption2.ttf"}, + {"roboto", "assets/fonts/reddit.ttf"}}; \ No newline at end of file diff --git a/natives/crop.cc b/natives/crop.cc index 4d895d5..07cbad5 100644 --- a/natives/crop.cc +++ b/natives/crop.cc @@ -1,14 +1,14 @@ -#include "common.h" #include #include #include +#include "common.h" + using namespace std; using namespace vips; char *Crop(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - VOption *options = VImage::option()->set("access", "sequential"); VImage in = @@ -44,10 +44,7 @@ char *Crop(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); - - vips_error_clear(); - vips_thread_shutdown(); + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/crop.h b/natives/crop.h index 5745da4..439b4d1 100644 --- a/natives/crop.h +++ b/natives/crop.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Crop(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Crop(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/deepfry.cc b/natives/deepfry.cc index b6f09e7..dce5b97 100644 --- a/natives/deepfry.cc +++ b/natives/deepfry.cc @@ -1,13 +1,13 @@ -#include "common.h" #include #include +#include "common.h" + using namespace std; using namespace vips; char *Deepfry(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - VOption *options = VImage::option()->set("access", "sequential"); VImage in = @@ -15,8 +15,7 @@ char *Deepfry(string *type, char *BufferData, size_t BufferLength, *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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -49,16 +48,13 @@ char *Deepfry(string *type, char *BufferData, size_t BufferLength, VImage::option()->set("Q", 1)->set("strip", true)); final = VImage::new_from_buffer(jpgBuf, jpgLength, ""); final.set(VIPS_META_PAGE_HEIGHT, pageHeight); - if (*type == "gif") - final.set("delay", fried.get_array_int("delay")); + if (*type == "gif") final.set("delay", fried.get_array_int("delay")); } void *buf; - final.write_to_buffer(("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0) : 0); - - vips_error_clear(); - vips_thread_shutdown(); + final.write_to_buffer( + ("." + *type).c_str(), &buf, DataSize, + *type == "gif" ? VImage::option()->set("dither", 0) : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/deepfry.h b/natives/deepfry.h index dfdfc45..00cc403 100644 --- a/natives/deepfry.h +++ b/natives/deepfry.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Deepfry(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Deepfry(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/explode.h b/natives/explode.h index 6967d91..255224f 100644 --- a/natives/explode.h +++ b/natives/explode.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Explode(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Explode(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/flag.cc b/natives/flag.cc index 790da54..5659be8 100644 --- a/natives/flag.cc +++ b/natives/flag.cc @@ -1,15 +1,14 @@ -#include "common.h" - #include #include #include +#include "common.h" + using namespace std; using namespace vips; char *Flag(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - string overlay = GetArgument(Arguments, "overlay"); string basePath = GetArgument(Arguments, "basePath"); @@ -20,8 +19,7 @@ char *Flag(string *type, char *BufferData, size_t BufferLength, *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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -31,8 +29,8 @@ char *Flag(string *type, char *BufferData, size_t BufferLength, VImage overlayInput = VImage::new_from_file(assetPath.c_str()); VImage overlayImage = overlayInput.resize( (double)width / (double)overlayInput.width(), - VImage::option()->set("vscale", (double)pageHeight / - (double)overlayInput.height())); + VImage::option()->set( + "vscale", (double)pageHeight / (double)overlayInput.height())); if (!overlayImage.has_alpha()) { overlayImage = overlayImage.bandjoin(127); } else { @@ -56,9 +54,7 @@ char *Flag(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/flag.h b/natives/flag.h index c392cae..976266b 100644 --- a/natives/flag.h +++ b/natives/flag.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Flag(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Flag(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/flip.cc b/natives/flip.cc index c72b584..a9eb71e 100644 --- a/natives/flip.cc +++ b/natives/flip.cc @@ -1,15 +1,13 @@ -#include "common.h" - #include - #include +#include "common.h" + using namespace std; using namespace vips; char *Flip(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - bool flop = GetArgument(Arguments, "flop"); VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", @@ -18,8 +16,7 @@ char *Flip(string *type, char *BufferData, size_t BufferLength, "access", "sequential") : 0) .colourspace(VIPS_INTERPRETATION_sRGB); - if (!in.has_alpha()) - in = in.bandjoin(255); + if (!in.has_alpha()) in = in.bandjoin(255); VImage out; if (flop) { @@ -44,9 +41,7 @@ char *Flip(string *type, char *BufferData, size_t BufferLength, out.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/flip.h b/natives/flip.h index ec66b15..9029498 100644 --- a/natives/flip.h +++ b/natives/flip.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Flip(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Flip(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/freeze.cc b/natives/freeze.cc index 8e3b1ce..6174dba 100644 --- a/natives/freeze.cc +++ b/natives/freeze.cc @@ -1,16 +1,14 @@ -#include "common.h" - #include #include - #include +#include "common.h" + using namespace std; using namespace vips; char *Freeze(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - bool loop = GetArgumentWithFallback(Arguments, "loop", false); int frame = GetArgumentWithFallback(Arguments, "frame", -1); @@ -42,22 +40,17 @@ char *Freeze(string *type, char *BufferData, size_t BufferLength, *DataSize = BufferLength + 19; break; } - if (none) - *DataSize = BufferLength; - - vips_error_clear(); - vips_thread_shutdown(); + if (none) *DataSize = BufferLength; return newData; } else if (frame >= 0 && !loop) { VOption *options = VImage::option()->set("access", "sequential"); - VImage in = - VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) - .colourspace(VIPS_INTERPRETATION_sRGB); - if (!in.has_alpha()) - in = in.bandjoin(255); + VImage in = VImage::new_from_buffer( + BufferData, BufferLength, "", + *type == "gif" ? options->set("n", -1) : options) + .colourspace(VIPS_INTERPRETATION_sRGB); + if (!in.has_alpha()) in = in.bandjoin(255); int pageHeight = vips_image_get_page_height(in.get_image()); int nPages = vips_image_get_n_pages(in.get_image()); @@ -69,9 +62,6 @@ char *Freeze(string *type, char *BufferData, size_t BufferLength, void *buf; out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); - return (char *)buf; } else { lastPos = (char *)memchr(fileData, '\x21', BufferLength); @@ -86,11 +76,8 @@ char *Freeze(string *type, char *BufferData, size_t BufferLength, none = false; break; } - if (none) - *DataSize = BufferLength; + if (none) *DataSize = BufferLength; - vips_error_clear(); - vips_thread_shutdown(); return fileData; } } diff --git a/natives/freeze.h b/natives/freeze.h index 81ceca5..dde7da9 100644 --- a/natives/freeze.h +++ b/natives/freeze.h @@ -4,4 +4,5 @@ using std::string; -char* Freeze(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Freeze(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/gamexplain.cc b/natives/gamexplain.cc index e497e09..21c33f1 100644 --- a/natives/gamexplain.cc +++ b/natives/gamexplain.cc @@ -1,13 +1,12 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; char *Gamexplain(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - string basePath = GetArgument(Arguments, "basePath"); VOption *options = VImage::option()->set("access", "sequential"); @@ -16,8 +15,7 @@ char *Gamexplain(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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); string assetPath = basePath + "assets/images/gamexplain.png"; VImage tmpl = VImage::new_from_file(assetPath.c_str()); @@ -45,10 +43,7 @@ char *Gamexplain(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); - - vips_error_clear(); - vips_thread_shutdown(); + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/gamexplain.h b/natives/gamexplain.h index 45289b9..42c6881 100644 --- a/natives/gamexplain.h +++ b/natives/gamexplain.h @@ -4,4 +4,5 @@ using std::string; -char* Gamexplain(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Gamexplain(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/globe.cc b/natives/globe.cc index 8735c6c..cd2874d 100644 --- a/natives/globe.cc +++ b/natives/globe.cc @@ -1,13 +1,12 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; char *Globe(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - string basePath = GetArgument(Arguments, "basePath"); VOption *options = VImage::option(); @@ -16,10 +15,9 @@ char *Globe(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer( BufferData, BufferLength, "", *type == "gif" ? options->set("n", -1)->set("access", "sequential") - : options) + : 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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -28,17 +26,15 @@ char *Globe(string *type, char *BufferData, size_t BufferLength, double size = min(width, pageHeight); string diffPath = basePath + "assets/images/globediffuse.png"; - VImage diffuse = - VImage::new_from_file(diffPath.c_str()) - .resize(size / 500.0, - VImage::option()->set("kernel", VIPS_KERNEL_CUBIC)) / - 255; + VImage diffuse = VImage::new_from_file(diffPath.c_str()) + .resize(size / 500.0, VImage::option()->set( + "kernel", VIPS_KERNEL_CUBIC)) / + 255; string specPath = basePath + "assets/images/globespec.png"; - VImage specular = - VImage::new_from_file(specPath.c_str()) - .resize(size / 500.0, - VImage::option()->set("kernel", VIPS_KERNEL_CUBIC)); + VImage specular = VImage::new_from_file(specPath.c_str()) + .resize(size / 500.0, VImage::option()->set( + "kernel", VIPS_KERNEL_CUBIC)); string distortPath = basePath + "assets/images/spheremap.png"; VImage distort = @@ -73,7 +69,5 @@ char *Globe(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer(".gif", &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/globe.h b/natives/globe.h index af2e1a1..66a97fb 100644 --- a/natives/globe.h +++ b/natives/globe.h @@ -4,4 +4,5 @@ using std::string; -char* Globe(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Globe(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/homebrew.cc b/natives/homebrew.cc index 1f2c90e..209630b 100644 --- a/natives/homebrew.cc +++ b/natives/homebrew.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -34,7 +34,5 @@ char *Homebrew(string *type, ArgumentMap Arguments, size_t *DataSize) { *type = "png"; - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/homebrew.h b/natives/homebrew.h index bc89ac0..d6db633 100644 --- a/natives/homebrew.h +++ b/natives/homebrew.h @@ -4,4 +4,4 @@ using std::string; -char* Homebrew(string *type, ArgumentMap Arguments, size_t *DataSize); \ No newline at end of file +char *Homebrew(string *type, ArgumentMap Arguments, size_t *DataSize); \ No newline at end of file diff --git a/natives/image.cc b/natives/image.cc index 96371de..b85efb6 100644 --- a/natives/image.cc +++ b/natives/image.cc @@ -1,16 +1,16 @@ -#include "common.h" - #include + +#include #include #include -#include #include "blur.h" #include "bounce.h" -#include "colors.h" #include "caption.h" #include "caption2.h" #include "circle.h" +#include "colors.h" +#include "common.h" #include "crop.h" #include "deepfry.h" #include "explode.h" @@ -25,7 +25,6 @@ #include "magik.h" #include "meme.h" #include "mirror.h" -#include "swirl.h" #include "motivate.h" #include "reddit.h" #include "resize.h" @@ -36,6 +35,7 @@ #include "speed.h" #include "spin.h" #include "squish.h" +#include "swirl.h" #include "tile.h" #include "togif.h" #include "uncanny.h" @@ -52,50 +52,50 @@ using namespace std; -std::map FunctionMap = { - {"blur", &Blur}, - {"bounce", &Bounce}, - {"caption", &Caption}, - {"captionTwo", &CaptionTwo}, - {"circle", &Circle}, - {"colors", &Colors}, - {"crop", &Crop}, - {"deepfry", &Deepfry}, - {"explode", &Explode}, - {"flag", &Flag}, - {"flip", &Flip}, - {"freeze", &Freeze}, - {"gamexplain", Gamexplain}, - {"globe", Globe}, - {"invert", Invert}, - {"jpeg", Jpeg}, - {"magik", Magik}, - {"meme", Meme}, - {"mirror", Mirror}, - {"motivate", Motivate}, - {"reddit", Reddit}, - {"resize", Resize}, - {"reverse", Reverse}, - {"scott", Scott}, - {"snapchat", Snapchat}, - {"speed", &Speed}, - {"spin", Spin}, - {"squish", Squish}, - {"swirl", Swirl}, - {"tile", Tile}, - {"togif", ToGif}, - {"uncanny", Uncanny}, - {"uncaption", &Uncaption}, - {"wall", Wall}, - {"watermark", &Watermark}, - {"whisper", Whisper}, - {"zamn", Zamn} -}; +std::map + FunctionMap = {{"blur", &Blur}, + {"bounce", &Bounce}, + {"caption", &Caption}, + {"captionTwo", &CaptionTwo}, + {"circle", &Circle}, + {"colors", &Colors}, + {"crop", &Crop}, + {"deepfry", &Deepfry}, + {"explode", &Explode}, + {"flag", &Flag}, + {"flip", &Flip}, + {"freeze", &Freeze}, + {"gamexplain", Gamexplain}, + {"globe", Globe}, + {"invert", Invert}, + {"jpeg", Jpeg}, + {"magik", Magik}, + {"meme", Meme}, + {"mirror", Mirror}, + {"motivate", Motivate}, + {"reddit", Reddit}, + {"resize", Resize}, + {"reverse", Reverse}, + {"scott", Scott}, + {"snapchat", Snapchat}, + {"speed", &Speed}, + {"spin", Spin}, + {"squish", Squish}, + {"swirl", Swirl}, + {"tile", Tile}, + {"togif", ToGif}, + {"uncanny", Uncanny}, + {"uncaption", &Uncaption}, + {"wall", Wall}, + {"watermark", &Watermark}, + {"whisper", Whisper}, + {"zamn", Zamn}}; -std::map NoInputFunctionMap = { - {"homebrew", Homebrew}, - {"sonic", Sonic} -}; +std::map + NoInputFunctionMap = {{"homebrew", Homebrew}, {"sonic", Sonic}}; bool isNapiValueInt(Napi::Env& env, Napi::Value& num) { return env.Global() @@ -108,21 +108,23 @@ bool isNapiValueInt(Napi::Env& env, Napi::Value& num) { .Value(); } -Napi::Value ProcessImage(const Napi::CallbackInfo &info) { +Napi::Value ProcessImage(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); Napi::Object result = Napi::Object::New(env); try { string command = info[0].As().Utf8Value(); Napi::Object obj = info[1].As(); - string type = obj.Has("type") ? obj.Get("type").As().Utf8Value() : NULL; + string type = + obj.Has("type") ? obj.Get("type").As().Utf8Value() : NULL; Napi::Array properties = obj.GetPropertyNames(); ArgumentMap Arguments; for (unsigned int i = 0; i < properties.Length(); i++) { - string property = properties.Get(uint32_t(i)).As().Utf8Value(); + string property = + properties.Get(uint32_t(i)).As().Utf8Value(); if (property == "data") { continue; @@ -142,23 +144,30 @@ Napi::Value ProcessImage(const Napi::CallbackInfo &info) { } } else { throw "Unimplemented value type passed to image native."; - //Arguments[property] = val; + // Arguments[property] = val; } } size_t length = 0; char* buf; if (obj.Has("data")) { - Napi::Buffer data = obj.Has("data") ? obj.Get("data").As>() : Napi::Buffer::New(env, 0); - buf = FunctionMap.at(command)(&type, data.Data(), data.Length(), Arguments, &length); + Napi::Buffer data = obj.Has("data") + ? obj.Get("data").As>() + : Napi::Buffer::New(env, 0); + buf = FunctionMap.at(command)(&type, data.Data(), data.Length(), + Arguments, &length); } else { buf = NoInputFunctionMap.at(command)(&type, Arguments, &length); } - result.Set("data", Napi::Buffer::New(env, buf, length, [](Napi::Env env, void* data) { - free(data); - })); + + vips_error_clear(); + vips_thread_shutdown(); + + result.Set("data", Napi::Buffer::New( + env, buf, length, + [](Napi::Env env, void* data) { free(data); })); result.Set("type", type); - } catch (std::exception const &err) { + } catch (std::exception const& err) { Napi::Error::New(env, err.what()).ThrowAsJavaScriptException(); } catch (...) { Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException(); @@ -167,30 +176,30 @@ Napi::Value ProcessImage(const Napi::CallbackInfo &info) { return result; } -Napi::Object Init(Napi::Env env, Napi::Object exports){ +Napi::Object Init(Napi::Env env, Napi::Object exports) { #ifdef _WIN32 Magick::InitializeMagick(""); #endif - if (vips_init("")) - vips_error_exit(NULL); - exports.Set(Napi::String::New(env, "image"), Napi::Function::New(env, ProcessImage)); // new function handler + if (vips_init("")) vips_error_exit(NULL); + exports.Set(Napi::String::New(env, "image"), + Napi::Function::New(env, ProcessImage)); // new function handler - Napi::Array arr = Napi::Array::New(env); - size_t i = 0; - for (auto const& imap: FunctionMap) { - Napi::HandleScope scope(env); - arr[i] = Napi::String::New(env, imap.first); - i++; - } - for (auto const& imap: NoInputFunctionMap) { - Napi::HandleScope scope(env); - arr[i] = Napi::String::New(env, imap.first); - i++; - } + Napi::Array arr = Napi::Array::New(env); + size_t i = 0; + for (auto const& imap : FunctionMap) { + Napi::HandleScope scope(env); + arr[i] = Napi::String::New(env, imap.first); + i++; + } + for (auto const& imap : NoInputFunctionMap) { + Napi::HandleScope scope(env); + arr[i] = Napi::String::New(env, imap.first); + i++; + } - exports.Set(Napi::String::New(env, "funcs"), arr); + exports.Set(Napi::String::New(env, "funcs"), arr); - return exports; + return exports; } NODE_API_MODULE(addon, Init) diff --git a/natives/invert.cc b/natives/invert.cc index cf7a16b..376c066 100644 --- a/natives/invert.cc +++ b/natives/invert.cc @@ -1,21 +1,19 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; char *Invert(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - VOption *options = VImage::option()->set("access", "sequential"); VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", *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); VImage noAlpha = in.extract_band(0, VImage::option()->set("n", in.bands() - 1)); @@ -25,7 +23,5 @@ char *Invert(string *type, char *BufferData, size_t BufferLength, void *buf; out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/invert.h b/natives/invert.h index b55e80f..42f7ea8 100644 --- a/natives/invert.h +++ b/natives/invert.h @@ -4,4 +4,5 @@ using std::string; -char* Invert(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Invert(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/jpeg.cc b/natives/jpeg.cc index c79b8fc..9dcb47d 100644 --- a/natives/jpeg.cc +++ b/natives/jpeg.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -16,8 +16,7 @@ char *Jpeg(string *type, char *BufferData, size_t BufferLength, BufferData, BufferLength, "", VImage::option()->set("access", "sequential")->set("n", -1)) .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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -53,18 +52,15 @@ char *Jpeg(string *type, char *BufferData, size_t BufferLength, final.set("delay", in.get_array_int("delay")); } - final.write_to_buffer(("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0) - : 0); + final.write_to_buffer( + ("." + *type).c_str(), &buf, DataSize, + *type == "gif" ? VImage::option()->set("dither", 0) : 0); } else { VImage in = VImage::new_from_buffer(BufferData, BufferLength, ""); in.write_to_buffer(".jpg", &buf, DataSize, VImage::option()->set("Q", quality)->set("strip", true)); - *type = "jpg"; } - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } diff --git a/natives/jpeg.h b/natives/jpeg.h index 57c5d7c..ed67612 100644 --- a/natives/jpeg.h +++ b/natives/jpeg.h @@ -4,4 +4,5 @@ using std::string; -char* Jpeg(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Jpeg(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/magik.cc b/natives/magik.cc index ad70677..1cbb1b8 100644 --- a/natives/magik.cc +++ b/natives/magik.cc @@ -1,16 +1,16 @@ -#include "common.h" #include #include #include #include +#include "common.h" + using namespace std; using namespace Magick; char *Magik(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - Blob blob; list frames; diff --git a/natives/magik.h b/natives/magik.h index af3cf10..37013a9 100644 --- a/natives/magik.h +++ b/natives/magik.h @@ -4,4 +4,5 @@ using std::string; -char* Magik(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Magik(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/meme.cc b/natives/meme.cc index 1a9a758..9b3dc5d 100644 --- a/natives/meme.cc +++ b/natives/meme.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -18,8 +18,7 @@ char *Meme(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -101,11 +100,10 @@ char *Meme(string *type, char *BufferData, size_t BufferLength, } bottomOutline = (bottomOutline == zeroVec); VImage bottomInvert = bottomOutline.extract_band(3).invert(); - bottomOutline = - bottomOutline - .extract_band(0, - VImage::option()->set("n", bottomOutline.bands() - 1)) - .bandjoin(bottomInvert); + bottomOutline = bottomOutline + .extract_band(0, VImage::option()->set( + "n", bottomOutline.bands() - 1)) + .bandjoin(bottomInvert); bottomText = bottomOutline.composite2(bottomIn, VIPS_BLEND_MODE_OVER); } @@ -134,9 +132,7 @@ char *Meme(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/meme.h b/natives/meme.h index e940ded..5d7bf58 100644 --- a/natives/meme.h +++ b/natives/meme.h @@ -4,4 +4,5 @@ using std::string; -char* Meme(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Meme(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/mirror.cc b/natives/mirror.cc index 96bea65..47bf015 100644 --- a/natives/mirror.cc +++ b/natives/mirror.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -16,8 +16,7 @@ char *Mirror(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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); VImage out; @@ -61,7 +60,5 @@ char *Mirror(string *type, char *BufferData, size_t BufferLength, void *buf; out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } diff --git a/natives/mirror.h b/natives/mirror.h index 8db0b2d..3ed6dac 100644 --- a/natives/mirror.h +++ b/natives/mirror.h @@ -4,4 +4,5 @@ using std::string; -char* Mirror(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Mirror(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/motivate.cc b/natives/motivate.cc index e800b10..11c9b20 100644 --- a/natives/motivate.cc +++ b/natives/motivate.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -18,8 +18,7 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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 / 5; @@ -100,8 +99,7 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength, VImage::option()->set("background", 0x000000)->set("expand", true)); } if (bottom_text != "") { - if (top_text == "") - frame = bordered3; + if (top_text == "") frame = bordered3; frame = frame.join( bottomImage.gravity(VIPS_COMPASS_DIRECTION_NORTH, bordered3.width(), bottomImage.height() + (size / 4), @@ -117,10 +115,9 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength, final.set(VIPS_META_PAGE_HEIGHT, height); void *buf; - final.write_to_buffer(("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 1) : 0); + final.write_to_buffer( + ("." + *type).c_str(), &buf, DataSize, + *type == "gif" ? VImage::option()->set("dither", 1) : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } diff --git a/natives/motivate.h b/natives/motivate.h index a23f79e..924f640 100644 --- a/natives/motivate.h +++ b/natives/motivate.h @@ -4,4 +4,5 @@ using std::string; -char* Motivate(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Motivate(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/reddit.cc b/natives/reddit.cc index 2391e60..d4b02e7 100644 --- a/natives/reddit.cc +++ b/natives/reddit.cc @@ -1,13 +1,12 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; char *Reddit(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - string text = GetArgument(Arguments, "text"); string basePath = GetArgument(Arguments, "basePath"); @@ -17,8 +16,7 @@ char *Reddit(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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); string assetPath = basePath + "assets/images/reddit.png"; VImage tmpl = VImage::new_from_file(assetPath.c_str()); @@ -62,9 +60,7 @@ char *Reddit(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/reddit.h b/natives/reddit.h index df3f035..7acdfd5 100644 --- a/natives/reddit.h +++ b/natives/reddit.h @@ -4,4 +4,5 @@ using std::string; -char* Reddit(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Reddit(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/resize.cc b/natives/resize.cc index b1bdf92..595bb30 100644 --- a/natives/resize.cc +++ b/natives/resize.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -50,7 +50,5 @@ char *Resize(string *type, char *BufferData, size_t BufferLength, void *buf; out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/resize.h b/natives/resize.h index 8c7740e..cb9d258 100644 --- a/natives/resize.h +++ b/natives/resize.h @@ -4,4 +4,5 @@ using std::string; -char* Resize(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Resize(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/reverse.cc b/natives/reverse.cc index 41fec49..62940b7 100644 --- a/natives/reverse.cc +++ b/natives/reverse.cc @@ -1,8 +1,8 @@ -#include "common.h" - #include #include +#include "common.h" + using namespace std; using namespace vips; @@ -55,7 +55,5 @@ char *Reverse(string *type, char *BufferData, size_t BufferLength, *type = "gif"; - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/reverse.h b/natives/reverse.h index 41dbff6..a436a7f 100644 --- a/natives/reverse.h +++ b/natives/reverse.h @@ -4,4 +4,5 @@ using std::string; -char* Reverse(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Reverse(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/scott.cc b/natives/scott.cc index 0c71578..e31ad71 100644 --- a/natives/scott.cc +++ b/natives/scott.cc @@ -1,10 +1,11 @@ -#include "common.h" #include #include #include #include +#include "common.h" + using namespace std; using namespace Magick; @@ -56,7 +57,7 @@ char *Scott(string *type, char *BufferData, size_t BufferLength, writeImages(mid.begin(), mid.end(), &blob); *DataSize = blob.length(); - + char *data = (char *)malloc(*DataSize); memcpy(data, blob.data(), *DataSize); return data; diff --git a/natives/scott.h b/natives/scott.h index d5076f0..6752c42 100644 --- a/natives/scott.h +++ b/natives/scott.h @@ -4,4 +4,5 @@ using std::string; -char* Scott(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Scott(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/snapchat.cc b/natives/snapchat.cc index 7e9398c..8346b56 100644 --- a/natives/snapchat.cc +++ b/natives/snapchat.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -17,8 +17,7 @@ char *Snapchat(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -66,9 +65,7 @@ char *Snapchat(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/snapchat.h b/natives/snapchat.h index f112ed5..bc40397 100644 --- a/natives/snapchat.h +++ b/natives/snapchat.h @@ -4,4 +4,5 @@ using std::string; -char* Snapchat(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Snapchat(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/sonic.cc b/natives/sonic.cc index b5e986e..b4f2bea 100644 --- a/natives/sonic.cc +++ b/natives/sonic.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -32,7 +32,5 @@ char *Sonic(string *type, ArgumentMap Arguments, size_t *DataSize) { *type = "png"; - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/sonic.h b/natives/sonic.h index 5cedb52..10ff4b4 100644 --- a/natives/sonic.h +++ b/natives/sonic.h @@ -4,4 +4,4 @@ using std::string; -char* Sonic(string *type, ArgumentMap Arguments, size_t *DataSize); \ No newline at end of file +char *Sonic(string *type, ArgumentMap Arguments, size_t *DataSize); \ No newline at end of file diff --git a/natives/speed.cc b/natives/speed.cc index 806a1d4..080904f 100644 --- a/natives/speed.cc +++ b/natives/speed.cc @@ -1,18 +1,16 @@ -#include "common.h" - #include #include - #include +#include "common.h" + using namespace std; using namespace vips; void *memset16(void *m, uint16_t val, size_t count) { uint16_t *buf = (uint16_t *)m; - while (count--) - *buf++ = val; + while (count--) *buf++ = val; return m; } @@ -21,8 +19,7 @@ char *vipsRemove(char *data, size_t length, size_t *DataSize, int speed) { VImage in = VImage::new_from_buffer(data, length, "", options->set("n", -1)) .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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -44,7 +41,6 @@ char *vipsRemove(char *data, size_t length, size_t *DataSize, int speed) { char *Speed(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - bool slow = GetArgumentWithFallback(Arguments, "slow", false); int speed = GetArgumentWithFallback(Arguments, "speed", 2); @@ -102,8 +98,5 @@ char *Speed(string *type, char *BufferData, size_t BufferLength, *DataSize = BufferLength; } - vips_error_clear(); - vips_thread_shutdown(); - return fileData; } \ No newline at end of file diff --git a/natives/speed.h b/natives/speed.h index a9097f0..6a8afef 100644 --- a/natives/speed.h +++ b/natives/speed.h @@ -4,4 +4,5 @@ using std::string; -char* Speed(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Speed(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/spin.h b/natives/spin.h index 62c28f5..dbd94f0 100644 --- a/natives/spin.h +++ b/natives/spin.h @@ -4,4 +4,5 @@ using std::string; -char* Spin(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Spin(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/squish.cc b/natives/squish.cc index e536998..868c163 100644 --- a/natives/squish.cc +++ b/natives/squish.cc @@ -1,14 +1,14 @@ -#include "common.h" #include #include +#include "common.h" + using namespace std; using namespace vips; char *Squish(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - VOption *options = VImage::option(); VImage in = @@ -17,8 +17,7 @@ char *Squish(string *type, char *BufferData, size_t BufferLength, *type == "gif" ? options->set("n", -1)->set("access", "sequential") : 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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -48,7 +47,5 @@ char *Squish(string *type, char *BufferData, size_t BufferLength, *type = "gif"; - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/squish.h b/natives/squish.h index d98def5..291b6a9 100644 --- a/natives/squish.h +++ b/natives/squish.h @@ -4,4 +4,5 @@ using std::string; -char* Squish(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Squish(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/swirl.cc b/natives/swirl.cc index 02ff822..5a068ff 100644 --- a/natives/swirl.cc +++ b/natives/swirl.cc @@ -1,21 +1,19 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; char *Swirl(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - VOption *options = VImage::option()->set("access", "sequential"); VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", *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 pageHeight = vips_image_get_page_height(in.get_image()); int nPages = vips_image_get_n_pages(in.get_image()); @@ -74,7 +72,5 @@ char *Swirl(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer(".gif", &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/swirl.h b/natives/swirl.h index ec46cea..eb67aff 100644 --- a/natives/swirl.h +++ b/natives/swirl.h @@ -4,4 +4,5 @@ using std::string; -char* Swirl(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Swirl(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/tile.cc b/natives/tile.cc index 93510a9..ee9ab28 100644 --- a/natives/tile.cc +++ b/natives/tile.cc @@ -1,16 +1,16 @@ -#include "common.h" #include #include #include #include +#include "common.h" + using namespace std; using namespace Magick; char *Tile(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - Blob blob; list frames; diff --git a/natives/tile.h b/natives/tile.h index 666e2cb..72ea5ca 100644 --- a/natives/tile.h +++ b/natives/tile.h @@ -4,4 +4,5 @@ using std::string; -char* Tile(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Tile(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/togif.cc b/natives/togif.cc index f9e4891..48c4c7f 100644 --- a/natives/togif.cc +++ b/natives/togif.cc @@ -1,32 +1,26 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; char *ToGif(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - if (*type == "gif") { - vips_error_clear(); - vips_thread_shutdown(); *DataSize = BufferLength; return BufferData; } else { VOption *options = VImage::option()->set("access", "sequential"); - VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "webp" ? options->set("n", -1) - : options); + VImage in = VImage::new_from_buffer( + BufferData, BufferLength, "", + *type == "webp" ? options->set("n", -1) : options); void *buf; in.write_to_buffer(".gif", &buf, DataSize); - *type = "gif"; - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } } \ No newline at end of file diff --git a/natives/togif.h b/natives/togif.h index c97a201..73b837e 100644 --- a/natives/togif.h +++ b/natives/togif.h @@ -4,4 +4,5 @@ using std::string; -char* ToGif(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* ToGif(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/uncanny.cc b/natives/uncanny.cc index 453c5de..695acfc 100644 --- a/natives/uncanny.cc +++ b/natives/uncanny.cc @@ -1,13 +1,12 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; char *Uncanny(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - string caption = GetArgument(Arguments, "caption"); string caption2 = GetArgument(Arguments, "caption2"); string font = GetArgument(Arguments, "font"); @@ -94,11 +93,9 @@ char *Uncanny(string *type, char *BufferData, size_t BufferLength, final.set(VIPS_META_PAGE_HEIGHT, 720); void *buf; - final.write_to_buffer(("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("reoptimise", 1) - : 0); + final.write_to_buffer( + ("." + *type).c_str(), &buf, DataSize, + *type == "gif" ? VImage::option()->set("reoptimise", 1) : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/uncanny.h b/natives/uncanny.h index 6ae0cd5..018495a 100644 --- a/natives/uncanny.h +++ b/natives/uncanny.h @@ -4,4 +4,5 @@ using std::string; -char* Uncanny(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Uncanny(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/uncaption.cc b/natives/uncaption.cc index 6b127e3..9481cf0 100644 --- a/natives/uncaption.cc +++ b/natives/uncaption.cc @@ -1,14 +1,13 @@ -#include "common.h" - #include #include +#include "common.h" + using namespace std; using namespace vips; char *Uncaption(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - float tolerance = GetArgumentWithFallback(Arguments, "tolerance", 0.5); VOption *options = VImage::option(); @@ -17,10 +16,9 @@ char *Uncaption(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer( BufferData, BufferLength, "", *type == "gif" ? options->set("n", -1)->set("access", "sequential") - : options) + : 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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -49,9 +47,7 @@ char *Uncaption(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } diff --git a/natives/uncaption.h b/natives/uncaption.h index 0dfa0a2..d90fcf1 100644 --- a/natives/uncaption.h +++ b/natives/uncaption.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Uncaption(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Uncaption(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/wall.cc b/natives/wall.cc index 359850e..88e007e 100644 --- a/natives/wall.cc +++ b/natives/wall.cc @@ -1,16 +1,16 @@ -#include "common.h" #include #include #include #include +#include "common.h" + using namespace std; using namespace Magick; char *Wall(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - Blob blob; list frames; diff --git a/natives/wall.h b/natives/wall.h index 9fcc884..f90817c 100644 --- a/natives/wall.h +++ b/natives/wall.h @@ -4,4 +4,5 @@ using std::string; -char* Wall(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Wall(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/watermark.cc b/natives/watermark.cc index dd5ae0d..208418f 100644 --- a/natives/watermark.cc +++ b/natives/watermark.cc @@ -1,14 +1,13 @@ -#include "common.h" - #include #include +#include "common.h" + using namespace std; using namespace vips; char *Watermark(string *type, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - string water = GetArgument(Arguments, "water"); int gravity = GetArgument(Arguments, "gravity"); @@ -31,8 +30,7 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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); string merged = basePath + water; VImage watermark = VImage::new_from_file(merged.c_str()); @@ -59,30 +57,30 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength, int x = 0, y = 0; switch (gravity) { - case 1: - break; - case 2: - x = (width / 2) - (watermark.width() / 2); - break; - case 3: - x = width - watermark.width(); - break; - case 5: - x = (width / 2) - (watermark.width() / 2); - y = (pageHeight / 2) - (watermark.height() / 2); - break; - case 6: - x = width - watermark.width(); - y = (pageHeight / 2) - (watermark.height() / 2); - break; - case 8: - x = (width / 2) - (watermark.width() / 2); - y = pageHeight - watermark.height(); - break; - case 9: - x = width - watermark.width(); - y = pageHeight - watermark.height(); - break; + case 1: + break; + case 2: + x = (width / 2) - (watermark.width() / 2); + break; + case 3: + x = width - watermark.width(); + break; + case 5: + x = (width / 2) - (watermark.width() / 2); + y = (pageHeight / 2) - (watermark.height() / 2); + break; + case 6: + x = width - watermark.width(); + y = (pageHeight / 2) - (watermark.height() / 2); + break; + case 8: + x = (width / 2) - (watermark.width() / 2); + y = pageHeight - watermark.height(); + break; + case 9: + x = width - watermark.width(); + y = pageHeight - watermark.height(); + break; } vector img; @@ -149,9 +147,7 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer( ("." + *type).c_str(), &buf, DataSize, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } diff --git a/natives/watermark.h b/natives/watermark.h index dd8ad76..c7bec04 100644 --- a/natives/watermark.h +++ b/natives/watermark.h @@ -1,9 +1,8 @@ #pragma once #include "common.h" -#include -using std::map; using std::string; -char* Watermark(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Watermark(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/whisper.cc b/natives/whisper.cc index 4d18944..61f833a 100644 --- a/natives/whisper.cc +++ b/natives/whisper.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -16,8 +16,7 @@ char *Whisper(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -82,7 +81,5 @@ char *Whisper(string *type, char *BufferData, size_t BufferLength, *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) : 0); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/whisper.h b/natives/whisper.h index a6e8b80..3cf3840 100644 --- a/natives/whisper.h +++ b/natives/whisper.h @@ -4,4 +4,5 @@ using std::string; -char* Whisper(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Whisper(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/zamn.cc b/natives/zamn.cc index ed274b2..28c0ee4 100644 --- a/natives/zamn.cc +++ b/natives/zamn.cc @@ -1,7 +1,7 @@ -#include "common.h" - #include +#include "common.h" + using namespace std; using namespace vips; @@ -15,8 +15,7 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength, VImage::new_from_buffer(BufferData, BufferLength, "", *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 pageHeight = vips_image_get_page_height(in.get_image()); @@ -29,13 +28,13 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength, for (int i = 0; i < nPages; i++) { VImage img_frame = *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; - VImage composited = - tmpl.insert(img_frame.extract_band(0, VImage::option()->set("n", 3)) - .bandjoin(255) - .resize(303.0 / (double)width, - VImage::option()->set( - "vscale", 438.0 / (double)pageHeight)), - 310, 76); + VImage composited = tmpl.insert( + img_frame.extract_band(0, VImage::option()->set("n", 3)) + .bandjoin(255) + .resize( + 303.0 / (double)width, + VImage::option()->set("vscale", 438.0 / (double)pageHeight)), + 310, 76); img.push_back(composited); } VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1)); @@ -44,7 +43,5 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer(("." + *type).c_str(), &buf, DataSize); - vips_error_clear(); - vips_thread_shutdown(); return (char *)buf; } \ No newline at end of file diff --git a/natives/zamn.h b/natives/zamn.h index 6581e73..e18f384 100644 --- a/natives/zamn.h +++ b/natives/zamn.h @@ -4,4 +4,5 @@ using std::string; -char* Zamn(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file +char* Zamn(string* type, char* BufferData, size_t BufferLength, + ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file