Set the image type of encoded image buffer 96/300596/3
authorEunki Hong <eunkiki.hong@samsung.com>
Sat, 28 Oct 2023 14:55:47 +0000 (23:55 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Sun, 29 Oct 2023 13:03:57 +0000 (22:03 +0900)
Let we prepare to support EncodedImageBuffer
as VectorImage / VectorAnimatedImage.

Change-Id: I062d7153291a10a81d48d5c250c113574a083a73
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-adaptor/utc-Dali-EncodedImageBuffer.cpp
dali/internal/imaging/common/encoded-image-buffer-impl.cpp
dali/internal/imaging/common/encoded-image-buffer-impl.h
dali/public-api/adaptor-framework/encoded-image-buffer.cpp
dali/public-api/adaptor-framework/encoded-image-buffer.h

index 5b2da93bac0303926bbc8c4b53bd3f6fdea33371..82bbfac327e6be9f5fe26d3518754bdbccc36ce8 100644 (file)
@@ -46,7 +46,7 @@ void dali_encoded_image_buffer_cleanup(void)
   test_return_value = TET_PASS;
 }
 
-int UtcDaliEncodedImageBufferNew(void)
+int UtcDaliEncodedImageBufferNew01(void)
 {
   // invoke default handle constructor
   EncodedImageBuffer buffer;
@@ -60,6 +60,20 @@ int UtcDaliEncodedImageBufferNew(void)
   END_TEST;
 }
 
+int UtcDaliEncodedImageBufferNew02(void)
+{
+  // invoke default handle constructor
+  EncodedImageBuffer buffer;
+
+  DALI_TEST_CHECK(!buffer);
+
+  // initialise handle
+  buffer = EncodedImageBuffer::New(tinybuffer(), Dali::EncodedImageBuffer::ImageType::VECTOR_IMAGE);
+
+  DALI_TEST_CHECK(buffer);
+  END_TEST;
+}
+
 int UtcDaliEncodedImageBufferCopyConstructor(void)
 {
   EncodedImageBuffer buffer = EncodedImageBuffer::New(tinybuffer());
@@ -142,5 +156,32 @@ int UtcDaliEncodedImageBufferGetHash(void)
   DALI_TEST_CHECK(buffer1.GetHash() != buffer3.GetHash());
   DALI_TEST_CHECK(buffer2.GetHash() != buffer3.GetHash());
 
+  END_TEST;
+}
+
+
+int UtcDaliEncodedImageBufferSetGetType(void)
+{
+  EncodedImageBuffer buffer1 = EncodedImageBuffer::New(tinybuffer());
+  EncodedImageBuffer buffer2 = buffer1; ///< Copy handle
+
+  DALI_TEST_CHECK(buffer1);
+  DALI_TEST_CHECK(buffer2);
+  DALI_TEST_CHECK(buffer1 == buffer2);
+  DALI_TEST_CHECK(buffer1.GetHash() == buffer2.GetHash());
+
+  DALI_TEST_EQUALS(buffer1.GetImageType(), Dali::EncodedImageBuffer::ImageType::DEFAULT, TEST_LOCATION);
+  DALI_TEST_EQUALS(buffer2.GetImageType(), Dali::EncodedImageBuffer::ImageType::DEFAULT, TEST_LOCATION);
+
+  buffer1.SetImageType(Dali::EncodedImageBuffer::ImageType::VECTOR_IMAGE);
+
+  DALI_TEST_EQUALS(buffer1.GetImageType(), Dali::EncodedImageBuffer::ImageType::VECTOR_IMAGE, TEST_LOCATION);
+  DALI_TEST_EQUALS(buffer2.GetImageType(), Dali::EncodedImageBuffer::ImageType::VECTOR_IMAGE, TEST_LOCATION);
+
+  buffer2.SetImageType(Dali::EncodedImageBuffer::ImageType::ANIMATED_VECTOR_IMAGE);
+
+  DALI_TEST_EQUALS(buffer1.GetImageType(), Dali::EncodedImageBuffer::ImageType::ANIMATED_VECTOR_IMAGE, TEST_LOCATION);
+  DALI_TEST_EQUALS(buffer2.GetImageType(), Dali::EncodedImageBuffer::ImageType::ANIMATED_VECTOR_IMAGE, TEST_LOCATION);
+
   END_TEST;
 }
\ No newline at end of file
index 2f1a799c5c9998962c100ed8b7858f2a73c2cf12..33c93d3ef7970c6afe4d1f37ffaa481a24d71193 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 // CLASS HEADER
-#include "encoded-image-buffer-impl.h"
+#include <dali/internal/imaging/common/encoded-image-buffer-impl.h>
 
 // EXTERNAL INCLUDE
 #include <dali/devel-api/common/hash.h>
@@ -25,8 +25,9 @@ namespace Dali
 {
 namespace Internal
 {
-EncodedImageBuffer::EncodedImageBuffer(const RawBufferType& buffer)
-: mBuffer(buffer)
+EncodedImageBuffer::EncodedImageBuffer(const RawBufferType& buffer, ImageType type)
+: mBuffer(buffer),
+  mType(type)
 {
   mBufferHash = CalculateHash(mBuffer);
 }
@@ -35,9 +36,9 @@ EncodedImageBuffer::~EncodedImageBuffer()
 {
 }
 
-IntrusivePtr<EncodedImageBuffer> EncodedImageBuffer::New(const RawBufferType& buffer)
+IntrusivePtr<EncodedImageBuffer> EncodedImageBuffer::New(const RawBufferType& buffer, ImageType type)
 {
-  IntrusivePtr<EncodedImageBuffer> internal = new EncodedImageBuffer(buffer);
+  IntrusivePtr<EncodedImageBuffer> internal = new EncodedImageBuffer(buffer, type);
 
   return internal;
 }
@@ -47,11 +48,21 @@ const EncodedImageBuffer::RawBufferType& EncodedImageBuffer::GetRawBuffer() cons
   return mBuffer;
 }
 
-const std::size_t EncodedImageBuffer::GetHash() const
+std::size_t EncodedImageBuffer::GetHash() const
 {
   return mBufferHash;
 }
 
+void EncodedImageBuffer::SetImageType(Dali::EncodedImageBuffer::ImageType type)
+{
+  mType = type;
+}
+
+Dali::EncodedImageBuffer::ImageType EncodedImageBuffer::GetImageType() const
+{
+  return mType;
+}
+
 } // namespace Internal
 
 } // namespace Dali
index 2c8e924936ebbbf61ed1f156ec5bc6f1bbeb0a31..f4823258bd88a253a977193c4880711a7fa5d236 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_ENCODED_IMAGE_BUFFER_IMPL_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -34,17 +34,19 @@ class EncodedImageBuffer : public BaseObject
 {
 public:
   using RawBufferType = Dali::EncodedImageBuffer::RawBufferType;
+  using ImageType     = Dali::EncodedImageBuffer::ImageType;
 
   /**
    * Constructor
-   * @param [in] buffer The raw buffer of image.
+   * @param[in] buffer The raw buffer of image.
+   * @param[in] type The type of image.
    */
-  EncodedImageBuffer(const RawBufferType& buffer);
+  EncodedImageBuffer(const RawBufferType& buffer, ImageType type);
 
   /**
    * @copydoc Dali::EncodedImageBuffer::New
    */
-  static IntrusivePtr<EncodedImageBuffer> New(const RawBufferType& buffer);
+  static IntrusivePtr<EncodedImageBuffer> New(const RawBufferType& buffer, ImageType type);
 
   /**
    * @copydoc Dali::EncodedImageBuffer::GetRawBuffer
@@ -54,7 +56,17 @@ public:
   /**
    * @copydoc Dali::EncodedImageBuffer::GetHash
    */
-  const std::size_t GetHash() const;
+  std::size_t GetHash() const;
+
+  /**
+   * @copydoc Dali::EncodedImageBuffer::SetImageType
+   */
+  void SetImageType(ImageType type);
+
+  /**
+   * @copydoc Dali::EncodedImageBuffer::GetImageType
+   */
+  ImageType GetImageType() const;
 
 protected:
   /**
@@ -72,6 +84,7 @@ private:
 private:
   Dali::Vector<uint8_t> mBuffer;
   std::size_t           mBufferHash;
+  ImageType             mType;
 };
 
 } // namespace Internal
index 713f4c93e6305ace5c8a7c8ce3bc993b266fb023..7710ce1a5ec1bda519ef6723cfe4789e28a26df9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -49,14 +49,29 @@ const EncodedImageBuffer::RawBufferType& EncodedImageBuffer::GetRawBuffer() cons
   return GetImplementation(*this).GetRawBuffer();
 }
 
-const std::size_t EncodedImageBuffer::GetHash() const
+std::size_t EncodedImageBuffer::GetHash() const
 {
   return GetImplementation(*this).GetHash();
 }
 
+void EncodedImageBuffer::SetImageType(ImageType type)
+{
+  GetImplementation(*this).SetImageType(type);
+}
+
+EncodedImageBuffer::ImageType EncodedImageBuffer::GetImageType() const
+{
+  return GetImplementation(*this).GetImageType();
+}
+
 EncodedImageBuffer EncodedImageBuffer::New(const RawBufferType& buffer)
 {
-  IntrusivePtr<Internal::EncodedImageBuffer> internal = Internal::EncodedImageBuffer::New(buffer);
+  return EncodedImageBuffer::New(buffer, ImageType::DEFAULT);
+}
+
+EncodedImageBuffer EncodedImageBuffer::New(const RawBufferType& buffer, ImageType type)
+{
+  IntrusivePtr<Internal::EncodedImageBuffer> internal = Internal::EncodedImageBuffer::New(buffer, type);
   return EncodedImageBuffer(internal.Get());
 }
 
index 71e5c8bab952868e328b02ce90e12bb23f49c20b..31bec4404346c901cf818818dcea53fc0a2b7579 100644 (file)
@@ -42,9 +42,23 @@ class DALI_ADAPTOR_API EncodedImageBuffer : public BaseHandle
 public:
   using RawBufferType = Dali::Vector<uint8_t>;
 
+  /**
+   * @brief The list of type of encoded image buffer.
+   *
+   * @SINCE_2_2.51
+   */
+  enum class ImageType
+  {
+    REGULAR_IMAGE,
+    VECTOR_IMAGE, ///< svg format.
+    ANIMATED_VECTOR_IMAGE, ///< lottie format.
+
+    DEFAULT = REGULAR_IMAGE,
+  };
+
 public:
   /**
-   * @brief Create a new EncodedImageBuffer.
+   * @brief Create a new EncodedImageBuffer. ImageType will be setted as DEFAULT.
    *
    * @SINCE_2_0.34
    * @param [in] buffer The encoded raw buffer
@@ -52,6 +66,16 @@ public:
    */
   static EncodedImageBuffer New(const RawBufferType& buffer);
 
+  /**
+   * @brief Create a new EncodedImageBuffer with ImageType.
+   *
+   * @SINCE_2_2.51
+   * @param [in] buffer The encoded raw buffer
+   * @param [in] type The type hint of encoded raw buffer
+   * @return A handle to a new EncodedImageBuffer.
+   */
+  static EncodedImageBuffer New(const RawBufferType& buffer, ImageType type);
+
   /**
    * @brief Create an empty handle.
    *
@@ -117,7 +141,23 @@ public:
    * @SINCE_2_1.20
    * @return A hash value of raw buffer.
    */
-  const std::size_t GetHash() const;
+  std::size_t GetHash() const;
+
+  /**
+   * @brief Set type of raw buffer.
+   *
+   * @SINCE_2_2.51
+   * @param[in] type A ImageType for this buffer
+   */
+  void SetImageType(ImageType type);
+
+  /**
+   * @brief Get type of raw buffer.
+   *
+   * @SINCE_2_2.51
+   * @return A ImageType this buffer have
+   */
+  ImageType GetImageType() const;
 
 public: // Not intended for developer use
   explicit DALI_INTERNAL EncodedImageBuffer(Internal::EncodedImageBuffer* impl);