unsigned int width,
unsigned int height,
Dali::Pixel::Format pixelFormat )
-: mBuffer( buffer ),
+: mMetadata(),
+ mBuffer( buffer ),
mBufferSize( bufferSize ),
mWidth( width ),
mHeight( height ),
}
+void PixelBuffer::SetMetadata( const Property::Map& map )
+{
+ mMetadata.reset(new Property::Map(map));
+}
+
+bool PixelBuffer::GetMetadata(Property::Map& outMetadata) const
+{
+ if( !mMetadata )
+ {
+ return false;
+ }
+ outMetadata = *mMetadata;
+ return true;
+}
+
+void PixelBuffer::SetMetadata(std::unique_ptr<Property::Map> metadata)
+{
+ mMetadata = std::move(metadata);
+}
+
void PixelBuffer::Resize( ImageDimensions outDimensions )
{
if( mWidth != outDimensions.GetWidth() || mHeight != outDimensions.GetHeight() )
#include <dali/public-api/images/image-operations.h> // For ImageDimensions
#include <dali/public-api/images/pixel-data.h>
#include <dali/public-api/object/base-object.h>
+#include <dali/public-api/object/property-map.h>
+
+// EXTERNAL INCLUDES
+#include <memory>
namespace Dali
{
*/
void Resize( ImageDimensions outDimensions );
+ /**
+ * @brief Sets image metadata
+ *
+ * @param map Property map containing Exif fields
+ */
+ void SetMetadata( const Property::Map& map );
+
+ /**
+ * @brief Returns image metadata as a property map
+ * @param[out] outMetadata Property map to copy the data into
+ * @return True on success
+ */
+ bool GetMetadata(Property::Map& outMetadata) const;
+
+ /**
+ * @brief Sets metadata property map for the pixel buffer
+ * @note The function takes over the ownership of the property map
+ * @param[in] metadata Property map to copy the data into
+ */
+ void SetMetadata(std::unique_ptr<Property::Map> metadata);
+
private:
/*
* Undefined copy constructor.
private:
- unsigned char* mBuffer; ///< The raw pixel data
- unsigned int mBufferSize; ///< Buffer sized in bytes
- unsigned int mWidth; ///< Buffer width in pixels
- unsigned int mHeight; ///< Buffer height in pixels
- Pixel::Format mPixelFormat; ///< Pixel format
+ std::unique_ptr<Property::Map> mMetadata; ///< Metadata fields
+ unsigned char* mBuffer; ///< The raw pixel data
+ unsigned int mBufferSize; ///< Buffer sized in bytes
+ unsigned int mWidth; ///< Buffer width in pixels
+ unsigned int mHeight; ///< Buffer height in pixels
+ Pixel::Format mPixelFormat; ///< Pixel format
};
} // namespace Adaptor
#include "image-loading.h"
// INTERNAL INCLUDES
+#include <dali/public-api/object/property-map.h>
#include "image-loaders/image-loader.h"
#include <resource-loader/network/file-download.h>
#include <platform-abstractions/portable/file-reader.h>
#include "pixel-buffer-impl.h"
+
+
namespace Dali
{
FILE * const fp = fileReader.GetFile();
if( fp != NULL )
{
- Integration::BitmapPtr bitmap;
+ Dali::Devel::PixelBuffer bitmap;
bool success = TizenPlatform::ImageLoader::ConvertStreamToBitmap( resourceType, url, fp, bitmap );
if( success && bitmap )
{
- // Use bitmap->GetBufferOwnership() to transfer the buffer ownership
- // to pixelData. The destroy of bitmap will not release the buffer,
- // instead, the pixelBuffer is responsible for releasing when its
- // reference count falls to zero.
- Internal::Adaptor::PixelBufferPtr pixelBufferImpl =
- Internal::Adaptor::PixelBuffer::New( bitmap->GetBufferOwnership(),
- bitmap->GetBufferSize(),
- bitmap->GetImageWidth(),
- bitmap->GetImageHeight(),
- bitmap->GetPixelFormat() );
-
- Dali::Devel::PixelBuffer pixelBuffer( pixelBufferImpl.Get() );
- return pixelBuffer;
+ return bitmap;
}
}
return Dali::Devel::PixelBuffer();
FILE * const fp = fileReader.GetFile();
if ( NULL != fp )
{
- Integration::BitmapPtr bitmap;
+ Dali::Devel::PixelBuffer bitmap;
bool result = TizenPlatform::ImageLoader::ConvertStreamToBitmap(
resourceType,
url,
if ( result && bitmap )
{
- Internal::Adaptor::PixelBufferPtr pixelBufferImpl =
- Internal::Adaptor::PixelBuffer::New( bitmap->GetBufferOwnership(),
- bitmap->GetBufferSize(),
- bitmap->GetImageWidth(),
- bitmap->GetImageHeight(),
- bitmap->GetPixelFormat() );
-
- Dali::Devel::PixelBuffer pixelBuffer( pixelBufferImpl.Get() );
- return pixelBuffer;
+ return bitmap;
}
else
{
GetImplementation(*this).Resize( ImageDimensions( width, height ) );
}
+bool PixelBuffer::GetMetadata( Property::Map& metadata ) const
+{
+ return GetImplementation(*this).GetMetadata(metadata);
+}
+
} // namespace Devel
} // namespace Dali
*
*/
+// INTERNAL INCLUDES
#include <dali/public-api/images/pixel.h>
#include <dali/public-api/images/pixel-data.h>
#include <dali/public-api/object/base-handle.h>
*/
void Resize( uint16_t width, uint16_t height );
+ /**
+ * Returns Exif metadata as a property map
+ *
+ * @param[out] metadata Property map object to write into
+ * @return True on success
+ */
+ bool GetMetadata( Property::Map& metadata ) const;
+
public:
/**
#include "image-loaders.h"
#include <dali-test-suite-utils.h>
-
+#include <adaptors/common/pixel-buffer-impl.h>
AutoCloseFile::AutoCloseFile( FILE *fp )
: filePtr( fp )
// Loading the header moves the pointer within the file so reset to start of file.
fseek( fp, 0, 0 );
- // Create a bitmap object and store a pointer to that object so it is destroyed at the end.
- Dali::Integration::Bitmap * bitmap = Dali::Integration::Bitmap::New( bitmapProfile, ResourcePolicy::OWNED_RETAIN );
- Dali::Integration::BitmapPtr bitmapPtr( bitmap );
+ Dali::Devel::PixelBuffer bitmap;
// Load Bitmap and check its return values.
- DALI_TEST_CHECK( functions.loader( input, *bitmap ) );
- DALI_TEST_EQUALS( image.width, bitmap->GetImageWidth(), TEST_LOCATION );
- DALI_TEST_EQUALS( image.height, bitmap->GetImageHeight(), TEST_LOCATION );
+ DALI_TEST_CHECK( functions.loader( input, bitmap ) );
+ DALI_TEST_EQUALS( image.width, bitmap.GetWidth(), TEST_LOCATION );
+ DALI_TEST_EQUALS( image.height, bitmap.GetHeight(), TEST_LOCATION );
// Compare buffer generated with reference buffer.
- Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() );
+ Dali::PixelBuffer* bufferPtr( bitmap.GetBuffer() );
Dali::PixelBuffer* refBufferPtr( image.refBuffer );
for ( unsigned int i = 0; i < image.refBufferSize; ++i, ++bufferPtr, ++refBufferPtr )
{
// Loading the header moves the pointer within the file so reset to start of file.
fseek( filePointer, 0, SEEK_SET );
- // Create a bitmap object and store a pointer to that object so it is destroyed at the end.
- Dali::Integration::Bitmap * bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
- Dali::Integration::BitmapPtr bitmapPointer( bitmap );
+ Dali::Devel::PixelBuffer bitmap;
// Load Bitmap and check its return values.
- DALI_TEST_CHECK( functions.loader( input, *bitmap ) );
- DALI_TEST_EQUALS( image.width, bitmap->GetImageWidth(), TEST_LOCATION );
- DALI_TEST_EQUALS( image.height, bitmap->GetImageHeight(), TEST_LOCATION );
+ DALI_TEST_CHECK( functions.loader( input, bitmap ) );
+ DALI_TEST_EQUALS( image.width, bitmap.GetWidth(), TEST_LOCATION );
+ DALI_TEST_EQUALS( image.height, bitmap.GetHeight(), TEST_LOCATION );
// Check the bytes per pixel.
- const Pixel::Format pixelFormat = bitmap->GetPixelFormat();
+ const Pixel::Format pixelFormat = bitmap.GetPixelFormat();
const unsigned int bytesPerPixel = Pixel::GetBytesPerPixel( pixelFormat );
// Compare buffer generated with reference buffer.
- Dali::PixelBuffer* pBitmapData( bitmapPointer->GetBuffer() );
+ Dali::PixelBuffer* pBitmapData( bitmap.GetBuffer() );
const uint32_t* pMaster( master );
// Loop through each pixel in the bitmap.
FILE* fp = fopen( filename.c_str() , "rb" );
AutoCloseFile autoClose( fp );
- Dali::Integration::Bitmap* bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
- Dali::Integration::BitmapPtr bitmapPtr( bitmap );
+ Dali::Devel::PixelBuffer bitmap;
const Dali::TizenPlatform::ImageLoader::Input input( fp );
- DALI_TEST_CHECK( functions.loader( input, *bitmap ) );
+ DALI_TEST_CHECK( functions.loader( input, bitmap ) );
- Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() );
+ Dali::PixelBuffer* bufferPtr( bitmap.GetBuffer() );
FILE* writeFp = fopen( targetFilename.c_str(), "wb" );
AutoCloseFile autoCloseWrite( writeFp );
- fwrite( bufferPtr, 1, bitmap->GetBufferSize(), writeFp );
+ auto& impl = GetImplementation(bitmap);
+ fwrite( bufferPtr, 1, impl.GetBufferSize(), writeFp );
}
#include <dali/dali.h>
#include <dali/integration-api/bitmap.h>
+#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
#include "platform-abstractions/tizen/image-loaders/image-loader-input.h"
// Simple structure to close the file when finished with it.
*/
struct LoadFunctions
{
- typedef bool (*LoadBitmapFunction)( const Dali::TizenPlatform::ImageLoader::Input& input, Dali::Integration::Bitmap& );
+ typedef bool (*LoadBitmapFunction)( const Dali::TizenPlatform::ImageLoader::Input& input, Dali::Devel::PixelBuffer& );
typedef bool (*LoadBitmapHeaderFunction)( const Dali::TizenPlatform::ImageLoader::Input& input, unsigned int& width, unsigned int& height );
LoadFunctions( LoadBitmapHeaderFunction _header, LoadBitmapFunction _loader );
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::OWNED_DISCARD );
- sourceBitmap->GetPackedPixelsProfile()->ReserveBuffer( format, sourceDimension, sourceDimension, sourceDimension, sourceDimension );
+ Dali::Devel::PixelBuffer sourceBitmap = Dali::Devel::PixelBuffer::New( sourceDimension, sourceDimension, format );
- Integration::BitmapPtr downScaled = DownscaleBitmap( *sourceBitmap, desired, fittingMode, samplingMode );
+ Dali::Devel::PixelBuffer 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 );
+ DALI_TEST_EQUALS( downScaled.GetWidth(), expectedDimension, location );
+ DALI_TEST_EQUALS( downScaled.GetHeight(), expectedDimension, location );
+ DALI_TEST_EQUALS( downScaled.GetPixelFormat(), format, location );
}
/**
typedef unsigned char PixelBuffer;
-void FillBitmap( BitmapPtr bitmap )
+void FillBitmap( Dali::Devel::PixelBuffer bitmap )
{
// Fill the given bitmap fully.
- const Pixel::Format pixelFormat = bitmap->GetPixelFormat();
+ const Pixel::Format pixelFormat = bitmap.GetPixelFormat();
const unsigned int bytesPerPixel = Pixel::GetBytesPerPixel( pixelFormat );
- PixelBuffer * const targetPixels = bitmap->GetBuffer();
- const int bytesToFill = bitmap.Get()->GetImageWidth() * bitmap.Get()->GetImageHeight() * bytesPerPixel;
+ PixelBuffer * const targetPixels = bitmap.GetBuffer();
+ const int bytesToFill = bitmap.GetWidth() * bitmap.GetHeight() * bytesPerPixel;
memset( targetPixels, BORDER_FILL_VALUE, bytesToFill );
}
// Create a source bitmap.
ImageDimensions desiredDimensions( desiredWidth, desiredHeight );
SamplingMode::Type samplingMode = SamplingMode::BOX_THEN_LINEAR;
- BitmapPtr sourceBitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
- Integration::Bitmap::PackedPixelsProfile *packedView = sourceBitmap->GetPackedPixelsProfile();
- const Pixel::Format pixelFormat = sourceBitmap->GetPixelFormat();
- packedView->ReserveBuffer( pixelFormat, sourceWidth, sourceHeight, sourceWidth, sourceHeight );
+
+ auto sourceBitmap = Dali::Devel::PixelBuffer::New( sourceWidth, sourceHeight, Pixel::Format::RGBA8888 );
+ const Pixel::Format pixelFormat = sourceBitmap.GetPixelFormat();
// Completely fill the source bitmap (with white).
FillBitmap( sourceBitmap );
// Perform fitting operations (this is the method we are testing).
- BitmapPtr newBitmap = ApplyAttributesToBitmap( sourceBitmap, desiredDimensions, fittingMode, samplingMode );
+ auto newBitmap = ApplyAttributesToBitmap( sourceBitmap, desiredDimensions, fittingMode, samplingMode );
DALI_TEST_CHECK( newBitmap );
return;
}
- Bitmap *bitmap = newBitmap.Get();
+ auto bitmap( newBitmap );
- unsigned int resultWidth = bitmap->GetImageWidth();
- unsigned int resultHeight = bitmap->GetImageHeight();
+ unsigned int resultWidth = bitmap.GetWidth();
+ unsigned int resultHeight = bitmap.GetHeight();
// Check the dimensions of the modified image match against the expected values defined in the test.
DALI_TEST_EQUALS( resultWidth, test.expectedWidth, TEST_LOCATION );
DALI_TEST_EQUALS( resultHeight, test.expectedHeight, TEST_LOCATION );
- PixelBuffer* resultBuffer = bitmap->GetBuffer();
+ PixelBuffer* resultBuffer = bitmap.GetBuffer();
const unsigned int bytesPerPixel = Pixel::GetBytesPerPixel( pixelFormat );
// We generate an ASCII representation of the source, desired and result images to log, purely as a debugging aid.
}
/**
- * @brief Construct a bitmap with format and dimensions requested.
+ * @brief Construct a pixel buffer object from a copy of the pixel array passed in.
*/
-BitmapPtr MakeEmptyBitmap( Pixel::Format pixelFormat, unsigned int width, unsigned int height )
-{
- DALI_ASSERT_DEBUG( Pixel::GetBytesPerPixel(pixelFormat) && "Compressed formats not supported." );
-
- // Allocate a pixel buffer to hold the image passed in:
- Integration::BitmapPtr newBitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
- newBitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, width, height, width, height );
- return newBitmap;
-}
-
-/**
- * @brief Construct a bitmap object from a copy of the pixel array passed in.
- */
-BitmapPtr MakeBitmap( const uint8_t * const pixels, Pixel::Format pixelFormat, unsigned int width, unsigned int height )
+Dali::Devel::PixelBuffer MakePixelBuffer( const uint8_t * const pixels, Pixel::Format pixelFormat, unsigned int width, unsigned int height )
{
DALI_ASSERT_DEBUG( pixels && "Null bitmap buffer to copy." );
// Allocate a pixel buffer to hold the image passed in:
- Integration::BitmapPtr newBitmap = MakeEmptyBitmap( pixelFormat, width, height );
+ auto newBitmap = Dali::Devel::PixelBuffer::New( width, height, pixelFormat );
// Copy over the pixels from the downscaled image that was generated in-place in the pixel buffer of the input bitmap:
- memcpy( newBitmap->GetBuffer(), pixels, width * height * Pixel::GetBytesPerPixel( pixelFormat ) );
+ memcpy( newBitmap.GetBuffer(), pixels, width * height * Pixel::GetBytesPerPixel( pixelFormat ) );
return newBitmap;
}
* bitmaps dimensions to only be as large as necessary, as a memory saving optimization. This will cause
* GPU scaling to be performed at render time giving the same result with less texture traversal.
*
- * @param[in] bitmap The source bitmap to perform modifications on.
+ * @param[in] bitmap The source pixel buffer to perform modifications on.
* @param[in] desiredDimensions The target dimensions to aim to fill based on the fitting mode.
* @param[in] fittingMode The fitting mode to use.
*
* @return A new bitmap with the padding and cropping required for fitting mode applied.
* If no modification is needed or possible, the passed in bitmap is returned.
*/
-Integration::BitmapPtr CropAndPadForFittingMode( Integration::BitmapPtr bitmap, ImageDimensions desiredDimensions, FittingMode::Type fittingMode );
+Dali::Devel::PixelBuffer CropAndPadForFittingMode( Dali::Devel::PixelBuffer& bitmap, ImageDimensions desiredDimensions, FittingMode::Type fittingMode );
/**
* @brief Adds horizontal or vertical borders to the source image.
*/
void AddBorders( PixelBuffer *targetPixels, const unsigned int bytesPerPixel, const ImageDimensions targetDimensions, const ImageDimensions padDimensions );
-BitmapPtr ApplyAttributesToBitmap( BitmapPtr bitmap, ImageDimensions dimensions, FittingMode::Type fittingMode, SamplingMode::Type samplingMode )
+Dali::Devel::PixelBuffer ApplyAttributesToBitmap( Dali::Devel::PixelBuffer bitmap, ImageDimensions dimensions, FittingMode::Type fittingMode, SamplingMode::Type samplingMode )
{
if( bitmap )
{
// Calculate the desired box, accounting for a possible zero component:
- const ImageDimensions desiredDimensions = CalculateDesiredDimensions( bitmap->GetImageWidth(), bitmap->GetImageHeight(), dimensions.GetWidth(), dimensions.GetHeight() );
+ const ImageDimensions desiredDimensions = CalculateDesiredDimensions( bitmap.GetWidth(), bitmap.GetHeight(), 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, fittingMode, samplingMode );
+ 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.
// Add crop and add borders if necessary depending on fitting mode.
- if( bitmap && bitmap->GetPackedPixelsProfile() )
+ if( bitmap )
{
bitmap = CropAndPadForFittingMode( bitmap, desiredDimensions, fittingMode );
}
-
- // Examine the image pixels remaining after cropping and scaling to see if all
- // are opaque, allowing faster rendering, or some have non-1.0 alpha:
- if( bitmap && bitmap->GetPackedPixelsProfile() && Pixel::HasAlpha( bitmap->GetPixelFormat() ) )
- {
- bitmap->GetPackedPixelsProfile()->TestForTransparency();
- }
}
return bitmap;
}
-BitmapPtr CropAndPadForFittingMode( BitmapPtr bitmap, ImageDimensions desiredDimensions, FittingMode::Type fittingMode )
+Dali::Devel::PixelBuffer CropAndPadForFittingMode( Dali::Devel::PixelBuffer& bitmap, ImageDimensions desiredDimensions, FittingMode::Type fittingMode )
{
- const unsigned int inputWidth = bitmap->GetImageWidth();
- const unsigned int inputHeight = bitmap->GetImageHeight();
+ const unsigned int inputWidth = bitmap.GetWidth();
+ const unsigned int inputHeight = bitmap.GetHeight();
if( desiredDimensions.GetWidth() < 1u || desiredDimensions.GetHeight() < 1u )
{
return bitmap;
}
- // Create a new bitmap with the desired size.
- BitmapPtr croppedBitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
- Integration::Bitmap::PackedPixelsProfile *packedView = croppedBitmap->GetPackedPixelsProfile();
- DALI_ASSERT_DEBUG( packedView );
- const Pixel::Format pixelFormat = bitmap->GetPixelFormat();
- packedView->ReserveBuffer( pixelFormat, desiredWidth, desiredHeight, desiredWidth, desiredHeight );
+ // Create new PixelBuffer with the desired size.
+ const auto pixelFormat = bitmap.GetPixelFormat();
+
+ auto croppedBitmap = Devel::PixelBuffer::New( desiredWidth, desiredHeight, pixelFormat );
// Add some pre-calculated offsets to the bitmap pointers so this is not done within a loop.
// The cropping is added to the source pointer, and the padding is added to the destination.
- const unsigned int bytesPerPixel = Pixel::GetBytesPerPixel( pixelFormat );
- const PixelBuffer * const sourcePixels = bitmap->GetBuffer() + ( ( ( ( scanlinesToCrop / 2 ) * inputWidth ) + ( columnsToCrop / 2 ) ) * bytesPerPixel );
- PixelBuffer * const targetPixels = croppedBitmap->GetBuffer();
+ const auto bytesPerPixel = Pixel::GetBytesPerPixel( pixelFormat );
+ const PixelBuffer * const sourcePixels = bitmap.GetBuffer() + ( ( ( ( scanlinesToCrop / 2 ) * inputWidth ) + ( columnsToCrop / 2 ) ) * bytesPerPixel );
+ PixelBuffer * const targetPixels = croppedBitmap.GetBuffer();
PixelBuffer * const targetPixelsActive = targetPixels + ( ( ( ( scanlinesToPad / 2 ) * desiredWidth ) + ( columnsToPad / 2 ) ) * bytesPerPixel );
DALI_ASSERT_DEBUG( sourcePixels && targetPixels );
// Add vertical or horizontal borders to the final image (if required).
desiredDimensions.SetWidth( desiredWidth );
desiredDimensions.SetHeight( desiredHeight );
- AddBorders( croppedBitmap->GetBuffer(), bytesPerPixel, desiredDimensions, ImageDimensions( columnsToPad, scanlinesToPad ) );
+ AddBorders( croppedBitmap.GetBuffer(), bytesPerPixel, desiredDimensions, ImageDimensions( columnsToPad, scanlinesToPad ) );
// Overwrite the loaded bitmap with the cropped version
bitmap = croppedBitmap;
}
}
}
-Integration::BitmapPtr DownscaleBitmap( Integration::Bitmap& bitmap,
+Dali::Devel::PixelBuffer DownscaleBitmap( Dali::Devel::PixelBuffer bitmap,
ImageDimensions desired,
FittingMode::Type fittingMode,
SamplingMode::Type samplingMode )
{
// Source dimensions as loaded from resources (e.g. filesystem):
- const unsigned int bitmapWidth = bitmap.GetImageWidth();
- const unsigned int bitmapHeight = bitmap.GetImageHeight();
+ auto bitmapWidth = bitmap.GetWidth();
+ auto bitmapHeight = bitmap.GetHeight();
// Desired dimensions (the rectangle to fit the source image to):
- const unsigned int desiredWidth = desired.GetWidth();
- const unsigned int desiredHeight = desired.GetHeight();
+ auto desiredWidth = desired.GetWidth();
+ auto desiredHeight = desired.GetHeight();
- BitmapPtr outputBitmap( &bitmap );
+ Dali::Devel::PixelBuffer outputBitmap { bitmap };
// If a different size than the raw one has been requested, resize the image:
- if( bitmap.GetPackedPixelsProfile() &&
+ if(
(desiredWidth > 0.0f) && (desiredHeight > 0.0f) &&
((desiredWidth < bitmapWidth) || (desiredHeight < bitmapHeight)) )
{
- const Pixel::Format pixelFormat = bitmap.GetPixelFormat();
+ auto pixelFormat = bitmap.GetPixelFormat();
// 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;
if( samplingMode == SamplingMode::LINEAR || samplingMode == SamplingMode::BOX_THEN_LINEAR ||
samplingMode == SamplingMode::NEAREST || samplingMode == SamplingMode::BOX_THEN_NEAREST )
{
- outputBitmap = MakeEmptyBitmap( pixelFormat, filteredWidth, filteredHeight );
+ outputBitmap = Dali::Devel::PixelBuffer::New( filteredWidth, filteredHeight, pixelFormat );
+
if( outputBitmap )
{
if( samplingMode == SamplingMode::LINEAR || samplingMode == SamplingMode::BOX_THEN_LINEAR )
{
- LinearSample( bitmap.GetBuffer(), ImageDimensions(shrunkWidth, shrunkHeight), pixelFormat, outputBitmap->GetBuffer(), filteredDimensions );
+ LinearSample( bitmap.GetBuffer(), ImageDimensions(shrunkWidth, shrunkHeight), pixelFormat, outputBitmap.GetBuffer(), filteredDimensions );
}
else
{
- PointSample( bitmap.GetBuffer(), shrunkWidth, shrunkHeight, pixelFormat, outputBitmap->GetBuffer(), filteredWidth, filteredHeight );
+ PointSample( bitmap.GetBuffer(), shrunkWidth, shrunkHeight, pixelFormat, outputBitmap.GetBuffer(), filteredWidth, filteredHeight );
}
filtered = true;
}
// Copy out the 2^x downscaled, box-filtered pixels if no secondary filter (point or linear) was applied:
if( filtered == false && ( shrunkWidth < bitmapWidth || shrunkHeight < bitmapHeight ) )
{
- outputBitmap = MakeBitmap( bitmap.GetBuffer(), pixelFormat, shrunkWidth, shrunkHeight );
+ outputBitmap = MakePixelBuffer( bitmap.GetBuffer(), pixelFormat, shrunkWidth, shrunkHeight );
}
}
#include <dali/public-api/images/image-operations.h>
#include <resampler.h>
+#ifdef DALI_ADAPTOR_COMPILATION
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
+#else
+#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
+#endif
+
+
namespace Dali
{
namespace Internal
* bitmap passed-in, or the original bitmap passed in if the attributes
* have no effect.
*/
-Integration::BitmapPtr ApplyAttributesToBitmap( Integration::BitmapPtr bitmap, ImageDimensions dimensions, FittingMode::Type fittingMode = FittingMode::DEFAULT, SamplingMode::Type samplingMode = SamplingMode::DEFAULT );
+Dali::Devel::PixelBuffer ApplyAttributesToBitmap( Dali::Devel::PixelBuffer 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, FittingMode::Type fittingMode, SamplingMode::Type samplingMode );
+Dali::Devel::PixelBuffer DownscaleBitmap( Dali::Devel::PixelBuffer bitmap,
+ ImageDimensions desired,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode );
/**@}*/
/**
#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-reader.h"
using namespace Dali::Integration;
namespace
{
-typedef bool (*LoadBitmapFunction)( 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 BitmapResourceType& resource, std::string path, FILE * const fp, BitmapPtr& ptr )
+bool ConvertStreamToBitmap( const BitmapResourceType& resource, std::string path, FILE * const fp, Dali::Devel::PixelBuffer& pixelBuffer )
{
DALI_LOG_TRACE_METHOD( gLogFilter );
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 ScalingParameters scalingParameters( resource.size, resource.scalingMode, resource.samplingMode );
const ImageLoader::Input input( fp, scalingParameters, resource.orientationCorrection );
// Run the image type decoder:
- result = function( input, *bitmap );
+ result = function( input, pixelBuffer );
if (!result)
{
DALI_LOG_WARNING( "Unable to convert %s\n", path.c_str() );
- bitmap = 0;
+ pixelBuffer.Reset();
}
- bitmap = Internal::Platform::ApplyAttributesToBitmap( bitmap, resource.size, resource.scalingMode, resource.samplingMode );
+ pixelBuffer = Internal::Platform::ApplyAttributesToBitmap( pixelBuffer, resource.size, resource.scalingMode, resource.samplingMode );
}
else
{
}
}
- ptr.Reset( bitmap.Get() );
return result;
}
ResourcePointer LoadImageSynchronously( const Integration::BitmapResourceType& resource, const std::string& path )
{
ResourcePointer result;
- BitmapPtr bitmap = 0;
+ Dali::Devel::PixelBuffer bitmap;
Internal::Platform::FileReader fileReader( path );
FILE * const fp = fileReader.GetFile();
if( fp != NULL )
{
- bool success = ConvertStreamToBitmap( resource, path, fp, bitmap );
- if( success && bitmap )
+ bool success = ConvertStreamToBitmap(resource, path, fp, bitmap);
+ if (success && bitmap)
{
- result.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 result;
#include <dali/public-api/images/image-operations.h>
#include <dali/integration-api/resource-types.h>
#include <dali/integration-api/bitmap.h>
+#include <dali/public-api/images/pixel-data.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
+#include <string>
namespace Dali
{
* @param[out] bitmap Pointer to write bitmap to
* @return true on success, false on failure
*/
-bool ConvertStreamToBitmap( const Integration::BitmapResourceType& resource, std::string path, FILE * const fp, Integration::BitmapPtr& ptr );
+bool ConvertStreamToBitmap( const Integration::BitmapResourceType& resource, std::string path, FILE * const fp, Dali::Devel::PixelBuffer& pixelBuffer );
/**
* Convert a bitmap and write to a file stream.
* @param[in] path The path to the resource.
* @param[in] fp File Pointer. Closed on exit.
- * @param[out] bitmap Pointer from which to read bitmap
+ * @param[out] pixelData Reference to PixelData object.
* @return true on success, false on failure
*/
-bool ConvertBitmapToStream( std::string path, FILE * const fp, Integration::BitmapPtr& ptr );
+bool ConvertBitmapToStream( std::string path, FILE * const fp, Dali::Devel::PixelBuffer& pixelBuffer );
/**
* Loads an image synchronously
#include "loader-astc.h"
// EXTERNAL INCLUDES
-#include <cstdio>
-#include <cstdlib>
#include <cstring>
-#include <stdint.h>
#include <dali/public-api/common/compile-time-assert.h>
#include <dali/integration-api/debug.h>
-#include <dali/integration-api/bitmap.h>
#include <dali/public-api/images/pixel.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
namespace Dali
{
-using Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
-
namespace TizenPlatform
{
-
namespace
{
}
// File loading API entry-point:
-bool LoadBitmapFromAstc( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromAstc( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
{
FILE* const filePointer = input.file;
if( !filePointer )
return false;
}
- // Allocate space to load the image data in to.
- PixelBuffer* const pixels = bitmap.GetCompressedProfile()->ReserveBufferOfSize( pixelFormat, width, height, imageByteCount );
- if( !pixels )
- {
- DALI_LOG_ERROR( "Unable to reserve a pixel buffer to load the requested bitmap into.\n" );
- return false;
- }
+ // allocate pixel data
+ bitmap = Dali::Devel::PixelBuffer::New(width, height, pixelFormat);
+ auto pixels = bitmap.GetBuffer();
// Load the image data.
const size_t bytesRead = fread( pixels, 1, imageByteCount, filePointer );
+
// Check the size of loaded data is what we expected.
if( bytesRead != imageByteCount )
{
namespace Dali
{
-
-namespace Integration
+namespace Devel
{
- class Bitmap;
+class PixelBuffer;
}
+
namespace TizenPlatform
{
* @param[out] bitmap The bitmap class where the decoded image will be stored
* @return True if file loaded successfully, false otherwise
*/
-bool LoadBitmapFromAstc( const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+bool LoadBitmapFromAstc( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap );
/**
* Loads the header of a ASTC file and fills in the width and height appropriately.
#include "loader-bmp.h"
#include <dali/public-api/common/vector-wrapper.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
#include <dali/integration-api/debug.h>
-#include <dali/integration-api/bitmap.h>
-
-#include <cstdlib>
namespace Dali
{
-using Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
+
namespace TizenPlatform
{
* @return true, if decode successful, false otherwise
*/
bool DecodeRGB24V5(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
for(unsigned int yPos = 0; yPos < height; yPos ++)
{
- PixelBuffer *pixelsPtr = NULL;
+ unsigned char* pixelsPtr = NULL;
if(topDown)
{
pixelsPtr = pixels + ( yPos * rowStride);
* @return true, if decode successful, false otherwise
*/
bool DecodeBF32V4(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
for(unsigned int yPos = 0; yPos < height; yPos ++)
{
- PixelBuffer *pixelsPtr = NULL;
+ unsigned char* pixelsPtr = NULL;
if(topDown)
{
pixelsPtr = pixels + ( yPos * rowStride);
* @return true, if decode successful, false otherwise
*/
bool DecodeBF32(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
for (unsigned int yPos = 0; yPos < height; yPos++)
{
- PixelBuffer *pixelsPtr;
+ unsigned char* pixelsPtr;
if (topDown)
{
// the data in the file is top down, and we store the data top down
* @return true, if decode successful, false otherwise
*/
bool DecodeBF565(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
for(unsigned int i = 0; i < height; i++)
{
- PixelBuffer *pixelsPtr = NULL;
+ unsigned char* pixelsPtr = NULL;
if (topDown)
{
// the data in the file is top down, and we store the data top down
* @return true, if decode successful, false otherwise
*/
bool DecodeBF555(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
for (unsigned int yPos = 0; yPos < height; yPos++)
{
- PixelBuffer *pixelsPtr = NULL;
+ unsigned char* pixelsPtr = NULL;
if (topDown)
{
// the data in the file is top down, and we store the data top down
* @return true, if decode successful, false otherwise
*/
bool DecodeRGB555(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
}
for(unsigned int i = 0; i < height; i++)
{
- PixelBuffer *pixelsPtr = NULL;
+ unsigned char* pixelsPtr = NULL;
if (topDown)
{
// the data in the file is top down, and we store the data top down
* @return true, if decode successful, false otherwise
*/
bool DecodeRGB1(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
for(unsigned int index = 0; index < height; index = index + 1)
{
- PixelBuffer *pixelsPtr = NULL;
+ unsigned char* pixelsPtr = NULL;
if (topDown)
{
// the data in the file is top down, and we store the data top down
* @return true, if decode successful, false otherwise
*/
bool DecodeRGB4(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
for(unsigned int index = 0; index < height; index = index + 1)
{
- PixelBuffer *pixelsPtr = NULL;
+ unsigned char* pixelsPtr = NULL;
if (topDown)
{
// the data in the file is top down, and we store the data top down
* @return true, if decode successful, false otherwise
*/
bool DecodeRGB8(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
unsigned int ctIndex = 0;
for(unsigned int index = 0; index < height; index = index + 1)
{
- PixelBuffer *pixelsPtr = NULL;
+ unsigned char* pixelsPtr = NULL;
if (topDown)
{
// the data in the file is top down, and we store the data top down
* @return true, if decode successful, false otherwise
*/
bool DecodeRLE4(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
DALI_LOG_ERROR("Error decoding BMP_RLE4 format\n");
return false;
}
- PixelBuffer *pixelsPtr = pixels;
+ unsigned char* pixelsPtr = pixels;
width = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
char cmd[2];
unsigned int cmdStride = 2;
* @return true, if decode successful, false otherwise
*/
bool DecodeRLE8(FILE *fp,
- PixelBuffer *pixels,
+ unsigned char* pixels,
unsigned int width,
unsigned int height,
unsigned int offset,
DALI_LOG_ERROR("Error decoding BMP_RLE8 format\n");
return false;
}
- PixelBuffer *pixelsPtr = pixels;
+ unsigned char* pixelsPtr = pixels;
unsigned int x = 0;
unsigned int y = 0;
unsigned int cmdStride = 2;
return ret;
}
-bool LoadBitmapFromBmp( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& 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)
{
padding = 4 - padding;
}
- PixelBuffer *pixels = NULL;
int imageW = infoHeader.width;
- int pixelBufferW = 0;
+ int pixelBufferW = infoHeader.width;
+ int pixelBufferH = infoHeader.height;
+ auto newPixelFormat = Pixel::Format::INVALID;
+
switch(customizedFormat)
{
case BMP_RLE8:
case BMP_BITFIELDS555:
{
pixelBufferW = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB888, pixelBufferW, abs(infoHeader.height));
+ pixelBufferH = abs(infoHeader.height);
+ newPixelFormat = Pixel::RGB888;
break;
}
case BMP_RGB1:
{
pixelBufferW = ((imageW & 63) != 0) ? imageW + 64 - (imageW & 63) : imageW;
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB888, pixelBufferW, abs(infoHeader.height));
+ pixelBufferH = abs(infoHeader.height);
+ newPixelFormat = Pixel::RGB888;
break;
}
case BMP_BITFIELDS32:
case BMP_BITFIELDS32V4:
{
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB8888, infoHeader.width, abs(infoHeader.height));
+ pixelBufferH = abs(infoHeader.height);
+ newPixelFormat = Pixel::RGB8888;
break;
}
case BMP_RGB24V5:
{
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB888, infoHeader.width, infoHeader.height);
+ newPixelFormat = Pixel::RGB888;
break;
}
default:
if(pixelFormat == Pixel::RGB565 )
{
pixelBufferW = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB565, pixelBufferW, abs(infoHeader.height));
- }
- else
- {
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(pixelFormat, infoHeader.width, infoHeader.height);
+ pixelBufferH = abs(infoHeader.height);
+ newPixelFormat = Pixel::RGB565;
}
break;
}
- // TODO: Add scaling support
+ bitmap = Dali::Devel::PixelBuffer::New(pixelBufferW, pixelBufferH, newPixelFormat);
+ auto pixels = bitmap.GetBuffer();
// Read the raw bitmap data
- PixelBuffer *pixelsPtr;
+ decltype(pixels) pixelsIterator = nullptr;
+
bool decodeResult(false);
switch(customizedFormat)
{
if (topDown)
{
// the data in the file is top down, and we store the data top down
- pixelsPtr = pixels + ( yPos * rowStride);
+ pixelsIterator = pixels + ( yPos * rowStride);
}
else
{
// the data in the file is bottom up, and we store the data top down
- pixelsPtr = pixels + (((height-1)-yPos) * rowStride);
+ pixelsIterator = pixels + (((height-1)-yPos) * rowStride);
}
- if (fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+ if (fread(pixelsIterator, 1, rowStride, fp) != rowStride)
{
DALI_LOG_ERROR("Error reading the BMP image\n");
break;
{
for(unsigned int i = 0; i < rowStride; i += 3)
{
- unsigned char temp = pixelsPtr[i];
- pixelsPtr[i] = pixelsPtr[i+2];
- pixelsPtr[i+2] = temp;
+ unsigned char temp = pixelsIterator[i];
+ pixelsIterator[i] = pixelsIterator[i+2];
+ pixelsIterator[i+2] = temp;
}
}
namespace Dali
{
-
-namespace Integration
+namespace Devel
{
-class Bitmap;
+class PixelBuffer;
}
+
namespace TizenPlatform
{
* @param[out] bitmap The bitmap class where the decoded image will be stored
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromBmp( const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap );
/**
* Loads the header of a BMP file and fills in the width and height appropriately.
#include "loader-gif.h"
#include <gif_lib.h>
-#include <cstdlib>
#include <dali/integration-api/debug.h>
-#include <dali/integration-api/bitmap.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
+#include <memory>
// We need to check if giflib has the new open and close API (including error parameter).
#ifdef GIFLIB_MAJOR
namespace Dali
{
-using Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
namespace TizenPlatform
{
GifFileType*& gifInfo;
};
-// Simple class to enforce clean-up of PixelBuffer
-struct AutoDeleteBuffer
-{
- AutoDeleteBuffer( PixelBuffer* _buffer )
- : buffer( _buffer )
- {
- }
-
- ~AutoDeleteBuffer()
- {
- delete []buffer;
- }
-
- PixelBuffer* buffer;
-};
-
// Used in the GIF interlace algorithm to determine the starting byte and the increment required
// for each pass.
struct InterlacePair
}
/// Decode the GIF image.
-bool DecodeImage( GifFileType* gifInfo, PixelBuffer* decodedData, const unsigned int width, const unsigned int height, const unsigned int bytesPerRow )
+bool DecodeImage( GifFileType* gifInfo, unsigned char* decodedData, const unsigned int width, const unsigned int height, const unsigned int bytesPerRow )
{
if ( gifInfo->Image.Interlace )
{
{
for( unsigned int currentByte = interlacePairPtr->startingByte; currentByte < height; currentByte += interlacePairPtr->incrementalByte )
{
- PixelBuffer* row = decodedData + currentByte * bytesPerRow;
+ unsigned char* row = decodedData + currentByte * bytesPerRow;
if ( DGifGetLine( gifInfo, row, width ) == GIF_ERROR )
{
DALI_LOG_ERROR( "GIF Loader: Error reading Interlaced GIF\n" );
else
{
// Non-interlace does not require any erratic reading / jumping.
- PixelBuffer* decodedDataPtr( decodedData );
+ unsigned char* decodedDataPtr( decodedData );
for ( unsigned int row = 0; row < height; ++row )
{
}
/// Called when we want to handle IMAGE_DESC_RECORD_TYPE
-bool HandleImageDescriptionRecordType( Bitmap& bitmap, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished )
+bool HandleImageDescriptionRecordType( Dali::Devel::PixelBuffer& bitmap, GifFileType* gifInfo, unsigned int width, unsigned int height, bool& finished )
{
if ( DGifGetImageDesc( gifInfo ) == GIF_ERROR )
{
return false;
}
+ Pixel::Format pixelFormat( Pixel::RGB888 );
+
SavedImage* image( &gifInfo->SavedImages[ gifInfo->ImageCount - 1 ] );
const GifImageDesc& desc( image->ImageDesc );
- // Create a buffer to store the decoded data.
- PixelBuffer* decodedData( new PixelBuffer[ width * height * sizeof( GifPixelType ) ] );
- AutoDeleteBuffer autoDeleteBuffer( decodedData );
+ auto decodedData = new unsigned char[ width * height * sizeof( GifPixelType ) ];
+
+ std::unique_ptr<unsigned char[]> ptr{ decodedData };
const unsigned int bytesPerRow( width * sizeof( GifPixelType ) );
const unsigned int actualWidth( desc.Width );
const unsigned int actualHeight( desc.Height );
+ // Create a buffer to store the decoded data.
+ bitmap = Dali::Devel::PixelBuffer::New( actualWidth, actualHeight, pixelFormat );
+
// Decode the GIF Image
if ( !DecodeImage( gifInfo, decodedData, actualWidth, actualHeight, bytesPerRow ) )
{
// If it's an animated GIF, we still only read the first image
// Create and populate pixel buffer.
-
- Pixel::Format pixelFormat( Pixel::RGB888 );
- PixelBuffer *pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, actualWidth, actualHeight );
-
+ auto pixels = bitmap.GetBuffer();
for (unsigned int row = 0; row < actualHeight; ++row)
{
for (unsigned int column = 0; column < actualWidth; ++column)
pixels += 3;
}
}
-
finished = true;
-
return true;
}
return LoadGifHeader(fp, width, height, &gifInfo);
}
-bool LoadBitmapFromGif( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromGif( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
{
FILE* const fp = input.file;
// Load the GIF Header file.
namespace Dali
{
-
-namespace Integration
+namespace Devel
{
- class Bitmap;
+class PixelBuffer;
}
+
namespace TizenPlatform
{
* @param[out] bitmap The bitmap class where the decoded image will be stored
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromGif( const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+bool LoadBitmapFromGif( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap );
/**
* Loads the header of a GIF file and fills in the width and height appropriately.
// INTERNAL INCLUDES
#include <dali/integration-api/debug.h>
-#include <dali/integration-api/bitmap.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
namespace Dali
{
-using Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
namespace TizenPlatform
{
return true;
}
-bool LoadBitmapFromIco( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromIco( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
{
IcoData chosen;
Dali::Vector<unsigned char> map;
int diff_size = 0;
unsigned int* pix;
- PixelBuffer* pixels = NULL;
size_t position = chosen.bmoffset;//22 == position
}
}
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, w, h );
+ bitmap = Dali::Devel::PixelBuffer::New(w, h, Pixel::Format::RGBA8888);
+ auto pixels = bitmap.GetBuffer();
memcpy( pixels, &surface[0], w * h * 4 );
return true;
namespace Dali
{
-
-namespace Integration
+namespace Devel
{
- class Bitmap;
+class PixelBuffer;
}
namespace TizenPlatform
* @param[out] bitmap The bitmap class where the decoded image will be stored
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromIco( const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+bool LoadBitmapFromIco( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap );
/**
* @param[in] input Information about the input image (including file pointer)
#include <cstring>
#include <setjmp.h>
-#include <dali/integration-api/bitmap.h>
+#include <dali/public-api/object/property-map.h>
+#include <dali/public-api/object/property-array.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
+
// INTERNAL HEADERS
#include "platform-capabilities.h"
#include "image-operations.h"
#include <image-loading.h>
+#include <adaptors/common/pixel-buffer-impl.h>
namespace
{
-using Dali::Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
using Dali::Vector;
namespace Pixel = Dali::Pixel;
-
-
+using PixelArray = unsigned char*;
const unsigned int DECODED_L8 = 1;
const unsigned int DECODED_RGB888 = 3;
const unsigned int DECODED_RGBA8888 = 4;
return UniquePointerSetter<T, Deleter>{uniquePointer};
}
-using TransformFunction = std::function<void(PixelBuffer*,unsigned, unsigned)>;
+using TransformFunction = std::function<void(PixelArray,unsigned, unsigned)>;
using TransformFunctionArray = std::array<TransformFunction, 3>; // 1, 3 and 4 bytes per pixel
/// @brief Select the transform function depending on the pixel format
return function;
}
+// Storing Exif fields as properties
+template<class R, class V>
+R ConvertExifNumeric( const ExifEntry& entry )
+{
+ return static_cast<R>((*reinterpret_cast<V*>(entry.data)));
+}
+
+void AddExifFieldPropertyMap( Dali::Property::Map& out, const ExifEntry& entry, ExifIfd ifd )
+{
+ auto shortName = std::string(exif_tag_get_name_in_ifd(entry.tag, ifd ));
+ switch( entry.format )
+ {
+ case EXIF_FORMAT_ASCII:
+ {
+ out.Insert( shortName, std::string(reinterpret_cast<char *>(entry.data)) );
+ break;
+ }
+ case EXIF_FORMAT_SHORT:
+ {
+ out.Insert( shortName, ConvertExifNumeric<int, unsigned int>(entry) );
+ break;
+ }
+ case EXIF_FORMAT_LONG:
+ {
+ out.Insert( shortName, ConvertExifNumeric<int, unsigned long>(entry) );
+ break;
+ }
+ case EXIF_FORMAT_SSHORT:
+ {
+ out.Insert( shortName, ConvertExifNumeric<int, int>(entry) );
+ break;
+ }
+ case EXIF_FORMAT_SLONG:
+ {
+ out.Insert( shortName, ConvertExifNumeric<int, long>(entry) );
+ break;
+ }
+ case EXIF_FORMAT_FLOAT:
+ {
+ out.Insert (shortName, ConvertExifNumeric<float, float>(entry) );
+ break;
+ }
+ case EXIF_FORMAT_DOUBLE:
+ {
+ out.Insert( shortName, ConvertExifNumeric<float, double>(entry) );
+ break;
+ }
+ case EXIF_FORMAT_RATIONAL:
+ {
+ auto values = reinterpret_cast<unsigned int*>( entry.data );
+ Dali::Property::Array array;
+ array.Add( static_cast<int>(values[0]) );
+ array.Add( static_cast<int>(values[1]) );
+ out.Insert(shortName, array);
+ break;
+ }
+ case EXIF_FORMAT_SBYTE:
+ {
+ out.Insert(shortName, "EXIF_FORMAT_SBYTE Unsupported");
+ break;
+ }
+ case EXIF_FORMAT_BYTE:
+ {
+ out.Insert(shortName, "EXIF_FORMAT_BYTE Unsupported");
+ break;
+ }
+ case EXIF_FORMAT_SRATIONAL:
+ {
+ auto values = reinterpret_cast<int*>( entry.data );
+ Dali::Property::Array array;
+ array.Add(values[0]);
+ array.Add(values[1]);
+ out.Insert(shortName, array);
+ break;
+ }
+ case EXIF_FORMAT_UNDEFINED:
+ default:
+ {
+ std::stringstream ss;
+ ss << "EXIF_FORMAT_UNDEFINED, size: " << entry.size << ", components: " << entry.components;
+ out.Insert( shortName, ss.str());
+ }
+ }
+}
+
/// @brief Apply a transform to a buffer
bool Transform(const TransformFunctionArray& transformFunctions,
- PixelBuffer *buffer,
+ PixelArray buffer,
int width,
int height,
Pixel::Format pixelFormat )
};
template<size_t N>
-void FlipVertical(PixelBuffer* buffer, int width, int height)
+void FlipVertical(PixelArray buffer, int width, int height)
{
// Destination pixel, set as the first pixel of screen
auto to = reinterpret_cast<PixelType<N>*>( buffer );
}
template<size_t N>
-void FlipHorizontal(PixelBuffer* buffer, int width, int height)
+void FlipHorizontal(PixelArray buffer, int width, int height)
{
for(auto iy = 0; iy < height; ++iy)
{
}
template<size_t N>
-void Transpose(PixelBuffer* buffer, int width, int height)
+void Transpose(PixelArray buffer, int width, int height)
{
//Transform vertically only
for(auto iy = 0; iy < height / 2; ++iy)
}
template<size_t N>
-void Transverse(PixelBuffer* buffer, int width, int height)
+void Transverse(PixelArray buffer, int width, int height)
{
using PixelT = PixelType<N>;
Vector<PixelT> data;
template<size_t N>
-void Rotate90(PixelBuffer* buffer, int width, int height)
+void Rotate90(PixelArray buffer, int width, int height)
{
using PixelT = PixelType<N>;
Vector<PixelT> data;
}
template<size_t N>
-void Rotate180(PixelBuffer* buffer, int width, int height)
+void Rotate180(PixelArray buffer, int width, int height)
{
using PixelT = PixelType<N>;
Vector<PixelT> data;
template<size_t N>
-void Rotate270(PixelBuffer* buffer, int width, int height)
+void Rotate270(PixelArray buffer, int width, int height)
{
using PixelT = PixelType<N>;
Vector<PixelT> data;
return true;
}
-bool LoadBitmapFromJpeg( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromJpeg( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
{
const int flags= 0;
FILE* const fp = input.file;
auto transform = JpegTransform::NONE;
- if( input.reorientationRequested )
+ // extract exif data
+ auto exifData = MakeExifDataFromData(jpegBufferPtr, jpegBufferSize);
+
+ if( exifData && input.reorientationRequested )
+ {
+ transform = ConvertExifOrientation(exifData.get());
+ }
+
+ std::unique_ptr<Property::Map> exifMap;
+ exifMap.reset( new Property::Map() );
+
+ for( auto k = 0u; k < EXIF_IFD_COUNT; ++k )
{
- auto exifData = MakeExifDataFromData(jpegBufferPtr, jpegBufferSize);
- if( exifData )
+ auto content = exifData->ifd[k];
+ for (auto i = 0u; i < content->count; ++i)
{
- transform = ConvertExifOrientation(exifData.get());
+ auto &&tag = content->entries[i];
+ const char *shortName = exif_tag_get_name_in_ifd(tag->tag, static_cast<ExifIfd>(k));
+ if(shortName)
+ {
+ AddExifFieldPropertyMap(*exifMap, *tag, static_cast<ExifIfd>(k));
+ }
}
}
}
#endif
// Allocate a bitmap and decompress the jpeg buffer into its pixel buffer:
- PixelBuffer* bitmapPixelBuffer = bitmap.GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, scaledPostXformWidth, scaledPostXformHeight ) ;
+ bitmap = Dali::Devel::PixelBuffer::New(scaledPostXformWidth, scaledPostXformHeight, pixelFormat);
+
+ // set metadata
+ GetImplementation(bitmap).SetMetadata( std::move(exifMap) );
+
+ auto bitmapPixelBuffer = bitmap.GetBuffer();
if( tjDecompress2( jpeg.get(), jpegBufferPtr, jpegBufferSize, reinterpret_cast<unsigned char*>( bitmapPixelBuffer ), scaledPreXformWidth, 0, scaledPreXformHeight, pixelLibJpegType, flags ) == -1 )
{
break;
}
}
+
return result;
}
namespace Dali
{
-
-namespace Integration
+namespace Devel
{
- class Bitmap;
+class PixelBuffer;
}
+
namespace TizenPlatform
{
* @param[out] bitmap The bitmap class where the decoded image will be stored
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromJpeg( const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+bool LoadBitmapFromJpeg( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap );
/**
* Loads the header of a JPEG file and fills in the width and height appropriately.
#include "loader-ktx.h"
// EXTERNAL INCLUDES
-#include <cstdio>
-#include <cstdlib>
#include <cstring>
-#include <stdint.h>
#include <dali/public-api/common/compile-time-assert.h>
#include <dali/integration-api/debug.h>
-#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/images/pixel.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
namespace Dali
{
-using Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
namespace TizenPlatform
{
}
// File loading API entry-point:
-bool LoadBitmapFromKtx( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromKtx( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
{
DALI_COMPILE_TIME_ASSERT( sizeof(Byte) == 1);
DALI_COMPILE_TIME_ASSERT( sizeof(uint32_t) == 4);
}
// Load up the image bytes:
- PixelBuffer* const pixels = bitmap.GetCompressedProfile()->ReserveBufferOfSize( pixelFormat, width, height, imageByteCount );
+ bitmap = Dali::Devel::PixelBuffer::New(width, height, pixelFormat);
+ auto pixels = bitmap.GetBuffer();
+
if(!pixels)
{
DALI_LOG_ERROR( "Unable to reserve a pixel buffer to load the requested bitmap into.\n" );
namespace Dali
{
-
-namespace Integration
+namespace Devel
{
- class Bitmap;
+class PixelBuffer;
}
namespace TizenPlatform
* @param[out] bitmap The bitmap class where the decoded image will be stored
* @return true if file loaded successfully, false otherwise
*/
-bool LoadBitmapFromKtx( const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+bool LoadBitmapFromKtx( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap );
/**
* Loads the header of a KTX file and fills in the width and height appropriately.
#include "loader-png.h"
#include <cstring>
-#include <cstdlib>
#include <zlib.h>
#include <png.h>
-#include <dali/integration-api/bitmap.h>
#include <dali/integration-api/debug.h>
#include <dali/public-api/images/image.h>
-#include "dali/public-api/math/math-utils.h"
-#include "dali/public-api/math/vector2.h"
#include "platform-capabilities.h"
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
namespace Dali
{
-
-using Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
-
namespace TizenPlatform
{
return success;
}
-bool LoadBitmapFromPng( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromPng( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
{
png_structp png = NULL;
png_infop info = NULL;
/// @todo: consider parameters
unsigned int y;
unsigned int width, height;
- unsigned char *pixels;
png_bytep *rows;
unsigned int bpp = 0; // bytes per pixel
bool valid = false;
}
// decode the whole image into bitmap buffer
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(pixelFormat, width, height, bufferWidth, bufferHeight);
+ auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(bufferWidth, bufferHeight, pixelFormat)).GetBuffer();
DALI_ASSERT_DEBUG(pixels);
rows = reinterpret_cast< png_bytep* >( malloc(sizeof(png_bytep) * height) );
namespace Dali
{
-
-namespace Integration
+namespace Devel
{
- class Bitmap;
+class PixelBuffer;
}
namespace TizenPlatform
* @param[out] bitmap The bitmap class where the decoded image will be stored
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromPng( const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+bool LoadBitmapFromPng( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap );
/**
* Loads the header of a PNG file and fills in the width and height appropriately.
// INTERNAL INCLUDES
#include <dali/integration-api/debug.h>
-#include <dali/integration-api/bitmap.h>
-#include <dali/public-api/common/dali-vector.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
namespace Dali
{
-using Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
+
namespace TizenPlatform
{
}// end unnamed namespace
-bool LoadBitmapFromWbmp( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromWbmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
{
FILE* const fp = input.file;
if(fp == NULL)
}
Dali::Vector<unsigned char> map;
Dali::Vector<unsigned char> surface;//unsigned int
- PixelBuffer* pixels = NULL;
size_t position = 0;
unsigned int w, h;
cur++;
}
}
- pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::L8, w, h);//Pixel::RGBA8888
+ auto pixels = (bitmap = Dali::Devel::PixelBuffer::New(w, h, Pixel::L8)).GetBuffer();
memcpy( pixels, &surface[0], w * h ); //w * h * 4
namespace Dali
{
-namespace Integration
+namespace Devel
{
- class Bitmap;
+class PixelBuffer;
}
namespace TizenPlatform
* @param[out] bitmap The bitmap class where the decoded image will be stored
* @return true if file decoded successfully, false otherwise
*/
-bool LoadBitmapFromWbmp( const ImageLoader::Input& input, Integration::Bitmap& bitmap );
+bool LoadBitmapFromWbmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap );
/**
* @param[in] input Information about the input image (including file pointer)
// INTERNAL INCLUDES
#include "image-loaders/image-loader.h"
#include "portable/file-reader.h"
+#include <adaptors/common/pixel-buffer-impl.h>
namespace Dali
{
Integration::BitmapPtr TizenPlatformAbstraction::DecodeBuffer( const Integration::BitmapResourceType& resource, uint8_t * buffer, size_t size )
{
- Integration::BitmapPtr bitmap = 0;
+ Integration::BitmapPtr resultBitmap;
+ Dali::Devel::PixelBuffer bitmap;
Dali::Internal::Platform::FileReader fileReader( buffer, size );
FILE * const fp = fileReader.GetFile();
bitmap.Reset();
DALI_LOG_WARNING( "Unable to decode bitmap supplied as in-memory blob.\n" );
}
+ else
+ {
+ Integration::Bitmap::Profile profile{Integration::Bitmap::Profile::BITMAP_2D_PACKED_PIXELS};
+
+ // For backward compatibility the Bitmap must be created
+ auto retval = Integration::Bitmap::New(profile, Dali::ResourcePolicy::OWNED_DISCARD);
+
+ 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());
+ resultBitmap.Reset(retval);
+ }
}
- return bitmap;
+ return resultBitmap;
}
bool TizenPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const