From 8e2765be395b9e3860dc2bd9d433dac6ea1e63dc Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 3 Jul 2021 16:09:56 +0900 Subject: [PATCH] common picture: fix invalid size returns from raw image. picture/raw should update the size if the raw image with size values are entered. --- src/lib/tvgPictureImpl.h | 2 ++ src/loaders/raw/tvgRawLoader.cpp | 6 +++--- test/testPicture.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index b4e65f0e..82d17180 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -195,6 +195,8 @@ struct Picture::Impl if (loader) loader->close(); loader = LoaderMgr::loader(data, w, h, copy); if (!loader) return Result::NonSupport; + this->w = loader->w; + this->h = loader->h; return Result::Success; } diff --git a/src/loaders/raw/tvgRawLoader.cpp b/src/loaders/raw/tvgRawLoader.cpp index 47968d1c..2acfc3b5 100644 --- a/src/loaders/raw/tvgRawLoader.cpp +++ b/src/loaders/raw/tvgRawLoader.cpp @@ -45,10 +45,10 @@ bool RawLoader::open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) { if (!data || w == 0 || h == 0) return false; - vw = w; - vh = h; - + this->w = vw = w; + this->h = vh = h; this->copy = copy; + if (copy) { content = (uint32_t*)malloc(sizeof(uint32_t) * vw * vh); if (!content) return false; diff --git a/test/testPicture.cpp b/test/testPicture.cpp index a4eb2b3e..c4281f3f 100644 --- a/test/testPicture.cpp +++ b/test/testPicture.cpp @@ -63,7 +63,7 @@ TEST_CASE("Load SVG Data", "[tvgPicture]") REQUIRE(h == Approx(1000).epsilon(0.0000001)); } -TEST_CASE("Load Raw Data", "[tvgPicture]") +TEST_CASE("Load RAW Data", "[tvgPicture]") { auto picture = Picture::gen(); REQUIRE(picture);