/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
FileFormat formatEncoding,
std::size_t width,
std::size_t height,
- Pixel::Format pixelFormat )
+ Pixel::Format pixelFormat,
+ const uint32_t quality )
{
switch( formatEncoding )
{
case JPG_FORMAT:
{
- return TizenPlatform::EncodeToJpeg( pixelBuffer, encodedPixels, width, height, pixelFormat );
+ return TizenPlatform::EncodeToJpeg( pixelBuffer, encodedPixels, width, height, pixelFormat, quality );
break;
}
case PNG_FORMAT:
const std::size_t width,
const std::size_t height )
{
+ return EncodeToFile( pixelBuffer, filename, pixelFormat, width, height, DEFAULT_JPG_QUALITY );
+}
+
+bool EncodeToFile(const unsigned char* const pixelBuffer,
+ const std::string& filename,
+ const Pixel::Format pixelFormat,
+ const std::size_t width,
+ const std::size_t height,
+ const uint32_t quality )
+{
DALI_ASSERT_DEBUG(pixelBuffer != 0 && filename.size() > 4 && width > 0 && height > 0);
Vector< unsigned char > pixbufEncoded;
const FileFormat format = GetFormatFromFileName( filename );
- const bool encodeResult = EncodeToFormat( pixelBuffer, pixbufEncoded, format, width, height, pixelFormat );
+ const bool encodeResult = EncodeToFormat( pixelBuffer, pixbufEncoded, format, width, height, pixelFormat, quality );
if(!encodeResult)
{
DALI_LOG_ERROR("Encoding pixels failed\n");
#define DALI_ADAPTOR_BITMAP_SAVER_H
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
namespace Dali
{
+static constexpr uint32_t DEFAULT_JPG_QUALITY = 100;
+
/**
* Store the given pixel data to a file.
* The suffix of the filename determines what type of file will be stored,
const std::size_t width,
const std::size_t height);
+/**
+ * Store the given pixel data to a file.
+ * The suffix of the filename determines what type of file will be stored,
+ * currently only jpeg and png formats are supported.
+ *
+ * @param[in] pixelBuffer Pointer to the pixel data
+ * @param[in] filename Filename to save
+ * @param[in] pixelFormat The format of the buffer's pixels
+ * @param[in] width The width of the image in pixels
+ * @param[in] height The height of the image in pixels
+ * @param[in] quality The value to control image quality for jpeg file format in the range [1, 100]
+ *
+ * @return true if the file was saved
+ */
+DALI_ADAPTOR_API bool EncodeToFile(const unsigned char* const pixelBuffer,
+ const std::string& filename,
+ const Pixel::Format pixelFormat,
+ const std::size_t width,
+ const std::size_t height,
+ const uint32_t quality);
+
} // namespace Dali
namespace DevelNativeImageSource\r
{\r
\r
+bool EncodeToFile( NativeImageSource& image, const std::string& filename, const uint32_t quality )\r
+{\r
+ return Dali::Internal::Adaptor::NativeImageSource::GetImplementation( image ).EncodeToFile( filename, quality );\r
+}\r
+\r
uint8_t* AcquireBuffer( NativeImageSource& image, uint16_t& width, uint16_t& height, uint16_t& stride )\r
{\r
return Dali::Internal::Adaptor::NativeImageSource::GetImplementation( image ).AcquireBuffer( width, height, stride );\r
{\r
\r
/**\r
+ * @brief Converts the current pixel contents to either a JPEG or PNG format\r
+ * and write that to the filesystem.\r
+ *\r
+ * @param[in] image The instance of NativeImageSource.\r
+ * @param[in] filename Identify the filesystem location at which to write the encoded image.\r
+ * The extension determines the encoding used.\r
+ * The two valid encoding are (".jpeg"|".jpg") and ".png".\r
+ * @param[in] quality The value to control image quality for jpeg file format in the range [1, 100]\r
+ * @return @c true if the pixels were written, and @c false otherwise\r
+ */\r
+DALI_ADAPTOR_API bool EncodeToFile( NativeImageSource& image, const std::string& filename, const uint32_t quality );\r
+\r
+/**\r
* @brief Acquire buffer and information of an internal native image.\r
*\r
* AcquireBuffer() and ReleaseBuffer() are a pair.\r
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
#include <dali/integration-api/adaptor-framework/render-surface-interface.h>
#include <dali/internal/graphics/common/egl-image-extensions.h>
#include <dali/internal/graphics/gles/egl-graphics.h>
return success;
}
-bool NativeImageSourceAndroid::EncodeToFile(const std::string& filename) const
-{
- std::vector< unsigned char > pixbuf;
- unsigned int width(0), height(0);
- Pixel::Format pixelFormat;
-
- if( GetPixels( pixbuf, width, height, pixelFormat ) )
- {
- return Dali::EncodeToFile( &pixbuf[0], filename, pixelFormat, width, height );
- }
- return false;
-}
-
void NativeImageSourceAndroid::SetSource( Any source )
{
if( mPixmap )
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const override;
/**
- * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
- */
- bool EncodeToFile(const std::string& filename) const override;
-
- /**
* @copydoc Dali::NativeImageSource::SetSource( Any source )
*/
void SetSource( Any source ) override;
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
// INTERNAL INCLUDES
#include <dali/public-api/adaptor-framework/native-image-source.h>
+#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
namespace Dali
{
{
public:
+ static constexpr uint32_t DEFAULT_QUALITY = 100;
+
/**
* Create a new NativeImageSource internally.
* Depending on hardware the width and height may have to be a power of two.
virtual bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const = 0;
/**
- * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
- */
- virtual bool EncodeToFile(const std::string& filename) const = 0;
-
- /**
* @copydoc Dali::NativeImageSource::SetSource( Any source )
*/
virtual void SetSource( Any source ) = 0;
*/
virtual bool ReleaseBuffer() = 0;
+ /**
+ * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
+ */
+ inline bool EncodeToFile( const std::string& filename ) const
+ {
+ return EncodeToFile( filename, DEFAULT_QUALITY );
+ }
+
+ /**
+ * @brief Converts the current pixel contents to either a JPEG or PNG format
+ * and write that to the filesystem.
+ *
+ * @param[in] filename Identify the filesystem location at which to write the encoded image.
+ * The extension determines the encoding used.
+ * The two valid encoding are (".jpeg"|".jpg") and ".png".
+ * @param[in] quality The quality of encoded jpeg image
+ * @return @c true if the pixels were written, and @c false otherwise
+ */
+ inline bool EncodeToFile( const std::string& filename, const uint32_t quality ) const
+ {
+ std::vector< uint8_t > pixbuf;
+ uint32_t width( 0 ), height( 0 );
+ Pixel::Format pixelFormat;
+
+ if( GetPixels( pixbuf, width, height, pixelFormat ) )
+ {
+ return Dali::EncodeToFile( &pixbuf[0], filename, pixelFormat, width, height, quality );
+ }
+ return false;
+ }
+
public:
inline static Internal::Adaptor::NativeImageSource& GetImplementation( Dali::NativeImageSource& image ) { return *image.mImpl; }
};
#include <dali/internal/adaptor/common/adaptor-impl.h>
#include <dali/integration-api/adaptor-framework/render-surface-interface.h>
-// Allow this to be encoded and saved:
-#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
-
namespace Dali
{
{
cOffset = c*4;
offset = cOffset + r*stride;
- *(bufptr+cOffset) = ptr[offset];
- *(bufptr+cOffset+1) = ptr[offset+3];
- *(bufptr+cOffset+2) = ptr[offset+2];
- *(bufptr+cOffset+3) = ptr[offset+1];
+ *(bufptr+cOffset) = ptr[offset+2];
+ *(bufptr+cOffset+1) = ptr[offset+1];
+ *(bufptr+cOffset+2) = ptr[offset];
+ *(bufptr+cOffset+3) = ptr[offset+3];
}
}
break;
return false;
}
-bool NativeImageSourceTizen::EncodeToFile(const std::string& filename) const
-{
- std::vector< unsigned char > pixbuf;
- unsigned int width(0), height(0);
- Pixel::Format pixelFormat;
-
- if(GetPixels(pixbuf, width, height, pixelFormat))
- {
- return Dali::EncodeToFile(&pixbuf[0], filename, pixelFormat, width, height);
- }
- return false;
-}
-
void NativeImageSourceTizen::SetSource( Any source )
{
Dali::Mutex::ScopedLock lock( mMutex );
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_IMPL_TIZEN_H
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
/**
* @copydoc Dali::NativeImageSource::GetPixels()
*/
- bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const override;
-
- /**
- * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
- */
- bool EncodeToFile(const std::string& filename) const override;
+ bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const override;
/**
* @copydoc Dali::NativeImageSource::SetSource( Any source )
#include <dali/internal/graphics/common/egl-image-extensions.h>
#include <dali/internal/graphics/gles/egl-graphics.h>
#include <dali/internal/adaptor/common/adaptor-impl.h>
-#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
#include <dali/integration-api/adaptor-framework/render-surface-interface.h>
namespace Dali
return success;
}
-bool NativeImageSourceX::EncodeToFile(const std::string& filename) const
-{
- std::vector< unsigned char > pixbuf;
- unsigned int width(0), height(0);
- Pixel::Format pixelFormat;
-
- if(GetPixels(pixbuf, width, height, pixelFormat))
- {
- return Dali::EncodeToFile(&pixbuf[0], filename, pixelFormat, width, height);
- }
- return false;
-}
-
void NativeImageSourceX::SetSource( Any source )
{
mPixmap = GetPixmapFromAny( source );
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
bool GetPixels(std::vector<unsigned char> &pixbuf, uint32_t &width, uint32_t &height, Pixel::Format& pixelFormat ) const override;
/**
- * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
- */
- bool EncodeToFile(const std::string& filename) const override;
-
- /**
* @copydoc Dali::NativeImageSource::SetSource( Any source )
*/
void SetSource( Any source ) override;
#include <dali/internal/graphics/gles/egl-graphics.h>
#include <dali/internal/adaptor/common/adaptor-impl.h>
#include <dali/internal/window-system/windows/platform-implement-win.h>
-#include <dali/devel-api/adaptor-framework/bitmap-saver.h>
#include <dali/integration-api/adaptor-framework/render-surface-interface.h>
namespace Dali
return success;
}
-bool NativeImageSourceWin::EncodeToFile(const std::string& filename) const
-{
- std::vector< uint8_t > pixbuf;
- uint32_t width(0), height(0);
- Pixel::Format pixelFormat;
-
- if(GetPixels(pixbuf, width, height, pixelFormat))
- {
- return Dali::EncodeToFile(&pixbuf[0], filename, pixelFormat, width, height);
- }
- return false;
-}
-
void NativeImageSourceWin::SetSource( Any source )
{
mPixmap = GetPixmapFromAny( source );
#define DALI_INTERNAL_NATIVE_IMAGE_SOURCE_H
/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
bool GetPixels(std::vector<unsigned char> &pixbuf, unsigned int &width, unsigned int &height, Pixel::Format& pixelFormat ) const override;
/**
- * @copydoc Dali::NativeImageSource::EncodeToFile(const std::string& )
- */
- bool EncodeToFile(const std::string& filename) const override;
-
- /**
* @copydoc Dali::NativeImageSource::SetSource( Any source )
*/
void SetSource( Any source ) override;
// INTERNAL INCLUDES
#include <dali/integration-api/adaptor-framework/adaptor.h>
+#include <dali/devel-api/adaptor-framework/native-image-source-devel.h>
namespace
{
{
Capture::Capture()
-: mTimer(),
+: mQuality( DEFAULT_QUALITY ),
+ mTimer(),
mPath(),
mNativeImageSourcePtr( NULL ),
mFileSave( false )
}
Capture::Capture( Dali::CameraActor cameraActor )
-: mCameraActor( cameraActor ),
+: mQuality( DEFAULT_QUALITY ),
+ mCameraActor( cameraActor ),
mTimer(),
mPath(),
mNativeImageSourcePtr( NULL ),
return pWorker;
}
+void Capture::Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor, const uint32_t quality )
+{
+ mQuality = quality;
+ Start( source, size, path, clearColor );
+}
+
void Capture::Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor )
{
DALI_ASSERT_ALWAYS(path.size() > 4 && "Path is invalid.");
{
DALI_ASSERT_ALWAYS(mNativeImageSourcePtr && "mNativeImageSourcePtr is NULL");
- return mNativeImageSourcePtr->EncodeToFile( mPath );
+ return Dali::DevelNativeImageSource::EncodeToFile( *mNativeImageSourcePtr, mPath, mQuality );
}
} // End of namespace Adaptor
class Capture : public BaseObject, public ConnectionTracker
{
public:
+
+ static constexpr uint32_t DEFAULT_QUALITY = 100;
+
/**
* @brief Constructor.
*/
/**
* @copydoc Dali::Capture::Start
*/
+ void Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor, const uint32_t quality );
+
+ /**
+ * @copydoc Dali::Capture::Start
+ */
void Start( Dali::Actor source, const Dali::Vector2& size, const std::string &path, const Dali::Vector4& clearColor );
/**
Capture& operator=( const Capture& rhs );
private:
+ uint32_t mQuality;
Dali::Texture mNativeTexture;
Dali::FrameBuffer mFrameBuffer;
Dali::RenderTask mRenderTask;
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
bool NativeImageSource::EncodeToFile(const std::string& filename) const
{
- return mImpl->EncodeToFile(filename);
+ return mImpl->EncodeToFile( filename );
}
void NativeImageSource::SetSource( Any source )
return *this;
}
+void Capture::Start( Actor source, const Vector2& size, const std::string &path, const Vector4& clearColor, const uint32_t quality )
+{
+ GetImpl( *this ).Start( source, size, path, clearColor, quality );
+}
+
void Capture::Start( Actor source, const Vector2& size, const std::string &path, const Vector4& clearColor )
{
GetImpl( *this ).Start( source, size, path, clearColor );
* @param[in] size captured size.
* @param[in] path image file path to be saved as a file.
* @param[in] clearColor background color of captured scene
+ * @param[in] quality The value to control image quality for jpeg file format in the range [1, 100]
+ */
+ void Start( Actor source, const Vector2& size, const std::string &path, const Vector4& clearColor, const uint32_t quality );
+
+ /**
+ * @brief Start capture and save the image as a file.
+ *
+ * @SINCE_1_9.10
+ *
+ * @param[in] source source actor to be used for capture.
+ * @param[in] size captured size.
+ * @param[in] path image file path to be saved as a file.
+ * @param[in] clearColor background color of captured scene
*/
void Start( Actor source, const Vector2& size, const std::string &path, const Vector4& clearColor );