示例#1
0
static void RageFile_png_flush( png_struct *pPng )
{
	RageFile *pFile = (RageFile *) png_get_io_ptr(pPng);

	int iGot = pFile->Flush();
	if( iGot == -1 )
		SafePngError( pPng, pFile->GetError() );
}
bool RageSurfaceUtils::SaveBMP( RageSurface *surface, RageFile &f )
{
	/* Convert the surface to 24bpp. */
	RageSurface *converted_surface;
	converted_surface = CreateSurface( surface->w, surface->h, 24,
		Swap24LE( 0xFF0000 ), Swap24LE( 0x00FF00 ), Swap24LE( 0x0000FF ), 0 );
	RageSurfaceUtils::CopySurface( surface, converted_surface );

	RString sError;

	int iFilePitch = converted_surface->pitch;
	iFilePitch = (iFilePitch+3) & ~3; // round up a multiple of 4

	int iDataSize = converted_surface->h * iFilePitch;
	const int iHeaderSize = 0x36;

	WriteBytes( f, sError, "BM", 2 );
	write_le32( f, sError, iHeaderSize+iDataSize ); // size (offset 0x2)
	write_le32( f, sError, 0 ); // reserved (offset 0x6)
	write_le32( f, sError, iHeaderSize ); // bitmap offset (offset 0xA)
	write_le32( f, sError, 0x28 ); // header size (offset 0xE)
	write_le32( f, sError, surface->w ); // width (offset 0x14)
	write_le32( f, sError, surface->h ); // height (offset 0x18)
	write_le16( f, sError, 1 ); // planes (offset 0x1A)
	write_le16( f, sError, (uint16_t) converted_surface->fmt.BytesPerPixel*8 ); // bpp (offset 0x1C)
	write_le32( f, sError, 0 ); // compression (offset 0x1E)
	write_le32( f, sError, iDataSize ); // bitmap size (offset 0x22)
	write_le32( f, sError, 0 ); // horiz resolution (offset 0x26)
	write_le32( f, sError, 0 ); // vert resolution (offset 0x2A)
	write_le32( f, sError, 0 ); // colors (offset 0x2E)
	write_le32( f, sError, 0 ); // important colors (offset 0x32)

	for( int y = converted_surface->h-1; y >= 0; --y )
	{
		const uint8_t *pRow = converted_surface->pixels + converted_surface->pitch*y;
		WriteBytes( f, sError, pRow, converted_surface->pitch );

		/* Pad the row to the pitch. */
		uint8_t padding[4] = { 0,0,0,0 };
		WriteBytes( f, sError, padding, iFilePitch-converted_surface->pitch );
	}

	delete converted_surface;

	if( sError.size() != 0 )
		return false;

	if( f.Flush() == -1 )
		return false;

	return true;
}
示例#3
0
bool IniFile::WriteFile( const RString &sPath ) const
{
	RageFile f;
	if( !f.Open( sPath, RageFile::WRITE ) )
	{
		LOG->Warn( "Writing '%s' failed: %s", sPath.c_str(), f.GetError().c_str() );
		m_sError = f.GetError();
		return false;
	}

	bool bSuccess = IniFile::WriteFile( f );
	int iFlush = f.Flush();
	bSuccess &= (iFlush != -1);
	return bSuccess;
}
示例#4
0
bool XNode::SaveToFile( CString sFile, DISP_OPT *opt )
{
	RageFile f;
	if( !f.Open(sFile, RageFile::WRITE) )
	{
		LOG->Warn("Couldn't open %s for writing: %s", sFile.c_str(), f.GetError().c_str() );
		return false;
	}
	f.PutLine( "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" );
	if( !opt->stylesheet.empty() )
		f.PutLine( "<?xml-stylesheet type=\"text/xsl\" href=\"" + opt->stylesheet + "\"?>" );
	if( !this->GetXML(f, opt) )
		return false;
	if( f.Flush() == -1 )
		return false;
	return true;
}
示例#5
0
static bool WriteFile( RString sFile, RString sBuf )
{
	RageFile output;
	if( !output.Open(sFile, RageFile::WRITE) )
	{
		LOG->Warn( "WriteFile: opening %s failed: %s", sFile.c_str(), output.GetError().c_str() );
		return false;
	}
	
	if( output.Write(sBuf) == -1 || output.Flush() == -1 )
	{
		LOG->Warn( "WriteFile: writing %s failed: %s", sFile.c_str(), output.GetError().c_str() );
		output.Close();
		FILEMAN->Remove( sFile );
		return false;
	}

	return true;
}