More PSP fixes.

This commit is contained in:
xawotihs
2013-12-28 11:44:00 +01:00
parent afb4c4605b
commit 3f43648b22
2 changed files with 32 additions and 26 deletions
+26 -21
View File
@@ -892,9 +892,10 @@ static void PNGCustomReadDataFn(png_structp png_ptr, png_bytep data, png_size_t
{ {
png_size_t check; png_size_t check;
JFileSystem *fileSystem = (JFileSystem*)png_ptr->io_ptr; JFile* jFile = (JFile*)png_ptr->io_ptr;
JFileSystem* fileSystem = JFileSystem::GetInstance();
check = fileSystem->ReadFile(data, length); check = fileSystem->ReadFile(jFile, data, length);
if (check != length) if (check != length)
{ {
@@ -1038,23 +1039,24 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
bits32 = NULL; bits32 = NULL;
JFileSystem* fileSystem = JFileSystem::GetInstance(); JFileSystem* fileSystem = JFileSystem::GetInstance();
if (!fileSystem->OpenFile(filename)) JFile* jFile = fileSystem->OpenFile(filename);
if (!jFile)
{ {
return; return;
} }
rawsize = fileSystem->GetFileSize(); rawsize = fileSystem->GetFileSize(jFile);
rawdata = new u8[rawsize]; rawdata = new u8[rawsize];
if (!rawdata) if (!rawdata)
{ {
fileSystem->CloseFile(); fileSystem->CloseFile(jFile);
return; return;
} }
fileSystem->ReadFile(rawdata, rawsize); fileSystem->ReadFile(jFile, rawdata, rawsize);
fileSystem->CloseFile(); fileSystem->CloseFile(jFile);
cinfo.err = jpeg_std_error(&jerr); cinfo.err = jpeg_std_error(&jerr);
@@ -1362,24 +1364,25 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode,
u32* line; u32* line;
JFileSystem* fileSystem = JFileSystem::GetInstance(); JFileSystem* fileSystem = JFileSystem::GetInstance();
if (!fileSystem->OpenFile(filename)) return JGE_ERR_CANT_OPEN_FILE; JFile* jFile = fileSystem->OpenFile(filename);
if (!jFile) return JGE_ERR_CANT_OPEN_FILE;
//JLOG("PNG opened - creating read struct"); //JLOG("PNG opened - creating read struct");
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) { if (png_ptr == NULL) {
fileSystem->CloseFile(); fileSystem->CloseFile(jFile);
return JGE_ERR_PNG; return JGE_ERR_PNG;
} }
//JLOG("Setting error callback func"); //JLOG("Setting error callback func");
png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, PNGCustomWarningFn); png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, PNGCustomWarningFn);
info_ptr = png_create_info_struct(png_ptr); info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) { if (info_ptr == NULL) {
fileSystem->CloseFile(); fileSystem->CloseFile(jFile);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL); png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
return JGE_ERR_PNG; return JGE_ERR_PNG;
} }
png_init_io(png_ptr, NULL); png_init_io(png_ptr, NULL);
png_set_read_fn(png_ptr, (png_voidp)fileSystem, PNGCustomReadDataFn); png_set_read_fn(png_ptr, (png_voidp)jFile, PNGCustomReadDataFn);
png_set_sig_bytes(png_ptr, sig_read); png_set_sig_bytes(png_ptr, sig_read);
png_read_info(png_ptr, info_ptr); png_read_info(png_ptr, info_ptr);
@@ -1392,7 +1395,7 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode,
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
line = (u32*) malloc(width * 4); line = (u32*) malloc(width * 4);
if (!line) { if (!line) {
fileSystem->CloseFile(); fileSystem->CloseFile(jFile);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL); png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
return JGE_ERR_MALLOC_FAILED; return JGE_ERR_MALLOC_FAILED;
} }
@@ -1430,7 +1433,7 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode,
std::ostringstream stream; std::ostringstream stream;
stream << "Alloc failed for: Tex Width: " << texWidth << " Tex Height: " << kVerticalBlockSize << ", total bytes: " << texWidth * kVerticalBlockSize * sizeof(PIXEL_TYPE); stream << "Alloc failed for: Tex Width: " << texWidth << " Tex Height: " << kVerticalBlockSize << ", total bytes: " << texWidth * kVerticalBlockSize * sizeof(PIXEL_TYPE);
JLOG(stream.str().c_str()); JLOG(stream.str().c_str());
fileSystem->CloseFile(); fileSystem->CloseFile(jFile);
png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL); png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
return JGE_ERR_MALLOC_FAILED; return JGE_ERR_MALLOC_FAILED;
} }
@@ -1505,7 +1508,7 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode,
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL); png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
//JLOG("Closing PNG"); //JLOG("Closing PNG");
fileSystem->CloseFile(); fileSystem->CloseFile(jFile);
if (done) if (done)
{ {
@@ -1725,9 +1728,9 @@ int JRenderer::image_readgif(void * handle, TextureInfo &textureInfo, DWORD * bg
int image_gif_read(GifFileType * ft, GifByteType * buf, int size) int image_gif_read(GifFileType * ft, GifByteType * buf, int size)
{ {
JFileSystem *fileSys = JFileSystem::GetInstance();
JFileSystem *fileSys = (JFileSystem *)ft->UserData; JFile* jFile = (JFile*)ft->UserData;
if (fileSys->ReadFile(buf, size)) if (fileSys->ReadFile(jFile, buf, size))
return size; return size;
else else
return 0; return 0;
@@ -1740,15 +1743,17 @@ void JRenderer::LoadGIF(TextureInfo &textureInfo, const char *filename, int mode
JFileSystem *fileSys = JFileSystem::GetInstance(); JFileSystem *fileSys = JFileSystem::GetInstance();
if (!fileSys->OpenFile(filename)) JFile* jFile = fileSys->OpenFile(filename);
if (!jFile)
return; return;
DWORD bkcol; DWORD bkcol;
int result = image_readgif(fileSys, textureInfo, &bkcol, image_gif_read, mode); int result = image_readgif(jFile, textureInfo, &bkcol, image_gif_read, mode);
if(result!=0) if(result!=0)
textureInfo.mBits=NULL; textureInfo.mBits=NULL;
fileSys->CloseFile(); fileSys->CloseFile(jFile);
return ; return ;
} }
@@ -2262,4 +2267,4 @@ void JRenderer::FillRoundRect(float x, float y, float w, float h, float radius,
void JRenderer::SetImageFilter(JImageFilter* imageFilter) void JRenderer::SetImageFilter(JImageFilter* imageFilter)
{ {
mImageFilter = imageFilter; mImageFilter = imageFilter;
} }
+6 -5
View File
@@ -199,15 +199,16 @@ bool JTTFont::Load(const char *filename, int size, int mode)
if (FT_Init_FreeType( &mLibrary ) == 0) if (FT_Init_FreeType( &mLibrary ) == 0)
{ {
JFileSystem* fileSystem = JFileSystem::GetInstance(); JFileSystem* fileSystem = JFileSystem::GetInstance();
if (fileSystem->OpenFile(filename)) JFile* jFile = fileSystem->OpenFile(filename);
if (jFile)
{ {
mFontBitsSize = fileSystem->GetFileSize(); mFontBitsSize = fileSystem->GetFileSize(jFile);
mFontBits = (FT_Byte*)malloc(mFontBitsSize); mFontBits = (FT_Byte*)malloc(mFontBitsSize);
fileSystem->ReadFile(mFontBits, mFontBitsSize); fileSystem->ReadFile(jFile, mFontBits, mFontBitsSize);
fileSystem->CloseFile(); fileSystem->CloseFile(jFile);
if (FT_New_Memory_Face(mLibrary, mFontBits, mFontBitsSize, 0, &mFace ) == 0) if (FT_New_Memory_Face(mLibrary, mFontBits, mFontBitsSize, 0, &mFace ) == 0)
{ {