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

RGBtoGray must the input be 32bit aligned?

uus831
Beginner
607 Views

I'm trying to convert a 24-bit image to Gray using ippiRGBToGray_8u_C3C1R function, but the output is corrupted when the image width cannot be divided with 8. For example, if the image width is 560, it works, but if it is 563 the output is corrupted. The image is allocated using the normal "new" keyword of C++ such as this

byte *src = new byte[width*height*3];

IppiSize roiSize = {width, height};

IppStatus s = ippiRGBToGray_8u_C3C1R (src,stride24,des,stride8,roiSize);

I am not using specific intel's new function. Must each row of the image start on a 32bit boundary? Why such corruption occur? I'm using IPPI 5.1

0 Kudos
5 Replies
Vladimir_Dudnik
Employee
607 Views

Hello,

there is no requirement to align image rows but if you do that you can expect better performance (because of efficient memory access).

In you piece of code, how do you calculate stride24 and stride8 parameters? Remember, image step, according IPP documentation is number of bytes (including any padding bytes) which required to keep one line of image. In your case stride24 should be width*3 and strude8 should be equal to width (if you do not use padding for your destination image).

Regards,
Vladimir

0 Kudos
uus831
Beginner
607 Views

I define stride8 as image width*bytes per pixel so, in the case of 8-bit destination, stride8 = width*1; and stride24= width*3. However, i'm still experiencing problems when the image width not divisible with 8. I'm using IPPI 5.1 on a Core Duo laptop.

Since the image is declared using new contiguously , i dont think there is any padding done at each rows.

A simple C++ grayscale code however has no problems with any width size of the image.

int

r,g,b;

int pos;

do

{

pos = end*3;

r = *(pSrc+pos)*3735;

g = *(pSrc+pos+1)*19234;

b = *(pSrc+pos+2)*9797;

*(pDest+end) = ( r+ g +b )>>15;

end--;

}

while (end >=0);

Is there anything else i should know? What is the cause of my problems? I wish i can post

the output picture for viewing.

0 Kudos
Vladimir_Dudnik
Employee
607 Views

If you have issues when image width is not divisable to 8 ti means that there is some padding in your image, and you need to pay attention to it

Vladimir

0 Kudos
uus831
Beginner
607 Views

Thanks, you are right! I was loading the bitmap from GDI+, and it seems it is automatically padded. I have fixed the problem. What suprises me is that the normal C++ code runs fine...

Thanks, and i'll be more careful next time! :)

0 Kudos
Vladimir_Dudnik
Employee
607 Views

Great. By the way, "normal" C++ code should corrupt memory n that case, it can not be detected in simple program, by might lead to errors which quite difficult to locate in complex program.

Vladimir

0 Kudos
Reply