mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-22 20:51:31 +00:00
Image: Add M32 support functions
https://github.com/TTimo/GtkRadiant/blob/master/plugins/imagem8/m32.h
This commit is contained in:
parent
f77e6940bd
commit
5e2ecede93
3 changed files with 116 additions and 1 deletions
|
@ -139,6 +139,59 @@ LoadM8(const char *origname, imagetype_t type, loadimage_t load_image)
|
|||
return image;
|
||||
}
|
||||
|
||||
struct image_s *
|
||||
LoadM32(const char *origname, imagetype_t type, loadimage_t load_image)
|
||||
{
|
||||
m32tex_t *mt;
|
||||
int width, height, ofs, size;
|
||||
struct image_s *image;
|
||||
char name[256];
|
||||
|
||||
FixFileExt(origname, "m32", 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) != 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(name, (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)
|
||||
{
|
||||
|
@ -198,3 +251,33 @@ GetM8Info(const char *origname, int *width, int *height)
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
GetM32Info(const char *origname, int *width, int *height)
|
||||
{
|
||||
m32tex_t *mt;
|
||||
int size;
|
||||
char filename[256];
|
||||
|
||||
FixFileExt(origname, "m32", filename, sizeof(filename));
|
||||
|
||||
size = ri.FS_LoadFile(filename, (void **)&mt);
|
||||
|
||||
if (!mt)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (size < sizeof(m32tex_t) || LittleLong (mt->version) != M32_VERSION)
|
||||
{
|
||||
ri.FS_FreeFile((void *)mt);
|
||||
return;
|
||||
}
|
||||
|
||||
*width = LittleLong(mt->width[0]);
|
||||
*height = LittleLong(mt->height[0]);
|
||||
|
||||
ri.FS_FreeFile((void *)mt);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -81,13 +81,15 @@ extern void R_Printf(int level, const char* msg, ...) PRINTF_ATTR(2, 3);
|
|||
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);
|
||||
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 struct image_s* LoadM8(const char *origname, imagetype_t type, loadimage_t load_image);
|
||||
extern struct image_s* LoadM32(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 GetPCXPalette(byte **colormap, unsigned *d_8to24table);
|
||||
extern void LoadPCX(const char *origname, byte **pic, byte **palette, 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 GetM8Info(const char *name, int *width, int *height);
|
||||
extern void GetM32Info(const char *name, int *width, int *height);
|
||||
|
||||
extern qboolean LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height);
|
||||
extern qboolean ResizeSTB(const byte *input_pixels, int input_width, int input_height,
|
||||
|
|
|
@ -199,6 +199,36 @@ typedef struct m8tex_s
|
|||
int value;
|
||||
} m8tex_t;
|
||||
|
||||
/* .M32 texture file format */
|
||||
|
||||
#define M32_VERSION 0x4
|
||||
#define M32_MIP_LEVELS 16
|
||||
|
||||
typedef struct m32tex_s
|
||||
{
|
||||
int version;
|
||||
char name[128];
|
||||
char altname[128]; // texture substitution
|
||||
char animname[128]; // next frame in animation chain
|
||||
char damagename[128]; // image that should be shown when damaged
|
||||
unsigned width[M32_MIP_LEVELS], height[M32_MIP_LEVELS];
|
||||
unsigned offsets[M32_MIP_LEVELS];
|
||||
int flags;
|
||||
int contents;
|
||||
int value;
|
||||
float scale_x, scale_y;
|
||||
int mip_scale;
|
||||
|
||||
// detail texturing info
|
||||
char dt_name[128]; // detailed texture name
|
||||
float dt_scale_x, dt_scale_y;
|
||||
float dt_u, dt_v;
|
||||
float dt_alpha;
|
||||
int dt_src_blend_mode, dt_dst_blend_mode;
|
||||
|
||||
int unused[20]; // future expansion to maintain compatibility with h2
|
||||
} m32tex_t;
|
||||
|
||||
/* .BSP file format */
|
||||
|
||||
#define IDBSPHEADER (('P' << 24) + ('S' << 16) + ('B' << 8) + 'I') /* little-endian "IBSP" */
|
||||
|
|
Loading…
Reference in a new issue