Merge branch 'flats-png-macro-fix-please-just-work-already' into 'master'

Use byteptr.h macros in flats png

See merge request STJr/SRB2Internal!339
This commit is contained in:
toaster 2019-09-20 11:34:10 -04:00
commit 971d35736a

View file

@ -23,6 +23,7 @@
#include "z_zone.h" #include "z_zone.h"
#include "p_setup.h" // levelflats #include "p_setup.h" // levelflats
#include "v_video.h" // pMasterPalette #include "v_video.h" // pMasterPalette
#include "byteptr.h"
#include "dehacked.h" #include "dehacked.h"
#ifdef _WIN32 #ifdef _WIN32
@ -2819,18 +2820,14 @@ patch_t *R_PNGToPatch(const UINT8 *png, size_t size, size_t *destsize, boolean t
UINT8 *imgptr = imgbuf; UINT8 *imgptr = imgbuf;
UINT8 *colpointers, *startofspan; UINT8 *colpointers, *startofspan;
#define WRITE8(buf, a) ({*buf = (a); buf++;})
#define WRITE16(buf, a) ({*buf = (a)&255; buf++; *buf = (a)>>8; buf++;})
#define WRITE32(buf, a) ({WRITE16(buf, (a)&65535); WRITE16(buf, (a)>>16);})
if (!raw) if (!raw)
I_Error("R_PNGToPatch: conversion failed"); I_Error("R_PNGToPatch: conversion failed");
// Write image size and offset // Write image size and offset
WRITE16(imgptr, width); WRITEINT16(imgptr, width);
WRITE16(imgptr, height); WRITEINT16(imgptr, height);
WRITE16(imgptr, leftoffset); WRITEINT16(imgptr, leftoffset);
WRITE16(imgptr, topoffset); WRITEINT16(imgptr, topoffset);
// Leave placeholder to column pointers // Leave placeholder to column pointers
colpointers = imgptr; colpointers = imgptr;
@ -2845,7 +2842,7 @@ patch_t *R_PNGToPatch(const UINT8 *png, size_t size, size_t *destsize, boolean t
//printf("%d ", x); //printf("%d ", x);
// Write column pointer (@TODO may be wrong) // Write column pointer (@TODO may be wrong)
WRITE32(colpointers, imgptr - imgbuf); WRITEINT32(colpointers, imgptr - imgbuf);
// Write pixels // Write pixels
for (y = 0; y < height; y++) for (y = 0; y < height; y++)
@ -2857,7 +2854,7 @@ patch_t *R_PNGToPatch(const UINT8 *png, size_t size, size_t *destsize, boolean t
if (!opaque) if (!opaque)
{ {
if (startofspan) if (startofspan)
WRITE8(imgptr, 0); WRITEUINT8(imgptr, 0);
startofspan = NULL; startofspan = NULL;
continue; continue;
} }
@ -2869,15 +2866,15 @@ patch_t *R_PNGToPatch(const UINT8 *png, size_t size, size_t *destsize, boolean t
// If we reached the span size limit, finish the previous span // If we reached the span size limit, finish the previous span
if (startofspan) if (startofspan)
WRITE8(imgptr, 0); WRITEUINT8(imgptr, 0);
if (y > 254) if (y > 254)
{ {
// Make sure we're aligned to 254 // Make sure we're aligned to 254
if (lastStartY < 254) if (lastStartY < 254)
{ {
WRITE8(imgptr, 254); WRITEUINT8(imgptr, 254);
WRITE8(imgptr, 0); WRITEUINT8(imgptr, 0);
imgptr += 2; imgptr += 2;
lastStartY = 254; lastStartY = 254;
} }
@ -2887,15 +2884,15 @@ patch_t *R_PNGToPatch(const UINT8 *png, size_t size, size_t *destsize, boolean t
while (writeY > 254) while (writeY > 254)
{ {
WRITE8(imgptr, 254); WRITEUINT8(imgptr, 254);
WRITE8(imgptr, 0); WRITEUINT8(imgptr, 0);
imgptr += 2; imgptr += 2;
writeY -= 254; writeY -= 254;
} }
} }
startofspan = imgptr; startofspan = imgptr;
WRITE8(imgptr, writeY);///@TODO calculate starting y pos WRITEUINT8(imgptr, writeY);///@TODO calculate starting y pos
imgptr += 2; imgptr += 2;
spanSize = 0; spanSize = 0;
@ -2903,21 +2900,17 @@ patch_t *R_PNGToPatch(const UINT8 *png, size_t size, size_t *destsize, boolean t
} }
// Write the pixel // Write the pixel
WRITE8(imgptr, paletteIndex); WRITEUINT8(imgptr, paletteIndex);
spanSize++; spanSize++;
startofspan[1] = spanSize; startofspan[1] = spanSize;
} }
if (startofspan) if (startofspan)
WRITE8(imgptr, 0); WRITEUINT8(imgptr, 0);
WRITE8(imgptr, 0xFF); WRITEUINT8(imgptr, 0xFF);
} }
#undef WRITE8
#undef WRITE16
#undef WRITE32
size = imgptr-imgbuf; size = imgptr-imgbuf;
img = Z_Malloc(size, PU_STATIC, NULL); img = Z_Malloc(size, PU_STATIC, NULL);
memcpy(img, imgbuf, size); memcpy(img, imgbuf, size);