mBufferSize = size;
}
-void PixelBuffer::Rotate( Degree angle )
+bool PixelBuffer::Rotate( Degree angle )
{
// Check first if Rotate() can perform the operation in the current pixel buffer.
{
// Can't rotate the pixel buffer with the current pixel format.
DALI_LOG_ERROR( "Can't rotate the pixel buffer with the current pixel format\n" );
- return;
+ return false;
}
float radians = Radian( angle ).radian;
if( radians < Dali::Math::MACHINE_EPSILON_10 )
{
// Nothing to do if the angle is zero.
- return;
+ return true;
}
const unsigned int pixelSize = Pixel::GetBytesPerPixel( mPixelFormat );
mWidth,
mHeight );
- // Release the memory of the current pixel buffer.
- ReleaseBuffer();
+ // Check whether the rotation succedded and set the new pixel buffer data.
+ const bool success = nullptr != pixelsOut;
- // Set the new pixel buffer.
- mBuffer = pixelsOut;
- pixelsOut = nullptr;
- mBufferSize = mWidth * mHeight * pixelSize;
+ if( success )
+ {
+ // Release the memory of the current pixel buffer.
+ ReleaseBuffer();
+
+ // Set the new pixel buffer.
+ mBuffer = pixelsOut;
+ pixelsOut = nullptr;
+ mBufferSize = mWidth * mHeight * pixelSize;
+ }
+
+ return success;
}
void PixelBuffer::ScaleAndCrop( float scaleFactor, ImageDimensions cropDimensions )
}
}
-
-
-
}// namespace Adaptor
}// namespace Internal
}// namespace Dali
#define DALI_PIXEL_BUFFER_H
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 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.
/**
* @brief Rotates the pixel buffer by the given angle.
*
- * @note Operation valid for pixel formats: A8, L8, LA88, RGB888, RGB8888, BGR8888, RGBA8888 and BGRA8888. Does nothing otherwise.
+ * @note Operation valid for pixel formats: A8, L8, LA88, RGB888, RGB8888, BGR8888, RGBA8888 and BGRA8888. Fails otherwise.
* @note The operation does nothing for angles equivalent to 0 degrees: -360, 360, 720, etc.
* @note If the pixel buffer does rotate, all the pointers to the internal pixel buffer retrieved by the method GetPixelBuffer() become invalid.
*
* @param[in] angle The angle in degrees.
+ *
+ * @return @e false if the rotation fails (invalid pixel format or memory issues).
*/
- void Rotate( Degree angle );
+ bool Rotate( Degree angle );
public:
#include <stddef.h>
#include <cmath>
#include <limits>
+#include <memory>
#include <dali/integration-api/debug.h>
#include <dali/public-api/common/dali-vector.h>
#include <dali/public-api/math/vector2.h>
return;
}
- const uint8_t* const firstHorizontalSkwePixelsIn = fastRotationPerformed ? pixelsOut : pixelsIn;
- uint8_t* tmpFirstHorizontalSkwePixelsIn = fastRotationPerformed ? pixelsOut : nullptr; // keep the pointer to free the memory.
+ const uint8_t* const firstHorizontalSkewPixelsIn = fastRotationPerformed ? pixelsOut : pixelsIn;
+ std::unique_ptr<uint8_t, void(*)(void*)> tmpPixelsInPtr( ( fastRotationPerformed ? pixelsOut : nullptr ), free );
// Reset the input/output
widthIn = widthOut;
if( nullptr == pixelsOut )
{
- // Free the memory allocated by the 'Fast Rotations'.
- free( tmpFirstHorizontalSkwePixelsIn );
-
widthOut = 0u;
heightOut = 0u;
+ // The deleter of the tmpPixelsInPtr unique pointer is called freeing the memory allocated by the 'Fast rotations'.
// Nothing else to do if the memory allocation fails.
return;
}
const float shear = angleTangent * ( ( angleTangent >= 0.f ) ? ( 0.5f + static_cast<float>( y ) ) : ( 0.5f + static_cast<float>( y ) - static_cast<float>( heightOut ) ) );
const int intShear = static_cast<int>( floor( shear ) );
- HorizontalSkew( firstHorizontalSkwePixelsIn, widthIn, pixelSize, pixelsOut, widthOut, y, intShear, shear - static_cast<float>( intShear ) );
+ HorizontalSkew( firstHorizontalSkewPixelsIn, widthIn, pixelSize, pixelsOut, widthOut, y, intShear, shear - static_cast<float>( intShear ) );
}
- // Free the memory allocated by the 'Fast Rotations'.
- free( tmpFirstHorizontalSkwePixelsIn );
-
- uint8_t* tmpPixelsIn = pixelsOut;
+ // Reset the 'pixel in' pointer with the output of the 'First Horizontal Skew' and free the memory allocated by the 'Fast Rotations'.
+ tmpPixelsInPtr.reset( pixelsOut );
unsigned int tmpWidthIn = widthOut;
unsigned int tmpHeightIn = heightOut;
if( nullptr == pixelsOut )
{
- // Free the memory allocated by the 'First Horizontal Skew'.
- free( tmpPixelsIn );
-
widthOut = 0u;
heightOut = 0u;
+ // The deleter of the tmpPixelsInPtr unique pointer is called freeing the memory allocated by the 'First Horizontal Skew'.
// Nothing else to do if the memory allocation fails.
return;
}
for( column = 0u; column < widthOut; ++column, offset -= angleSinus )
{
const int shear = static_cast<int>( floor( offset ) );
- VerticalSkew( tmpPixelsIn, tmpWidthIn, tmpHeightIn, pixelSize, pixelsOut, widthOut, heightOut, column, shear, offset - static_cast<float>( shear ) );
+ VerticalSkew( tmpPixelsInPtr.get(), tmpWidthIn, tmpHeightIn, pixelSize, pixelsOut, widthOut, heightOut, column, shear, offset - static_cast<float>( shear ) );
}
-
- // Free the memory allocated by the 'First Horizontal Skew'.
- free( tmpPixelsIn );
-
+ // Reset the 'pixel in' pointer with the output of the 'Vertical Skew' and free the memory allocated by the 'First Horizontal Skew'.
// Reset the input/output
- tmpPixelsIn = pixelsOut;
+ tmpPixelsInPtr.reset( pixelsOut );
tmpWidthIn = widthOut;
tmpHeightIn = heightOut;
pixelsOut = nullptr;
if( nullptr == pixelsOut )
{
- // Free the memory allocated by the 'Vertical Skew'.
- free( tmpPixelsIn );
-
widthOut = 0u;
heightOut = 0u;
+ // The deleter of the tmpPixelsInPtr unique pointer is called freeing the memory allocated by the 'Vertical Skew'.
// Nothing else to do if the memory allocation fails.
return;
}
for( unsigned int y = 0u; y < heightOut; ++y, offset += angleTangent )
{
const int shear = static_cast<int>( floor( offset ) );
- HorizontalSkew( tmpPixelsIn, tmpWidthIn, pixelSize, pixelsOut, widthOut, y, shear, offset - static_cast<float>( shear ) );
+ HorizontalSkew( tmpPixelsInPtr.get(), tmpWidthIn, pixelSize, pixelsOut, widthOut, y, shear, offset - static_cast<float>( shear ) );
}
- // Free the memory allocated by the 'Vertical Skew'.
- free( tmpPixelsIn );
-
+ // The deleter of the tmpPixelsInPtr unique pointer is called freeing the memory allocated by the 'Vertical Skew'.
// @note Allocated memory by the last 'Horizontal Skew' has to be freed by the caller to this function.
}