> Awesome.  That's just what I needed to know.  Implementation
> sounds straightforward but time is of the essence.  I don't
> suppose you would be willing to share your code?

  ok.. :P here it is:

BMPExtractor.java
---
import java.io.*;

public class BMPExtractor
{
  public static void main(String args[]) 
    throws Exception
  {
    RandomAccessFile in = new RandomAccessFile(args[0] + ".bmp", "r");
    long offset = in.length();

    // read in the file dimensions
    in.seek(0x12);
    int width  = in.readUnsignedByte() | (in.readUnsignedByte() << 8);
    in.seek(0x16);
    int height = in.readUnsignedByte() | (in.readUnsignedByte() << 8);

    byte[] image = new byte[(width*height) >> 2];
    int    count = 0;

    offset -= (width >> 1);  
    while (offset > 0x75) {
      in.seek(offset);

      for (int i=0; i<(width >> 2); i++) {

        byte b1 = in.readByte();
        byte b2 = in.readByte(); 
        image[count++] = (byte)
                         ((((b1 & 0x80) == 0x00) ? 0x40 : 0x00) |
                          (((b1 & 0x08) == 0x00) ? 0x10 : 0x00) |
                          (((b2 & 0x80) == 0x00) ? 0x04 : 0x00) |
                          (((b2 & 0x08) == 0x00) ? 0x01 : 0x00)
                         );
      }       

      // next line
      offset -= (width >> 1);  
    }       
    in.close();

    FileOutputStream out = new FileOutputStream(args[0] + ".rle");

    out.write((width & 0xff00) >> 8);
    out.write(width & 0x00ff);
    out.write((height & 0xff00) >> 8);
    out.write(height & 0x00ff);

    for (int i=0; i<count; ) {
      byte  val = image[i++];
      short num = 1;
      while ((num < 255) && (i < count) && (image[i] == val)) {
        num++; i++;
      }
      out.write(val);
      out.write(num & 0xFF);
    }
    out.close();
  }
}
---

  basically, this creates a .rle file from a 16 color windows BMP
  file (i know, hardcoding - but it does the job) :P it works well,
  and i did not want to spend more than 1 hour on it :)

  somehow get it in as a resource to your program and then you can 
  display it taking advantage of the RLE compression.. this code above
  is used to generate a file that is for 2bpp display - in this
  code, the use of more than one color is ignored (it is a background
  bitmap).. download CitiKey and you will see how it is used.

  windows BMP files are stored in a bizzare manner too.. from what
  i saw, they were bottom row first, left to right.. my original
  images were upside down :P

    http://www.citikey.com/

  it took me a few days to figure out how to do this :) however
  i give you a hint - use MemSet() wherever you can.. take advantage
  of screen memory (or in 3.5, bitmap memory) and write huge chunks
  of data at a time. i cannot supply the palmos code as i developed
  it under contract and i no longer own it.

  the display of my bitmaps are REAL time.. very very very fast :)

  cheers

az. 
--
Aaron Ardiri 
Java Certified Programmer      http://www.hig.se/~ardiri/
University-College i G�vle     mailto:[EMAIL PROTECTED]
SE 801 76 G�vle SWEDEN       
Tel: +46 26 64 87 38           Fax: +46 26 64 87 88
Mob: +46 70 656 1143           A/H: +46 26 10 16 11

Reply via email to