mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 05:36:18 +01:00
Compare commits
1 Commits
0.35
...
17d4a684df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17d4a684df |
@@ -510,11 +510,11 @@ namespace sharp {
|
|||||||
option = GetOptionsForImageType(imageType, descriptor);
|
option = GetOptionsForImageType(imageType, descriptor);
|
||||||
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
|
image = VImage::new_from_buffer(descriptor->buffer, descriptor->bufferLength, nullptr, option);
|
||||||
}
|
}
|
||||||
} catch (vips::VError const &err) {
|
} catch (std::runtime_error const &err) {
|
||||||
throw vips::VError(std::string("Input buffer has corrupt header: ") + err.what());
|
throw std::runtime_error(std::string("Input buffer has corrupt header: ") + err.what());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw vips::VError("Input buffer contains unsupported image format");
|
throw std::runtime_error("Input buffer contains unsupported image format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -585,10 +585,10 @@ namespace sharp {
|
|||||||
imageType = DetermineImageType(descriptor->file.data());
|
imageType = DetermineImageType(descriptor->file.data());
|
||||||
if (imageType == ImageType::MISSING) {
|
if (imageType == ImageType::MISSING) {
|
||||||
if (descriptor->file.find("<svg") != std::string::npos) {
|
if (descriptor->file.find("<svg") != std::string::npos) {
|
||||||
throw vips::VError("Input file is missing, did you mean "
|
throw std::runtime_error("Input file is missing, did you mean "
|
||||||
"sharp(Buffer.from('" + descriptor->file.substr(0, 8) + "...')?");
|
"sharp(Buffer.from('" + descriptor->file.substr(0, 8) + "...')?");
|
||||||
}
|
}
|
||||||
throw vips::VError("Input file is missing: " + descriptor->file);
|
throw std::runtime_error("Input file is missing: " + descriptor->file);
|
||||||
}
|
}
|
||||||
if (imageType != ImageType::UNKNOWN) {
|
if (imageType != ImageType::UNKNOWN) {
|
||||||
try {
|
try {
|
||||||
@@ -600,11 +600,11 @@ namespace sharp {
|
|||||||
option = GetOptionsForImageType(imageType, descriptor);
|
option = GetOptionsForImageType(imageType, descriptor);
|
||||||
image = VImage::new_from_file(descriptor->file.data(), option);
|
image = VImage::new_from_file(descriptor->file.data(), option);
|
||||||
}
|
}
|
||||||
} catch (vips::VError const &err) {
|
} catch (std::runtime_error const &err) {
|
||||||
throw vips::VError(std::string("Input file has corrupt header: ") + err.what());
|
throw std::runtime_error(std::string("Input file has corrupt header: ") + err.what());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw vips::VError("Input file contains unsupported image format");
|
throw std::runtime_error("Input file contains unsupported image format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -612,7 +612,7 @@ namespace sharp {
|
|||||||
// Limit input images to a given number of pixels, where pixels = width * height
|
// Limit input images to a given number of pixels, where pixels = width * height
|
||||||
if (descriptor->limitInputPixels > 0 &&
|
if (descriptor->limitInputPixels > 0 &&
|
||||||
static_cast<uint64_t>(image.width()) * image.height() > descriptor->limitInputPixels) {
|
static_cast<uint64_t>(image.width()) * image.height() > descriptor->limitInputPixels) {
|
||||||
throw vips::VError("Input image exceeds pixel limit");
|
throw std::runtime_error("Input image exceeds pixel limit");
|
||||||
}
|
}
|
||||||
return std::make_tuple(image, imageType);
|
return std::make_tuple(image, imageType);
|
||||||
}
|
}
|
||||||
@@ -788,19 +788,19 @@ namespace sharp {
|
|||||||
: image.height();
|
: image.height();
|
||||||
if (imageType == ImageType::JPEG) {
|
if (imageType == ImageType::JPEG) {
|
||||||
if (image.width() > 65535 || height > 65535) {
|
if (image.width() > 65535 || height > 65535) {
|
||||||
throw vips::VError("Processed image is too large for the JPEG format");
|
throw std::runtime_error("Processed image is too large for the JPEG format");
|
||||||
}
|
}
|
||||||
} else if (imageType == ImageType::WEBP) {
|
} else if (imageType == ImageType::WEBP) {
|
||||||
if (image.width() > 16383 || height > 16383) {
|
if (image.width() > 16383 || height > 16383) {
|
||||||
throw vips::VError("Processed image is too large for the WebP format");
|
throw std::runtime_error("Processed image is too large for the WebP format");
|
||||||
}
|
}
|
||||||
} else if (imageType == ImageType::GIF) {
|
} else if (imageType == ImageType::GIF) {
|
||||||
if (image.width() > 65535 || height > 65535) {
|
if (image.width() > 65535 || height > 65535) {
|
||||||
throw vips::VError("Processed image is too large for the GIF format");
|
throw std::runtime_error("Processed image is too large for the GIF format");
|
||||||
}
|
}
|
||||||
} else if (imageType == ImageType::HEIF) {
|
} else if (imageType == ImageType::HEIF) {
|
||||||
if (image.width() > 16384 || height > 16384) {
|
if (image.width() > 16384 || height > 16384) {
|
||||||
throw vips::VError("Processed image is too large for the HEIF format");
|
throw std::runtime_error("Processed image is too large for the HEIF format");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
||||||
try {
|
try {
|
||||||
std::tie(image, imageType) = OpenInput(baton->input);
|
std::tie(image, imageType) = OpenInput(baton->input);
|
||||||
} catch (vips::VError const &err) {
|
} catch (std::runtime_error const &err) {
|
||||||
(baton->err).append(err.what());
|
(baton->err).append(err.what());
|
||||||
}
|
}
|
||||||
if (imageType != sharp::ImageType::UNKNOWN) {
|
if (imageType != sharp::ImageType::UNKNOWN) {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#include "./operations.h"
|
#include "./operations.h"
|
||||||
|
|
||||||
using vips::VImage;
|
using vips::VImage;
|
||||||
using vips::VError;
|
|
||||||
|
|
||||||
namespace sharp {
|
namespace sharp {
|
||||||
/*
|
/*
|
||||||
@@ -287,7 +286,7 @@ namespace sharp {
|
|||||||
*/
|
*/
|
||||||
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt, int const margin) {
|
VImage Trim(VImage image, std::vector<double> background, double threshold, bool const lineArt, int const margin) {
|
||||||
if (image.width() < 3 && image.height() < 3) {
|
if (image.width() < 3 && image.height() < 3) {
|
||||||
throw VError("Image to trim must be at least 3x3 pixels");
|
throw std::runtime_error("Image to trim must be at least 3x3 pixels");
|
||||||
}
|
}
|
||||||
if (background.size() == 0) {
|
if (background.size() == 0) {
|
||||||
// Top-left pixel provides the default background colour if none is given
|
// Top-left pixel provides the default background colour if none is given
|
||||||
@@ -361,7 +360,7 @@ namespace sharp {
|
|||||||
VImage Linear(VImage image, std::vector<double> const a, std::vector<double> const b) {
|
VImage Linear(VImage image, std::vector<double> const a, std::vector<double> const b) {
|
||||||
size_t const bands = static_cast<size_t>(image.bands());
|
size_t const bands = static_cast<size_t>(image.bands());
|
||||||
if (a.size() > bands) {
|
if (a.size() > bands) {
|
||||||
throw VError("Band expansion using linear is unsupported");
|
throw std::runtime_error("Band expansion using linear is unsupported");
|
||||||
}
|
}
|
||||||
bool const uchar = !Is16Bit(image.interpretation());
|
bool const uchar = !Is16Bit(image.interpretation());
|
||||||
if (image.has_alpha() && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
|
if (image.has_alpha() && a.size() != bands && (a.size() == 1 || a.size() == bands - 1 || bands - 1 == 1)) {
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
sharp::SetDensity(image, baton->input->density);
|
sharp::SetDensity(image, baton->input->density);
|
||||||
if (image.width() > 32767 || image.height() > 32767) {
|
if (image.width() > 32767 || image.height() > 32767) {
|
||||||
throw vips::VError("Input SVG image will exceed 32767x32767 pixel limit when scaled");
|
throw std::runtime_error("Input SVG image will exceed 32767x32767 pixel limit when scaled");
|
||||||
}
|
}
|
||||||
} else if (inputImageType == sharp::ImageType::PDF) {
|
} else if (inputImageType == sharp::ImageType::PDF) {
|
||||||
if (baton->input->buffer != nullptr) {
|
if (baton->input->buffer != nullptr) {
|
||||||
@@ -290,7 +290,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (inputImageType == sharp::ImageType::SVG && (image.width() > 32767 || image.height() > 32767)) {
|
if (inputImageType == sharp::ImageType::SVG && (image.width() > 32767 || image.height() > 32767)) {
|
||||||
throw vips::VError("Input SVG image exceeds 32767x32767 pixel limit");
|
throw std::runtime_error("Input SVG image exceeds 32767x32767 pixel limit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (baton->input->autoOrient) {
|
if (baton->input->autoOrient) {
|
||||||
@@ -675,7 +675,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
// Verify within current dimensions
|
// Verify within current dimensions
|
||||||
if (compositeImage.width() > image.width() || compositeImage.height() > image.height()) {
|
if (compositeImage.width() > image.width() || compositeImage.height() > image.height()) {
|
||||||
throw vips::VError("Image to composite must have same dimensions or smaller");
|
throw std::runtime_error("Image to composite must have same dimensions or smaller");
|
||||||
}
|
}
|
||||||
// Check if overlay is tiled
|
// Check if overlay is tiled
|
||||||
if (composite->tile) {
|
if (composite->tile) {
|
||||||
@@ -1086,20 +1086,19 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Get raw image data
|
// Get raw image data
|
||||||
baton->bufferOut = static_cast<char*>(image.write_to_memory(&baton->bufferOutLength));
|
baton->bufferOut = static_cast<char*>(image.write_to_memory(&baton->bufferOutLength));
|
||||||
if (baton->bufferOut == nullptr) {
|
if (baton->bufferOut == nullptr) {
|
||||||
(baton->err).append("Could not allocate enough memory for raw output");
|
throw std::runtime_error("Could not allocate enough memory for raw output");
|
||||||
return Error();
|
|
||||||
}
|
}
|
||||||
baton->formatOut = "raw";
|
baton->formatOut = "raw";
|
||||||
} else {
|
} else {
|
||||||
// Unsupported output format
|
// Unsupported output format
|
||||||
(baton->err).append("Unsupported output format ");
|
auto unsupported = std::string("Unsupported output format ");
|
||||||
if (baton->formatOut == "input") {
|
if (baton->formatOut == "input") {
|
||||||
(baton->err).append("when trying to match input format of ");
|
unsupported.append("when trying to match input format of ");
|
||||||
(baton->err).append(ImageTypeId(inputImageType));
|
unsupported.append(ImageTypeId(inputImageType));
|
||||||
} else {
|
} else {
|
||||||
(baton->err).append(baton->formatOut);
|
unsupported.append(baton->formatOut);
|
||||||
}
|
}
|
||||||
return Error();
|
throw std::runtime_error(unsupported);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// File output
|
// File output
|
||||||
@@ -1274,7 +1273,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
return Error();
|
return Error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (vips::VError const &err) {
|
} catch (std::runtime_error const &err) {
|
||||||
char const *what = err.what();
|
char const *what = err.what();
|
||||||
if (what && what[0]) {
|
if (what && what[0]) {
|
||||||
(baton->err).append(what);
|
(baton->err).append(what);
|
||||||
@@ -1306,7 +1305,6 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
warning = sharp::VipsWarningPop();
|
warning = sharp::VipsWarningPop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baton->err.empty()) {
|
if (baton->err.empty()) {
|
||||||
int width = baton->width;
|
int width = baton->width;
|
||||||
int height = baton->height;
|
int height = baton->height;
|
||||||
@@ -1407,7 +1405,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
void MultiPageUnsupported(int const pages, std::string op) {
|
void MultiPageUnsupported(int const pages, std::string op) {
|
||||||
if (pages > 1) {
|
if (pages > 1) {
|
||||||
throw vips::VError(op + " is not supported for multi-page images");
|
throw std::runtime_error(op + " is not supported for multi-page images");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
sharp::ImageType imageType = sharp::ImageType::UNKNOWN;
|
||||||
try {
|
try {
|
||||||
std::tie(image, imageType) = OpenInput(baton->input);
|
std::tie(image, imageType) = OpenInput(baton->input);
|
||||||
} catch (vips::VError const &err) {
|
} catch (std::runtime_error const &err) {
|
||||||
(baton->err).append(err.what());
|
(baton->err).append(err.what());
|
||||||
}
|
}
|
||||||
if (imageType != sharp::ImageType::UNKNOWN) {
|
if (imageType != sharp::ImageType::UNKNOWN) {
|
||||||
@@ -92,7 +92,7 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
baton->dominantRed = dx * 16 + 8;
|
baton->dominantRed = dx * 16 + 8;
|
||||||
baton->dominantGreen = dy * 16 + 8;
|
baton->dominantGreen = dy * 16 + 8;
|
||||||
baton->dominantBlue = dz * 16 + 8;
|
baton->dominantBlue = dz * 16 + 8;
|
||||||
} catch (vips::VError const &err) {
|
} catch (std::runtime_error const &err) {
|
||||||
(baton->err).append(err.what());
|
(baton->err).append(err.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,7 +112,6 @@ class StatsWorker : public Napi::AsyncWorker {
|
|||||||
debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) });
|
debuglog.Call(Receiver().Value(), { Napi::String::New(env, warning) });
|
||||||
warning = sharp::VipsWarningPop();
|
warning = sharp::VipsWarningPop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baton->err.empty()) {
|
if (baton->err.empty()) {
|
||||||
// Stats Object
|
// Stats Object
|
||||||
Napi::Object info = Napi::Object::New(env);
|
Napi::Object info = Napi::Object::New(env);
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ Napi::Value _maxColourDistance(const Napi::CallbackInfo& info) {
|
|||||||
}
|
}
|
||||||
// Calculate colour distance
|
// Calculate colour distance
|
||||||
maxColourDistance = image1.dE00(image2).max();
|
maxColourDistance = image1.dE00(image2).max();
|
||||||
} catch (vips::VError const &err) {
|
} catch (std::runtime_error const &err) {
|
||||||
throw Napi::Error::New(env, err.what());
|
throw Napi::Error::New(env, err.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user