×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    9

    Problem loading Images in 6600

    I have noticed that, in some Nokia 6600 firmware versions, there are some PNG's that, although perfectly legal (tested in emulator and other handsets and firmware versions), will refuse to load. Have any of you also encountered this problem and found a workaround to it? Does anybody know what pricular part of the PNG is causing the uncompatibility?

    Thanks in advance

  2. #2
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,430

    Re: Problem loading Images in 6600

    Hi,

    Is a particular PNG image causing the problem? Are you using this PNG image from an application ?

    Regards
    Gopal

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    9

    Post Re: Problem loading Images in 6600

    The code I'm trying to get to work is something like this:


    byte[] iImgBuffer = new byte[3705]; // Size of the image
    InputStream vGfxStream;
    ms_vTestCanvas=new TestCanvas();

    vGfxStream=ms_vTestCanvas.getClass().getResourceAsStream("/image.png");
    vGfxStream.read(iImgBuffer);
    vGfxStream.close();

    ms_vImg = Image.createImage(iImgBuffer, 0, iImgBuffer.length);


    I've left out some try/catches to make it clearer. What i want is load an image as bytes, manipulate these bytes, and then build an image with them. In this example there is not even manipulation, it just transforms the image into bytes and then builds it as another image.
    I've tested this on several devices and it works, except on some 6600 with old firmware ( v3.42.1 ). On these phones, the createImage throws an IllegalArgumentException (bad image format). I tried it with many images and only worked with a couple of very small (icon-sized) ones. I tried fiddling with the other ones, altering color depth, number of colors, optimizing and no optimizing the palette, to no avail. It looks like CreateImage from a byte array is either faulty of incredible strict with PNG's. Or, of course, I might be doing something wrong.
    ¿Does anybody have some insight into this? It's really puzzling me, and I need it to work on all 6600's.
    Thanks in advance

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2005
    Location
    Paris
    Posts
    814

    Re: Problem loading Images in 6600

    try this :

    try{
    ms_vImg = Image.createImage("/image.png");
    int[] data = new int[ms_vImg.getWidth() * ms_vImg.getHeight()];
    ms_vImg.getRGB(data, 0, 0, data.length, ms_vImg.getWidth(), ms_vImg.getHeight());
    } catch (IOException ioe) {}

    then you have your image, and data is you pixels array.
    to use your data to create a new image once you have modified it :

    Image newImg = Image.createRGBImage(data, ms_vImg.getWidth(), ms_vImg.getHeight(), true);//or false

    btw, how are you modifiying an image stored as png ?

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    9

    Re: Problem loading Images in 6600

    I need to store it as PNG because I want to change the PNG's palette. By using GetRGB I would have to go through each pixel in the image changing it to its appropriate value, which would take forever and is hard to use reliably because the colors in the pixel array are approximations to the PNG's actual colors.
    When I first faced this problem I thought that maybe I was not calculating the palette's CRC correctly (PNG's are divided in chunks and each has an associated CRC), but then I tried just decoding and re-coding the PNG without changing the data and it failed too, so assuming the PNG initially was correct and had valid CRC's (it was generated with Photoshop), the problem has to be on the phone.
    Interestingly enough, the problem seems to have to do more with the image size than with the palette, as small images ( < 1024 bytes ) could be decoded and recoded with no problems.
    I also found out that some phones ignore the CRC's, at least in the palette data. Once I tried changing the palette's CRC to an arbitrary value and it worked, so it seems the CRC checking is not enforced.

    Thanks anyway for taking the time to answer Much appreciated.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    3

    Re: Problem loading Images in 6600

    Most likely the problem is that the 6600 reads the image data in blocks. If you simply use vGfxStream.read(iImgBuffer) it will only read the first block, so the image data is incomplete. This issue is also mentioned in the Forum Nokia Technical Library document. Quoting the full entry:

    Reading resources from a JAR file KIJ000081
    Description:

    The MIDP 2.0/Monty implementation for the InputStream.read(byte[]) method in the Nokia 6600 device takes a literal reading of the definitions of java.io.InputStream.read(bytes[] b) and java.io.InputStream.read(byte[] b, int off, int len), which indicate that these functions might NOT read the number of bytes equal to the size of the array argument (b.length) before returning, and will indicate the number of bytes that were successfully read as a return value. This is basically because it is a more optimized approach for the implementation.

    NOTE: Because all other InputStream classes (for example, DataInputStream and ByteArrayInputStream) are subclasses of InputStream, this issue is the same for ALL InputStream operations.

    Solution:

    The Java™ programmer (in this case for MIDlets on the Nokia 6600 device, but this is generally the best practice) should always loop until reading is complete and not assume a resource will be read in one go; see the following examples of wrong and right code:


    WRONG

    Code:
    InputStream in = getClass().getResourceAsStream(resource);
    if (in == NULL) return;
    DataInputStream din = new DataInputStream(in);
    int bytes = din.read(data);
    din.close();
    Image I = Image.createImage(data, 0, offset);
    RIGHT

    Code:
    InputStream in = getClass().getResourceAsStream(resource);
    if (in == null) return;
    DataInputStream din = new DataInputStream(in);
    int bytes = 0;
    int offset = 0;
    while (true) {
        bytes = din.read(data, offset, data.length - offset);    
        offset += bytes;
        if (bytes == -1 || offset >= data.length) {
            // may need to handle error condition here!
            break;
        }
    }
    din.close();
    // now it’s safe to assume data is already fully read (or error 
    // occurred) for example, if it was image data..
    Image I = Image.createImage(data, 0, offset);

  7. #7
    Registered User
    Join Date
    Apr 2005
    Posts
    9

    Re: Problem loading Images in 6600

    Thanks a bunch John, that was precisely the problem, I didn't think of that possibility. The problem is that my code worked in some Nokias while in others it didn't, so it's difficult to judge which ones are faulty and which aren't.
    Again, much appreciated

Similar Threads

  1. Recognizer problem on 6600
    By Exit-1 in forum Symbian
    Replies: 3
    Last Post: 2005-09-21, 15:44
  2. 6600 stream problem
    By tdh in forum Bluetooth Technology
    Replies: 1
    Last Post: 2005-04-27, 11:44
  3. image loading problem(nokia 6600)
    By trupt_es in forum Mobile Java General
    Replies: 1
    Last Post: 2004-09-06, 12:43
  4. 6600 and PC Suite problem
    By Quellepacha in forum General Development Questions
    Replies: 0
    Last Post: 2004-08-30, 20:03
  5. Replies: 3
    Last Post: 2004-04-26, 14:58

Posting Permissions

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