mirror of
https://github.com/lovell/sharp.git
synced 2025-12-06 03:51:40 +01:00
Use structured binding for tuples where possible
This commit is contained in:
parent
e1628d8ef5
commit
6c1e840098
@ -219,10 +219,10 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
if (!baton->levels.empty()) {
|
if (!baton->levels.empty()) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
|
Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
|
||||||
for (std::pair<int, int> const &l : baton->levels) {
|
for (const auto& [width, height] : baton->levels) {
|
||||||
Napi::Object level = Napi::Object::New(env);
|
Napi::Object level = Napi::Object::New(env);
|
||||||
level.Set("width", l.first);
|
level.Set("width", width);
|
||||||
level.Set("height", l.second);
|
level.Set("height", height);
|
||||||
levels.Set(i++, level);
|
levels.Set(i++, level);
|
||||||
}
|
}
|
||||||
info.Set("levels", levels);
|
info.Set("levels", levels);
|
||||||
@ -279,10 +279,10 @@ class MetadataWorker : public Napi::AsyncWorker {
|
|||||||
if (baton->comments.size() > 0) {
|
if (baton->comments.size() > 0) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Napi::Array comments = Napi::Array::New(env, baton->comments.size());
|
Napi::Array comments = Napi::Array::New(env, baton->comments.size());
|
||||||
for (auto &c : baton->comments) {
|
for (const auto& [keyword, text] : baton->comments) {
|
||||||
Napi::Object comment = Napi::Object::New(env);
|
Napi::Object comment = Napi::Object::New(env);
|
||||||
comment.Set("keyword", c.first);
|
comment.Set("keyword", keyword);
|
||||||
comment.Set("text", c.second);
|
comment.Set("text", text);
|
||||||
comments.Set(i++, comment);
|
comments.Set(i++, comment);
|
||||||
}
|
}
|
||||||
info.Set("comments", comments);
|
info.Set("comments", comments);
|
||||||
|
|||||||
@ -455,12 +455,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
std::tie(image, background) = sharp::ApplyAlpha(image, baton->resizeBackground, shouldPremultiplyAlpha);
|
std::tie(image, background) = sharp::ApplyAlpha(image, baton->resizeBackground, shouldPremultiplyAlpha);
|
||||||
|
|
||||||
// Embed
|
// Embed
|
||||||
int left;
|
const auto& [left, top] = sharp::CalculateEmbedPosition(
|
||||||
int top;
|
|
||||||
std::tie(left, top) = sharp::CalculateEmbedPosition(
|
|
||||||
inputWidth, inputHeight, baton->width, baton->height, baton->position);
|
inputWidth, inputHeight, baton->width, baton->height, baton->position);
|
||||||
int width = std::max(inputWidth, baton->width);
|
const int width = std::max(inputWidth, baton->width);
|
||||||
int height = std::max(inputHeight, baton->height);
|
const int height = std::max(inputHeight, baton->height);
|
||||||
|
|
||||||
image = nPages > 1
|
image = nPages > 1
|
||||||
? sharp::EmbedMultiPage(image,
|
? sharp::EmbedMultiPage(image,
|
||||||
@ -479,13 +477,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Crop
|
// Crop
|
||||||
if (baton->position < 9) {
|
if (baton->position < 9) {
|
||||||
// Gravity-based crop
|
// Gravity-based crop
|
||||||
int left;
|
const auto& [left, top] = sharp::CalculateCrop(
|
||||||
int top;
|
|
||||||
|
|
||||||
std::tie(left, top) = sharp::CalculateCrop(
|
|
||||||
inputWidth, inputHeight, baton->width, baton->height, baton->position);
|
inputWidth, inputHeight, baton->width, baton->height, baton->position);
|
||||||
int width = std::min(inputWidth, baton->width);
|
const int width = std::min(inputWidth, baton->width);
|
||||||
int height = std::min(inputHeight, baton->height);
|
const int height = std::min(inputHeight, baton->height);
|
||||||
|
|
||||||
image = nPages > 1
|
image = nPages > 1
|
||||||
? sharp::CropMultiPage(image,
|
? sharp::CropMultiPage(image,
|
||||||
@ -803,7 +798,7 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
}
|
}
|
||||||
if (image.interpretation() != baton->colourspace) {
|
if (image.interpretation() != baton->colourspace) {
|
||||||
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
|
||||||
if (inputProfile.first && baton->withIccProfile.empty()) {
|
if (inputProfile.first != nullptr && baton->withIccProfile.empty()) {
|
||||||
image = sharp::SetProfile(image, inputProfile);
|
image = sharp::SetProfile(image, inputProfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -860,8 +855,8 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
if (!baton->withExifMerge) {
|
if (!baton->withExifMerge) {
|
||||||
image = sharp::RemoveExif(image);
|
image = sharp::RemoveExif(image);
|
||||||
}
|
}
|
||||||
for (const auto& s : baton->withExif) {
|
for (const auto& [key, value] : baton->withExif) {
|
||||||
image.set(s.first.data(), s.second.data());
|
image.set(key.c_str(), value.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// XMP buffer
|
// XMP buffer
|
||||||
@ -1440,11 +1435,11 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
std::string
|
std::string
|
||||||
AssembleSuffixString(std::string extname, std::vector<std::pair<std::string, std::string>> options) {
|
AssembleSuffixString(std::string extname, std::vector<std::pair<std::string, std::string>> options) {
|
||||||
std::string argument;
|
std::string argument;
|
||||||
for (auto const &option : options) {
|
for (const auto& [key, value] : options) {
|
||||||
if (!argument.empty()) {
|
if (!argument.empty()) {
|
||||||
argument += ",";
|
argument += ",";
|
||||||
}
|
}
|
||||||
argument += option.first + "=" + option.second;
|
argument += key + "=" + value;
|
||||||
}
|
}
|
||||||
return extname + "[" + argument + "]";
|
return extname + "[" + argument + "]";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user