Added crop and loop, fixed database not properly adding new commands
This commit is contained in:
parent
10e934e722
commit
0ebd0a0cee
9 changed files with 115 additions and 14 deletions
57
natives/crop.cc
Normal file
57
natives/crop.cc
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include <napi.h>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Magick;
|
||||
|
||||
class CropWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
CropWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
~CropWorker() {}
|
||||
|
||||
void Execute() {
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> mid;
|
||||
list<Image> result;
|
||||
readImages(&frames, in_path);
|
||||
coalesceImages(&coalesced, frames.begin(), frames.end());
|
||||
|
||||
for (Image &image : coalesced) {
|
||||
image.extent(Geometry(to_string(image.columns() / image.rows() >= 1 ? image.rows() : image.columns()) + "x"), Magick::CenterGravity);
|
||||
image.extent(Geometry("x" + to_string(image.columns() / image.rows() <= 1 ? image.columns() : image.rows())), Magick::CenterGravity);
|
||||
image.magick(type);
|
||||
mid.push_back(image);
|
||||
}
|
||||
|
||||
optimizeImageLayers(&result, mid.begin(), mid.end());
|
||||
if (delay != 0) for_each(result.begin(), result.end(), animationDelayImage(delay));
|
||||
writeImages(result.begin(), result.end(), &blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
Callback().Call({Env().Undefined(), Napi::Buffer<char>::Copy(Env(), (char *)blob.data(), blob.length())});
|
||||
}
|
||||
|
||||
private:
|
||||
string in_path, type;
|
||||
int delay, wordlength, i, n;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
};
|
||||
|
||||
Napi::Value Crop(const Napi::CallbackInfo &info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
|
||||
string in_path = info[0].As<Napi::String>().Utf8Value();
|
||||
string type = info[1].As<Napi::String>().Utf8Value();
|
||||
int delay = info[2].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[3].As<Napi::Function>();
|
||||
|
||||
CropWorker* blurWorker = new CropWorker(cb, in_path, type, delay);
|
||||
blurWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
8
natives/crop.h
Normal file
8
natives/crop.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef ESMBOT_NATIVES_CROP_H_
|
||||
#define ESMBOT_NATIVES_CROP_H_
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
Napi::Value Crop(const Napi::CallbackInfo& info);
|
||||
|
||||
#endif
|
|
@ -1,4 +1,5 @@
|
|||
#include <napi.h>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <Magick++.h>
|
||||
|
||||
|
@ -7,20 +8,18 @@ using namespace Magick;
|
|||
|
||||
class FreezeWorker : public Napi::AsyncWorker {
|
||||
public:
|
||||
FreezeWorker(Napi::Function& callback, string in_path, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), type(type), delay(delay) {}
|
||||
FreezeWorker(Napi::Function& callback, string in_path, bool loop, string type, int delay)
|
||||
: Napi::AsyncWorker(callback), in_path(in_path), loop(loop), type(type), delay(delay) {}
|
||||
~FreezeWorker() {}
|
||||
|
||||
void Execute() {
|
||||
list<Image> frames;
|
||||
list<Image> result;
|
||||
readImages(&frames, in_path);
|
||||
|
||||
for_each(frames.begin(), frames.end(), animationIterationsImage(1));
|
||||
for_each(frames.begin(), frames.end(), animationIterationsImage(loop ? 0 : 1));
|
||||
|
||||
optimizeImageLayers(&result, frames.begin(), frames.end());
|
||||
if (delay != 0) for_each(result.begin(), result.end(), animationDelayImage(delay));
|
||||
writeImages(result.begin(), result.end(), &blob);
|
||||
if (delay != 0) for_each(frames.begin(), frames.end(), animationDelayImage(delay));
|
||||
writeImages(frames.begin(), frames.end(), &blob);
|
||||
}
|
||||
|
||||
void OnOK() {
|
||||
|
@ -32,6 +31,7 @@ class FreezeWorker : public Napi::AsyncWorker {
|
|||
int delay, wordlength, i, n;
|
||||
size_t bytes, type_size;
|
||||
Blob blob;
|
||||
bool loop;
|
||||
};
|
||||
|
||||
Napi::Value Freeze(const Napi::CallbackInfo &info)
|
||||
|
@ -39,11 +39,12 @@ Napi::Value Freeze(const Napi::CallbackInfo &info)
|
|||
Napi::Env env = info.Env();
|
||||
|
||||
string in_path = info[0].As<Napi::String>().Utf8Value();
|
||||
string type = info[1].As<Napi::String>().Utf8Value();
|
||||
int delay = info[2].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[3].As<Napi::Function>();
|
||||
bool loop = info[1].As<Napi::Boolean>().Value();
|
||||
string type = info[2].As<Napi::String>().Utf8Value();
|
||||
int delay = info[3].As<Napi::Number>().Int32Value();
|
||||
Napi::Function cb = info[4].As<Napi::Function>();
|
||||
|
||||
FreezeWorker* blurWorker = new FreezeWorker(cb, in_path, type, delay);
|
||||
FreezeWorker* blurWorker = new FreezeWorker(cb, in_path, loop, type, delay);
|
||||
blurWorker->Queue();
|
||||
return env.Undefined();
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include "caption.h"
|
||||
#include "caption2.h"
|
||||
#include "circle.h"
|
||||
#include "crop.h"
|
||||
#include "explode.h"
|
||||
#include "flag.h"
|
||||
#include "flip.h"
|
||||
|
@ -39,6 +40,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
|||
exports.Set(Napi::String::New(env, "caption"), Napi::Function::New(env, Caption));
|
||||
exports.Set(Napi::String::New(env, "captionTwo"), Napi::Function::New(env, CaptionTwo));
|
||||
exports.Set(Napi::String::New(env, "circle"), Napi::Function::New(env, Circle));
|
||||
exports.Set(Napi::String::New(env, "crop"), Napi::Function::New(env, Crop));
|
||||
exports.Set(Napi::String::New(env, "explode"), Napi::Function::New(env, Explode));
|
||||
exports.Set(Napi::String::New(env, "flag"), Napi::Function::New(env, Flag));
|
||||
exports.Set(Napi::String::New(env, "flip"), Napi::Function::New(env, Flip));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue