Question about NPP scaling in MulC functions nppiMulC_8u_C1IRSfs

Hi,

so I have a question about how some of the NPP image processing functions work, specifically the function nppiMulC_8u_C1IRSfs(…);

It has the parameters nConstant and nScaleFactor. Let’s say I have an input pixel value of x, what is my output y? Is it y = x * nConstant / nScaleFactor ?
I’m confused because it’s 8 bit, so what if x * nConstant is out of bounds?

What I want to do is multiply by something like 1.2, I could set nConstant = 12 and nScaleFactor = 10 but does that really do what I expect it to do?

Thanks!

The scalefactor is the exponent power of 2. So the function calculates:

y = x * nConstant / (2^nScaleFactor)

So to multiply by 1.2:
nConstant should be 307, which is round(1.2*256)
nScaleFactor should be 8, because 2^8 is 256.

This allows you to multiply by approx 1.2 by only doing integer operations.

I haven’t confirmed this, but x*nConstant should internally be done using 32-bit registers, so overflow is not an issue at that point. If the number is still out-of-bounds after the divide, it should automatically clamp to the saturate value (255) before it’s sent back to the 8-bit buffer.