diff --git a/src/metadata.cc b/src/metadata.cc index 73e3f930..2fde7bf6 100644 --- a/src/metadata.cc +++ b/src/metadata.cc @@ -219,10 +219,10 @@ class MetadataWorker : public Napi::AsyncWorker { if (!baton->levels.empty()) { int i = 0; Napi::Array levels = Napi::Array::New(env, static_cast(baton->levels.size())); - for (std::pair const &l : baton->levels) { + for (const auto& [width, height] : baton->levels) { Napi::Object level = Napi::Object::New(env); - level.Set("width", l.first); - level.Set("height", l.second); + level.Set("width", width); + level.Set("height", height); levels.Set(i++, level); } info.Set("levels", levels); @@ -279,10 +279,10 @@ class MetadataWorker : public Napi::AsyncWorker { if (baton->comments.size() > 0) { int i = 0; 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); - comment.Set("keyword", c.first); - comment.Set("text", c.second); + comment.Set("keyword", keyword); + comment.Set("text", text); comments.Set(i++, comment); } info.Set("comments", comments); diff --git a/src/pipeline.cc b/src/pipeline.cc index 23cad078..5f0a3bb0 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -455,12 +455,10 @@ class PipelineWorker : public Napi::AsyncWorker { std::tie(image, background) = sharp::ApplyAlpha(image, baton->resizeBackground, shouldPremultiplyAlpha); // Embed - int left; - int top; - std::tie(left, top) = sharp::CalculateEmbedPosition( + const auto& [left, top] = sharp::CalculateEmbedPosition( inputWidth, inputHeight, baton->width, baton->height, baton->position); - int width = std::max(inputWidth, baton->width); - int height = std::max(inputHeight, baton->height); + const int width = std::max(inputWidth, baton->width); + const int height = std::max(inputHeight, baton->height); image = nPages > 1 ? sharp::EmbedMultiPage(image, @@ -479,13 +477,10 @@ class PipelineWorker : public Napi::AsyncWorker { // Crop if (baton->position < 9) { // Gravity-based crop - int left; - int top; - - std::tie(left, top) = sharp::CalculateCrop( + const auto& [left, top] = sharp::CalculateCrop( inputWidth, inputHeight, baton->width, baton->height, baton->position); - int width = std::min(inputWidth, baton->width); - int height = std::min(inputHeight, baton->height); + const int width = std::min(inputWidth, baton->width); + const int height = std::min(inputHeight, baton->height); image = nPages > 1 ? sharp::CropMultiPage(image, @@ -803,7 +798,7 @@ class PipelineWorker : public Napi::AsyncWorker { } if (image.interpretation() != baton->colourspace) { 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); } } @@ -860,8 +855,8 @@ class PipelineWorker : public Napi::AsyncWorker { if (!baton->withExifMerge) { image = sharp::RemoveExif(image); } - for (const auto& s : baton->withExif) { - image.set(s.first.data(), s.second.data()); + for (const auto& [key, value] : baton->withExif) { + image.set(key.c_str(), value.c_str()); } } // XMP buffer @@ -1440,11 +1435,11 @@ class PipelineWorker : public Napi::AsyncWorker { std::string AssembleSuffixString(std::string extname, std::vector> options) { std::string argument; - for (auto const &option : options) { + for (const auto& [key, value] : options) { if (!argument.empty()) { argument += ","; } - argument += option.first + "=" + option.second; + argument += key + "=" + value; } return extname + "[" + argument + "]"; }