mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-10 07:12:07 +00:00
soft: resuse image load code for wal
This commit is contained in:
parent
0c2bf1f65d
commit
eb979d73ed
1 changed files with 62 additions and 49 deletions
|
@ -210,12 +210,15 @@ R_LoadPic
|
||||||
================
|
================
|
||||||
*/
|
*/
|
||||||
static image_t *
|
static image_t *
|
||||||
R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int realheight, imagetype_t type)
|
R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int realheight,
|
||||||
|
size_t data_size, imagetype_t type)
|
||||||
{
|
{
|
||||||
image_t *image;
|
image_t *image;
|
||||||
size_t i, size, full_size;
|
size_t i, size, full_size;
|
||||||
|
|
||||||
if (!pic)
|
size = width * height;
|
||||||
|
|
||||||
|
if (!pic || data_size <= 0 || width <= 0 || height <= 0 || size <= 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
image = R_FindFreeImage();
|
image = R_FindFreeImage();
|
||||||
|
@ -230,7 +233,6 @@ R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int real
|
||||||
image->asset_height = realheight;
|
image->asset_height = realheight;
|
||||||
image->type = type;
|
image->type = type;
|
||||||
|
|
||||||
size = width * height;
|
|
||||||
full_size = R_GetImageMipsSize(size);
|
full_size = R_GetImageMipsSize(size);
|
||||||
image->pixels[0] = malloc(full_size);
|
image->pixels[0] = malloc(full_size);
|
||||||
if (!image->pixels[0])
|
if (!image->pixels[0])
|
||||||
|
@ -239,7 +241,10 @@ R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int real
|
||||||
// code never returns after ERR_FATAL
|
// code never returns after ERR_FATAL
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
image->transparent = false;
|
image->transparent = false;
|
||||||
|
if (type != it_wall)
|
||||||
|
{
|
||||||
for (i=0 ; i<size ; i++)
|
for (i=0 ; i<size ; i++)
|
||||||
{
|
{
|
||||||
if (pic[i] == 255)
|
if (pic[i] == 255)
|
||||||
|
@ -248,12 +253,23 @@ R_LoadPic (char *name, byte *pic, int width, int realwidth, int height, int real
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data_size > full_size)
|
||||||
|
{
|
||||||
|
data_size = full_size;
|
||||||
|
}
|
||||||
|
memcpy(image->pixels[0], pic, data_size);
|
||||||
|
|
||||||
memcpy(image->pixels[0], pic, size);
|
|
||||||
// restore mips
|
// restore mips
|
||||||
R_RestoreImagePointers(image, 0);
|
R_RestoreImagePointers(image, 0);
|
||||||
// restore everything from first image
|
|
||||||
|
if (full_size > data_size)
|
||||||
|
{
|
||||||
|
// looks short, restore everything from first image
|
||||||
R_RestoreMips(image, 0);
|
R_RestoreMips(image, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +284,7 @@ R_LoadWal (char *name, imagetype_t type)
|
||||||
miptex_t *mt;
|
miptex_t *mt;
|
||||||
int ofs;
|
int ofs;
|
||||||
image_t *image;
|
image_t *image;
|
||||||
size_t size, file_size;
|
size_t file_size, width, height;
|
||||||
|
|
||||||
file_size = ri.FS_LoadFile (name, (void **)&mt);
|
file_size = ri.FS_LoadFile (name, (void **)&mt);
|
||||||
if (!mt)
|
if (!mt)
|
||||||
|
@ -284,48 +300,32 @@ R_LoadWal (char *name, imagetype_t type)
|
||||||
return r_notexture_mip;
|
return r_notexture_mip;
|
||||||
}
|
}
|
||||||
|
|
||||||
image = R_FindFreeImage ();
|
width = LittleLong (mt->width);
|
||||||
strcpy (image->name, name);
|
height = LittleLong (mt->height);
|
||||||
image->width = LittleLong (mt->width);
|
|
||||||
image->height = LittleLong (mt->height);
|
|
||||||
image->asset_width = image->width;
|
|
||||||
image->asset_height = image->height;
|
|
||||||
image->type = type;
|
|
||||||
image->registration_sequence = registration_sequence;
|
|
||||||
ofs = LittleLong(mt->offsets[0]);
|
ofs = LittleLong(mt->offsets[0]);
|
||||||
size = R_GetImageMipsSize(image->width * image->height);
|
|
||||||
|
|
||||||
if ((ofs <= 0) || (image->width <= 0) || (image->height <= 0) ||
|
if ((ofs <= 0) || (width <= 0) || (height <= 0) ||
|
||||||
((file_size - ofs) / image->width < image->height))
|
((file_size - ofs) / width < height))
|
||||||
{
|
{
|
||||||
R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name);
|
R_Printf(PRINT_ALL, "%s: can't load %s, small body\n", __func__, name);
|
||||||
ri.FS_FreeFile((void *)mt);
|
ri.FS_FreeFile((void *)mt);
|
||||||
return r_notexture_mip;
|
return r_notexture_mip;
|
||||||
}
|
}
|
||||||
|
|
||||||
image->pixels[0] = malloc (size);
|
image = R_LoadPic(name, (byte *)mt + ofs,
|
||||||
R_RestoreImagePointers(image, 0);
|
width, width,
|
||||||
|
height, height,
|
||||||
if (size > (file_size - ofs))
|
(file_size - ofs), type);
|
||||||
{
|
|
||||||
memcpy(image->pixels[0], (byte *)mt + ofs, file_size - ofs);
|
|
||||||
// looks short, restore everything from first image
|
|
||||||
R_RestoreMips(image, 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memcpy(image->pixels[0], (byte *)mt + ofs, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
ri.FS_FreeFile((void *)mt);
|
ri.FS_FreeFile((void *)mt);
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *d_16to8table; // 16 to 8 bit conversion table
|
static unsigned char *d_16to8table = NULL; // 16 to 8 bit conversion table
|
||||||
|
|
||||||
static void
|
static void
|
||||||
R_Convert32To8bit(const unsigned char* pic_in, unsigned char* pic_out, size_t size)
|
R_Convert32To8bit(const unsigned char* pic_in, pixel_t* pic_out, size_t size)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
@ -336,20 +336,21 @@ R_Convert32To8bit(const unsigned char* pic_in, unsigned char* pic_out, size_t si
|
||||||
{
|
{
|
||||||
unsigned int r, g, b, c;
|
unsigned int r, g, b, c;
|
||||||
|
|
||||||
r = ( pic_in[i * 4 + 0] >> 3 ) & 31;
|
r = ( pic_in[0] >> 3 ) & 31;
|
||||||
g = ( pic_in[i * 4 + 1] >> 2 ) & 63;
|
g = ( pic_in[1] >> 2 ) & 63;
|
||||||
b = ( pic_in[i * 4 + 2] >> 3 ) & 31;
|
b = ( pic_in[2] >> 3 ) & 31;
|
||||||
|
|
||||||
c = r | ( g << 5 ) | ( b << 11 );
|
c = r | ( g << 5 ) | ( b << 11 );
|
||||||
|
|
||||||
pic_out[i] = d_16to8table[c & 0xFFFF];
|
pic_out[i] = d_16to8table[c & 0xFFFF];
|
||||||
|
pic_in += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
R_FixPalette(unsigned char* pixels, size_t size, rgb_t* pallette)
|
R_FixPalette(pixel_t* pixels, size_t size, const rgb_t* pallette)
|
||||||
{
|
{
|
||||||
unsigned char* convert = malloc(256);
|
pixel_t* convert = malloc(256);
|
||||||
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
@ -554,14 +555,20 @@ R_LoadHiColorImage(char *name, const char* namewe, const char *ext, imagetype_t
|
||||||
pic32, uploadwidth, uploadheight))
|
pic32, uploadwidth, uploadheight))
|
||||||
{
|
{
|
||||||
R_Convert32To8bit(pic32, pic8, uploadwidth * uploadheight);
|
R_Convert32To8bit(pic32, pic8, uploadwidth * uploadheight);
|
||||||
image = R_LoadPic(name, pic8, uploadwidth, realwidth, uploadheight, realheight, type);
|
image = R_LoadPic(name, pic8,
|
||||||
|
uploadwidth, realwidth,
|
||||||
|
uploadheight, realheight,
|
||||||
|
uploadwidth * uploadheight, type);
|
||||||
}
|
}
|
||||||
free(pic32);
|
free(pic32);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
R_Convert32To8bit(pic, pic8, width * height);
|
R_Convert32To8bit(pic, pic8, width * height);
|
||||||
image = R_LoadPic(name, pic8, width, width, height, height, type);
|
image = R_LoadPic(name, pic8,
|
||||||
|
width, width,
|
||||||
|
height, height,
|
||||||
|
width * height, type);
|
||||||
}
|
}
|
||||||
free(pic8);
|
free(pic8);
|
||||||
}
|
}
|
||||||
|
@ -614,12 +621,18 @@ R_LoadImage(char *name, const char* namewe, const char *ext, imagetype_t type)
|
||||||
scale2x(pic, scaled, width, height);
|
scale2x(pic, scaled, width, height);
|
||||||
width *= 2;
|
width *= 2;
|
||||||
height *= 2;
|
height *= 2;
|
||||||
image = R_LoadPic(name, scaled, width, realwidth, height, realheight, type);
|
image = R_LoadPic(name, scaled,
|
||||||
|
width, realwidth,
|
||||||
|
height, realheight,
|
||||||
|
width * height, type);
|
||||||
free(scaled);
|
free(scaled);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
image = R_LoadPic(name, pic, width, width, height, height, type);
|
image = R_LoadPic(name, pic,
|
||||||
|
width, width,
|
||||||
|
height, height,
|
||||||
|
width * height, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (palette)
|
if (palette)
|
||||||
|
@ -793,9 +806,9 @@ R_InitTextures (void)
|
||||||
{
|
{
|
||||||
if ( (y< (8>>m) ) ^ (x< (8>>m) ) )
|
if ( (y< (8>>m) ) ^ (x< (8>>m) ) )
|
||||||
|
|
||||||
*dest++ = 0;
|
*dest++ = d_16to8table[0x0000];
|
||||||
else
|
else
|
||||||
*dest++ = 0xff;
|
*dest++ = d_16to8table[0xFFFF];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue