org.oscim.backend: docs and cleanups

This commit is contained in:
Hannes Janetzek 2013-09-25 05:30:34 +02:00
parent a9d9c97bff
commit 2db1cf8b6c
17 changed files with 171 additions and 105 deletions

View File

@ -66,7 +66,7 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
}
@Override
public int uploadToTexture(boolean replace) {
public void uploadToTexture(boolean replace) {
int format = GLUtils.getInternalFormat(mBitmap);
int type = GLUtils.getType(mBitmap);
@ -76,8 +76,6 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
type);
else
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format, mBitmap, type, 0);
return 0;
}
@Override

View File

@ -55,35 +55,11 @@ public final class AndroidGraphics extends CanvasAdapter {
return null;
}
@Override
public int getColor(Color color) {
switch (color) {
case BLACK:
return android.graphics.Color.BLACK;
case CYAN:
return android.graphics.Color.CYAN;
case TRANSPARENT:
return android.graphics.Color.TRANSPARENT;
case WHITE:
return android.graphics.Color.WHITE;
}
throw new IllegalArgumentException("unknown color value: " + color);
}
@Override
public Paint getPaint() {
return new AndroidPaint();
}
@Override
public int parseColor(String colorString) {
return android.graphics.Color.parseColor(colorString);
}
@Override
public Bitmap getBitmap(int width, int height, int format) {
return new AndroidBitmap(width, height, format);

View File

@ -16,9 +16,10 @@ package org.oscim.android.canvas;
import java.io.InputStream;
import org.oscim.backend.GL20;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.opengl.GLES20;
import android.opengl.GLUtils;
public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
@ -66,18 +67,16 @@ public class AndroidBitmap implements org.oscim.backend.canvas.Bitmap {
}
@Override
public int uploadToTexture(boolean replace) {
public void uploadToTexture(boolean replace) {
int format = GLUtils.getInternalFormat(mBitmap);
int type = GLUtils.getType(mBitmap);
if (replace)
GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, mBitmap, format,
GLUtils.texSubImage2D(GL20.GL_TEXTURE_2D, 0, 0, 0, mBitmap, format,
type);
else
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format, mBitmap, type, 0);
return 0;
GLUtils.texImage2D(GL20.GL_TEXTURE_2D, 0, format, mBitmap, type, 0);
}
@Override

View File

@ -49,35 +49,11 @@ public final class AndroidGraphics extends CanvasAdapter {
return new AndroidBitmap(inputStream);
}
@Override
public int getColor(Color color) {
switch (color) {
case BLACK:
return android.graphics.Color.BLACK;
case CYAN:
return android.graphics.Color.CYAN;
case TRANSPARENT:
return android.graphics.Color.TRANSPARENT;
case WHITE:
return android.graphics.Color.WHITE;
}
throw new IllegalArgumentException("unknown color value: " + color);
}
@Override
public Paint getPaint() {
return new AndroidPaint();
}
@Override
public int parseColor(String colorString) {
return android.graphics.Color.parseColor(colorString);
}
@Override
public Bitmap getBitmap(int width, int height, int format) {
return new AndroidBitmap(width, height, format);

View File

@ -67,7 +67,7 @@ public class AwtBitmap implements Bitmap {
private int dbgCnt;
@Override
public int uploadToTexture(boolean replace) {
public void uploadToTexture(boolean replace) {
int[] pixels;
IntBuffer buffer;
@ -113,8 +113,6 @@ public class AwtBitmap implements Bitmap {
Gdx.gl20.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, width,
height, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, buffer);
return 0;
}
@Override

View File

@ -24,23 +24,11 @@ public class AwtGraphics extends CanvasAdapter {
// do nothing
}
@Override
public int getColor(Color color) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Paint getPaint() {
return new AwtPaint();
}
@Override
public int parseColor(String colorString) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Bitmap getBitmap(int width, int height, int format) {
return new AwtBitmap(width, height, format);

View File

@ -58,7 +58,7 @@ public class GwtBitmap implements Bitmap {
}
@Override
public int uploadToTexture(boolean replace) {
public void uploadToTexture(boolean replace) {
Gdx.gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(),
pixmap.getHeight(), 0,
@ -71,8 +71,6 @@ public class GwtBitmap implements Bitmap {
if (image != null)
RootPanel.get().remove(image);
}
return 1;
}
}

View File

@ -41,23 +41,11 @@ public class GwtCanvasAdapter extends CanvasAdapter {
return new GwtBitmap(fileName);
}
@Override
public int getColor(Color color) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Paint getPaint() {
return new GwtPaint();
}
@Override
public int parseColor(String colorString) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Bitmap getBitmap(int width, int height, int format) {
return new GwtBitmap(width, height, format);

View File

@ -7,10 +7,11 @@ import java.io.InputStream;
*/
public abstract class AssetAdapter {
/** The instance provided by backend */
public static AssetAdapter g;
/**
* Open file as stream.
* Open file from asset path as stream.
*
* @param name the name
* @return the input stream

View File

@ -1,5 +1,4 @@
/*
* Copyright 2010, 2011, 2012 mapsforge.org
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
@ -22,31 +21,59 @@ import org.oscim.backend.canvas.Bitmap;
import org.oscim.backend.canvas.Canvas;
import org.oscim.backend.canvas.Paint;
/**
* The Class CanvasAdapter.
*/
public abstract class CanvasAdapter {
protected static final String TAG = CanvasAdapter.class.getName();
/** The instance provided by backend */
public static CanvasAdapter g;
/** The dpi. */
public static float dpi = 240;
/** The text scale. */
public static float textScale = 1;
public enum Color {
BLACK, CYAN, TRANSPARENT, WHITE;
}
public abstract Bitmap decodeBitmap(InputStream inputStream);
public abstract Bitmap loadBitmapAsset(String fileName);
public abstract int getColor(Color color);
/**
* Create a Canvas.
*
* @return the canvas
*/
public abstract Canvas getCanvas();
/**
* Create Paint.
*
* @return the paint
*/
public abstract Paint getPaint();
public abstract int parseColor(String colorString);
/**
* Create {@link Bitmap} with given dimensions.
*
* @param width the width
* @param height the height
* @param format the format
* @return the bitmap
*/
public abstract Bitmap getBitmap(int width, int height, int format);
public abstract Canvas getCanvas();
/**
* Create {@link Bitmap} from InputStream.
*
* @param inputStream the input stream
* @return the bitmap
*/
public abstract Bitmap decodeBitmap(InputStream inputStream);
/**
* Create {@link Bitmap} from bundled assets.
*
* @param fileName the file name
* @return the bitmap
*/
public abstract Bitmap loadBitmapAsset(String fileName);
protected static Bitmap createBitmap(String src) throws IOException {
if (src == null || src.length() == 0) {
@ -56,7 +83,7 @@ public abstract class CanvasAdapter {
InputStream inputStream = AssetAdapter.g.openFileAsStream(src);
if (inputStream == null) {
Log.e(TAG, "invalid bitmap source: " + src);
Log.e(CanvasAdapter.class.getName(), "invalid bitmap source: " + src);
return null;
}

View File

@ -16,6 +16,7 @@ package org.oscim.backend;
public class GLAdapter {
/** The instance provided by backend */
public static GL20 g;
public static boolean GDX_DESKTOP_QUIRKS;

View File

@ -15,6 +15,8 @@
package org.oscim.backend;
public class Log {
/** The instance provided by backend */
public static Logger logger;
public static void d(String tag, String msg) {

View File

@ -11,6 +11,10 @@ import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
/**
* The Class XMLReaderAdapter. Used by RenderTheme. Note: GWT Backend provides
* its own implementation.
*/
public class XMLReaderAdapter {
public void parse(DefaultHandler handler, InputStream is) throws IOException {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@ -14,17 +14,48 @@
*/
package org.oscim.backend.canvas;
/**
* The Interface Bitmap.
*/
public interface Bitmap {
/**
* Gets the width.
*
* @return the width
*/
int getWidth();
/**
* Gets the height.
*
* @return the height
*/
int getHeight();
/**
* Recycle.
*/
void recycle();
/**
* Gets the pixels as ARGB int array.
*
* @return the pixels
*/
int[] getPixels();
/**
* Erase color, clear Bitmap.
*
* @param color the color
*/
void eraseColor(int color);
int uploadToTexture(boolean replace);
/**
* Upload Bitmap to currently bound GL texture.
*
* @param replace true, when glSubImage2D can be used for upload
*/
void uploadToTexture(boolean replace);
}

View File

@ -1,11 +1,49 @@
/*
* Copyright 2013 Hannes Janetzek
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* Foundation, either version 3 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.oscim.backend.canvas;
/**
* The Interface Canvas.
*/
public interface Canvas {
/**
* Sets the backing {@link Bitmap}.
*
* @param bitmap the new bitmap
*/
void setBitmap(Bitmap bitmap);
/**
* Draw text to Canvas.
*
* @param string the String
* @param x
* @param y
* @param stroke the stroke
*/
void drawText(String string, float x, float y, Paint stroke);
/**
* Draw Bitmap to Canvas.
*
* @param bitmap the Bitmap
* @param x
* @param y
*/
void drawBitmap(Bitmap bitmap, float x, float y);
}

View File

@ -15,20 +15,55 @@
*/
package org.oscim.backend.canvas;
/**
* The Class Color.
*/
public class Color {
/** The Constant BLACK. */
public static final int BLACK = 0xFF000000;
/** The Constant DKGRAY. */
public static final int DKGRAY = 0xFF444444;
/** The Constant GRAY. */
public static final int GRAY = 0xFF888888;
/** The Constant LTGRAY. */
public static final int LTGRAY = 0xFFCCCCCC;
/** The Constant WHITE. */
public static final int WHITE = 0xFFFFFFFF;
/** The Constant RED. */
public static final int RED = 0xFFFF0000;
/** The Constant GREEN. */
public static final int GREEN = 0xFF00FF00;
/** The Constant BLUE. */
public static final int BLUE = 0xFF0000FF;
/** The Constant YELLOW. */
public static final int YELLOW = 0xFFFFFF00;
/** The Constant CYAN. */
public static final int CYAN = 0xFF00FFFF;
/** The Constant MAGENTA. */
public static final int MAGENTA = 0xFFFF00FF;
/** The Constant TRANSPARENT. */
public static final int TRANSPARENT = 0;
/**
* Pack 8 bit r, g, b into one int.
*
* @param r the r
* @param g the g
* @param b the b
* @return the int
*/
public static int get(int r, int g, int b) {
return 0xff << 24 | r << 16 | g << 8 | b;
}
@ -41,6 +76,9 @@ public class Color {
* #AARRGGBB
* 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta',
* 'yellow', 'lightgray', 'darkgray'
*
* @param colorString the color string
* @return the int
*/
public static int parseColor(String colorString) {
if (colorString.charAt(0) == '#') {

View File

@ -14,6 +14,9 @@
*/
package org.oscim.backend.canvas;
/**
* The Interface Paint.
*/
public interface Paint {
public static enum Align {