Exemple #1
0
void CAL_SetupGrFile()
{
    char fname[13];
    bstone::FileStream handle;
    Uint8* compseg;

    //
    // load ???dict.ext (huffman dictionary for graphics files)
    //

    strcpy(fname, gdictname);
    strcat(fname, extension);

    handle.open(fname);

    if (!handle.is_open())
        CA_CannotOpen(fname);

    handle.read(&grhuffman, sizeof(grhuffman));

    //
    // load the data offsets from ???head.ext
    //
    int grstarts_size = (NUMCHUNKS + 1) * FILEPOSSIZE;

    grstarts = new Sint32[(grstarts_size + 3) / 4];

    strcpy(fname, gheadname);
    strcat(fname, extension);

    handle.open(fname);

    if (!handle.is_open())
        CA_CannotOpen(fname);

    handle.read(grstarts, grstarts_size);

    //
    // Open the graphics file, leaving it open until the game is finished
    //
    OpenGrFile();

    //
    // load the pic and sprite headers into the arrays in the data segment
    //
    pictable = new pictabletype[NUMPICS];
    CAL_GetGrChunkLength(STRUCTPIC);		// position file pointer
    compseg = new Uint8[chunkcomplen];
    grhandle.read(compseg, chunkcomplen);

    CAL_HuffExpand(
        compseg,
        (Uint8*)pictable,
        NUMPICS * sizeof(pictabletype),
        grhuffman);

    delete [] compseg;
}
Exemple #2
0
/*
-----------------------------------------------------------------------------
 Function: CAL_ExpandGrChunk() -Expand compressed graphic chunk.
 
 Parameters: chunk -[in] Chunk number to expand.
             source -[in] Pointer to compressed data.
             version -[in] extension version. 
                        1 -WL6
                        2 -SOD 
 
 Returns: Nothing.
 
 Notes: 
-----------------------------------------------------------------------------
*/
PRIVATE void CAL_ExpandGrChunk( W32 chunk, const W8 *source, W16 version )
{
	W32 expanded;
	W16	 offset = 0;

	if( version & SOD_PAK )
        offset = SOD_STARTDIFF;

	if( chunk >= ( STARTTILE8 + offset ) && 
        chunk < ( STARTEXTERNS + offset ) )
	{
	//
	// expanded sizes of tile8/16/32 are implicit
	//

#define BLOCK		64
#define MASKBLOCK	128

		if( chunk < (STARTTILE8M + offset) ) // tile 8s are all in one chunk!
			expanded = BLOCK * NUMTILE8;
		else if( chunk < (STARTTILE16 + offset) )
			expanded = MASKBLOCK * NUMTILE8M;
		else if( chunk < (STARTTILE16M + offset) )	// all other tiles are one/chunk
			expanded = BLOCK << 2;
		else if( chunk < (STARTTILE32 + offset) )
			expanded = MASKBLOCK << 2;
		else if( chunk < (STARTTILE32M + offset) )
			expanded = BLOCK << 4;
		else
			expanded = MASKBLOCK << 4;
	}
	else
	{
	//
	// everything else has an explicit size longword
	//
		expanded = *(PW32)source;
		source += 4;			// skip over length
	}

//
// allocate final space and decompress it.
// Sprites need to have shifts made and various other junk.
//
	grsegs[ chunk ] = MM_MALLOC( expanded );
	if( grsegs[ chunk ] == NULL )
	{
		return;
	}
	
	CAL_HuffExpand( source, grsegs[ chunk ], expanded, grhuffman );
}
Exemple #3
0
static void CAL_ExpandGrChunkSOD(int chunk, const byte *source)
{
	int tilecount = 0, i;
	long expanded;

	int width = 0, height = 0;

	if (chunk >= STARTTILE8SOD && chunk < STARTEXTERNSSOD)
	{
	/* expanded sizes of tile8 are implicit */
		expanded = 8*8*NUMTILE8;
		width = 8;
		height = 8;
		tilecount = NUMTILE8;
	} else if (chunk >= STARTPICS && chunk < STARTTILE8SOD) {
		width = pictableSOD[chunk - STARTPICS].width;
		height = pictableSOD[chunk - STARTPICS].height;
		expanded = source[0]|(source[1]<<8)|(source[2]<<16)|(source[3]<<24);
		source += 4;
	} else {
	/* everything else has an explicit size longword */
		expanded = source[0]|(source[1]<<8)|(source[2]<<16)|(source[3]<<24);
		source += 4;
	}

/* allocate final space and decompress it */
	MM_GetPtr((void *)&grsegsSOD[chunk], expanded);
	CAL_HuffExpand(source, grsegsSOD[chunk], expanded, grhuffman);
	if (width && height) {
		if (tilecount) {
			for (i = 0; i < tilecount; i++) 
				VL_DeModeXize(grsegsSOD[chunk]+(width*height)*i, width, height);
		} else			
			VL_DeModeXize(grsegsSOD[chunk], width, height);
	}
}
Exemple #4
0
/*
-----------------------------------------------------------------------------
 Function: CAL_SetupGrFile() -Initialize graphic files and arrays.
 
 Parameters: extension -[in] Pointer to a null-terminated string that 
                            specifies the file extension.
                            (must be in '.XXX' format).
 
 Returns: 1 on success, 0 otherwise.
 
 Notes: 
        Uses global variables grhandle and pictable.
        1. Open vgadict.XXX, read huffman dictionary data.
        2. Open vgahead.XXX, read data offsets.
        3. Open vgagraph.XXX, read pic and sprite header, expand data.
-----------------------------------------------------------------------------
*/
PRIVATE W8 CAL_SetupGrFile( const char *extension )
{
	void *compseg;
	FILE *handle;
	char filename[ 16 ];
	SW32 chunkcomplen; // chunk compressed length
	
//
// load vgadict.ext (huffman dictionary for graphics files)
//
	cs_strlcpy( filename, GFXDICTFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( ( handle = fopen( cs_strupr( filename ), "rb" ) ) ==  NULL )
	{
		if( ( handle = fopen( cs_strlwr( filename ), "rb" ) ) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
  
	fread( grhuffman, sizeof( grhuffman ), 1, handle );
	fclose( handle );
	
//
// Open then load the data offsets from vgahead.ext
//	
	
	cs_strlcpy( filename, GFXHEADFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( (handle = fopen( cs_strupr( filename ), "rb" )) ==  NULL )
	{
		if( (handle = fopen( cs_strlwr( filename ), "rb" )) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
	
	grstarts = MM_MALLOC( (NUMCHUNKS+1) * FILEPOSSIZE );
	if( grstarts == NULL )
	{
		return 0;
	}
  
	fread( grstarts, sizeof( long ), (NUMCHUNKS+1) * FILEPOSSIZE, handle );
	
	fclose( handle );
	
//
// Open the graphics file 'vgagraph.XXX'.
//
	
	cs_strlcpy( filename, GFXFNAME, sizeof( filename ) );
	cs_strlcat( filename, extension, sizeof( filename ) );
	
	if( ( grhandle = fopen( cs_strupr( filename ), "rb" ) ) ==  NULL )
	{
		if( ( grhandle = fopen( cs_strlwr( filename ), "rb" ) ) ==  NULL )
		{
			printf( "Could not open file (%s) for read!\n", filename );
			return 0;
		}
	}
  
//
// load the pic and sprite headers into the arrays.
//
	pictable = MM_MALLOC( NUMPICS * sizeof( pictabletype ) );
	if( pictable == NULL )
	{
		return 0;
	}
  
  
	chunkcomplen = CAL_GetGrChunkLength( STRUCTPIC );  // position file pointer
	
	compseg = MM_MALLOC( chunkcomplen );
	if( compseg == NULL )
	{
		return 0;
	}
	
	fread( compseg, chunkcomplen, 1, grhandle );
	
	CAL_HuffExpand( compseg, (PW8)pictable, 
	                NUMPICS * sizeof( pictabletype ), 
                    grhuffman );

	MM_FREE( compseg ); 
 
    return 1;                 
}