Skip to content

Commit

Permalink
moved png loader to imagelib and support jpeg loading, too
Browse files Browse the repository at this point in the history
support multi-touch emulation on pandora (left shoulder = second finger)
fixed makefile
fixed modules (added request_exit functions)
  • Loading branch information
crowriot committed Jan 22, 2013
1 parent ce1bf3b commit 0b4e573
Show file tree
Hide file tree
Showing 20 changed files with 353 additions and 99 deletions.
26 changes: 24 additions & 2 deletions apkenv.c
Expand Up @@ -321,9 +321,7 @@ void system_exit()


int main(int argc, char **argv) int main(int argc, char **argv)
{ {
#ifdef APKENV_DEBUG
debug_init(); debug_init();
#endif


char **tmp; char **tmp;


Expand Down Expand Up @@ -453,6 +451,9 @@ int main(int argc, char **argv)


module->init(module, platform_getscreenwidth(), platform_getscreenheight(), data_directory); module->init(module, platform_getscreenwidth(), platform_getscreenheight(), data_directory);


int emulate_multitouch = 0;
const int emulate_finger_id = 2;

while (1) { while (1) {


if (module->requests_exit(module)) { if (module->requests_exit(module)) {
Expand All @@ -467,13 +468,34 @@ int main(int argc, char **argv)
module->deinit(module); module->deinit(module);
goto finish; 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) { else if (e.type == SDL_MOUSEBUTTONDOWN) {
module->input(module, ACTION_DOWN, e.button.x, e.button.y, e.button.which); 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) { } else if (e.type == SDL_MOUSEBUTTONUP) {
module->input(module, ACTION_UP, e.button.x, e.button.y, e.button.which); 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) { } else if (e.type == SDL_MOUSEMOTION) {
module->input(module, ACTION_MOVE, e.motion.x, e.motion.y, e.motion.which); 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) { } else if (e.type == SDL_QUIT) {
module->deinit(module); module->deinit(module);
goto finish; goto finish;
Expand Down
2 changes: 1 addition & 1 deletion apkenv.cbp
Expand Up @@ -15,7 +15,7 @@
<Add option="-g" /> <Add option="-g" />
<Add option="-DDEBUG=1" /> <Add option="-DDEBUG=1" />
<Add option="-DLINKER_DEBUG=2" /> <Add option="-DLINKER_DEBUG=2" />
<Add option="-DAPKENV_DEBUG" /> <Add option="-DAPKENV_DEBUGx" />
<Add option="-DAPKENV_GLES" /> <Add option="-DAPKENV_GLES" />
</Compiler> </Compiler>
<Linker> <Linker>
Expand Down
3 changes: 2 additions & 1 deletion apkenv.h
Expand Up @@ -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 *(*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 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 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 {
struct JniLibrary *next; struct JniLibrary *next;
Expand Down
13 changes: 11 additions & 2 deletions compat/gles_wrappers.c
Expand Up @@ -3,8 +3,10 @@
#include <assert.h> #include <assert.h>
#ifdef APKENV_DEBUG #ifdef APKENV_DEBUG
# define WRAPPERS_DEBUG_PRINTF(...) printf(__VA_ARGS__) # define WRAPPERS_DEBUG_PRINTF(...) printf(__VA_ARGS__)
# define GL_TEST_ERROR if (glGetError()!=GL_NO_ERROR) { printf("GL ERROR near %s\n", __FUNCTION__); }
#else #else
# define WRAPPERS_DEBUG_PRINTF(...) # define WRAPPERS_DEBUG_PRINTF(...)
# define GL_TEST_ERROR
#endif #endif
void void
my_glAlphaFunc(GLenum func, GLclampf ref) my_glAlphaFunc(GLenum func, GLclampf ref)
Expand Down Expand Up @@ -165,7 +167,10 @@ my_glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz)
void void
my_glOrthof(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar) 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); glOrthof(left, right, bottom, top, zNear, zFar);
} }
void void
Expand Down Expand Up @@ -429,7 +434,7 @@ my_glEnable(GLenum cap)
void void
my_glEnableClientState(GLenum array) my_glEnableClientState(GLenum array)
{ {
WRAPPERS_DEBUG_PRINTF("glEnableClientState()\n", array); WRAPPERS_DEBUG_PRINTF("glEnableClientState(0x%x)\n", array);
glEnableClientState(array); glEnableClientState(array);
} }
void void
Expand Down Expand Up @@ -868,7 +873,11 @@ void
my_glViewport(GLint x, GLint y, GLsizei width, GLsizei height) my_glViewport(GLint x, GLint y, GLsizei width, GLsizei height)
{ {
WRAPPERS_DEBUG_PRINTF("glViewport()\n", x, y, width, 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); glViewport(x, y, width, height);
#endif
} }
void void
my_glPointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *pointer) my_glPointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *pointer)
Expand Down
2 changes: 1 addition & 1 deletion compat/libc_mapping.h
Expand Up @@ -74,7 +74,7 @@


{"ioctl", ioctl}, {"ioctl", ioctl},
{"mmap", mmap}, {"mmap", mmap},
{"munmap", my_munmap}, {"munmap", munmap},
{"poll", poll}, {"poll", poll},


{"mkdir", mkdir}, {"mkdir", mkdir},
Expand Down
20 changes: 9 additions & 11 deletions compat/libc_wrappers.c
Expand Up @@ -103,7 +103,7 @@ my_exp(double __x)
int int
my_fclose(FILE *__stream) 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)); int offset = ((void*)__stream - (void*)(&my___sF));
//printf("offset: %d\n", offset); //printf("offset: %d\n", offset);
if (offset < 1000) { if (offset < 1000) {
Expand Down Expand Up @@ -139,8 +139,10 @@ my_fmod(double __x, double __y)
FILE * FILE *
my_fopen(__const char *__restrict __filename, __const char *__restrict __modes) my_fopen(__const char *__restrict __filename, __const char *__restrict __modes)
{ {
//WRAPPERS_DEBUG_PRINTF("fopen(%s, %s)\n", __filename, __modes); WRAPPERS_DEBUG_PRINTF("fopen(%s, %s)\n", __filename, __modes);
return fopen(__filename, __modes); FILE *f = fopen(__filename,__modes);
WRAPPERS_DEBUG_PRINTF("fopen(%s, %s) -> %x\n", __filename, __modes, f);
return f;
} }
int int
my_fputc(int __c, FILE *__stream) my_fputc(int __c, FILE *__stream)
Expand Down Expand Up @@ -591,7 +593,7 @@ my_strstr(__const char *__haystack, __const char *__needle)
double double
my_strtod(__const char *__restrict __nptr, char **__restrict __endptr) 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); return strtod(__nptr, __endptr);
} }
char * char *
Expand Down Expand Up @@ -671,7 +673,7 @@ my_write(int __fd, __const void *__buf, size_t __n)
int int
my_fprintf(FILE *stream, const char *format, ...) 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_list ap;
va_start(ap, format); va_start(ap, format);
int result = vfprintf(stderr, format, ap); int result = vfprintf(stderr, format, ap);
Expand All @@ -682,14 +684,14 @@ my_fprintf(FILE *stream, const char *format, ...)
int int
my_vfprintf(FILE *stream, const char *format, va_list ap) 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); return vfprintf(stderr, format, ap);
} }


int int
my_fflush(FILE *stream) 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)); int offset = ((void*)stream - (void*)(&my___sF));
//printf("offset: %d\n", offset); //printf("offset: %d\n", offset);
if (offset < 1000) { if (offset < 1000) {
Expand Down Expand Up @@ -725,7 +727,3 @@ int my_vsnprintf(char *str, size_t size, const char *format, va_list ap)
return vsnprintf(str, size, format, ap); return vsnprintf(str, size, format, ap);
} }


int my_munmap(void* __addr, size_t __len)
{
return munmap(__addr,__len);
}
36 changes: 36 additions & 0 deletions imagelib/imagelib.h
@@ -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
63 changes: 50 additions & 13 deletions png/loadpng.c → imagelib/loadpng.c
Expand Up @@ -2,36 +2,40 @@


#include <stdio.h> #include <stdio.h>
#include <libpng12/png.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"); FILE *fp = fopen(filepath,"rb");
if (!fp) if (!fp)
return NULL; return NULL;


png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL); png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
if ( !png_ptr ) { if ( !png_ptr ) {
fclose(fp);
return NULL; return NULL;
} }


png_infop info = png_create_info_struct(png_ptr); png_infop info = png_create_info_struct(png_ptr);
if ( !info ) { if ( !info ) {
png_destroy_read_struct(&png_ptr, NULL, NULL); png_destroy_read_struct(&png_ptr, NULL, NULL);
fclose(fp);
return NULL; return NULL;
} }


if ( setjmp(png_jmpbuf(png_ptr)) ) { if ( setjmp(png_jmpbuf(png_ptr)) ) {
png_destroy_read_struct(&png_ptr, &info, NULL); png_destroy_read_struct(&png_ptr, &info, NULL);
fclose(fp);
return NULL; return NULL;
} }


png_init_io(png_ptr,fp); png_init_io(png_ptr,fp);
png_set_sig_bytes(png_ptr,0); 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); png_read_png(png_ptr, info, png_transforms, NULL);




Expand All @@ -56,29 +60,29 @@ image_t* loadpng( const char *filepath, int swapy, int force_rgba, int swap_rb)
} }


if ( bytepp==0 ) { if ( bytepp==0 ) {
fclose(fp);
png_destroy_read_struct(&png_ptr, &info, NULL); png_destroy_read_struct(&png_ptr, &info, NULL);
return NULL; return NULL;
} }


if (bytepp==4) int forcergba = settings.forcergba && color_type!=PNG_COLOR_TYPE_RGBA;
force_rgba = 0;




image_t* image = malloc(sizeof(image_t)); 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->width = width;
image->height = height; image->height = height;
image->bpp = bytepp; 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); png_bytepp row_pointers = png_get_rows(png_ptr, info);


int x,y; int x,y;


if (!force_rgba) { if (!forcergba) {
if (swapy) { if (settings.swapy) {
for ( y=0; y<image->height; y++ ) for ( y=0; y<image->height; y++ )
memcpy(image->data+stride*(image->height-1-y), row_pointers[y], rowbytes); memcpy(image->data+stride*(image->height-1-y), row_pointers[y], rowbytes);
} }
Expand All @@ -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* src = row_pointers[y];
unsigned char* trg = image->data+stride*y; unsigned char* trg = image->data+stride*y;
for ( x=0; x<image->width; x++ ) { for ( x=0; x<image->width; x++ ) {
trg[x*4+0] = src[x*bytepp+0]; int tx = x*4;
trg[x*4+1] = src[x*bytepp+1]; int sx = x*bytepp;
trg[x*4+2] = src[x*bytepp+2]; trg[tx+0] = src[sx+0];
trg[x*4+3] = 255; 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); png_destroy_read_struct(&png_ptr, &info, NULL);
fclose(fp);


return image; return image;
} }
Expand Down
5 changes: 5 additions & 0 deletions jni/jnienv.h
Expand Up @@ -45,6 +45,11 @@ struct dummy_byte_array {
long size; long size;
}; };


struct dummy_float_array {
float *data;
long size;
};

struct dummy_jclass { struct dummy_jclass {
char *name; char *name;
}; };
Expand Down
4 changes: 2 additions & 2 deletions linker/linker.c
Expand Up @@ -159,8 +159,8 @@ const char *linker_get_error(void)
*/ */
extern void __attribute__((noinline)) rtld_db_dlactivity(void); extern void __attribute__((noinline)) rtld_db_dlactivity(void);


static struct r_debug _r_debug = {1, NULL, &rtld_db_dlactivity, //static struct r_debug _r_debug = {1, NULL, &rtld_db_dlactivity,
RT_CONSISTENT, 0}; // RT_CONSISTENT, 0};
static struct link_map *r_debug_tail = 0; static struct link_map *r_debug_tail = 0;


static pthread_mutex_t _r_debug_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _r_debug_lock = PTHREAD_MUTEX_INITIALIZER;
Expand Down

0 comments on commit 0b4e573

Please sign in to comment.