mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
images: move m8 decode to vid/images
This commit is contained in:
parent
8e4c329351
commit
6de0e06c4a
4 changed files with 57 additions and 74 deletions
|
@ -500,7 +500,9 @@ LoadImage_Ext(const char *name, const char* namewe, const char *ext, imagetype_t
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
{
|
{
|
||||||
if (!strcmp(ext, "pcx") || !strcmp(ext, "swl"))
|
if (!strcmp(ext, "pcx") ||
|
||||||
|
!strcmp(ext, "m8") ||
|
||||||
|
!strcmp(ext, "swl"))
|
||||||
{
|
{
|
||||||
int width = 0, height = 0, realwidth = 0, realheight = 0;
|
int width = 0, height = 0, realwidth = 0, realheight = 0;
|
||||||
byte *pic = NULL;
|
byte *pic = NULL;
|
||||||
|
@ -581,10 +583,6 @@ LoadImage_Ext(const char *name, const char* namewe, const char *ext, imagetype_t
|
||||||
{
|
{
|
||||||
image = LoadWal(name, namewe, type, load_image);
|
image = LoadWal(name, namewe, type, load_image);
|
||||||
}
|
}
|
||||||
else if (!strcmp(ext, "m8"))
|
|
||||||
{
|
|
||||||
image = LoadM8(name, namewe, type, load_image);
|
|
||||||
}
|
|
||||||
else if (!strcmp(ext, "tga") ||
|
else if (!strcmp(ext, "tga") ||
|
||||||
!strcmp(ext, "m32") ||
|
!strcmp(ext, "m32") ||
|
||||||
!strcmp(ext, "png") ||
|
!strcmp(ext, "png") ||
|
||||||
|
|
|
@ -143,72 +143,6 @@ LoadWal(const char *origname, const char *namewe, imagetype_t type,
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct image_s *
|
|
||||||
LoadM8(const char *origname, const char *namewe, imagetype_t type,
|
|
||||||
loadimage_t load_image)
|
|
||||||
{
|
|
||||||
int width, height, ofs, size, i;
|
|
||||||
byte *image_buffer = NULL;
|
|
||||||
struct image_s *image;
|
|
||||||
char name[256];
|
|
||||||
m8tex_t *mt;
|
|
||||||
|
|
||||||
FixFileExt(namewe, "m8", name, sizeof(name));
|
|
||||||
|
|
||||||
size = ri.FS_LoadFile(name, (void **)&mt);
|
|
||||||
|
|
||||||
if (!mt)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size < sizeof(*mt))
|
|
||||||
{
|
|
||||||
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(origname, 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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -98,8 +98,6 @@ typedef struct image_s* (*loadimage_t)(const char *name, byte *pic, int width, i
|
||||||
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, const char *namewe, imagetype_t type,
|
extern struct image_s* LoadWal(const char *origname, const char *namewe, imagetype_t type,
|
||||||
loadimage_t load_image);
|
loadimage_t load_image);
|
||||||
extern struct image_s* LoadM8(const char *origname, const char *namewe, 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 GetPCXInfo(const char *origname, int *width, int *height);
|
extern void GetPCXInfo(const char *origname, int *width, int *height);
|
||||||
extern void GetWalInfo(const char *name, int *width, int *height);
|
extern void GetWalInfo(const char *name, int *width, int *height);
|
||||||
|
|
|
@ -294,7 +294,7 @@ SWL_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
||||||
int *width, int *height)
|
int *width, int *height)
|
||||||
{
|
{
|
||||||
sinmiptex_t *mt;
|
sinmiptex_t *mt;
|
||||||
int ofs, i;
|
int ofs;
|
||||||
|
|
||||||
mt = (sinmiptex_t *)raw;
|
mt = (sinmiptex_t *)raw;
|
||||||
|
|
||||||
|
@ -327,6 +327,8 @@ SWL_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
||||||
|
|
||||||
if (palette)
|
if (palette)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
*palette = malloc(768);
|
*palette = malloc(768);
|
||||||
for (i = 0; i < 256; i ++)
|
for (i = 0; i < 256; i ++)
|
||||||
{
|
{
|
||||||
|
@ -376,6 +378,52 @@ M32_Decode(const char *name, const byte *raw, int len, byte **pic, int *width, i
|
||||||
memcpy(*pic, (byte *)mt + ofs, len - ofs);
|
memcpy(*pic, (byte *)mt + ofs, len - ofs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
M8_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palette,
|
||||||
|
int *width, int *height)
|
||||||
|
{
|
||||||
|
m8tex_t *mt;
|
||||||
|
int ofs;
|
||||||
|
|
||||||
|
mt = (m8tex_t *)raw;
|
||||||
|
|
||||||
|
if (!mt)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len < sizeof(*mt))
|
||||||
|
{
|
||||||
|
Com_Printf("%s: can't load %s, small header\n", __func__, name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LittleLong (mt->version) != M8_VERSION)
|
||||||
|
{
|
||||||
|
Com_Printf("%s: can't load %s, wrong magic value.\n", __func__, name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*width = LittleLong(mt->width[0]);
|
||||||
|
*height = LittleLong(mt->height[0]);
|
||||||
|
ofs = LittleLong(mt->offsets[0]);
|
||||||
|
|
||||||
|
if ((ofs <= 0) || (*width <= 0) || (*height <= 0) ||
|
||||||
|
(((len - ofs) / *height) < *width))
|
||||||
|
{
|
||||||
|
Com_Printf("%s: can't load %s, small body\n", __func__, name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pic = malloc(len - ofs);
|
||||||
|
memcpy(*pic, (byte *)mt + ofs, len - ofs);
|
||||||
|
if (palette)
|
||||||
|
{
|
||||||
|
*palette = malloc(768);
|
||||||
|
memcpy(*palette, mt->palette, 768);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VID_ImageDecode(const char *filename, byte **pic, byte **palette,
|
VID_ImageDecode(const char *filename, byte **pic, byte **palette,
|
||||||
int *width, int *height, int *bytesPerPixel)
|
int *width, int *height, int *bytesPerPixel)
|
||||||
|
@ -419,6 +467,11 @@ VID_ImageDecode(const char *filename, byte **pic, byte **palette,
|
||||||
|
|
||||||
*bytesPerPixel = 1;
|
*bytesPerPixel = 1;
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(ext, "m8"))
|
||||||
|
{
|
||||||
|
M8_Decode(filename, raw, len, pic, palette, width, height);
|
||||||
|
*bytesPerPixel = 1;
|
||||||
|
}
|
||||||
else if (!strcmp(ext, "swl"))
|
else if (!strcmp(ext, "swl"))
|
||||||
{
|
{
|
||||||
SWL_Decode(filename, raw, len, pic, palette, width, height);
|
SWL_Decode(filename, raw, len, pic, palette, width, height);
|
||||||
|
|
Loading…
Reference in a new issue