Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- g2dImage* g2dTexLoad(char path[], g2dEnum tex_mode)
- {
- if (path == NULL) return NULL;
- g2dImage* tex = NULL;
- FILE* fp = NULL;
- if ((tex = malloc(sizeof(g2dImage))) == NULL) goto loadfail;
- if ((fp = fopen(path,"rb")) == NULL) goto loadfail;
- #ifdef USE_PNG
- if (strstr(path,".png") != NULL)
- {
- _g2dTexLoadPNG(fp,tex);
- tex->can_blend = true;
- }
- #endif
- #ifdef USE_JPEG
- if (strstr(path,".jpg") != NULL ||
- strstr(path,".jpeg") != NULL )
- {
- _g2dTexLoadJPEG(fp,tex);
- tex->can_blend = false;
- }
- #endif
- fclose(fp);
- sceKernelDcacheWritebackAll();
- // The PSP can't draw 512*512+ textures.
- if (tex->w > 512 || tex->h > 512)
- {
- g2dTexFree(&tex);
- return NULL;
- }
- // Swizzling is useless with small textures.
- if ((tex_mode & G2D_SWIZZLE) && (tex->w >= 16 || tex->h >= 16))
- {
- u8* tmp = malloc(tex->tw*tex->th*PIXEL_SIZE);
- _swizzle(tmp,(u8*)tex->data,tex->tw*PIXEL_SIZE,tex->th);
- free(tex->data);
- tex->data = (g2dColor*)tmp;
- tex->swizzled = true;
- sceKernelDcacheWritebackAll();
- }
- else tex->swizzled = false;
- return tex;
- // Load failure... abort
- loadfail:
- fclose(fp);
- free(tex);
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement