mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-26 06:20:48 +00:00
Use resize stb image
This commit is contained in:
parent
1dfb54bf38
commit
dcc2892de0
3 changed files with 42 additions and 9 deletions
|
@ -41,6 +41,10 @@
|
|||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
// include resize implementation
|
||||
#define STB_IMAGE_RESIZE_IMPLEMENTATION
|
||||
#include "stb_image_resize.h"
|
||||
|
||||
/*
|
||||
* origname: the filename to be opened, might be without extension
|
||||
* type: extension of the type we wanna open ("jpg", "png" or "tga")
|
||||
|
@ -89,5 +93,11 @@ LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *hei
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern qboolean ResizeSTB(byte *input_pixels, int input_width, int input_height,
|
||||
byte *output_pixels, int output_width, int output_height)
|
||||
{
|
||||
if (stbir_resize_uint8(input_pixels, input_width, input_height, 0,
|
||||
output_pixels, output_width, output_height, 0, 4))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,8 @@ extern void LoadPCX(char *origname, byte **pic, byte **palette, int *width, int
|
|||
extern void GetPCXInfo(char *filename, int *width, int *height);
|
||||
|
||||
extern qboolean LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height);
|
||||
extern qboolean ResizeSTB(byte *input_pixels, int input_width, int input_height,
|
||||
byte *output_pixels, int output_width, int output_height);
|
||||
|
||||
extern void GetWalInfo(char *name, int *width, int *height);
|
||||
|
||||
|
|
|
@ -318,8 +318,10 @@ R_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t
|
|||
{
|
||||
if (width >= realwidth && height >= realheight)
|
||||
{
|
||||
// resulted image
|
||||
byte* pic8 = NULL;
|
||||
size_t size;
|
||||
// resulted image memory size
|
||||
size_t size8;
|
||||
|
||||
if (realheight == 0 || realwidth == 0)
|
||||
{
|
||||
|
@ -327,14 +329,33 @@ R_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t
|
|||
realwidth = width;
|
||||
}
|
||||
|
||||
size = R_GetImageMipsSize(width * height);
|
||||
pic8 = malloc(size);
|
||||
R_Convert32To8bit(pic, pic8, width * height);
|
||||
size8 = R_GetImageMipsSize(width * height);
|
||||
pic8 = malloc(size8);
|
||||
|
||||
if (width != realwidth || height != realheight)
|
||||
{
|
||||
R_ImageShrink(pic8, pic8, width, realwidth, height, realheight);
|
||||
}
|
||||
// temporary place for shrinked image
|
||||
byte* pic32 = NULL;
|
||||
// temporary image memory size
|
||||
size_t size32;
|
||||
|
||||
// resize image
|
||||
size32 = width * height * 4;
|
||||
pic32 = malloc(size32);
|
||||
|
||||
if (ResizeSTB(pic, width, height,
|
||||
pic32, realwidth, realheight))
|
||||
{
|
||||
R_Convert32To8bit(pic32, pic8, realwidth * realheight);
|
||||
image = R_LoadPic(name, pic8, realwidth, realheight, type);
|
||||
}
|
||||
free(pic32);
|
||||
}
|
||||
else
|
||||
{
|
||||
R_Convert32To8bit(pic, pic8, width * height);
|
||||
image = R_LoadPic(name, pic8, width, height, type);
|
||||
}
|
||||
free(pic8);
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +374,7 @@ R_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type)
|
|||
image_t *image = NULL;
|
||||
|
||||
// with retexturing and not skin
|
||||
if (sw_retexturing->value && type != it_skin)
|
||||
if (sw_retexturing->value)
|
||||
{
|
||||
image = R_LoadHiColorImage(name, namewe, ext, type);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue