/* * R_SkinFileForName */ static skinfile_t *R_SkinFileForName( const char *name ) { char filename[MAX_QPATH]; int i; char *buffer; skinfile_t *skinfile; Q_strncpyz( filename, name, sizeof( filename ) ); COM_DefaultExtension( filename, ".skin", sizeof( filename ) ); for( i = 0, skinfile = r_skinfiles; i < r_numskinfiles; i++, skinfile++ ) { if( !skinfile->name ) { break; // free slot } if( !Q_stricmp( skinfile->name, filename ) ) { return skinfile; } } if( i == MAX_SKINFILES ) { Com_Printf( S_COLOR_YELLOW "R_SkinFile_Load: Skin files limit exceeded\n" ); return NULL; } if( R_LoadFile( filename, (void **)&buffer ) == -1 ) { ri.Com_DPrintf( S_COLOR_YELLOW "R_SkinFile_Load: Failed to load %s\n", name ); return NULL; } r_numskinfiles++; skinfile = &r_skinfiles[i]; skinfile->name = R_CopyString( filename ); skinfile->numpairs = SkinFile_ParseBuffer( buffer, NULL ); if( skinfile->numpairs ) { skinfile->pairs = R_Malloc( skinfile->numpairs * sizeof( mesh_shader_pair_t ) ); SkinFile_ParseBuffer( buffer, skinfile->pairs ); } else { ri.Com_DPrintf( S_COLOR_YELLOW "R_SkinFile_Load: no mesh/shader pairs in %s\n", name ); } R_FreeFile( (void *)buffer ); return skinfile; }
/* * LoadTGA */ r_imginfo_t LoadTGA( const char *name, qbyte *(*allocbuf)( void *, size_t, const char *, int ), void *uptr ) { int i, j, columns, rows, samples; qbyte *buf_p, *buffer, *pixbuf, *targa_rgba; qbyte palette[256][4]; TargaHeader targa_header; r_imginfo_t imginfo; memset( &imginfo, 0, sizeof( imginfo ) ); // // load the file // R_LoadFile( name, (void **)&buffer ); if( !buffer ) return imginfo; buf_p = buffer; targa_header.id_length = *buf_p++; targa_header.colormap_type = *buf_p++; targa_header.image_type = *buf_p++; targa_header.colormap_index = buf_p[0] + buf_p[1] * 256; buf_p += 2; targa_header.colormap_length = buf_p[0] + buf_p[1] * 256; buf_p += 2; targa_header.colormap_size = *buf_p++; targa_header.x_origin = LittleShort( *( (short *)buf_p ) ); buf_p += 2; targa_header.y_origin = LittleShort( *( (short *)buf_p ) ); buf_p += 2; targa_header.width = LittleShort( *( (short *)buf_p ) ); buf_p += 2; targa_header.height = LittleShort( *( (short *)buf_p ) ); buf_p += 2; targa_header.pixel_size = *buf_p++; targa_header.attributes = *buf_p++; if( targa_header.id_length != 0 ) buf_p += targa_header.id_length; // skip TARGA image comment samples = 3; if( targa_header.image_type == 1 || targa_header.image_type == 9 ) { // uncompressed colormapped image if( targa_header.pixel_size != 8 ) { ri.Com_DPrintf( S_COLOR_YELLOW "LoadTGA: Only 8 bit images supported for type 1 and 9" ); R_FreeFile( buffer ); return imginfo; } if( targa_header.colormap_length != 256 ) { ri.Com_DPrintf( S_COLOR_YELLOW "LoadTGA: Only 8 bit colormaps are supported for type 1 and 9" ); R_FreeFile( buffer ); return imginfo; } if( targa_header.colormap_index ) { ri.Com_DPrintf( S_COLOR_YELLOW "LoadTGA: colormap_index is not supported for type 1 and 9" ); R_FreeFile( buffer ); return imginfo; } if( targa_header.colormap_size == 24 ) { for( i = 0; i < targa_header.colormap_length; i++ ) { palette[i][2] = *buf_p++; palette[i][1] = *buf_p++; palette[i][0] = *buf_p++; palette[i][3] = 255; } } else if( targa_header.colormap_size == 32 ) { samples = 4; for( i = 0; i < targa_header.colormap_length; i++ ) { palette[i][2] = *buf_p++; palette[i][1] = *buf_p++; palette[i][0] = *buf_p++; palette[i][3] = *buf_p++; } } else { ri.Com_DPrintf( S_COLOR_YELLOW "LoadTGA: only 24 and 32 bit colormaps are supported for type 1 and 9" ); R_FreeFile( buffer ); return imginfo; } } else if( targa_header.image_type == 2 || targa_header.image_type == 10 ) { // uncompressed or RLE compressed RGB if( targa_header.pixel_size != 32 && targa_header.pixel_size != 24 ) { ri.Com_DPrintf( S_COLOR_YELLOW "LoadTGA: Only 32 or 24 bit images supported for type 2 and 10" ); R_FreeFile( buffer ); return imginfo; } samples = targa_header.pixel_size >> 3; } else if( targa_header.image_type == 3 || targa_header.image_type == 11 )