Efficient design for multiple pixel operations when decompressing an image

Viewed 58

I maintain an image codec that requires post processing of the image with a varying number of simple pixel operations: for example, gain, colour transform, scaling, truncating. Some ops work on single channels, while others (colour transform) work on three channels at a time.

When an image is decoded, it is stored in planar format, one buffer per channel.

I want to design an efficient framework in c++ that can apply a specified series of pixel ops. Since this is the inner loop, I need it to be efficient - pixel ops should be inlined, with minimum branching.

Simplest approach is to have a fixed array of say 20 operands, and pass this array with the actual number of ops to the post-process method. Can someone suggest a more clever way ?

Edit: This would be a block operation, for efficiency, and I do plan on using SIMD to accelerate. So, for each pixel, I want to efficiently perform a configurable sequence of pixel ops, using SIMD instructions.

1 Answers

I would not recommend to execute the pipeline at the pixel level, this will be horribly inefficient (and inapplicable for some operations), do it for whole images.

As you suggested, it is an easy matter to encode the sequence of operations and associated arguments as a list, and write a simple execution engine that will call the desired functions.

Probably some of your operations are done in-place and some other require an extra buffer. You will need to add suitable buffer management. Nothing insurmountable.

Related