pcx: fix support of bytes_per_line

https://github.com/yquake2/yquake2/issues/1119
This commit is contained in:
Denis Pauk 2024-07-06 14:16:45 +03:00
parent 50de5e091a
commit c5841b7c2f

View file

@ -139,13 +139,12 @@ PCX_Decode(const byte *raw, int len, byte **pic, byte **palette,
int *width, int *height) int *width, int *height)
{ {
pcx_t *pcx; pcx_t *pcx;
int x, y, full_size; int y, full_size, bpl, xmax, ymax, xmin, ymin, xsize, ysize;
int dataByte, runLength;
byte *out, *pix; byte *out, *pix;
*pic = NULL; *pic = NULL;
if (len < sizeof(pcx_t)) if (len < (sizeof(pcx_t) + 768))
{ {
return; return;
} }
@ -162,7 +161,21 @@ PCX_Decode(const byte *raw, int len, byte **pic, byte **palette,
return; return;
} }
full_size = (pcx->ymax + 1) * (pcx->xmax + 1); bpl = LittleShort(pcx->bytes_per_line);
xmax = LittleShort(pcx->xmax);
ymax = LittleShort(pcx->ymax);
xmin = LittleShort(pcx->xmin);
ymin = LittleShort(pcx->ymin);
/* get real size of image */
xsize = xmax - xmin + 1;
ysize = ymax - ymin + 1;
/* fix bpl */
if (bpl < xsize)
{
bpl = xsize;
}
full_size = ysize * bpl;
out = malloc(full_size); out = malloc(full_size);
*pic = out; *pic = out;
@ -177,18 +190,22 @@ PCX_Decode(const byte *raw, int len, byte **pic, byte **palette,
if (width) if (width)
{ {
*width = pcx->xmax + 1; *width = xsize;
} }
if (height) if (height)
{ {
*height = pcx->ymax + 1; *height = ysize;
} }
for (y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1) for (y = 0; y < ysize; y++, pix += xsize)
{ {
for (x = 0; x <= pcx->xmax; ) int x;
for (x = 0; x < bpl; )
{ {
int dataByte, runLength;
dataByte = *raw++; dataByte = *raw++;
if ((dataByte & 0xC0) == 0xC0) if ((dataByte & 0xC0) == 0xC0)