Added animation reading. It seems to work fine for the first frame, but none of my saves have >1 frames so I can't test the reading of the other frames, which should work fine anyway.

Only missing is DISPLAYING the banner and the animation/icon.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@410 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
gigaherz 2008-08-31 21:08:47 +00:00
parent be6c1518ea
commit 532c675a3a
3 changed files with 116 additions and 3 deletions

View File

@ -193,7 +193,7 @@ void CMemcardManager::ReloadMemcard(const char *fileName, int card)
#if FALSE
char t[257];
sprintf(t,"card%d_%d.bmp",card,index);
sprintf(t,"card%d_%d.bmp",card,i);
FILE*f=fopen(t,"wb");
if(f) {
const u8 hdr[] = {
@ -212,6 +212,36 @@ void CMemcardManager::ReloadMemcard(const char *fileName, int card)
fwrite(ftr,1,2,f);
fclose(f);
}
#endif
}
static u8 animDelay[8];
static u32 animData[32*32*8];
int numFrames = memoryCard[card]->ReadAnimRGBA8(i,animData,animDelay);
for(int n=0;n<numFrames;n++)
{
// TODO: replace this debug stuff with actually showing the image data in the lists!
#if FALSE
char t[257];
sprintf(t,"card%d_%d_anim%d.bmp",card,i,n);
FILE*f=fopen(t,"wb");
if(f) {
const u8 hdr[] = {
0x42,0x4D,0x38,0x30,0x00,0x00,0x00,0x00,
0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,
0x00,0x00,0x01,0x00,0x20,0x00,0x00,0x00,
0x00,0x00,0x02,0x30,0x00,0x00,0x12,0x0B,
0x00,0x00,0x12,0x0B,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00
};
const u8 ftr[] = {0,0};
fwrite(hdr,1,sizeof(hdr),f);
fwrite(animData+(n*32*32),4,32*32,f); // note BMP "inverts" the image vertically, so it'll look upside-down when exported this way
fwrite(ftr,1,2,f);
fclose(f);
}
#endif
}
}

View File

@ -394,8 +394,8 @@ bool GCMemcard::ReadBannerRGBA8(u32 index, u32* buffer)
int flags = dir.Dir[index].BIFlags;
bool hasBanner = flags&2;
bool fmtIsCI8 = flags&1; // else RGB5A3 (if bit15 [ RGB5 A=0xFF ] else [ RGB4 A3 ] )
bool hasBanner = (flags&2)!=0;
bool fmtIsCI8 = (flags&1)!=0; // else RGB5A3 (if bit15 [ RGB5 A=0xFF ] else [ RGB4 A3 ] )
if(!hasBanner)
return false;
@ -426,6 +426,86 @@ bool GCMemcard::ReadBannerRGBA8(u32 index, u32* buffer)
return true;
}
u32 GCMemcard::ReadAnimRGBA8(u32 index, u32* buffer, u8 *delays)
{
if(!mcdFile) return 0;
int formats = BE16(dir.Dir[index].IconFmt);
int fdelays = BE16(dir.Dir[index].AnimSpeed);
int flags = dir.Dir[index].BIFlags;
bool hasBanner = (flags&2)!=0;
bool fmtIsCI8 = (flags&1)!=0;
u32 DataOffset=BE32(dir.Dir[index].ImageOffset);
u32 DataBlock =BE16(dir.Dir[index].FirstBlock)-5;
if(DataOffset==0xFFFFFFFF)
{
return 0;
}
u8* animData=(u8* )(mc_data +(DataBlock*0x2000) + DataOffset);
if(hasBanner)
{
if(fmtIsCI8) animData+=96*32 + 2*256; // image+palette
else animData+=96*32*2;
}
int fmts[8];
u8* data[8];
int frames = 0;
for(int i=0;i<8;i++)
{
fmts[i] = formats>>(2*i);
delays[i] = (fdelays>>(2*i))<<2;
data[i] = animData;
switch(fmts[i])
{
case 1: // CI8 with shared palette
animData+=32*32;
frames++;
break;
case 2: // RGB5A3
animData+=32*32*2;
frames++;
break;
case 3: // CI8 with own palette
animData+=32*32 + 2*256;
frames++;
break;
}
}
u16* sharedPal = (u16*)(animData);
for(int i=0;i<8;i++)
{
switch(fmts[i])
{
case 1: // CI8 with shared palette
decodeCI8image(buffer,data[i],sharedPal,32,32);
buffer+=32*32;
break;
case 2: // RGB5A3
decode5A3image(buffer,(u16*)(data[i]),32,32);
break;
case 3: // CI8 with own palette
u16 *paldata = (u16*)(data[i]+32*32);
decodeCI8image(buffer,data[i],paldata,32,32);
buffer+=32*32;
break;
}
}
return frames;
}
u32 GCMemcard::TestChecksums()
{
if(!mcdFile) return 0xFFFFFFFF;

View File

@ -157,6 +157,9 @@ public:
// reads the banner image
bool ReadBannerRGBA8(u32 index, u32* buffer);
// reads the animation frames
u32 ReadAnimRGBA8(u32 index, u32* buffer, u8 *delays);
bool Save();
};