mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
cin: add lmp image format support
This commit is contained in:
parent
f1d8387d81
commit
7ee871dc76
3 changed files with 76 additions and 50 deletions
|
@ -96,36 +96,6 @@ typedef struct
|
|||
|
||||
cinematics_t cin;
|
||||
|
||||
static void
|
||||
SCR_LoadPCX(char *filename, byte **pic, byte **palette, int *width, int *height,
|
||||
int *bitsPerPixel)
|
||||
{
|
||||
byte *data, *palette_in;
|
||||
|
||||
*pic = NULL;
|
||||
*palette = NULL;
|
||||
|
||||
VID_ImageDecode(filename, &data, &palette_in, width, height, bitsPerPixel);
|
||||
|
||||
if (data)
|
||||
{
|
||||
*pic = Z_Malloc((*width) * (*height) * (*bitsPerPixel) / 8);
|
||||
memcpy(*pic, data, (*height) * (*width) * (*bitsPerPixel) / 8);
|
||||
free(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Com_Printf("Bad pcx file %s\n", filename);
|
||||
}
|
||||
|
||||
if (palette_in)
|
||||
{
|
||||
*palette = Z_Malloc(768);
|
||||
memcpy(*palette, palette_in, 768);
|
||||
free(palette_in);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SCR_StopCinematic(void)
|
||||
{
|
||||
|
@ -779,26 +749,28 @@ SCR_DrawCinematic(void)
|
|||
|
||||
static byte *
|
||||
SCR_LoadHiColor(const char* namewe, const char *ext, int *width, int *height,
|
||||
int *bitsPerPixel)
|
||||
byte **palette, int *bitsPerPixel)
|
||||
{
|
||||
byte *pic, *data = NULL, *palette = NULL;
|
||||
byte *pic, *data = NULL, *palette_in = NULL;
|
||||
char filename[256];
|
||||
|
||||
Q_strlcpy(filename, namewe, sizeof(filename));
|
||||
Q_strlcat(filename, ".", sizeof(filename));
|
||||
Q_strlcat(filename, ext, sizeof(filename));
|
||||
|
||||
VID_ImageDecode(filename, &data, &palette,
|
||||
VID_ImageDecode(filename, &data, &palette_in,
|
||||
width, height, bitsPerPixel);
|
||||
if (data == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (palette)
|
||||
if (palette_in)
|
||||
{
|
||||
/* strange, here should be no palleted image */
|
||||
free(palette);
|
||||
/* pcx file could have palette */
|
||||
*palette = Z_Malloc(768);
|
||||
memcpy(*palette, palette_in, 768);
|
||||
free(palette_in);
|
||||
}
|
||||
|
||||
pic = Z_Malloc(cin.height * cin.width * (*bitsPerPixel) / 8);
|
||||
|
@ -826,44 +798,45 @@ SCR_PlayCinematic(char *arg)
|
|||
|
||||
/* static pcx image */
|
||||
if (dot && (!strcmp(dot, ".pcx") ||
|
||||
!strcmp(dot, ".lmp") ||
|
||||
!strcmp(dot, ".tga") ||
|
||||
!strcmp(dot, ".jpg") ||
|
||||
!strcmp(dot, ".png")))
|
||||
{
|
||||
cvar_t *r_retexturing;
|
||||
char namewe[256];
|
||||
|
||||
Com_sprintf(name, sizeof(name), "pics/%s", arg);
|
||||
r_retexturing = Cvar_Get("r_retexturing", "1", CVAR_ARCHIVE);
|
||||
|
||||
/* Remove the extension */
|
||||
memset(namewe, 0, 256);
|
||||
memcpy(namewe, name, strlen(name) - strlen(dot));
|
||||
|
||||
if (r_retexturing->value)
|
||||
{
|
||||
char namewe[256];
|
||||
|
||||
cin.color_bits = 32;
|
||||
|
||||
/* Remove the extension */
|
||||
memset(namewe, 0, 256);
|
||||
memcpy(namewe, name, strlen(name) - strlen(dot));
|
||||
cin.pic = SCR_LoadHiColor(namewe, "tga", &cin.width, &cin.height,
|
||||
&cin.color_bits);
|
||||
&palette, &cin.color_bits);
|
||||
|
||||
if (!cin.pic)
|
||||
{
|
||||
cin.pic = SCR_LoadHiColor(namewe, "png", &cin.width, &cin.height,
|
||||
&cin.color_bits);
|
||||
&palette, &cin.color_bits);
|
||||
}
|
||||
|
||||
if (!cin.pic)
|
||||
{
|
||||
cin.pic = SCR_LoadHiColor(namewe, "jpg", &cin.width, &cin.height,
|
||||
&cin.color_bits);
|
||||
&palette, &cin.color_bits);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cin.pic)
|
||||
{
|
||||
SCR_LoadPCX(name, &cin.pic, &palette, &cin.width, &cin.height,
|
||||
&cin.color_bits);
|
||||
cin.pic = SCR_LoadHiColor(namewe, dot + 1, &cin.width, &cin.height,
|
||||
&palette, &cin.color_bits);
|
||||
}
|
||||
|
||||
cl.cinematicframe = -1;
|
||||
|
@ -882,6 +855,18 @@ SCR_PlayCinematic(char *arg)
|
|||
memcpy(cl.cinematicpalette, palette, sizeof(cl.cinematicpalette));
|
||||
Z_Free(palette);
|
||||
}
|
||||
else if (cin.color_bits == 8)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* palette r:2bit, g:3bit, b:3bit */
|
||||
for (i = 0; i < sizeof(cl.cinematicpalette); i++)
|
||||
{
|
||||
cl.cinematicpalette[i * 3 + 0] = ((i >> 0) & 0x3) << 6;
|
||||
cl.cinematicpalette[i * 3 + 1] = ((i >> 2) & 0x7) << 5;
|
||||
cl.cinematicpalette[i * 3 + 2] = ((i >> 5) & 0x7) << 5;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -491,7 +491,7 @@ SWL_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
return;
|
||||
}
|
||||
|
||||
*pic = malloc (len - ofs);
|
||||
*pic = malloc(len - ofs);
|
||||
memcpy(*pic, (byte *)mt + ofs, len - ofs);
|
||||
|
||||
if (palette)
|
||||
|
@ -543,7 +543,7 @@ M32_Decode(const char *name, const byte *raw, int len, byte **pic, int *width, i
|
|||
Com_DPrintf("%s: can't load %s small body\n", __func__, name);
|
||||
}
|
||||
|
||||
*pic = malloc (len - ofs);
|
||||
*pic = malloc(len - ofs);
|
||||
memcpy(*pic, (byte *)mt + ofs, len - ofs);
|
||||
}
|
||||
|
||||
|
@ -619,7 +619,7 @@ LoadWalQ2(const char *name, const byte *raw, int len, byte **pic, byte **palette
|
|||
return;
|
||||
}
|
||||
|
||||
*pic = malloc (len - ofs);
|
||||
*pic = malloc(len - ofs);
|
||||
memcpy(*pic, (byte *)mt + ofs, len - ofs);
|
||||
}
|
||||
|
||||
|
@ -655,7 +655,7 @@ LoadWalDKM(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
return;
|
||||
}
|
||||
|
||||
*pic = malloc (len - ofs);
|
||||
*pic = malloc(len - ofs);
|
||||
memcpy(*pic, (byte *)mt + ofs, len - ofs);
|
||||
|
||||
if (palette)
|
||||
|
@ -679,6 +679,41 @@ WAL_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
LMP_Decode(const char *name, const byte *raw, int len, byte **pic,
|
||||
int *width, int *height)
|
||||
{
|
||||
unsigned lmp_width = 0, lmp_height = 0, lmp_size = 0;
|
||||
if (len < (sizeof(int) * 3))
|
||||
{
|
||||
/* looks too small */
|
||||
return;
|
||||
}
|
||||
|
||||
lmp_width = LittleLong(((int*)raw)[0]) & 0xFFFF;
|
||||
lmp_height = LittleLong(((int*)raw)[1]) & 0xFFFF;
|
||||
lmp_size = lmp_height * lmp_width;
|
||||
if ((lmp_size + sizeof(int) * 2) > len)
|
||||
{
|
||||
Com_Printf("%s: can't load %s, small body %dx%d ? %d\n",
|
||||
__func__, name, lmp_width, lmp_height, len);
|
||||
return;
|
||||
}
|
||||
|
||||
*pic = malloc(lmp_size);
|
||||
memcpy(*pic, raw + sizeof(int) * 2, lmp_size);
|
||||
|
||||
if (width)
|
||||
{
|
||||
*width = lmp_width;
|
||||
}
|
||||
|
||||
if (height)
|
||||
{
|
||||
*height = lmp_height;
|
||||
}
|
||||
}
|
||||
|
||||
static byte
|
||||
Convert24to8(const byte *d_8to24table, const int rgb[3])
|
||||
{
|
||||
|
@ -825,6 +860,11 @@ LoadImageWithPalette(const char *filename, byte **pic, byte **palette,
|
|||
WAL_Decode(filename, raw, len, pic, palette, width, height);
|
||||
*bitsPerPixel = 8;
|
||||
}
|
||||
else if (!strcmp(ext, "lmp"))
|
||||
{
|
||||
LMP_Decode(filename, raw, len, pic, width, height);
|
||||
*bitsPerPixel = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
int sourcebitsPerPixel = 0;
|
||||
|
|
|
@ -595,6 +595,7 @@ SV_Map(qboolean attractloop, char *levelstring, qboolean loadgame, qboolean isau
|
|||
SV_SpawnServer(level, spawnpoint, ss_demo, attractloop, loadgame, isautosave);
|
||||
}
|
||||
else if ((l > 4) && (!strcmp(level + l - 4, ".pcx") ||
|
||||
!strcmp(level + l - 4, ".lmp") ||
|
||||
!strcmp(level + l - 4, ".tga") ||
|
||||
!strcmp(level + l - 4, ".jpg") ||
|
||||
!strcmp(level + l - 4, ".png")))
|
||||
|
|
Loading…
Reference in a new issue