Refactor and prepare for future CLI implementation
This commit is contained in:
parent
de308ca795
commit
cc7ea2762c
17 changed files with 152 additions and 115 deletions
|
@ -2,24 +2,34 @@ cmake_minimum_required(VERSION 3.15)
|
|||
cmake_policy(SET CMP0091 NEW)
|
||||
cmake_policy(SET CMP0042 NEW)
|
||||
project(image)
|
||||
include_directories(${CMAKE_JS_INC})
|
||||
|
||||
file(GLOB SOURCE_FILES "natives/*.cc" "natives/*.h")
|
||||
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
|
||||
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
|
||||
if(MSVC) # todo: change flags for more parity with GCC/clang, I don't know much about MSVC so pull requests are open
|
||||
set(CMAKE_CXX_FLAGS "/Wall /EHsc /GS")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "/Zi")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "/Ox")
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
set(BUILD_SHARED_LIBS TRUE)
|
||||
|
||||
if (CMAKE_JS_VERSION)
|
||||
include_directories(${CMAKE_JS_INC})
|
||||
add_library(${PROJECT_NAME} SHARED ${SOURCE_FILES} ${CMAKE_JS_SRC} natives/node/image.cc)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
|
||||
target_link_libraries(${PROJECT_NAME} ${CMAKE_JS_LIB})
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror=format-security -Wno-cast-function-type -fexceptions -D_GLIBCXX_ASSERTIONS -fstack-clash-protection -pedantic -D_GLIBCXX_USE_CXX11_ABI=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES} natives/cli/image.cc)
|
||||
endif()
|
||||
|
||||
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
|
||||
|
||||
if(MSVC) # todo: change flags for more parity with GCC/clang, I don't know much about MSVC so pull requests are open
|
||||
set(CMAKE_CXX_FLAGS "/Wall /EHsc /GS")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "/Zi")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "/Ox")
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
set(BUILD_SHARED_LIBS TRUE)
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror=format-security -Wno-cast-function-type -fexceptions -D_GLIBCXX_ASSERTIONS -fstack-clash-protection -pedantic -D_GLIBCXX_USE_CXX11_ABI=1")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
|
||||
endif()
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
find_package(ImageMagick REQUIRED COMPONENTS Magick++ MagickCore)
|
||||
add_definitions(-DMAGICKCORE_QUANTUM_DEPTH=16)
|
||||
add_definitions(-DMAGICKCORE_HDRI_ENABLE=0)
|
||||
|
@ -31,7 +41,7 @@ include_directories(${VIPS_INCLUDE_DIRS})
|
|||
link_directories(${VIPS_LIBRARY_DIRS})
|
||||
target_link_libraries(${PROJECT_NAME} ${VIPS_LDFLAGS})
|
||||
|
||||
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
|
||||
if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET AND CMAKE_JS_VERSION)
|
||||
# Generate node.lib
|
||||
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
|
||||
endif()
|
||||
|
|
|
@ -8,7 +8,7 @@ using namespace std;
|
|||
using namespace vips;
|
||||
|
||||
char *Bounce(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
VOption *options = VImage::option();
|
||||
|
||||
VImage in =
|
||||
|
|
|
@ -12,7 +12,7 @@ using namespace std;
|
|||
using namespace Magick;
|
||||
|
||||
char *Circle(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
Blob blob;
|
||||
|
||||
list<Image> frames;
|
||||
|
|
26
natives/cli/image.cc
Normal file
26
natives/cli/image.cc
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
#include "../common.h"
|
||||
|
||||
void showUsage(char *path) {
|
||||
std::cout << "Usage: " << path << " operation [--arg=\"param\"] [...]" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 1 ||
|
||||
(argc == 1 && !strcmp(argv[1], "-h"))) {
|
||||
showUsage(argv[0]);
|
||||
#ifdef _WIN32
|
||||
system("PAUSE");
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *op = argv[1];
|
||||
|
||||
//handleArguments(argc, argv);
|
||||
|
||||
std::cout << "This does nothing yet, but it might in the future!" << std::endl;
|
||||
return 0;
|
||||
}
|
|
@ -12,6 +12,46 @@ using std::variant;
|
|||
typedef variant<string, float, bool, int> ArgumentVariant;
|
||||
typedef map<string, ArgumentVariant> ArgumentMap;
|
||||
|
||||
#include "blur.h"
|
||||
#include "bounce.h"
|
||||
#include "caption.h"
|
||||
#include "caption2.h"
|
||||
#include "circle.h"
|
||||
#include "colors.h"
|
||||
#include "crop.h"
|
||||
#include "deepfry.h"
|
||||
#include "explode.h"
|
||||
#include "flag.h"
|
||||
#include "flip.h"
|
||||
#include "freeze.h"
|
||||
#include "gamexplain.h"
|
||||
#include "globe.h"
|
||||
#include "homebrew.h"
|
||||
#include "invert.h"
|
||||
#include "jpeg.h"
|
||||
#include "magik.h"
|
||||
#include "meme.h"
|
||||
#include "mirror.h"
|
||||
#include "motivate.h"
|
||||
#include "reddit.h"
|
||||
#include "resize.h"
|
||||
#include "reverse.h"
|
||||
#include "scott.h"
|
||||
#include "snapchat.h"
|
||||
#include "sonic.h"
|
||||
#include "speed.h"
|
||||
#include "spin.h"
|
||||
#include "squish.h"
|
||||
#include "swirl.h"
|
||||
#include "tile.h"
|
||||
#include "togif.h"
|
||||
#include "uncanny.h"
|
||||
#include "uncaption.h"
|
||||
#include "wall.h"
|
||||
#include "watermark.h"
|
||||
#include "whisper.h"
|
||||
#include "zamn.h"
|
||||
|
||||
template <typename T>
|
||||
T GetArgument(ArgumentMap map, string key) {
|
||||
try {
|
||||
|
@ -43,3 +83,48 @@ 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::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}};
|
||||
|
||||
const std::map<std::string,
|
||||
char* (*)(string* type, ArgumentMap Arguments, size_t* DataSize)>
|
||||
NoInputFunctionMap = {{"homebrew", Homebrew}, {"sonic", Sonic}};
|
|
@ -8,7 +8,7 @@ using namespace std;
|
|||
using namespace vips;
|
||||
|
||||
char *Crop(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
VImage in =
|
||||
|
|
|
@ -7,7 +7,7 @@ using namespace std;
|
|||
using namespace vips;
|
||||
|
||||
char *Deepfry(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
VImage in =
|
||||
|
|
|
@ -6,7 +6,7 @@ using namespace std;
|
|||
using namespace vips;
|
||||
|
||||
char *Invert(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
VImage in =
|
||||
|
|
|
@ -10,7 +10,7 @@ using namespace std;
|
|||
using namespace Magick;
|
||||
|
||||
char *Magik(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
Blob blob;
|
||||
|
||||
list<Image> frames;
|
||||
|
|
|
@ -4,46 +4,7 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "blur.h"
|
||||
#include "bounce.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"
|
||||
#include "flag.h"
|
||||
#include "flip.h"
|
||||
#include "freeze.h"
|
||||
#include "gamexplain.h"
|
||||
#include "globe.h"
|
||||
#include "homebrew.h"
|
||||
#include "invert.h"
|
||||
#include "jpeg.h"
|
||||
#include "magik.h"
|
||||
#include "meme.h"
|
||||
#include "mirror.h"
|
||||
#include "motivate.h"
|
||||
#include "reddit.h"
|
||||
#include "resize.h"
|
||||
#include "reverse.h"
|
||||
#include "scott.h"
|
||||
#include "snapchat.h"
|
||||
#include "sonic.h"
|
||||
#include "speed.h"
|
||||
#include "spin.h"
|
||||
#include "squish.h"
|
||||
#include "swirl.h"
|
||||
#include "tile.h"
|
||||
#include "togif.h"
|
||||
#include "uncanny.h"
|
||||
#include "uncaption.h"
|
||||
#include "wall.h"
|
||||
#include "watermark.h"
|
||||
#include "whisper.h"
|
||||
#include "zamn.h"
|
||||
#include "../common.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Magick++.h>
|
||||
|
@ -52,51 +13,6 @@
|
|||
|
||||
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, ArgumentMap Arguments, size_t* DataSize)>
|
||||
NoInputFunctionMap = {{"homebrew", Homebrew}, {"sonic", Sonic}};
|
||||
|
||||
bool isNapiValueInt(Napi::Env& env, Napi::Value& num) {
|
||||
return env.Global()
|
||||
.Get("Number")
|
||||
|
@ -165,7 +81,7 @@ Napi::Value ProcessImage(const Napi::CallbackInfo& info) {
|
|||
|
||||
result.Set("data", Napi::Buffer<char>::New(
|
||||
env, buf, length,
|
||||
[](Napi::Env env, void* data) { free(data); }));
|
||||
[]([[maybe_unused]] Napi::Env env, void* data) { free(data); }));
|
||||
result.Set("type", type);
|
||||
} catch (std::exception const& err) {
|
||||
Napi::Error::New(env, err.what()).ThrowAsJavaScriptException();
|
|
@ -39,7 +39,7 @@ char *vipsRemove(char *data, size_t length, size_t *DataSize, int speed) {
|
|||
return (char *)buf;
|
||||
}
|
||||
|
||||
char *Speed(string *type, char *BufferData, size_t BufferLength,
|
||||
char *Speed([[maybe_unused]] 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);
|
||||
|
|
|
@ -9,7 +9,7 @@ using namespace std;
|
|||
using namespace Magick;
|
||||
|
||||
char *Spin(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
int delay = GetArgumentWithFallback<int>(Arguments, "delay", 0);
|
||||
|
||||
Blob blob;
|
||||
|
|
|
@ -8,7 +8,7 @@ using namespace std;
|
|||
using namespace vips;
|
||||
|
||||
char *Squish(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
VOption *options = VImage::option();
|
||||
|
||||
VImage in =
|
||||
|
|
|
@ -6,7 +6,7 @@ using namespace std;
|
|||
using namespace vips;
|
||||
|
||||
char *Swirl(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
VOption *options = VImage::option()->set("access", "sequential");
|
||||
|
||||
VImage in =
|
||||
|
|
|
@ -10,7 +10,7 @@ using namespace std;
|
|||
using namespace Magick;
|
||||
|
||||
char *Tile(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
Blob blob;
|
||||
|
||||
list<Image> frames;
|
||||
|
|
|
@ -6,7 +6,7 @@ using namespace std;
|
|||
using namespace vips;
|
||||
|
||||
char *ToGif(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
if (*type == "gif") {
|
||||
*DataSize = BufferLength;
|
||||
char *data = (char *)malloc(BufferLength);
|
||||
|
|
|
@ -10,7 +10,7 @@ using namespace std;
|
|||
using namespace Magick;
|
||||
|
||||
char *Wall(string *type, char *BufferData, size_t BufferLength,
|
||||
ArgumentMap Arguments, size_t *DataSize) {
|
||||
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
||||
Blob blob;
|
||||
|
||||
list<Image> frames;
|
||||
|
|
Loading…
Reference in a new issue