modified scott native to accept arbitrary values

This commit is contained in:
murm 2023-03-22 04:49:51 -04:00
parent 513efc4436
commit 44f8f30ccc
3 changed files with 31 additions and 3 deletions

View file

@ -8,6 +8,11 @@ using namespace vips;
ArgumentMap Scott(string type, string *outType, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
string basePath = GetArgument<string>(Arguments, "basePath");
string assetPathIn = GetArgumentWithFallback<string>(Arguments, "assetPath", "assets/images/scott.png");
string distortPathIn = GetArgumentWithFallback<string>(Arguments, "distortPath", "assets/images/scottmap.png");
int compx = GetArgumentWithFallback<int>(Arguments, "compx", 127);
int compy = GetArgumentWithFallback<int>(Arguments, "compy", 181);
VOption *options = VImage::option()->set("access", "sequential");
@ -21,10 +26,13 @@ ArgumentMap Scott(string type, string *outType, char *BufferData, size_t BufferL
int pageHeight = vips_image_get_page_height(in.get_image());
int nPages = vips_image_get_n_pages(in.get_image());
string assetPath = basePath + "assets/images/scott.png";
string assetPath = basePath + assetPathIn;
VImage bg = VImage::new_from_file(assetPath.c_str());
string distortPath = basePath + "assets/images/scottmap.png";
int bgwidth = bg.width();
int bgpageHeight = vips_image_get_page_height(bg.get_image());
string distortPath = basePath + distortPathIn;
VImage distort = VImage::new_from_file(distortPath.c_str());
VImage distortImage =
@ -40,7 +48,7 @@ ArgumentMap Scott(string type, string *outType, char *BufferData, size_t BufferL
VImage mapped = resized.mapim(distortImage)
.extract_band(0, VImage::option()->set("n", 3))
.bandjoin(distort[2]);
VImage offset = mapped.embed(127, 181, 864, 481);
VImage offset = mapped.embed(compx, compy, bgwidth, bgpageHeight);
VImage composited = bg.composite2(offset, VIPS_BLEND_MODE_OVER);
img.push_back(composited);
}