bool ConvertStreamToBitmap( const ResourceType& resourceType, std::string path, FILE * const fp, const ResourceLoadingClient& client, BitmapPtr& ptr )
{
  DALI_LOG_TRACE_METHOD( gLogFilter );
  DALI_ASSERT_DEBUG( ResourceBitmap == resourceType.id );

  bool result = false;
  BitmapPtr bitmap = 0;

  if (fp != NULL)
  {
    LoadBitmapFunction function;
    LoadBitmapHeaderFunction header;
    Bitmap::Profile profile;

    if ( GetBitmapLoaderFunctions( fp,
                                   GetFormatHint( path ),
                                   function,
                                   header,
                                   profile ) )
    {
      bitmap = Bitmap::New( profile, ResourcePolicy::OWNED_DISCARD );

      DALI_LOG_SET_OBJECT_STRING( bitmap, path );
      const BitmapResourceType& resType = static_cast<const BitmapResourceType&>( resourceType );
      const ScalingParameters scalingParameters( resType.size, resType.scalingMode, resType.samplingMode );
      const ImageLoader::Input input( fp, scalingParameters, resType.orientationCorrection );

      // Check for cancellation now we have hit the filesystem, done some allocation, and burned some cycles:
      // This won't do anything from synchronous API, it's only useful when called from another thread.
      client.InterruptionPoint(); // Note: By design, this can throw an exception

      // Run the image type decoder:
      result = function( client, input, *bitmap );

      if (!result)
      {
        DALI_LOG_WARNING( "Unable to convert %s\n", path.c_str() );
        bitmap = 0;
      }

      // Apply the requested image attributes if not interrupted:
      client.InterruptionPoint(); // Note: By design, this can throw an exception
      bitmap = Internal::Platform::ApplyAttributesToBitmap( bitmap, resType.size, resType.scalingMode, resType.samplingMode );
    }
    else
    {
      DALI_LOG_WARNING( "Image Decoder for %s unavailable\n", path.c_str() );
    }
  }

  ptr.Reset( bitmap.Get() );
  return result;
}
ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
{
  ResourcePointer resource;
  BitmapPtr bitmap = 0;

  Internal::Platform::FileCloser fc( resourcePath.c_str(), "rb");
  FILE * const fp = fc.GetFile();
  if( fp != NULL )
  {
    bool result = ConvertStreamToBitmap( resourceType, resourcePath, fp, StubbedResourceLoadingClient(), bitmap );
    if( result && bitmap )
    {
      resource.Reset(bitmap.Get());
    }
  }
  return resource;
}