mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-17 22:50:51 +00:00
Add support for supplying NULL palettes to LoadPCX() [uses the .pcx's palette].
Change convert in LoadPCX() to use rgb rather than rgba, since it was just supplying 255 for A anyways. Also restructure image.c a bit, remove unneeded ifs.
This commit is contained in:
parent
99034fef27
commit
c8b9f7552a
2 changed files with 43 additions and 28 deletions
|
@ -54,7 +54,7 @@ LoadImage (const char *imageFile)
|
|||
tex_t *tex = NULL;
|
||||
QFile *fp;
|
||||
|
||||
/* Get the file name without extension */
|
||||
// Get the file name without extension
|
||||
tmpFile = dstring_new ();
|
||||
dstring_copystr (tmpFile, imageFile);
|
||||
ext = strrchr (tmpFile->str, '.');
|
||||
|
@ -62,36 +62,49 @@ LoadImage (const char *imageFile)
|
|||
tmp = ext - tmpFile->str;
|
||||
else
|
||||
tmp = tmpFile->size - 1;
|
||||
|
||||
/* Check for a .png */
|
||||
|
||||
// Check for a .png
|
||||
dstring_replace (tmpFile, tmp, tmpFile->size, ".png", 5);
|
||||
QFS_FOpenFile (tmpFile->str, &fp);
|
||||
if (fp) {
|
||||
tex = LoadPNG (fp);
|
||||
Qclose (fp);
|
||||
dstring_delete (tmpFile);
|
||||
return (tex);
|
||||
}
|
||||
|
||||
/* Check for a .tga */
|
||||
if (!tex) {
|
||||
dstring_replace (tmpFile, tmp, tmpFile->size, ".tga", 5);
|
||||
QFS_FOpenFile (tmpFile->str, &fp);
|
||||
if (fp) {
|
||||
tex = LoadTGA (fp);
|
||||
Qclose (fp);
|
||||
}
|
||||
|
||||
// Check for a .tga
|
||||
dstring_replace (tmpFile, tmp, tmpFile->size, ".tga", 5);
|
||||
QFS_FOpenFile (tmpFile->str, &fp);
|
||||
if (fp) {
|
||||
tex = LoadTGA (fp);
|
||||
Qclose (fp);
|
||||
dstring_delete (tmpFile);
|
||||
return (tex);
|
||||
}
|
||||
|
||||
/* Check for a .pcx */
|
||||
/*if (!tex) {
|
||||
dstring_replace (tmpFile, tmp, tmpFile->size, ".pcx", 5);
|
||||
QFS_FOpenFile (tmpFile->str, &fp);
|
||||
|
||||
if (fp) {
|
||||
tex = LoadPCX (fp); // FIXME: needs extra arguments, how should we be passed them?
|
||||
Qclose (fp);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
// Check for a .jpg
|
||||
dstring_replace (tmpFile, tmp, tmpFile->size, ".jpg", 5);
|
||||
QFS_FOpenFile (tmpFile->str, &fp);
|
||||
if (fp) {
|
||||
tex = LoadJPG (fp);
|
||||
Qclose (fp);
|
||||
dstring_delete (tmpFile);
|
||||
return (tex);
|
||||
}
|
||||
*/
|
||||
|
||||
// Check for a .pcx
|
||||
dstring_replace (tmpFile, tmp, tmpFile->size, ".pcx", 5);
|
||||
QFS_FOpenFile (tmpFile->str, &fp);
|
||||
if (fp) {
|
||||
tex = LoadPCX (fp, 1, NULL); // Convert, some users don't grok paletted
|
||||
Qclose (fp);
|
||||
dstring_delete (tmpFile);
|
||||
return (tex);
|
||||
}
|
||||
|
||||
dstring_delete (tmpFile);
|
||||
return (tex);
|
||||
}
|
||||
|
|
|
@ -88,13 +88,16 @@ LoadPCX (QFile *f, int convert, byte *pal)
|
|||
|
||||
count = (pcx->xmax + 1) * (pcx->ymax + 1);
|
||||
if (convert) {
|
||||
tex = Hunk_TempAlloc (field_offset (tex_t, data[count * 4]));
|
||||
tex->format = tex_rgba;
|
||||
tex = Hunk_TempAlloc (field_offset (tex_t, data[count * 3]));
|
||||
tex->format = tex_rgb;
|
||||
tex->palette = 0;
|
||||
} else {
|
||||
tex = Hunk_TempAlloc (field_offset (tex_t, data[count]));
|
||||
tex->format = tex_palette;
|
||||
tex->palette = pal;
|
||||
if (pal)
|
||||
tex->palette = pal;
|
||||
else
|
||||
tex->palette = palette;
|
||||
}
|
||||
tex->width = pcx->xmax + 1;
|
||||
tex->height = pcx->ymax + 1;
|
||||
|
@ -121,7 +124,6 @@ LoadPCX (QFile *f, int convert, byte *pal)
|
|||
*pix++ = palette[*dataByte * 3];
|
||||
*pix++ = palette[*dataByte * 3 + 1];
|
||||
*pix++ = palette[*dataByte * 3 + 2];
|
||||
*pix++ = 255;
|
||||
}
|
||||
} else {
|
||||
for (; runLength > 0; runLength--) {
|
||||
|
|
Loading…
Reference in a new issue