Ejemplo n.º 1
0
/**
 * \brief Redux the Page file data.
 * \param[in] vsfname data file name.
 * \param[in] wallPath Path to save wall data.
 * \param[in] spritePath Path to save sprite data.
 * \param[in] soundPath Path to save sound data.
 * \param[in] palette Palette array.
 * \return On success true, otherwise false.
 * \note Caller is responsible for freeing allocated data by calling MM_FREE.
 */
PUBLIC wtBoolean PageFile_ReduxDecodePageData( const char *vsfname, const char *wallPath, const char *spritePath, const char *soundPath, W8 *palette )
{
	void *data;
	void *decdata;
	W32 length;
	char tempFileName[ 1024 ];
	W32 i;
	W32 SpriteStart, NumBlocks, SoundStart;
	W32 soundBufferSize;
	W8 *soundBuffer;
	W32 totallength;


	printf( "Decoding Page Data..." );

	if( ! PageFile_Setup( vsfname, &NumBlocks, &SpriteStart, &SoundStart ) )
	{
		PageFile_Shutdown();

		return false;
	}

    // ////////////////////////////////////////////////////////////////////////
    // Decode Walls

	for( i = 0 ; i < SpriteStart ; ++i )
	{
		data = PageFile_getPage( i, &length );
		if( data == NULL )
		{
			continue;
		}

		decdata = PageFile_decodeWall_RGB32( (PW8)data, palette );
		if( decdata == NULL )
		{
			fprintf( stderr, "[PageFile_ReduxDecodePageData]: Unable to decode wall (%d).\n", i );

			MM_FREE( data );

			continue;
		}


		if( _filterScale > 0 )
		{
			void *scaledImgBuf;

			scaledImgBuf = (void *) MM_MALLOC( 128 * 128 * 4 );
			if( NULL == scaledImgBuf )
			{
				MM_FREE( data );
				MM_FREE( decdata );
				continue;
			}


			// Scale2x
		        if( _filterScale == 1 )
			{
		                scale( 2, (void *)scaledImgBuf, 128 * 4, decdata, 64 * 4, 4, 64, 64 );
				RGB32toRGB24( (const PW8)scaledImgBuf, (PW8)scaledImgBuf, 128 * 128 * 4 );
			} else {
		                // hq2x
		                RGB32toRGB24( (const PW8)decdata, (PW8)decdata, 64 * 64 * 4 );
		                RGB24toBGR565( decdata, decdata, 64 * 64 * 3 );
				hq2x_32( (PW8)decdata, (PW8)scaledImgBuf, 64, 64, 64 * 2 * 4  );
        		        RGB32toRGB24( (const PW8)scaledImgBuf, (PW8)scaledImgBuf, 128 * 128 * 4 );

        		}

    		        wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", wallPath, PATH_SEP, GetWallMappedIndex( i ) );
			TGA_write( tempFileName, 24, 128, 128, scaledImgBuf, 0, 1 );

			MM_FREE( scaledImgBuf );

		} else {
		        wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", wallPath, PATH_SEP, GetWallMappedIndex( i ) );

		        RGB32toRGB24( (const PW8)decdata, (PW8)decdata, 64 * 64 * 4 );
			TGA_write( tempFileName, 24, 64, 64, decdata, 0, 1 );
		}


		MM_FREE( data );
		MM_FREE( decdata );
	}


    // ////////////////////////////////////////////////////////////////////////
    // Decode Sprites

	for( i = SpriteStart ; i < SoundStart ; ++i )
	{
		data = PageFile_getPage( i, &length );
		if( data == NULL )
		{
			continue;
		}

		decdata = PageFile_decodeSprite_RGB32( (PW8)data, palette );
		if( decdata == NULL )
		{
			MM_FREE( data );

			continue;
		}

		if( _filterScale_Sprites > 0 )
		{
			W8 *scaledImgBuf;

			scaledImgBuf = (PW8) MM_MALLOC( 128 * 128 * 4 );
			if( NULL == scaledImgBuf ) {
				MM_FREE( data );
				MM_FREE( decdata );
				continue;
			}
			if( _filterScale_Sprites == 1 ) {
				scale( 2, (void *)scaledImgBuf, 128 * 4, decdata, 64 * 4, 4, 64, 64 );
			} else {
			// hq2x
				RGB32toRGB24( (const PW8)decdata, (PW8)decdata, 64 * 64 * 4 );
				RGB24toBGR565( decdata, decdata, 64 * 64 * 3 );
				hq2x_32( (PW8)decdata, (PW8)scaledImgBuf, 64, 64, 64 * 2 * 4  );
				ReduxAlphaChannel_hq2x( scaledImgBuf, 128, 128 );
			}

			wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", spritePath, PATH_SEP, GetSpriteMappedIndex( i - SpriteStart ) );
			TGA_write( tempFileName, 32, 128, 128, scaledImgBuf, 0, 1 );
			MM_FREE( scaledImgBuf );
		} else {
			wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", spritePath, PATH_SEP, GetSpriteMappedIndex( i - SpriteStart )  );
			TGA_write( tempFileName, 32, 64, 64, decdata, 0, 1 );
		}
		MM_FREE( data );
		MM_FREE( decdata );
	}


    // ////////////////////////////////////////////////////////////////////////
    // Decode SFX

	soundBufferSize = 20 * 4096;
	soundBuffer = (PW8) MM_MALLOC( soundBufferSize );
	if( soundBuffer == NULL )
	{
		PageFile_Shutdown();

		return false;
	}

	totallength = 0;
	for( i = SoundStart ; i < NumBlocks ; ++i )
	{
		data = PageFile_getPage( i, &length );
		if( data == NULL )
		{
			continue;
		}


		if( (totallength + length) > soundBufferSize )
		{
			fprintf( stderr, "[PageFile_ReduxDecodePageData]: Buffer not large enough to hold sound data!\n" );


			MM_FREE( data );
			MM_FREE( soundBuffer );

			return false;
		}

	  	MM_MEMCPY( soundBuffer + totallength, data, length );

		totallength += length;


		if( length < 4096 )
		{

			wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.wav", soundPath, PATH_SEP, i - SoundStart );
			wav_write( tempFileName, soundBuffer, totallength, 1, SAMPLERATE, 1 );


			totallength = 0;

		}


		MM_FREE( data );


	}
	MM_FREE( soundBuffer );

	PageFile_Shutdown();
	MM_FREE( data );

	printf( "Done\n" );

	return true;
}
/**
 * \brief Decodes Blake Stone Planet Strike data. 
 * \return Nothing. 
 */
PUBLIC void blakestonePS_decoder( void )
{
	W32 width, height;
	void *data;
	char fname[ 256 ];

	W8 *tempPalette;


	printf( "Blake Stone: Planet Strike Decoding\n\n" );

	if( ! buildCacheDirectories() )
    {
        fprintf( stderr, "Unable to create cache directories\n" );

		return;
    }
	
	if( GFXFile_Setup( "VGADICT.VSI", "VGAHEAD.VSI", "VGAGRAPH.VSI" ) )
	{
		GFXFile_decodeFont( 1, 256, 128, DIR_PICS );
		GFXFile_decodeFont( 2, 256, 128, DIR_PICS );
		GFXFile_decodeFont( 3, 256, 128, DIR_PICS );
		GFXFile_decodeFont( 4, 256, 128, DIR_PICS );
		GFXFile_decodeFont( 5, 256, 128, DIR_PICS );


        GFXFile_decodeScript( 216, 248, DIR_GSCRIPTS );
		

		GFXFile_decodeGFX( 6, 197, blakestone_gamepal, DIR_PICS );
	
		
		
		GFXFile_cacheChunk( 201 );
		tempPalette = (PW8)GFXFile_getChunk( 201 );

		data = GFXFile_decodeChunk_RGB24( 53, &width, &height, tempPalette );
		if( data )
		{
            wt_snprintf( fname, sizeof( fname ), "%s%c%.3d.tga", DIR_PICS, PATH_SEP, 53 );
			
			RGB24_adjustBrightness( data, width * height * 3 );
			
			TGA_write( fname, 24, width, height, data, 0, 1 );
			
			MM_FREE( data );
		}


		GFXFile_cacheChunk( 203 );
		tempPalette = (PW8)GFXFile_getChunk( 203 );

		data = GFXFile_decodeChunk_RGB24( 143, &width, &height, tempPalette );
		if( data )
		{
            wt_snprintf( fname, sizeof( fname ), "%s%c%.3d.tga", DIR_PICS, PATH_SEP, 143 );
			
			RGB24_adjustBrightness( data, width * height * 3 );
			
			TGA_write( fname, 24, width, height, data, 0, 1 );
			
			MM_FREE( data );
		}

		data = GFXFile_decodeChunk_RGB24( 144, &width, &height, tempPalette );
		if( data )
		{
            wt_snprintf( fname, sizeof( fname ), "%s%c%.3d.tga", DIR_PICS, PATH_SEP, 144 );
			
			RGB24_adjustBrightness( data, width * height * 3 );
			
			TGA_write( fname, 24, width, height, data, 0, 1 );
			
			MM_FREE( data );
		}
	
	}
	GFXFile_Shutdown();

	

	PageFile_ReduxDecodePageData( "VSWAP.VSI", DIR_WALLS, DIR_SPRITES, DIR_DSOUND, blakestone_gamepal );

/*
	if( AudioFile_Setup( "AUDIOHED.VSI", "AUDIOT.VSI" ) )
	{
		AudioFile_ReduxDecodeSound( 0, 0, DIR_SOUNDFX );

		AudioFile_ReduxDecodeMusic( 0, 0, DIR_MUSIC, NULL );
	}
	AudioFile_Shutdown();
*/
}
/**
 * \brief Decodes Blake Stone Aliens of Gold Full Version data. 
 * \return Nothing. 
 */
PUBLIC void blakestoneAGfull_decoder( void )
{
	W32 width, height;
	void *data;
	char fname[ 1024 ];

	W8 *tempPalette;

	printf( "\n\nBlake Stone: Aliens of Gold Decoding\n" );

	if( ! buildCacheDirectories() )
    {
        printf( "Unable to create cache directories\n" );

		return;
    }
	
	if( GFXFile_Setup( "VGADICT.BS6", "VGAHEAD.BS6", "VGAGRAPH.BS6" ) )
	{
		GFXFile_decodeFont( 1, 256, 128, DIR_PICS );
		GFXFile_decodeFont( 2, 256, 128, DIR_PICS );
		GFXFile_decodeFont( 3, 256, 128, DIR_PICS );
		GFXFile_decodeFont( 4, 256, 128, DIR_PICS );
		GFXFile_decodeFont( 5, 256, 128, DIR_PICS );

		GFXFile_decodeScript( 181, 223, DIR_GSCRIPTS );

		GFXFile_decodeGFX( 6, 164, blakestone_gamepal, DIR_PICS );


		GFXFile_cacheChunk( 168 );
		tempPalette = (PW8)GFXFile_getChunk( 168 );

		data = GFXFile_decodeChunk_RGB24( 29, &width, &height, tempPalette );
		if( data )
		{
			wt_snprintf( fname, sizeof( fname ), "%s%c%.3d.tga", DIR_PICS, PATH_SEP, 29 );
			
			RGB24_adjustBrightness( data, width * height * 3 );
			
			TGA_write( fname, 24, width, height, data, 0, 1 );
			
			MM_FREE( data );
		}


		GFXFile_cacheChunk( 167 );
		tempPalette = (PW8)GFXFile_getChunk( 167 );

		data = GFXFile_decodeChunk_RGB24( 30, &width, &height, tempPalette );
		if( data )
		{
            wt_snprintf( fname, sizeof( fname ), "%s%c%.3d.tga", DIR_PICS, PATH_SEP, 30 );
			
			RGB24_adjustBrightness( data, width * height * 3 );
			
			TGA_write( fname, 24, width, height, data, 0, 1 );
			
			MM_FREE( data );
		}

	}
	GFXFile_Shutdown();

	

	PageFile_ReduxDecodePageData( "VSWAP.BS6", DIR_WALLS, DIR_SPRITES, DIR_DSOUND, blakestone_gamepal );

/*
	if( AudioFile_Setup( "AUDIOHED.BS6", "AUDIOT.BS6" ) )
	{
		AudioFile_ReduxDecodeSound( 0, 200, DIR_SOUNDFX );

		AudioFile_ReduxDecodeMusic( 200, 210, DIR_MUSIC, NULL );
	}
	AudioFile_Shutdown();
*/	
}
Ejemplo n.º 4
0
/**
 * \brief Converts Wolf3D graphic data.
 * \param[in] dict Name of dictionary file to load.
 * \param[in] head Name of header file to load. 
 * \param[in] graph Name of graphics file to load. 
 * \param[in] start Offset to start of sprite data
 * \param[in] end Offset to end of sprite data
 * \param[in] picNum Pointer to picNum_t structure to 
 * \param[in] GetReduxGFXFileName Call back function to get file names for graphics data.
 * \return On success true, otherwise false.
 */
PRIVATE wtBoolean wolf3d_gfx( char *dict, char *head, char *graph, W32 start, W32 end, picNum_t *picNum,
							 char *(*GetReduxGFXFileName)( W32 ) )
{
	wtBoolean bRetVal;
	W32 width, height;
	void *data;
	W32 i;
	char tempFileName[ 1024 ];


    printf( "\nDecoding GFX..." );
	
		
	bRetVal = GFXFile_Setup( dict, head, graph );
    if( ! bRetVal )
	{		
        printf( "Failed\n" );
        return false;
    }

	for( i = 1; i < start; ++i )
	{			
		GFXFile_decodeFont( i, 256, 128, DIR_PICS );
	}

    // Create directory for help scripts   "gscripts/wolfhelp%.3d.txt"
	GFXFile_decodeScript( picNum->PN_HelpScript, picNum->PN_HelpScript+1, DIR_GSCRIPTS );
	GFXFile_decodeScript( picNum->PN_ScriptStart, picNum->PN_ScriptEnd, DIR_GSCRIPTS );


	for( i = start ; i < end ; ++i )
	{
		GFXFile_cacheChunk( i );
        data = GFXFile_decodeChunk_RGB32( i, &width, &height, wolf_gamepal );
		if( NULL == data )
		{
            continue;
        }

        if( _doRedux )
        {
        	W32 id;
        	void *updata;
        	
        	id = 0;
            updata = wolfcore_ReduxGFX( i, data, &width, &height, &id, wolf_gamepal, picNum );
            if( updata == NULL )
            {
            	MM_FREE( data );
            	
            	continue;
            }
            
            wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%s.tga", DIR_PICS, PATH_SEP, GetReduxGFXFileName( i ) );
			
            RGB32toRGB24( updata, updata, width * height * 4 );
			TGA_write( tempFileName, 24, width, height, updata, 0, 1 );
		
			 // updata and data could point to the same memory block.
            if( updata == data)
            {
	            MM_FREE( data );
            }
            else
            {
                MM_FREE( data );
                MM_FREE( updata );
            }
			
			i += id;                        
        }
		else
		{		
            wt_snprintf( tempFileName, sizeof( tempFileName ), "%s%c%.3d.tga", DIR_PICS, PATH_SEP, i );
			
            RGB32toRGB24( data, data, width * height * 4 ); 
			TGA_write( tempFileName, 24, width, height, data, 0, 1 );
		
			MM_FREE( data );
		}
				
	}

	GFXFile_Shutdown();

    printf( "Done\n" );
	
	return bRetVal;
}