renders: simplify LoadImage_Ext

This commit is contained in:
Denis Pauk 2024-07-07 17:25:32 +03:00
parent 0390db7aec
commit e08490d3de

View file

@ -500,117 +500,91 @@ LoadImage_Ext(const char *name, const char* namewe, const char *ext, imagetype_t
if (!image)
{
if (!strcmp(ext, "pcx") ||
!strcmp(ext, "wal") ||
!strcmp(ext, "m8") ||
!strcmp(ext, "swl"))
int width = 0, height = 0, realwidth = 0, realheight = 0;
byte *pic = NULL, *palette = NULL;
char filename[256];
int bitesPerPixel;
/* name could not be used here as could have different extension
* originaly */
FixFileExt(namewe, ext, filename, sizeof(filename));
ri.VID_ImageDecode(filename, &pic, &palette, &width, &height, &bitesPerPixel);
if (!pic)
{
int width = 0, height = 0, realwidth = 0, realheight = 0;
byte *pic = NULL;
byte *palette = NULL;
char filename[256];
int bitesPerPixel;
R_Printf(PRINT_DEVELOPER, "Bad %s file %s\n", ext, filename);
return NULL;
}
/* name could not be used here as could have different extension
* originaly */
FixFileExt(namewe, ext, filename, sizeof(filename));
realheight = height;
realwidth = width;
ri.VID_ImageDecode(filename, &pic, &palette, &width, &height, &bitesPerPixel);
if (!pic)
if (bitesPerPixel == 32)
{
image = load_image(name, pic,
width, realwidth,
height, realheight,
width * height,
type, bitesPerPixel);
}
else
{
if (r_retexturing >= 2)
{
R_Printf(PRINT_DEVELOPER, "Bad %s file %s\n", ext, filename);
return NULL;
byte *image_scale = NULL;
/* scale image paletted images */
image_scale = malloc(width * height * 4);
scale2x(pic, image_scale, width, height);
/* replace pic with scale */
free(pic);
pic = image_scale;
width *= 2;
height *= 2;
}
realheight = height;
realwidth = width;
if (r_retexturing && palette)
{
byte *image_buffer = NULL;
int i, size;
if (bitesPerPixel == 32)
size = width * height;
/* convert to full color */
image_buffer = malloc (size * 4);
for(i = 0; i < size; i++)
{
unsigned char value = pic[i];
image_buffer[i * 4 + 0] = palette[value * 3 + 0];
image_buffer[i * 4 + 1] = palette[value * 3 + 1];
image_buffer[i * 4 + 2] = palette[value * 3 + 2];
image_buffer[i * 4 + 3] = value == 255 ? 0 : 255;
}
image = load_image(name, image_buffer,
width, realwidth,
height, realheight,
size, type, 32);
free (image_buffer);
}
else
{
image = load_image(name, pic,
width, realwidth,
height, realheight,
width * height,
type, bitesPerPixel);
width * height, type, bitesPerPixel);
}
else
{
if (r_retexturing >= 2)
{
byte *image_scale = NULL;
/* scale image paletted images */
image_scale = malloc(width * height * 4);
scale2x(pic, image_scale, width, height);
/* replace pic with scale */
free(pic);
pic = image_scale;
width *= 2;
height *= 2;
}
if (r_retexturing && palette)
{
byte *image_buffer = NULL;
int i, size;
size = width * height;
/* convert to full color */
image_buffer = malloc (size * 4);
for(i = 0; i < size; i++)
{
unsigned char value = pic[i];
image_buffer[i * 4 + 0] = palette[value * 3 + 0];
image_buffer[i * 4 + 1] = palette[value * 3 + 1];
image_buffer[i * 4 + 2] = palette[value * 3 + 2];
image_buffer[i * 4 + 3] = value == 255 ? 0 : 255;
}
image = load_image(name, image_buffer,
width, realwidth,
height, realheight,
size, type, 32);
free (image_buffer);
}
else
{
image = load_image(name, pic,
width, realwidth,
height, realheight,
width * height, type, bitesPerPixel);
}
}
if (palette)
{
free(palette);
}
free(pic);
}
else if (!strcmp(ext, "tga") ||
!strcmp(ext, "m32") ||
!strcmp(ext, "png") ||
!strcmp(ext, "jpg"))
if (palette)
{
byte *pic = NULL;
int width = 0, height = 0;
if (LoadSTB (namewe, ext, &pic, &width, &height) && pic)
{
image = load_image(name, pic,
width, width,
height, height,
width * height,
type, 32);
free(pic);
}
free(palette);
}
free(pic);
}
return image;