* Signature: ([J[BII)Ljava/nio/ByteBuffer;\r
*/\r
JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_load\r
- (JNIEnv *, jclass, jlongArray, jbyteArray, jint, jint) {\r
-\r
+ (JNIEnv *env, jclass, jlongArray nativeData, jbyteArray buffer, jint len, jint req_format) {\r
+ char* p_buffer = (char*)env->GetPrimitiveArrayCritical(buffer, 0);\r
+ gdx2d_pixmap* pixmap = gdx2d_load(p_buffer, len, req_format);\r
+ env->ReleasePrimitiveArrayCritical(buffer, p_buffer, 0);\r
+\r
+ if(pixmap==0)\r
+ return 0;\r
+\r
+ jobject pixel_buffer = env->NewDirectByteBuffer((void*)pixmap->pixels, pixmap->width * pixmap->height * pixmap->format);\r
+ long* p_native_data = (long*)env->GetPrimitiveArrayCritical(nativeData, 0);\r
+ p_native_data[0] = (long)pixmap;\r
+ p_native_data[1] = pixmap->width;\r
+ p_native_data[2] = pixmap->height;\r
+ p_native_data[3] = pixmap->format;\r
+ env->ReleasePrimitiveArrayCritical(nativeData, p_native_data, 0);\r
+\r
+ return pixel_buffer;\r
}\r
\r
/*\r
* Signature: ([JIII)Ljava/nio/ByteBuffer;\r
*/\r
JNIEXPORT jobject JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_newPixmap\r
- (JNIEnv *, jclass, jlongArray, jint, jint, jint) {\r
-\r
+ (JNIEnv *env, jclass, jlongArray nativeData, jint width, jint height, jint format) {\r
+ gdx2d_pixmap* pixmap = gdx2d_new(width, height, format);\r
+ if(pixmap==0)\r
+ return 0;\r
+\r
+ jobject pixel_buffer = env->NewDirectByteBuffer((void*)pixmap->pixels, pixmap->width * pixmap->height * pixmap->format);\r
+ long* p_native_data = (long*)env->GetPrimitiveArrayCritical(nativeData, 0);\r
+ p_native_data[0] = (long)pixmap;\r
+ p_native_data[1] = pixmap->width;\r
+ p_native_data[2] = pixmap->height;\r
+ p_native_data[3] = pixmap->format;\r
+ env->ReleasePrimitiveArrayCritical(nativeData, p_native_data, 0);\r
+\r
+ return pixel_buffer;\r
}\r
\r
/*\r
* Signature: (J)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_free\r
- (JNIEnv *, jclass, jlong) {\r
-\r
+ (JNIEnv *, jclass, jlong pixmap) {\r
+ gdx2d_free((gdx2d_pixmap*)pixmap);\r
}\r
\r
/*\r
* Signature: (JI)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_clear\r
- (JNIEnv *, jclass, jlong, jint) {\r
-\r
+ (JNIEnv *, jclass, jlong pixmap, jint color) {\r
+ gdx2d_clear((gdx2d_pixmap*)pixmap, color);\r
}\r
\r
/*\r
* Signature: (JIII)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setPixel\r
- (JNIEnv *, jclass, jlong, jint, jint, jint) {\r
-\r
+ (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint color) {\r
+ gdx2d_set_pixel((gdx2d_pixmap*)pixmap, x, y, color);\r
}\r
\r
/*\r
* Signature: (JIIIII)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawLine\r
- (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) {\r
-\r
+ (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint x2, jint y2, jint color) {\r
+ gdx2d_draw_line((gdx2d_pixmap*)pixmap, x, y, x2, y2, color);\r
}\r
\r
/*\r
* Signature: (JIIIII)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawRect\r
- (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) {\r
-\r
+ (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint width, jint height, jint color) {\r
+ gdx2d_draw_rect((gdx2d_pixmap*)pixmap, x, y, width, height, color);\r
}\r
\r
/*\r
* Signature: (JIIII)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawCircle\r
- (JNIEnv *, jclass, jlong, jint, jint, jint, jint) {\r
-\r
+ (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint radius, jint color) {\r
+ gdx2d_draw_circle((gdx2d_pixmap*)pixmap, x, y, radius, color);\r
}\r
\r
/*\r
* Signature: (JIIIII)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillRect\r
- (JNIEnv *, jclass, jlong, jint, jint, jint, jint, jint) {\r
-\r
+ (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint width, jint height, jint color) {\r
+ gdx2d_fill_rect((gdx2d_pixmap*)pixmap, x, y, width, height, color);\r
}\r
\r
/*\r
* Signature: (JIIII)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_fillCircle\r
- (JNIEnv *, jclass, jlong, jint, jint, jint, jint) {\r
-\r
+ (JNIEnv *, jclass, jlong pixmap, jint x, jint y, jint radius, jint color) {\r
+ gdx2d_fill_circle((gdx2d_pixmap*)pixmap, x, y, radius, color);\r
}\r
\r
/*\r
* Signature: (JJIIIIIIIIII)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawPixmap\r
- (JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint) {\r
+ (JNIEnv *, jclass, jlong src, jlong dst, jint src_x, jint src_y, jint src_width, jint src_height, jint dst_x, jint dst_y, jint dst_width, jint dst_height) {\r
+ gdx2d_draw_pixmap((gdx2d_pixmap*)src, (gdx2d_pixmap*)dst, src_x, src_y, src_width, src_height, dst_x, dst_y, dst_width, dst_height);\r
+}\r
\r
+/*\r
+ * Class: com_badlogic_gdx_graphics_Gdx2DPixmap\r
+ * Method: setBlend\r
+ * Signature: (I)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setBlend\r
+ (JNIEnv *, jclass, jint blend) {\r
+ gdx2d_set_blend(blend);\r
+}\r
+\r
+/*\r
+ * Class: com_badlogic_gdx_graphics_Gdx2DPixmap\r
+ * Method: setScale\r
+ * Signature: (I)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setScale\r
+ (JNIEnv *, jclass, jint scale) {\r
+ gdx2d_set_scale(scale);\r
}\r
/*\r
* Class: com_badlogic_gdx_graphics_Gdx2DPixmap\r
* Method: drawPixmap\r
- * Signature: (JJIIIIIIIIII)V\r
+ * Signature: (JJIIIIIIII)V\r
*/\r
JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_drawPixmap\r
- (JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint);\r
+ (JNIEnv *, jclass, jlong, jlong, jint, jint, jint, jint, jint, jint, jint, jint);\r
+\r
+/*\r
+ * Class: com_badlogic_gdx_graphics_Gdx2DPixmap\r
+ * Method: setBlend\r
+ * Signature: (I)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setBlend\r
+ (JNIEnv *, jclass, jint);\r
+\r
+/*\r
+ * Class: com_badlogic_gdx_graphics_Gdx2DPixmap\r
+ * Method: setScale\r
+ * Signature: (I)V\r
+ */\r
+JNIEXPORT void JNICALL Java_com_badlogic_gdx_graphics_Gdx2DPixmap_setScale\r
+ (JNIEnv *, jclass, jint);\r
\r
#ifdef __cplusplus\r
}\r
#include "gdx2d.h"\r
#define STB_TRUETYPE_IMPLEMENTATION\r
#define STBI_HEADER_FILE_ONLY\r
+#define STBI_NO_FAILURE_STRINGS\r
#include "stb_image.c"\r
#include "stb_truetype.h"\r
+\r
+static int gdx2d_blend = GDX2D_BLEND_NONE;\r
+static int gdx2d_scale = GDX2D_SCALE_NEAREST;\r
+\r
+gdx2d_pixmap* gdx2d_load(const char *buffer, int len, int req_format) {\r
+ int width, height, format;\r
+ const char* pixels = stbi_load_from_memory(buffer, len, &width, &height, &format, req_format);\r
+ if(pixels == NULL)\r
+ return NULL;\r
+\r
+ gdx2d_pixmap* pixmap = (gdx2d_pixmap*)malloc(sizeof(gdx2d_pixmap));\r
+ pixmap->width = width;\r
+ pixmap->height = height;\r
+ pixmap->format = format;\r
+ pixmap->pixels = pixels;\r
+ return pixmap;\r
+}\r
+\r
+gdx2d_pixmap* gdx2d_new(int width, int height, int format) {\r
+ gdx2d_pixmap* pixmap = (gdx2d_pixmap*)malloc(sizeof(gdx2d_pixmap));\r
+ pixmap->width = width;\r
+ pixmap->height = height;\r
+ pixmap->format = format;\r
+ pixmap->pixels = (char*)malloc(width * height * format);\r
+ return pixmap;\r
+}\r
+void gdx2d_free(const gdx2d_pixmap* pixmap) {\r
+ free((void*)pixmap->pixels);\r
+ free((void*)pixmap);\r
+}\r
+\r
+void gdx2d_set_blend (int blend) {\r
+ gdx2d_blend = blend;\r
+}\r
+\r
+void gdx2d_set_scale (int scale) {\r
+ gdx2d_scale = scale;\r
+}\r
+\r
+void gdx2d_clear(const gdx2d_pixmap* pixmap, int col) {\r
+\r
+}\r
+\r
+void gdx2d_set_pixel(const gdx2d_pixmap* pixmap, int x, int y, int col) {\r
+\r
+}\r
+\r
+void gdx2d_draw_line(const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col) {\r
+\r
+}\r
+\r
+void gdx2d_draw_rect(const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col) {\r
+\r
+}\r
+\r
+void gdx2d_draw_circle(const gdx2d_pixmap* pixmap, int x, int y, int radius, int col) {\r
+\r
+}\r
+\r
+void gdx2d_fill_rect(const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col) {\r
+\r
+}\r
+\r
+void gdx2d_fill_circle(const gdx2d_pixmap* pixmap, int x, int y, int radius, int col) {\r
+\r
+}\r
+\r
+void gdx2d_draw_pixmap(const gdx2d_pixmap* src_pixmap, const gdx2d_pixmap* dst_pixmap,\r
+ int src_x, int src_y, int src_width, int src_height,\r
+ int dst_x, int dst_y, int dst_width, int dst_height) {\r
+\r
+}\r
* the dimensions and the format of the pixmap.\r
* the format is one of the GDX2D_FORMAT_XXX constants.\r
*/\r
-struct {\r
+typedef struct {\r
int width;\r
int height;\r
int format;\r
const char* pixels;\r
-} gdx2d_pixmap_struct;\r
-typedef struct gdx2d_pixmap_struct gdx2d_pixmap;\r
+} gdx2d_pixmap;\r
\r
+extern gdx2d_pixmap* gdx2d_load (const char *buffer, int len, int req_format);\r
+extern gdx2d_pixmap* gdx2d_new (int width, int height, int format);\r
+extern void gdx2d_free (const gdx2d_pixmap* pixmap);\r
\r
-gdx2d_pixmap* gdx2d_load_buffer (const char *buffer, int len, int req_format);\r
-gdx2d_pixmap* gdx2d_load_file (const char *filename, int req_format);\r
-gdx2d_pixmap* gdx2d_new (int width, int height, int format);\r
-void gdx2d_free (const gdx2d_pixmap* pixmap);\r
+extern void gdx2d_set_blend (int blend);\r
+extern void gdx2d_set_scale (int scale);\r
\r
-void gdx2d_clear (const gdx2d_pixmap* pixmap, int col);\r
-void gdx2d_set_pixel (const gdx2d_pixmap* pixmap, int x, int y, int col);\r
-void gdx2d_draw_line (const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col);\r
-void gdx2d_draw_rect (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col);\r
-void gdx2d_draw_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
-void gdx2d_fill_rect (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
-void gdx2d_fill_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
-void gdx2d_draw_pixmap (const gdx2d_pixmap* src_pixmap,\r
- const gdx2d_pixmap* dst_pixmap,\r
- int src_x, int src_y, int src_width, int src_height,\r
- int dst_x, int dst_y, int dst_width, int dst_height,\r
- int blend, int scale);\r
+extern void gdx2d_clear (const gdx2d_pixmap* pixmap, int col);\r
+extern void gdx2d_set_pixel (const gdx2d_pixmap* pixmap, int x, int y, int col);\r
+extern void gdx2d_draw_line (const gdx2d_pixmap* pixmap, int x, int y, int x2, int y2, int col);\r
+extern void gdx2d_draw_rect (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col);\r
+extern void gdx2d_draw_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
+extern void gdx2d_fill_rect (const gdx2d_pixmap* pixmap, int x, int y, int width, int height, int col);\r
+extern void gdx2d_fill_circle (const gdx2d_pixmap* pixmap, int x, int y, int radius, int col);\r
+extern void gdx2d_draw_pixmap (const gdx2d_pixmap* src_pixmap,\r
+ const gdx2d_pixmap* dst_pixmap,\r
+ int src_x, int src_y, int src_width, int src_height,\r
+ int dst_x, int dst_y, int dst_width, int dst_height);\r
\r
#ifdef __cplusplus\r
}\r
\r
private void drawPixmap(Gdx2DPixmap src, \r
int srcX, int srcY, int srcWidth, int srcHeight, \r
- int dstX, int dstY, int dstWidth, int dstHeight, \r
- int blend, int scale) {\r
- drawPixmap(src.basePtr, basePtr, srcX, srcY, srcWidth, srcHeight, dstX, dstY, dstWidth, dstHeight, blend, scale);\r
+ int dstX, int dstY, int dstWidth, int dstHeight) {\r
+ drawPixmap(src.basePtr, basePtr, srcX, srcY, srcWidth, srcHeight, dstX, dstY, dstWidth, dstHeight);\r
}\r
\r
\r
private static native void drawCircle(long pixmap, int x, int y, int radius, int color);\r
private static native void fillRect(long pixmap, int x, int y, int width, int height, int color);\r
private static native void fillCircle(long pixmap, int x, int y, int radius, int color);\r
- private static native void drawPixmap(long src, long dst, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight, int blend, int scale);\r
+ private static native void drawPixmap(long src, long dst, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight);\r
+ \r
+ public static native void setBlend(int blend);\r
+ public static native void setScale(int scale);\r
}\r