diff --git a/natives/blur.cc b/natives/blur.cc index 5ca0fd0..0f27b3c 100644 --- a/natives/blur.cc +++ b/natives/blur.cc @@ -8,7 +8,7 @@ using namespace std; using namespace vips; char *Blur(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { bool sharp = MAP_GET(Arguments, "sharp", bool); VOption *options = VImage::option()->set("access", "sequential"); diff --git a/natives/blur.h b/natives/blur.h index 82d611b..b0c14ea 100644 --- a/natives/blur.h +++ b/natives/blur.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Blur(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Blur(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/caption.cc b/natives/caption.cc index 881e25a..c1f0599 100644 --- a/natives/caption.cc +++ b/natives/caption.cc @@ -8,7 +8,7 @@ using namespace std; using namespace vips; char *Caption(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { string caption = MAP_GET(Arguments, "caption", string); string font = MAP_GET(Arguments, "font", string); diff --git a/natives/caption.h b/natives/caption.h index e354dae..b1266ec 100644 --- a/natives/caption.h +++ b/natives/caption.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Caption(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Caption(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/caption2.cc b/natives/caption2.cc index eed3fb4..b517ceb 100644 --- a/natives/caption2.cc +++ b/natives/caption2.cc @@ -8,7 +8,7 @@ using namespace std; using namespace vips; char *CaptionTwo(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { bool top = MAP_GET(Arguments, "top", bool); string caption = MAP_GET(Arguments, "caption", string); diff --git a/natives/caption2.h b/natives/caption2.h index 77fe4bb..7fd17bc 100644 --- a/natives/caption2.h +++ b/natives/caption2.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* CaptionTwo(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* CaptionTwo(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/circle.cc b/natives/circle.cc index ed8917e..4772393 100644 --- a/natives/circle.cc +++ b/natives/circle.cc @@ -11,7 +11,7 @@ using namespace std; using namespace Magick; char *Circle(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { Blob blob; diff --git a/natives/circle.h b/natives/circle.h index 9d1e78a..be378da 100644 --- a/natives/circle.h +++ b/natives/circle.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Circle(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Circle(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/colors.cc b/natives/colors.cc index ae6a885..2ffc002 100644 --- a/natives/colors.cc +++ b/natives/colors.cc @@ -11,7 +11,7 @@ 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, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { string color = MAP_GET(Arguments, "color", string); diff --git a/natives/colors.h b/natives/colors.h index a3f4665..ea11984 100644 --- a/natives/colors.h +++ b/natives/colors.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Colors(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Colors(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/common.h b/natives/common.h index 820adbb..ebca0fe 100644 --- a/natives/common.h +++ b/natives/common.h @@ -1,12 +1,14 @@ #pragma once -#include +#include #include #include #define MAP_HAS(ARRAY, KEY) (ARRAY.count(KEY) > 0) -#define MAP_GET(ARRAY, KEY, TYPE) (MAP_HAS(ARRAY, KEY) ? any_cast(ARRAY.at(KEY)) : NULL) // C++ has forced my hand -#define MAP_GET_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) (MAP_HAS(ARRAY, KEY) ? any_cast(ARRAY.at(KEY)) : FALLBACK) +#define MAP_GET(ARRAY, KEY, TYPE) (MAP_HAS(ARRAY, KEY) ? get(ARRAY.at(KEY)) : NULL) // C++ has forced my hand +#define MAP_GET_FALLBACK(ARRAY, KEY, TYPE, FALLBACK) (MAP_HAS(ARRAY, KEY) ? get(ARRAY.at(KEY)) : FALLBACK) + +#define ARG_TYPES std::variant const std::unordered_map fontPaths { {"futura", "assets/fonts/caption.otf"}, diff --git a/natives/crop.cc b/natives/crop.cc index 4b9f527..d74badb 100644 --- a/natives/crop.cc +++ b/natives/crop.cc @@ -7,7 +7,7 @@ using namespace std; using namespace vips; char *Crop(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { VOption *options = VImage::option()->set("access", "sequential"); diff --git a/natives/crop.h b/natives/crop.h index aeea95c..a3ab89e 100644 --- a/natives/crop.h +++ b/natives/crop.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Crop(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Crop(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/deepfry.cc b/natives/deepfry.cc index 03b4bad..5aa0941 100644 --- a/natives/deepfry.cc +++ b/natives/deepfry.cc @@ -6,7 +6,7 @@ using namespace std; using namespace vips; char *Deepfry(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { VOption *options = VImage::option()->set("access", "sequential"); diff --git a/natives/deepfry.h b/natives/deepfry.h index b06cb6c..fd8104e 100644 --- a/natives/deepfry.h +++ b/natives/deepfry.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Deepfry(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Deepfry(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/explode.cc b/natives/explode.cc index d2c9970..9ab1a5d 100644 --- a/natives/explode.cc +++ b/natives/explode.cc @@ -12,7 +12,7 @@ using namespace std; using namespace Magick; char *Explode(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { int amount = MAP_GET(Arguments, "amount", int); int delay = MAP_GET_FALLBACK(Arguments, "delay", int, 0); diff --git a/natives/explode.h b/natives/explode.h index 1b9126c..74427b6 100644 --- a/natives/explode.h +++ b/natives/explode.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Explode(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Explode(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/flag.cc b/natives/flag.cc index 4aae54e..75cf91c 100644 --- a/natives/flag.cc +++ b/natives/flag.cc @@ -8,7 +8,7 @@ using namespace std; using namespace vips; char *Flag(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { string overlay = MAP_GET(Arguments, "overlay", string); string basePath = MAP_GET(Arguments, "basePath", string); diff --git a/natives/flag.h b/natives/flag.h index 9e6da56..da5fc46 100644 --- a/natives/flag.h +++ b/natives/flag.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Flag(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Flag(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/flip.cc b/natives/flip.cc index 5811fae..c2ad6ea 100644 --- a/natives/flip.cc +++ b/natives/flip.cc @@ -8,7 +8,7 @@ using namespace std; using namespace vips; char *Flip(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { bool flop = MAP_GET(Arguments, "flop", bool); diff --git a/natives/flip.h b/natives/flip.h index aba5962..c910833 100644 --- a/natives/flip.h +++ b/natives/flip.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Flip(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Flip(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/image.cc b/natives/image.cc index 0ecbd53..7a717bb 100644 --- a/natives/image.cc +++ b/natives/image.cc @@ -4,7 +4,6 @@ #include #include #include -#include #include "blur.h" #include "colors.h" @@ -52,7 +51,7 @@ using namespace std; -std::map Arguments, size_t* DataSize)> FunctionMap = { +std::map Arguments, size_t* DataSize)> FunctionMap = { {"blur", &Blur}, {"caption", &Caption}, {"captionTwo", &CaptionTwo}, @@ -118,7 +117,7 @@ Napi::Value NewProcessImage(const Napi::CallbackInfo &info) { Napi::Array properties = obj.GetPropertyNames(); - std::map Arguments; + std::map Arguments; for (unsigned int i = 0; i < properties.Length(); i++) { string property = properties.Get(uint32_t(i)).As().Utf8Value(); @@ -139,8 +138,6 @@ Napi::Value NewProcessImage(const Napi::CallbackInfo &info) { } else { Arguments[property] = num.FloatValue(); } - } else { - Arguments[property] = val; } } @@ -174,6 +171,7 @@ Napi::Value ProcessImage(const Napi::CallbackInfo &info) { // janky solution for return OldProcessImage(command, info); } else { Napi::Error::New(env, "Invalid command").ThrowAsJavaScriptException(); + return env.Null(); } } diff --git a/natives/uncaption.cc b/natives/uncaption.cc index 61bb468..11b0f93 100644 --- a/natives/uncaption.cc +++ b/natives/uncaption.cc @@ -7,7 +7,7 @@ using namespace std; using namespace vips; char *Uncaption(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { float tolerance = MAP_GET_FALLBACK(Arguments, "tolerance", float, 0.5); diff --git a/natives/uncaption.h b/natives/uncaption.h index ebd4318..6798490 100644 --- a/natives/uncaption.h +++ b/natives/uncaption.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Uncaption(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Uncaption(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file diff --git a/natives/watermark.cc b/natives/watermark.cc index 9b53857..f1bb970 100644 --- a/natives/watermark.cc +++ b/natives/watermark.cc @@ -7,7 +7,7 @@ using namespace std; using namespace vips; char *Watermark(string type, char *BufferData, size_t BufferLength, - map Arguments, size_t *DataSize) { + map Arguments, size_t *DataSize) { string water = MAP_GET(Arguments, "water", string); int gravity = MAP_GET(Arguments, "gravity", int); diff --git a/natives/watermark.h b/natives/watermark.h index f67d916..338a61a 100644 --- a/natives/watermark.h +++ b/natives/watermark.h @@ -1,11 +1,9 @@ #pragma once -#include +#include "common.h" #include -#include -using std::any; using std::map; using std::string; -char* Watermark(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file +char* Watermark(string type, char* BufferData, size_t BufferLength, map Arguments, size_t* DataSize); \ No newline at end of file