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;
}
Exemple #2
0
BitmapTexture::BitmapTexture(Integration::Bitmap* const bitmap, const Integration::Bitmap::PackedPixelsProfile * const bitmapPackedPixelsProfile, Context& context)
: Texture(context,
          bitmapPackedPixelsProfile->GetBufferWidth(),
          bitmapPackedPixelsProfile->GetBufferHeight(),
          bitmap->GetImageWidth(),
          bitmap->GetImageHeight(),
          bitmap->GetPixelFormat()),
  mBitmap(bitmap),
  mClearPixels(false)
{
  DALI_LOG_TRACE_METHOD(Debug::Filter::gImage);
  DALI_LOG_SET_OBJECT_STRING(this, DALI_LOG_GET_OBJECT_STRING(bitmap));
}