Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 1,626
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

simple image processing grayscale help

[ Edited ]

I have a jpg loaded and want to change it to grayscale.

 

Here is what my code

 

 

for ( ii = 0; ii < _img.h; ii++)
{
	for ( b = 0; b < _img.w; b++)
	{
		*data = getGrayScale(*data);
		++data;
	}

}


 

the above code works in JAVA.  Is there something wrong with the type conversion or something else?




Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: simple image processing grayscale help

Every pixel is represented by 4 bytes but in your code you replace only first byte without touching three other.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: simple image processing grayscale help

smiley, your edit hides basically all the information that would have been useful in solving the problem, though BGmot presumably saw the original as his answer is correct.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 1,626
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: simple image processing grayscale help

[ Edited ]

Thanks.  Will give it a go.

 

Peter, there was a problem with the func that is why I removed. 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: simple image processing grayscale help

By the way, once you get it working you may want to read this section of the Wikipedia article on grayscales: http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale

Of note is the fact that humans perceive brightness levels of the various colours differently, so weighting R G and B all equally as you are doing may give sub-optimal results.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: simple image processing grayscale help

Oh, forgot to mention - C/C++ is not Java (fortunately!)

-)))))

Highlighted
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: simple image processing grayscale help


smiley wrote:

Peter, there was a problem with the func that is why I removed. 


I know, but you also removed the definition of the variable, which was basically the source of the bug BGmot pointed out.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!