×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    71

    manipulation parameter with drawPixels(byte[]...int manipulation....)

    It seems the manipulation specified is only applied to the pixel data, and not the pixel mask.
    Is this correct?
    (if so, how bloody useless is that!! (

    rob,

    a prompt response would be *realy* helpful

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    71

    RE: manipulation parameter with drawPixels(byte[]...int manipulation....)

    still nothing - does no-one have ne idea?

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

    RE: manipulation parameter with drawPixels(byte[]...int manipulation....)

    Hi,

    This sounds quite strange, it shouldn't be that way. Could you tell more and send the example that shows the baviour? What is the device that you are using.

    regards,

    Petri/Forum Nokia

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Posts
    71

    RE: manipulation parameter with drawPixels(byte[]...int manipulation....)

    here is the complete class - its a wrapper for 2 byte []'s, to allow me to use drawPixels conveniently.

    As I said, it works fine when there is no manipulation, it also works fine when there is a manipulation and no mask. But when there is a mask and a manipulation, it messes up.

    This is using the 6310 emulator beta 0.1 (i don't have hardware to test this on)


    To test my problem, you can integrate this into pretty much any program, by using the createImage(String pngFile) method as the creation method. (this method isn't written for efficiency as I don't use it myself [I read in raw data and use the constructor directly])


    rob,


    Code:
    package chaddock.nokia.util;
    import javax.microedition.lcdui.Graphics;
    import com.nokia.mid.ui.*;
    import java.io.*;
    public class Image
    {
    byte [] data;
    byte [] mask;
    int width, height;
    
    //loads the png file specified by String name, in and then converts it to this format
    public static Image createImage(String name) throws IOException
    {
    InputStream is = null;
    int blocksize = 4096;
    is = name.getClass().getResourceAsStream(name);
    if(is == null) throw new IOException();
    int l = is.available();
    byte buffer[] = new byte[l + 1];
    int length = 0;
    while((l = is.read(buffer, length, buffer.length - length)) != -1)
    {
    length += l;
    if(length == buffer.length)
    {
    byte b[] = new byte[buffer.length + blocksize];
    System.arraycopy(buffer, 0, b, 0, length);
    buffer = b;
    }
    }
    is.close();
    return createImage(DirectUtils.createImage(buffer, 0, length));
    }
    
    //creates a chaddock.nokia.util.Image from a javax.microedition.lcdui.Image
    //the Image must be mutable
    public static Image createImage(javax.microedition.lcdui.Image source)
    {
    int width = source.getWidth();
    int height = source.getHeight();
    int dataLength = width*height;
    if(dataLength%8!=0)
    {
    dataLength= dataLength/8+1;
    }
    else
    {
    dataLength/=8;
    }
    
    byte [] data = new byte[dataLength];
    byte [] mask = new byte[dataLength];
    
    DirectUtils.getDirectGraphics(source.getGraphics()).
    getPixels(data,mask,0,width,0,0,width,height,DirectGraphics.TYPE_BYTE_1_GRAY);
    
    return new Image(data, mask, width, height);
    }
    
    public Image(byte [] data, byte [] mask, int width, int height)
    {
    this.data = data;
    this.mask = mask;
    this.width = width;
    this.height = height;
    }
    
    //clears a rectangle in the data array
    public void clearRect(int x, int y, int width, int height)
    {
    x+= y*this.width;
    y = x+width;
    while(height>0)
    {
    while(x<y)
    {
    data[x/8] |= -128>>>((x%8));
    x++;
    }
    height--;
    x =x-width+this.width;
    y+=this.width;
    }
    }
    
    public void drawImage(Graphics g, int x, int y)
    {
    this.drawImage(DirectUtils.getDirectGraphics(g),x,y, 0);
    }
    
    public void drawImage(DirectGraphics dg, int x, int y)
    {
    this.drawImage(dg,x,y,0);
    }
    
    public void drawImage(Graphics g, int x, int y, int manipulation)
    {
    this.drawImage(DirectUtils.getDirectGraphics(g),x,y, manipulation);
    }
    
    public void drawImage(DirectGraphics dg, int x, int y, int manipulation)
    {
    dg.drawPixels(data,mask, 0, width,x,y,width,height,manipulation,DirectGraphics.TYPE_BYTE_1_GRAY);
    }
    
    public int getWidth()
    {
    return width;
    }
    
    public int getHeight()
    {
    return height;
    }
    }

  5. #5
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    229

    RE: manipulation parameter with drawPixels(byte[]...int manipulation....)

    It wouldn't surprise me, I must say!

    I found some odd glitches with FLIP_HORIZONTAL. I didn't investigated it closely but it seemed to not flip certain columns near the center of the image. I had an image comprising of 8 sprite frames in 2 rows of 4, and the center 2 frames ended up with glitches when drawn flipped.

    In the end it was quicker to just write 10 lines of code to flip the image manually and store it. It takes up more storage that way, but you know it's going to work.

    Cheers,
    Steve

  6. #6
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    229

    RE: manipulation parameter with drawPixels(byte[]...int manipulation....)

    > I mean... was it the mask that was being drawn incorrectly?

    I'm afraid I honestly can't remember. I ended up taking the image and the mask arrays seperately, flipping them myself with a for/loop/byte swap blah blah blah and then drawing them with just a normal drawPixels.

    Have you tried switching the pixel format from HORIZONTAL to VERTICAL, or vice versa, the opposite of whatever you have? I'm just guessing though, since I got lucky and got away with not using any manipulation in the end.

    Sorry,
    Steve

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    14

    RE: manipulation parameter with drawPixels(byte[]...int manipulation....)

    Have you actually tested it on the real phone?

    The implementation of 6310i emulator is a bit crappy, it screws up the drawPixels stuff when you try to play with the scanlength and width. I learnt that the hard way when I was doing a sprite clipping routines...

    - Sampsa

Posting Permissions

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