Port explode/implode, add new playing messages
This commit is contained in:
parent
a77dc5acf9
commit
d236179639
4 changed files with 43 additions and 50 deletions
|
@ -1,57 +1,52 @@
|
|||
#include <Magick++.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vips/vips8>
|
||||
|
||||
#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<int>(Arguments, "amount");
|
||||
int delay = GetArgumentWithFallback<int>(Arguments, "delay", 0);
|
||||
bool implode = GetArgument<bool>(Arguments, "implode");
|
||||
string basePath = GetArgument<string>(Arguments, "basePath");
|
||||
|
||||
Blob blob;
|
||||
VOption *options = VImage::option();
|
||||
|
||||
list<Image> frames;
|
||||
list<Image> coalesced;
|
||||
list<Image> 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<VImage> 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue