mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Deprecate limitInputPixels and sequentialRead, move to input options
This commit is contained in:
@@ -86,6 +86,10 @@ namespace sharp {
|
||||
descriptor->createHeight = AttrTo<uint32_t>(input, "createHeight");
|
||||
descriptor->createBackground = AttrAsRgba(input, "createBackground");
|
||||
}
|
||||
// Limit input images to a given number of pixels, where pixels = width * height
|
||||
descriptor->limitInputPixels = AttrTo<uint32_t>(input, "limitInputPixels");
|
||||
// Allow switch from random to sequential access
|
||||
descriptor->access = AttrTo<bool>(input, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@@ -244,7 +248,7 @@ namespace sharp {
|
||||
/*
|
||||
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
|
||||
*/
|
||||
std::tuple<VImage, ImageType> OpenInput(InputDescriptor *descriptor, VipsAccess accessMethod) {
|
||||
std::tuple<VImage, ImageType> OpenInput(InputDescriptor *descriptor) {
|
||||
VImage image;
|
||||
ImageType imageType;
|
||||
if (descriptor->isBuffer) {
|
||||
@@ -264,7 +268,7 @@ namespace sharp {
|
||||
if (imageType != ImageType::UNKNOWN) {
|
||||
try {
|
||||
vips::VOption *option = VImage::option()
|
||||
->set("access", accessMethod)
|
||||
->set("access", descriptor->access)
|
||||
->set("fail", descriptor->failOnError);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||
option->set("dpi", descriptor->density);
|
||||
@@ -310,7 +314,7 @@ namespace sharp {
|
||||
if (imageType != ImageType::UNKNOWN) {
|
||||
try {
|
||||
vips::VOption *option = VImage::option()
|
||||
->set("access", accessMethod)
|
||||
->set("access", descriptor->access)
|
||||
->set("fail", descriptor->failOnError);
|
||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
|
||||
option->set("dpi", descriptor->density);
|
||||
@@ -334,6 +338,11 @@ namespace sharp {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Limit input images to a given number of pixels, where pixels = width * height
|
||||
if (descriptor->limitInputPixels > 0 &&
|
||||
static_cast<uint64_t>(image.width() * image.height()) > static_cast<uint64_t>(descriptor->limitInputPixels)) {
|
||||
throw vips::VError("Input image exceeds pixel limit");
|
||||
}
|
||||
return std::make_tuple(image, imageType);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ namespace sharp {
|
||||
std::string file;
|
||||
char *buffer;
|
||||
bool failOnError;
|
||||
int limitInputPixels;
|
||||
VipsAccess access;
|
||||
size_t bufferLength;
|
||||
bool isBuffer;
|
||||
double density;
|
||||
@@ -64,6 +66,8 @@ namespace sharp {
|
||||
InputDescriptor():
|
||||
buffer(nullptr),
|
||||
failOnError(TRUE),
|
||||
limitInputPixels(0x3FFF * 0x3FFF),
|
||||
access(VIPS_ACCESS_RANDOM),
|
||||
bufferLength(0),
|
||||
isBuffer(FALSE),
|
||||
density(72.0),
|
||||
@@ -156,7 +160,7 @@ namespace sharp {
|
||||
/*
|
||||
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
|
||||
*/
|
||||
std::tuple<VImage, ImageType> OpenInput(InputDescriptor *descriptor, VipsAccess accessMethod);
|
||||
std::tuple<VImage, ImageType> OpenInput(InputDescriptor *descriptor);
|
||||
|
||||
/*
|
||||
Does this image have an embedded profile?
|
||||
|
||||
@@ -46,7 +46,7 @@ class MetadataWorker : public Nan::AsyncWorker {
|
||||
vips::VImage image;
|
||||
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
||||
try {
|
||||
std::tie(image, imageType) = OpenInput(baton->input, VIPS_ACCESS_SEQUENTIAL);
|
||||
std::tie(image, imageType) = OpenInput(baton->input);
|
||||
} catch (vips::VError const &err) {
|
||||
(baton->err).append(err.what());
|
||||
}
|
||||
|
||||
@@ -77,15 +77,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
// Open input
|
||||
vips::VImage image;
|
||||
ImageType inputImageType;
|
||||
std::tie(image, inputImageType) = sharp::OpenInput(baton->input, baton->accessMethod);
|
||||
|
||||
// Limit input images to a given number of pixels, where pixels = width * height
|
||||
// Ignore if 0
|
||||
if (baton->limitInputPixels > 0 &&
|
||||
static_cast<uint64_t>(image.width() * image.height()) > static_cast<uint64_t>(baton->limitInputPixels)) {
|
||||
(baton->err).append("Input image exceeds pixel limit");
|
||||
return Error();
|
||||
}
|
||||
std::tie(image, inputImageType) = sharp::OpenInput(baton->input);
|
||||
|
||||
// Calculate angle of rotation
|
||||
VipsAngle rotation;
|
||||
@@ -270,7 +262,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
if (shrink_on_load > 1) {
|
||||
// Reload input using shrink-on-load
|
||||
vips::VOption *option = VImage::option()
|
||||
->set("access", baton->accessMethod)
|
||||
->set("access", baton->input->access)
|
||||
->set("shrink", shrink_on_load)
|
||||
->set("fail", baton->input->failOnError);
|
||||
if (baton->input->buffer != nullptr) {
|
||||
@@ -426,7 +418,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
ImageType joinImageType = ImageType::UNKNOWN;
|
||||
|
||||
for (unsigned int i = 0; i < baton->joinChannelIn.size(); i++) {
|
||||
std::tie(joinImage, joinImageType) = sharp::OpenInput(baton->joinChannelIn[i], baton->accessMethod);
|
||||
std::tie(joinImage, joinImageType) = sharp::OpenInput(baton->joinChannelIn[i]);
|
||||
image = image.bandjoin(joinImage);
|
||||
}
|
||||
image = image.copy(VImage::option()->set("interpretation", baton->colourspace));
|
||||
@@ -479,7 +471,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
baton->height = image.height();
|
||||
}
|
||||
image = image.tilecache(VImage::option()
|
||||
->set("access", baton->accessMethod)
|
||||
->set("access", VIPS_ACCESS_RANDOM)
|
||||
->set("threaded", TRUE));
|
||||
image = image.smartcrop(baton->width, baton->height, VImage::option()
|
||||
->set("interesting", baton->position == 16 ? VIPS_INTERESTING_ENTROPY : VIPS_INTERESTING_ATTENTION));
|
||||
@@ -556,7 +548,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
for (Composite *composite : baton->composite) {
|
||||
VImage compositeImage;
|
||||
ImageType compositeImageType = ImageType::UNKNOWN;
|
||||
std::tie(compositeImage, compositeImageType) = OpenInput(composite->input, baton->accessMethod);
|
||||
std::tie(compositeImage, compositeImageType) = OpenInput(composite->input);
|
||||
// Verify within current dimensions
|
||||
if (compositeImage.width() > image.width() || compositeImage.height() > image.height()) {
|
||||
throw vips::VError("Image to composite must have same dimensions or smaller");
|
||||
@@ -646,7 +638,7 @@ class PipelineWorker : public Nan::AsyncWorker {
|
||||
if (baton->boolean != nullptr) {
|
||||
VImage booleanImage;
|
||||
ImageType booleanImageType = ImageType::UNKNOWN;
|
||||
std::tie(booleanImage, booleanImageType) = sharp::OpenInput(baton->boolean, baton->accessMethod);
|
||||
std::tie(booleanImage, booleanImageType) = sharp::OpenInput(baton->boolean);
|
||||
image = sharp::Boolean(image, booleanImage, baton->booleanOp);
|
||||
}
|
||||
|
||||
@@ -1193,10 +1185,6 @@ NAN_METHOD(pipeline) {
|
||||
|
||||
// Input
|
||||
baton->input = CreateInputDescriptor(AttrAs<v8::Object>(options, "input"), buffersToPersist);
|
||||
baton->accessMethod = AttrTo<bool>(options, "sequentialRead") ?
|
||||
VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
||||
// Limit input images to a given number of pixels, where pixels = width * height
|
||||
baton->limitInputPixels = AttrTo<int32_t>(options, "limitInputPixels");
|
||||
// Extract image options
|
||||
baton->topOffsetPre = AttrTo<int32_t>(options, "topOffsetPre");
|
||||
baton->leftOffsetPre = AttrTo<int32_t>(options, "leftOffsetPre");
|
||||
@@ -1408,11 +1396,12 @@ NAN_METHOD(pipeline) {
|
||||
// signal that we do not want to pass any value to dzSave
|
||||
baton->tileDepth = VIPS_FOREIGN_DZ_DEPTH_LAST;
|
||||
}
|
||||
|
||||
// Force random access for certain operations
|
||||
if (baton->accessMethod == VIPS_ACCESS_SEQUENTIAL && (
|
||||
baton->trimThreshold > 0.0 || baton->normalise ||
|
||||
baton->position == 16 || baton->position == 17)) {
|
||||
baton->accessMethod = VIPS_ACCESS_RANDOM;
|
||||
if (baton->input->access == VIPS_ACCESS_SEQUENTIAL) {
|
||||
if (baton->trimThreshold > 0.0 || baton->normalise || baton->position == 16 || baton->position == 17) {
|
||||
baton->input->access = VIPS_ACCESS_RANDOM;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to notify of libvips warnings
|
||||
|
||||
@@ -55,7 +55,6 @@ struct Composite {
|
||||
|
||||
struct PipelineBaton {
|
||||
sharp::InputDescriptor *input;
|
||||
int limitInputPixels;
|
||||
std::string formatOut;
|
||||
std::string fileOut;
|
||||
void *bufferOut;
|
||||
@@ -119,7 +118,6 @@ struct PipelineBaton {
|
||||
int extendRight;
|
||||
std::vector<double> extendBackground;
|
||||
bool withoutEnlargement;
|
||||
VipsAccess accessMethod;
|
||||
int jpegQuality;
|
||||
bool jpegProgressive;
|
||||
std::string jpegChromaSubsampling;
|
||||
@@ -182,7 +180,6 @@ struct PipelineBaton {
|
||||
|
||||
PipelineBaton():
|
||||
input(nullptr),
|
||||
limitInputPixels(0),
|
||||
bufferOutLength(0),
|
||||
topOffsetPre(-1),
|
||||
topOffsetPost(-1),
|
||||
|
||||
@@ -62,7 +62,7 @@ class StatsWorker : public Nan::AsyncWorker {
|
||||
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
||||
|
||||
try {
|
||||
std::tie(image, imageType) = OpenInput(baton->input, baton->accessMethod);
|
||||
std::tie(image, imageType) = OpenInput(baton->input);
|
||||
} catch (vips::VError const &err) {
|
||||
(baton->err).append(err.what());
|
||||
}
|
||||
@@ -178,7 +178,6 @@ NAN_METHOD(stats) {
|
||||
|
||||
// Input
|
||||
baton->input = sharp::CreateInputDescriptor(sharp::AttrAs<v8::Object>(options, "input"), buffersToPersist);
|
||||
baton->accessMethod = AttrTo<bool>(options, "sequentialRead") ? VIPS_ACCESS_SEQUENTIAL : VIPS_ACCESS_RANDOM;
|
||||
|
||||
// Function to notify of libvips warnings
|
||||
Nan::Callback *debuglog = new Nan::Callback(sharp::AttrAs<v8::Function>(options, "debuglog"));
|
||||
|
||||
@@ -46,7 +46,6 @@ struct ChannelStats {
|
||||
struct StatsBaton {
|
||||
// Input
|
||||
sharp::InputDescriptor *input;
|
||||
VipsAccess accessMethod;
|
||||
|
||||
// Output
|
||||
std::vector<ChannelStats> channelStats;
|
||||
|
||||
Reference in New Issue
Block a user