views:

32

answers:

2

I would like to create linear gradient using IPP (Integrated Performance Primitives) functions and avoid pixel-by-pixel color manipulation.

In other words, I can't find appropriate function or combination of functions that will alow me to create RGB image with gradient R0 to R1, G0 to G1, B0 to B1 (initial and final RGB values). I can create it manually by cycling each pixel and setting the color but I hope there is more elegant (and fast) way to do it.

A: 

I found some solution. With the help of ippiImageRamp function.

The function creates a one- or three-channel image that can be used as a test image to examine the effect of applying different image processing functions.

The destination image pixel values are computed according to one of the following formulas:

dst(x,y) = offset + slope * x, if axis = ippAxsHorizontal,

dst(x,y) = offset + slope * y, if axis = ippAxsVertical,

dst(x,y) = offset + slope * x * y, if axis = ippAxsBoth

Ross
+1  A: 

The way I understand it, ippiImageRamp can only create grey-value ramps, right?

Alternatively, you could use ippiResizeSqrPixel to resize a 2x2 pixel image to full size with IPPI_INTER_LINEAR interpolation:

RGB0   |   RGB1
---------------                 =>         [Full Sized Image]
RGB0   |   RGB1

The result should be a linear gradient (although I never tried it). If you need a rotated gradient, you could use ippiWarpAffine to scale and rotate at the same time.

nikie
Good idea about ResizeSqrPixel, not sure about performance. I actually use ippiRotate for translation and rotation but ippiWarpAffine can do the job too. ippiImageRamp work on RGB but not independently. My current algorithm actually need only gray-value ramp for initialization.
Ross