×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    5

    Incorrect rgb values for jpg images on S40 3rd ed

    Hi,

    I am creating a game which uses some jpg images. When running the game on the Nokia S40 SDK 3rd Ed FP 2, the images are not displayed correctly. This made me run some tests and I discovered that the rgb values of the pixels are altered to differ from the values in the original images.

    For example I load an image which only has one color: rgb 254,128,67. When grabbing the rgb values from the image object after loading it in the midlet, they have been altered to 255,125,60! Similar alterations happen to all the jpg images I've tested and I have tried with a number of different jpg settings for compression and other. The problem is the same on the real device Nokia 5300 as in the emulator. Everything works fine on phones and emulators from other brands however. Also note that png images are handled correctly, the problem is only for jpgs.

    Has anyone experienced the same problem and has any suggestion for a workaround for this? I need the images to have their correct, original rgb values since I am drawing them together with png images.

    Below is a code sample that should print "ARGB:255,254,128,67" but prints "ARGB:255,255,125,50" ...

    Code:
    Image img = Image.createImage("/test.jpg");
    int[] srcpixels=new int[1];
    img.getRGB(srcpixels, 0,1,0,0,1,1);
    System.out.println("ARGB:"+((srcpixels[0] >> 24) & 0xFF) + "," + ((srcpixels[0] >> 16) & 0xFF)+ "," + ((srcpixels[0] >> 8) & 0xFF) + "," + ((srcpixels[0] >> 0) & 0xFF));
    Regards,
    David

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    62

    Re: Incorrect rgb values for jpg images on S40 3rd ed

    Quote Originally Posted by bjudfar
    I am creating a game which uses some jpg images. When running the game on the Nokia S40 SDK 3rd Ed FP 2, the images are not displayed correctly. This made me run some tests and I discovered that the rgb values of the pixels are altered to differ from the values in the original images.

    For example I load an image which only has one color: rgb 254,128,67. When grabbing the rgb values from the image object after loading it in the midlet, they have been altered to 255,125,60! Similar alterations happen to all the jpg images I've tested and I have tried with a number of different jpg settings for compression and other. The problem is the same on the real device Nokia 5300 as in the emulator. Everything works fine on phones and emulators from other brands however. Also note that png images are handled correctly, the problem is only for jpgs.
    Please note the following section from the Javadoc of the getRGB() method:

    Quote Originally Posted by Javadoc
    The returned values are not guaranteed to be identical to values from the original source, such as from createRGBImage or from a PNG image. Color values may be resampled to reflect the display capabilities of the device (for example, red, green or blue pixels may all be represented by the same gray value on a grayscale device).
    So in other words, you need to remember that the screens of the phones are not fully 24 bit RGB (= 16,777,216 colors). (At least yet, maybe at some time in the future.) The Nokia 5300 you seem to be using has according to the specs only an 18 bit display (= 262,144 colors). This means that instead of the full 8-bit-per-pixel color range for each RGB component (8+8+8 = 24), the screen can only display 6 bits per pixel for each RGB component (6+6+6 = 18). This loss of accuracy (only 2^6 = 64 available values for each RGB component instead of the full 2^8 = 256) means that the phone needs to dither the displayed images to the nearest color that the phone can display. And it is these dithered values that you can read back from the Image object using the getRGB() method.

    Quote Originally Posted by bjudfar
    Has anyone experienced the same problem and has any suggestion for a workaround for this? I need the images to have their correct, original rgb values since I am drawing them together with png images.
    For the image colors to work properly, you need to take the amount of available colors into account already when creating the images in your image editing program. Most advanced image editors have the functionality to specify custom color bit depths when creating new images. This way, the images you create are limited to "allowed" color values only and they can be represented exactly as they are on the screen of the phone -- no dithering occurs.


    But yet I'm a bit puzzled, since according to your description PNG files are working and displaying ok, while JPEG files are not. Screen display bit depths should affect and limit all image formats similarly... :-/

  3. #3
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: Incorrect rgb values for jpg images on S40 3rd ed

    Quote Originally Posted by knorring
    But yet I'm a bit puzzled, since according to your description PNG files are working and displaying ok, while JPEG files are not. Screen display bit depths should affect and limit all image formats similarly... :-/
    I was about to post exactly the same thing as you said, but this part made me reconsider, since it doesn't really make sense.

    bjudfar, could you recheck what you said about png images? Are you testing it with the same image in png and jpg format, or is it possible that you simply chose png images that just happened to fit the screen color depth (ie, would extracting the pixel array from the jpg and png on a true color display give you the exact same result)?

    shmoove

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    5

    Re: Incorrect rgb values for jpg images on S40 3rd ed

    Thank you knorring and shmoove for your helpful replies! What you wrote about the bit depths of the displays seems logical, except for the png vs jpg issue.

    Upon the request from shmoove, I ran some tests again with one one-color image saved using photoshop both as png and jpg. The emulator returns correct values for the png and altered values for the jpg. Since the values are correct for the png, the display can handle this specific RGB value, right? The problem should then reside in the handling of jpg images?

  5. #5
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: Incorrect rgb values for jpg images on S40 3rd ed

    Well, my only other guess (and it's just a guess, a Nokia engineer would have to confirm it), is on how the images are decoded by the phone. Most modern phones come with specialized hardware for these tasks (a decoder chip), and maybe the decoders for the different formats just have different "quirks".

    shmoove

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    5

    Re: Incorrect rgb values for jpg images on S40 3rd ed

    Yes, I also suspect it is a flaw in the jpg decoder. However, that leaves me quite discouraged, since the way graphics is used in my game, it becomes very obvious when images are not displayed in the same colors they are meant to have.

    If someone from Nokia reads this, could you please confirm this jpg handling issue in the Nokia S40 3rd FP2? Also, is it specific for this edition or may it be present on other Nokia phones as well?

  7. #7
    Nokia Developer Moderator
    Join Date
    Nov 2006
    Location
    Helsinki
    Posts
    413

    Re: Incorrect rgb values for jpg images on S40 3rd ed

    I tested this, also using a 5300 and a picture that had only one color. For this device JPG and PNG returned slightly different values. The reference phone I used (N71) returned same values for both of the file formats.

    I also noticed that the values my emulator (WTK) returned were different from those returned by Nokia devices.. So the situation might also vary a bit depending on the implementation the manufacturer uses.

    I will file a bug report for this, lets see what happens.

  8. #8
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Incorrect rgb values for jpg images on S40 3rd ed

    bloodredsky,

    This issue will be published in the Technical Library as a known issue soon, and also a issue has been raised with the dev team. no need to spend time filing a bug report.

    Hartti

  9. #9
    Registered User
    Join Date
    Apr 2003
    Posts
    62

    Re: Incorrect rgb values for jpg images on S40 3rd ed

    Quote Originally Posted by knorring
    For the image colors to work properly, you need to take the amount of available colors into account already when creating the images in your image editing program. Most advanced image editors have the functionality to specify custom color bit depths when creating new images. This way, the images you create are limited to "allowed" color values only and they can be represented exactly as they are on the screen of the phone -- no dithering occurs.
    To add to what I wrote above:

    This document from SonyEricsson explains in detail about mobile phone screen palettes with different bit depths, and also how to prepare and optimize your MIDlet image files to use these bit depths using Photoshop and GIMP.

    The document is rather old (from June 2004), since improperly displayed image colors was a bigger problem in the past when phones' displays had smaller bit depths than what new phones currently have.
    Last edited by knorring; 2007-05-29 at 16:36. Reason: typo

Similar Threads

  1. How to get RGB values from PNG Data byte[]
    By allypone in forum Mobile Java Media (Graphics & Sounds)
    Replies: 11
    Last Post: 2009-09-09, 17:37
  2. SIP - S60 3rd Nokia 3250 CSIPMessageElements::Content() returns an incorrect TDesC8?
    By AlfredoRU in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2006-11-08, 05:42
  3. Images in Menus, S40, Netbeans
    By upcork in forum Mobile Java General
    Replies: 2
    Last Post: 2006-09-29, 14:08
  4. font.getHeight returns different values among devices s40
    By dpolyakov in forum Mobile Java General
    Replies: 2
    Last Post: 2004-02-16, 14:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×