(keitai-l) Re: Doja limitations

From: Douglas MacDougall <mac_at_gnajp.com>
Date: 12/02/01
Message-ID: <00dc01c17b6d$8306d7c0$060119ac@gna.gnajp.com>
I just made a somewhat interesting discovery. It turns out you can read images from the scratchpad.
This basically solves my entire problem (except for possibly speed.) I just tested this and the only
apparent drawback is the speed which the program writes to the scratchpad. This could be a function
of the emulator. I haven't tested this on a phone, but for anyone interested I copied the code
below.

In order to test this I needed the binary data from a gif. I wrote a quick script to read a file and
print out a java representation which is also included below. For the actual gif image I used the
file "up.gif" from the icons directory of Apache.

Douglas MacDougall
GNA Inc. Japan

package ugly;

import com.nttdocomo.ui.*;
import com.nttdocomo.io.*;
import java.util.*;
import java.lang.*;
import java.io.*;
import javax.microedition.io.*;


public class uglyAppli extends IApplication {

 public void start() {
  Display.setCurrent(new uglyCanvas());
 }

 class uglyCanvas extends Canvas {
 private byte gifData[]={
 0x47,0x49,0x46,0x38,0x39,0x61,0x14,0x00,0x16,0x00,
 (byte)0xA1,0x00,0x00,(byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xCC,(byte)0xFF,(byte)0xFF,0x00,
 0x00,0x00,0x00,0x00,0x00,0x21,(byte)0xFE,0x4E,0x54,0x68,
 0x69,0x73,0x20,0x61,0x72,0x74,0x20,0x69,0x73,0x20,
 0x69,0x6E,0x20,0x74,0x68,0x65,0x20,0x70,0x75,0x62,
 0x6C,0x69,0x63,0x20,0x64,0x6F,0x6D,0x61,0x69,0x6E,
 0x2E,0x20,0x4B,0x65,0x76,0x69,0x6E,0x20,0x48,0x75,
 0x67,0x68,0x65,0x73,0x2C,0x20,0x6B,0x65,0x76,0x69,
 0x6E,0x68,0x40,0x65,0x69,0x74,0x2E,0x63,0x6F,0x6D,
 0x2C,0x20,0x53,0x65,0x70,0x74,0x65,0x6D,0x62,0x65,
 0x72,0x20,0x31,0x39,0x39,0x35,0x00,0x21,(byte)0xF9,0x04,
 0x01,0x00,0x00,0x01,0x00,0x2C,0x00,0x00,0x00,0x00,
 0x14,0x00,0x16,0x00,0x00,0x02,0x23,(byte)0x8C,(byte)0x8F,(byte)0xA9,
 (byte)0xCB,(byte)0xED,0x0F,(byte)0xA3,(byte)0x9C,0x4D,0x08,0x1A,(byte)0xAC,(byte)0x9D,
 0x5A,(byte)0xC7,(byte)0xDE,0x3D,0x20,0x58,(byte)0x8D,(byte)0xA4,0x62,(byte)0x9A,
 0x49,(byte)0x9A,0x1E,0x2C,(byte)0x8B,(byte)0xC5,(byte)0xF2,0x4C,(byte)0xD7,0x76,
 0x50,0x00,0x00,0x3B
};
 Image img;
 MediaImage mi;

 protected uglyCanvas() {
  try
  {
   OutputStream out=Connector.openOutputStream("scratchpad:///0");
   out.write(gifData);
   out.close();
  }
  catch(IOException e){
    System.out.println("Failed write to scratchpad.");
    IApplication.getCurrentApp().terminate();
  }
  try
  {
   mi=MediaManager.getImage("scratchpad:///0");
   mi.use();
  }catch(ConnectionException ce)
  {
   System.out.println("Failed to read image from scratchpad");
   IApplication.getCurrentApp().terminate();
  }
  img=mi.getImage();
  setSoftLabel(SOFT_KEY_2,"QUIT");
 }

 public void processEvent(int type,int param) {
  if(type == Display.KEY_PRESSED_EVENT && param==Display.KEY_SOFT2)
   IApplication.getCurrentApp().terminate();
 }

 public void paint(Graphics g) {
  g.drawImage(img,1,1);
 }
 }
}


The following is an ugly perl script which gets the job done. It reads a file and prints out a java
representation of that file.

Usage: file2java.pl filename
Output:
byte gifData[]={ 0xXX...};

Simply execute this script(requires perl of course) and copy the output into your java source.


#!/usr/bin/perl

unless(scalar(@ARGV)==1)
{
 die("Usage: $0 filename\n");
}
my ($i,$c,$data);

open(F,$ARGV[0]) || die("Failed to open $ARGV[0]: $!\n");
my $size=-s $ARGV[0];
unless($size==read(F,$data,$size))
{
 close(F);
 die("Incomplete read: $!");
}
close(F);
(my $encoded_data = $data) =~
s{([\x00-\xff])}{$c=ord($1);sprintf("%s0x%02X,%s",($c>0x7e?"(byte)":""),$c,++$i%10==0?"\n\t":"")}eg;
;
chop($encoded_data);
print "byte gifData[]={\n\t$encoded_data\n};\n";
exit(0);



[ Need archives? How to unsubscribe? http://www.appelsiini.net/keitai-l/ ]
Received on Sun Dec 2 22:23:43 2001