gt: 				if (shift < 0) {
context: // ME4SE - A MicroEdition Emulation for J2SE 
  //
  // Copyright (C) 2001 Stefan Haustein, Oberhausen (Rhld.), Germany
  //
  // Contributors: Geoff Hubbard, Andre Gerard
  //
  // STATUS: 
  //
  // This program is free software; you can redistribute it and/or
  // modify it under the terms of the GNU General Public License as
  // published by the Free Software Foundation; either version 2 of the
  // License, or (at your option) any later version. This program is
  // distributed in the hope that it will be useful, but WITHOUT ANY
  // WARRANTY; without even the implied warranty of MERCHANTABILITY or
  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  // License for more details. You should have received a copy of the
  // GNU General Public License along with this program; if not, write
  // to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  // Boston, MA 02111-1307, USA.
  
  package javax.microedition.lcdui;
  
  import java.awt.image.*;
  import java.io.*;
  
  import javax.microedition.midlet.ApplicationManager;
  
  import org.me4se.impl.lcdui.Color2GrayFilter;
  
  /**
   * @API MIDP-1.0
   * @API MIDP-2.0 
   */
  public class Image {
  
  	/** 
  	 * bit 2 (value 4) seems to indicate odd rotation (90,270=w/h swap). 
  	 * Constants copied here to avoid Sprite dependency */
  
  	private static final int TRANS_NONE = 0;
  	private static final int TRANS_MIRROR_ROT180 = 1;
  	private static final int TRANS_MIRROR = 2;
  	private static final int TRANS_ROT180 = 3;
  	private static final int TRANS_MIRROR_ROT270 = 4;
  	private static final int TRANS_ROT90 = 5;
  	private static final int TRANS_ROT270 = 6;
  	private static final int TRANS_MIRROR_ROT90 = 7;
  
      
  	/** 
  	 * Required for Siemens and Nokia API support. 
  	 * Please note: Drawing operations on images with transparentcy 
  	 * require to obtain a mutable image (without transparency).
  	 *
       * This is best checked in a general "check" method before
       * executing drawing operations in the Graphics class.
  	 * 	 
  	 * @ME4SE INTERNAL 
  	 */
  	public boolean _transparent;
  
  	/** 
  	 * The underlying AWT image, but adopted to the device LCD color. 
       * May contain transparency if not mutable.
  	 * 
  	 * @ME4SE INTERNAL
  	 */
  
      
  	public java.awt.Image _image;
  
  	boolean mutable;
  
  	// IMPROVE: helper does not seem to be referenced anywhere. Is it really needed??
  	static java.awt.Component helper = new java.awt.Panel();
  	String name;
  
      static int imageCreationCount;
      
      
  	/**
  	 * Attention: this call performs the gray filter step!!!
  	 * 
  	 * @ME4SE INTERNAL 
  	 */
  	protected Image(java.awt.Image image, boolean mutable, boolean toGray, String name) {
  		Display.check();
          
          // Give VM some time to cleanup every n images... 
          if(((++imageCreationCount) & 7) == 0){
              try{
                  Thread.sleep(4);
              }
              catch(InterruptedException e){
                  
              }
          }
          
  		if(toGray){
  		    this._image = java.awt.Toolkit.getDefaultToolkit().createImage(
  					new FilteredImageSource(
  						image.getSource(),
  						Color2GrayFilter.instance));
          
  		}
  		else{
  			this._image = image;
  		}
  		this.mutable = mutable;
  		this.name = name;
  	}
  
  	/** 
  	 * MIDP spec requires that every pixel is white. 
  	 * 
  	 * @API MIDP-1.0 
  	 */
  	public static Image createImage(int w, int h) {
  		Display.check();
  
  		java.awt.Image img =
  			ApplicationManager.manager.awtContainer.createImage(w, h);
  		java.awt.Graphics g = img.getGraphics();
  		g.setColor(ApplicationManager.manager.bgColor);
  		g.fillRect(0, 0, w, h);
  
  		return new Image(img, true, false, "createImage(x,y)");
  	}
  
  	/**
  	 * @API MIDP-1.0 
  	 */
  	public static Image createImage(byte[] data, int start, int len) {
  
  		return new Image(
  			ApplicationManager.manager.createImage(data, start, len),
  			false, true, "createImage(byte[] data, start, len)");
  	}
  
  	/**
  	 * @API MIDP-1.0 
  	 */
  	public static Image createImage(String name) throws IOException {
  		return
  			new Image(ApplicationManager.manager.getImage(name), false, true, name);
  	}
  
  	/**
  	 * Additional siemes method
  	 * @API SIEMENS 
  	 */
  	public static Image createImageFromBitmap(
  		byte[] bytes,
  		int width,
  		int height) {
  
  		Display.check();
  
  		int pix[] = new int[width * height];
  		int index = 0;
  
  		int srcPos = 0;
  		int dstPos = 0;
  
  		int bgcolor = ApplicationManager.manager.bgColor.getRGB();
  
  		for (int y = 0; y < height; y++) {
  			int mask = 128;
  			for (int x = 0; x < width; x++) {
  				pix[dstPos++] =
  				 ((((bytes[srcPos] & mask) == 0) ? 0x0ffffffff : 0x0ff000000));
  
  				mask = mask >> 1;
  				if (mask == 0) {
  					mask = 128;
  					srcPos++;
  				}
  			}
  
  			if (mask != 128)
  				srcPos++;
  		}
  
  		return new Image(
  			java.awt.Toolkit.getDefaultToolkit().createImage(
  				new MemoryImageSource(width, height, pix, 0, width)),
  			false,
  			true,
  			"createImageFromBitmap(..)");
  	}
  
  	/**
  	 * Additional siemes method
  	 * 
  	 * @API SIEMENS 
  	 */
  	public static Image createTransparentImageFromBitmap(
  		byte[] bytes,
  		int width,
  		int height) {
  
  		Display.check();
  
  		int pix[] = new int[width * height];
  		int index = 0;
  
  		int srcPos = 0;
  		int dstPos = 0;
  
  		int[] colors =
  			{
  				0x000ffffff,
  				0x0ffffffff,
  				0x0ff000000,
  				0x0ff000000 };
  
  		for (int y = 0; y < height; y++) {
  			int shift = 6;
  			for (int x = 0; x < width; x++) {
  				pix[dstPos++] = colors[(bytes[srcPos] >> shift) & 3];
  
  				shift -= 2;
  