From 10b80f2fd098a0f9f9dc371838173009e871b320 Mon Sep 17 00:00:00 2001 From: Essem Date: Wed, 8 Mar 2023 19:36:39 -0600 Subject: [PATCH] Add togif parameter --- classes/imageCommand.js | 9 ++++++++- natives/blur.cc | 6 +++--- natives/blur.h | 2 +- natives/bounce.cc | 17 +++++++++-------- natives/bounce.h | 2 +- natives/caption.cc | 15 ++++++++------- natives/caption.h | 2 +- natives/caption2.cc | 15 ++++++++------- natives/caption2.h | 2 +- natives/circle.cc | 9 +++++---- natives/circle.h | 2 +- natives/colors.cc | 8 ++++---- natives/colors.h | 2 +- natives/common.h | 4 ++-- natives/crop.cc | 13 +++++++------ natives/crop.h | 2 +- natives/deepfry.cc | 15 ++++++++------- natives/deepfry.h | 2 +- natives/explode.cc | 13 ++++++------- natives/explode.h | 2 +- natives/flag.cc | 11 ++++++----- natives/flag.h | 2 +- natives/flip.cc | 13 +++++++------ natives/flip.h | 2 +- natives/freeze.cc | 14 +++++++------- natives/freeze.h | 2 +- natives/gamexplain.cc | 15 ++++++++------- natives/gamexplain.h | 2 +- natives/globe.cc | 10 +++++----- natives/globe.h | 2 +- natives/homebrew.cc | 7 +++---- natives/homebrew.h | 2 +- natives/invert.cc | 9 +++++---- natives/invert.h | 2 +- natives/jpeg.cc | 21 +++++++++++++++------ natives/jpeg.h | 2 +- natives/magik.cc | 6 +++--- natives/magik.h | 2 +- natives/meme.cc | 13 +++++++------ natives/meme.h | 2 +- natives/mirror.cc | 10 +++++----- natives/mirror.h | 2 +- natives/motivate.cc | 12 ++++++------ natives/motivate.h | 2 +- natives/node/image.cc | 17 ++++++++++------- natives/reddit.cc | 15 ++++++++------- natives/reddit.h | 2 +- natives/resize.cc | 10 +++++----- natives/resize.h | 2 +- natives/reverse.cc | 6 +++--- natives/reverse.h | 2 +- natives/scott.cc | 6 +++--- natives/scott.h | 2 +- natives/snapchat.cc | 15 ++++++++------- natives/snapchat.h | 2 +- natives/sonic.cc | 7 +++---- natives/sonic.h | 2 +- natives/speed.cc | 8 ++++---- natives/speed.h | 2 +- natives/spin.cc | 11 ++++++----- natives/spin.h | 2 +- natives/squish.cc | 17 +++++++++-------- natives/squish.h | 2 +- natives/swirl.cc | 8 ++++---- natives/swirl.h | 2 +- natives/tile.cc | 6 +++--- natives/tile.h | 2 +- natives/togif.cc | 8 ++++---- natives/togif.h | 2 +- natives/uncanny.cc | 12 ++++++------ natives/uncanny.h | 2 +- natives/uncaption.cc | 15 ++++++++------- natives/uncaption.h | 2 +- natives/wall.cc | 6 +++--- natives/wall.h | 2 +- natives/watermark.cc | 19 ++++++++++--------- natives/watermark.h | 2 +- natives/whisper.cc | 15 ++++++++------- natives/whisper.h | 2 +- natives/zamn.cc | 8 ++++---- natives/zamn.h | 2 +- 81 files changed, 293 insertions(+), 259 deletions(-) diff --git a/classes/imageCommand.js b/classes/imageCommand.js index a9ba426..554a17b 100644 --- a/classes/imageCommand.js +++ b/classes/imageCommand.js @@ -25,7 +25,9 @@ class ImageCommand extends Command { const imageParams = { cmd: this.constructor.command, - params: {}, + params: { + togif: !!this.options.togif + }, id: (this.interaction ?? this.message).id }; @@ -129,6 +131,11 @@ class ImageCommand extends Command { description: "An image/GIF URL" }); } + this.flags.push({ + name: "togif", + type: 5, + description: "Force GIF output" + }); return this; } diff --git a/natives/blur.cc b/natives/blur.cc index 8cdebd4..5347f8e 100644 --- a/natives/blur.cc +++ b/natives/blur.cc @@ -7,14 +7,14 @@ using namespace std; using namespace vips; -char *Blur(string *type, char *BufferData, size_t BufferLength, +char *Blur(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { bool sharp = GetArgument(Arguments, "sharp"); VOption *options = VImage::option()->set("access", "sequential"); VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -25,7 +25,7 @@ char *Blur(string *type, char *BufferData, size_t BufferLength, sharp ? in.sharpen(VImage::option()->set("sigma", 3)) : in.gaussblur(15); void *buf; - out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); + out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } diff --git a/natives/blur.h b/natives/blur.h index 8b017e2..4f4b96d 100644 --- a/natives/blur.h +++ b/natives/blur.h @@ -4,5 +4,5 @@ using std::string; -char* Blur(string* type, char* BufferData, size_t BufferLength, +char* Blur(string type, string* outType, 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 9f58f72..e0d27a7 100644 --- a/natives/bounce.cc +++ b/natives/bounce.cc @@ -7,28 +7,29 @@ using namespace std; using namespace vips; -char *Bounce(string *type, char *BufferData, size_t BufferLength, - [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { +char *Bounce(string type, string *outType, char *BufferData, + size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments, + size_t *DataSize) { VOption *options = VImage::option(); VImage in = VImage::new_from_buffer( BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1)->set("access", "sequential") - : options) + type == "gif" ? options->set("n", -1)->set("access", "sequential") + : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); int width = in.width(); int pageHeight = vips_image_get_page_height(in.get_image()); - int nPages = *type == "gif" ? vips_image_get_n_pages(in.get_image()) : 15; + int nPages = type == "gif" ? vips_image_get_n_pages(in.get_image()) : 15; double mult = M_PI / nPages; int halfHeight = pageHeight / 2; vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + 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); @@ -36,7 +37,7 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength, } VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1)); final.set(VIPS_META_PAGE_HEIGHT, pageHeight + halfHeight); - if (*type != "gif") { + if (type != "gif") { vector delay(30, 50); final.set("delay", delay); } @@ -44,7 +45,7 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer(".gif", &buf, DataSize); - *type = "gif"; + *outType = "gif"; return (char *)buf; } \ No newline at end of file diff --git a/natives/bounce.h b/natives/bounce.h index 44a329f..0ea273a 100644 --- a/natives/bounce.h +++ b/natives/bounce.h @@ -4,5 +4,5 @@ using std::string; -char* Bounce(string* type, char* BufferData, size_t BufferLength, +char* Bounce(string type, string* outType, 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 d1824af..1979c4f 100644 --- a/natives/caption.cc +++ b/natives/caption.cc @@ -6,8 +6,8 @@ using namespace std; using namespace vips; -char *Caption(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Caption(string type, string *outType, 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"); @@ -16,7 +16,7 @@ char *Caption(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -57,7 +57,7 @@ char *Caption(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; VImage frame = captionImage.join( img_frame, VIPS_DIRECTION_VERTICAL, VImage::option()->set("background", 0xffffff)->set("expand", true)); @@ -68,9 +68,10 @@ char *Caption(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } diff --git a/natives/caption.h b/natives/caption.h index a84ccb1..6ff73c1 100644 --- a/natives/caption.h +++ b/natives/caption.h @@ -4,5 +4,5 @@ using std::string; -char* Caption(string* type, char* BufferData, size_t BufferLength, +char* Caption(string type, string* outType, 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 a7bf181..0b9026e 100644 --- a/natives/caption2.cc +++ b/natives/caption2.cc @@ -7,8 +7,8 @@ using namespace std; using namespace vips; -char *CaptionTwo(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *CaptionTwo(string type, string *outType, 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"); @@ -18,7 +18,7 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -58,7 +58,7 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; VImage frame = (top ? captionImage : img_frame) .join(top ? img_frame : captionImage, VIPS_DIRECTION_VERTICAL, @@ -72,9 +72,10 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } diff --git a/natives/caption2.h b/natives/caption2.h index d45e2d2..6ee4790 100644 --- a/natives/caption2.h +++ b/natives/caption2.h @@ -4,5 +4,5 @@ using std::string; -char* CaptionTwo(string* type, char* BufferData, size_t BufferLength, +char* CaptionTwo(string type, string* outType, 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 0d3e38f..96a1768 100644 --- a/natives/circle.cc +++ b/natives/circle.cc @@ -11,8 +11,9 @@ using namespace std; using namespace Magick; -char *Circle(string *type, char *BufferData, size_t BufferLength, - [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { +char *Circle(string type, string *outType, char *BufferData, + size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments, + size_t *DataSize) { Blob blob; list frames; @@ -29,13 +30,13 @@ char *Circle(string *type, char *BufferData, size_t BufferLength, for (Image &image : coalesced) { image.rotationalBlur(10); - image.magick(*type); + image.magick(*outType); blurred.push_back(image); } optimizeTransparency(blurred.begin(), blurred.end()); - if (*type == "gif") { + if (*outType == "gif") { for (Image &image : blurred) { image.quantizeDitherMethod(FloydSteinbergDitherMethod); image.quantize(); diff --git a/natives/circle.h b/natives/circle.h index 283ca79..4ee7f96 100644 --- a/natives/circle.h +++ b/natives/circle.h @@ -4,5 +4,5 @@ using std::string; -char* Circle(string* type, char* BufferData, size_t BufferLength, +char* Circle(string type, string* outType, 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 6c8fa62..b488600 100644 --- a/natives/colors.cc +++ b/natives/colors.cc @@ -10,15 +10,15 @@ using namespace vips; VImage sepia = VImage::new_matrixv(3, 3, 0.3588, 0.7044, 0.1368, 0.2990, 0.5870, 0.1140, 0.2392, 0.4696, 0.0912); -char *Colors(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Colors(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string color = GetArgument(Arguments, "color"); VOption *options = VImage::option()->set("access", "sequential"); VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); VImage out; @@ -30,7 +30,7 @@ char *Colors(string *type, char *BufferData, size_t BufferLength, } void *buf; - out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); + out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } diff --git a/natives/colors.h b/natives/colors.h index d0bddf5..4d00d0b 100644 --- a/natives/colors.h +++ b/natives/colors.h @@ -4,5 +4,5 @@ using std::string; -char* Colors(string* type, char* BufferData, size_t BufferLength, +char* Colors(string type, string* outType, 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 1361be7..1d71efb 100644 --- a/natives/common.h +++ b/natives/common.h @@ -85,7 +85,7 @@ const std::unordered_map fontPaths{ {"roboto", "assets/fonts/reddit.ttf"}}; const std::map FunctionMap = {{"blur", &Blur}, {"bounce", &Bounce}, @@ -126,5 +126,5 @@ const std::map + char* (*)(string type, string* outType, ArgumentMap Arguments, size_t* DataSize)> NoInputFunctionMap = {{"homebrew", Homebrew}, {"sonic", Sonic}}; \ No newline at end of file diff --git a/natives/crop.cc b/natives/crop.cc index d72fa85..9faba5b 100644 --- a/natives/crop.cc +++ b/natives/crop.cc @@ -7,13 +7,13 @@ using namespace std; using namespace vips; -char *Crop(string *type, char *BufferData, size_t BufferLength, +char *Crop(string type, string *outType, char *BufferData, size_t BufferLength, [[maybe_unused]] 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) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); int width = in.width(); @@ -24,7 +24,7 @@ char *Crop(string *type, char *BufferData, size_t BufferLength, int finalHeight = 0; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; int frameWidth = img_frame.width(); int frameHeight = img_frame.height(); bool widthOrHeight = frameWidth / frameHeight >= 1; @@ -42,9 +42,10 @@ char *Crop(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/crop.h b/natives/crop.h index 439b4d1..c7cad96 100644 --- a/natives/crop.h +++ b/natives/crop.h @@ -4,5 +4,5 @@ using std::string; -char* Crop(string* type, char* BufferData, size_t BufferLength, +char* Crop(string type, string* outType, 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 aa08d2c..9fe72a0 100644 --- a/natives/deepfry.cc +++ b/natives/deepfry.cc @@ -6,13 +6,14 @@ using namespace std; using namespace vips; -char *Deepfry(string *type, char *BufferData, size_t BufferLength, - [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { +char *Deepfry(string type, string *outType, char *BufferData, + size_t BufferLength, [[maybe_unused]] 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) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -25,7 +26,7 @@ char *Deepfry(string *type, char *BufferData, size_t BufferLength, VImage fried = (in * 1.3 - (255.0 * 1.3 - 255.0)) * 1.5; VImage final; - if (totalHeight > 65500 && *type == "gif") { + if (totalHeight > 65500 && type == "gif") { vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = in.crop(0, i * pageHeight, width, pageHeight); @@ -48,13 +49,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); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "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 00cc403..9196438 100644 --- a/natives/deepfry.h +++ b/natives/deepfry.h @@ -4,5 +4,5 @@ using std::string; -char* Deepfry(string* type, char* BufferData, size_t BufferLength, +char* Deepfry(string type, string* outType, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/explode.cc b/natives/explode.cc index 4d6d42c..f4fc4a1 100644 --- a/natives/explode.cc +++ b/natives/explode.cc @@ -1,5 +1,3 @@ -#include "common.h" - #include #include @@ -8,12 +6,13 @@ #include #include +#include "common.h" + using namespace std; using namespace Magick; -char *Explode(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { - +char *Explode(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { int amount = GetArgument(Arguments, "amount"); int delay = GetArgumentWithFallback(Arguments, "delay", 0); @@ -33,13 +32,13 @@ char *Explode(string *type, char *BufferData, size_t BufferLength, for (Image &image : coalesced) { image.implode(amount); - image.magick(*type); + image.magick(*outType); blurred.push_back(image); } optimizeTransparency(blurred.begin(), blurred.end()); - if (*type == "gif") { + if (*outType == "gif") { for (Image &image : blurred) { image.quantizeDither(false); image.quantize(); diff --git a/natives/explode.h b/natives/explode.h index 255224f..3c07169 100644 --- a/natives/explode.h +++ b/natives/explode.h @@ -4,5 +4,5 @@ using std::string; -char* Explode(string* type, char* BufferData, size_t BufferLength, +char* Explode(string type, string* outType, 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 2c4a9a5..adfaeb2 100644 --- a/natives/flag.cc +++ b/natives/flag.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -char *Flag(string *type, char *BufferData, size_t BufferLength, +char *Flag(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string overlay = GetArgument(Arguments, "overlay"); string basePath = GetArgument(Arguments, "basePath"); @@ -14,7 +14,7 @@ char *Flag(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -40,9 +40,10 @@ char *Flag(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/flag.h b/natives/flag.h index 976266b..123aa73 100644 --- a/natives/flag.h +++ b/natives/flag.h @@ -4,5 +4,5 @@ using std::string; -char* Flag(string* type, char* BufferData, size_t BufferLength, +char* Flag(string type, string* outType, 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 a9eb71e..1344404 100644 --- a/natives/flip.cc +++ b/natives/flip.cc @@ -6,12 +6,12 @@ using namespace std; using namespace vips; -char *Flip(string *type, char *BufferData, size_t BufferLength, +char *Flip(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { bool flop = GetArgument(Arguments, "flop"); VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" + type == "gif" ? VImage::option()->set("n", -1)->set( "access", "sequential") : 0) @@ -21,7 +21,7 @@ char *Flip(string *type, char *BufferData, size_t BufferLength, VImage out; if (flop) { out = in.flip(VIPS_DIRECTION_HORIZONTAL); - } else if (*type == "gif") { + } else if (type == "gif") { // libvips gif handling is both a blessing and a curse vector img; int pageHeight = vips_image_get_page_height(in.get_image()); @@ -39,9 +39,10 @@ char *Flip(string *type, char *BufferData, size_t BufferLength, void *buf; out.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/flip.h b/natives/flip.h index 9029498..d9ff128 100644 --- a/natives/flip.h +++ b/natives/flip.h @@ -4,5 +4,5 @@ using std::string; -char* Flip(string* type, char* BufferData, size_t BufferLength, +char* Flip(string type, string* outType, 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 6174dba..2eb15c4 100644 --- a/natives/freeze.cc +++ b/natives/freeze.cc @@ -7,8 +7,8 @@ using namespace std; using namespace vips; -char *Freeze(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Freeze(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { bool loop = GetArgumentWithFallback(Arguments, "loop", false); int frame = GetArgumentWithFallback(Arguments, "frame", -1); @@ -46,10 +46,10 @@ char *Freeze(string *type, char *BufferData, size_t BufferLength, } 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); + 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()); @@ -60,7 +60,7 @@ char *Freeze(string *type, char *BufferData, size_t BufferLength, out.set("loop", 1); void *buf; - out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); + out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } else { diff --git a/natives/freeze.h b/natives/freeze.h index dde7da9..4c0e931 100644 --- a/natives/freeze.h +++ b/natives/freeze.h @@ -4,5 +4,5 @@ using std::string; -char* Freeze(string* type, char* BufferData, size_t BufferLength, +char* Freeze(string type, string* outType, 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 21c33f1..a05b371 100644 --- a/natives/gamexplain.cc +++ b/natives/gamexplain.cc @@ -5,15 +5,15 @@ using namespace std; using namespace vips; -char *Gamexplain(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Gamexplain(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string basePath = GetArgument(Arguments, "basePath"); VOption *options = VImage::option()->set("access", "sequential"); VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -27,7 +27,7 @@ char *Gamexplain(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; VImage resized = img_frame .resize(1181.0 / (double)width, @@ -41,9 +41,10 @@ char *Gamexplain(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/gamexplain.h b/natives/gamexplain.h index 42c6881..7c07c6d 100644 --- a/natives/gamexplain.h +++ b/natives/gamexplain.h @@ -4,5 +4,5 @@ using std::string; -char* Gamexplain(string* type, char* BufferData, size_t BufferLength, +char* Gamexplain(string type, string* outType, 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 cd2874d..595329e 100644 --- a/natives/globe.cc +++ b/natives/globe.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -char *Globe(string *type, char *BufferData, size_t BufferLength, +char *Globe(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string basePath = GetArgument(Arguments, "basePath"); @@ -14,14 +14,14 @@ char *Globe(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer( BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1)->set("access", "sequential") + type == "gif" ? options->set("n", -1)->set("access", "sequential") : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); int width = in.width(); int pageHeight = vips_image_get_page_height(in.get_image()); - int nPages = *type == "gif" ? vips_image_get_n_pages(in.get_image()) : 30; + int nPages = type == "gif" ? vips_image_get_n_pages(in.get_image()) : 30; double size = min(width, pageHeight); @@ -47,7 +47,7 @@ char *Globe(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; VImage resized = img_frame.resize( size / (double)width, VImage::option()->set("vscale", size / (double)pageHeight)); @@ -61,7 +61,7 @@ char *Globe(string *type, char *BufferData, size_t BufferLength, } VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1)); final.set(VIPS_META_PAGE_HEIGHT, size); - if (*type != "gif") { + if (type != "gif") { vector delay(30, 50); final.set("delay", delay); } diff --git a/natives/globe.h b/natives/globe.h index 66a97fb..ca21889 100644 --- a/natives/globe.h +++ b/natives/globe.h @@ -4,5 +4,5 @@ using std::string; -char* Globe(string* type, char* BufferData, size_t BufferLength, +char* Globe(string type, string* outType, 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 209630b..28f2afd 100644 --- a/natives/homebrew.cc +++ b/natives/homebrew.cc @@ -5,7 +5,8 @@ using namespace std; using namespace vips; -char *Homebrew(string *type, ArgumentMap Arguments, size_t *DataSize) { +char *Homebrew(string type, string *outType, ArgumentMap Arguments, + size_t *DataSize) { string caption = GetArgument(Arguments, "caption"); string basePath = GetArgument(Arguments, "basePath"); @@ -30,9 +31,7 @@ char *Homebrew(string *type, ArgumentMap Arguments, size_t *DataSize) { ->set("y", 300 - (text.height() / 2) - 8)); void *buf; - out.write_to_buffer(".png", &buf, DataSize); - - *type = "png"; + out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } \ No newline at end of file diff --git a/natives/homebrew.h b/natives/homebrew.h index d6db633..3304c4e 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, string *outType, ArgumentMap Arguments, size_t *DataSize); \ No newline at end of file diff --git a/natives/invert.cc b/natives/invert.cc index ae3782b..a46fc10 100644 --- a/natives/invert.cc +++ b/natives/invert.cc @@ -5,13 +5,14 @@ using namespace std; using namespace vips; -char *Invert(string *type, char *BufferData, size_t BufferLength, - [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { +char *Invert(string type, string *outType, char *BufferData, + size_t BufferLength, [[maybe_unused]] 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) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -21,7 +22,7 @@ char *Invert(string *type, char *BufferData, size_t BufferLength, VImage out = inverted.bandjoin(in.extract_band(3)); void *buf; - out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); + out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } \ No newline at end of file diff --git a/natives/invert.h b/natives/invert.h index 42f7ea8..7db64e3 100644 --- a/natives/invert.h +++ b/natives/invert.h @@ -4,5 +4,5 @@ using std::string; -char* Invert(string* type, char* BufferData, size_t BufferLength, +char* Invert(string type, string* outType, 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 9dcb47d..d1eff63 100644 --- a/natives/jpeg.cc +++ b/natives/jpeg.cc @@ -5,13 +5,13 @@ using namespace std; using namespace vips; -char *Jpeg(string *type, char *BufferData, size_t BufferLength, +char *Jpeg(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { int quality = GetArgumentWithFallback(Arguments, "quality", 0); void *buf; - if (*type == "gif") { + if (type == "gif") { VImage in = VImage::new_from_buffer( BufferData, BufferLength, "", VImage::option()->set("access", "sequential")->set("n", -1)) @@ -53,13 +53,22 @@ char *Jpeg(string *type, char *BufferData, size_t BufferLength, } final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0) : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" ? VImage::option()->set("dither", 0) : 0); } else { VImage in = VImage::new_from_buffer(BufferData, BufferLength, ""); - in.write_to_buffer(".jpg", &buf, DataSize, + void *jpgBuf; + in.write_to_buffer(".jpg", &jpgBuf, DataSize, VImage::option()->set("Q", quality)->set("strip", true)); - *type = "jpg"; + if (*outType == "gif") { + VImage gifIn = VImage::new_from_buffer((char *)jpgBuf, *DataSize, ""); + gifIn.write_to_buffer( + ".gif", &buf, DataSize, + VImage::option()->set("Q", quality)->set("strip", true)); + } else { + *outType = "jpg"; + buf = jpgBuf; + } } return (char *)buf; diff --git a/natives/jpeg.h b/natives/jpeg.h index ed67612..2e6912c 100644 --- a/natives/jpeg.h +++ b/natives/jpeg.h @@ -4,5 +4,5 @@ using std::string; -char* Jpeg(string* type, char* BufferData, size_t BufferLength, +char* Jpeg(string type, string* outType, 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 94e6e1c..4aae8f6 100644 --- a/natives/magik.cc +++ b/natives/magik.cc @@ -9,7 +9,7 @@ using namespace std; using namespace Magick; -char *Magik(string *type, char *BufferData, size_t BufferLength, +char *Magik(string type, string *outType, char *BufferData, size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { Blob blob; @@ -29,13 +29,13 @@ char *Magik(string *type, char *BufferData, size_t BufferLength, image.scale(Geometry("350x350")); image.liquidRescale(Geometry("175x175")); image.liquidRescale(Geometry("350x350")); - image.magick(*type); + image.magick(*outType); blurred.push_back(image); } optimizeTransparency(blurred.begin(), blurred.end()); - if (*type == "gif") { + if (*outType == "gif") { for (Image &image : blurred) { image.quantizeDitherMethod(FloydSteinbergDitherMethod); image.quantize(); diff --git a/natives/magik.h b/natives/magik.h index 37013a9..b4c1639 100644 --- a/natives/magik.h +++ b/natives/magik.h @@ -4,5 +4,5 @@ using std::string; -char* Magik(string* type, char* BufferData, size_t BufferLength, +char* Magik(string type, string* outType, 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 9b3dc5d..f7cb51a 100644 --- a/natives/meme.cc +++ b/natives/meme.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -char *Meme(string *type, char *BufferData, size_t BufferLength, +char *Meme(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string top = GetArgument(Arguments, "top"); string bottom = GetArgument(Arguments, "bottom"); @@ -16,7 +16,7 @@ char *Meme(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -110,7 +110,7 @@ char *Meme(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; if (top != "") { img_frame = img_frame.composite2( topText, VIPS_BLEND_MODE_OVER, @@ -130,9 +130,10 @@ char *Meme(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/meme.h b/natives/meme.h index 5d7bf58..5c05a29 100644 --- a/natives/meme.h +++ b/natives/meme.h @@ -4,5 +4,5 @@ using std::string; -char* Meme(string* type, char* BufferData, size_t BufferLength, +char* Meme(string type, string* outType, 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 47bf015..bb4db00 100644 --- a/natives/mirror.cc +++ b/natives/mirror.cc @@ -5,8 +5,8 @@ using namespace std; using namespace vips; -char *Mirror(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Mirror(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { bool vertical = GetArgumentWithFallback(Arguments, "vertical", false); bool first = GetArgumentWithFallback(Arguments, "first", false); @@ -14,14 +14,14 @@ char *Mirror(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); VImage out; if (vertical) { - if (*type == "gif") { + if (type == "gif") { // once again, libvips gif handling is both a blessing and a curse vector img; int pageHeight = vips_image_get_page_height(in.get_image()); @@ -58,7 +58,7 @@ char *Mirror(string *type, char *BufferData, size_t BufferLength, } void *buf; - out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); + out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } diff --git a/natives/mirror.h b/natives/mirror.h index 3ed6dac..419f595 100644 --- a/natives/mirror.h +++ b/natives/mirror.h @@ -4,5 +4,5 @@ using std::string; -char* Mirror(string* type, char* BufferData, size_t BufferLength, +char* Mirror(string type, string* outType, 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 11c9b20..a2f48bd 100644 --- a/natives/motivate.cc +++ b/natives/motivate.cc @@ -5,8 +5,8 @@ using namespace std; using namespace vips; -char *Motivate(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Motivate(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string top_text = GetArgument(Arguments, "top"); string bottom_text = GetArgument(Arguments, "bottom"); string font = GetArgument(Arguments, "font"); @@ -16,7 +16,7 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -69,7 +69,7 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength, int height; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; int borderSize = max(2, width / 66); int borderSize2 = borderSize * 0.5; @@ -116,8 +116,8 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 1) : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" ? VImage::option()->set("dither", 1) : 0); return (char *)buf; } diff --git a/natives/motivate.h b/natives/motivate.h index 924f640..7f7624b 100644 --- a/natives/motivate.h +++ b/natives/motivate.h @@ -4,5 +4,5 @@ using std::string; -char* Motivate(string* type, char* BufferData, size_t BufferLength, +char* Motivate(string type, string* outType, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/node/image.cc b/natives/node/image.cc index 3f171c6..c3ecb9f 100644 --- a/natives/node/image.cc +++ b/natives/node/image.cc @@ -32,7 +32,7 @@ Napi::Value ProcessImage(const Napi::CallbackInfo& info) { string command = info[0].As().Utf8Value(); Napi::Object obj = info[1].As(); string type = - obj.Has("type") ? obj.Get("type").As().Utf8Value() : NULL; + obj.Has("type") ? obj.Get("type").As().Utf8Value() : "png"; Napi::Array properties = obj.GetPropertyNames(); @@ -64,25 +64,28 @@ Napi::Value ProcessImage(const Napi::CallbackInfo& info) { } } + string outType = GetArgument(Arguments, "togif") ? "gif" : type; + 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(), + buf = FunctionMap.at(command)(type, &outType, data.Data(), data.Length(), Arguments, &length); } else { - buf = NoInputFunctionMap.at(command)(&type, Arguments, &length); + buf = NoInputFunctionMap.at(command)(type, &outType, Arguments, &length); } vips_error_clear(); vips_thread_shutdown(); - result.Set("data", Napi::Buffer::New( - env, buf, length, - []([[maybe_unused]] Napi::Env env, void* data) { free(data); })); - result.Set("type", type); + result.Set("data", + Napi::Buffer::New(env, buf, length, + []([[maybe_unused]] Napi::Env env, + void* data) { free(data); })); + result.Set("type", outType); } catch (std::exception const& err) { Napi::Error::New(env, err.what()).ThrowAsJavaScriptException(); } catch (...) { diff --git a/natives/reddit.cc b/natives/reddit.cc index d4b02e7..c89b6c7 100644 --- a/natives/reddit.cc +++ b/natives/reddit.cc @@ -5,8 +5,8 @@ using namespace std; using namespace vips; -char *Reddit(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Reddit(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string text = GetArgument(Arguments, "text"); string basePath = GetArgument(Arguments, "basePath"); @@ -14,7 +14,7 @@ char *Reddit(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -48,7 +48,7 @@ char *Reddit(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; VImage frame = img_frame.join(watermark, VIPS_DIRECTION_VERTICAL, VImage::option()->set("expand", true)); img.push_back(frame); @@ -58,9 +58,10 @@ char *Reddit(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/reddit.h b/natives/reddit.h index 7acdfd5..564341f 100644 --- a/natives/reddit.h +++ b/natives/reddit.h @@ -4,5 +4,5 @@ using std::string; -char* Reddit(string* type, char* BufferData, size_t BufferLength, +char* Reddit(string type, string* outType, 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 595bb30..ae9f93e 100644 --- a/natives/resize.cc +++ b/natives/resize.cc @@ -5,8 +5,8 @@ using namespace std; using namespace vips; -char *Resize(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Resize(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { bool stretch = GetArgumentWithFallback(Arguments, "stretch", false); bool wide = GetArgumentWithFallback(Arguments, "wide", false); @@ -14,7 +14,7 @@ char *Resize(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); VImage out; @@ -37,7 +37,7 @@ char *Resize(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; VImage resized = img_frame.resize(0.1).resize( 10, VImage::option()->set("kernel", VIPS_KERNEL_NEAREST)); img.push_back(resized); @@ -48,7 +48,7 @@ char *Resize(string *type, char *BufferData, size_t BufferLength, out.set(VIPS_META_PAGE_HEIGHT, finalHeight); void *buf; - out.write_to_buffer(("." + *type).c_str(), &buf, DataSize); + out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } \ No newline at end of file diff --git a/natives/resize.h b/natives/resize.h index cb9d258..61bc26d 100644 --- a/natives/resize.h +++ b/natives/resize.h @@ -4,5 +4,5 @@ using std::string; -char* Resize(string* type, char* BufferData, size_t BufferLength, +char* Resize(string type, string* outType, 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 62940b7..6444bd0 100644 --- a/natives/reverse.cc +++ b/natives/reverse.cc @@ -6,8 +6,8 @@ using namespace std; using namespace vips; -char *Reverse(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Reverse(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { bool soos = GetArgumentWithFallback(Arguments, "soos", false); VOption *options = @@ -53,7 +53,7 @@ char *Reverse(string *type, char *BufferData, size_t BufferLength, final.write_to_buffer(".gif", &buf, DataSize, VImage::option()->set("dither", 0)); - *type = "gif"; + *outType = "gif"; return (char *)buf; } \ No newline at end of file diff --git a/natives/reverse.h b/natives/reverse.h index a436a7f..9a7db85 100644 --- a/natives/reverse.h +++ b/natives/reverse.h @@ -4,5 +4,5 @@ using std::string; -char* Reverse(string* type, char* BufferData, size_t BufferLength, +char* Reverse(string type, string* outType, 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 e31ad71..aabd828 100644 --- a/natives/scott.cc +++ b/natives/scott.cc @@ -9,7 +9,7 @@ using namespace std; using namespace Magick; -char *Scott(string *type, char *BufferData, size_t BufferLength, +char *Scott(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string basePath = GetArgument(Arguments, "basePath"); @@ -40,14 +40,14 @@ char *Scott(string *type, char *BufferData, size_t BufferLength, image.extent(Geometry("864x481"), Magick::CenterGravity); watermark_new.composite(image, Geometry("-110+83"), Magick::OverCompositeOp); - watermark_new.magick(*type); + watermark_new.magick(*outType); watermark_new.animationDelay(image.animationDelay()); mid.push_back(watermark_new); } optimizeTransparency(mid.begin(), mid.end()); - if (*type == "gif") { + if (*outType == "gif") { for (Image &image : mid) { image.quantizeDitherMethod(FloydSteinbergDitherMethod); image.quantize(); diff --git a/natives/scott.h b/natives/scott.h index 6752c42..45313af 100644 --- a/natives/scott.h +++ b/natives/scott.h @@ -4,5 +4,5 @@ using std::string; -char* Scott(string* type, char* BufferData, size_t BufferLength, +char* Scott(string type, string* outType, 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 8346b56..7b5a812 100644 --- a/natives/snapchat.cc +++ b/natives/snapchat.cc @@ -5,8 +5,8 @@ using namespace std; using namespace vips; -char *Snapchat(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Snapchat(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string caption = GetArgument(Arguments, "caption"); float pos = GetArgumentWithFallback(Arguments, "pos", 0.5); string basePath = GetArgument(Arguments, "basePath"); @@ -15,7 +15,7 @@ char *Snapchat(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -52,7 +52,7 @@ char *Snapchat(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; img_frame = img_frame.composite2( textIn, VIPS_BLEND_MODE_OVER, VImage::option()->set("x", 0)->set("y", pageHeight * pos)); @@ -63,9 +63,10 @@ char *Snapchat(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/snapchat.h b/natives/snapchat.h index bc40397..a43a4a3 100644 --- a/natives/snapchat.h +++ b/natives/snapchat.h @@ -4,5 +4,5 @@ using std::string; -char* Snapchat(string* type, char* BufferData, size_t BufferLength, +char* Snapchat(string type, string* outType, 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 b4f2bea..581700c 100644 --- a/natives/sonic.cc +++ b/natives/sonic.cc @@ -5,7 +5,8 @@ using namespace std; using namespace vips; -char *Sonic(string *type, ArgumentMap Arguments, size_t *DataSize) { +char *Sonic(string type, string *outType, ArgumentMap Arguments, + size_t *DataSize) { string text = GetArgument(Arguments, "text"); string basePath = GetArgument(Arguments, "basePath"); @@ -28,9 +29,7 @@ char *Sonic(string *type, ArgumentMap Arguments, size_t *DataSize) { VImage::option()->set("x", 391)->set("y", 84)); void *buf; - out.write_to_buffer(".png", &buf, DataSize); - - *type = "png"; + out.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } \ No newline at end of file diff --git a/natives/sonic.h b/natives/sonic.h index 10ff4b4..6b3df86 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, string *outType, ArgumentMap Arguments, size_t *DataSize); \ No newline at end of file diff --git a/natives/speed.cc b/natives/speed.cc index 2b0fd14..f7fc116 100644 --- a/natives/speed.cc +++ b/natives/speed.cc @@ -39,8 +39,8 @@ char *vipsRemove(char *data, size_t length, size_t *DataSize, int speed) { return (char *)buf; } -char *Speed([[maybe_unused]] string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Speed([[maybe_unused]] string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { bool slow = GetArgumentWithFallback(Arguments, "slow", false); int speed = GetArgumentWithFallback(Arguments, "speed", 2); @@ -53,7 +53,7 @@ char *Speed([[maybe_unused]] string *type, char *BufferData, size_t BufferLength bool removeFrames = false; char *lastPos; - int amount = 0; + // int amount = 0; lastPos = (char *)memchr(fileData, '\x00', BufferLength); while (lastPos != NULL) { @@ -62,7 +62,7 @@ char *Speed([[maybe_unused]] string *type, char *BufferData, size_t BufferLength (BufferLength - (lastPos - fileData)) - 1); continue; } - ++amount; + //++amount; uint16_t old_delay; memcpy(&old_delay, lastPos + 5, 2); old_delays.push_back(old_delay); diff --git a/natives/speed.h b/natives/speed.h index 6a8afef..0c861ae 100644 --- a/natives/speed.h +++ b/natives/speed.h @@ -4,5 +4,5 @@ using std::string; -char* Speed(string* type, char* BufferData, size_t BufferLength, +char* Speed(string type, string* outType, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/spin.cc b/natives/spin.cc index 238ebef..2c1d07e 100644 --- a/natives/spin.cc +++ b/natives/spin.cc @@ -1,14 +1,15 @@ -#include "common.h" #include #include #include #include +#include "common.h" + using namespace std; using namespace Magick; -char *Spin(string *type, char *BufferData, size_t BufferLength, +char *Spin(string type, string *outType, char *BufferData, size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { int delay = GetArgumentWithFallback(Arguments, "delay", 0); @@ -26,7 +27,7 @@ char *Spin(string *type, char *BufferData, size_t BufferLength, } coalesceImages(&coalesced, frames.begin(), frames.end()); - if (*type != "gif") { + if (type != "gif") { list::iterator it = coalesced.begin(); for (int i = 0; i < 29; ++i) { coalesced.push_back(*it); @@ -51,7 +52,7 @@ char *Spin(string *type, char *BufferData, size_t BufferLength, optimizeTransparency(mid.begin(), mid.end()); if (delay != 0) { for_each(mid.begin(), mid.end(), animationDelayImage(delay)); - } else if (*type != "gif") { + } else if (type != "gif") { for_each(mid.begin(), mid.end(), animationDelayImage(5)); } @@ -62,7 +63,7 @@ char *Spin(string *type, char *BufferData, size_t BufferLength, writeImages(mid.begin(), mid.end(), &blob); - *type = "gif"; + *outType = "gif"; *DataSize = blob.length(); char *data = (char *)malloc(*DataSize); diff --git a/natives/spin.h b/natives/spin.h index dbd94f0..74f16b8 100644 --- a/natives/spin.h +++ b/natives/spin.h @@ -4,5 +4,5 @@ using std::string; -char* Spin(string* type, char* BufferData, size_t BufferLength, +char* Spin(string type, string* outType, 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 b7b8a3f..a28463b 100644 --- a/natives/squish.cc +++ b/natives/squish.cc @@ -7,27 +7,28 @@ using namespace std; using namespace vips; -char *Squish(string *type, char *BufferData, size_t BufferLength, - [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { +char *Squish(string type, string *outType, char *BufferData, + size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments, + size_t *DataSize) { VOption *options = VImage::option(); VImage in = VImage::new_from_buffer( BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1)->set("access", "sequential") - : options) + type == "gif" ? options->set("n", -1)->set("access", "sequential") + : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); int width = in.width(); int pageHeight = vips_image_get_page_height(in.get_image()); - int nPages = *type == "gif" ? vips_image_get_n_pages(in.get_image()) : 30; + int nPages = type == "gif" ? vips_image_get_n_pages(in.get_image()) : 30; double mult = (2 * M_PI) / nPages; vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; double newWidth = (sin(i * mult) / 4) + 0.75; double newHeight = (cos(i * mult) / 4) + 0.75; VImage resized = @@ -37,7 +38,7 @@ char *Squish(string *type, char *BufferData, size_t BufferLength, } VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1)); final.set(VIPS_META_PAGE_HEIGHT, pageHeight); - if (*type != "gif") { + if (type != "gif") { vector delay(30, 50); final.set("delay", delay); } @@ -45,7 +46,7 @@ char *Squish(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer(".gif", &buf, DataSize); - *type = "gif"; + *outType = "gif"; return (char *)buf; } \ No newline at end of file diff --git a/natives/squish.h b/natives/squish.h index 291b6a9..47c5118 100644 --- a/natives/squish.h +++ b/natives/squish.h @@ -4,5 +4,5 @@ using std::string; -char* Squish(string* type, char* BufferData, size_t BufferLength, +char* Squish(string type, string* outType, 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 a61c9f5..8ae3be4 100644 --- a/natives/swirl.cc +++ b/natives/swirl.cc @@ -5,13 +5,13 @@ using namespace std; using namespace vips; -char *Swirl(string *type, char *BufferData, size_t BufferLength, +char *Swirl(string type, string *outType, char *BufferData, size_t BufferLength, [[maybe_unused]] 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) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -54,7 +54,7 @@ char *Swirl(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; VImage distort = img_frame @@ -70,7 +70,7 @@ char *Swirl(string *type, char *BufferData, size_t BufferLength, final.set(VIPS_META_PAGE_HEIGHT, pageHeight); void *buf; - final.write_to_buffer(".gif", &buf, DataSize); + final.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } \ No newline at end of file diff --git a/natives/swirl.h b/natives/swirl.h index eb67aff..fecb25c 100644 --- a/natives/swirl.h +++ b/natives/swirl.h @@ -4,5 +4,5 @@ using std::string; -char* Swirl(string* type, char* BufferData, size_t BufferLength, +char* Swirl(string type, string* outType, 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 973b21f..30feb7b 100644 --- a/natives/tile.cc +++ b/natives/tile.cc @@ -9,7 +9,7 @@ using namespace std; using namespace Magick; -char *Tile(string *type, char *BufferData, size_t BufferLength, +char *Tile(string type, string *outType, char *BufferData, size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { Blob blob; @@ -30,7 +30,7 @@ char *Tile(string *type, char *BufferData, size_t BufferLength, Image appended; list montage; Image frame; - image.magick(*type); + image.magick(*outType); for (int i = 0; i < 5; ++i) { duplicated.push_back(image); } @@ -48,7 +48,7 @@ char *Tile(string *type, char *BufferData, size_t BufferLength, optimizeTransparency(mid.begin(), mid.end()); - if (*type == "gif") { + if (*outType == "gif") { for (Image &image : mid) { image.quantizeDitherMethod(FloydSteinbergDitherMethod); image.quantize(); diff --git a/natives/tile.h b/natives/tile.h index 72ea5ca..a1fe22b 100644 --- a/natives/tile.h +++ b/natives/tile.h @@ -4,5 +4,5 @@ using std::string; -char* Tile(string* type, char* BufferData, size_t BufferLength, +char* Tile(string type, string* outType, 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 5426654..678b537 100644 --- a/natives/togif.cc +++ b/natives/togif.cc @@ -5,9 +5,9 @@ using namespace std; using namespace vips; -char *ToGif(string *type, char *BufferData, size_t BufferLength, +char *ToGif(string type, string *outType, char *BufferData, size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { - if (*type == "gif") { + if (type == "gif") { *DataSize = BufferLength; char *data = (char *)malloc(BufferLength); memcpy(data, BufferData, BufferLength); @@ -17,11 +17,11 @@ char *ToGif(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer( BufferData, BufferLength, "", - *type == "webp" ? options->set("n", -1) : options); + type == "webp" ? options->set("n", -1) : options); void *buf; in.write_to_buffer(".gif", &buf, DataSize); - *type = "gif"; + *outType = "gif"; return (char *)buf; } diff --git a/natives/togif.h b/natives/togif.h index 73b837e..5e3f8c0 100644 --- a/natives/togif.h +++ b/natives/togif.h @@ -4,5 +4,5 @@ using std::string; -char* ToGif(string* type, char* BufferData, size_t BufferLength, +char* ToGif(string type, string* outType, 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 695acfc..16a922b 100644 --- a/natives/uncanny.cc +++ b/natives/uncanny.cc @@ -5,8 +5,8 @@ using namespace std; using namespace vips; -char *Uncanny(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Uncanny(string type, string *outType, 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"); @@ -17,7 +17,7 @@ char *Uncanny(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB) .extract_band(0, VImage::option()->set("n", 3)); @@ -79,7 +79,7 @@ char *Uncanny(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; VImage resized = img_frame.resize(690.0 / (double)width); if (resized.height() > 590) { double vscale = 590.0 / (double)resized.height(); @@ -94,8 +94,8 @@ char *Uncanny(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("reoptimise", 1) : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" ? VImage::option()->set("reoptimise", 1) : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/uncanny.h b/natives/uncanny.h index 018495a..d9c34e5 100644 --- a/natives/uncanny.h +++ b/natives/uncanny.h @@ -4,5 +4,5 @@ using std::string; -char* Uncanny(string* type, char* BufferData, size_t BufferLength, +char* Uncanny(string type, string* outType, 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 9481cf0..0145d87 100644 --- a/natives/uncaption.cc +++ b/natives/uncaption.cc @@ -6,8 +6,8 @@ using namespace std; using namespace vips; -char *Uncaption(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Uncaption(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { float tolerance = GetArgumentWithFallback(Arguments, "tolerance", 0.5); VOption *options = VImage::option(); @@ -15,8 +15,8 @@ char *Uncaption(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer( BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1)->set("access", "sequential") - : options) + type == "gif" ? options->set("n", -1)->set("access", "sequential") + : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -45,9 +45,10 @@ char *Uncaption(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } diff --git a/natives/uncaption.h b/natives/uncaption.h index d90fcf1..74b9f4d 100644 --- a/natives/uncaption.h +++ b/natives/uncaption.h @@ -4,5 +4,5 @@ using std::string; -char* Uncaption(string* type, char* BufferData, size_t BufferLength, +char* Uncaption(string type, string* outType, 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 b97e756..aa87fc9 100644 --- a/natives/wall.cc +++ b/natives/wall.cc @@ -9,7 +9,7 @@ using namespace std; using namespace Magick; -char *Wall(string *type, char *BufferData, size_t BufferLength, +char *Wall(string type, string *outType, char *BufferData, size_t BufferLength, [[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) { Blob blob; @@ -35,13 +35,13 @@ char *Wall(string *type, char *BufferData, size_t BufferLength, 128, 0, 140, 60, 128, 128, 140, 140}; image.distort(Magick::PerspectiveDistortion, 16, arguments); image.scale(Geometry("800x800>")); - image.magick(*type); + image.magick(*outType); mid.push_back(image); } optimizeTransparency(mid.begin(), mid.end()); - if (*type == "gif") { + if (*outType == "gif") { for (Image &image : mid) { image.quantizeDitherMethod(FloydSteinbergDitherMethod); image.quantize(); diff --git a/natives/wall.h b/natives/wall.h index f90817c..93119d3 100644 --- a/natives/wall.h +++ b/natives/wall.h @@ -4,5 +4,5 @@ using std::string; -char* Wall(string* type, char* BufferData, size_t BufferLength, +char* Wall(string type, string* outType, 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 208418f..7193067 100644 --- a/natives/watermark.cc +++ b/natives/watermark.cc @@ -6,8 +6,8 @@ using namespace std; using namespace vips; -char *Watermark(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Watermark(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string water = GetArgument(Arguments, "water"); int gravity = GetArgument(Arguments, "gravity"); @@ -28,7 +28,7 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -91,7 +91,7 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength, VImage frame; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; if (append) { VImage appended = img_frame.join(watermark, VIPS_DIRECTION_VERTICAL, VImage::option()->set("expand", true)); @@ -121,8 +121,8 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength, bg = frameAlpha.new_from_image({0, 0, 0}).copy(VImage::option()->set( "interpretation", VIPS_INTERPRETATION_sRGB)); frame = bg.bandjoin(frameAlpha); - if (*type == "jpg" || *type == "jpeg") { - *type = "png"; + if (*outType == "jpg" || *outType == "jpeg") { + *outType = "png"; } } VImage content = @@ -145,9 +145,10 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } diff --git a/natives/watermark.h b/natives/watermark.h index c7bec04..da102dc 100644 --- a/natives/watermark.h +++ b/natives/watermark.h @@ -4,5 +4,5 @@ using std::string; -char* Watermark(string* type, char* BufferData, size_t BufferLength, +char* Watermark(string type, string* outType, 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 61f833a..da96542 100644 --- a/natives/whisper.cc +++ b/natives/whisper.cc @@ -5,8 +5,8 @@ using namespace std; using namespace vips; -char *Whisper(string *type, char *BufferData, size_t BufferLength, - ArgumentMap Arguments, size_t *DataSize) { +char *Whisper(string type, string *outType, char *BufferData, + size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string caption = GetArgument(Arguments, "caption"); string basePath = GetArgument(Arguments, "basePath"); @@ -14,7 +14,7 @@ char *Whisper(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -64,7 +64,7 @@ char *Whisper(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; img_frame = img_frame.composite2( textImg, VIPS_BLEND_MODE_OVER, VImage::option() @@ -77,9 +77,10 @@ char *Whisper(string *type, char *BufferData, size_t BufferLength, void *buf; final.write_to_buffer( - ("." + *type).c_str(), &buf, DataSize, - *type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1) - : 0); + ("." + *outType).c_str(), &buf, DataSize, + *outType == "gif" + ? VImage::option()->set("dither", 0)->set("reoptimise", 1) + : 0); return (char *)buf; } \ No newline at end of file diff --git a/natives/whisper.h b/natives/whisper.h index 3cf3840..df9160e 100644 --- a/natives/whisper.h +++ b/natives/whisper.h @@ -4,5 +4,5 @@ using std::string; -char* Whisper(string* type, char* BufferData, size_t BufferLength, +char* Whisper(string type, string* outType, 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 28c0ee4..55173c3 100644 --- a/natives/zamn.cc +++ b/natives/zamn.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -char *Zamn(string *type, char *BufferData, size_t BufferLength, +char *Zamn(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { string basePath = GetArgument(Arguments, "basePath"); @@ -13,7 +13,7 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength, VImage in = VImage::new_from_buffer(BufferData, BufferLength, "", - *type == "gif" ? options->set("n", -1) : options) + type == "gif" ? options->set("n", -1) : options) .colourspace(VIPS_INTERPRETATION_sRGB); if (!in.has_alpha()) in = in.bandjoin(255); @@ -27,7 +27,7 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength, vector img; for (int i = 0; i < nPages; i++) { VImage img_frame = - *type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + 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) @@ -41,7 +41,7 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength, final.set(VIPS_META_PAGE_HEIGHT, 516); void *buf; - final.write_to_buffer(("." + *type).c_str(), &buf, DataSize); + final.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); return (char *)buf; } \ No newline at end of file diff --git a/natives/zamn.h b/natives/zamn.h index e18f384..0eec42c 100644 --- a/natives/zamn.h +++ b/natives/zamn.h @@ -4,5 +4,5 @@ using std::string; -char* Zamn(string* type, char* BufferData, size_t BufferLength, +char* Zamn(string type, string* outType, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize); \ No newline at end of file