Permalink
Browse files

moved png loader to imagelib and support jpeg loading, too

support multi-touch emulation on pandora (left shoulder = second finger)
fixed makefile
fixed modules (added request_exit functions)
  • Loading branch information...
1 parent ce1bf3b commit 0b4e573ee7cbad56b26d09060c5d5bc6be51a27c @crowriot crowriot committed Jan 22, 2013
View
@@ -321,9 +321,7 @@ void system_exit()
int main(int argc, char **argv)
{
-#ifdef APKENV_DEBUG
debug_init();
-#endif
char **tmp;
@@ -453,6 +451,9 @@ int main(int argc, char **argv)
module->init(module, platform_getscreenwidth(), platform_getscreenheight(), data_directory);
+ int emulate_multitouch = 0;
+ const int emulate_finger_id = 2;
+
while (1) {
if (module->requests_exit(module)) {
@@ -467,13 +468,34 @@ int main(int argc, char **argv)
module->deinit(module);
goto finish;
}
+#ifdef PANDORA
+ else if (e.key.keysym.sym==SDLK_RSHIFT) {
+ //emulate_multitouch = 1;
+ module->input(module,ACTION_DOWN, platform_getscreenwidth()>>1, platform_getscreenheight()>>1,emulate_finger_id);
+ }
+ }
+ else if (e.type == SDL_KEYUP) {
+ if (e.key.keysym.sym==SDLK_RSHIFT) {
+ //emulate_multitouch = 0;
+ module->input(module,ACTION_UP, platform_getscreenwidth()>>1, platform_getscreenheight()>>1,emulate_finger_id);
+ }
}
+#endif
else if (e.type == SDL_MOUSEBUTTONDOWN) {
module->input(module, ACTION_DOWN, e.button.x, e.button.y, e.button.which);
+ if (emulate_multitouch) {
+ module->input(module,ACTION_DOWN, platform_getscreenwidth()-e.button.x, platform_getscreenheight()-e.button.y,emulate_finger_id);
+ }
} else if (e.type == SDL_MOUSEBUTTONUP) {
module->input(module, ACTION_UP, e.button.x, e.button.y, e.button.which);
+ if (emulate_multitouch) {
+ module->input(module,ACTION_UP, platform_getscreenwidth()-e.button.x, platform_getscreenheight()-e.button.y,emulate_finger_id);
+ }
} else if (e.type == SDL_MOUSEMOTION) {
module->input(module, ACTION_MOVE, e.motion.x, e.motion.y, e.motion.which);
+ if (emulate_multitouch) {
+ module->input(module,ACTION_MOVE, platform_getscreenwidth()-e.button.x, platform_getscreenheight()-e.button.y,emulate_finger_id);
+ }
} else if (e.type == SDL_QUIT) {
module->deinit(module);
goto finish;
View
@@ -15,7 +15,7 @@
<Add option="-g" />
<Add option="-DDEBUG=1" />
<Add option="-DLINKER_DEBUG=2" />
- <Add option="-DAPKENV_DEBUG" />
+ <Add option="-DAPKENV_DEBUGx" />
<Add option="-DAPKENV_GLES" />
</Compiler>
<Linker>
View
@@ -67,7 +67,8 @@ typedef void *(*lookup_symbol_t)(const char *method);
typedef void *(*lookup_lib_symbol_t)(const char *lib, const char *method);
typedef void (*foreach_file_t)(const char *prefix, apk_for_each_file_callback callback);
typedef int (*read_file_t)(const char *filename, char **buffer, size_t *size);
-typedef void (*recursive_mkdir_t)(const char* path);
+typedef void (*recursive_mkdir_t)(const char *path);
+typedef void (*patch_symbol_t)(const char *symbol, void *function);
struct JniLibrary {
struct JniLibrary *next;
View
@@ -3,8 +3,10 @@
#include <assert.h>
#ifdef APKENV_DEBUG
# define WRAPPERS_DEBUG_PRINTF(...) printf(__VA_ARGS__)
+# define GL_TEST_ERROR if (glGetError()!=GL_NO_ERROR) { printf("GL ERROR near %s\n", __FUNCTION__); }
#else
# define WRAPPERS_DEBUG_PRINTF(...)
+# define GL_TEST_ERROR
#endif
void
my_glAlphaFunc(GLenum func, GLclampf ref)
@@ -165,7 +167,10 @@ my_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
void
my_glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
{
- WRAPPERS_DEBUG_PRINTF("glOrthof()\n", left, right, bottom, top, zNear, zFar);
+ WRAPPERS_DEBUG_PRINTF("glOrthof(%f, %f, %f, %f)\n", left, right, bottom, top, zNear, zFar);
+#ifdef LANDSCAPE_TO_PORTRAIT
+ glRotatef(-90,0,0,1);
+#endif
glOrthof(left, right, bottom, top, zNear, zFar);
}
void
@@ -429,7 +434,7 @@ my_glEnable(GLenum cap)
void
my_glEnableClientState(GLenum array)
{
- WRAPPERS_DEBUG_PRINTF("glEnableClientState()\n", array);
+ WRAPPERS_DEBUG_PRINTF("glEnableClientState(0x%x)\n", array);
glEnableClientState(array);
}
void
@@ -868,7 +873,11 @@ void
my_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
{
WRAPPERS_DEBUG_PRINTF("glViewport()\n", x, y, width, height);
+#ifdef LANDSCAPE_TO_PORTRAIT
+ glViewport(x, y, height, width);
+#else
glViewport(x, y, width, height);
+#endif
}
void
my_glPointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *pointer)
View
@@ -74,7 +74,7 @@
{"ioctl", ioctl},
{"mmap", mmap},
-{"munmap", my_munmap},
+{"munmap", munmap},
{"poll", poll},
{"mkdir", mkdir},
View
@@ -103,7 +103,7 @@ my_exp(double __x)
int
my_fclose(FILE *__stream)
{
- //WRAPPERS_DEBUG_PRINTF("fclose(%x, %x)\n", __stream, &my___sF);
+ WRAPPERS_DEBUG_PRINTF("fclose(%x, %x)\n", __stream, &my___sF);
int offset = ((void*)__stream - (void*)(&my___sF));
//printf("offset: %d\n", offset);
if (offset < 1000) {
@@ -139,8 +139,10 @@ my_fmod(double __x, double __y)
FILE *
my_fopen(__const char *__restrict __filename, __const char *__restrict __modes)
{
- //WRAPPERS_DEBUG_PRINTF("fopen(%s, %s)\n", __filename, __modes);
- return fopen(__filename, __modes);
+ WRAPPERS_DEBUG_PRINTF("fopen(%s, %s)\n", __filename, __modes);
+ FILE *f = fopen(__filename,__modes);
+ WRAPPERS_DEBUG_PRINTF("fopen(%s, %s) -> %x\n", __filename, __modes, f);
+ return f;
}
int
my_fputc(int __c, FILE *__stream)
@@ -591,7 +593,7 @@ my_strstr(__const char *__haystack, __const char *__needle)
double
my_strtod(__const char *__restrict __nptr, char **__restrict __endptr)
{
- //WRAPPERS_DEBUG_PRINTF("strtod()\n", __nptr, __endptr);
+ WRAPPERS_DEBUG_PRINTF("strtod()\n", __nptr, __endptr);
return strtod(__nptr, __endptr);
}
char *
@@ -671,7 +673,7 @@ my_write(int __fd, __const void *__buf, size_t __n)
int
my_fprintf(FILE *stream, const char *format, ...)
{
- //WRAPPERS_DEBUG_PRINTF("my_fprintf(%x, %s)\n", stream, format);
+ WRAPPERS_DEBUG_PRINTF("my_fprintf(%x, %s)\n", stream, format);
va_list ap;
va_start(ap, format);
int result = vfprintf(stderr, format, ap);
@@ -682,14 +684,14 @@ my_fprintf(FILE *stream, const char *format, ...)
int
my_vfprintf(FILE *stream, const char *format, va_list ap)
{
- //WRAPPERS_DEBUG_PRINTF("my_vfprintf(%x, %s)\n", stream, format);
+ WRAPPERS_DEBUG_PRINTF("my_vfprintf(%x, %s)\n", stream, format);
return vfprintf(stderr, format, ap);
}
int
my_fflush(FILE *stream)
{
- //WRAPPERS_DEBUG_PRINTF("my_fflush(%x)\n", stream);
+ WRAPPERS_DEBUG_PRINTF("my_fflush(%x)\n", stream);
int offset = ((void*)stream - (void*)(&my___sF));
//printf("offset: %d\n", offset);
if (offset < 1000) {
@@ -725,7 +727,3 @@ int my_vsnprintf(char *str, size_t size, const char *format, va_list ap)
return vsnprintf(str, size, format, ap);
}
-int my_munmap(void* __addr, size_t __len)
-{
- return munmap(__addr,__len);
-}
View
@@ -0,0 +1,36 @@
+#ifndef IMAGELIB_H
+#define IMAGELIB_h
+
+/// image lib, (c) crow_riot 2013
+
+
+typedef struct {
+ unsigned char* data;
+ int width;
+ int height;
+ int bpp;
+} image_t;
+
+
+typedef struct {
+ /// flip horizontally
+ int swapy;
+ /// convert image data to rgba
+ int forcergba;
+ /// swap red and blue channels (bgr<>rgb)
+ int swaprb;
+ /// the alpha value to be used when image conversion takes place
+ /// and the source file does not provide an alpha
+ unsigned char alpha;
+} imageloadersettings_t;
+
+
+/// load png from disk
+image_t* loadpng(const char *filename, const imageloadersettings_t settings);
+
+/// load jpeg from disk
+/// please not that only rgb jpeg images are suported by the loader, no color indexed ones!
+image_t* loadjpeg(const char *filename, const imageloadersettings_t settings);
+
+
+#endif
@@ -2,36 +2,40 @@
#include <stdio.h>
#include <libpng12/png.h>
-#include "loadpng.h"
+#include <stdlib.h>
+#include "imagelib.h"
-image_t* loadpng( const char *filepath, int swapy, int force_rgba, int swap_rb)
+image_t* loadpng( const char *filepath, const imageloadersettings_t settings)
{
FILE *fp = fopen(filepath,"rb");
if (!fp)
return NULL;
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
if ( !png_ptr ) {
+ fclose(fp);
return NULL;
}
png_infop info = png_create_info_struct(png_ptr);
if ( !info ) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
+ fclose(fp);
return NULL;
}
if ( setjmp(png_jmpbuf(png_ptr)) ) {
png_destroy_read_struct(&png_ptr, &info, NULL);
+ fclose(fp);
return NULL;
}
png_init_io(png_ptr,fp);
png_set_sig_bytes(png_ptr,0);
- int png_transforms = PNG_TRANSFORM_STRIP_16|PNG_TRANSFORM_SWAP_ENDIAN|PNG_TRANSFORM_PACKING|PNG_TRANSFORM_EXPAND|(swap_rb?PNG_TRANSFORM_BGR:0);
+ int png_transforms = PNG_TRANSFORM_STRIP_16|PNG_TRANSFORM_SWAP_ENDIAN|PNG_TRANSFORM_PACKING|PNG_TRANSFORM_EXPAND|(settings.swaprb?PNG_TRANSFORM_BGR:0);
png_read_png(png_ptr, info, png_transforms, NULL);
@@ -56,29 +60,29 @@ image_t* loadpng( const char *filepath, int swapy, int force_rgba, int swap_rb)
}
if ( bytepp==0 ) {
+ fclose(fp);
png_destroy_read_struct(&png_ptr, &info, NULL);
return NULL;
}
- if (bytepp==4)
- force_rgba = 0;
+ int forcergba = settings.forcergba && color_type!=PNG_COLOR_TYPE_RGBA;
image_t* image = malloc(sizeof(image_t));
- image->data = malloc(sizeof(unsigned char)*width*height*(force_rgba?4:bytepp));
+ image->data = malloc(sizeof(unsigned char)*width*height*(forcergba?4:bytepp));
image->width = width;
image->height = height;
image->bpp = bytepp;
- int stride = width*(force_rgba?4:bytepp);
+ int stride = width*(forcergba?4:bytepp);
png_bytepp row_pointers = png_get_rows(png_ptr, info);
int x,y;
- if (!force_rgba) {
- if (swapy) {
+ if (!forcergba) {
+ if (settings.swapy) {
for ( y=0; y<image->height; y++ )
memcpy(image->data+stride*(image->height-1-y), row_pointers[y], rowbytes);
}
@@ -93,16 +97,49 @@ image_t* loadpng( const char *filepath, int swapy, int force_rgba, int swap_rb)
unsigned char* src = row_pointers[y];
unsigned char* trg = image->data+stride*y;
for ( x=0; x<image->width; x++ ) {
- trg[x*4+0] = src[x*bytepp+0];
- trg[x*4+1] = src[x*bytepp+1];
- trg[x*4+2] = src[x*bytepp+2];
- trg[x*4+3] = 255;
+ int tx = x*4;
+ int sx = x*bytepp;
+ trg[tx+0] = src[sx+0];
+ trg[tx+1] = src[sx+1];
+ trg[tx+2] = src[sx+2];
+ trg[tx+3] = settings.alpha;
+ }
+ }
+ }
+ else
+ if (color_type==PNG_COLOR_TYPE_GRAY) {
+ for ( y=0;y<image->height;y++ ) {
+ unsigned char* src = row_pointers[y];
+ unsigned char* trg = image->data+stride*y;
+ for ( x=0; x<image->width; x++ ) {
+ int tx = x*4;
+ int sx = x*bytepp;
+ trg[tx+0] = src[sx];
+ trg[tx+1] = src[sx];
+ trg[tx+2] = src[sx];
+ trg[tx+3] = settings.alpha;
+ }
+ }
+ }
+ else
+ if (color_type==PNG_COLOR_TYPE_GRAY_ALPHA) {
+ for ( y=0;y<image->height;y++ ) {
+ unsigned char* src = row_pointers[y];
+ unsigned char* trg = image->data+stride*y;
+ for ( x=0; x<image->width; x++ ) {
+ int tx = x*4;
+ int sx = x*bytepp;
+ trg[tx+0] = src[sx];
+ trg[tx+1] = src[sx];
+ trg[tx+2] = src[sx];
+ trg[tx+3] = src[sx+1];
}
}
}
}
png_destroy_read_struct(&png_ptr, &info, NULL);
+ fclose(fp);
return image;
}
View
@@ -45,6 +45,11 @@ struct dummy_byte_array {
long size;
};
+struct dummy_float_array {
+ float *data;
+ long size;
+};
+
struct dummy_jclass {
char *name;
};
View
@@ -159,8 +159,8 @@ const char *linker_get_error(void)
*/
extern void __attribute__((noinline)) rtld_db_dlactivity(void);
-static struct r_debug _r_debug = {1, NULL, &rtld_db_dlactivity,
- RT_CONSISTENT, 0};
+//static struct r_debug _r_debug = {1, NULL, &rtld_db_dlactivity,
+// RT_CONSISTENT, 0};
static struct link_map *r_debug_tail = 0;
static pthread_mutex_t _r_debug_lock = PTHREAD_MUTEX_INITIALIZER;
Oops, something went wrong.

0 comments on commit 0b4e573

Please sign in to comment.