- Zip file support for card pictures
- TODO : linux, update JGFX.cpp for zip support
- TODO : make sure there is no leak in the PSP version
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-05-10 11:10:53 +00:00
parent 69903af2c8
commit 62f6b92332
6 changed files with 120 additions and 29 deletions
+12 -7
View File
@@ -68,8 +68,7 @@ JFileSystem::JFileSystem()
JFileSystem::~JFileSystem()
{
if (mZipAvailable && mZipFile != NULL)
unzCloseCurrentFile(mZipFile);
DetachZipFile();
}
@@ -78,7 +77,9 @@ bool JFileSystem::AttachZipFile(const string &zipfile, char *password /* = NULL
if (mZipAvailable && mZipFile != NULL)
{
if (mZipFileName != zipfile)
unzCloseCurrentFile(mZipFile); // close the previous zip file
DetachZipFile(); // close the previous zip file
else
return true;
}
mZipFileName = zipfile;
@@ -101,6 +102,7 @@ void JFileSystem::DetachZipFile()
if (mZipAvailable && mZipFile != NULL)
{
unzCloseCurrentFile(mZipFile);
unzClose(mZipFile);
}
mZipFile = NULL;
@@ -115,9 +117,10 @@ bool JFileSystem::OpenFile(const string &filename)
if (mZipAvailable && mZipFile != NULL)
{
if (unzLocateFile(mZipFile, path.c_str(), 0) != UNZ_OK)
return false;
if (unzLocateFile(mZipFile, filename.c_str(), 0) != UNZ_OK){
DetachZipFile();
return OpenFile(filename);
}
char filenameInzip[256];
unz_file_info fileInfo;
@@ -159,8 +162,10 @@ bool JFileSystem::OpenFile(const string &filename)
void JFileSystem::CloseFile()
{
if (mZipAvailable && mZipFile != NULL)
if (mZipAvailable && mZipFile != NULL){
unzCloseCurrentFile(mZipFile);
return;
}
#if defined (WIN32) || defined (LINUX)
if (mFile != NULL)
+40 -3
View File
@@ -1022,7 +1022,7 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
u8 *scanline, *p;
u8 *rawdata, *scanline, *p;
u16 *rgbadata16, *q16, *bits16;
u32 *rgbadata32, *q32, *bits32;
int rawsize, i;
@@ -1030,6 +1030,7 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
bits16 = NULL;
bits32 = NULL;
/*
FILE * fp = fopen(filenamenew, "rb");
if (fp==NULL)
return;
@@ -1039,6 +1040,39 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, fp);
*/
JFileSystem* fileSystem = JFileSystem::GetInstance();
if (!fileSystem->OpenFile(filename))
{
return;
}
rawsize = fileSystem->GetFileSize();
rawdata = new u8[rawsize];
if (!rawdata)
{
fileSystem->CloseFile();
return;
}
fileSystem->ReadFile(rawdata, rawsize);
fileSystem->CloseFile();
/* if (rawdata[6] != 'J' || rawdata[7] != 'F' || rawdata[8] != 'I' || rawdata[9] != 'F')
{
delete [] rawdata;
return;
} */
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_mem_src(&cinfo, rawdata, rawsize);
jpeg_read_header(&cinfo, true);
@@ -1175,7 +1209,9 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
free(scanline);
jpeg_finish_decompress(&cinfo);
try{
jpeg_finish_decompress(&cinfo);
}catch(...){}
@@ -1202,7 +1238,8 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
textureInfo.mVRAM =videoRAMUsed;
jpeg_destroy_decompress(&cinfo);
fclose(fp);
// fclose(fp);
delete [] rawdata;
}
+45 -10
View File
@@ -608,17 +608,45 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
BYTE *rgbadata, *scanline, *p, *q;
BYTE *rawdata, *rgbadata, *scanline, *p, *q;
int rawsize, i;
char filenamenew[4096];
sprintf(filenamenew, "Res/%s", filename);
// char filenamenew[4096];
// sprintf(filenamenew, "Res/%s", filename);
// Initialise libJpeg Object
JFileSystem* fileSystem = JFileSystem::GetInstance();
if (!fileSystem->OpenFile(filename))
{
return;
}
rawsize = fileSystem->GetFileSize();
rawdata = new BYTE[rawsize];
if (!rawdata)
{
fileSystem->CloseFile();
return;
}
fileSystem->ReadFile(rawdata, rawsize);
fileSystem->CloseFile();
/* if (rawdata[6] != 'J' || rawdata[7] != 'F' || rawdata[8] != 'I' || rawdata[9] != 'F')
{
delete [] rawdata;
return;
} */
// Initialise libJpeg Object
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
jpeg_create_decompress(&cinfo);
/*
FILE* fp = fopen(filenamenew, "rb");
if (fp == NULL)
{
@@ -627,12 +655,16 @@ FILE* fp = fopen(filenamenew, "rb");
}
jpeg_stdio_src(&cinfo, fp);
*/
jpeg_mem_src(&cinfo, rawdata, rawsize);
// Process JPEG header
jpeg_read_header(&cinfo, true);
// Start Decompression
jpeg_start_decompress(&cinfo);
@@ -703,7 +735,8 @@ FILE* fp = fopen(filenamenew, "rb");
fclose(fp);
@@ -715,12 +748,14 @@ fclose(fp);
// Finish Decompression
jpeg_finish_decompress(&cinfo);
try{
jpeg_finish_decompress(&cinfo);
}catch(...){}
// Destroy JPEG object
jpeg_destroy_decompress(&cinfo);
//fclose(fp);
delete [] rawdata;
}