mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
images: pcx make buffer const
This commit is contained in:
parent
2e32da65bd
commit
3ba0f35636
1 changed files with 30 additions and 37 deletions
|
@ -186,11 +186,12 @@ static void
|
|||
PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palette,
|
||||
int *width, int *height, int *bitesPerPixel)
|
||||
{
|
||||
pcx_t *pcx;
|
||||
const pcx_t *pcx;
|
||||
int full_size;
|
||||
int pcx_width, pcx_height;
|
||||
int pcx_width, pcx_height, bytes_per_line;
|
||||
qboolean image_issues = false;
|
||||
byte *out, *pix;
|
||||
const byte *data;
|
||||
|
||||
*pic = NULL;
|
||||
*bitesPerPixel = 8;
|
||||
|
@ -206,21 +207,13 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
}
|
||||
|
||||
/* parse the PCX file */
|
||||
pcx = (pcx_t *)raw;
|
||||
pcx = (const pcx_t *)raw;
|
||||
|
||||
pcx->xmin = LittleShort(pcx->xmin);
|
||||
pcx->ymin = LittleShort(pcx->ymin);
|
||||
pcx->xmax = LittleShort(pcx->xmax);
|
||||
pcx->ymax = LittleShort(pcx->ymax);
|
||||
pcx->hres = LittleShort(pcx->hres);
|
||||
pcx->vres = LittleShort(pcx->vres);
|
||||
pcx->bytes_per_line = LittleShort(pcx->bytes_per_line);
|
||||
pcx->palette_type = LittleShort(pcx->palette_type);
|
||||
data = &pcx->data;
|
||||
|
||||
raw = &pcx->data;
|
||||
|
||||
pcx_width = pcx->xmax - pcx->xmin;
|
||||
pcx_height = pcx->ymax - pcx->ymin;
|
||||
bytes_per_line = LittleShort(pcx->bytes_per_line);
|
||||
pcx_width = LittleShort(pcx->xmax) - LittleShort(pcx->xmin);
|
||||
pcx_height = LittleShort(pcx->ymax) - LittleShort(pcx->ymin);
|
||||
|
||||
if ((pcx->manufacturer != 0x0a) ||
|
||||
(pcx->version != 5) ||
|
||||
|
@ -265,29 +258,29 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
int x, y;
|
||||
byte *line;
|
||||
|
||||
if (pcx->bytes_per_line <= pcx_width)
|
||||
if (bytes_per_line <= pcx_width)
|
||||
{
|
||||
pcx->bytes_per_line = pcx_width + 1;
|
||||
bytes_per_line = pcx_width + 1;
|
||||
image_issues = true;
|
||||
}
|
||||
|
||||
/* clean image alpha */
|
||||
memset(pix, 255, full_size);
|
||||
|
||||
line = malloc(pcx->bytes_per_line * pcx->color_planes);
|
||||
line = malloc(bytes_per_line * pcx->color_planes);
|
||||
|
||||
for (y = 0; y <= pcx_height; y++, pix += (pcx_width + 1) * 4)
|
||||
{
|
||||
raw = PCX_RLE_Decode(line, line + (pcx_width + 1) * pcx->color_planes,
|
||||
raw, (byte *)pcx + len,
|
||||
pcx->bytes_per_line * pcx->color_planes);
|
||||
data = PCX_RLE_Decode(line, line + (pcx_width + 1) * pcx->color_planes,
|
||||
data, (byte *)pcx + len,
|
||||
bytes_per_line * pcx->color_planes);
|
||||
|
||||
for (x = 0; x <= pcx_width; x++) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < pcx->color_planes; j++)
|
||||
{
|
||||
pix[4 * x + j] = line[x + pcx->bytes_per_line * j];
|
||||
pix[4 * x + j] = line[x + bytes_per_line * j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -313,15 +306,15 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
memcpy(*palette, pcx->palette, sizeof(pcx->palette));
|
||||
}
|
||||
|
||||
line = malloc(pcx->bytes_per_line * pcx->color_planes);
|
||||
line = malloc(bytes_per_line * pcx->color_planes);
|
||||
|
||||
for (y = 0; y <= pcx_height; y++, pix += pcx_width + 1)
|
||||
{
|
||||
int x;
|
||||
|
||||
raw = PCX_RLE_Decode(line, line + pcx->bytes_per_line * pcx->color_planes,
|
||||
raw, (byte *)pcx + len,
|
||||
pcx->bytes_per_line * pcx->color_planes);
|
||||
data = PCX_RLE_Decode(line, line + bytes_per_line * pcx->color_planes,
|
||||
data, (byte *)pcx + len,
|
||||
bytes_per_line * pcx->color_planes);
|
||||
|
||||
for (x = 0; x <= pcx_width; x++)
|
||||
{
|
||||
|
@ -332,7 +325,7 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
|
||||
for (i = pcx->color_planes - 1; i >= 0; i--) {
|
||||
v <<= 1;
|
||||
v += (line[i * pcx->bytes_per_line + (x >> 3)] & m) ? 1 : 0;
|
||||
v += (line[i * bytes_per_line + (x >> 3)] & m) ? 1 : 0;
|
||||
}
|
||||
pix[x] = v;
|
||||
}
|
||||
|
@ -369,17 +362,17 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
}
|
||||
}
|
||||
|
||||
if (pcx->bytes_per_line <= pcx_width)
|
||||
if (bytes_per_line <= pcx_width)
|
||||
{
|
||||
pcx->bytes_per_line = pcx_width + 1;
|
||||
bytes_per_line = pcx_width + 1;
|
||||
image_issues = true;
|
||||
}
|
||||
|
||||
for (y = 0; y <= pcx_height; y++, pix += pcx_width + 1)
|
||||
{
|
||||
raw = PCX_RLE_Decode(pix, pix + pcx_width + 1,
|
||||
raw, (byte *)pcx + len,
|
||||
pcx->bytes_per_line);
|
||||
data = PCX_RLE_Decode(pix, pix + pcx_width + 1,
|
||||
data, (byte *)pcx + len,
|
||||
bytes_per_line);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -402,15 +395,15 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
memcpy(*palette, pcx->palette, sizeof(pcx->palette));
|
||||
}
|
||||
|
||||
line = malloc(pcx->bytes_per_line);
|
||||
line = malloc(bytes_per_line);
|
||||
|
||||
for (y = 0; y <= pcx_height; y++, pix += pcx_width + 1)
|
||||
{
|
||||
int x, mask, div;
|
||||
|
||||
raw = PCX_RLE_Decode(line, line + pcx->bytes_per_line,
|
||||
raw, (byte *)pcx + len,
|
||||
pcx->bytes_per_line);
|
||||
data = PCX_RLE_Decode(line, line + bytes_per_line,
|
||||
data, (byte *)pcx + len,
|
||||
bytes_per_line);
|
||||
|
||||
mask = (1 << pcx->bits_per_pixel) - 1;
|
||||
div = 8 / pcx->bits_per_pixel;
|
||||
|
@ -442,7 +435,7 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
*pic = NULL;
|
||||
}
|
||||
|
||||
if (raw - (byte *)pcx > len)
|
||||
if (data - (byte *)pcx > len)
|
||||
{
|
||||
Com_DPrintf("%s: %s file was malformed\n", __func__, name);
|
||||
free(*pic);
|
||||
|
|
Loading…
Reference in a new issue