/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "image-loader.h"
#include <dali/devel-api/common/ref-counted-dali-vector.h>
-#include <dali/integration-api/bitmap.h>
-#include <dali/integration-api/debug.h>
+#include <adaptors/common/pixel-buffer-impl.h>
+
#include "loader-astc.h"
#include "loader-bmp.h"
#include "loader-png.h"
#include "loader-wbmp.h"
#include "image-operations.h"
-#include "image-loader-input.h"
-#include "portable/file-closer.h"
+#include "portable/file-reader.h"
using namespace Dali::Integration;
namespace
{
-typedef bool (*LoadBitmapFunction)( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+typedef bool (*LoadBitmapFunction)( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& pixelData );
typedef bool (*LoadBitmapHeaderFunction)( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
#if defined(DEBUG_ENABLED)
namespace ImageLoader
{
-bool ConvertStreamToBitmap( const ResourceType& resourceType, std::string path, FILE * const fp, const ResourceLoadingClient& client, BitmapPtr& ptr )
+bool ConvertStreamToBitmap( const BitmapResourceType& resource, std::string path, FILE * const fp, Dali::Devel::PixelBuffer& pixelBuffer )
{
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,
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
+ const ScalingParameters scalingParameters( resource.size, resource.scalingMode, resource.samplingMode );
+ const ImageLoader::Input input( fp, scalingParameters, resource.orientationCorrection );
// Run the image type decoder:
- result = function( client, input, *bitmap );
+ result = function( input, pixelBuffer );
if (!result)
{
DALI_LOG_WARNING( "Unable to convert %s\n", path.c_str() );
- bitmap = 0;
+ pixelBuffer.Reset();
}
- // 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 );
+ pixelBuffer = Internal::Platform::ApplyAttributesToBitmap( pixelBuffer, resource.size, resource.scalingMode, resource.samplingMode );
}
else
{
}
}
- ptr.Reset( bitmap.Get() );
return result;
}
-ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
+ResourcePointer LoadImageSynchronously( const Integration::BitmapResourceType& resource, const std::string& path )
{
- ResourcePointer resource;
- BitmapPtr bitmap = 0;
+ ResourcePointer result;
+ Dali::Devel::PixelBuffer bitmap;
- Internal::Platform::FileCloser fc( resourcePath.c_str(), "rb");
- FILE * const fp = fc.GetFile();
+ Internal::Platform::FileReader fileReader( path );
+ FILE * const fp = fileReader.GetFile();
if( fp != NULL )
{
- bool result = ConvertStreamToBitmap( resourceType, resourcePath, fp, StubbedResourceLoadingClient(), bitmap );
- if( result && bitmap )
+ bool success = ConvertStreamToBitmap(resource, path, fp, bitmap);
+ if (success && bitmap)
{
- resource.Reset(bitmap.Get());
+ Bitmap::Profile profile{Bitmap::Profile::BITMAP_2D_PACKED_PIXELS};
+
+ // For backward compatibility the Bitmap must be created
+ auto retval = Bitmap::New(profile, Dali::ResourcePolicy::OWNED_DISCARD);
+
+ DALI_LOG_SET_OBJECT_STRING( retval, path );
+
+ retval->GetPackedPixelsProfile()->ReserveBuffer(
+ bitmap.GetPixelFormat(),
+ bitmap.GetWidth(),
+ bitmap.GetHeight(),
+ bitmap.GetWidth(),
+ bitmap.GetHeight()
+ );
+
+ auto& impl = Dali::GetImplementation(bitmap);
+
+ std::copy( impl.GetBuffer(), impl.GetBuffer()+impl.GetBufferSize(), retval->GetBuffer());
+ result.Reset(retval);
}
}
- return resource;
+ return result;
}
///@ToDo: Rename GetClosestImageSize() functions. Make them use the orientation correction and scaling information. Requires jpeg loader to tell us about reorientation. [Is there still a requirement for this functionality at all?]
unsigned int width = 0;
unsigned int height = 0;
- Internal::Platform::FileCloser fc(filename.c_str(), "rb");
- FILE *fp = fc.GetFile();
+ Internal::Platform::FileReader fileReader( filename );
+ FILE *fp = fileReader.GetFile();
if (fp != NULL)
{
LoadBitmapFunction loaderFunction;
return ImageDimensions( width, height );
}
-
-
ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
ImageDimensions size,
FittingMode::Type fittingMode,
if( encodedBlob != 0 )
{
- const size_t blobSize = encodedBlob->GetVector().Size();
- uint8_t * const blobBytes = &(encodedBlob->GetVector()[0]);
- DALI_ASSERT_DEBUG( blobSize > 0U );
- DALI_ASSERT_DEBUG( blobBytes != 0U );
-
- if( blobBytes != 0 && blobSize > 0U )
+ if( encodedBlob->GetVector().Size() )
{
// Open a file handle on the memory buffer:
- Internal::Platform::FileCloser fc( blobBytes, blobSize, "rb" );
- FILE *fp = fc.GetFile();
+ Internal::Platform::FileReader fileReader( encodedBlob->GetVector() );
+ FILE *fp = fileReader.GetFile();
if ( fp != NULL )
{
LoadBitmapFunction loaderFunction;