write 24bpp pngs for screenshots using new deemph code

This commit is contained in:
zeromus 2015-09-12 18:44:03 +00:00
parent 96078b99ac
commit 57ec344b1f
1 changed files with 16 additions and 16 deletions

View File

@ -568,7 +568,7 @@ int SaveSnapshot(void)
int x,u,y; int x,u,y;
FILE *pp=NULL; FILE *pp=NULL;
uint8 *compmem=NULL; uint8 *compmem=NULL;
uLongf compmemsize=totallines*263+12; uLongf compmemsize=(totallines*263+12)*3;
if(!(compmem=(uint8 *)FCEU_malloc(compmemsize))) if(!(compmem=(uint8 *)FCEU_malloc(compmemsize)))
return 0; return 0;
@ -588,7 +588,7 @@ int SaveSnapshot(void)
} }
{ {
static uint8 header[8]={137,80,78,71,13,10,26,10}; static const uint8 header[8]={137,80,78,71,13,10,26,10};
if(fwrite(header,8,1,pp)!=1) if(fwrite(header,8,1,pp)!=1)
goto PNGerr; goto PNGerr;
} }
@ -602,8 +602,8 @@ int SaveSnapshot(void)
chunko[4]=chunko[5]=chunko[6]=0; chunko[4]=chunko[5]=chunko[6]=0;
chunko[7]=totallines; // Height chunko[7]=totallines; // Height
chunko[8]=8; // bit depth chunko[8]=8; // 8 bits per sample(24 bits per pixel)
chunko[9]=3; // Color type; indexed 8-bit chunko[9]=2; // Color type; RGB triplet
chunko[10]=0; // compression: deflate chunko[10]=0; // compression: deflate
chunko[11]=0; // Basic adapative filter set(though none are used). chunko[11]=0; // Basic adapative filter set(though none are used).
chunko[12]=0; // No interlace. chunko[12]=0; // No interlace.
@ -612,19 +612,12 @@ int SaveSnapshot(void)
goto PNGerr; goto PNGerr;
} }
{
uint8 pdata[256*3];
for(x=0;x<256;x++)
FCEUD_GetPalette(x,pdata+x*3,pdata+x*3+1,pdata+x*3+2);
if(!WritePNGChunk(pp,256*3,"PLTE",pdata))
goto PNGerr;
}
{ {
uint8 *tmp=XBuf+FSettings.FirstSLine*256; uint8 *tmp=XBuf+FSettings.FirstSLine*256;
uint8 *dest,*mal,*mork; uint8 *dest,*mal,*mork;
if(!(mal=mork=dest=(uint8 *)FCEU_dmalloc((totallines<<8)+totallines))) int bufsize = (256*3+1)*totallines;
if(!(mal=mork=dest=(uint8 *)FCEU_dmalloc(bufsize)))
goto PNGerr; goto PNGerr;
// mork=dest=XBuf; // mork=dest=XBuf;
@ -632,11 +625,18 @@ int SaveSnapshot(void)
{ {
*dest=0; // No filter. *dest=0; // No filter.
dest++; dest++;
for(x=256;x;x--,tmp++,dest++) for(x=256;x;x--)
*dest=*tmp; {
extern u32 ModernDeemphColorMap(u8* src);
u32 color = ModernDeemphColorMap(tmp);
*dest++=(color>>0x10)&0xFF;
*dest++=(color>>0x08)&0xFF;
*dest++=(color>>0x00)&0xFF;
tmp++;
}
} }
if(compress(compmem,&compmemsize,mork,(totallines<<8)+totallines)!=Z_OK) if(compress(compmem,&compmemsize,mork,bufsize)!=Z_OK)
{ {
if(mal) free(mal); if(mal) free(mal);
goto PNGerr; goto PNGerr;