/** * MicroEmulator * Copyright (C) 2008 Bartek Teodorczyk <barteo@barteo.net> * * It is licensed under the following two licenses as alternatives: * 1. GNU Lesser General Public License (the "LGPL") version 2.1 or any newer version * 2. Apache License (the "AL") Version 2.0 * * You may not use this file except in compliance with at least one of * the above two licenses. * * You may obtain a copy of the LGPL at * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt * * You may obtain a copy of the AL at * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the LGPL or the AL for the specific language governing permissions and * limitations. * * @version $Id: AndroidMutableImage.java 2222 2009-12-02 18:42:39Z barteo@gmail.com $ */ package org.microemu.android.device; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; import org.microemu.device.MutableImage; import android.graphics.Bitmap; public class AndroidMutableImage extends MutableImage { private Bitmap bitmap; public AndroidMutableImage(int width, int height, boolean withAlpha, int fillColor) { if (withAlpha) { bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.eraseColor(fillColor); } else { bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); bitmap.eraseColor(0xff000000 | fillColor); } } @Override public int[] getData() { // TODO Auto-generated method stub return null; } @Override public Image scale(int w, int h) { return new AndroidImmutableImage(Bitmap.createScaledBitmap(bitmap, w, h, false)); } @Override public Graphics getGraphics() { AndroidDisplayGraphics displayGraphics = new AndroidDisplayGraphics(bitmap); displayGraphics.setColor(0x00000000); displayGraphics.translate(-displayGraphics.getTranslateX(), -displayGraphics.getTranslateY()); return displayGraphics; } @Override public boolean isMutable() { return true; } public Bitmap getBitmap() { return bitmap; } @Override public int getWidth() { return bitmap.getWidth(); } @Override public int getHeight() { return bitmap.getHeight(); } @Override public void getRGB(int []argb, int offset, int scanlength, int x, int y, int width, int height) { if (width <= 0 || height <= 0) return; if (x < 0 || y < 0 || x + width > getWidth() || y + height > getHeight()) throw new IllegalArgumentException("Specified area exceeds bounds of image"); if ((scanlength < 0? -scanlength:scanlength) < width) throw new IllegalArgumentException("abs value of scanlength is less than width"); if (argb == null) throw new NullPointerException("null rgbData"); if (offset < 0 || offset + width > argb.length) throw new ArrayIndexOutOfBoundsException(); if (scanlength < 0) { if (offset + scanlength*(height-1) < 0) throw new ArrayIndexOutOfBoundsException(); } else { if (offset + scanlength*(height-1) + width > argb.length) throw new ArrayIndexOutOfBoundsException(); } bitmap.getPixels(argb, offset, scanlength, x, y, width, height); /* for (int i = 0; i < argb.length; i++) { int a = (argb[i] & 0xFF000000); int b = (argb[i] & 0x00FF0000) >>> 16; int g = (argb[i] & 0x0000FF00) >>> 8; int r = (argb[i] & 0x000000FF); argb[i] = a | (r << 16) | (g << 8) | b; }*/ } }