Fix patch conversion

This commit is contained in:
Jaime Passos 2020-01-06 20:39:38 -03:00
parent d5c44350c2
commit 218fdaeaf8
2 changed files with 17 additions and 8 deletions

View File

@ -926,9 +926,15 @@ void *Picture_PNGConvert(
png_bytep *row_pointers = PNG_Read(png, w, h, topoffset, leftoffset, insize); png_bytep *row_pointers = PNG_Read(png, w, h, topoffset, leftoffset, insize);
png_uint_32 width = *w, height = *h; png_uint_32 width = *w, height = *h;
outbpp = Picture_FormatBPP(outformat); // Hack for patches because you'll want to preserve transparency.
if (!outbpp) if (Picture_IsPatchFormat(outformat))
I_Error("Picture_PNGConvert: unknown output bits per pixel?!"); outbpp = 16;
else
{
outbpp = Picture_FormatBPP(outformat);
if (!outbpp)
I_Error("Picture_PNGConvert: unknown output bits per pixel?!");
}
// Figure out the size // Figure out the size
flatsize = (width * height) * (outbpp / 8); flatsize = (width * height) * (outbpp / 8);
@ -936,7 +942,9 @@ void *Picture_PNGConvert(
*outsize = flatsize; *outsize = flatsize;
// Convert the image // Convert the image
flat = Z_Malloc(flatsize, PU_STATIC, NULL); flat = Z_Calloc(flatsize, PU_STATIC, NULL);
// Set transparency
if (outbpp == 8) if (outbpp == 8)
memset(flat, TRANSPARENTPIXEL, (width * height)); memset(flat, TRANSPARENTPIXEL, (width * height));
@ -980,7 +988,7 @@ void *Picture_PNGConvert(
} }
} }
// Free the row pointers that libpng allocated. // Free the row pointers that we allocated for libpng.
free(row_pointers); free(row_pointers);
// But wait, there's more! // But wait, there's more!
@ -990,7 +998,7 @@ void *Picture_PNGConvert(
pictureformat_t informat = PICFMT_NONE; pictureformat_t informat = PICFMT_NONE;
INT16 patleftoffset = 0, pattopoffset = 0; INT16 patleftoffset = 0, pattopoffset = 0;
// Figure out the input format, from the bitdepth of the input format // Figure out the format of the flat, from the bit depth of the output format
switch (outbpp) switch (outbpp)
{ {
case 32: case 32:
@ -1000,7 +1008,7 @@ void *Picture_PNGConvert(
informat = PICFMT_FLAT16; informat = PICFMT_FLAT16;
break; break;
default: default:
informat = PICFMT_FLAT; // Assumed 8bpp informat = PICFMT_FLAT;
break; break;
} }
@ -1016,6 +1024,7 @@ void *Picture_PNGConvert(
return converted; return converted;
} }
// Return the converted flat!
return flat; return flat;
} }

View File

@ -824,7 +824,7 @@ static UINT8 *R_GetTextureFlat(levelflat_t *levelflat, boolean leveltexture, boo
{ {
INT32 pngwidth, pngheight; INT32 pngwidth, pngheight;
levelflat->flatpatch = Picture_PNGConvert(ds_source, PICFMT_FLAT32, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0); levelflat->flatpatch = Picture_PNGConvert(ds_source, PICFMT_FLAT, &pngwidth, &pngheight, NULL, NULL, W_LumpLength(levelflat->u.flat.lumpnum), NULL, 0);
levelflat->topoffset = levelflat->leftoffset = 0; levelflat->topoffset = levelflat->leftoffset = 0;
levelflat->width = (UINT16)pngwidth; levelflat->width = (UINT16)pngwidth;
levelflat->height = (UINT16)pngheight; levelflat->height = (UINT16)pngheight;