qt - QtConcurrent reduce with initial value -


i want calculate bunch of pixels , put them qimage using qtconcurrent::mappedreduced. qimage::setpixel: coordinate (636,442) out of range error. presumably because of using default qimage constructor constructs null image. didn't find way in documentation how set constructor arguments or how provide initial value reduction. there way how this? thought reduction requires specify initial value... in js... qt had different idea.

skeleton:

struct pixel{     qrgb value;     qpoint pos; };  void reducer(qimage &result, const pixel &pixel){     result.setpixel(pixel.pos,pixel.value); } 

i found workaround... code not optimal... because have make check every time reducer runs...

void reducer(qimage &result, const pixel &pixel, int width, int height){     if(result.width()==0)         result = qimage(width,height, qimage::format_rgb888);     result.setpixel(pixel.pos,pixel.value); } ... auto boundreducer = std::bind(reducer,_1,_2,width,height); 

this check cheap, reducer little work, you'll have performance problems no matter what.

to make bit cleaner, check if image default-constructed - i.e. null, , pass intended initial image parameter, instead of passing width/height.

void reducer(qimage &result, const pixel &pixel, const qimage& initial) {     if (result.isnull())        result = initial;     result.setpixel(pixel.pos,pixel.value); }  auto boundreducer = std::bind(reducer, _1, _2,                                qimage(width,height,qimage::format_rgb888)); 

you use class derives qimage , knows how default-construct itself, pass runtime variable arguments such class require use of static member variables. that's of hack think.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo