Giter Club home page Giter Club logo

Comments (5)

dtschump avatar dtschump commented on June 30, 2024

Well, if I understand well, you will get this kind of issues with all the CImg<T>::get_*() method, or is it specific to warp() ?

from cimg.

rtobar avatar rtobar commented on June 30, 2024

I haven't really dug that deep to see if this is a general issue with all get_ methods, so I'd assume you're correct. I focused on warp because that's the one in particular we were more worried about in terms of performance.

The question still stands: would such a patch be welcomed? I wouldn't be able to provide a patch for all get_ methods, in case you worry about maintaining full consistency, but maybe ths could be a start. Maybe I could have also named do_warp as get_warp and make it an overload instead of bringing a new name into the mix.

from cimg.

dtschump avatar dtschump commented on June 30, 2024

Considering that it is not really a issue with the get_warp() method, I doubt such a patch is the solution.
Maybe we can think about a more general (and elegant) solution that could apply to all get_*() methods instead.

from cimg.

rtobar avatar rtobar commented on June 30, 2024

Thanks @dtschump for that feedback. I agree that this is a wider problem and not specific to the warp function.

OTOH I don't think there's a solution that will allow you to offer this functionality in a generic way for all functions, given how their outputs' sizes depend so heavily on the input values of each operation. If anything, I think the "generic" solution would be something along the lines of implementing three variants for each method, just like there are two at the moment:

CImg<T> &op(a, b, c); // inline
CImg<T> get_op(a, c, b); // new instance
void get_op(CImg<T> &out, a, c, b); // raw operation

This is obviously a big effort that I wouldn't be able to undertake, and probably neither would you without some clear incentive. If that's the situation, and you'd want to have an all-or-nothing solution, then I'll stick to my patch on our local copy; otherwise if you would consider adding this functionality on a function-by-function basis then I'd be happy to upstream this patch, and others that might come.

from cimg.

dtschump avatar dtschump commented on June 30, 2024

I do actually think there is a generic solution.
Maybe this can be a good start. The example below apply some CImg methods on buffers manually allocated.
All temporary allocations that may happen will be freed by CImg destructors.

#include "CImg.h"
using namespace cimg_library;

int main(int argc, char **argv) {

  // Allocate memory for input image.
  const int width = 512, height = 512, depth = 1, spectrum = 3;
  const float *p_in = new float[width*height*depth*spectrum];

  // Allocate memory for output image.
  const float *p_out = new float[width*height*depth*spectrum];

  // Call a CImg method to fill values in 'p_in'.
  CImg<float>(p_in,width,height,depth,spectrum,true).rand(0,255);

  // Call a method so that p_out contains the resulting image.
  // All temporary allocations will be freed by CImg.
  CImg<float>(p_out,width,height,depth,spectrum,true) =
    CImg<float>(p_in,width,height,depth,spectrum,true).get_blur(10);

  // Display result.
  CImg<float>(p_out,width,height,depth,spectrum,true).display();

  // Free memory.
  delete[] p_in;
  delete[] p_out;

  return 0;
}

Wouldn't it be something like this that you are looking for?

from cimg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.