Advertisement
GeeckoDev

goto !

Jul 26th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. g2dImage* g2dTexLoad(char path[], g2dEnum tex_mode)
  2. {
  3.   if (path == NULL) return NULL;
  4.  
  5.   g2dImage* tex = NULL;
  6.   FILE* fp = NULL;
  7.   if ((tex = malloc(sizeof(g2dImage))) == NULL) goto loadfail;
  8.   if ((fp = fopen(path,"rb")) == NULL) goto loadfail;
  9.  
  10.   #ifdef USE_PNG
  11.   if (strstr(path,".png") != NULL)
  12.   {
  13.     _g2dTexLoadPNG(fp,tex);
  14.     tex->can_blend = true;
  15.   }
  16.   #endif
  17.   #ifdef USE_JPEG
  18.   if (strstr(path,".jpg")  != NULL ||
  19.       strstr(path,".jpeg") != NULL )
  20.   {
  21.     _g2dTexLoadJPEG(fp,tex);
  22.     tex->can_blend = false;
  23.   }
  24.   #endif
  25.  
  26.   fclose(fp);
  27.   sceKernelDcacheWritebackAll();
  28.  
  29.   // The PSP can't draw 512*512+ textures.
  30.   if (tex->w > 512 || tex->h > 512)
  31.   {
  32.     g2dTexFree(&tex);
  33.     return NULL;
  34.   }
  35.  
  36.   // Swizzling is useless with small textures.
  37.   if ((tex_mode & G2D_SWIZZLE) && (tex->w >= 16 || tex->h >= 16))
  38.   {
  39.     u8* tmp = malloc(tex->tw*tex->th*PIXEL_SIZE);
  40.     _swizzle(tmp,(u8*)tex->data,tex->tw*PIXEL_SIZE,tex->th);
  41.     free(tex->data);
  42.     tex->data = (g2dColor*)tmp;
  43.     tex->swizzled = true;
  44.     sceKernelDcacheWritebackAll();
  45.   }
  46.   else tex->swizzled = false;
  47.  
  48.   return tex;
  49.  
  50.   // Load failure... abort
  51.   loadfail:
  52.   fclose(fp);
  53.   free(tex);
  54.   return NULL;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement