Deduplicate vips shutdown, reformat natives, remove soos alias

This commit is contained in:
Essem 2022-12-28 17:01:50 -06:00
parent 5d8974d177
commit 3c16599126
No known key found for this signature in database
GPG Key ID: 7D497397CC3A2A8C
81 changed files with 360 additions and 464 deletions

1
.clang-format Normal file
View File

@ -0,0 +1 @@
BasedOnStyle: google

View File

@ -6,7 +6,7 @@ class SooSCommand extends ImageCommand {
};
static description = "\"Loops\" an image sequence by reversing it when it's finished";
static aliases = ["bounce", "boomerang"];
static aliases = ["boomerang"];
static requiresGIF = true;
static noImage = "You need to provide an image/GIF to loop!";

View File

@ -195,6 +195,7 @@
"Pizza Tower",
"ANTONBLAST",
"[object Object]",
"Xonotic",
"The clock is ticking."
]
}

View File

@ -1,9 +1,9 @@
#include "common.h"
#include <map>
#include <string>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -17,8 +17,7 @@ char *Blur(string *type, char *BufferData, size_t BufferLength,
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
// TODO: find a better way to calculate the intensity for GIFs without
// splitting frames
@ -28,8 +27,5 @@ char *Blur(string *type, char *BufferData, size_t BufferLength,
void *buf;
out.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Blur(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Blur(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,14 +1,14 @@
#include "common.h"
#include <math.h>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Bounce(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
VOption *options = VImage::option();
VImage in =
@ -17,8 +17,7 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength,
*type == "gif" ? options->set("n", -1)->set("access", "sequential")
: options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -31,7 +30,8 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength,
VImage img_frame =
*type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
double height = halfHeight * ((abs(sin(i * mult)) * -1) + 1);
VImage embedded = img_frame.embed(0, height, width, pageHeight + halfHeight);
VImage embedded =
img_frame.embed(0, height, width, pageHeight + halfHeight);
img.push_back(embedded);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
@ -46,7 +46,5 @@ char *Bounce(string *type, char *BufferData, size_t BufferLength,
*type = "gif";
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Bounce(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Bounce(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,15 +1,13 @@
#include "common.h"
#include <map>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Caption(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string caption = GetArgument<string>(Arguments, "caption");
string font = GetArgument<string>(Arguments, "font");
string basePath = GetArgument<string>(Arguments, "basePath");
@ -21,8 +19,7 @@ char *Caption(string *type, char *BufferData, size_t BufferLength,
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int size = width / 10;
@ -73,10 +70,7 @@ char *Caption(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
vips_error_clear();
vips_thread_shutdown();
: 0);
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Caption(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Caption(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,15 +1,14 @@
#include "common.h"
#include <map>
#include <string>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *CaptionTwo(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
bool top = GetArgument<bool>(Arguments, "top");
string caption = GetArgument<string>(Arguments, "caption");
string font = GetArgument<string>(Arguments, "font");
@ -22,8 +21,7 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength,
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int size = width / 13;
@ -76,10 +74,7 @@ char *CaptionTwo(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
vips_error_clear();
vips_thread_shutdown();
: 0);
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* CaptionTwo(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* CaptionTwo(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,4 +1,3 @@
#include "common.h"
#include <Magick++.h>
#include <cstring>
@ -7,12 +6,13 @@
#include <map>
#include <string>
#include "common.h"
using namespace std;
using namespace Magick;
char *Circle(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
Blob blob;
list<Image> frames;
@ -45,7 +45,7 @@ char *Circle(string *type, char *BufferData, size_t BufferLength,
writeImages(blurred.begin(), blurred.end(), &blob);
*DataSize = blob.length();
// workaround because the data is tied to the blob
char *data = (char *)malloc(*DataSize);
memcpy(data, blob.data(), *DataSize);

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Circle(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Circle(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,9 +1,9 @@
#include "common.h"
#include <map>
#include <string>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -12,7 +12,6 @@ VImage sepia = VImage::new_matrixv(3, 3, 0.3588, 0.7044, 0.1368, 0.2990, 0.5870,
char *Colors(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string color = GetArgument<string>(Arguments, "color");
VOption *options = VImage::option()->set("access", "sequential");
@ -33,8 +32,5 @@ char *Colors(string *type, char *BufferData, size_t BufferLength,
void *buf;
out.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Colors(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Colors(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,13 +1,13 @@
#pragma once
#include <variant>
#include <string>
#include <map>
#include <string>
#include <unordered_map>
#include <variant>
using std::map;
using std::string;
using std::variant;
using std::map;
typedef variant<string, float, bool, int> ArgumentVariant;
typedef map<string, ArgumentVariant> ArgumentMap;
@ -25,19 +25,21 @@ template <typename T>
T GetArgumentWithFallback(ArgumentMap map, string key, T fallback) {
try {
return std::get<T>(map.at(key));
} catch (...) { // this is, not great...
} catch (...) { // this is, not great...
return fallback;
}
}
#define MAP_HAS(ARRAY, KEY) (ARRAY.count(KEY) > 0)
#define MAP_GET(ARRAY, KEY, TYPE) (MAP_HAS(ARRAY, KEY) ? get<TYPE>(ARRAY.at(KEY)) : NULL) // C++ has forced my hand
#define MAP_GET_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) (MAP_HAS(ARRAY, KEY) ? get<TYPE>(ARRAY.at(KEY)) : FALLBACK)
#define MAP_GET(ARRAY, KEY, TYPE) \
(MAP_HAS(ARRAY, KEY) ? get<TYPE>(ARRAY.at(KEY)) \
: NULL) // C++ has forced my hand
#define MAP_GET_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) \
(MAP_HAS(ARRAY, KEY) ? get<TYPE>(ARRAY.at(KEY)) : FALLBACK)
#define ARG_TYPES std::variant<string, bool, int, float>
const std::unordered_map<std::string, std::string> fontPaths {
{"futura", "assets/fonts/caption.otf"},
{"helvetica", "assets/fonts/caption2.ttf"},
{"roboto", "assets/fonts/reddit.ttf"}
};
const std::unordered_map<std::string, std::string> fontPaths{
{"futura", "assets/fonts/caption.otf"},
{"helvetica", "assets/fonts/caption2.ttf"},
{"roboto", "assets/fonts/reddit.ttf"}};

View File

@ -1,14 +1,14 @@
#include "common.h"
#include <map>
#include <string>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Crop(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
@ -44,10 +44,7 @@ char *Crop(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
vips_error_clear();
vips_thread_shutdown();
: 0);
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Crop(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Crop(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,13 +1,13 @@
#include "common.h"
#include <map>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Deepfry(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
@ -15,8 +15,7 @@ char *Deepfry(string *type, char *BufferData, size_t BufferLength,
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -49,16 +48,13 @@ char *Deepfry(string *type, char *BufferData, size_t BufferLength,
VImage::option()->set("Q", 1)->set("strip", true));
final = VImage::new_from_buffer(jpgBuf, jpgLength, "");
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
if (*type == "gif")
final.set("delay", fried.get_array_int("delay"));
if (*type == "gif") final.set("delay", fried.get_array_int("delay"));
}
void *buf;
final.write_to_buffer(("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0) : 0);
vips_error_clear();
vips_thread_shutdown();
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0) : 0);
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Deepfry(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Deepfry(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Explode(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Explode(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,15 +1,14 @@
#include "common.h"
#include <map>
#include <string>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Flag(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string overlay = GetArgument<string>(Arguments, "overlay");
string basePath = GetArgument<string>(Arguments, "basePath");
@ -20,8 +19,7 @@ char *Flag(string *type, char *BufferData, size_t BufferLength,
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -31,8 +29,8 @@ char *Flag(string *type, char *BufferData, size_t BufferLength,
VImage overlayInput = VImage::new_from_file(assetPath.c_str());
VImage overlayImage = overlayInput.resize(
(double)width / (double)overlayInput.width(),
VImage::option()->set("vscale", (double)pageHeight /
(double)overlayInput.height()));
VImage::option()->set(
"vscale", (double)pageHeight / (double)overlayInput.height()));
if (!overlayImage.has_alpha()) {
overlayImage = overlayImage.bandjoin(127);
} else {
@ -56,9 +54,7 @@ char *Flag(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
: 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Flag(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Flag(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,15 +1,13 @@
#include "common.h"
#include <map>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Flip(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
bool flop = GetArgument<bool>(Arguments, "flop");
VImage in = VImage::new_from_buffer(BufferData, BufferLength, "",
@ -18,8 +16,7 @@ char *Flip(string *type, char *BufferData, size_t BufferLength,
"access", "sequential")
: 0)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
VImage out;
if (flop) {
@ -44,9 +41,7 @@ char *Flip(string *type, char *BufferData, size_t BufferLength,
out.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
: 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Flip(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Flip(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,16 +1,14 @@
#include "common.h"
#include <algorithm>
#include <map>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Freeze(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
bool loop = GetArgumentWithFallback<bool>(Arguments, "loop", false);
int frame = GetArgumentWithFallback<int>(Arguments, "frame", -1);
@ -42,22 +40,17 @@ char *Freeze(string *type, char *BufferData, size_t BufferLength,
*DataSize = BufferLength + 19;
break;
}
if (none)
*DataSize = BufferLength;
vips_error_clear();
vips_thread_shutdown();
if (none) *DataSize = BufferLength;
return newData;
} else if (frame >= 0 && !loop) {
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
VImage in = VImage::new_from_buffer(
BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
int pageHeight = vips_image_get_page_height(in.get_image());
int nPages = vips_image_get_n_pages(in.get_image());
@ -69,9 +62,6 @@ char *Freeze(string *type, char *BufferData, size_t BufferLength,
void *buf;
out.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
} else {
lastPos = (char *)memchr(fileData, '\x21', BufferLength);
@ -86,11 +76,8 @@ char *Freeze(string *type, char *BufferData, size_t BufferLength,
none = false;
break;
}
if (none)
*DataSize = BufferLength;
if (none) *DataSize = BufferLength;
vips_error_clear();
vips_thread_shutdown();
return fileData;
}
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Freeze(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Freeze(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,13 +1,12 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Gamexplain(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string basePath = GetArgument<string>(Arguments, "basePath");
VOption *options = VImage::option()->set("access", "sequential");
@ -16,8 +15,7 @@ char *Gamexplain(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
string assetPath = basePath + "assets/images/gamexplain.png";
VImage tmpl = VImage::new_from_file(assetPath.c_str());
@ -45,10 +43,7 @@ char *Gamexplain(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
vips_error_clear();
vips_thread_shutdown();
: 0);
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Gamexplain(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Gamexplain(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,13 +1,12 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Globe(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string basePath = GetArgument<string>(Arguments, "basePath");
VOption *options = VImage::option();
@ -16,10 +15,9 @@ char *Globe(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(
BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1)->set("access", "sequential")
: options)
: options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -28,17 +26,15 @@ char *Globe(string *type, char *BufferData, size_t BufferLength,
double size = min(width, pageHeight);
string diffPath = basePath + "assets/images/globediffuse.png";
VImage diffuse =
VImage::new_from_file(diffPath.c_str())
.resize(size / 500.0,
VImage::option()->set("kernel", VIPS_KERNEL_CUBIC)) /
255;
VImage diffuse = VImage::new_from_file(diffPath.c_str())
.resize(size / 500.0, VImage::option()->set(
"kernel", VIPS_KERNEL_CUBIC)) /
255;
string specPath = basePath + "assets/images/globespec.png";
VImage specular =
VImage::new_from_file(specPath.c_str())
.resize(size / 500.0,
VImage::option()->set("kernel", VIPS_KERNEL_CUBIC));
VImage specular = VImage::new_from_file(specPath.c_str())
.resize(size / 500.0, VImage::option()->set(
"kernel", VIPS_KERNEL_CUBIC));
string distortPath = basePath + "assets/images/spheremap.png";
VImage distort =
@ -73,7 +69,5 @@ char *Globe(string *type, char *BufferData, size_t BufferLength,
void *buf;
final.write_to_buffer(".gif", &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Globe(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Globe(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -34,7 +34,5 @@ char *Homebrew(string *type, ArgumentMap Arguments, size_t *DataSize) {
*type = "png";
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

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

View File

@ -1,16 +1,16 @@
#include "common.h"
#include <napi.h>
#include <iostream>
#include <map>
#include <string>
#include <iostream>
#include "blur.h"
#include "bounce.h"
#include "colors.h"
#include "caption.h"
#include "caption2.h"
#include "circle.h"
#include "colors.h"
#include "common.h"
#include "crop.h"
#include "deepfry.h"
#include "explode.h"
@ -25,7 +25,6 @@
#include "magik.h"
#include "meme.h"
#include "mirror.h"
#include "swirl.h"
#include "motivate.h"
#include "reddit.h"
#include "resize.h"
@ -36,6 +35,7 @@
#include "speed.h"
#include "spin.h"
#include "squish.h"
#include "swirl.h"
#include "tile.h"
#include "togif.h"
#include "uncanny.h"
@ -52,50 +52,50 @@
using namespace std;
std::map<std::string, char* (*)(string *type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize)> FunctionMap = {
{"blur", &Blur},
{"bounce", &Bounce},
{"caption", &Caption},
{"captionTwo", &CaptionTwo},
{"circle", &Circle},
{"colors", &Colors},
{"crop", &Crop},
{"deepfry", &Deepfry},
{"explode", &Explode},
{"flag", &Flag},
{"flip", &Flip},
{"freeze", &Freeze},
{"gamexplain", Gamexplain},
{"globe", Globe},
{"invert", Invert},
{"jpeg", Jpeg},
{"magik", Magik},
{"meme", Meme},
{"mirror", Mirror},
{"motivate", Motivate},
{"reddit", Reddit},
{"resize", Resize},
{"reverse", Reverse},
{"scott", Scott},
{"snapchat", Snapchat},
{"speed", &Speed},
{"spin", Spin},
{"squish", Squish},
{"swirl", Swirl},
{"tile", Tile},
{"togif", ToGif},
{"uncanny", Uncanny},
{"uncaption", &Uncaption},
{"wall", Wall},
{"watermark", &Watermark},
{"whisper", Whisper},
{"zamn", Zamn}
};
std::map<std::string,
char* (*)(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize)>
FunctionMap = {{"blur", &Blur},
{"bounce", &Bounce},
{"caption", &Caption},
{"captionTwo", &CaptionTwo},
{"circle", &Circle},
{"colors", &Colors},
{"crop", &Crop},
{"deepfry", &Deepfry},
{"explode", &Explode},
{"flag", &Flag},
{"flip", &Flip},
{"freeze", &Freeze},
{"gamexplain", Gamexplain},
{"globe", Globe},
{"invert", Invert},
{"jpeg", Jpeg},
{"magik", Magik},
{"meme", Meme},
{"mirror", Mirror},
{"motivate", Motivate},
{"reddit", Reddit},
{"resize", Resize},
{"reverse", Reverse},
{"scott", Scott},
{"snapchat", Snapchat},
{"speed", &Speed},
{"spin", Spin},
{"squish", Squish},
{"swirl", Swirl},
{"tile", Tile},
{"togif", ToGif},
{"uncanny", Uncanny},
{"uncaption", &Uncaption},
{"wall", Wall},
{"watermark", &Watermark},
{"whisper", Whisper},
{"zamn", Zamn}};
std::map<std::string, char* (*)(string *type, ArgumentMap Arguments, size_t* DataSize)> NoInputFunctionMap = {
{"homebrew", Homebrew},
{"sonic", Sonic}
};
std::map<std::string,
char* (*)(string* type, ArgumentMap Arguments, size_t* DataSize)>
NoInputFunctionMap = {{"homebrew", Homebrew}, {"sonic", Sonic}};
bool isNapiValueInt(Napi::Env& env, Napi::Value& num) {
return env.Global()
@ -108,21 +108,23 @@ bool isNapiValueInt(Napi::Env& env, Napi::Value& num) {
.Value();
}
Napi::Value ProcessImage(const Napi::CallbackInfo &info) {
Napi::Value ProcessImage(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Object result = Napi::Object::New(env);
try {
string command = info[0].As<Napi::String>().Utf8Value();
Napi::Object obj = info[1].As<Napi::Object>();
string type = obj.Has("type") ? obj.Get("type").As<Napi::String>().Utf8Value() : NULL;
string type =
obj.Has("type") ? obj.Get("type").As<Napi::String>().Utf8Value() : NULL;
Napi::Array properties = obj.GetPropertyNames();
ArgumentMap Arguments;
for (unsigned int i = 0; i < properties.Length(); i++) {
string property = properties.Get(uint32_t(i)).As<Napi::String>().Utf8Value();
string property =
properties.Get(uint32_t(i)).As<Napi::String>().Utf8Value();
if (property == "data") {
continue;
@ -142,23 +144,30 @@ Napi::Value ProcessImage(const Napi::CallbackInfo &info) {
}
} else {
throw "Unimplemented value type passed to image native.";
//Arguments[property] = val;
// Arguments[property] = val;
}
}
size_t length = 0;
char* buf;
if (obj.Has("data")) {
Napi::Buffer<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(), Arguments, &length);
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(),
Arguments, &length);
} else {
buf = NoInputFunctionMap.at(command)(&type, Arguments, &length);
}
result.Set("data", Napi::Buffer<char>::New(env, buf, length, [](Napi::Env env, void* data) {
free(data);
}));
vips_error_clear();
vips_thread_shutdown();
result.Set("data", Napi::Buffer<char>::New(
env, buf, length,
[](Napi::Env env, void* data) { free(data); }));
result.Set("type", type);
} catch (std::exception const &err) {
} catch (std::exception const& err) {
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
} catch (...) {
Napi::Error::New(env, "Unknown error").ThrowAsJavaScriptException();
@ -167,30 +176,30 @@ Napi::Value ProcessImage(const Napi::CallbackInfo &info) {
return result;
}
Napi::Object Init(Napi::Env env, Napi::Object exports){
Napi::Object Init(Napi::Env env, Napi::Object exports) {
#ifdef _WIN32
Magick::InitializeMagick("");
#endif
if (vips_init(""))
vips_error_exit(NULL);
exports.Set(Napi::String::New(env, "image"), Napi::Function::New(env, ProcessImage)); // new function handler
if (vips_init("")) vips_error_exit(NULL);
exports.Set(Napi::String::New(env, "image"),
Napi::Function::New(env, ProcessImage)); // new function handler
Napi::Array arr = Napi::Array::New(env);
size_t i = 0;
for (auto const& imap: FunctionMap) {
Napi::HandleScope scope(env);
arr[i] = Napi::String::New(env, imap.first);
i++;
}
for (auto const& imap: NoInputFunctionMap) {
Napi::HandleScope scope(env);
arr[i] = Napi::String::New(env, imap.first);
i++;
}
Napi::Array arr = Napi::Array::New(env);
size_t i = 0;
for (auto const& imap : FunctionMap) {
Napi::HandleScope scope(env);
arr[i] = Napi::String::New(env, imap.first);
i++;
}
for (auto const& imap : NoInputFunctionMap) {
Napi::HandleScope scope(env);
arr[i] = Napi::String::New(env, imap.first);
i++;
}
exports.Set(Napi::String::New(env, "funcs"), arr);
exports.Set(Napi::String::New(env, "funcs"), arr);
return exports;
return exports;
}
NODE_API_MODULE(addon, Init)

View File

@ -1,21 +1,19 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Invert(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
VImage noAlpha =
in.extract_band(0, VImage::option()->set("n", in.bands() - 1));
@ -25,7 +23,5 @@ char *Invert(string *type, char *BufferData, size_t BufferLength,
void *buf;
out.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Invert(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Invert(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -16,8 +16,7 @@ char *Jpeg(string *type, char *BufferData, size_t BufferLength,
BufferData, BufferLength, "",
VImage::option()->set("access", "sequential")->set("n", -1))
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -53,18 +52,15 @@ char *Jpeg(string *type, char *BufferData, size_t BufferLength,
final.set("delay", in.get_array_int("delay"));
}
final.write_to_buffer(("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)
: 0);
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0) : 0);
} else {
VImage in = VImage::new_from_buffer(BufferData, BufferLength, "");
in.write_to_buffer(".jpg", &buf, DataSize,
VImage::option()->set("Q", quality)->set("strip", true));
*type = "jpg";
}
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Jpeg(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Jpeg(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,16 +1,16 @@
#include "common.h"
#include <Magick++.h>
#include <cstring>
#include <iostream>
#include <list>
#include "common.h"
using namespace std;
using namespace Magick;
char *Magik(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
Blob blob;
list<Image> frames;

View File

@ -4,4 +4,5 @@
using std::string;
char* Magik(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Magik(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -18,8 +18,7 @@ char *Meme(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -101,11 +100,10 @@ char *Meme(string *type, char *BufferData, size_t BufferLength,
}
bottomOutline = (bottomOutline == zeroVec);
VImage bottomInvert = bottomOutline.extract_band(3).invert();
bottomOutline =
bottomOutline
.extract_band(0,
VImage::option()->set("n", bottomOutline.bands() - 1))
.bandjoin(bottomInvert);
bottomOutline = bottomOutline
.extract_band(0, VImage::option()->set(
"n", bottomOutline.bands() - 1))
.bandjoin(bottomInvert);
bottomText = bottomOutline.composite2(bottomIn, VIPS_BLEND_MODE_OVER);
}
@ -134,9 +132,7 @@ char *Meme(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
: 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Meme(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Meme(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -16,8 +16,7 @@ char *Mirror(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
VImage out;
@ -61,7 +60,5 @@ char *Mirror(string *type, char *BufferData, size_t BufferLength,
void *buf;
out.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Mirror(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Mirror(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -18,8 +18,7 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int size = width / 5;
@ -100,8 +99,7 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength,
VImage::option()->set("background", 0x000000)->set("expand", true));
}
if (bottom_text != "") {
if (top_text == "")
frame = bordered3;
if (top_text == "") frame = bordered3;
frame = frame.join(
bottomImage.gravity(VIPS_COMPASS_DIRECTION_NORTH, bordered3.width(),
bottomImage.height() + (size / 4),
@ -117,10 +115,9 @@ char *Motivate(string *type, char *BufferData, size_t BufferLength,
final.set(VIPS_META_PAGE_HEIGHT, height);
void *buf;
final.write_to_buffer(("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 1) : 0);
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 1) : 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Motivate(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Motivate(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,13 +1,12 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Reddit(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string text = GetArgument<string>(Arguments, "text");
string basePath = GetArgument<string>(Arguments, "basePath");
@ -17,8 +16,7 @@ char *Reddit(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
string assetPath = basePath + "assets/images/reddit.png";
VImage tmpl = VImage::new_from_file(assetPath.c_str());
@ -62,9 +60,7 @@ char *Reddit(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
: 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Reddit(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Reddit(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -50,7 +50,5 @@ char *Resize(string *type, char *BufferData, size_t BufferLength,
void *buf;
out.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Resize(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Resize(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,8 +1,8 @@
#include "common.h"
#include <algorithm>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -55,7 +55,5 @@ char *Reverse(string *type, char *BufferData, size_t BufferLength,
*type = "gif";
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Reverse(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Reverse(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,10 +1,11 @@
#include "common.h"
#include <Magick++.h>
#include <cstring>
#include <iostream>
#include <list>
#include "common.h"
using namespace std;
using namespace Magick;
@ -56,7 +57,7 @@ char *Scott(string *type, char *BufferData, size_t BufferLength,
writeImages(mid.begin(), mid.end(), &blob);
*DataSize = blob.length();
char *data = (char *)malloc(*DataSize);
memcpy(data, blob.data(), *DataSize);
return data;

View File

@ -4,4 +4,5 @@
using std::string;
char* Scott(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Scott(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -17,8 +17,7 @@ char *Snapchat(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -66,9 +65,7 @@ char *Snapchat(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
: 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Snapchat(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Snapchat(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -32,7 +32,5 @@ char *Sonic(string *type, ArgumentMap Arguments, size_t *DataSize) {
*type = "png";
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

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

View File

@ -1,18 +1,16 @@
#include "common.h"
#include <iostream>
#include <map>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
void *memset16(void *m, uint16_t val, size_t count) {
uint16_t *buf = (uint16_t *)m;
while (count--)
*buf++ = val;
while (count--) *buf++ = val;
return m;
}
@ -21,8 +19,7 @@ char *vipsRemove(char *data, size_t length, size_t *DataSize, int speed) {
VImage in = VImage::new_from_buffer(data, length, "", options->set("n", -1))
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -44,7 +41,6 @@ char *vipsRemove(char *data, size_t length, size_t *DataSize, int speed) {
char *Speed(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
bool slow = GetArgumentWithFallback<bool>(Arguments, "slow", false);
int speed = GetArgumentWithFallback<int>(Arguments, "speed", 2);
@ -102,8 +98,5 @@ char *Speed(string *type, char *BufferData, size_t BufferLength,
*DataSize = BufferLength;
}
vips_error_clear();
vips_thread_shutdown();
return fileData;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Speed(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Speed(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -4,4 +4,5 @@
using std::string;
char* Spin(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Spin(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,14 +1,14 @@
#include "common.h"
#include <math.h>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Squish(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
VOption *options = VImage::option();
VImage in =
@ -17,8 +17,7 @@ char *Squish(string *type, char *BufferData, size_t BufferLength,
*type == "gif" ? options->set("n", -1)->set("access", "sequential")
: options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -48,7 +47,5 @@ char *Squish(string *type, char *BufferData, size_t BufferLength,
*type = "gif";
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Squish(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Squish(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,21 +1,19 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Swirl(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
VOption *options = VImage::option()->set("access", "sequential");
VImage in =
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int pageHeight = vips_image_get_page_height(in.get_image());
int nPages = vips_image_get_n_pages(in.get_image());
@ -74,7 +72,5 @@ char *Swirl(string *type, char *BufferData, size_t BufferLength,
void *buf;
final.write_to_buffer(".gif", &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Swirl(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Swirl(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,16 +1,16 @@
#include "common.h"
#include <Magick++.h>
#include <cstring>
#include <iostream>
#include <list>
#include "common.h"
using namespace std;
using namespace Magick;
char *Tile(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
Blob blob;
list<Image> frames;

View File

@ -4,4 +4,5 @@
using std::string;
char* Tile(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Tile(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,32 +1,26 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *ToGif(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
if (*type == "gif") {
vips_error_clear();
vips_thread_shutdown();
*DataSize = BufferLength;
return BufferData;
} else {
VOption *options = VImage::option()->set("access", "sequential");
VImage in = VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "webp" ? options->set("n", -1)
: options);
VImage in = VImage::new_from_buffer(
BufferData, BufferLength, "",
*type == "webp" ? options->set("n", -1) : options);
void *buf;
in.write_to_buffer(".gif", &buf, DataSize);
*type = "gif";
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}
}

View File

@ -4,4 +4,5 @@
using std::string;
char* ToGif(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* ToGif(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,13 +1,12 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Uncanny(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string caption = GetArgument<string>(Arguments, "caption");
string caption2 = GetArgument<string>(Arguments, "caption2");
string font = GetArgument<string>(Arguments, "font");
@ -94,11 +93,9 @@ char *Uncanny(string *type, char *BufferData, size_t BufferLength,
final.set(VIPS_META_PAGE_HEIGHT, 720);
void *buf;
final.write_to_buffer(("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("reoptimise", 1)
: 0);
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("reoptimise", 1) : 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Uncanny(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Uncanny(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,14 +1,13 @@
#include "common.h"
#include <map>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Uncaption(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
float tolerance = GetArgumentWithFallback<float>(Arguments, "tolerance", 0.5);
VOption *options = VImage::option();
@ -17,10 +16,9 @@ char *Uncaption(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(
BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1)->set("access", "sequential")
: options)
: options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -49,9 +47,7 @@ char *Uncaption(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
: 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Uncaption(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Uncaption(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,16 +1,16 @@
#include "common.h"
#include <Magick++.h>
#include <cstring>
#include <iostream>
#include <list>
#include "common.h"
using namespace std;
using namespace Magick;
char *Wall(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
Blob blob;
list<Image> frames;

View File

@ -4,4 +4,5 @@
using std::string;
char* Wall(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Wall(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,14 +1,13 @@
#include "common.h"
#include <map>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
char *Watermark(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string water = GetArgument<string>(Arguments, "water");
int gravity = GetArgument<int>(Arguments, "gravity");
@ -31,8 +30,7 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
string merged = basePath + water;
VImage watermark = VImage::new_from_file(merged.c_str());
@ -59,30 +57,30 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength,
int x = 0, y = 0;
switch (gravity) {
case 1:
break;
case 2:
x = (width / 2) - (watermark.width() / 2);
break;
case 3:
x = width - watermark.width();
break;
case 5:
x = (width / 2) - (watermark.width() / 2);
y = (pageHeight / 2) - (watermark.height() / 2);
break;
case 6:
x = width - watermark.width();
y = (pageHeight / 2) - (watermark.height() / 2);
break;
case 8:
x = (width / 2) - (watermark.width() / 2);
y = pageHeight - watermark.height();
break;
case 9:
x = width - watermark.width();
y = pageHeight - watermark.height();
break;
case 1:
break;
case 2:
x = (width / 2) - (watermark.width() / 2);
break;
case 3:
x = width - watermark.width();
break;
case 5:
x = (width / 2) - (watermark.width() / 2);
y = (pageHeight / 2) - (watermark.height() / 2);
break;
case 6:
x = width - watermark.width();
y = (pageHeight / 2) - (watermark.height() / 2);
break;
case 8:
x = (width / 2) - (watermark.width() / 2);
y = pageHeight - watermark.height();
break;
case 9:
x = width - watermark.width();
y = pageHeight - watermark.height();
break;
}
vector<VImage> img;
@ -149,9 +147,7 @@ char *Watermark(string *type, char *BufferData, size_t BufferLength,
final.write_to_buffer(
("." + *type).c_str(), &buf, DataSize,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
: 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -1,9 +1,8 @@
#pragma once
#include "common.h"
#include <map>
using std::map;
using std::string;
char* Watermark(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Watermark(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -16,8 +16,7 @@ char *Whisper(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -82,7 +81,5 @@ char *Whisper(string *type, char *BufferData, size_t BufferLength,
*type == "gif" ? VImage::option()->set("dither", 0)->set("reoptimise", 1)
: 0);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Whisper(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Whisper(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);

View File

@ -1,7 +1,7 @@
#include "common.h"
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace vips;
@ -15,8 +15,7 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength,
VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha())
in = in.bandjoin(255);
if (!in.has_alpha()) in = in.bandjoin(255);
int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
@ -29,13 +28,13 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength,
for (int i = 0; i < nPages; i++) {
VImage img_frame =
*type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage composited =
tmpl.insert(img_frame.extract_band(0, VImage::option()->set("n", 3))
.bandjoin(255)
.resize(303.0 / (double)width,
VImage::option()->set(
"vscale", 438.0 / (double)pageHeight)),
310, 76);
VImage composited = tmpl.insert(
img_frame.extract_band(0, VImage::option()->set("n", 3))
.bandjoin(255)
.resize(
303.0 / (double)width,
VImage::option()->set("vscale", 438.0 / (double)pageHeight)),
310, 76);
img.push_back(composited);
}
VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
@ -44,7 +43,5 @@ char *Zamn(string *type, char *BufferData, size_t BufferLength,
void *buf;
final.write_to_buffer(("." + *type).c_str(), &buf, DataSize);
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}

View File

@ -4,4 +4,5 @@
using std::string;
char* Zamn(string* type, char* BufferData, size_t BufferLength, ArgumentMap Arguments, size_t* DataSize);
char* Zamn(string* type, char* BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t* DataSize);