Skip to content

Commit

Permalink
Refactor conv op to use slightly safer std::vector
Browse files Browse the repository at this point in the history
Inspired by similar change to recomb op in commit 60c5c50
  • Loading branch information
lovell committed Jul 5, 2024
1 parent 60c5c50 commit 2f0bbeb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<double[]> const &kernel_v
std::vector<double> const &kernel_v
) {
VImage kernel = VImage::new_from_memory(
kernel_v.get(),
static_cast<void*>(const_cast<double*>(kernel_v.data())),
width * height * sizeof(double),
width,
height,
Expand Down
2 changes: 1 addition & 1 deletion src/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<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.
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<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>();
for (unsigned int i = 0; i < kernelSize; i++) {
baton->convKernel[i] = sharp::AttrAsDouble(kdata, i);
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ struct PipelineBaton {
std::unordered_map<std::string, std::string> withExif;
bool withExifMerge;
int timeoutSeconds;
std::unique_ptr<double[]> convKernel;
std::vector<double> convKernel;
int convKernelWidth;
int convKernelHeight;
double convKernelScale;
Expand Down

0 comments on commit 2f0bbeb

Please sign in to comment.