From c0cb8c0ce8faf215de81e10e56882f1d2ec0d24a Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Tue, 1 Aug 2023 11:04:52 +0900 Subject: [PATCH] apis: remove a beta api. - const uint32_t* Picture::data(uint32_t* w, uint32_t* h) const Returning pixel data is not guaranteed as the picture may contain vector resources. Remove it unless it's absolutely necessary. @Issue: https://github.com/thorvg/thorvg/issues/1372 --- inc/thorvg.h | 11 ----------- src/lib/tvgPicture.cpp | 17 ----------------- src/lib/tvgPictureImpl.h | 16 ++++++++++++++++ src/savers/tvg/tvgTvgSaver.cpp | 3 ++- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/inc/thorvg.h b/inc/thorvg.h index 7543efa6..d6afd92d 100644 --- a/inc/thorvg.h +++ b/inc/thorvg.h @@ -1307,17 +1307,6 @@ public: */ Result size(float* w, float* h) const noexcept; - /** - * @brief Gets the pixels information of the picture. - * - * @note The data must be pre-multiplied by the alpha channels. - * - * @warning Please do not use it, this API is not official one. It could be modified in the next version. - * - * @BETA_API - */ - const uint32_t* data(uint32_t* w, uint32_t* h) const noexcept; - /** * @brief Loads a raw data from a memory block with a given size. * diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index fd324a94..74c4b608 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -97,23 +97,6 @@ Result Picture::size(float* w, float* h) const noexcept } -const uint32_t* Picture::data(uint32_t* w, uint32_t* h) const noexcept -{ - //Try it, If not loaded yet. - pImpl->load(); - - if (pImpl->loader) { - if (w) *w = static_cast(pImpl->loader->w); - if (h) *h = static_cast(pImpl->loader->h); - } else { - if (w) *w = 0; - if (h) *h = 0; - } - if (pImpl->surface) return pImpl->surface->buf32; - else return nullptr; -} - - Result Picture::mesh(const Polygon* triangles, uint32_t triangleCnt) noexcept { if (!triangles && triangleCnt > 0) return Result::InvalidArguments; diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index 114c46f5..5c769033 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -318,6 +318,22 @@ struct Picture::Impl load(); return new PictureIterator(paint); } + + uint32_t* data(uint32_t* w, uint32_t* h) + { + //Try it, If not loaded yet. + load(); + + if (loader) { + if (w) *w = static_cast(loader->w); + if (h) *h = static_cast(loader->h); + } else { + if (w) *w = 0; + if (h) *h = 0; + } + if (surface) return surface->buf32; + else return nullptr; + } }; #endif //_TVG_PICTURE_IMPL_H_ diff --git a/src/savers/tvg/tvgTvgSaver.cpp b/src/savers/tvg/tvgTvgSaver.cpp index 0276e746..14a762d6 100644 --- a/src/savers/tvg/tvgTvgSaver.cpp +++ b/src/savers/tvg/tvgTvgSaver.cpp @@ -26,6 +26,7 @@ #include "tvgTvgSaver.h" #include "tvgLzw.h" #include "tvgShapeImpl.h" +#include "tvgPictureImpl.h" #ifdef _WIN32 #include @@ -607,7 +608,7 @@ TvgBinCounter TvgSaver::serializePicture(const Picture* picture, const Matrix* p //Case - Bitmap Image: uint32_t w, h; - auto pixels = picture->data(&w, &h); + auto pixels = P(picture)->data(&w, &h); if (!pixels) return 0; writeTag(TVG_TAG_CLASS_PICTURE);