void BitmapLoader::Initialize(const std::string& filename)
{
- ImageAttributes attributes;
- Integration::BitmapResourceType bitmapResourceType( attributes );
+ // Load with default scaling and orientation correction:
+ Integration::BitmapResourceType bitmapResourceType;
Integration::ResourcePointer resource = TizenPlatform::ImageLoader::LoadResourceSynchronously( bitmapResourceType, filename );
mBitmap = static_cast<Integration::Bitmap*>(resource.Get());
// Check the header file.
unsigned int width(0), height(0);
- Dali::ImageAttributes attributes;
- DALI_TEST_CHECK( functions.header( fp, attributes, width, height ) );
+ const Dali::TizenPlatform::ImageLoader::Input input( fp );
+ DALI_TEST_CHECK( functions.header( input, width, height ) );
DALI_TEST_EQUALS( width, image.reportedWidth, TEST_LOCATION );
DALI_TEST_EQUALS( height, image.reportedHeight, TEST_LOCATION );
// Load Bitmap and check its return values.
- DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes, StubImageLoaderClient() ) );
- DALI_TEST_EQUALS( image.width, attributes.GetWidth(), TEST_LOCATION );
- DALI_TEST_EQUALS( image.height, attributes.GetHeight(), TEST_LOCATION );
+ DALI_TEST_CHECK( functions.loader( StubImageLoaderClient(), input, *bitmap ) );
+ DALI_TEST_EQUALS( image.width, bitmap->GetImageWidth(), TEST_LOCATION );
+ DALI_TEST_EQUALS( image.height, bitmap->GetImageHeight(), TEST_LOCATION );
// Compare buffer generated with reference buffer.
Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() );
Dali::Integration::Bitmap* bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
Dali::Integration::BitmapPtr bitmapPtr( bitmap );
- Dali::ImageAttributes attributes;
+ const Dali::TizenPlatform::ImageLoader::Input input( fp );
- DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes, StubImageLoaderClient() ) );
+ DALI_TEST_CHECK( functions.loader( StubImageLoaderClient(), input, *bitmap ) );
Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() );
FILE* writeFp = fopen( targetFilename.c_str(), "wb" );
AutoCloseFile autoCloseWrite( writeFp );
- fwrite( bufferPtr, sizeof( Dali::PixelBuffer ), attributes.GetWidth() * attributes.GetHeight(), writeFp );
+ fwrite( bufferPtr, 1, bitmap->GetBufferSize(), writeFp );
}
#include <dali/dali.h>
#include <dali/integration-api/bitmap.h>
#include "platform-abstractions/tizen/resource-loader/resource-loading-client.h"
+#include "platform-abstractions/tizen/image-loaders/image-loader-input.h"
// Simple structure to close the file when finished with it.
struct AutoCloseFile
*/
struct LoadFunctions
{
- typedef bool (*LoadBitmapFunction)(FILE*, Dali::Integration::Bitmap&, Dali::ImageAttributes&, const Dali::TizenPlatform::ResourceLoadingClient& client);
- typedef bool (*LoadBitmapHeaderFunction)(FILE*, const Dali::ImageAttributes& attrs, unsigned int& width, unsigned int& height );
+ typedef bool (*LoadBitmapFunction)( const Dali::TizenPlatform::ResourceLoadingClient& client, const Dali::TizenPlatform::ImageLoader::Input& input, Dali::Integration::Bitmap& );
+ typedef bool (*LoadBitmapHeaderFunction)( const Dali::TizenPlatform::ImageLoader::Input& input, unsigned int& width, unsigned int& height );
LoadFunctions( LoadBitmapHeaderFunction _header, LoadBitmapFunction _loader );
LoadBitmapHeaderFunction header;
uint32_t expectedDimension,
const char * const location )
{
- ImageAttributes attributes;
- attributes.SetScalingMode( ImageAttributes::ShrinkToFit );
- attributes.SetFilterMode( ImageAttributes::Box );
- attributes.SetSize( targetDimension, targetDimension );
+ ImageDimensions desired( targetDimension, targetDimension );
+ FittingMode::Type fittingMode( FittingMode::SHRINK_TO_FIT );
+ SamplingMode::Type samplingMode( SamplingMode::BOX );
Integration::BitmapPtr sourceBitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::DISCARD );
sourceBitmap->GetPackedPixelsProfile()->ReserveBuffer( format, sourceDimension, sourceDimension, sourceDimension, sourceDimension );
- Integration::BitmapPtr downScaled = DownscaleBitmap( *sourceBitmap, ImageDimensions( targetDimension, targetDimension ), attributes.GetScalingMode(), attributes.GetFilterMode() );
+ Integration::BitmapPtr downScaled = DownscaleBitmap( *sourceBitmap, desired, fittingMode, samplingMode );
+
DALI_TEST_EQUALS( downScaled->GetImageWidth(), expectedDimension, location );
DALI_TEST_EQUALS( downScaled->GetImageHeight(), expectedDimension, location );
DALI_TEST_EQUALS( downScaled->GetPixelFormat(), format, location );
/**
* @brief Test the small int (x,y) tuple.
*/
-int UtcDaliImageOperationsVector2Uint16(void)
+int UtcDaliImageOperationsUint16Pair(void)
{
- Vector2Uint16 vec1( 2, 3 );
+ Uint16Pair vec1( 2, 3 );
DALI_TEST_EQUALS( vec1.GetWidth(), 2, TEST_LOCATION );
DALI_TEST_EQUALS( vec1.GetX(), 2, TEST_LOCATION );
DALI_TEST_EQUALS( vec1.GetHeight(), 3, TEST_LOCATION );
DALI_TEST_EQUALS( vec1.GetY(), 3, TEST_LOCATION );
- Vector2Uint16 vec1Copy = vec1;
+ Uint16Pair vec1Copy = vec1;
DALI_TEST_EQUALS( vec1Copy.GetWidth(), 2, TEST_LOCATION );
DALI_TEST_EQUALS( vec1Copy.GetX(), 2, TEST_LOCATION );
DALI_TEST_EQUALS( vec1Copy.GetHeight(), 3, TEST_LOCATION );
DALI_TEST_EQUALS( vec1Copy.GetY(), 3, TEST_LOCATION );
- Vector2Uint16 vec2( 65535u, 65535u );
+ Uint16Pair vec2( 65535u, 65535u );
DALI_TEST_EQUALS( vec2.GetX(), 65535u, TEST_LOCATION );
DALI_TEST_EQUALS( vec2.GetY(), 65535u, TEST_LOCATION );
mTrace.PushCall("Resume", "");
}
-void TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2& closestSize)
+ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection )
{
- closestSize = mClosestSize;
+ ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
mTrace.PushCall("GetClosestImageSize", "");
+ return closestSize;
}
-void TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2& closestSize)
+ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection )
{
- closestSize = mClosestSize;
+ ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
mTrace.PushCall("GetClosestImageSize", "");
+ return closestSize;
}
-
/**
* @copydoc PlatformAbstraction::LoadResource()
*/
// EXTERNAL INCLUDES
#include <stdint.h>
#include <cstring>
+#include <dali/public-api/images/image-operations.h>
// INTERNAL INCLUDES
#include <dali/public-api/common/set-wrapper.h>
*/
virtual void Resume();
- virtual void GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2& closestSize);
-
- virtual void GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2& closestSize);
+ /**
+ * @copydoc PlatformAbstraction::GetClosestImageSize()
+ */
+ virtual ImageDimensions GetClosestImageSize( const std::string& filename,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection );
+ /**
+ * @copydoc PlatformAbstraction::GetClosestImageSize()
+ */
+ virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection );
/**
* @copydoc PlatformAbstraction::LoadResource()
*/
// Issue load requests for a batch of images:
for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
{
- const BitmapResourceType bitmapResourceType( gCancelAttributes[ loadsLaunched % gCancelAttributes.size() ] );
+ const ImageAttributes & loadParams = gCancelAttributes[ loadsLaunched % gCancelAttributes.size() ];
+ const BitmapResourceType bitmapResourceType( loadParams.first, loadParams.second.first, loadParams.second.second.first, loadParams.second.second.second );
const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
gAbstraction->LoadResource( ResourceRequest( resourceId, bitmapResourceType, VALID_IMAGES[validImage], priority ) );
loadsLaunched += 1;
// Issue load requests for a batch of images:
for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
{
- const BitmapResourceType bitmapResourceType( gCancelAttributes[ loadsLaunched % gCancelAttributes.size() ] );
+ const ImageAttributes & loadParams = gCancelAttributes[ loadsLaunched % gCancelAttributes.size() ];
+ const BitmapResourceType bitmapResourceType( loadParams.first, loadParams.second.first, loadParams.second.second.first, loadParams.second.second.second );
const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
gAbstraction->LoadResource( ResourceRequest( resourceId, bitmapResourceType, VALID_IMAGES[validImage], priority ) );
loadsLaunched += 1;
// Setup some ImageAttributes to engage post-processing stages:
ImageAttributes scaleToFillAttributes;
- scaleToFillAttributes.SetScalingMode( ImageAttributes::ScaleToFill );
- scaleToFillAttributes.SetSize( 160, 120 );
+ scaleToFillAttributes.second.first = FittingMode::SCALE_TO_FILL;
+ scaleToFillAttributes.first = ImageDimensions( 160, 120 );
gCancelAttributes.push_back( scaleToFillAttributes );
// Hit the derived dimensions code:
ImageAttributes scaleToFillAttributesDeriveWidth = scaleToFillAttributes;
- scaleToFillAttributesDeriveWidth.SetSize( 0, 120 );
+ scaleToFillAttributesDeriveWidth.first = ImageDimensions( 0, 120 );
gCancelAttributes.push_back( scaleToFillAttributesDeriveWidth );
ImageAttributes scaleToFillAttributesDeriveHeight = scaleToFillAttributes;
- scaleToFillAttributesDeriveHeight.SetSize( 160, 0 );
+ scaleToFillAttributesDeriveHeight.first = ImageDimensions( 160, 0 );
gCancelAttributes.push_back( scaleToFillAttributesDeriveHeight );
// Try to push a tall crop:
ImageAttributes scaleToFillAttributesTall = scaleToFillAttributes;
- scaleToFillAttributesTall.SetSize( 160, 480 );
+ scaleToFillAttributesTall.first = ImageDimensions( 160, 480 );
ImageAttributes scaleToFillAttributesTall2 = scaleToFillAttributes;
- scaleToFillAttributesTall2.SetSize( 160, 509 );
+ scaleToFillAttributesTall2.first = ImageDimensions( 160, 509 );
ImageAttributes scaleToFillAttributesTall3 = scaleToFillAttributes;
- scaleToFillAttributesTall3.SetSize( 37, 251 );
+ scaleToFillAttributesTall3.first = ImageDimensions( 37, 251 );
gCancelAttributes.push_back( scaleToFillAttributesTall );
gCancelAttributes.push_back( scaleToFillAttributesTall2 );
gCancelAttributes.push_back( scaleToFillAttributesTall3 );
// Try to push a wide crop:
ImageAttributes scaleToFillAttributesWide = scaleToFillAttributes;
- scaleToFillAttributesWide.SetSize( 320, 60 );
+ scaleToFillAttributesWide.first = ImageDimensions( 320, 60 );
ImageAttributes scaleToFillAttributesWide2 = scaleToFillAttributes;
- scaleToFillAttributesWide2.SetSize( 317, 60 );
+ scaleToFillAttributesWide2.first = ImageDimensions( 317, 60 );
ImageAttributes scaleToFillAttributesWide3 = scaleToFillAttributes;
- scaleToFillAttributesWide3.SetSize( 317, 53 );
+ scaleToFillAttributesWide3.first = ImageDimensions( 317, 53 );
gCancelAttributes.push_back( scaleToFillAttributesWide );
gCancelAttributes.push_back( scaleToFillAttributesWide2 );
gCancelAttributes.push_back( scaleToFillAttributesWide3 );
ImageAttributes shrinkToFitAttributes = scaleToFillAttributes;
- shrinkToFitAttributes.SetScalingMode( ImageAttributes::ShrinkToFit );
+ shrinkToFitAttributes.second.first = FittingMode::SHRINK_TO_FIT;
gCancelAttributes.push_back( shrinkToFitAttributes );
ImageAttributes fitWidthAttributes = scaleToFillAttributes;
- fitWidthAttributes.SetScalingMode( ImageAttributes::FitWidth );
+ fitWidthAttributes.second.first = FittingMode::FIT_WIDTH;
gCancelAttributes.push_back( fitWidthAttributes );
ImageAttributes fitHeightAttributes = scaleToFillAttributes;
- fitHeightAttributes.SetScalingMode( ImageAttributes::FitHeight );
+ fitHeightAttributes.second.first = FittingMode::FIT_HEIGHT;
gCancelAttributes.push_back( fitHeightAttributes );
///@ToDo: Add attribute variants for all scale modes.
+ ///@ToDo: Add attribute variants for all filter modes.
// Pad the array to a prime number to mitigate any accidental periodic
// patterns in which image file has which attributes applied to its load:
extern Integration::PlatformAbstraction * gAbstraction;
/** A variety of ImageAttributes to reach different code paths that have embedded code paths. */
+typedef std::pair<ImageDimensions, std::pair<FittingMode::Type, std::pair<SamplingMode::Type, bool> > > ImageAttributes;
extern std::vector<ImageAttributes> gCancelAttributes;
// Start a bunch of loads that should work:
- const Dali::ImageAttributes attributes;
- const Dali::Integration::BitmapResourceType bitmapResourceType( attributes );
+ Dali::Integration::BitmapResourceType bitmapResourceType;
Dali::Integration::LoadResourcePriority priority = Dali::Integration::LoadPriorityNormal;
unsigned loadsLaunched = 0;
{
for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
{
- gAbstraction->LoadResource( ResourceRequest( loadGroup * NUM_VALID_IMAGES + validImage + 1, bitmapResourceType, VALID_IMAGES[validImage], priority ) );
+ Dali::Integration::ResourceRequest request( loadGroup * NUM_VALID_IMAGES + validImage + 1, bitmapResourceType, VALID_IMAGES[validImage], priority );
+ gAbstraction->LoadResource( request );
}
loadsLaunched += NUM_VALID_IMAGES;
}
// Drain the completed loads:
Dali::Internal::Platform::ResourceCollector resourceSink;
- usleep( 1000 * 1000 );
gAbstraction->GetResources( resourceSink );
usleep( 500 * 1000 );
gAbstraction->GetResources( resourceSink );
// EXTERNAL INCLUDES
#include <cstring>
#include <stddef.h>
+#include <cmath>
#include <dali/integration-api/debug.h>
+#include <dali/public-api/math/vector2.h>
// INTERNAL INCLUDES
/**
* @brief Converts a scaling mode to the definition of which dimensions matter when box filtering as a part of that mode.
*/
-BoxDimensionTest DimensionTestForScalingMode( ImageAttributes::ScalingMode scalingMode )
+BoxDimensionTest DimensionTestForScalingMode( FittingMode::Type fittingMode )
{
BoxDimensionTest dimensionTest;
dimensionTest = BoxDimensionTestEither;
- switch( scalingMode )
+ switch( fittingMode )
{
// Shrink to fit attempts to make one or zero dimensions smaller than the
// desired dimensions and one or two dimensions exactly the same as the desired
// ones, so as long as one dimension is larger than the desired size, box
// filtering can continue even if the second dimension is smaller than the
// desired dimensions:
- case ImageAttributes::ShrinkToFit:
+ case FittingMode::SHRINK_TO_FIT:
{
dimensionTest = BoxDimensionTestEither;
break;
}
// Scale to fill mode keeps both dimensions at least as large as desired:
- case ImageAttributes::ScaleToFill:
+ case FittingMode::SCALE_TO_FILL:
{
dimensionTest = BoxDimensionTestBoth;
break;
}
- // Y dimension is irrelevant when downscaling in FitWidth mode:
- case ImageAttributes::FitWidth:
+ // Y dimension is irrelevant when downscaling in FIT_WIDTH mode:
+ case FittingMode::FIT_WIDTH:
{
dimensionTest = BoxDimensionTestX;
break;
}
- // X Dimension is ignored by definition in FitHeight mode:
- case ImageAttributes::FitHeight:
+ // X Dimension is ignored by definition in FIT_HEIGHT mode:
+ case FittingMode::FIT_HEIGHT:
{
dimensionTest = BoxDimensionTestY;
break;
/**
* @brief Work out the dimensions for a uniform scaling of the input to map it
- * into the target while effecting ScaleToFill scaling mode.
+ * into the target while effecting SCALE_TO_FILL scaling mode.
* @note The output dimensions will need either top and bottom or left and right
* to be cropped away unless the source was pre-cropped to match the destination
* aspect ratio.
/**
* @brief Work out the dimensions for a uniform scaling of the input to map it
- * into the target while effecting FitWidth scaling mode.
+ * into the target while effecting FIT_WIDTH scaling mode.
*/
ImageDimensions FitForFitWidth( ImageDimensions target, ImageDimensions source )
{
/**
* @brief Work out the dimensions for a uniform scaling of the input to map it
- * into the target while effecting FitHeight scaling mode.
+ * into the target while effecting FIT_HEIGHT scaling mode.
*/
ImageDimensions FitForFitHeight( ImageDimensions target, ImageDimensions source )
{
* @brief Generate the rectangle to use as the target of a pixel sampling pass
* (e.g., nearest or linear).
*/
-ImageDimensions FitToScalingMode( ImageDimensions requestedSize, ImageDimensions sourceSize, ImageAttributes::ScalingMode scalingMode )
+ImageDimensions FitToScalingMode( ImageDimensions requestedSize, ImageDimensions sourceSize, FittingMode::Type fittingMode )
{
ImageDimensions fitDimensions;
- switch( scalingMode )
+ switch( fittingMode )
{
- case ImageAttributes::ShrinkToFit:
+ case FittingMode::SHRINK_TO_FIT:
{
fitDimensions = FitForShrinkToFit( requestedSize, sourceSize );
break;
}
- case ImageAttributes::ScaleToFill:
+ case FittingMode::SCALE_TO_FILL:
{
fitDimensions = FitForScaleToFill( requestedSize, sourceSize );
break;
}
- case ImageAttributes::FitWidth:
+ case FittingMode::FIT_WIDTH:
{
fitDimensions = FitForFitWidth( requestedSize, sourceSize );
break;
}
- case ImageAttributes::FitHeight:
+ case FittingMode::FIT_HEIGHT:
{
fitDimensions = FitForFitHeight( requestedSize, sourceSize );
break;
} // namespace - unnamed
/**
- * @brief Implement ImageAttributes::ScaleTofill scaling mode cropping.
+ * @brief Implement ScaleTofill scaling mode cropping.
*
- * Implement the cropping required for ImageAttributes::ScaleToFill mode,
+ * Implement the cropping required for SCALE_TO_FILL mode,
* returning a new bitmap with the aspect ratio specified by the scaling mode.
* This scaling mode selects the central portion of a source image so any spare
* pixels off one of either the top or bottom edge need to be removed.
*/
Integration::BitmapPtr CropForScaleToFill( Integration::BitmapPtr bitmap, ImageDimensions desiredDimensions );
-BitmapPtr ApplyAttributesToBitmap( BitmapPtr bitmap, const ImageAttributes& requestedAttributes )
+BitmapPtr ApplyAttributesToBitmap( BitmapPtr bitmap, ImageDimensions dimensions, FittingMode::Type fittingMode, SamplingMode::Type samplingMode )
{
- ///@ToDo: Optimisation - If Scaling Mode is ScaletoFill, either do cropping here at the front of the pipe, or equivalently modify all scaling functions to take a source rectangle and have the first one to be applied, pull in a subset of source pixels to crop on the fly. That would make every scaling slightly slower but would save the memcpy()s at the end for ScaleToFill.
-
if( bitmap )
{
// Calculate the desired box, accounting for a possible zero component:
- const ImageDimensions desiredDimensions = CalculateDesiredDimensions( bitmap->GetImageWidth(), bitmap->GetImageHeight(), requestedAttributes.GetWidth(), requestedAttributes.GetHeight() );
+ const ImageDimensions desiredDimensions = CalculateDesiredDimensions( bitmap->GetImageWidth(), bitmap->GetImageHeight(), dimensions.GetWidth(), dimensions.GetHeight() );
// If a different size than the raw one has been requested, resize the image
// maximally using a repeated box filter without making it smaller than the
// requested size in either dimension:
- bitmap = DownscaleBitmap( *bitmap, desiredDimensions, requestedAttributes.GetScalingMode(), requestedAttributes.GetFilterMode() );
+ bitmap = DownscaleBitmap( *bitmap, desiredDimensions, fittingMode, samplingMode );
// Cut the bitmap according to the desired width and height so that the
// resulting bitmap has the same aspect ratio as the desired dimensions:
- if( bitmap && bitmap->GetPackedPixelsProfile() && requestedAttributes.GetScalingMode() == ImageAttributes::ScaleToFill )
+ if( bitmap && bitmap->GetPackedPixelsProfile() && fittingMode == FittingMode::SCALE_TO_FILL )
{
bitmap = CropForScaleToFill( bitmap, desiredDimensions );
}
Integration::BitmapPtr DownscaleBitmap( Integration::Bitmap& bitmap,
ImageDimensions desired,
- ImageAttributes::ScalingMode scalingMode,
- ImageAttributes::FilterMode filterMode )
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode )
{
// Source dimensions as loaded from resources (e.g. filesystem):
const unsigned int bitmapWidth = bitmap.GetImageWidth();
// Do the fast power of 2 iterated box filter to get to roughly the right side if the filter mode requests that:
unsigned int shrunkWidth = -1, shrunkHeight = -1;
- DownscaleInPlacePow2( bitmap.GetBuffer(), pixelFormat, bitmapWidth, bitmapHeight, desiredWidth, desiredHeight, scalingMode, filterMode, shrunkWidth, shrunkHeight );
+ DownscaleInPlacePow2( bitmap.GetBuffer(), pixelFormat, bitmapWidth, bitmapHeight, desiredWidth, desiredHeight, fittingMode, samplingMode, shrunkWidth, shrunkHeight );
// Work out the dimensions of the downscaled bitmap, given the scaling mode and desired dimensions:
- const ImageDimensions filteredDimensions = FitToScalingMode( ImageDimensions( desiredWidth, desiredHeight ), ImageDimensions( shrunkWidth, shrunkHeight ), scalingMode );
+ const ImageDimensions filteredDimensions = FitToScalingMode( ImageDimensions( desiredWidth, desiredHeight ), ImageDimensions( shrunkWidth, shrunkHeight ), fittingMode );
const unsigned int filteredWidth = filteredDimensions.GetWidth();
const unsigned int filteredHeight = filteredDimensions.GetHeight();
bool filtered = false;
if( filteredWidth < shrunkWidth || filteredHeight < shrunkHeight )
{
- if( filterMode == ImageAttributes::Linear || filterMode == ImageAttributes::BoxThenLinear ||
- filterMode == ImageAttributes::Nearest || filterMode == ImageAttributes::BoxThenNearest )
+ if( samplingMode == SamplingMode::LINEAR || samplingMode == SamplingMode::BOX_THEN_LINEAR ||
+ samplingMode == SamplingMode::NEAREST || samplingMode == SamplingMode::BOX_THEN_NEAREST )
{
outputBitmap = MakeEmptyBitmap( pixelFormat, filteredWidth, filteredHeight );
if( outputBitmap )
{
- if( filterMode == ImageAttributes::Linear || filterMode == ImageAttributes::BoxThenLinear )
+ if( samplingMode == SamplingMode::LINEAR || samplingMode == SamplingMode::BOX_THEN_LINEAR )
{
LinearSample( bitmap.GetBuffer(), ImageDimensions(shrunkWidth, shrunkHeight), pixelFormat, outputBitmap->GetBuffer(), filteredDimensions );
}
unsigned int inputHeight,
unsigned int desiredWidth,
unsigned int desiredHeight,
- ImageAttributes::ScalingMode scalingMode,
- ImageAttributes::FilterMode filterMode,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
unsigned& outWidth,
unsigned& outHeight )
{
outWidth = inputWidth;
outHeight = inputHeight;
// Perform power of 2 iterated 4:1 box filtering if the requested filter mode requires it:
- if( filterMode == ImageAttributes::Box || filterMode == ImageAttributes::BoxThenNearest || filterMode == ImageAttributes::BoxThenLinear )
+ if( samplingMode == SamplingMode::BOX || samplingMode == SamplingMode::BOX_THEN_NEAREST || samplingMode == SamplingMode::BOX_THEN_LINEAR )
{
// Check the pixel format is one that is supported:
if( pixelFormat == Pixel::RGBA8888 || pixelFormat == Pixel::RGB888 || pixelFormat == Pixel::RGB565 || pixelFormat == Pixel::LA88 || pixelFormat == Pixel::L8 || pixelFormat == Pixel::A8 )
{
- const BoxDimensionTest dimensionTest = DimensionTestForScalingMode( scalingMode );
+ const BoxDimensionTest dimensionTest = DimensionTestForScalingMode( fittingMode );
if( pixelFormat == Pixel::RGBA8888 )
{
// INTERNAL INCLUDES
#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/image-attributes.h>
+#include <dali/public-api/images/image-operations.h>
namespace Dali
{
BoxDimensionTestY
};
-/**
- * @brief Simple class for passing around pairs of small ints.
- *
- * These are immutable. If you want to change a value, make a whole new object.
- * @note One of these can be passed in a single 32 bit integer register on
- * common architectures.
- */
-class Vector2Uint16
-{
-public:
- /**
- * @brief Default constructor for the (0, 0) vector.
- */
- Vector2Uint16() : mData(0) {}
-
- /**
- * @brief Constructor taking separate x and y (width and height) parameters.
- * @param[in] width The width or X dimension of the vector. Make sure it is less than 65536,
- * @param[in] height The height or Y dimension of the vector. Make sure it is less than 65536,
- */
- Vector2Uint16( uint32_t width, uint32_t height )
- {
- DALI_ASSERT_DEBUG( width < ( 1u << 16 ) && "Width parameter not representable." );
- DALI_ASSERT_DEBUG( height < ( 1u << 16 ) && "Height parameter not representable." );
-
- /* Do equivalent of the code below with one aligned memory access:
- * mComponents[0] = width;
- * mComponents[1] = height;
- * Unit tests make sure this is equivalent.
- **/
- mData = (height << 16u) + width;
- }
-
- /**
- * @brief Copy constructor.
- */
- Vector2Uint16( const Vector2Uint16& rhs )
- {
- mData = rhs.mData;
- }
-
- /**
- * @returns the x dimension stored in this 2-tuple.
- */
- uint16_t GetWidth() const
- {
- return mComponents[0];
- }
-
- /**
- * @returns the y dimension stored in this 2-tuple.
- */
- uint16_t GetHeight() const
- {
- return mComponents[1];
- }
-
- /**
- * @returns the x dimension stored in this 2-tuple.
- */
- uint16_t GetX() const
- {
- return mComponents[0];
- }
-
- /**
- * @returns the y dimension stored in this 2-tuple.
- */
- uint16_t GetY() const
- {
- return mComponents[1];
- }
-
-private:
- union
- {
- // Addressable view of X and Y:
- uint16_t mComponents[2];
- // Packed view of X and Y to force alignment and allow a faster copy:
- uint32_t mData;
- };
-};
-
/**
* @brief The integer dimensions of an image or a region of an image packed into
* 16 bits per component.
* @note This can only be used for images of up to 65535 x 65535 pixels.
*/
-typedef Vector2Uint16 ImageDimensions;
+typedef Uint16Pair ImageDimensions;
/**
* @defgroup BitmapOperations Bitmap-to-Bitmap Image operations.
* bitmap passed-in, or the original bitmap passed in if the attributes
* have no effect.
*/
-Integration::BitmapPtr ApplyAttributesToBitmap( Integration::BitmapPtr bitmap, const ImageAttributes& requestedAttributes );
+Integration::BitmapPtr ApplyAttributesToBitmap( Integration::BitmapPtr bitmap, ImageDimensions dimensions, FittingMode::Type fittingMode = FittingMode::DEFAULT, SamplingMode::Type samplingMode = SamplingMode::DEFAULT );
/**
* @brief Apply downscaling to a bitmap according to requested attributes.
* @note The input bitmap pixel buffer may be modified and used as scratch working space for efficiency, so it must be discarded.
**/
-Integration::BitmapPtr DownscaleBitmap( Integration::Bitmap& bitmap, ImageDimensions desired, ImageAttributes::ScalingMode scalingMode, ImageAttributes::FilterMode filterMode );
+Integration::BitmapPtr DownscaleBitmap( Integration::Bitmap& bitmap, ImageDimensions desired, FittingMode::Type fittingMode, SamplingMode::Type samplingMode );
/**@}*/
/**
unsigned int inputHeight,
unsigned int desiredWidth,
unsigned int desiredHeight,
- ImageAttributes::ScalingMode scalingMode,
- ImageAttributes::FilterMode filterMode,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
unsigned& outWidth,
unsigned& outHeight );
{
DALI_ASSERT_DEBUG( fractBlendHorizontal <= 65535u && "Factor should be in 0.16 fixed-point." );
DALI_ASSERT_DEBUG( fractBlendVertical <= 65535u && "Factor should be in 0.16 fixed-point." );
- //
+
const unsigned int topBlend = WeightedBlendIntToFixed1616( tl, tr, fractBlendHorizontal );
const unsigned int botBlend = WeightedBlendIntToFixed1616( bl, br, fractBlendHorizontal );
const uint64_t blended2x2 = WeightedBlendFixed1616ToFixed1632( topBlend, botBlend, fractBlendVertical );
--- /dev/null
+#ifndef __DALI_TIZEN_PLATFORM_IMAGE_LOADER_INPUT_H__
+#define __DALI_TIZEN_PLATFORM_IMAGE_LOADER_INPUT_H__
+
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// EXTERNAL INCLUDES
+#include <cstdio>
+#include <dali/public-api/images/image-operations.h>
+
+// INTERNAL INCLUDES
+
+namespace Dali
+{
+namespace TizenPlatform
+{
+namespace ImageLoader
+{
+
+
+/**
+ * @brief A simple immutable struct to bundle together parameters for scaling an image.
+ * @ToDo Move this to adaptor internal?
+ * @ToDo Rename it after the move to ImageScalingParameters.
+ */
+class ScalingParameters
+{
+public:
+ ScalingParameters( ImageDimensions dimensions = ImageDimensions(), FittingMode::Type fittingMode = FittingMode::DEFAULT, SamplingMode::Type samplingMode = SamplingMode::DEFAULT ) :
+ dimensions(dimensions), scalingMode(fittingMode), samplingMode(samplingMode) {}
+ const ImageDimensions dimensions;
+ const FittingMode::Type scalingMode;
+ const SamplingMode::Type samplingMode;
+};
+
+ /**
+ * @brief Bundle-up the data pushed into an image loader.
+ */
+struct Input
+{
+ Input( FILE* file, ScalingParameters scalingParameters = ScalingParameters(), bool reorientationRequested = true ) :
+ file(file), scalingParameters(scalingParameters), reorientationRequested(reorientationRequested) {}
+ FILE* file;
+ ScalingParameters scalingParameters;
+ bool reorientationRequested;
+};
+
+} // ImageLoader
+} // TizenPlatform
+} // Dali
+
+#endif // __DALI_TIZEN_PLATFORM_IMAGE_LOADER_INPUT_H__
#include "image-loader.h"
#include <dali/public-api/common/ref-counted-dali-vector.h>
-#include <dali/public-api/images/image-attributes.h>
#include <dali/integration-api/bitmap.h>
#include <dali/integration-api/debug.h>
#include "loader-ktx.h"
#include "loader-wbmp.h"
#include "image-operations.h"
+#include "image-loader-input.h"
+#include "portable/file-closer.h"
using namespace Dali::Integration;
namespace
{
-typedef bool (*LoadBitmapFunction)( FILE*, Bitmap&, ImageAttributes&, const ResourceLoadingClient& );
-typedef bool (*LoadBitmapHeaderFunction)(FILE*, const ImageAttributes& attrs, unsigned int& width, unsigned int& height );
+typedef bool (*LoadBitmapFunction)( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+typedef bool (*LoadBitmapHeaderFunction)( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
#if defined(DEBUG_ENABLED)
-Integration::Log::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_IMAGE_LOADING");
+Integration::Log::Filter* gLogFilter = Debug::Filter::New( Debug::Concise, false, "LOG_IMAGE_LOADING" );
#endif
/**
bool loaderFound = false;
const BitmapLoader *lookupPtr = BITMAP_LOADER_LOOKUP_TABLE;
- ImageAttributes attrs;
+ ImageLoader::Input defaultInput( fp );
// try hinted format first
if ( format != FORMAT_UNKNOWN )
{
unsigned int width = 0;
unsigned int height = 0;
- loaderFound = lookupPtr->header(fp, attrs, width, height );
+ loaderFound = lookupPtr->header( fp, width, height );
}
}
// to seperate ico file format and wbmp file format
unsigned int width = 0;
unsigned int height = 0;
- loaderFound = lookupPtr->header(fp, attrs, width, height);
+ loaderFound = lookupPtr->header(fp, width, height);
}
if (loaderFound)
{
// to seperate ico file format and wbmp file format
unsigned int width = 0;
unsigned int height = 0;
- loaderFound = lookupPtr->header(fp, attrs, width, height);
+ loaderFound = lookupPtr->header(fp, width, height);
if (loaderFound)
{
break;
namespace ImageLoader
{
-bool ConvertStreamToBitmap(const ResourceType& resourceType, std::string path, FILE * const fp, const ResourceLoadingClient& client, BitmapPtr& ptr)
+bool ConvertStreamToBitmap( const ResourceType& resourceType, std::string path, FILE * const fp, const ResourceLoadingClient& client, BitmapPtr& ptr )
{
- DALI_LOG_TRACE_METHOD(gLogFilter);
+ DALI_LOG_TRACE_METHOD( gLogFilter );
DALI_ASSERT_DEBUG( ResourceBitmap == resourceType.id );
bool result = false;
header,
profile ) )
{
- bitmap = Bitmap::New(profile, ResourcePolicy::DISCARD );
+ bitmap = Bitmap::New( profile, ResourcePolicy::DISCARD );
- DALI_LOG_SET_OBJECT_STRING(bitmap, path);
- const BitmapResourceType& resType = static_cast<const BitmapResourceType&>(resourceType);
- const ImageAttributes& requestedAttributes = resType.imageAttributes; //< Original attributes.
- ImageAttributes attributes = resType.imageAttributes; //< r/w copy of the attributes.
+ 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:
- // Note, this can overwrite the attributes parameter.
- result = function( fp, *bitmap, attributes, client );
+ result = function( client, input, *bitmap );
if (!result)
{
bitmap = 0;
}
- // Apply the requested image attributes in best-effort fashion:
+ // Apply the requested image attributes if not interrupted:
client.InterruptionPoint(); // Note: By design, this can throw an exception
- bitmap = Internal::Platform::ApplyAttributesToBitmap( bitmap, requestedAttributes );
+ bitmap = Internal::Platform::ApplyAttributesToBitmap( bitmap, resType.size, resType.scalingMode, resType.samplingMode );
}
else
{
- DALI_LOG_WARNING("Image Decoder for %s unavailable\n", path.c_str());
+ DALI_LOG_WARNING( "Image Decoder for %s unavailable\n", path.c_str() );
}
}
ResourcePointer resource;
BitmapPtr bitmap = 0;
- FILE * const fp = fopen( resourcePath.c_str(), "rb" );
+ Internal::Platform::FileCloser fc( resourcePath.c_str(), "rb");
+ FILE * const fp = fc.GetFile();
if( fp != NULL )
{
bool result = ConvertStreamToBitmap( resourceType, resourcePath, fp, StubbedResourceLoadingClient(), bitmap );
{
resource.Reset(bitmap.Get());
}
- fclose(fp);
}
return resource;
}
-
-void GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2 &closestSize )
+///@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?]
+ImageDimensions GetClosestImageSize( const std::string& filename,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection )
{
- FILE *fp = fopen(filename.c_str(), "rb");
+ unsigned int width = 0;
+ unsigned int height = 0;
+
+ Internal::Platform::FileCloser fc(filename.c_str(), "rb");
+ FILE *fp = fc.GetFile();
if (fp != NULL)
{
LoadBitmapFunction loaderFunction;
headerFunction,
profile ) )
{
- unsigned int width;
- unsigned int height;
+ const ImageLoader::Input input( fp, ScalingParameters( size, fittingMode, samplingMode ), orientationCorrection );
- const bool read_res = headerFunction(fp, attributes, width, height);
+ const bool read_res = headerFunction( input, width, height );
if(!read_res)
{
DALI_LOG_WARNING("Image Decoder failed to read header for %s\n", filename.c_str());
}
-
- closestSize.width = (float)width;
- closestSize.height = (float)height;
}
else
{
DALI_LOG_WARNING("Image Decoder for %s unavailable\n", filename.c_str());
}
- fclose(fp);
}
+ return ImageDimensions( width, height );
}
-void GetClosestImageSize( ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2 &closestSize )
+
+ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection )
{
- BitmapPtr bitmap = 0;
+ unsigned int width = 0;
+ unsigned int height = 0;
// Get the blob of binary data that we need to decode:
DALI_ASSERT_DEBUG( resourceBuffer );
if( blobBytes != 0 && blobSize > 0U )
{
// Open a file handle on the memory buffer:
- FILE * const fp = fmemopen(blobBytes, blobSize, "rb");
+ Internal::Platform::FileCloser fc( blobBytes, blobSize, "rb" );
+ FILE *fp = fc.GetFile();
if ( fp != NULL )
{
LoadBitmapFunction loaderFunction;
headerFunction,
profile ) )
{
- unsigned int width;
- unsigned int height;
- const bool read_res = headerFunction(fp, attributes, width, height);
- if(!read_res)
+ const ImageLoader::Input input( fp, ScalingParameters( size, fittingMode, samplingMode ), orientationCorrection );
+ const bool read_res = headerFunction( input, width, height );
+ if( !read_res )
{
- DALI_LOG_WARNING("Image Decoder failed to read header for resourceBuffer\n");
+ DALI_LOG_WARNING( "Image Decoder failed to read header for resourceBuffer\n" );
}
-
- closestSize.width = (float) width;
- closestSize.height = (float) height;
}
- fclose(fp);
}
}
}
+ return ImageDimensions( width, height );
}
} // ImageLoader
* limitations under the License.
*/
+// EXTERNAL INCLUDES
+#include <dali/public-api/images/image-operations.h>
#include <dali/integration-api/resource-cache.h>
#include <dali/integration-api/resource-types.h>
#include <dali/integration-api/bitmap.h>
+
+// INTERNAL INCLUDES
#include "resource-loading-client.h"
namespace Dali
Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
-void GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2 &closestSize );
+ImageDimensions GetClosestImageSize( const std::string& filename,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection );
-void GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2 &closestSize );
+ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection );
} // ImageLoader
} // TizenPlatform
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/image-attributes.h>
#include <cstdlib>
} // unnamed namespace
-bool LoadBmpHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height)
+bool LoadBmpHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
{
BmpFileHeader fileHeader;
BmpInfoHeader infoHeader;
- bool ret = LoadBmpHeader(fp, width, height, fileHeader, infoHeader);
+ bool ret = LoadBmpHeader( input.file, width, height, fileHeader, infoHeader );
return ret;
}
-bool LoadBitmapFromBmp( FILE *fp, Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client )
+bool LoadBitmapFromBmp( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
- DALI_ASSERT_DEBUG(bitmap.GetPackedPixelsProfile() != 0 && "Need a packed pixel bitmap to load into.");
+ DALI_ASSERT_DEBUG( bitmap.GetPackedPixelsProfile() != 0 && "Need a packed pixel bitmap to load into." );
+ FILE* const fp = input.file;
if(fp == NULL)
{
DALI_LOG_ERROR("Error loading bitmap\n");
return false;
}
- attributes.SetSize(infoHeader.width, infoHeader.height);
return true;
}
*/
#include <cstdio>
+#include "image-loader-input.h"
namespace Dali
{
* @param[in] attributes Describes the dimensions, pixel format and other details for loading the image data
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromBmp( FILE *fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client );
+bool LoadBitmapFromBmp( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
/**
* Loads the header of a BMP file and fills in the width and height appropriately.
* @param[out] height Is set with the height of the image
* @return true if the file's header was read successully, false otherwise
*/
-bool LoadBmpHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height);
+bool LoadBmpHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
} // namespace TizenPlatform
#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/image-attributes.h>
namespace Dali
{
}
/// Called when we want to handle IMAGE_DESC_RECORD_TYPE
-bool HandleImageDescriptionRecordType( Bitmap& bitmap, ImageAttributes& attributes, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished )
+bool HandleImageDescriptionRecordType( Bitmap& bitmap, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished )
{
if ( DGifGetImageDesc( gifInfo ) == GIF_ERROR )
{
return false;
}
- // TODO: Add scaling support
-
// Get the colormap for the GIF
GifColorType* color( GetImageColors( image, gifInfo ) );
}
}
- attributes.SetSize( actualWidth, actualHeight );
-
finished = true;
return true;
} // unnamed namespace
-bool LoadGifHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height )
+bool LoadGifHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
{
GifFileType* gifInfo = NULL;
AutoCleanupGif autoCleanupGif(gifInfo);
+ FILE* const fp = input.file;
return LoadGifHeader(fp, width, height, &gifInfo);
}
-bool LoadBitmapFromGif(FILE *fp, Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client )
+bool LoadBitmapFromGif( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
+ FILE* const fp = input.file;
// Load the GIF Header file.
GifFileType* gifInfo( NULL );
if( IMAGE_DESC_RECORD_TYPE == recordType )
{
- if ( !HandleImageDescriptionRecordType( bitmap, attributes, gifInfo, width, height, finished ) )
+ if ( !HandleImageDescriptionRecordType( bitmap, gifInfo, width, height, finished ) )
{
return false;
}
*/
#include <cstdio>
+#include "image-loader-input.h"
namespace Dali
{
* @param[in] attributes Describes the dimensions, pixel format and other details for loading the image data
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromGif( FILE *fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client );
+bool LoadBitmapFromGif( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
/**
* Loads the header of a GIF file and fills in the width and height appropriately.
* @param[in/out] height Is set with the height of the image
* @return true if the file's header was read successully, false otherwise
*/
-bool LoadGifHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height );
+bool LoadGifHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
} // namespace TizenPlatform
// INTERNAL INCLUDES
#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/image-attributes.h>
namespace Dali
{
}//unnamed namespace
-bool LoadIcoHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height )
+bool LoadIcoHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
{
IcoData chosen;
Dali::Vector<unsigned char> map;
unsigned int fsize;
+ FILE* const fp = input.file;
if ( false == LoadIcoHeaderHelper(fp, chosen, map, fsize) )
{
return true;
}
-bool LoadBitmapFromIco( FILE *fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client )
+bool LoadBitmapFromIco( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
IcoData chosen;
Dali::Vector<unsigned char> map;
unsigned int fsize;
+ FILE* const fp = input.file;
if ( false == LoadIcoHeaderHelper(fp, chosen, map, fsize) )
{
memset(pixels, 0, w * h * 4);
memcpy(pixels, (unsigned char*)&surface[0], w * h * 4);
- attributes.SetSize(w, h);
-
return true;
}
*/
#include <cstdio>
+#include "image-loader-input.h"
namespace Dali
{
const unsigned char MAGIC_BYTE_2 = 0x00;
}
-bool LoadBitmapFromIco( FILE *fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client );
+bool LoadBitmapFromIco( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
-bool LoadIcoHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height );
+bool LoadIcoHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
}
#include "loader-jpeg.h"
#include "resource-loading-client.h"
#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/image-attributes.h>
#include <resource-loader/debug/resource-loader-debug.h>
#include "platform-capabilities.h"
char B;
};
- struct RGBA8888Type
- {
- char R;
- char G;
- char B;
- char A;
- };
-
- struct RGB565Type
- {
- char RG;
- char GB;
- };
-
- struct L8Type
- {
- char gray;
- };
-
/**
* @brief Error handling bookeeping for the JPEG Turbo library's
* setjmp/longjmp simulated exceptions.
return true;
}
-bool LoadBitmapFromJpeg( FILE *fp, Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client )
+bool LoadBitmapFromJpeg( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
const int flags= 0;
+ FILE* const fp = input.file;
if( fseek(fp,0,SEEK_END) )
{
JPGFORM_CODE transform = JPGFORM_NONE;
- if( attributes.GetOrientationCorrection() )
+ if( input.reorientationRequested )
{
ExifAutoPtr exifData( exif_data_new_from_data(jpegBufferPtr, jpegBufferSize) );
if( exifData.mData )
return false;
}
- int requiredWidth = attributes.GetWidth();
- int requiredHeight = attributes.GetHeight();
+ int requiredWidth = input.scalingParameters.dimensions.GetWidth();
+ int requiredHeight = input.scalingParameters.dimensions.GetHeight();
// If transform is a 90 or 270 degree rotation, the logical width and height
// request from the client needs to be adjusted to account by effectively
return false;
}
- attributes.SetSize( scaledPostXformWidth, scaledPostXformHeight );
-
const unsigned int bufferWidth = GetTextureDimension( scaledPreXformWidth );
const unsigned int bufferHeight = GetTextureDimension( scaledPreXformHeight );
return result;
}
+///@Todo: Move all these rotation functions to portable/image-operations and take "Jpeg" out of their names.
bool JpegRotate90(unsigned char *buffer, int width, int height, int bpp)
{
int w, iw, ih, hw = 0;
return exifData;
}
-bool LoadJpegHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height)
+bool LoadJpegHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
{
- unsigned int requiredWidth = attributes.GetWidth();
- unsigned int requiredHeight = attributes.GetHeight();
+ unsigned int requiredWidth = input.scalingParameters.dimensions.GetWidth();
+ unsigned int requiredHeight = input.scalingParameters.dimensions.GetHeight();
+ FILE* const fp = input.file;
bool success = false;
if( requiredWidth == 0 && requiredHeight == 0 )
{
JPGFORM_CODE transform = JPGFORM_NONE;
- if( attributes.GetOrientationCorrection() )
+ if( input.reorientationRequested )
{
ExifAutoPtr exifData( LoadExifData( fp ) );
if( exifData.mData )
#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/image-attributes.h>
#include <dali/public-api/math/math-utils.h>
#include <dali/public-api/math/vector2.h>
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/images/pixel.h>
#include "image-encoder.h"
+#include "image-loader-input.h"
namespace Dali
{
* @param[in] attributes Describes the dimensions, pixel format and other details for loading the image data
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromJpeg( FILE *fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client );
+bool LoadBitmapFromJpeg( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
/**
* Loads the header of a JPEG file and fills in the width and height appropriately.
* @param[in/out] height Is set with the height of the image
* @return true if the file's header was read successully, false otherwise
*/
-bool LoadJpegHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height);
+bool LoadJpegHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
/**
* Encode raw pixel data to JPEG format.
#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
#include <dali/public-api/images/pixel.h>
-#include <dali/public-api/images/image-attributes.h>
namespace Dali
{
} // unnamed namespace
// File loading API entry-point:
-bool LoadKtxHeader(FILE * const fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height)
+bool LoadKtxHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
{
KtxFileHeader fileHeader;
+ FILE* const fp = input.file;
+
bool ret = LoadKtxHeader(fp, width, height, fileHeader);
return ret;
}
// File loading API entry-point:
-bool LoadBitmapFromKtx( FILE * const fp, Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client )
+bool LoadBitmapFromKtx( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
DALI_COMPILE_TIME_ASSERT( sizeof(Byte) == 1);
DALI_COMPILE_TIME_ASSERT( sizeof(uint32_t) == 4);
+
+ FILE* const fp = input.file;
if( fp == NULL )
{
DALI_LOG_ERROR( "Null file handle passed to KTX compressed bitmap file loader.\n" );
return false;
}
- // Ignore all input requests from image attributes and set the available metadata:
- attributes.SetSize(width, height);
-
return true;
}
*/
#include <cstdio>
+#include "image-loader-input.h"
namespace Dali
{
* @param[in] attributes Describes the dimensions, pixel format and other details for loading the image data
* @return true if file loaded successfully, false otherwise
*/
-bool LoadBitmapFromKtx( FILE * const fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client );
+bool LoadBitmapFromKtx( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
/**
* Loads the header of a KTX file and fills in the width and height appropriately.
* @param[out] height Is set with the height of the image
* @return true if the file's header was read successully, false otherwise
*/
-bool LoadKtxHeader(FILE * const fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height);
+bool LoadKtxHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
} // namespace TizenPlatform
#include <dali/integration-api/bitmap.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/images/image.h>
-#include <dali/public-api/images/image-attributes.h>
#include "dali/public-api/math/math-utils.h"
#include "dali/public-api/math/vector2.h"
#include "platform-capabilities.h"
} // namespace - anonymous
-bool LoadPngHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height )
+bool LoadPngHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
{
png_structp png = NULL;
png_infop info = NULL;
auto_png autoPng(png, info);
- bool success = LoadPngHeader(fp, width, height, png, info);
+ bool success = LoadPngHeader( input.file, width, height, png, info );
return success;
}
-bool LoadBitmapFromPng( FILE *fp, Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client )
+bool LoadBitmapFromPng( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
png_structp png = NULL;
png_infop info = NULL;
bool valid = false;
// Load info from the header
- if( !LoadPngHeader(fp, width, height, png, info) )
+ if( !LoadPngHeader( input.file, width, height, png, info ) )
{
return false;
}
// decode image
png_read_image(png, rows);
- // set the attributes
- attributes.SetSize( width, height );
-
free(rows);
return true;
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/images/pixel.h>
#include "image-encoder.h"
+#include "image-loader-input.h"
namespace Dali
{
* @param[in] attributes Describes the dimensions, pixel format and other details for loading the image data
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromPng( FILE *fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client );
+bool LoadBitmapFromPng( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
/**
* Loads the header of a PNG file and fills in the width and height appropriately.
* @param[out] height Is set with the height of the image
* @return true if the file's header was read successully, false otherwise
*/
-bool LoadPngHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height );
+bool LoadPngHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
/**
* A bucket of bytes representing a PNG image.
// INTERNAL INCLUDES
#include <dali/integration-api/debug.h>
#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/image-attributes.h>
#include <dali/public-api/common/dali-vector.h>
namespace Dali
}// end unnamed namespace
-bool LoadBitmapFromWbmp( FILE *fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client )
+bool LoadBitmapFromWbmp( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap )
{
-
+ FILE* const fp = input.file;
if(fp == NULL)
{
DALI_LOG_ERROR("Error loading bitmap\n");
pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::L8, w, h);//Pixel::RGBA8888
memcpy(pixels, (unsigned char*)&surface[0], w * h );//w * h * 4
- attributes.SetSize(w, h);
return true;
}
-bool LoadWbmpHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height )
+bool LoadWbmpHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height )
{
+ FILE* const fp = input.file;
if(fp == NULL)
{
DALI_LOG_ERROR("Error loading bitmap\n");
*/
#include <cstdio>
+#include "image-loader-input.h"
namespace Dali
{
class ResourceLoadingClient;
-bool LoadBitmapFromWbmp( FILE *fp, Integration::Bitmap& bitmap, ImageAttributes& attributes, const ResourceLoadingClient& client );
+bool LoadBitmapFromWbmp( const ResourceLoadingClient& client, const ImageLoader::Input& input, Integration::Bitmap& bitmap );
-bool LoadWbmpHeader(FILE *fp, const ImageAttributes& attributes, unsigned int &width, unsigned int &height );
+bool LoadWbmpHeader( const ImageLoader::Input& input, unsigned int& width, unsigned int& height );
}
return fontSize;
}
-void TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2& closestSize )
+ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( const std::string& filename,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection )
{
- closestSize = Vector2::ZERO;
- ImageLoader::GetClosestImageSize(filename, attributes, closestSize );
+ return ImageLoader::GetClosestImageSize( filename, size, fittingMode, samplingMode, orientationCorrection );
}
-void TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2& closestSize )
+ImageDimensions TizenPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection )
{
- closestSize = Vector2::ZERO;
- ImageLoader::GetClosestImageSize(resourceBuffer, attributes, closestSize );
+ return ImageLoader::GetClosestImageSize( resourceBuffer, size, fittingMode, samplingMode, orientationCorrection );
}
-
void TizenPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
{
if (mResourceLoader)
/**
* @copydoc PlatformAbstraction::GetClosestImageSize()
*/
- virtual void GetClosestImageSize( const std::string& filename,
- const ImageAttributes& attributes,
- Vector2& closestSize );
+ virtual ImageDimensions GetClosestImageSize( const std::string& filename,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection );
/**
* @copydoc PlatformAbstraction::GetClosestImageSize()
*/
- virtual void GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
- const ImageAttributes& attributes,
- Vector2& closestSize );
+ virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection );
/**
* @copydoc PlatformAbstraction::LoadResource()