Refactor conv op to use slightly safer std::vector

Inspired by similar change to recomb op in commit 60c5c50
This commit is contained in:
Lovell Fuller 2024-07-05 21:34:24 +01:00
parent 60c5c5083d
commit 2f0bbebfc9
4 changed files with 5 additions and 5 deletions

View File

@ -164,10 +164,10 @@ namespace sharp {
*/ */
VImage Convolve(VImage image, int const width, int const height, VImage Convolve(VImage image, int const width, int const height,
double const scale, double const offset, double const scale, double const offset,
std::unique_ptr<double[]> const &kernel_v std::vector<double> const &kernel_v
) { ) {
VImage kernel = VImage::new_from_memory( VImage kernel = VImage::new_from_memory(
kernel_v.get(), static_cast<void*>(const_cast<double*>(kernel_v.data())),
width * height * sizeof(double), width * height * sizeof(double),
width, width,
height, height,

View File

@ -53,7 +53,7 @@ namespace sharp {
* Convolution with a kernel. * Convolution with a kernel.
*/ */
VImage Convolve(VImage image, int const width, int const height, VImage Convolve(VImage image, int const width, int const height,
double const scale, double const offset, std::unique_ptr<double[]> const &kernel_v); double const scale, double const offset, std::vector<double> const &kernel_v);
/* /*
* Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen. * Sharpen flat and jagged areas. Use sigma of -1.0 for fast sharpen.

View File

@ -1606,7 +1606,7 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
baton->convKernelScale = sharp::AttrAsDouble(kernel, "scale"); baton->convKernelScale = sharp::AttrAsDouble(kernel, "scale");
baton->convKernelOffset = sharp::AttrAsDouble(kernel, "offset"); baton->convKernelOffset = sharp::AttrAsDouble(kernel, "offset");
size_t const kernelSize = static_cast<size_t>(baton->convKernelWidth * baton->convKernelHeight); size_t const kernelSize = static_cast<size_t>(baton->convKernelWidth * baton->convKernelHeight);
baton->convKernel = std::unique_ptr<double[]>(new double[kernelSize]); baton->convKernel.resize(kernelSize);
Napi::Array kdata = kernel.Get("kernel").As<Napi::Array>(); Napi::Array kdata = kernel.Get("kernel").As<Napi::Array>();
for (unsigned int i = 0; i < kernelSize; i++) { for (unsigned int i = 0; i < kernelSize; i++) {
baton->convKernel[i] = sharp::AttrAsDouble(kdata, i); baton->convKernel[i] = sharp::AttrAsDouble(kdata, i);

View File

@ -197,7 +197,7 @@ struct PipelineBaton {
std::unordered_map<std::string, std::string> withExif; std::unordered_map<std::string, std::string> withExif;
bool withExifMerge; bool withExifMerge;
int timeoutSeconds; int timeoutSeconds;
std::unique_ptr<double[]> convKernel; std::vector<double> convKernel;
int convKernelWidth; int convKernelWidth;
int convKernelHeight; int convKernelHeight;
double convKernelScale; double convKernelScale;