Add togif parameter

This commit is contained in:
Essem 2023-03-08 19:36:39 -06:00
parent cc7ea2762c
commit 10b80f2fd0
No known key found for this signature in database
GPG Key ID: 7D497397CC3A2A8C
81 changed files with 293 additions and 259 deletions

View File

@ -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;
}

View File

@ -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<bool>(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;
}

View File

@ -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);

View File

@ -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<VImage> 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<int> 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;
}

View File

@ -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);

View File

@ -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<string>(Arguments, "caption");
string font = GetArgument<string>(Arguments, "font");
string basePath = GetArgument<string>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<bool>(Arguments, "top");
string caption = GetArgument<string>(Arguments, "caption");
string font = GetArgument<string>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<Image> 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();

View File

@ -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);

View File

@ -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<string>(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;
}

View File

@ -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);

View File

@ -85,7 +85,7 @@ const std::unordered_map<std::string, std::string> fontPaths{
{"roboto", "assets/fonts/reddit.ttf"}};
const std::map<std::string,
char* (*)(string* type, char* BufferData, size_t BufferLength,
char* (*)(string type, string* outType, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize)>
FunctionMap = {{"blur", &Blur},
{"bounce", &Bounce},
@ -126,5 +126,5 @@ const std::map<std::string,
{"zamn", Zamn}};
const std::map<std::string,
char* (*)(string* type, ArgumentMap Arguments, size_t* DataSize)>
char* (*)(string type, string* outType, ArgumentMap Arguments, size_t* DataSize)>
NoInputFunctionMap = {{"homebrew", Homebrew}, {"sonic", Sonic}};

View File

@ -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;
}

View File

@ -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);

View File

@ -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<VImage> 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;
}

View File

@ -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);

View File

@ -1,5 +1,3 @@
#include "common.h"
#include <Magick++.h>
#include <cstring>
@ -8,12 +6,13 @@
#include <map>
#include <string>
#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<int>(Arguments, "amount");
int delay = GetArgumentWithFallback<int>(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();

View File

@ -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);

View File

@ -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<string>(Arguments, "overlay");
string basePath = GetArgument<string>(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;
}

View File

@ -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);

View File

@ -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<bool>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<bool>(Arguments, "loop", false);
int frame = GetArgumentWithFallback<int>(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 {

View File

@ -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);

View File

@ -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<string>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<string>(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<VImage> 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<int> delay(30, 50);
final.set("delay", delay);
}

View File

@ -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);

View File

@ -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<string>(Arguments, "caption");
string basePath = GetArgument<string>(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;
}

View File

@ -4,4 +4,4 @@
using std::string;
char *Homebrew(string *type, ArgumentMap Arguments, size_t *DataSize);
char *Homebrew(string type, string *outType, ArgumentMap Arguments, size_t *DataSize);

View File

@ -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;
}

View File

@ -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);

View File

@ -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<int>(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;

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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<string>(Arguments, "top");
string bottom = GetArgument<string>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<bool>(Arguments, "vertical", false);
bool first = GetArgumentWithFallback<bool>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<string>(Arguments, "top");
string bottom_text = GetArgument<string>(Arguments, "bottom");
string font = GetArgument<string>(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;
}

View File

@ -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);

View File

@ -32,7 +32,7 @@ Napi::Value ProcessImage(const Napi::CallbackInfo& info) {
string command = info[0].As<Napi::String>().Utf8Value();
Napi::Object obj = info[1].As<Napi::Object>();
string type =
obj.Has("type") ? obj.Get("type").As<Napi::String>().Utf8Value() : NULL;
obj.Has("type") ? obj.Get("type").As<Napi::String>().Utf8Value() : "png";
Napi::Array properties = obj.GetPropertyNames();
@ -64,25 +64,28 @@ Napi::Value ProcessImage(const Napi::CallbackInfo& info) {
}
}
string outType = GetArgument<bool>(Arguments, "togif") ? "gif" : type;
size_t length = 0;
char* buf;
if (obj.Has("data")) {
Napi::Buffer<char> data = obj.Has("data")
? obj.Get("data").As<Napi::Buffer<char>>()
: Napi::Buffer<char>::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<char>::New(
env, buf, length,
[]([[maybe_unused]] Napi::Env env, void* data) { free(data); }));
result.Set("type", type);
result.Set("data",
Napi::Buffer<char>::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 (...) {

View File

@ -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<string>(Arguments, "text");
string basePath = GetArgument<string>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<bool>(Arguments, "stretch", false);
bool wide = GetArgumentWithFallback<bool>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<bool>(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;
}

View File

@ -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);

View File

@ -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<string>(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();

View File

@ -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);

View File

@ -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<string>(Arguments, "caption");
float pos = GetArgumentWithFallback<float>(Arguments, "pos", 0.5);
string basePath = GetArgument<string>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<string>(Arguments, "text");
string basePath = GetArgument<string>(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;
}

View File

@ -4,4 +4,4 @@
using std::string;
char *Sonic(string *type, ArgumentMap Arguments, size_t *DataSize);
char *Sonic(string type, string *outType, ArgumentMap Arguments, size_t *DataSize);

View File

@ -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<bool>(Arguments, "slow", false);
int speed = GetArgumentWithFallback<int>(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);

View File

@ -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);

View File

@ -1,14 +1,15 @@
#include "common.h"
#include <Magick++.h>
#include <cstring>
#include <iostream>
#include <list>
#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<int>(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<Image>::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);

View File

@ -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);

View File

@ -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<VImage> 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<int> 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;
}

View File

@ -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);

View File

@ -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<VImage> 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;
}

View File

@ -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);

View File

@ -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<Image> 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();

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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<string>(Arguments, "caption");
string caption2 = GetArgument<string>(Arguments, "caption2");
string font = GetArgument<string>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<float>(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;
}

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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<string>(Arguments, "water");
int gravity = GetArgument<int>(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;
}

View File

@ -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);

View File

@ -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<string>(Arguments, "caption");
string basePath = GetArgument<string>(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<VImage> 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;
}

View File

@ -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);

View File

@ -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<string>(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<VImage> 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;
}

View File

@ -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);