コード例 #1
0
RageSurfaceUtils::OpenResult RageSurface_Load_JPEG( const RString &sPath, RageSurface *&ret, bool bHeaderOnly, RString &error )
{
    RageFile f;
    if( !f.Open( sPath ) )
    {
        error = f.GetError();
        return RageSurfaceUtils::OPEN_FATAL_ERROR;
    }

    char errorbuf[1024];
    ret = RageSurface_Load_JPEG( &f, sPath, errorbuf );
    if( ret == NULL )
    {
        error = errorbuf;
        return RageSurfaceUtils::OPEN_UNKNOWN_FILE_FORMAT; // XXX
    }

    return RageSurfaceUtils::OPEN_OK;
}
コード例 #2
0
static RageSurface *TryOpenFile( RString sPath, bool bHeaderOnly, RString &error, RString format, bool &bKeepTrying )
{
	RageSurface *ret = NULL;
	RageSurfaceUtils::OpenResult result;
	if( !format.CompareNoCase("png") )
		result = RageSurface_Load_PNG( sPath, ret, bHeaderOnly, error );
	else if( !format.CompareNoCase("gif") )
		result = RageSurface_Load_GIF( sPath, ret, bHeaderOnly, error );
	else if( !format.CompareNoCase("jpg") || !format.CompareNoCase("jpeg") )
		result = RageSurface_Load_JPEG( sPath, ret, bHeaderOnly, error );
	else if( !format.CompareNoCase("bmp") )
		result = RageSurface_Load_BMP( sPath, ret, bHeaderOnly, error );
	else
	{
		error = "Unsupported format";
		bKeepTrying = true;
		return NULL;
	}

	if( result == RageSurfaceUtils::OPEN_OK )
	{
		ASSERT( ret != NULL );
		return ret;
	}

	LOG->Trace( "Format %s failed: %s", format.c_str(), error.c_str() );

	/*
	 * The file failed to open, or failed to read.  This indicates a problem that will
	 * affect all readers, so don't waste time trying more readers. (OPEN_IO_ERROR)
	 *
	 * Errors fall in two categories:
	 * OPEN_UNKNOWN_FILE_FORMAT: Data was successfully read from the file, but it's the
	 * wrong file format.  The error message always looks like "unknown file format" or
	 * "Not Vorbis data"; ignore it so we always give a consistent error message, and
	 * continue trying other file formats.
	 * 
	 * OPEN_FATAL_ERROR: Either the file was opened successfully and appears to be the
	 * correct format, but a fatal format-specific error was encountered that will probably
	 * not be fixed by using a different reader (for example, an Ogg file that doesn't
	 * actually contain any audio streams); or the file failed to open or read ("I/O
	 * error", "permission denied"), in which case all other readers will probably fail,
	 * too.  The returned error is used, and no other formats will be tried.
	 */
	bKeepTrying = (result != RageSurfaceUtils::OPEN_FATAL_ERROR);
	switch( result )
	{
		case RageSurfaceUtils::OPEN_UNKNOWN_FILE_FORMAT:
			bKeepTrying = true;
			error = "Unknown file format";
			break;

		case RageSurfaceUtils::OPEN_FATAL_ERROR:
			/* The file matched, but failed to load.  We know it's this type of data;
			 * don't bother trying the other file types. */
			bKeepTrying = false;
			break;
		default: break;
	}

	return NULL;
}