diff --git a/CMakeLists.txt b/CMakeLists.txt index 0953b3a0..e44861fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,49 +5,49 @@ include(FindPkgConfig) include(FetchContent) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(IMAGE_SOURCE_FILES natives/blur.cc - natives/bounce.cc - natives/caption.cc - natives/caption2.cc - natives/circle.cc - natives/colors.cc - natives/commands.h - natives/common.cc - natives/common.h - natives/crop.cc - natives/deepfry.cc - natives/distort.cc - natives/fade.cc - natives/flag.cc - natives/flip.cc - natives/freeze.cc - natives/gamexplain.cc - natives/globe.cc - natives/homebrew.cc - natives/invert.cc - natives/jpeg.cc - natives/meme.cc - natives/mirror.cc - natives/motivate.cc - natives/reddit.cc - natives/resize.cc - natives/reverse.cc - natives/scott.cc - natives/slide.cc - natives/snapchat.cc - natives/sonic.cc - natives/speed.cc - natives/spin.cc - natives/spotify.cc - natives/squish.cc - natives/swirl.cc - natives/tile.cc - natives/togif.cc - natives/uncanny.cc - natives/uncaption.cc - natives/wall.cc - natives/watermark.cc - natives/whisper.cc) +set(IMAGE_SOURCE_FILES natives/image/blur.cc + natives/image/bounce.cc + natives/image/caption.cc + natives/image/caption2.cc + natives/image/circle.cc + natives/image/colors.cc + natives/image/commands.h + natives/image/common.cc + natives/image/common.h + natives/image/crop.cc + natives/image/deepfry.cc + natives/image/distort.cc + natives/image/fade.cc + natives/image/flag.cc + natives/image/flip.cc + natives/image/freeze.cc + natives/image/gamexplain.cc + natives/image/globe.cc + natives/image/homebrew.cc + natives/image/invert.cc + natives/image/jpeg.cc + natives/image/meme.cc + natives/image/mirror.cc + natives/image/motivate.cc + natives/image/reddit.cc + natives/image/resize.cc + natives/image/reverse.cc + natives/image/scott.cc + natives/image/slide.cc + natives/image/snapchat.cc + natives/image/sonic.cc + natives/image/speed.cc + natives/image/spin.cc + natives/image/spotify.cc + natives/image/squish.cc + natives/image/swirl.cc + natives/image/tile.cc + natives/image/togif.cc + natives/image/uncanny.cc + natives/image/uncaption.cc + natives/image/wall.cc + natives/image/watermark.cc + natives/image/whisper.cc) if (APPLE) set(WITH_ZXING_DEFAULT OFF) @@ -62,11 +62,11 @@ option(WITH_BACKWARD "Build with backward-cpp, prints a backtrace on crash/abort option(WITH_CLI "Build the CLI interface" OFF) if (WITH_MAGICK) - list(APPEND IMAGE_SOURCE_FILES natives/magik.cc) + list(APPEND IMAGE_SOURCE_FILES natives/image/magik.cc) endif() if (WITH_ZXING) - list(APPEND IMAGE_SOURCE_FILES natives/qr.cc) + list(APPEND IMAGE_SOURCE_FILES natives/image/qr.cc) endif() set(SOURCE_FILES "${IMAGE_SOURCE_FILES}") diff --git a/natives/cli/cli.cc b/natives/cli/cli.cc index 524a986f..adfad7e2 100644 --- a/natives/cli/cli.cc +++ b/natives/cli/cli.cc @@ -107,12 +107,12 @@ void printHelp() { std::cerr << "Available functions:" << std::endl; bool started = false; - for (auto cmd : esmb::FunctionMap) { + for (auto cmd : esmb::Image::FunctionMap) { if (started) std::cerr << ", "; std::cerr << cmd.first; started = true; } - for (auto cmd : esmb::NoInputFunctionMap) { + for (auto cmd : esmb::Image::NoInputFunctionMap) { if (started) std::cerr << ", "; std::cerr << cmd.first; started = true; @@ -134,8 +134,8 @@ int main(int argc, char *argv[]) { } std::string function = args.args[1]; - bool isInputFunc = MapContainsKey(esmb::FunctionMap, function); - bool isNoInputFunc = MapContainsKey(esmb::NoInputFunctionMap, function); + bool isInputFunc = MapContainsKey(esmb::Image::FunctionMap, function); + bool isNoInputFunc = MapContainsKey(esmb::Image::NoInputFunctionMap, function); if ((!isInputFunc && !isNoInputFunc) || (isInputFunc && args.args.size() < 4)) { printHelp(); return 1; @@ -145,8 +145,8 @@ int main(int argc, char *argv[]) { args.flags["basePath"] = std::filesystem::current_path().string() + "/"; } - if (MapContainsKey(esmb::FunctionArgsMap, function)) { - FunctionArgs *funcArgs = esmb::FunctionArgsMap.at(function); + if (MapContainsKey(esmb::Image::FunctionArgsMap, function)) { + FunctionArgs *funcArgs = esmb::Image::FunctionArgsMap.at(function); for (auto arg : *funcArgs) { if (!MapContainsKey(args.flags, arg.first)) { if (arg.second.required) { diff --git a/natives/commands.h b/natives/commands.h deleted file mode 100644 index 896613d9..00000000 --- a/natives/commands.h +++ /dev/null @@ -1,112 +0,0 @@ -#pragma once - -#include "common/argmap.h" -#include - -struct CmdOutput { - char *buf; - size_t length; -}; - -struct FunctionArg { - std::type_index type; - bool required; -}; - -typedef const std::map FunctionArgs; - -// Vultu: These are both bad, but I wanted to clean up code at least a little -#define declare_input_func(NAME) \ - CmdOutput NAME(const std::string &type, std::string &outType, const char *bufferData, size_t bufferLength, \ - esmb::ArgumentMap arguments, bool *shouldKill) -#define declare_noinput_func(NAME) \ - CmdOutput NAME(const std::string &type, std::string &outType, esmb::ArgumentMap arguments, bool *shouldKill) -#define declare_input_args(NAME) extern FunctionArgs NAME; - -// Declare our Input Functions -declare_input_func(Blur); -declare_input_func(Bounce); -declare_input_func(Caption); -declare_input_func(CaptionTwo); -declare_input_func(Circle); -declare_input_func(Colors); -declare_input_func(Crop); -declare_input_func(Deepfry); -declare_input_func(Distort); -declare_input_func(Fade); -declare_input_func(Flag); -declare_input_func(Flip); -declare_input_func(Freeze); -declare_input_func(Gamexplain); -declare_input_func(Globe); -declare_input_func(Invert); -declare_input_func(Jpeg); -#if MAGICK_ENABLED -declare_input_func(Magik); -#endif -declare_input_func(Meme); -declare_input_func(Mirror); -declare_input_func(Motivate); -#if ZXING_ENABLED -declare_input_func(QrRead); -#endif -declare_input_func(Reddit); -declare_input_func(Resize); -declare_input_func(Reverse); -declare_input_func(Scott); -declare_input_func(Slide); -declare_input_func(Snapchat); -declare_input_func(Speed); -declare_input_func(Spin); -declare_input_func(Spotify); -declare_input_func(Squish); -declare_input_func(Swirl); -declare_input_func(Tile); -declare_input_func(ToGif); -declare_input_func(Uncanny); -declare_input_func(Uncaption); -declare_input_func(Wall); -declare_input_func(Watermark); -declare_input_func(Whisper); - -// Declare our No-Input Functions - -declare_noinput_func(Homebrew); -#if ZXING_ENABLED -declare_noinput_func(QrCreate); -#endif -declare_noinput_func(Sonic); - -// Declare our Input Args -declare_input_args(BlurArgs); -declare_input_args(CaptionArgs); -declare_input_args(CaptionTwoArgs); -declare_input_args(ColorsArgs); -declare_input_args(DistortArgs); -declare_input_args(FadeArgs); -declare_input_args(FlagArgs); -declare_input_args(FlipArgs); -declare_input_args(FreezeArgs); -declare_input_args(GamexplainArgs); -declare_input_args(GlobeArgs); -declare_input_args(HomebrewArgs); -declare_input_args(JpegArgs); -declare_input_args(MemeArgs); -declare_input_args(MirrorArgs); -declare_input_args(MotivateArgs); -#if ZXING_ENABLED -declare_input_args(QrCreateArgs); -#endif -declare_input_args(RedditArgs); -declare_input_args(ResizeArgs); -declare_input_args(ReverseArgs); -declare_input_args(ScottArgs); -declare_input_args(SlideArgs); -declare_input_args(SnapchatArgs); -declare_input_args(SonicArgs); -declare_input_args(SpeedArgs); -declare_input_args(SpotifyArgs); -declare_input_args(UncannyArgs); -declare_input_args(UncaptionArgs); -declare_input_args(WatermarkArgs); -declare_input_args(WhisperArgs); diff --git a/natives/common/maps.h b/natives/common/maps.h index a1fc9fc9..aee70b2e 100644 --- a/natives/common/maps.h +++ b/natives/common/maps.h @@ -1,98 +1,100 @@ -#include "../commands.h" +#include "../image/commands.h" #include "argmap.h" namespace esmb { - const std::map - FunctionMap = { - {"blur", &Blur }, - {"bounce", &Bounce }, - {"caption", &Caption }, - {"captionTwo", &CaptionTwo}, - {"circle", &Circle }, - {"colors", &Colors }, - {"crop", &Crop }, - {"deepfry", &Deepfry }, - {"distort", &Distort }, - {"fade", &Fade }, - {"flag", &Flag }, - {"flip", &Flip }, - {"freeze", &Freeze }, - {"gamexplain", &Gamexplain}, - {"globe", &Globe }, - {"invert", &Invert }, - {"jpeg", &Jpeg }, + namespace Image { + const std::map + FunctionMap = { + {"blur", &Blur }, + {"bounce", &Bounce }, + {"caption", &Caption }, + {"captionTwo", &CaptionTwo}, + {"circle", &Circle }, + {"colors", &Colors }, + {"crop", &Crop }, + {"deepfry", &Deepfry }, + {"distort", &Distort }, + {"fade", &Fade }, + {"flag", &Flag }, + {"flip", &Flip }, + {"freeze", &Freeze }, + {"gamexplain", &Gamexplain}, + {"globe", &Globe }, + {"invert", &Invert }, + {"jpeg", &Jpeg }, #ifdef MAGICK_ENABLED - {"magik", &Magik }, + {"magik", &Magik }, #endif - {"meme", &Meme }, - {"mirror", &Mirror }, - {"motivate", &Motivate }, + {"meme", &Meme }, + {"mirror", &Mirror }, + {"motivate", &Motivate }, #ifdef ZXING_ENABLED - {"qrread", &QrRead }, + {"qrread", &QrRead }, #endif - {"reddit", &Reddit }, - {"resize", &Resize }, - {"reverse", &Reverse }, - {"scott", &Scott }, - {"slide", &Slide }, - {"snapchat", &Snapchat }, - {"speed", &Speed }, - {"spin", &Spin }, - {"spotify", &Spotify }, - {"squish", &Squish }, - {"swirl", &Swirl }, - {"tile", &Tile }, - {"togif", &ToGif }, - {"uncanny", &Uncanny }, - {"uncaption", &Uncaption }, - {"wall", &Wall }, - {"watermark", &Watermark }, - {"whisper", &Whisper } - }; + {"reddit", &Reddit }, + {"resize", &Resize }, + {"reverse", &Reverse }, + {"scott", &Scott }, + {"slide", &Slide }, + {"snapchat", &Snapchat }, + {"speed", &Speed }, + {"spin", &Spin }, + {"spotify", &Spotify }, + {"squish", &Squish }, + {"swirl", &Swirl }, + {"tile", &Tile }, + {"togif", &ToGif }, + {"uncanny", &Uncanny }, + {"uncaption", &Uncaption }, + {"wall", &Wall }, + {"watermark", &Watermark }, + {"whisper", &Whisper } + }; - const std::map - NoInputFunctionMap = { - {"homebrew", &Homebrew}, + const std::map + NoInputFunctionMap = { + {"homebrew", &Homebrew}, #if ZXING_ENABLED - {"qrcreate", &QrCreate}, + {"qrcreate", &QrCreate}, #endif - {"sonic", &Sonic } - }; + {"sonic", &Sonic } + }; - const std::map FunctionArgsMap = { - {"blur", &BlurArgs }, - {"caption", &CaptionArgs }, - {"captionTwo", &CaptionTwoArgs}, - {"colors", &ColorsArgs }, - {"distort", &DistortArgs }, - {"fade", &FadeArgs }, - {"flag", &FlagArgs }, - {"flip", &FlipArgs }, - {"freeze", &FreezeArgs }, - {"gamexplain", &GamexplainArgs}, - {"globe", &GlobeArgs }, - {"homebrew", &HomebrewArgs }, - {"jpeg", &JpegArgs }, - {"meme", &MemeArgs }, - {"mirror", &MirrorArgs }, - {"motivate", &MotivateArgs }, + const std::map FunctionArgsMap = { + {"blur", &BlurArgs }, + {"caption", &CaptionArgs }, + {"captionTwo", &CaptionTwoArgs}, + {"colors", &ColorsArgs }, + {"distort", &DistortArgs }, + {"fade", &FadeArgs }, + {"flag", &FlagArgs }, + {"flip", &FlipArgs }, + {"freeze", &FreezeArgs }, + {"gamexplain", &GamexplainArgs}, + {"globe", &GlobeArgs }, + {"homebrew", &HomebrewArgs }, + {"jpeg", &JpegArgs }, + {"meme", &MemeArgs }, + {"mirror", &MirrorArgs }, + {"motivate", &MotivateArgs }, #if ZXING_ENABLED - {"qrcreate", &QrCreateArgs }, + {"qrcreate", &QrCreateArgs }, #endif - {"reddit", &RedditArgs }, - {"resize", &ResizeArgs }, - {"reverse", &ReverseArgs }, - {"scott", &ScottArgs }, - {"slide", &SlideArgs }, - {"snapchat", &SnapchatArgs }, - {"sonic", &SonicArgs }, - {"speed", &SpeedArgs }, - {"spotify", &SpotifyArgs }, - {"uncanny", &UncannyArgs }, - {"uncaption", &UncaptionArgs }, - {"watermark", &WatermarkArgs }, - {"whisper", &WhisperArgs } - }; + {"reddit", &RedditArgs }, + {"resize", &ResizeArgs }, + {"reverse", &ReverseArgs }, + {"scott", &ScottArgs }, + {"slide", &SlideArgs }, + {"snapchat", &SnapchatArgs }, + {"sonic", &SonicArgs }, + {"speed", &SpeedArgs }, + {"spotify", &SpotifyArgs }, + {"uncanny", &UncannyArgs }, + {"uncaption", &UncaptionArgs }, + {"watermark", &WatermarkArgs }, + {"whisper", &WhisperArgs } + }; + } // namespace Image } // namespace esmb diff --git a/natives/generic/media.cc b/natives/generic/media.cc index fc28f562..3fe4c7a3 100644 --- a/natives/generic/media.cc +++ b/natives/generic/media.cc @@ -21,16 +21,16 @@ esmb_media_result *esmb_media_process(const char *command, esmb::ArgumentMap arg CmdOutput outData; if (length != 0) { - if (MapContainsKey(esmb::FunctionMap, command)) { - outData = esmb::FunctionMap.at(command)(type, outType, data, length, args, NULL); + if (MapContainsKey(esmb::Image::FunctionMap, command)) { + outData = esmb::Image::FunctionMap.at(command)(type, outType, data, length, args, NULL); } else { // Vultu: I don't think we will ever be here, but just in case we need a descriptive error std::string cmd(command); throw "Error: \"FunctionMap\" does not contain \"" + cmd + "\", which was requested because \"length\" parameter was not 0."; } } else { - if (MapContainsKey(esmb::NoInputFunctionMap, command)) { - outData = esmb::NoInputFunctionMap.at(command)(type, outType, args, NULL); + if (MapContainsKey(esmb::Image::NoInputFunctionMap, command)) { + outData = esmb::Image::NoInputFunctionMap.at(command)(type, outType, args, NULL); } else { std::string cmd(command); throw "Error: \"NoInputFunctionMap\" does not contain \"" + cmd + diff --git a/natives/blur.cc b/natives/image/blur.cc similarity index 81% rename from natives/blur.cc rename to natives/image/blur.cc index 6e167a12..dd5e38b9 100644 --- a/natives/blur.cc +++ b/natives/image/blur.cc @@ -2,16 +2,15 @@ #include #include "common.h" -#include "common/argmap.h" using namespace std; using namespace vips; -FunctionArgs BlurArgs = { +FunctionArgs esmb::Image::BlurArgs = { {"sharp", {typeid(bool), false}} }; -CmdOutput Blur(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Blur(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool sharp = GetArgumentWithFallback(arguments, "sharp", false); diff --git a/natives/bounce.cc b/natives/image/bounce.cc similarity index 93% rename from natives/bounce.cc rename to natives/image/bounce.cc index 462a2376..595c8843 100644 --- a/natives/bounce.cc +++ b/natives/image/bounce.cc @@ -6,7 +6,7 @@ using namespace std; using namespace vips; -CmdOutput Bounce(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Bounce(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, true, true)) .colourspace(VIPS_INTERPRETATION_sRGB); diff --git a/natives/caption.cc b/natives/image/caption.cc similarity index 94% rename from natives/caption.cc rename to natives/image/caption.cc index 5800d505..466f3144 100644 --- a/natives/caption.cc +++ b/natives/image/caption.cc @@ -5,13 +5,13 @@ using namespace std; using namespace vips; -FunctionArgs CaptionArgs = { +FunctionArgs esmb::Image::CaptionArgs = { {"caption", {typeid(string), true} }, {"font", {typeid(string), false}}, {"basePath", {typeid(string), true} } }; -CmdOutput Caption(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Caption(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string caption = GetArgument(arguments, "caption"); string font = GetArgumentWithFallback(arguments, "font", "futura"); diff --git a/natives/caption2.cc b/natives/image/caption2.cc similarity index 94% rename from natives/caption2.cc rename to natives/image/caption2.cc index d7adffc0..2da5212f 100644 --- a/natives/caption2.cc +++ b/natives/image/caption2.cc @@ -6,14 +6,14 @@ using namespace std; using namespace vips; -FunctionArgs CaptionTwoArgs = { +FunctionArgs esmb::Image::CaptionTwoArgs = { {"top", {typeid(bool), false} }, {"caption", {typeid(string), true} }, {"font", {typeid(string), false}}, {"basePath", {typeid(string), true} } }; -CmdOutput CaptionTwo(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::CaptionTwo(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool top = GetArgumentWithFallback(arguments, "top", false); string caption = GetArgument(arguments, "caption"); diff --git a/natives/circle.cc b/natives/image/circle.cc similarity index 95% rename from natives/circle.cc rename to natives/image/circle.cc index 8d386c2a..ac6bcfd6 100644 --- a/natives/circle.cc +++ b/natives/image/circle.cc @@ -29,7 +29,7 @@ VImage rectangularMap(int width, int height) { return index; } -CmdOutput Circle(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Circle(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, false, false)); diff --git a/natives/colors.cc b/natives/image/colors.cc similarity index 89% rename from natives/colors.cc rename to natives/image/colors.cc index f47edf1c..84a64cf6 100644 --- a/natives/colors.cc +++ b/natives/image/colors.cc @@ -6,14 +6,14 @@ using namespace std; using namespace vips; -FunctionArgs ColorsArgs = { +FunctionArgs esmb::Image::ColorsArgs = { {"color", {typeid(string), true}}, {"shift", {typeid(int), false} } }; 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); -CmdOutput Colors(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Colors(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string color = GetArgument(arguments, "color"); int shift = GetArgumentWithFallback(arguments, "shift", 0); diff --git a/natives/image/commands.h b/natives/image/commands.h new file mode 100644 index 00000000..dd798432 --- /dev/null +++ b/natives/image/commands.h @@ -0,0 +1,93 @@ +#pragma once + +#include "../shared.h" + +namespace esmb::Image { + // Declare our Input Functions + declare_input_func(Blur); + declare_input_func(Bounce); + declare_input_func(Caption); + declare_input_func(CaptionTwo); + declare_input_func(Circle); + declare_input_func(Colors); + declare_input_func(Crop); + declare_input_func(Deepfry); + declare_input_func(Distort); + declare_input_func(Fade); + declare_input_func(Flag); + declare_input_func(Flip); + declare_input_func(Freeze); + declare_input_func(Gamexplain); + declare_input_func(Globe); + declare_input_func(Invert); + declare_input_func(Jpeg); +#if MAGICK_ENABLED + declare_input_func(Magik); +#endif + declare_input_func(Meme); + declare_input_func(Mirror); + declare_input_func(Motivate); +#if ZXING_ENABLED + declare_input_func(QrRead); +#endif + declare_input_func(Reddit); + declare_input_func(Resize); + declare_input_func(Reverse); + declare_input_func(Scott); + declare_input_func(Slide); + declare_input_func(Snapchat); + declare_input_func(Speed); + declare_input_func(Spin); + declare_input_func(Spotify); + declare_input_func(Squish); + declare_input_func(Swirl); + declare_input_func(Tile); + declare_input_func(ToGif); + declare_input_func(Uncanny); + declare_input_func(Uncaption); + declare_input_func(Wall); + declare_input_func(Watermark); + declare_input_func(Whisper); + + // Declare our No-Input Functions + + declare_noinput_func(Homebrew); +#if ZXING_ENABLED + declare_noinput_func(QrCreate); +#endif + declare_noinput_func(Sonic); + + // Declare our Input Args + declare_input_args(BlurArgs); + declare_input_args(CaptionArgs); + declare_input_args(CaptionTwoArgs); + declare_input_args(ColorsArgs); + declare_input_args(DistortArgs); + declare_input_args(FadeArgs); + declare_input_args(FlagArgs); + declare_input_args(FlipArgs); + declare_input_args(FreezeArgs); + declare_input_args(GamexplainArgs); + declare_input_args(GlobeArgs); + declare_input_args(HomebrewArgs); + declare_input_args(JpegArgs); + declare_input_args(MemeArgs); + declare_input_args(MirrorArgs); + declare_input_args(MotivateArgs); +#if ZXING_ENABLED + declare_input_args(QrCreateArgs); +#endif + declare_input_args(RedditArgs); + declare_input_args(ResizeArgs); + declare_input_args(ReverseArgs); + declare_input_args(ScottArgs); + declare_input_args(SlideArgs); + declare_input_args(SnapchatArgs); + declare_input_args(SonicArgs); + declare_input_args(SpeedArgs); + declare_input_args(SpotifyArgs); + declare_input_args(UncannyArgs); + declare_input_args(UncaptionArgs); + declare_input_args(WatermarkArgs); + declare_input_args(WhisperArgs); +} // namespace esmb::Image diff --git a/natives/common.cc b/natives/image/common.cc similarity index 90% rename from natives/common.cc rename to natives/image/common.cc index 0bdfc03f..1342fccc 100644 --- a/natives/common.cc +++ b/natives/image/common.cc @@ -1,3 +1,4 @@ +#include #include #include "common.h" @@ -69,8 +70,3 @@ void SetupTimeoutCallback(vips::VImage image, bool *shouldKill) { g_signal_connect(img, "eval", G_CALLBACK(TimeoutCallback), cbData); vips_image_set_progress(img, true); } - -uint32_t readUint32LE(unsigned char *buffer) { - return static_cast(buffer[0]) | (static_cast(buffer[1]) << 8) | - (static_cast(buffer[2]) << 16) | (static_cast(buffer[3]) << 24); -} diff --git a/natives/common.h b/natives/image/common.h similarity index 90% rename from natives/common.h rename to natives/image/common.h index f0045dd6..28110f5b 100644 --- a/natives/common.h +++ b/natives/image/common.h @@ -3,13 +3,10 @@ #include #include -#include -#include #include #include #include #include -#include using std::map; using std::string; @@ -22,8 +19,6 @@ typedef struct { } CallbackData; #define IMG_TIMEOUT 600 -uint32_t readUint32LE(unsigned char *buffer); - #include "commands.h" void LoadFonts(string basePath); diff --git a/natives/crop.cc b/natives/image/crop.cc similarity index 93% rename from natives/crop.cc rename to natives/image/crop.cc index 2c202212..c4cc5f9c 100644 --- a/natives/crop.cc +++ b/natives/image/crop.cc @@ -6,7 +6,7 @@ using namespace std; using namespace vips; -CmdOutput Crop(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Crop(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, true, false)); diff --git a/natives/deepfry.cc b/natives/image/deepfry.cc similarity index 94% rename from natives/deepfry.cc rename to natives/image/deepfry.cc index 3735e3d0..02161f44 100644 --- a/natives/deepfry.cc +++ b/natives/image/deepfry.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -CmdOutput Deepfry(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Deepfry(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, true, false)); diff --git a/natives/distort.cc b/natives/image/distort.cc similarity index 90% rename from natives/distort.cc rename to natives/image/distort.cc index 54ab5a6f..d0e39ec7 100644 --- a/natives/distort.cc +++ b/natives/image/distort.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs DistortArgs = { +FunctionArgs esmb::Image::DistortArgs = { {"mapName", {typeid(string), true}}, {"basePath", {typeid(string), true}} }; -CmdOutput Distort(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Distort(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string mapName = GetArgument(arguments, "mapName"); string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/fade.cc b/natives/image/fade.cc similarity index 92% rename from natives/fade.cc rename to natives/image/fade.cc index 2af11332..c8c3ea7a 100644 --- a/natives/fade.cc +++ b/natives/image/fade.cc @@ -7,11 +7,11 @@ using namespace std; using namespace vips; -FunctionArgs FadeArgs = { +FunctionArgs esmb::Image::FadeArgs = { {"alpha", {typeid(bool), false}} }; -CmdOutput Fade(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Fade(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool alpha = GetArgumentWithFallback(arguments, "alpha", false); diff --git a/natives/flag.cc b/natives/image/flag.cc similarity index 91% rename from natives/flag.cc rename to natives/image/flag.cc index de9024c9..cc95303b 100644 --- a/natives/flag.cc +++ b/natives/image/flag.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs FlagArgs = { +FunctionArgs esmb::Image::FlagArgs = { {"overlay", {typeid(string), true}}, {"basePath", {typeid(string), true}} }; -CmdOutput Flag(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Flag(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string overlay = GetArgument(arguments, "overlay"); string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/flip.cc b/natives/image/flip.cc similarity index 90% rename from natives/flip.cc rename to natives/image/flip.cc index 998fe9de..1136bf1c 100644 --- a/natives/flip.cc +++ b/natives/image/flip.cc @@ -5,11 +5,11 @@ using namespace std; using namespace vips; -FunctionArgs FlipArgs = { +FunctionArgs esmb::Image::FlipArgs = { {"flop", {typeid(bool), false}} }; -CmdOutput Flip(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Flip(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool flop = GetArgumentWithFallback(arguments, "flop", false); diff --git a/natives/freeze.cc b/natives/image/freeze.cc similarity index 96% rename from natives/freeze.cc rename to natives/image/freeze.cc index c5cfe55b..f3362ccd 100644 --- a/natives/freeze.cc +++ b/natives/image/freeze.cc @@ -6,7 +6,7 @@ using namespace std; using namespace vips; -FunctionArgs FreezeArgs = { +FunctionArgs esmb::Image::FreezeArgs = { {"loop", {typeid(bool), false}}, {"frame", {typeid(int), false} } }; @@ -30,7 +30,7 @@ char *vipsTrim(const char *data, size_t length, size_t &dataSize, int frame, str return buf; } -CmdOutput Freeze(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Freeze(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool loop = GetArgumentWithFallback(arguments, "loop", false); int frame = GetArgumentWithFallback(arguments, "frame", -1); diff --git a/natives/gamexplain.cc b/natives/image/gamexplain.cc similarity index 91% rename from natives/gamexplain.cc rename to natives/image/gamexplain.cc index d4c3898b..fca5b6dc 100644 --- a/natives/gamexplain.cc +++ b/natives/image/gamexplain.cc @@ -5,11 +5,11 @@ using namespace std; using namespace vips; -FunctionArgs GamexplainArgs = { +FunctionArgs esmb::Image::GamexplainArgs = { {"basePath", {typeid(string), true}} }; -CmdOutput Gamexplain(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Gamexplain(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/globe.cc b/natives/image/globe.cc similarity index 94% rename from natives/globe.cc rename to natives/image/globe.cc index bc6a36a3..6f4f3388 100644 --- a/natives/globe.cc +++ b/natives/image/globe.cc @@ -5,11 +5,11 @@ using namespace std; using namespace vips; -FunctionArgs GlobeArgs = { +FunctionArgs esmb::Image::GlobeArgs = { {"basePath", {typeid(string), true}} }; -CmdOutput Globe(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Globe(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/homebrew.cc b/natives/image/homebrew.cc similarity index 89% rename from natives/homebrew.cc rename to natives/image/homebrew.cc index edf5c011..9276af3b 100644 --- a/natives/homebrew.cc +++ b/natives/image/homebrew.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs HomebrewArgs = { +FunctionArgs esmb::Image::HomebrewArgs = { {"caption", {typeid(string), true}}, {"basePath", {typeid(string), true}} }; -CmdOutput Homebrew([[maybe_unused]] const string &type, string &outType, esmb::ArgumentMap arguments, +CmdOutput esmb::Image::Homebrew([[maybe_unused]] const string &type, string &outType, esmb::ArgumentMap arguments, bool *shouldKill) { string caption = GetArgument(arguments, "caption"); string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/invert.cc b/natives/image/invert.cc similarity index 86% rename from natives/invert.cc rename to natives/image/invert.cc index 3a65c244..dcef4a58 100644 --- a/natives/invert.cc +++ b/natives/image/invert.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -CmdOutput Invert(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Invert(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, true, false)); diff --git a/natives/jpeg.cc b/natives/image/jpeg.cc similarity index 94% rename from natives/jpeg.cc rename to natives/image/jpeg.cc index 1817e305..709cfa29 100644 --- a/natives/jpeg.cc +++ b/natives/image/jpeg.cc @@ -5,11 +5,11 @@ using namespace std; using namespace vips; -FunctionArgs JpegArgs = { +FunctionArgs esmb::Image::JpegArgs = { {"quality", {typeid(int), false}} }; -CmdOutput Jpeg(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Jpeg(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { int quality = GetArgumentWithFallback(arguments, "quality", 1); diff --git a/natives/magik.cc b/natives/image/magik.cc similarity index 51% rename from natives/magik.cc rename to natives/image/magik.cc index 472dfd78..f462cac1 100644 --- a/natives/magik.cc +++ b/natives/image/magik.cc @@ -8,17 +8,17 @@ #include "common.h" using namespace std; -using namespace Magick; -CmdOutput Magik([[maybe_unused]] const string &type, string &outType, const char *bufferdata, size_t bufferLength, - [[maybe_unused]] esmb::ArgumentMap arguments, [[maybe_unused]] bool *shouldKill) { - Blob blob; +CmdOutput esmb::Image::Magik([[maybe_unused]] const string &type, string &outType, const char *bufferdata, + size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, + [[maybe_unused]] bool *shouldKill) { + Magick::Blob blob; - list frames; - list coalesced; - list blurred; + list frames; + list coalesced; + list blurred; try { - readImages(&frames, Blob(bufferdata, bufferLength)); + readImages(&frames, Magick::Blob(bufferdata, bufferLength)); } catch (Magick::WarningCoder &warning) { cerr << "Coder Warning: " << warning.what() << endl; } catch (Magick::Warning &warning) { @@ -26,10 +26,10 @@ CmdOutput Magik([[maybe_unused]] const string &type, string &outType, const char } coalesceImages(&coalesced, frames.begin(), frames.end()); - for (Image &image : coalesced) { - image.scale(Geometry("350x350")); - image.liquidRescale(Geometry("175x175")); - image.liquidRescale(Geometry("350x350")); + for (Magick::Image &image : coalesced) { + image.scale(Magick::Geometry("350x350")); + image.liquidRescale(Magick::Geometry("175x175")); + image.liquidRescale(Magick::Geometry("350x350")); image.magick(outType); blurred.push_back(image); } @@ -37,8 +37,8 @@ CmdOutput Magik([[maybe_unused]] const string &type, string &outType, const char optimizeTransparency(blurred.begin(), blurred.end()); if (outType == "gif") { - for (Image &image : blurred) { - image.quantizeDitherMethod(FloydSteinbergDitherMethod); + for (Magick::Image &image : blurred) { + image.quantizeDitherMethod(Magick::FloydSteinbergDitherMethod); image.quantize(); } } diff --git a/natives/meme.cc b/natives/image/meme.cc similarity index 96% rename from natives/meme.cc rename to natives/image/meme.cc index 50a5b956..a2911709 100644 --- a/natives/meme.cc +++ b/natives/image/meme.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -FunctionArgs MemeArgs = { +FunctionArgs esmb::Image::MemeArgs = { {"topText", {typeid(string), false}}, {"bottomText", {typeid(string), false}}, {"font", {typeid(string), false}}, @@ -28,7 +28,7 @@ VImage genText(string text, string font, const char *fontfile, int width, VImage return outline.composite2(in, VIPS_BLEND_MODE_OVER); } -CmdOutput Meme(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Meme(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string top = GetArgumentWithFallback(arguments, "topText", ""); string bottom = GetArgumentWithFallback(arguments, "bottomText", ""); diff --git a/natives/mirror.cc b/natives/image/mirror.cc similarity index 94% rename from natives/mirror.cc rename to natives/image/mirror.cc index 64824f6a..4d75c35b 100644 --- a/natives/mirror.cc +++ b/natives/image/mirror.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs MirrorArgs = { +FunctionArgs esmb::Image::MirrorArgs = { {"vertical", {typeid(bool), false}}, {"first", {typeid(bool), false}}, }; -CmdOutput Mirror(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Mirror(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool vertical = GetArgumentWithFallback(arguments, "vertical", false); bool first = GetArgumentWithFallback(arguments, "first", false); diff --git a/natives/motivate.cc b/natives/image/motivate.cc similarity index 96% rename from natives/motivate.cc rename to natives/image/motivate.cc index d2e97bdd..7a0f23bd 100644 --- a/natives/motivate.cc +++ b/natives/image/motivate.cc @@ -5,14 +5,14 @@ using namespace std; using namespace vips; -FunctionArgs MotivateArgs = { +FunctionArgs esmb::Image::MotivateArgs = { {"topText", {typeid(string), false}}, {"bottomText", {typeid(string), false}}, {"font", {typeid(string), false}}, {"basePath", {typeid(string), true} } }; -CmdOutput Motivate(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Motivate(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string top_text = GetArgumentWithFallback(arguments, "topText", ""); string bottom_text = GetArgumentWithFallback(arguments, "bottomText", ""); diff --git a/natives/qr.cc b/natives/image/qr.cc similarity index 89% rename from natives/qr.cc rename to natives/image/qr.cc index 02e354eb..9d470f36 100644 --- a/natives/qr.cc +++ b/natives/image/qr.cc @@ -10,11 +10,11 @@ #include "common.h" -FunctionArgs QrCreateArgs = { +FunctionArgs esmb::Image::QrCreateArgs = { {"text", {typeid(string), true}} }; -CmdOutput QrCreate([[maybe_unused]] const string &type, string &outType, esmb::ArgumentMap arguments, +CmdOutput esmb::Image::QrCreate([[maybe_unused]] const string &type, string &outType, esmb::ArgumentMap arguments, [[maybe_unused]] bool *shouldKill) { string text = GetArgument(arguments, "text"); @@ -39,7 +39,7 @@ CmdOutput QrCreate([[maybe_unused]] const string &type, string &outType, esmb::A return {buf, dataSize}; } -CmdOutput QrRead([[maybe_unused]] const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::QrRead([[maybe_unused]] const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, [[maybe_unused]] bool *shouldKill) { vips::VOption *options = vips::VImage::option()->set("access", "sequential"); diff --git a/natives/reddit.cc b/natives/image/reddit.cc similarity index 93% rename from natives/reddit.cc rename to natives/image/reddit.cc index 69b2b79b..5b05c1e1 100644 --- a/natives/reddit.cc +++ b/natives/image/reddit.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs RedditArgs = { +FunctionArgs esmb::Image::RedditArgs = { {"caption", {typeid(string), true}}, {"basePath", {typeid(string), true}} }; -CmdOutput Reddit(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Reddit(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string text = GetArgument(arguments, "caption"); string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/resize.cc b/natives/image/resize.cc similarity index 92% rename from natives/resize.cc rename to natives/image/resize.cc index 8c1659fd..3fc397f1 100644 --- a/natives/resize.cc +++ b/natives/image/resize.cc @@ -5,13 +5,13 @@ using namespace std; using namespace vips; -FunctionArgs ResizeArgs = { +FunctionArgs esmb::Image::ResizeArgs = { {"stretch", {typeid(bool), false}}, {"wide", {typeid(bool), false}}, {"amount", {typeid(int), false} } }; -CmdOutput Resize(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Resize(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool stretch = GetArgumentWithFallback(arguments, "stretch", false); bool wide = GetArgumentWithFallback(arguments, "wide", false); diff --git a/natives/reverse.cc b/natives/image/reverse.cc similarity index 92% rename from natives/reverse.cc rename to natives/image/reverse.cc index cddefd56..5700ca21 100644 --- a/natives/reverse.cc +++ b/natives/image/reverse.cc @@ -5,11 +5,11 @@ using namespace std; using namespace vips; -FunctionArgs ReverseArgs = { +FunctionArgs esmb::Image::ReverseArgs = { {"soos", {typeid(bool), false}} }; -CmdOutput Reverse([[maybe_unused]] const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Reverse([[maybe_unused]] const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool soos = GetArgumentWithFallback(arguments, "soos", false); diff --git a/natives/scott.cc b/natives/image/scott.cc similarity index 93% rename from natives/scott.cc rename to natives/image/scott.cc index ef86329c..84c5c191 100644 --- a/natives/scott.cc +++ b/natives/image/scott.cc @@ -5,11 +5,11 @@ using namespace std; using namespace vips; -FunctionArgs ScottArgs = { +FunctionArgs esmb::Image::ScottArgs = { {"basePath", {typeid(string), true}} }; -CmdOutput Scott(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Scott(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/slide.cc b/natives/image/slide.cc similarity index 92% rename from natives/slide.cc rename to natives/image/slide.cc index 89fd828e..85edfe86 100644 --- a/natives/slide.cc +++ b/natives/image/slide.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs SlideArgs = { +FunctionArgs esmb::Image::SlideArgs = { {"vertical", {typeid(bool), false}}, {"reverse", {typeid(bool), false}}, }; -CmdOutput Slide(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Slide(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool vertical = GetArgumentWithFallback(arguments, "vertical", false); bool reverse = GetArgumentWithFallback(arguments, "reverse", false); diff --git a/natives/snapchat.cc b/natives/image/snapchat.cc similarity index 94% rename from natives/snapchat.cc rename to natives/image/snapchat.cc index cf636433..20769c6b 100644 --- a/natives/snapchat.cc +++ b/natives/image/snapchat.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -FunctionArgs SnapchatArgs = { +FunctionArgs esmb::Image::SnapchatArgs = { {"caption", {typeid(string), true}}, {"pos", {typeid(float), false}}, {"basePath", {typeid(string), true}} @@ -13,7 +13,7 @@ FunctionArgs SnapchatArgs = { const vector zeroVec178 = {0, 0, 0, 178}; -CmdOutput Snapchat(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Snapchat(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string caption = GetArgument(arguments, "caption"); float pos = GetArgumentWithFallback(arguments, "pos", 0.565); diff --git a/natives/sonic.cc b/natives/image/sonic.cc similarity index 89% rename from natives/sonic.cc rename to natives/image/sonic.cc index 2ac9fb83..f42ce318 100644 --- a/natives/sonic.cc +++ b/natives/image/sonic.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs SonicArgs = { +FunctionArgs esmb::Image::SonicArgs = { {"text", {typeid(string), true}}, {"basePath", {typeid(string), true}} }; -CmdOutput Sonic([[maybe_unused]] const string &type, string &outType, esmb::ArgumentMap arguments, bool *shouldKill) { +CmdOutput esmb::Image::Sonic([[maybe_unused]] const string &type, string &outType, esmb::ArgumentMap arguments, bool *shouldKill) { string text = GetArgument(arguments, "text"); string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/speed.cc b/natives/image/speed.cc similarity index 96% rename from natives/speed.cc rename to natives/image/speed.cc index 6438f366..75dfebf9 100644 --- a/natives/speed.cc +++ b/natives/image/speed.cc @@ -6,7 +6,7 @@ using namespace std; using namespace vips; -FunctionArgs SpeedArgs = { +FunctionArgs esmb::Image::SpeedArgs = { {"slow", {typeid(bool), false}}, {"speed", {typeid(int), false} } }; @@ -43,7 +43,7 @@ char *vipsRemove(const char *data, size_t length, size_t &dataSize, int speed, s return buf; } -CmdOutput Speed([[maybe_unused]] const string &type, [[maybe_unused]] string &outType, const char *bufferdata, +CmdOutput esmb::Image::Speed([[maybe_unused]] const string &type, [[maybe_unused]] string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { bool slow = GetArgumentWithFallback(arguments, "slow", false); int speed = GetArgumentWithFallback(arguments, "speed", 2); diff --git a/natives/spin.cc b/natives/image/spin.cc similarity index 93% rename from natives/spin.cc rename to natives/image/spin.cc index b1e935e6..8b47d77d 100644 --- a/natives/spin.cc +++ b/natives/image/spin.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -CmdOutput Spin(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Spin(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, true, true)); diff --git a/natives/spotify.cc b/natives/image/spotify.cc similarity index 93% rename from natives/spotify.cc rename to natives/image/spotify.cc index 09b174c1..09e7469e 100644 --- a/natives/spotify.cc +++ b/natives/image/spotify.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs SpotifyArgs = { +FunctionArgs esmb::Image::SpotifyArgs = { {"caption", {typeid(string), true}}, {"basePath", {typeid(string), true}} }; -CmdOutput Spotify(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Spotify(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string text = GetArgument(arguments, "caption"); string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/squish.cc b/natives/image/squish.cc similarity index 93% rename from natives/squish.cc rename to natives/image/squish.cc index 9b4ef8a8..970211b8 100644 --- a/natives/squish.cc +++ b/natives/image/squish.cc @@ -7,7 +7,7 @@ using namespace std; using namespace vips; -CmdOutput Squish(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Squish(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, true, true)); diff --git a/natives/swirl.cc b/natives/image/swirl.cc similarity index 95% rename from natives/swirl.cc rename to natives/image/swirl.cc index f02f3ab3..84f42e7e 100644 --- a/natives/swirl.cc +++ b/natives/image/swirl.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -CmdOutput Swirl(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Swirl(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, false, false)); diff --git a/natives/tile.cc b/natives/image/tile.cc similarity index 93% rename from natives/tile.cc rename to natives/image/tile.cc index 7cda8409..0a81f046 100644 --- a/natives/tile.cc +++ b/natives/image/tile.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -CmdOutput Tile(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Tile(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, false, false)); diff --git a/natives/togif.cc b/natives/image/togif.cc similarity index 87% rename from natives/togif.cc rename to natives/image/togif.cc index cb6d9a19..bf560ce2 100644 --- a/natives/togif.cc +++ b/natives/image/togif.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -CmdOutput ToGif(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::ToGif(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { if (type == "gif") { char *data = reinterpret_cast(malloc(bufferLength)); diff --git a/natives/uncanny.cc b/natives/image/uncanny.cc similarity index 96% rename from natives/uncanny.cc rename to natives/image/uncanny.cc index fc4dc525..83ca5179 100644 --- a/natives/uncanny.cc +++ b/natives/image/uncanny.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -FunctionArgs UncannyArgs = { +FunctionArgs esmb::Image::UncannyArgs = { {"caption", {typeid(string), true} }, {"caption2", {typeid(string), true} }, {"font", {typeid(string), false}}, @@ -13,7 +13,7 @@ FunctionArgs UncannyArgs = { {"basePath", {typeid(string), true} } }; -CmdOutput Uncanny(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Uncanny(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string caption = GetArgument(arguments, "caption"); string caption2 = GetArgument(arguments, "caption2"); diff --git a/natives/uncaption.cc b/natives/image/uncaption.cc similarity index 90% rename from natives/uncaption.cc rename to natives/image/uncaption.cc index 44904ded..e3efb56d 100644 --- a/natives/uncaption.cc +++ b/natives/image/uncaption.cc @@ -5,11 +5,11 @@ using namespace std; using namespace vips; -FunctionArgs UncaptionArgs = { +FunctionArgs esmb::Image::UncaptionArgs = { {"tolerance", {typeid(float), false}}, }; -CmdOutput Uncaption(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Uncaption(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { float tolerance = GetArgumentWithFallback(arguments, "tolerance", 0.5); diff --git a/natives/wall.cc b/natives/image/wall.cc similarity index 95% rename from natives/wall.cc rename to natives/image/wall.cc index 55706b41..7bfa2152 100644 --- a/natives/wall.cc +++ b/natives/image/wall.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -CmdOutput Wall(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Wall(const string &type, string &outType, const char *bufferdata, size_t bufferLength, [[maybe_unused]] esmb::ArgumentMap arguments, bool *shouldKill) { VImage in = VImage::new_from_buffer(bufferdata, bufferLength, "", GetInputOptions(type, false, false)); if (!in.has_alpha()) in = in.bandjoin(255); diff --git a/natives/watermark.cc b/natives/image/watermark.cc similarity index 97% rename from natives/watermark.cc rename to natives/image/watermark.cc index 11ea105e..a0fc982c 100644 --- a/natives/watermark.cc +++ b/natives/image/watermark.cc @@ -5,7 +5,7 @@ using namespace std; using namespace vips; -FunctionArgs WatermarkArgs = { +FunctionArgs esmb::Image::WatermarkArgs = { {"water", {typeid(string), true}}, {"gravity", {typeid(int), true} }, {"resize", {typeid(bool), false} }, @@ -18,7 +18,7 @@ FunctionArgs WatermarkArgs = { {"basePath", {typeid(string), true}} }; -CmdOutput Watermark(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Watermark(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string water = GetArgument(arguments, "water"); int gravity = GetArgument(arguments, "gravity"); diff --git a/natives/whisper.cc b/natives/image/whisper.cc similarity index 93% rename from natives/whisper.cc rename to natives/image/whisper.cc index 59b74732..f28ba3c7 100644 --- a/natives/whisper.cc +++ b/natives/image/whisper.cc @@ -5,12 +5,12 @@ using namespace std; using namespace vips; -FunctionArgs WhisperArgs = { +FunctionArgs esmb::Image::WhisperArgs = { {"caption", {typeid(string), true}}, {"basePath", {typeid(string), true}} }; -CmdOutput Whisper(const string &type, string &outType, const char *bufferdata, size_t bufferLength, +CmdOutput esmb::Image::Whisper(const string &type, string &outType, const char *bufferdata, size_t bufferLength, esmb::ArgumentMap arguments, bool *shouldKill) { string caption = GetArgument(arguments, "caption"); string basePath = GetArgument(arguments, "basePath"); diff --git a/natives/node/media.cc b/natives/node/media.cc index 76855bc1..3fe9cab8 100644 --- a/natives/node/media.cc +++ b/natives/node/media.cc @@ -5,7 +5,7 @@ #include #endif -#include "../common.h" +#include "../shared.h" #include "worker.h" #if defined(WIN32) && defined(MAGICK_ENABLED) @@ -41,8 +41,8 @@ Napi::Value ProcessMedia(const Napi::CallbackInfo &info) { Arguments["togif"] = val.ToBoolean().Value(); } - if (MapContainsKey(esmb::FunctionArgsMap, command)) { - FunctionArgs *argTypes = esmb::FunctionArgsMap.at(command); + if (MapContainsKey(esmb::Image::FunctionArgsMap, command)) { + FunctionArgs *argTypes = esmb::Image::FunctionArgsMap.at(command); for (auto arg : *argTypes) { val = obj.Get(arg.first); if (val.IsEmpty() || val.IsUndefined() || val.IsNull()) continue; @@ -145,12 +145,12 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { Napi::Array arr = Napi::Array::New(env); size_t i = 0; - for (auto const &imap : esmb::FunctionMap) { + for (auto const &imap : esmb::Image::FunctionMap) { Napi::HandleScope scope(env); arr[i] = Napi::String::New(env, imap.first); i++; } - for (auto const &imap : esmb::NoInputFunctionMap) { + for (auto const &imap : esmb::Image::NoInputFunctionMap) { Napi::HandleScope scope(env); arr[i] = Napi::String::New(env, imap.first); i++; diff --git a/natives/node/worker.cc b/natives/node/worker.cc index 1c49f988..33750544 100644 --- a/natives/node/worker.cc +++ b/natives/node/worker.cc @@ -1,5 +1,5 @@ #include "worker.h" -#include "../common.h" +#include "../image/common.h" using namespace std; @@ -13,9 +13,9 @@ void ImageAsyncWorker::Execute() { shouldKill = false; if (bufSize != 0) { - outData = esmb::FunctionMap.at(command)(type, outType, bufData, bufSize, inArgs, &shouldKill); + outData = esmb::Image::FunctionMap.at(command)(type, outType, bufData, bufSize, inArgs, &shouldKill); } else { - outData = esmb::NoInputFunctionMap.at(command)(type, outType, inArgs, &shouldKill); + outData = esmb::Image::NoInputFunctionMap.at(command)(type, outType, inArgs, &shouldKill); } } diff --git a/natives/shared.h b/natives/shared.h new file mode 100644 index 00000000..30d210c7 --- /dev/null +++ b/natives/shared.h @@ -0,0 +1,33 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "common/argmap.h" + +struct CmdOutput { + char *buf; + size_t length; +}; + +struct FunctionArg { + std::type_index type; + bool required; +}; + +typedef const std::map FunctionArgs; + +#define declare_input_func(NAME) \ + CmdOutput NAME(const std::string &type, std::string &outType, const char *bufferData, size_t bufferLength, \ + esmb::ArgumentMap arguments, bool *shouldKill) +#define declare_noinput_func(NAME) \ + CmdOutput NAME(const std::string &type, std::string &outType, esmb::ArgumentMap arguments, bool *shouldKill) +#define declare_input_args(NAME) extern FunctionArgs NAME; + +inline uint32_t readUint32LE(unsigned char *buffer) { + return static_cast(buffer[0]) | (static_cast(buffer[1]) << 8) | + (static_cast(buffer[2]) << 16) | (static_cast(buffer[3]) << 24); +} \ No newline at end of file