Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

MulC_8u problem

alexfarber
Beginner
269 Views

I am trying to multiply 8 bpp image by float factor. The code is:

void Multiply8(unsigned char* image, int imageWidth, int imageHeight, float factor) // factor > 1.0
{
IppiSize roiSize = {imageWidth, imageHeight};

ippiMulC_8u_C1IRSfs(
(int)(factor * 256.0f + 0.5f),
image,imageWidth*sizeof(unsigned char),roiSize,
8);
}

I get incorrect result. For example, trying to multiply image with pixel values 100 by 2.0, I get result 0. It looks like MulC function clips intermediate result (factor * 256) to 0-255 and then divides to 2^8 - with such behavior function is unusable. Is there any solution for this?
IPP version is 5.1.
BTW, ippiMulC_16u_C1IRSfs function gives correct result when intermediate result is out of 0-65535 range. I expect that all calculations are done with 32 bits, with clipping only final result, but ippiMulC_8u_C1IRSfs doesn't behave by this way.

Thank you.

0 Kudos
1 Reply
Vladimir_Dudnik
Employee
269 Views

Hello Alex,

please take a look on comments provided by our experts:

Aswe cansee, our customer tries to call ippiMulC_8u_C1IRSfs function with value (int)(factor * 256.0f + 0.5f) but according to API of the function value has type Ipp8u and when factor = 2.0 we have value = (int)(2.0 * 256.0f + 0.5f) = 512 and after casting to Ipp8u = 0. Certainly, it works correctly for ippiMulC_16u_C1IRSfs function, because result of calculation in the range of Ipp16u.

Regards,
Vladimir

0 Kudos
Reply