[Interest] QImage + pixel lambdas

Allan Sandfeld Jensen kde at carewolf.com
Sun Jun 3 12:15:05 CEST 2018


On Freitag, 1. Juni 2018 15:38:03 CEST Jason H wrote:
> So I'm doing some qimage analysis/manipulation. I think it would be really
> good if QImage came with a per-pixel function. (Examples below) I'm tired
> of writing the x/y for loops. The really neat thing (not in the examples)
> is using QImage::scanLine(int y) for faster access, and automatically
> choosing the value of p in the lambda based on bit depth.
> 
> Anyone else think this is a good idea?
> 
I would strongly advise the templates use scanLine or raw pointer access. 
Going through the pixel() methods is rather slow. To get any kind of 
performance out of this the whole things need to be inlinable at compile time, 
images are just big that pixel transformations almost always need to consider 
performance (just a 1000x1000 image has 1 million pixels, which is a lot 
bigger than most arrays or lists we usually iterate over).

But providing some helpful templates to cut down on boilerplate code would 
probably not be a bad idea. Check for instance qimage_conversions.cpp for 
function after function with the same boiler-plate shape and a different inner 
conversion method. If you want to try you could try making a private template 
first and cut down on the boiler-plate code there first, and then we can 
discuss it, and consider making it public?

'Allan





More information about the Interest mailing list