mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-03-15 07:21:33 +00:00
renders: move m32 load to vid/image code
This commit is contained in:
parent
ce37d4b748
commit
50de5e091a
4 changed files with 51 additions and 61 deletions
|
@ -585,11 +585,8 @@ LoadImage_Ext(const char *name, const char* namewe, const char *ext, imagetype_t
|
|||
{
|
||||
image = LoadM8(name, namewe, type, load_image);
|
||||
}
|
||||
else if (!strcmp(ext, "m32"))
|
||||
{
|
||||
image = LoadM32(name, namewe, type, load_image);
|
||||
}
|
||||
else if (!strcmp(ext, "tga") ||
|
||||
!strcmp(ext, "m32") ||
|
||||
!strcmp(ext, "png") ||
|
||||
!strcmp(ext, "jpg"))
|
||||
{
|
||||
|
|
|
@ -230,59 +230,6 @@ LoadSWL(const char *origname, byte **pic, byte **palette, int *width, int *heigh
|
|||
}
|
||||
}
|
||||
|
||||
struct image_s *
|
||||
LoadM32(const char *origname, const char *namewe, imagetype_t type,
|
||||
loadimage_t load_image)
|
||||
{
|
||||
m32tex_t *mt;
|
||||
int width, height, ofs, size;
|
||||
struct image_s *image;
|
||||
char name[256];
|
||||
|
||||
FixFileExt(namewe, "m32", name, sizeof(name));
|
||||
|
||||
size = ri.FS_LoadFile(name, (void **)&mt);
|
||||
|
||||
if (!mt)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size < sizeof(m32tex_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) != M32_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 * 4)))
|
||||
{
|
||||
R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name);
|
||||
ri.FS_FreeFile((void *)mt);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = load_image(origname, (byte *)mt + ofs,
|
||||
width, 0,
|
||||
height, 0,
|
||||
(size - ofs) / 4, type, 32);
|
||||
ri.FS_FreeFile ((void *)mt);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
void
|
||||
GetWalInfo(const char *origname, int *width, int *height)
|
||||
{
|
||||
|
|
|
@ -100,8 +100,6 @@ extern struct image_s* LoadWal(const char *origname, const char *namewe, imagety
|
|||
loadimage_t load_image);
|
||||
extern struct image_s* LoadM8(const char *origname, const char *namewe, imagetype_t type,
|
||||
loadimage_t load_image);
|
||||
extern struct image_s* LoadM32(const char *origname, const char *namewe, imagetype_t type,
|
||||
loadimage_t load_image);
|
||||
extern void LoadSWL(const char *origname, byte **pic, byte **palette, int *width, int *height);
|
||||
extern void FixFileExt(const char *origname, const char *ext, char *filename, size_t size);
|
||||
extern void LoadPCX(const char *origname, byte **pic, byte **palette, int *width, int *height);
|
||||
|
|
|
@ -271,6 +271,45 @@ SWL_Decode(const byte *raw, int len, byte **pic, byte **palette,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
M32_Decode(const byte *raw, int len, byte **pic, int *width, int *height)
|
||||
{
|
||||
m32tex_t *mt;
|
||||
int ofs;
|
||||
|
||||
mt = (m32tex_t *)raw;
|
||||
|
||||
if (!mt)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (len < sizeof(m32tex_t))
|
||||
{
|
||||
Com_DPrintf("%s: can't load, small header\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (LittleLong (mt->version) != M32_VERSION)
|
||||
{
|
||||
Com_DPrintf("%s: can't load, wrong magic value.\n", __func__);
|
||||
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 * 4)))
|
||||
{
|
||||
Com_DPrintf("%s: can't load, small body\n", __func__);
|
||||
}
|
||||
|
||||
*pic = malloc (len - ofs);
|
||||
memcpy(*pic, (byte *)mt + ofs, len - ofs);
|
||||
}
|
||||
|
||||
void
|
||||
VID_ImageDecode(const char *filename, byte **pic, byte **palette,
|
||||
int *width, int *height, int *bytesPerPixel)
|
||||
|
@ -322,14 +361,23 @@ VID_ImageDecode(const char *filename, byte **pic, byte **palette,
|
|||
else
|
||||
{
|
||||
int sourceBytesPerPixel = 0;
|
||||
|
||||
/* other formats does not have palette directly */
|
||||
if (palette)
|
||||
{
|
||||
*palette = NULL;
|
||||
}
|
||||
|
||||
*pic = stbi_load_from_memory(raw, len, width, height,
|
||||
&sourceBytesPerPixel, STBI_rgb_alpha);
|
||||
if (!strcmp(ext, "m32"))
|
||||
{
|
||||
M32_Decode(raw, len, pic, width, height);
|
||||
printf("->%s:%p\n", filename, *pic);
|
||||
}
|
||||
else
|
||||
{
|
||||
*pic = stbi_load_from_memory(raw, len, width, height,
|
||||
&sourceBytesPerPixel, STBI_rgb_alpha);
|
||||
}
|
||||
|
||||
if (*pic == NULL)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue