mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-18 02:50:33 +00:00
engine: imagelib: add BGRA saving for PNG
Fix incorrect output, when input format has alpha but flags don't have set IMAGE_HAS_ALPHA. Flags are meant to control output format, but input format may be arbitrary, as usually given by video driver(screenshots, etc)
This commit is contained in:
parent
c62db950f1
commit
9c8059ea96
@ -427,12 +427,10 @@ qboolean Image_SavePNG( const char *name, rgbdata_t *pix )
|
|||||||
// get image description
|
// get image description
|
||||||
switch( pix->type )
|
switch( pix->type )
|
||||||
{
|
{
|
||||||
case PF_RGB_24:
|
case PF_BGR_24:
|
||||||
pixel_size = 3;
|
case PF_RGB_24: pixel_size = 3; break;
|
||||||
break;
|
case PF_BGRA_32:
|
||||||
case PF_RGBA_32:
|
case PF_RGBA_32: pixel_size = 4; break;
|
||||||
pixel_size = 4;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -443,18 +441,47 @@ qboolean Image_SavePNG( const char *name, rgbdata_t *pix )
|
|||||||
filtered_size = ( rowsize + 1 ) * pix->height;
|
filtered_size = ( rowsize + 1 ) * pix->height;
|
||||||
|
|
||||||
out = filtered_buffer = Mem_Malloc( host.imagepool, filtered_size );
|
out = filtered_buffer = Mem_Malloc( host.imagepool, filtered_size );
|
||||||
in = pix->buffer;
|
|
||||||
|
|
||||||
// apply adaptive filter to image
|
// apply adaptive filter to image
|
||||||
|
switch( pix->type )
|
||||||
|
{
|
||||||
|
case PF_RGB_24:
|
||||||
|
case PF_RGBA_32:
|
||||||
for( y = 0; y < pix->height; y++ )
|
for( y = 0; y < pix->height; y++ )
|
||||||
{
|
{
|
||||||
|
in = pix->buffer + y * pix->width * pixel_size;
|
||||||
*out++ = PNG_F_NONE;
|
*out++ = PNG_F_NONE;
|
||||||
rowend = in + rowsize;
|
rowend = in + rowsize;
|
||||||
for( ; in < rowend; )
|
for( ; in < rowend; in += pixel_size )
|
||||||
{
|
{
|
||||||
*out++ = *in++;
|
*out++ = in[0];
|
||||||
|
*out++ = in[1];
|
||||||
|
*out++ = in[2];
|
||||||
|
if( pix->flags & IMAGE_HAS_ALPHA )
|
||||||
|
*out++ = in[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case PF_BGR_24:
|
||||||
|
case PF_BGRA_32:
|
||||||
|
for( y = 0; y < pix->height; y++ )
|
||||||
|
{
|
||||||
|
in = pix->buffer + y * pix->width * pixel_size;
|
||||||
|
*out++ = PNG_F_NONE;
|
||||||
|
rowend = in + rowsize;
|
||||||
|
for( ; in < rowend; in += pixel_size )
|
||||||
|
{
|
||||||
|
*out++ = in[2];
|
||||||
|
*out++ = in[1];
|
||||||
|
*out++ = in[0];
|
||||||
|
if( pix->flags & IMAGE_HAS_ALPHA )
|
||||||
|
*out++ = in[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// get IHDR chunk length
|
// get IHDR chunk length
|
||||||
ihdr_len = sizeof( png_ihdr_t );
|
ihdr_len = sizeof( png_ihdr_t );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user