Revert "loaders: Consider colorspaces (#838)"
authorHermet Park <chuneon.park@samsung.com>
Mon, 1 Nov 2021 07:53:25 +0000 (16:53 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Tue, 2 Nov 2021 00:41:05 +0000 (09:41 +0900)
This reverts commit cd5116b05315698ebc5e8592beb4753929dc2eed.

Ah this breaks the Stress example due to Picture::duplicate() is not available...

Need to consider and come back again.

22 files changed:
inc/thorvg.h
src/lib/gl_engine/tvgGlRenderer.cpp
src/lib/gl_engine/tvgGlRenderer.h
src/lib/sw_engine/tvgSwRenderer.cpp
src/lib/sw_engine/tvgSwRenderer.h
src/lib/tvgLoadModule.h
src/lib/tvgPictureImpl.h
src/lib/tvgRender.h
src/loaders/external_jpg/tvgJpgLoader.cpp
src/loaders/external_jpg/tvgJpgLoader.h
src/loaders/external_png/tvgPngLoader.cpp
src/loaders/external_png/tvgPngLoader.h
src/loaders/jpg/tvgJpgLoader.cpp
src/loaders/jpg/tvgJpgLoader.h
src/loaders/png/tvgPngLoader.cpp
src/loaders/png/tvgPngLoader.h
src/loaders/raw/tvgRawLoader.cpp
src/loaders/raw/tvgRawLoader.h
src/loaders/svg/tvgSvgLoader.cpp
src/loaders/svg/tvgSvgLoader.h
src/loaders/tvg/tvgTvgLoader.cpp
src/loaders/tvg/tvgTvgLoader.h

index dea2b2b..e5dcc66 100644 (file)
@@ -1099,6 +1099,7 @@ public:
      * @retval Result::Success When succeed.
      * @retval Result::InvalidArguments In case the @p path is invalid.
      * @retval Result::NonSupport When trying to load a file with an unknown extension.
+     * @retval Result::Unknown If an error occurs at a later stage.
      *
      * @note The Load behavior can be asynchronous if the assigned thread number is greater than zero.
      * @see Initializer::init()
@@ -1115,6 +1116,7 @@ public:
      * @retval Result::Success When succeed.
      * @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less.
      * @retval Result::NonSupport When trying to load a file with an unknown extension.
+     * @retval Result::Unknown If an error occurs at a later stage.
      *
      * @warning: you have responsibility to release the @p data memory if the @p copy is true
      * @deprecated Use load(const char* data, uint32_t size, const std::string& mimeType, bool copy) instead.
@@ -1133,6 +1135,7 @@ public:
      * @retval Result::Success When succeed.
      * @retval Result::InvalidArguments In case no data are provided or the @p size is zero or less.
      * @retval Result::NonSupport When trying to load a file with an unknown extension.
+     * @retval Result::Unknown If an error occurs at a later stage.
      *
      * @warning: It's the user responsibility to release the @p data memory if the @p copy is @c true.
      *
index 3e2ba18..e05bc61 100644 (file)
@@ -246,13 +246,6 @@ bool GlRenderer::viewport(TVG_UNUSED const RenderRegion& vp)
 }
 
 
-uint32_t GlRenderer::colorSpace()
-{
-    //TODO:
-    return 0;
-}
-
-
 int GlRenderer::init(uint32_t threads)
 {
     if ((initEngineCnt++) > 0) return true;
index 63e7514..0935284 100644 (file)
@@ -40,7 +40,6 @@ public:
     RenderRegion region(RenderData data) override;
     RenderRegion viewport() override;
     bool viewport(const RenderRegion& vp) override;
-    uint32_t colorSpace() override;
 
     bool target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h);
     bool sync() override;
index 3740d0d..8b3ec2c 100644 (file)
@@ -299,12 +299,6 @@ bool SwRenderer::target(uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t
 }
 
 
-uint32_t SwRenderer::colorSpace()
-{
-    return surface->cs;
-}
-
-
 bool SwRenderer::preRender()
 {
     return rasterClear(surface);
index 66550b7..51eed5d 100644 (file)
@@ -45,7 +45,6 @@ public:
     RenderRegion region(RenderData data) override;
     RenderRegion viewport() override;
     bool viewport(const RenderRegion& vp) override;
-    uint32_t colorSpace() override;
 
     bool clear() override;
     bool sync() override;
index 60ff01f..70b95b7 100644 (file)
@@ -47,7 +47,7 @@ public:
     //Override this if the vector-format has own resizing policy.
     virtual bool resize(Paint* paint, float w, float h) { return false; };
 
-    virtual bool read(uint32_t colorspace) = 0;
+    virtual bool read() = 0;
     virtual bool close() = 0;
     virtual const uint32_t* pixels() { return nullptr; };
     virtual unique_ptr<Paint> paint() { return nullptr; };
index a84184f..8a56f10 100644 (file)
@@ -66,7 +66,6 @@ struct Picture::Impl
     void* rdata = nullptr;            //engine data
     float w = 0, h = 0;
     bool resizing = false;
-    bool justloaded = false;
 
     Impl(Picture* p) : picture(p)
     {
@@ -91,7 +90,7 @@ struct Picture::Impl
 
     uint32_t reload()
     {
-        if (loader && !justloaded) {
+        if (loader) {
             if (!paint) {
                 if (auto p = loader->paint()) {
                     paint = p.release();
@@ -128,14 +127,6 @@ struct Picture::Impl
 
     void* update(RenderMethod &renderer, const RenderTransform* pTransform, uint32_t opacity, Array<RenderData>& clips, RenderUpdateFlag pFlag)
     {
-        if (loader && justloaded) {
-            justloaded = false;
-            if (!loader->read(renderer.colorSpace())) {
-                TVGERR("Picture", "Loader read failure!");
-                return nullptr;
-            }
-        }
-
         auto flag = reload();
 
         if (pixels) {
@@ -203,9 +194,9 @@ struct Picture::Impl
             if (invalid) return Result::InvalidArguments;
             return Result::NonSupport;
         }
+        if (!loader->read()) return Result::Unknown;
         w = loader->w;
         h = loader->h;
-        justloaded = true;
         return Result::Success;
     }
 
@@ -215,9 +206,9 @@ struct Picture::Impl
         if (loader) loader->close();
         loader = LoaderMgr::loader(data, size, mimeType, copy);
         if (!loader) return Result::NonSupport;
+        if (!loader->read()) return Result::Unknown;
         w = loader->w;
         h = loader->h;
-        justloaded = true;
         return Result::Success;
     }
 
@@ -229,7 +220,6 @@ struct Picture::Impl
         if (!loader) return Result::NonSupport;
         this->w = loader->w;
         this->h = loader->h;
-        justloaded = true;
         return Result::Success;
     }
 
index 3d841b6..b45405a 100644 (file)
@@ -100,8 +100,6 @@ public:
     virtual Compositor* target(const RenderRegion& region) = 0;
     virtual bool beginComposite(Compositor* cmp, CompositeMethod method, uint32_t opacity) = 0;
     virtual bool endComposite(Compositor* cmp) = 0;
-
-    virtual uint32_t colorSpace() = 0;
 };
 
 }
index 8fd9e7e..76ccdde 100644 (file)
@@ -124,15 +124,14 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
 }
 
 
-bool JpgLoader::read(uint32_t colorspace)
+bool JpgLoader::read()
 {
     if (image) tjFree(image);
     image = (unsigned char *)tjAlloc(static_cast<int>(w) * static_cast<int>(h) * tjPixelSize[TJPF_BGRX]);
     if (!image) return false;
 
     //decompress jpg image
-    auto pixelFormat = (colorspace == tvg::SwCanvas::ABGR8888) ? TJPF_RGBX : TJPF_BGRX;
-    if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), pixelFormat, 0) < 0) {
+    if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), TJPF_BGRX, 0) < 0) {
         TVGERR("JPG LOADER", "%s", tjGetErrorStr());
         tjFree(image);
         image = nullptr;
index 03dbae5..1aeaa04 100644 (file)
@@ -34,7 +34,7 @@ public:
     using LoadModule::open;
     bool open(const string& path) override;
     bool open(const char* data, uint32_t size, bool copy) override;
-    bool read(uint32_t colorspace) override;
+    bool read() override;
     bool close() override;
 
     const uint32_t* pixels() override;
index c663d8d..faafc62 100644 (file)
  * SOFTWARE.
  */
 
-#include <memory.h>
 #include "tvgLoader.h"
 #include "tvgPngLoader.h"
 
-
-/************************************************************************/
-/* Internal Class Implementation                                        */
-/************************************************************************/
-
-void PngLoader::clear()
-{
-    if (freeData) free(data);
-    data = nullptr;
-    freeData = false;
-}
-
-
-/************************************************************************/
-/* External Class Implementation                                        */
-/************************************************************************/
-
 PngLoader::PngLoader()
 {
     image = static_cast<png_imagep>(calloc(1, sizeof(png_image)));
@@ -50,9 +32,6 @@ PngLoader::PngLoader()
 
 PngLoader::~PngLoader()
 {
-    if (freeData) free(data);
-    data = nullptr;
-
     if (content) {
         free((void*)content);
         content = nullptr;
@@ -62,7 +41,6 @@ PngLoader::~PngLoader()
 
 bool PngLoader::open(const string& path)
 {
-    clear();
     image->opaque = NULL;
 
     if (!png_image_begin_read_from_file(image, path.c_str())) return false;
@@ -75,19 +53,9 @@ bool PngLoader::open(const string& path)
 
 bool PngLoader::open(const char* data, uint32_t size, bool copy)
 {
-    clear();
     image->opaque = NULL;
 
-    if (copy) {
-        this->data = (char *) malloc(size);
-        if (!this->data) return false;
-        memcpy(this->data, data, size);
-        freeData = true;
-    } else {
-        this->data = (char *) data;
-    }
-
-    if (!png_image_begin_read_from_memory(image, this->data, size)) return false;
+    if (!png_image_begin_read_from_memory(image, data, size)) return false;
 
     w = (float)image->width;
     h = (float)image->height;
@@ -95,10 +63,10 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy)
     return true;
 }
 
-bool PngLoader::read(uint32_t colorspace)
+bool PngLoader::read()
 {
     png_bytep buffer;
-    image->format = (colorspace == tvg::SwCanvas::ABGR8888) ? PNG_FORMAT_RGBA : PNG_FORMAT_BGRA;
+    image->format = PNG_FORMAT_BGRA;
     buffer = static_cast<png_bytep>(malloc(PNG_IMAGE_SIZE((*image))));
     if (!buffer) {
         //out of memory, only time when libpng doesnt free its data
index d36a06f..ab2c816 100644 (file)
@@ -33,16 +33,12 @@ public:
     using LoadModule::open;
     bool open(const string& path) override;
     bool open(const char* data, uint32_t size, bool copy) override;
-    bool read(uint32_t colorspace) override;
+    bool read() override;
     bool close() override;
 
     const uint32_t* pixels() override;
 
 private:
-    void clear();
-
-    char* data = nullptr;
-    bool freeData = false;
     png_imagep image = nullptr;
     const uint32_t* content = nullptr;
 };
index 8e87599..599d2fe 100644 (file)
@@ -90,7 +90,8 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
 }
 
 
-bool JpgLoader::read(uint32_t colorspace)
+
+bool JpgLoader::read()
 {
     if (!decoder || w <= 0 || h <= 0) return false;
 
index e69d287..e7ec3ab 100644 (file)
@@ -41,7 +41,7 @@ public:
     using LoadModule::open;
     bool open(const string& path) override;
     bool open(const char* data, uint32_t size, bool copy) override;
-    bool read(uint32_t colorspace) override;
+    bool read() override;
     bool close() override;
 
     const uint32_t* pixels() override;
index f7d690a..e50f34e 100644 (file)
@@ -123,7 +123,7 @@ bool PngLoader::open(const char* data, uint32_t size, bool copy)
 }
 
 
-bool PngLoader::read(uint32_t colorspace)
+bool PngLoader::read()
 {
     if (!data || w <= 0 || h <= 0) return false;
 
index 864751f..fa1860c 100644 (file)
@@ -44,7 +44,7 @@ public:
     using LoadModule::open;
     bool open(const string& path) override;
     bool open(const char* data, uint32_t size, bool copy) override;
-    bool read(uint32_t colorspace) override;
+    bool read() override;
     bool close() override;
 
     const uint32_t* pixels() override;
index 5b9caab..a38dc5e 100644 (file)
@@ -60,9 +60,8 @@ bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, bool copy)
 }
 
 
-bool RawLoader::read(uint32_t colorspace)
+bool RawLoader::read()
 {
-    //NOTE: raw data is used "as it is"- developer must take care of it so the same color space used
     return true;
 }
 
index 4abd4c7..f6eed20 100644 (file)
@@ -32,7 +32,7 @@ public:
 
     using LoadModule::open;
     bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) override;
-    bool read(uint32_t colorspace) override;
+    bool read() override;
     bool close() override;
 
     const uint32_t* pixels() override;
index f142cfd..3ca7bdb 100644 (file)
@@ -2927,7 +2927,7 @@ bool SvgLoader::resize(Paint* paint, float w, float h)
 }
 
 
-bool SvgLoader::read(uint32_t colorspace)
+bool SvgLoader::read()
 {
     if (!content || size == 0) return false;
 
index 104dff8..468f058 100644 (file)
@@ -45,7 +45,7 @@ public:
     bool open(const string& path) override;
     bool open(const char* data, uint32_t size, bool copy) override;
     bool resize(Paint* paint, float w, float h) override;
-    bool read(uint32_t colorspace) override;
+    bool read() override;
     bool close() override;
     unique_ptr<Paint> paint() override;
 
index deb5440..d7f3184 100644 (file)
@@ -188,7 +188,7 @@ bool TvgLoader::resize(Paint* paint, float w, float h)
 }
 
 
-bool TvgLoader::read(uint32_t colorspace)
+bool TvgLoader::read()
 {
     if (!ptr || size == 0) return false;
 
index f7cbc47..d276ded 100644 (file)
@@ -47,7 +47,7 @@ public:
     using LoadModule::open;
     bool open(const string &path) override;
     bool open(const char *data, uint32_t size, bool copy) override;
-    bool read(uint32_t colorspace) override;
+    bool read() override;
     bool close() override;
     bool resize(Paint* paint, float w, float h) override;
     unique_ptr<Paint> paint() override;