Bitmap Fonts under 1.5 and 1.1

I am using Bitmap Fonts in my Applet, is it bad to use a Image for every character ???

how about the hueing, at the moment i use a RGBFilter to do the hueing, but for every paint, a new image is created and then flushed ( not nice ).

The Applet should be compatbile with java 1.1

I have my own image loader and i load my images from a special compressed format, so maybe its better to have only one image with all chars in it ?

load char after char and put it into one big image in the applet, hue the big image if color of text is different, so only 1 image is created flushed for each paint cycle ???

what about performance ???

i noticed M$ VM 1.1 is buggy and does not flush images correctly, i am running out of memory in my applet and i am running also out of images.

Stop using that nasty 1.1 VM! :stuck_out_tongue:

If you’re going to use 1.5 then don’t try for any backward compatibility with 1.1.

My understanding is that using an image per character is the ‘normal’ way of doing things. Its less intensive to blit an image than to calculate the glyph.

ok sometimes i am paranoid, but it seems i am coding it the normal way.

Unfortunaly I HAVE TO stay 1.1 compatible, dont ask …

20 years ago i coded bitmap fonts like i described above, so i was not thinking about the way i did it.

Question: Whats the best way for hueing a bitmap font, like i described or how to do it best under 1.4 and above ???

turn your chars into palletized BufferedImages and just change the palette before painting.
Never tested, but that should do the trick.

interesting — never tried to create ( or dont know how to ) create a BufferedImage with a 8bit primitive , so my chars live in a DIB , lol

i am bound to 1.1 and upwards coughs, with 1.4 my bitmap drawing and colring is fast like hell, under 1.1 its normal speed, but it eats my image mem ( M$ was too lazy ) and after some time i am running out of memory ( depends on the size of user mem )

even a dispose DOES not help ( nah i am not deaf called this function ) the Image ( the native resources are held in mem )

time is running out for 1.1 only 60 days to go …

BufferedImages didn’t exist for 1.1. You could muck around with the ColorModels for the regular images, but that would be something of a PITA. A much better idea might be to create your own ImageProducer. e.g.:


import java.awt.*;
import java.awt.image.*;

public class GlyphBlitter implements ImageProducer
{   
  private ColorModel model = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0);
  private ImageConsumer consumer;
  private Image image;
    
  private int width;
  private int height;
  private int[][] pixels;
    
  public GlyphBlitter(int width, int height)
  {
    this.width = width;
    this.height = height;

    //Creates space for the lower 128 characters of
    //the ASCII set.
    this.pixels = new int[128][width*height*4];
    this.image = Toolkit.getDefaultToolkit().createImage(this);
  }

  //Make sure you only pass a character between 0
  //and 127!!!
  public void setGlyph(char c, int[] pixels)
  {
    this.pixels[(int)c] = pixels;
  }
    
  //Make sure you only pass a character between 0
  //and 127!!!
  public void render(Graphics g, char c)
  {
    if(consumer != null)
    {
      consumer.setPixels(0, 0, width, height, model, pixels[(int)c], 0, width);
      consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
    }
        
    g.drawImage(image, 0, 0, width, height, null);
  }
    
  public void addConsumer(ImageConsumer consumer)
  {
    this.consumer = consumer;
        
    consumer.setDimensions(width, height);
    consumer.setHints(ImageConsumer.TOPDOWNLEFTRIGHT |
    ImageConsumer.COMPLETESCANLINES |
    ImageConsumer.SINGLEPASS |
    ImageConsumer.SINGLEFRAME);

    consumer.setColorModel(model);
  }
    
  public boolean isConsumer(ImageConsumer imageConsumer)
  {
    //We'll take anyone
    return true;
  }
    
  public void removeConsumer(ImageConsumer imageConsumer)
  {
    //nothing to do
  }
    
  public void requestTopDownLeftRightResend(ImageConsumer imageConsumer)
  {
    //ignore
  }
    
  public void startProduction(ImageConsumer imageConsumer)
  {
    addConsumer(imageConsumer);
  }
    
  //Recolors the character
  public void setColor(char c, int color)
  {
    for(int i=0; i<pixels.length; i++)
    {
      if(pixels[(int)c][i]  != 0x00000000)
      {
        pixels[(int)c][i] = color;
      }
    }
  }  
}

I haven’t actually tried compiling the above, but something like it should do the trick. All you need to do is create the object with the width and height of the characters (I’m assuming that you’re using fixed width), then loop through and set the pixels for each character you need to display. Once you have it loaded, you can render the character by calling “render(Graphics g, char c)” with the character you want to draw. To recolor the character, call “setColor(int color)”.

The only thing I’ve left up to you, is breaking up your images into individual pixel arrays for each character. I might even suggest packing the pixels directly into a file instead of breaking them up when your applet starts. A good example of pixel packing can be found in my Defender game (see: http://java.dnsalias.com/4k). Download the source code, and look in “src/tools/ImagePacker.java”. That program takes a set of graphic files and packs them into a 1 bit per pixel format. A viewer is also included for debugging.

If you have any questions, feel free to ask!

thanks jbanes, i have already a well working pixel packer, and i am using a RGBFilter ( its the same method u use producer --> consumer model )

you only have to add a few lines ( very important for applets, create small classes ).

but it seems, there is at the moment no faster way to use bitmap fonts under 1.1 and 1.4 , so i guess i am doing everything alright ( applet is running smooth ), but i always think about improving and reducing the applet, that was the reason for me to start the thread.

I know nobody will post complete code or secrets ( i will never do because i am bound to nda ), but looking or discusiing about problems is, i think, ok and will not interfere with other problems ( like your boss )

P.S.: i do not recolor my fonts i hue 'em :slight_smile: