From 2f0bbebfc99cb9606b52097807c1887139ea27bc Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 5 Jul 2024 21:34:24 +0100 Subject: [PATCH] Refactor conv op to use slightly safer std::vector Inspired by similar change to recomb op in commit 60c5c50 --- src/operations.cc | 4 ++-- src/operations.h | 2 +- src/pipeline.cc | 2 +- src/pipeline.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/operations.cc b/src/operations.cc index 57790c001..3f0d4b730 100644 --- a/src/operations.cc +++ b/src/operations.cc @@ -164,10 +164,10 @@ namespace sharp { */ VImage Convolve(VImage image, int const width, int const height, double const scale, double const offset, - std::unique_ptr const &kernel_v + std::vector const &kernel_v ) { VImage kernel = VImage::new_from_memory( - kernel_v.get(), + static_cast(const_cast(kernel_v.data())), width * height * sizeof(double), width, height, diff --git a/src/operations.h b/src/operations.h index 8c8791c6b..1dfbe22b4 100644 --- a/src/operations.h +++ b/src/operations.h @@ -53,7 +53,7 @@ namespace sharp { * Convolution with a kernel. */ VImage Convolve(VImage image, int const width, int const height, - double const scale, double const offset, std::unique_ptr const &kernel_v); + double const scale, double const offset, std::vector const &kernel_v); /* * Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen. diff --git a/src/pipeline.cc b/src/pipeline.cc index 1455c5751..de18ee32f 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -1606,7 +1606,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) { baton->convKernelScale = sharp::AttrAsDouble(kernel, "scale"); baton->convKernelOffset = sharp::AttrAsDouble(kernel, "offset"); size_t const kernelSize = static_cast(baton->convKernelWidth * baton->convKernelHeight); - baton->convKernel = std::unique_ptr(new double[kernelSize]); + baton->convKernel.resize(kernelSize); Napi::Array kdata = kernel.Get("kernel").As(); for (unsigned int i = 0; i < kernelSize; i++) { baton->convKernel[i] = sharp::AttrAsDouble(kdata, i); diff --git a/src/pipeline.h b/src/pipeline.h index 163f84f1c..00cd338c4 100644 --- a/src/pipeline.h +++ b/src/pipeline.h @@ -197,7 +197,7 @@ struct PipelineBaton { std::unordered_map withExif; bool withExifMerge; int timeoutSeconds; - std::unique_ptr convKernel; + std::vector convKernel; int convKernelWidth; int convKernelHeight; double convKernelScale;