mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-01-31 13:20:34 +00:00
Image: Share M8
This commit is contained in:
parent
11f5b9e475
commit
f77e6940bd
5 changed files with 135 additions and 296 deletions
|
@ -26,8 +26,8 @@
|
||||||
|
|
||||||
#include "../ref_shared.h"
|
#include "../ref_shared.h"
|
||||||
|
|
||||||
struct image_s*
|
struct image_s *
|
||||||
LoadWal(const char *origname, imagetype_t type, load_image_t loadImage)
|
LoadWal(const char *origname, imagetype_t type, loadimage_t load_image)
|
||||||
{
|
{
|
||||||
int width, height, ofs, size;
|
int width, height, ofs, size;
|
||||||
struct image_s *image;
|
struct image_s *image;
|
||||||
|
@ -63,7 +63,7 @@ LoadWal(const char *origname, imagetype_t type, load_image_t loadImage)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
image = loadImage(name, (byte *)mt + ofs,
|
image = load_image(name, (byte *)mt + ofs,
|
||||||
width, 0,
|
width, 0,
|
||||||
height, 0,
|
height, 0,
|
||||||
(size - ofs), type, 8);
|
(size - ofs), type, 8);
|
||||||
|
@ -73,6 +73,72 @@ LoadWal(const char *origname, imagetype_t type, load_image_t loadImage)
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct image_s *
|
||||||
|
LoadM8(const char *origname, imagetype_t type, loadimage_t load_image)
|
||||||
|
{
|
||||||
|
m8tex_t *mt;
|
||||||
|
int width, height, ofs, size, i;
|
||||||
|
struct image_s *image;
|
||||||
|
char name[256];
|
||||||
|
unsigned char *image_buffer = NULL;
|
||||||
|
|
||||||
|
FixFileExt(origname, "m8", name, sizeof(name));
|
||||||
|
|
||||||
|
size = ri.FS_LoadFile(name, (void **)&mt);
|
||||||
|
|
||||||
|
if (!mt)
|
||||||
|
{
|
||||||
|
R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < sizeof(m8tex_t))
|
||||||
|
{
|
||||||
|
R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name);
|
||||||
|
ri.FS_FreeFile((void *)mt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LittleLong (mt->version) != M8_VERSION)
|
||||||
|
{
|
||||||
|
R_Printf(PRINT_ALL, "%s: can't load %s, wrong magic value.\n", __func__, name);
|
||||||
|
ri.FS_FreeFile ((void *)mt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
width = LittleLong(mt->width[0]);
|
||||||
|
height = LittleLong(mt->height[0]);
|
||||||
|
ofs = LittleLong(mt->offsets[0]);
|
||||||
|
|
||||||
|
if ((ofs <= 0) || (width <= 0) || (height <= 0) ||
|
||||||
|
(((size - ofs) / height) < width))
|
||||||
|
{
|
||||||
|
R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name);
|
||||||
|
ri.FS_FreeFile((void *)mt);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
image_buffer = malloc ((size - ofs) * 4);
|
||||||
|
for(i=0; i<(size - ofs); i++)
|
||||||
|
{
|
||||||
|
unsigned char value = *((byte *)mt + ofs + i);
|
||||||
|
image_buffer[i * 4 + 0] = mt->palette[value].r;
|
||||||
|
image_buffer[i * 4 + 1] = mt->palette[value].g;
|
||||||
|
image_buffer[i * 4 + 2] = mt->palette[value].b;
|
||||||
|
image_buffer[i * 4 + 3] = value == 255 ? 0 : 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
image = load_image(name, image_buffer,
|
||||||
|
width, 0,
|
||||||
|
height, 0,
|
||||||
|
(size - ofs), type, 32);
|
||||||
|
free(image_buffer);
|
||||||
|
|
||||||
|
ri.FS_FreeFile((void *)mt);
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GetWalInfo(const char *origname, int *width, int *height)
|
GetWalInfo(const char *origname, int *width, int *height)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1027,72 +1027,6 @@ R_LoadPic(char *name, byte *pic, int width, int realwidth,
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
static image_t *
|
|
||||||
LoadM8(const char *origname, imagetype_t type)
|
|
||||||
{
|
|
||||||
m8tex_t *mt;
|
|
||||||
int width, height, ofs, size;
|
|
||||||
image_t *image;
|
|
||||||
char name[256];
|
|
||||||
unsigned char *image_buffer = NULL;
|
|
||||||
|
|
||||||
FixFileExt(origname, "m8", name, sizeof(name));
|
|
||||||
|
|
||||||
size = ri.FS_LoadFile(name, (void **)&mt);
|
|
||||||
|
|
||||||
if (!mt)
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name);
|
|
||||||
return r_notexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size < sizeof(m8tex_t))
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name);
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
|
||||||
return r_notexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LittleLong (mt->version) != M8_VERSION)
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, wrong magic value.\n", __func__, name);
|
|
||||||
ri.FS_FreeFile ((void *)mt);
|
|
||||||
return r_notexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
width = LittleLong(mt->width[0]);
|
|
||||||
height = LittleLong(mt->height[0]);
|
|
||||||
ofs = LittleLong(mt->offsets[0]);
|
|
||||||
|
|
||||||
if ((ofs <= 0) || (width <= 0) || (height <= 0) ||
|
|
||||||
(((size - ofs) / height) < width))
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name);
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
|
||||||
return r_notexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
image_buffer = malloc (width * height * 4);
|
|
||||||
for(int i=0; i<width * height; i++)
|
|
||||||
{
|
|
||||||
unsigned char value = *((byte *)mt + ofs + i);
|
|
||||||
image_buffer[i * 4 + 0] = mt->palette[value].r;
|
|
||||||
image_buffer[i * 4 + 1] = mt->palette[value].g;
|
|
||||||
image_buffer[i * 4 + 2] = mt->palette[value].b;
|
|
||||||
image_buffer[i * 4 + 3] = value == 255 ? 0 : 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
image = R_LoadPic(name, image_buffer,
|
|
||||||
width, 0,
|
|
||||||
height, 0,
|
|
||||||
width * height, type, 32);
|
|
||||||
free(image_buffer);
|
|
||||||
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Finds or loads the given image
|
* Finds or loads the given image
|
||||||
*/
|
*/
|
||||||
|
@ -1238,12 +1172,12 @@ R_FindImage(char *name, imagetype_t type)
|
||||||
}
|
}
|
||||||
else if (strcmp(ext, "m8") == 0)
|
else if (strcmp(ext, "m8") == 0)
|
||||||
{
|
{
|
||||||
image = LoadM8(namewe, type);
|
image = (image_t *)LoadM8(namewe, type, (loadimage_t)R_LoadPic);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* WAL if no TGA/PNG/JPEG available (exists always) */
|
/* WAL if no TGA/PNG/JPEG available (exists always) */
|
||||||
image = (image_t *)LoadWal(namewe, type, (load_image_t)R_LoadPic);
|
image = (image_t *)LoadWal(namewe, type, (loadimage_t)R_LoadPic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
|
@ -1254,7 +1188,7 @@ R_FindImage(char *name, imagetype_t type)
|
||||||
}
|
}
|
||||||
else if (strcmp(ext, "m8") == 0)
|
else if (strcmp(ext, "m8") == 0)
|
||||||
{
|
{
|
||||||
image = LoadM8(name, type);
|
image = (image_t *)LoadM8(name, type, (loadimage_t)R_LoadPic);
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
{
|
{
|
||||||
|
@ -1264,7 +1198,7 @@ R_FindImage(char *name, imagetype_t type)
|
||||||
}
|
}
|
||||||
else /* gl_retexture is not set */
|
else /* gl_retexture is not set */
|
||||||
{
|
{
|
||||||
image = (image_t *)LoadWal(name, type, (load_image_t)R_LoadPic);
|
image = (image_t *)LoadWal(name, type, (loadimage_t)R_LoadPic);
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
{
|
{
|
||||||
|
|
|
@ -597,71 +597,6 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gl3image_t *
|
|
||||||
LoadM8(const char *origname, imagetype_t type)
|
|
||||||
{
|
|
||||||
m8tex_t *mt;
|
|
||||||
int width, height, ofs, size;
|
|
||||||
gl3image_t *image;
|
|
||||||
char name[256];
|
|
||||||
unsigned char *image_buffer = NULL;
|
|
||||||
|
|
||||||
FixFileExt(origname, "m8", name, sizeof(name));
|
|
||||||
|
|
||||||
size = ri.FS_LoadFile(name, (void **)&mt);
|
|
||||||
|
|
||||||
if (!mt)
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name);
|
|
||||||
return gl3_notexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size < sizeof(m8tex_t))
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name);
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
|
||||||
return gl3_notexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LittleLong (mt->version) != M8_VERSION)
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, wrong magic value.\n", __func__, name);
|
|
||||||
ri.FS_FreeFile ((void *)mt);
|
|
||||||
return gl3_notexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
width = LittleLong(mt->width[0]);
|
|
||||||
height = LittleLong(mt->height[0]);
|
|
||||||
ofs = LittleLong(mt->offsets[0]);
|
|
||||||
|
|
||||||
if ((ofs <= 0) || (width <= 0) || (height <= 0) ||
|
|
||||||
(((size - ofs) / height) < width))
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name);
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
|
||||||
return gl3_notexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
image_buffer = malloc (width * height * 4);
|
|
||||||
for(int i=0; i<width * height; i++)
|
|
||||||
{
|
|
||||||
unsigned char value = *((byte *)mt + ofs + i);
|
|
||||||
image_buffer[i * 4 + 0] = mt->palette[value].r;
|
|
||||||
image_buffer[i * 4 + 1] = mt->palette[value].g;
|
|
||||||
image_buffer[i * 4 + 2] = mt->palette[value].b;
|
|
||||||
image_buffer[i * 4 + 3] = value == 255 ? 0 : 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
image = GL3_LoadPic(name, image_buffer,
|
|
||||||
width, 0, height, 0,
|
|
||||||
width * height, type, 32);
|
|
||||||
free(image_buffer);
|
|
||||||
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Finds or loads the given image
|
* Finds or loads the given image
|
||||||
*/
|
*/
|
||||||
|
@ -807,12 +742,12 @@ GL3_FindImage(char *name, imagetype_t type)
|
||||||
}
|
}
|
||||||
else if (strcmp(ext, "m8") == 0)
|
else if (strcmp(ext, "m8") == 0)
|
||||||
{
|
{
|
||||||
image = LoadM8(namewe, type);
|
image = (gl3image_t *)LoadM8(namewe, type, (loadimage_t)GL3_LoadPic);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* WAL if no TGA/PNG/JPEG available (exists always) */
|
/* WAL if no TGA/PNG/JPEG available (exists always) */
|
||||||
image = (gl3image_t *)LoadWal(namewe, type, (load_image_t)GL3_LoadPic);
|
image = (gl3image_t *)LoadWal(namewe, type, (loadimage_t)GL3_LoadPic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
|
@ -823,7 +758,7 @@ GL3_FindImage(char *name, imagetype_t type)
|
||||||
}
|
}
|
||||||
else if (strcmp(ext, "m8") == 0)
|
else if (strcmp(ext, "m8") == 0)
|
||||||
{
|
{
|
||||||
image = LoadM8(name, type);
|
image = (gl3image_t *)LoadM8(name, type, (loadimage_t)GL3_LoadPic);
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
{
|
{
|
||||||
|
@ -833,7 +768,7 @@ GL3_FindImage(char *name, imagetype_t type)
|
||||||
}
|
}
|
||||||
else /* gl_retexture is not set */
|
else /* gl_retexture is not set */
|
||||||
{
|
{
|
||||||
image = (gl3image_t *)LoadWal(name, type, (load_image_t)GL3_LoadPic);
|
image = (gl3image_t *)LoadWal(name, type, (loadimage_t)GL3_LoadPic);
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,9 +78,10 @@ typedef enum
|
||||||
extern void R_Printf(int level, const char* msg, ...) PRINTF_ATTR(2, 3);
|
extern void R_Printf(int level, const char* msg, ...) PRINTF_ATTR(2, 3);
|
||||||
|
|
||||||
/* Shared images load */
|
/* Shared images load */
|
||||||
typedef struct image_s* (*load_image_t)(const char *name, byte *pic, int width, int realwidth,
|
typedef struct image_s* (*loadimage_t)(const char *name, byte *pic, int width, int realwidth,
|
||||||
int height, int realheight, size_t data_size, imagetype_t type, int bits);
|
int height, int realheight, size_t data_size, imagetype_t type, int bits);
|
||||||
extern struct image_s* LoadWal(const char *origname, imagetype_t type, load_image_t loadImage);
|
extern struct image_s* LoadWal(const char *origname, imagetype_t type, loadimage_t load_image);
|
||||||
|
struct image_s* LoadM8(const char *origname, imagetype_t type, loadimage_t load_image);
|
||||||
extern void FixFileExt(const char *origname, const char *ext, char *filename, size_t size);
|
extern void FixFileExt(const char *origname, const char *ext, char *filename, size_t size);
|
||||||
extern void GetPCXPalette(byte **colormap, unsigned *d_8to24table);
|
extern void GetPCXPalette(byte **colormap, unsigned *d_8to24table);
|
||||||
extern void LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *height);
|
extern void LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *height);
|
||||||
|
|
|
@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "header/local.h"
|
#include "header/local.h"
|
||||||
|
|
||||||
#define MAX_RIMAGES 1024
|
#define MAX_RIMAGES 1024
|
||||||
static image_t *r_whitetexture_mip = NULL;
|
static image_t *r_whitetexture_mip = NULL;
|
||||||
static image_t r_images[MAX_RIMAGES];
|
static image_t r_images[MAX_RIMAGES];
|
||||||
static int numr_images;
|
static int numr_images;
|
||||||
static int image_max = 0;
|
static int image_max = 0;
|
||||||
|
@ -204,6 +204,40 @@ Get_BestImageSize(const image_t *image, int *req_width, int *req_height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static byte *d_16to8table = NULL; // 16 to 8 bit conversion table
|
||||||
|
|
||||||
|
static void
|
||||||
|
R_Convert32To8bit(const unsigned char* pic_in, pixel_t* pic_out, size_t size,
|
||||||
|
qboolean transparent)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!d_16to8table)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(i=0; i < size; i++)
|
||||||
|
{
|
||||||
|
if (pic_in[3] > 128 || !transparent)
|
||||||
|
{
|
||||||
|
unsigned int r, g, b, c;
|
||||||
|
|
||||||
|
r = ( pic_in[0] >> 3 ) & 31;
|
||||||
|
g = ( pic_in[1] >> 2 ) & 63;
|
||||||
|
b = ( pic_in[2] >> 3 ) & 31;
|
||||||
|
|
||||||
|
c = r | ( g << 5 ) | ( b << 11 );
|
||||||
|
|
||||||
|
pic_out[i] = d_16to8table[c & 0xFFFF];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pic_out[i] = TRANSPARENT_COLOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
pic_in += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
================
|
================
|
||||||
R_LoadPic
|
R_LoadPic
|
||||||
|
@ -244,14 +278,29 @@ R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int real
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// some file types can have more data in file than code needs
|
||||||
|
if (data_size > full_size)
|
||||||
|
{
|
||||||
|
data_size = full_size;
|
||||||
|
}
|
||||||
|
|
||||||
image->transparent = false;
|
image->transparent = false;
|
||||||
|
if (bits == 32)
|
||||||
|
{
|
||||||
|
R_Convert32To8bit(pic, image->pixels[0], data_size, type != it_wall);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(image->pixels[0], pic, data_size);
|
||||||
|
}
|
||||||
|
|
||||||
if (type != it_wall)
|
if (type != it_wall)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i=0 ; i<size ; i++)
|
for (i=0 ; i<size ; i++)
|
||||||
{
|
{
|
||||||
if (pic[i] == 255)
|
if (image->pixels[0][i] == TRANSPARENT_COLOR)
|
||||||
{
|
{
|
||||||
image->transparent = true;
|
image->transparent = true;
|
||||||
break;
|
break;
|
||||||
|
@ -259,12 +308,6 @@ R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int real
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data_size > full_size)
|
|
||||||
{
|
|
||||||
data_size = full_size;
|
|
||||||
}
|
|
||||||
memcpy(image->pixels[0], pic, data_size);
|
|
||||||
|
|
||||||
// restore mips
|
// restore mips
|
||||||
R_RestoreImagePointers(image, 0);
|
R_RestoreImagePointers(image, 0);
|
||||||
|
|
||||||
|
@ -277,8 +320,6 @@ R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int real
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte *d_16to8table = NULL; // 16 to 8 bit conversion table
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply color light to texture pixel
|
* Apply color light to texture pixel
|
||||||
*
|
*
|
||||||
|
@ -320,144 +361,6 @@ R_ApplyLight(pixel_t pix, const light3_t light)
|
||||||
return d_16to8table[i_c & 0xFFFF];
|
return d_16to8table[i_c & 0xFFFF];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
R_Convert32To8bit(const unsigned char* pic_in, pixel_t* pic_out, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!d_16to8table)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for(i=0; i < size; i++)
|
|
||||||
{
|
|
||||||
unsigned int r, g, b, c;
|
|
||||||
|
|
||||||
r = ( pic_in[0] >> 3 ) & 31;
|
|
||||||
g = ( pic_in[1] >> 2 ) & 63;
|
|
||||||
b = ( pic_in[2] >> 3 ) & 31;
|
|
||||||
|
|
||||||
c = r | ( g << 5 ) | ( b << 11 );
|
|
||||||
|
|
||||||
pic_out[i] = d_16to8table[c & 0xFFFF];
|
|
||||||
pic_in += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
R_FixPalette(pixel_t* pixels, size_t size, const rgb_t* pallette)
|
|
||||||
{
|
|
||||||
pixel_t* convert = malloc(256);
|
|
||||||
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!d_16to8table)
|
|
||||||
{
|
|
||||||
free(convert);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0; i < 256; i ++)
|
|
||||||
{
|
|
||||||
unsigned int r, g, b, c;
|
|
||||||
|
|
||||||
r = ( pallette[i].r >> 3 ) & 31;
|
|
||||||
g = ( pallette[i].g >> 2 ) & 63;
|
|
||||||
b = ( pallette[i].b >> 3 ) & 31;
|
|
||||||
|
|
||||||
c = r | ( g << 5 ) | ( b << 11 );
|
|
||||||
|
|
||||||
convert[i] = d_16to8table[c & 0xFFFF];
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0; i < size; i++)
|
|
||||||
{
|
|
||||||
pixels[i] = convert[pixels[i]];
|
|
||||||
}
|
|
||||||
free(convert);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
R_LoadM8
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
static image_t *
|
|
||||||
R_LoadM8 (char *name, imagetype_t type)
|
|
||||||
{
|
|
||||||
m8tex_t *mt;
|
|
||||||
int ofs, file_size;
|
|
||||||
image_t *image;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
file_size = ri.FS_LoadFile (name, (void **)&mt);
|
|
||||||
if (!mt)
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s\n", __func__, name);
|
|
||||||
return r_notexture_mip;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file_size < sizeof(m8tex_t))
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, small header\n", __func__, name);
|
|
||||||
ri.FS_FreeFile ((void *)mt);
|
|
||||||
return r_notexture_mip;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LittleLong (mt->version) != M8_VERSION)
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, wrong magic value.\n", __func__, name);
|
|
||||||
ri.FS_FreeFile ((void *)mt);
|
|
||||||
return r_notexture_mip;
|
|
||||||
}
|
|
||||||
|
|
||||||
image = R_FindFreeImage ();
|
|
||||||
strcpy (image->name, name);
|
|
||||||
image->width = LittleLong (mt->width[0]);
|
|
||||||
image->height = LittleLong (mt->height[0]);
|
|
||||||
image->asset_width = image->width;
|
|
||||||
image->asset_height = image->height;
|
|
||||||
image->type = type;
|
|
||||||
image->registration_sequence = registration_sequence;
|
|
||||||
ofs = LittleLong (mt->offsets[0]);
|
|
||||||
size = image->width * image->height * (256+64+16+4)/256;
|
|
||||||
|
|
||||||
if ((ofs <= 0) || (image->width <= 0) || (image->height <= 0) ||
|
|
||||||
((file_size - ofs) / image->width < image->height))
|
|
||||||
{
|
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name);
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
|
||||||
return r_notexture_mip;
|
|
||||||
}
|
|
||||||
|
|
||||||
image->pixels[0] = malloc (size);
|
|
||||||
image->pixels[1] = image->pixels[0] + image->width*image->height;
|
|
||||||
image->pixels[2] = image->pixels[1] + image->width*image->height/4;
|
|
||||||
image->pixels[3] = image->pixels[2] + image->width*image->height/16;
|
|
||||||
|
|
||||||
if (size > (file_size - ofs))
|
|
||||||
{
|
|
||||||
memcpy(image->pixels[0], (byte *)mt + ofs, file_size - ofs);
|
|
||||||
// looks short, restore everything from first image
|
|
||||||
R_ImageShrink(image->pixels[0], image->pixels[1],
|
|
||||||
image->height, image->height/2,
|
|
||||||
image->width, image->width/2);
|
|
||||||
R_ImageShrink(image->pixels[1], image->pixels[2],
|
|
||||||
image->height/2, image->height/4,
|
|
||||||
image->width/2, image->width/4);
|
|
||||||
R_ImageShrink(image->pixels[2], image->pixels[3],
|
|
||||||
image->height/4, image->height/8,
|
|
||||||
image->width/4, image->width/8);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy ( image->pixels[0], (byte *)mt + ofs, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
R_FixPalette(image->pixels[0], size, mt->palette);
|
|
||||||
ri.FS_FreeFile ((void *)mt);
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
static image_t *
|
static image_t *
|
||||||
R_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t type)
|
R_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t type)
|
||||||
{
|
{
|
||||||
|
@ -550,7 +453,7 @@ R_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t
|
||||||
if (ResizeSTB(pic, width, height,
|
if (ResizeSTB(pic, width, height,
|
||||||
pic32, uploadwidth, uploadheight))
|
pic32, uploadwidth, uploadheight))
|
||||||
{
|
{
|
||||||
R_Convert32To8bit(pic32, pic8, uploadwidth * uploadheight);
|
R_Convert32To8bit(pic32, pic8, uploadwidth * uploadheight, type != it_wall);
|
||||||
image = R_LoadPic(name, pic8,
|
image = R_LoadPic(name, pic8,
|
||||||
uploadwidth, realwidth,
|
uploadwidth, realwidth,
|
||||||
uploadheight, realheight,
|
uploadheight, realheight,
|
||||||
|
@ -560,7 +463,7 @@ R_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
R_Convert32To8bit(pic, pic8, width * height);
|
R_Convert32To8bit(pic, pic8, width * height, type != it_wall);
|
||||||
image = R_LoadPic(name, pic8,
|
image = R_LoadPic(name, pic8,
|
||||||
width, width,
|
width, width,
|
||||||
height, height,
|
height, height,
|
||||||
|
@ -639,11 +542,11 @@ R_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type)
|
||||||
}
|
}
|
||||||
else if (strcmp(ext, "wal") == 0)
|
else if (strcmp(ext, "wal") == 0)
|
||||||
{
|
{
|
||||||
image = (image_t *)LoadWal(namewe, type, (load_image_t)R_LoadPic);
|
image = (image_t *)LoadWal(namewe, type, (loadimage_t)R_LoadPic);
|
||||||
}
|
}
|
||||||
else if (strcmp(ext, "m8") == 0)
|
else if (strcmp(ext, "m8") == 0)
|
||||||
{
|
{
|
||||||
image = R_LoadM8 (name, type);
|
image = (image_t *)LoadM8(namewe, type, (loadimage_t)R_LoadPic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue