From ce074ff6f53739ccc6b1da0e459cfe0af4a2615c Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 29 Nov 2017 21:02:06 +0000 Subject: [PATCH] Added Crop and Resize APIs to PixelBuffer Change-Id: I4861bd3b8172713870b4ad802dfe07a3003469a9 --- adaptors/common/pixel-buffer-impl.h | 41 ++++++++++++---------- .../devel-api/adaptor-framework/pixel-buffer.cpp | 10 ++++++ .../devel-api/adaptor-framework/pixel-buffer.h | 21 +++++++++++ 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/adaptors/common/pixel-buffer-impl.h b/adaptors/common/pixel-buffer-impl.h index 3484416..1882909 100644 --- a/adaptors/common/pixel-buffer-impl.h +++ b/adaptors/common/pixel-buffer-impl.h @@ -140,9 +140,11 @@ public: Dali::PixelData CreatePixelData() const; /** - * Apply the mask to the current buffer. This method may update the - * internal object - e.g. the new buffer may have a different pixel - * format - as an alpha channel may be added. + * @brief Apply the mask to the current buffer. + * + * This method may update the internal object - e.g. the new buffer + * may have a different pixel format - as an alpha channel may be + * added. * @param[in] mask The mask to apply to this pixel buffer * @param[in] contentScale The scaling factor to apply to the content * @param[in] cropToMask Whether to crop the output to the mask size (true) or scale the @@ -151,12 +153,28 @@ public: void ApplyMask( const PixelBuffer& mask, float contentScale, bool cropToMask ); /** - * Apply a Gaussian blur to the current buffer with the given radius. + * @brief Apply a Gaussian blur to the current buffer with the given radius. * * @param[in] blurRadius The radius for Gaussian blur */ void ApplyGaussianBlur( const float blurRadius ); + /** + * Crops this buffer to the given crop rectangle. Assumes the crop rectangle + * is within the bounds of this size. + * @param[in] x The top left corner's X + * @param[in] y The top left corner's y + * @param[in] cropDimensions The dimensions of the crop + */ + void Crop( uint16_t x, uint16_t y, ImageDimensions cropDimensions ); + + /** + * Resizes the buffer to the given dimensions. Uses either Lanczos4 for downscaling + * or Mitchell for upscaling + * @param[in] outDimensions The new dimensions + */ + void Resize( ImageDimensions outDimensions ); + private: /* * Undefined copy constructor. @@ -210,21 +228,6 @@ private: */ static PixelBufferPtr NewResize( const PixelBuffer& inBuffer, ImageDimensions outDimensions ); - /** - * Crops this buffer to the given crop rectangle. Assumes the crop rectangle - * is within the bounds of this size. - * @param[in] x The top left corner's X - * @param[in] y The top left corner's y - * @param[in] cropDimensions The dimensions of the crop - */ - void Crop( uint16_t x, uint16_t y, ImageDimensions cropDimensions ); - - /** - * Resizes the buffer to the given dimensions. Uses either Lanczos4 for downscaling - * or Mitchell for upscaling - * @param[in] outDimensions The new dimensions - */ - void Resize( ImageDimensions outDimensions ); private: diff --git a/adaptors/devel-api/adaptor-framework/pixel-buffer.cpp b/adaptors/devel-api/adaptor-framework/pixel-buffer.cpp index b767d49..d8245b1 100644 --- a/adaptors/devel-api/adaptor-framework/pixel-buffer.cpp +++ b/adaptors/devel-api/adaptor-framework/pixel-buffer.cpp @@ -106,6 +106,16 @@ void PixelBuffer::ApplyGaussianBlur( const float blurRadius ) GetImplementation(*this).ApplyGaussianBlur( blurRadius ); } +void PixelBuffer::Crop( uint16_t x, uint16_t y, uint16_t width, uint16_t height ) +{ + GetImplementation(*this).Crop( x, y, ImageDimensions( width, height ) ); +} + +void PixelBuffer::Resize( uint16_t width, uint16_t height ) +{ + GetImplementation(*this).Resize( ImageDimensions( width, height ) ); +} + } // namespace Devel } // namespace Dali diff --git a/adaptors/devel-api/adaptor-framework/pixel-buffer.h b/adaptors/devel-api/adaptor-framework/pixel-buffer.h index dfe228b..8a777bf 100644 --- a/adaptors/devel-api/adaptor-framework/pixel-buffer.h +++ b/adaptors/devel-api/adaptor-framework/pixel-buffer.h @@ -33,6 +33,7 @@ class PixelBuffer; } } + // Use namespace to separate from PixelBuffer typedef in buffer-image.h namespace Devel { @@ -179,6 +180,26 @@ public: */ void ApplyGaussianBlur( const float blurRadius ); + /** + * @brief Crops this buffer to the given crop rectangle. + * + * The crop rectangle will be clamped to the edges of the buffer if it is larger. + * @param[in] x The top left corner's X + * @param[in] y The top left corner's y + * @param[in] width The crop width + * @param[in] height The crop height + */ + void Crop( uint16_t x, uint16_t y, uint16_t width, uint16_t height ); + + /** + * @brief Resizes the buffer to the given dimensions. + * + * Uses either Lanczos4 for downscaling or Mitchell for upscaling + * @param[in] width The new width + * @param[in] height The new height + */ + void Resize( uint16_t width, uint16_t height ); + public: /** -- 2.7.4