mirror of https://github.com/yquake2/ref_vk.git
Image: Share M8
This commit is contained in:
parent
1732f4c6fe
commit
94fc74ca9d
|
@ -61,9 +61,10 @@ typedef enum
|
||||||
extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 2, 3)));
|
extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 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);
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
|
|
||||||
#include "../common/header/ref_shared.h"
|
#include "../common/header/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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1218,73 +1218,6 @@ Vk_LoadPic(const char *name, byte *pic, int width, int realwidth,
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
static image_t *
|
|
||||||
Vk_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, "LoadWal: can't load %s, wrong magic value.\n", 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 = Vk_LoadPic(name, image_buffer,
|
|
||||||
width, width,
|
|
||||||
height, height,
|
|
||||||
width * height,
|
|
||||||
type, 32);
|
|
||||||
free(image_buffer);
|
|
||||||
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
static image_t*
|
static image_t*
|
||||||
Vk_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t type)
|
Vk_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t type)
|
||||||
{
|
{
|
||||||
|
@ -1377,11 +1310,11 @@ Vk_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type)
|
||||||
}
|
}
|
||||||
else if (!strcmp(ext, "wal"))
|
else if (!strcmp(ext, "wal"))
|
||||||
{
|
{
|
||||||
image = (image_t *)LoadWal(namewe, type, (load_image_t)Vk_LoadPic);
|
image = (image_t *)LoadWal(namewe, type, (loadimage_t)Vk_LoadPic);
|
||||||
}
|
}
|
||||||
else if (!strcmp(ext, "m8"))
|
else if (!strcmp(ext, "m8"))
|
||||||
{
|
{
|
||||||
image = Vk_LoadM8 (name, type);
|
image = (image_t *)LoadM8(namewe, type, (loadimage_t)Vk_LoadPic);
|
||||||
}
|
}
|
||||||
else if (!strcmp(ext, "tga"))
|
else if (!strcmp(ext, "tga"))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue