I want to calculate a bunch of pixels and then put them into a QImage using QtConcurrent::mappedReduced
. But I get QImage::setPixel: coordinate (636,442) out of range
error. That is presumably because of using the default QImage constructor which constructs a null image. I didn't find any way in the documentation how to set the constructor arguments or how to provide the initial value for the reduction. Is there any way how to do this? I thought that reduction requires you to specify the initial value... like in JS... but Qt probably had a different idea.
skeleton:
struct Pixel{
QRgb value;
QPoint pos;
};
void reducer(QImage &result, const Pixel &pixel){
result.setPixel(pixel.pos,pixel.value);
}
I found a workaround... but this code is not optimal... because now i have to make a check every time the 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);