×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    4

    drawPixels(short[]) on 6800/3.14

    Hi,

    When I try to draw pixels like this:

    short[] data = new short[2568];
    drawPixels(data, false, 0, 16, 0, 0, 16, 16, 0, DirectGraphics.TYPE_USHORT_444_RGB);

    it works, but with

    drawPixels(data, false, 200, 16, 0, 0, 16, 16, 0, DirectGraphics.TYPE_USHORT_444_RGB);

    it gives an IllegalArgumentException: invalid offset | scanline

    Why? The array should be large enough...

    It seems that the offset should be a multiple of the length of scanline. Offsets 0,16, 32 and so on work. However, this makes no sense as it is said in the api docs that the formula is:

    P(x1, y1) = pixels[offset + (x1 - x) + (y1 - y) * scanlength],
    for each P(x1, y1), where (x <= x1 < x + width) and (y <= y1 < y + height).

    I also tested it on a 6610, and it had similar behavior.

    How am I supposed to store multiple images with different widths (scanline widths)? I hope the cliprect works properly with drawPixels so that I won't need to do the manual clipping...

    BTW, The emulator works like a charm. It seems to follow the formula presented in the docs.

    Thanks.
    Last edited by conrad2k; 2003-05-21 at 13:23.

  2. #2
    Registered User
    Join Date
    May 2003
    Posts
    17
    Got the same problem.
    Wonder if there is any solution...

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    7
    Yes, you are indeed right. The Offset must be an integer multiple of scanlength or drawPixels will throw an error.

    When reading in you graphics you can simply align the position in your storage array to such an integer. Then you can easily store lots of sprites of different sizes in one array, although a little space is wasted.

    The alignment formula (in my code) looks something like this:

    if (offs % width != 0)
    offs -= (offs % width)+width;

    This aligns the offset to the next possible position when reading in the sprites. This works perfect.
    I suspect that drawPixels uses some hardware blitting device to speed up the process, which relies on the above constraint.

    Good luck

    Martin

  4. #4
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    134
    How am I supposed to store multiple images with different widths (scanline widths)?

    How about a single array for each image?

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    17
    About: How am I supposed to store multiple images with different widths (scanline widths)?

    Store the images in a short[imageIndex][pixelIndex] array
    and store these images' width and height in a byte[imageIndex][widthOrHeightIndex]

    eg:

    short[][] imagePixel = {
    { // image 0
    (short)0xF567, (short)0xF890, ......
    },
    { // image 1
    (short)0xF342, (short)0xF123, ......
    },
    .....
    .....
    };


    byte[][] imageSize = {
    { 10, 15 }, // image 0: width=10, height=15
    { 12, 13 }, // image 1: width=12, height=13
    .....
    .....
    };

  6. #6
    Regular Contributor
    Join Date
    Aug 2003
    Posts
    134
    nice solution...

Posting Permissions

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