diff --git a/commands/image-editing/explode.js b/commands/image-editing/explode.js index a03bda2..63168f4 100644 --- a/commands/image-editing/explode.js +++ b/commands/image-editing/explode.js @@ -1,10 +1,6 @@ import ImageCommand from "../../classes/imageCommand.js"; class ExplodeCommand extends ImageCommand { - params = { - amount: -1 - }; - static description = "Explodes an image"; static aliases = ["exp"]; diff --git a/commands/image-editing/implode.js b/commands/image-editing/implode.js index 60f9909..1f05b2e 100644 --- a/commands/image-editing/implode.js +++ b/commands/image-editing/implode.js @@ -2,7 +2,7 @@ import ImageCommand from "../../classes/imageCommand.js"; class ImplodeCommand extends ImageCommand { params = { - amount: 1 + implode: true }; static description = "Implodes an image"; diff --git a/config/messages.json b/config/messages.json index 0e4cd71..4c6f16f 100644 --- a/config/messages.json +++ b/config/messages.json @@ -158,7 +158,6 @@ "Item Asylum", "TIC-80", "Ghetto Smosh", - "brought to you by the DFS project", "Splatoon 3", "changed", "Chutes and Ladders", @@ -195,6 +194,9 @@ "ANTONBLAST", "[object Object]", "Xonotic", + "Lario", + "Hi-Fi Rush", + "Calckey", "The clock is ticking." ] } diff --git a/natives/explode.cc b/natives/explode.cc index f4fc4a1..bc167e0 100644 --- a/natives/explode.cc +++ b/natives/explode.cc @@ -1,57 +1,52 @@ -#include - -#include -#include -#include -#include -#include +#include #include "common.h" using namespace std; -using namespace Magick; +using namespace vips; char *Explode(string type, string *outType, char *BufferData, size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { - int amount = GetArgument(Arguments, "amount"); - int delay = GetArgumentWithFallback(Arguments, "delay", 0); + bool implode = GetArgument(Arguments, "implode"); + string basePath = GetArgument(Arguments, "basePath"); - Blob blob; + VOption *options = VImage::option(); - list frames; - list coalesced; - list blurred; - try { - readImages(&frames, Blob(BufferData, BufferLength)); - } catch (Magick::WarningCoder &warning) { - cerr << "Coder Warning: " << warning.what() << endl; - } catch (Magick::Warning &warning) { - cerr << "Warning: " << warning.what() << endl; + VImage in = + VImage::new_from_buffer( + BufferData, BufferLength, "", + type == "gif" ? options->set("n", -1)->set("access", "sequential") + : options) + .colourspace(VIPS_INTERPRETATION_sRGB); + if (!in.has_alpha()) in = in.bandjoin(255); + + int width = in.width(); + int pageHeight = vips_image_get_page_height(in.get_image()); + int nPages = vips_image_get_n_pages(in.get_image()); + + string distortPath = basePath + "assets/images/" + + (implode ? "linearimplode.png" : "linearexplode.png"); + VImage distort = + (VImage::new_from_file(distortPath.c_str()) + .resize(width / 500.0, VImage::option() + ->set("vscale", pageHeight / 500.0) + ->set("kernel", VIPS_KERNEL_CUBIC)) / + 65535); + + VImage distortImage = (distort[0] * width).bandjoin(distort[1] * pageHeight); + + vector img; + for (int i = 0; i < nPages; i++) { + VImage img_frame = + type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in; + VImage mapped = img_frame.mapim(distortImage); + img.push_back(mapped); } - coalesceImages(&coalesced, frames.begin(), frames.end()); + VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1)); + final.set(VIPS_META_PAGE_HEIGHT, pageHeight); - for (Image &image : coalesced) { - image.implode(amount); - image.magick(*outType); - blurred.push_back(image); - } + void *buf; + final.write_to_buffer(("." + *outType).c_str(), &buf, DataSize); - optimizeTransparency(blurred.begin(), blurred.end()); - - if (*outType == "gif") { - for (Image &image : blurred) { - image.quantizeDither(false); - image.quantize(); - if (delay != 0) image.animationDelay(delay); - } - } - - 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); - return data; + return (char *)buf; } \ No newline at end of file