Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cache images

  • Loading branch information...
commit a254188eae468506eb27cdc98970fd673b43606a 1 parent 81de027
@crowriot authored
Showing with 59 additions and 29 deletions.
  1. +59 −29 modules/cuttherope.c
View
88 modules/cuttherope.c
@@ -69,9 +69,9 @@ typedef struct {
#define MAX_IMAGES 200
typedef struct {
- char* name;
+ char filename[PATH_MAX];
jint id;
- image_t image;
+ image_t* image;
} Image;
@@ -262,15 +262,35 @@ cuttherope_CallObjectMethodV(JNIEnv *env, jobject p1, jmethodID p2, va_list p3)
return GLOBAL_J(env);
}
-static void
-cuttherope_CallVoidMethodV(JNIEnv* env, jobject p1, jmethodID p2, va_list p3)
+static image_t*
+cuttherope_loadImage(JNIEnv *env, const char *filename )
{
- if (!p2)
- return;
+ int i;
+ Image* img = 0;
+ for (i=0; i<MAX_IMAGES;i++) {
+ img = &cuttherope_priv.images[i];
+ if (img->filename==0 || img->filename[0]==0) {
+ break;
+ }
+ if (strcmp(img->filename,filename)==0) {
+ MODULE_DEBUG_PRINTF("cuttherope_loadImage: returning cached image %s\n",filename);
+ return img->image;
+ }
+ }
- MODULE_DEBUG_PRINTF("cuttherope_CallVoidMethodV %s\n",p2->name);
+ if (i>=MAX_IMAGES) {
+ MODULE_DEBUG_PRINTF("cuttherope_loadImage: Images exceeding limits: %s\n",filename);
+ return NULL;
+ }
- if (strcmp(p2->name,"loadImage")==0) {//public void loadImage(String paramString, int paramInt)
+ strcpy(img->filename,filename);
+ img->image = NULL;
+
+ char *buf;
+ size_t buf_size;
+ char filepath[PATH_MAX]; sprintf(filepath,"assets/%s",filename);
+
+ if (GLOBAL_J(env)->read_file(filepath, &buf, &buf_size)) {
imageloadersettings_t loadsettings =
{
@@ -280,32 +300,38 @@ cuttherope_CallVoidMethodV(JNIEnv* env, jobject p1, jmethodID p2, va_list p3)
.swaprb = 1,
};
- struct dummy_jstring *filename = va_arg(p3, struct dummy_jstring*);
- jint fileId = va_arg(p3, jint);
+ image_t* image = 0;
+ if (strstr(filepath,".png")!=0) {
+ img->image = loadpng_mem(buf,buf_size,loadsettings);
+ }
+ else
+ if (strstr(filepath,".jpeg")!=0) {
+ img->image = loadjpeg_mem(buf,buf_size,loadsettings);
+ }
+ }
+ return img->image;
+}
- MODULE_DEBUG_PRINTF("cuttherope_CallVoidMethodV(%s): filename=%s fileId=%d\n",p2->name,filename->data,fileId);
+static void
+cuttherope_CallVoidMethodV(JNIEnv* env, jobject p1, jmethodID p2, va_list p3)
+{
+ if (!p2)
+ return;
- char *buf;
- size_t buf_size;
+ MODULE_DEBUG_PRINTF("cuttherope_CallVoidMethodV %s\n",p2->name);
- char filepath[PATH_MAX]; sprintf(filepath,"assets/%s",filename->data);
+ if (strcmp(p2->name,"loadImage")==0) {//public void loadImage(String paramString, int paramInt)
- if (GLOBAL_J(env)->read_file(filepath, &buf, &buf_size)) {
+ struct dummy_jstring *filename = va_arg(p3, struct dummy_jstring*);
+ jint fileId = va_arg(p3, jint);
- MODULE_DEBUG_PRINTF("cuttherope_CallVoidMethodV(%s): filename=%s ok\n",p2->name,filename->data);
- image_t* image = 0;
- if (strstr(filepath,".png")!=0) {
- image = loadpng_mem(buf,buf_size,loadsettings);
- }
- else
- if (strstr(filepath,".jpeg")!=0) {
- image = loadjpeg_mem(buf,buf_size,loadsettings);
- }
- if (image!=NULL) {
- MODULE_DEBUG_PRINTF("cuttherope_CallVoidMethodV(%s): imageLoaded=%s (%d,%d,%d) (%x)\n",p2->name,filename->data,image->width,image->height,image->bpp,image);
- cuttherope_priv.imageLoaded(ENV(cuttherope_priv.global),cuttherope_priv.global,fileId,image,image->width,image->height);
- }
+ MODULE_DEBUG_PRINTF("cuttherope_CallVoidMethodV(%s): filename=%s fileId=%d\n",p2->name,filename->data,fileId);
+
+ image_t *image = cuttherope_loadImage(env,filename->data);
+ if (image!=NULL) {
+ MODULE_DEBUG_PRINTF("cuttherope_CallVoidMethodV(%s): imageLoaded=%s (%d,%d,%d) (%x)\n",p2->name,filename->data,image->width,image->height,image->bpp,image);
+ cuttherope_priv.imageLoaded(ENV(cuttherope_priv.global),cuttherope_priv.global,fileId,image,image->width,image->height);
}
}
else
@@ -619,12 +645,16 @@ cuttherope_init(struct SupportModule *self, int width, int height, const char *h
void *billingInterface = (void*)0xF07;
void *remoteDataManager = (void*)0xF08;
+ memset(self->priv->images,0,sizeof(self->priv->images));
self->priv->JNI_OnLoad(VM_M, NULL);
#ifdef PANDORA
- self->priv->nativeResize(ENV_M, GLOBAL_M, height, width); //$$$ landscape-to-portrait pandora fix
self->priv->global->module_hacks->gles_landscape_to_portrait = 1;
+ if (self->priv->global->module_hacks->gles_landscape_to_portrait)
+ self->priv->nativeResize(ENV_M, GLOBAL_M, height, width);
+ else
+ self->priv->nativeResize(ENV_M, GLOBAL_M, width, height);
self->priv->global->module_hacks->gles_downscale_images = 1;
#else
self->priv->nativeResize(ENV_M, GLOBAL_M, width, height);
Please sign in to comment.
Something went wrong with that request. Please try again.