engine/EngineVideoTextureManager.c
/*	Reloads a texture, and colormaps it if needed
*/
Reloads a texture, and colormaps it if needed
Reloads a texture and colormaps it if needed
void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants)
{
	uint8_t	translation[256];
	uint8_t	*src, *dst, *data = NULL, *translated;
	int	mark, size, i;
	mark = Hunk_LowMark ();
	if (glt->source_file[0] && glt->source_offset)
	{
		data = COM_LoadHunkFile (glt->source_file);
		if (!data)
			goto invalid;
		data += glt->source_offset;
	}
	else if (glt->source_file[0] && !glt->source_offset)
		data = Image_LoadImage(glt->source_file,&glt->source_width,&glt->source_height); 
	else if (!glt->source_file[0] && glt->source_offset)
		data = (uint8_t*)glt->source_offset; 
	if(!data)
	{
invalid:
		Con_Printf ("TexMgr_ReloadImage: invalid source for %s\n", glt->name);
		Hunk_FreeToLowMark(mark);
		return;
	}
	glt->width  = glt->source_width;
	glt->height = glt->source_height;
	if (shirt > -1 && pants > -1)
	{
		if (glt->source_format == SRC_INDEXED)
		{
			glt->shirt = shirt;
			glt->pants = pants;
		}
		else
			Con_Printf ("TexMgr_ReloadImage: can't colormap a non SRC_INDEXED texture: %s\n", glt->name);
	}
	if (glt->shirt > -1 && glt->pants > -1)
	{
		for (i=0 ; i<256 ; i++)
			translation[i] = i;
		shirt = glt->shirt * 16;
		if (shirt < 128)
			for (i=0 ; i<16 ; i++)
				translation[TOP_RANGE+i] = shirt+i;
		else
			for (i=0 ; i<16 ; i++)
				translation[TOP_RANGE+i] = shirt+15-i;
		pants = glt->pants * 16;
		if (pants < 128)
			for (i=0 ; i<16 ; i++)
				translation[BOTTOM_RANGE+i] = pants+i;
		else
			for (i=0 ; i<16 ; i++)
				translation[BOTTOM_RANGE+i] = pants+15-i;
		size = glt->width * glt->height;
		dst = translated = (byte*)Hunk_Alloc (size);
		src = data;
		for (i=0; i<size; i++)
			*dst++ = translation[*src++];
		data = translated;
	}
	switch (glt->source_format)
	{
		case SRC_INDEXED:
			TexMgr_LoadImage8 (glt, data);
			break;
		case SRC_LIGHTMAP:
			TexMgr_LoadLightmap (glt, data);
			break;
		case SRC_RGBA:
			TexMgr_LoadImage32 (glt, data);
			break;
	}
	Hunk_FreeToLowMark(mark);
}
void TexMgr_ReloadImage ( gltexture_t * glt , int shirt , int pants ) { uint8_t translation [ 256 ] ; uint8_t * src , * dst , * data = NULL , * translated ; int mark , size , i ; mark = Hunk_LowMark ( ) ; if ( glt -> source_file [ 0 ] && glt -> source_offset ) { data = COM_LoadHunkFile ( glt -> source_file ) ; if ( ! data ) goto invalid ; data += glt -> source_offset ; } else if ( glt -> source_file [ 0 ] && ! glt -> source_offset ) data = Image_LoadImage ( glt -> source_file , & glt -> source_width , & glt -> source_height ) ; else if ( ! glt -> source_file [ 0 ] && glt -> source_offset ) data = ( uint8_t * ) glt -> source_offset ; if ( ! data ) { invalid : Con_Printf ( " \n " , glt -> name ) ; Hunk_FreeToLowMark ( mark ) ; return ; } glt -> width = glt -> source_width ; glt -> height = glt -> source_height ; if ( shirt > -1 && pants > -1 ) { if ( glt -> source_format == SRC_INDEXED ) { glt -> shirt = shirt ; glt -> pants = pants ; } else Con_Printf ( " \n " , glt -> name ) ; } if ( glt -> shirt > -1 && glt -> pants > -1 ) { for ( i = 0 ; i < 256 ; i ++ ) translation [ i ] = i ; shirt = glt -> shirt * 16 ; if ( shirt < 128 ) for ( i = 0 ; i < 16 ; i ++ ) translation [ TOP_RANGE + i ] = shirt + i ; else for ( i = 0 ; i < 16 ; i ++ ) translation [ TOP_RANGE + i ] = shirt + 15 - i ; pants = glt -> pants * 16 ; if ( pants < 128 ) for ( i = 0 ; i < 16 ; i ++ ) translation [ BOTTOM_RANGE + i ] = pants + i ; else for ( i = 0 ; i < 16 ; i ++ ) translation [ BOTTOM_RANGE + i ] = pants + 15 - i ; size = glt -> width * glt -> height ; dst = translated = ( byte * ) Hunk_Alloc ( size ) ; src = data ; for ( i = 0 ; i < size ; i ++ ) * dst ++ = translation [ * src ++ ] ; data = translated ; } switch ( glt -> source_format ) { case SRC_INDEXED : TexMgr_LoadImage8 ( glt , data ) ; break ; case SRC_LIGHTMAP : TexMgr_LoadLightmap ( glt , data ) ; break ; case SRC_RGBA : TexMgr_LoadImage32 ( glt , data ) ; break ; } Hunk_FreeToLowMark ( mark ) ; }
Reloads a texture, and colormaps it if needed
Reloads a texture and colormaps it if needed
// Get source data //lump inside file //simple file //image in memory // apply shirt and pants colors // if shirt and pants are -1,-1, use existing shirt and pants colors // if existing shirt and pants colors are -1,-1, don't bother colormapping //create new translation table //translate texture // upload it