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
smiley
Posts: 1,454
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?




Please use plain text.
Developer
BGmot
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.

Please use plain text.
Developer
peter9477
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!
Please use plain text.
Developer
smiley
Posts: 1,454
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. 

Please use plain text.
Developer
peter9477
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!
Please use plain text.
Developer
BGmot
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!)

-)))))

Please use plain text.
Developer
peter9477
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!
Please use plain text.