From 4fbfc1a4ff5e7221a21be19a85c188fb43039c41 Mon Sep 17 00:00:00 2001 From: h3r3x3 Date: Mon, 24 Jan 2022 14:07:39 +0800 Subject: [PATCH 1/4] fix webp encode premultiplied image bug. --- tgfx/src/image/webp/WebpImage.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tgfx/src/image/webp/WebpImage.cpp b/tgfx/src/image/webp/WebpImage.cpp index 15db8fe6b8..c18af534c6 100644 --- a/tgfx/src/image/webp/WebpImage.cpp +++ b/tgfx/src/image/webp/WebpImage.cpp @@ -134,14 +134,16 @@ static int webp_reader_write_data(const uint8_t* data, size_t data_size, std::shared_ptr WebpImage::Encode(const ImageInfo& imageInfo, const void* pixels, EncodedFormat, int quality) { - if (imageInfo.colorType() == ColorType::ALPHA_8) return nullptr; + if (imageInfo.colorType() == ColorType::ALPHA_8) { + return nullptr; + } const uint8_t* srcPixels = static_cast(const_cast(pixels)); const uint8_t* convertPixels = nullptr; - if (imageInfo.colorType() == ColorType::ALPHA_8) { + if (imageInfo.alphaType() == AlphaType::Premultiplied) { PixelMap pixelMap(imageInfo, srcPixels); auto dstPixels = new uint8_t[imageInfo.byteSize()]; - auto dstInfo = ImageInfo::Make(imageInfo.width(), imageInfo.height(), ColorType::RGBA_8888, - AlphaType::Opaque); + auto dstInfo = ImageInfo::Make(imageInfo.width(), imageInfo.height(), imageInfo.colorType(), + AlphaType::Unpremultiplied); if (!pixelMap.readPixels(dstInfo, dstPixels)) { delete[] dstPixels; return nullptr; From f8fa9c913635a91c778da5edecbd818c73b39324 Mon Sep 17 00:00:00 2001 From: h3r3x3 Date: Thu, 27 Jan 2022 17:02:45 +0800 Subject: [PATCH 2/4] Add Alpha8 colorType suppport for Webp encoding --- test/PAGReadPixelsTest.cpp | 39 ++++++++++++------- .../JpegCodec_Decode.webp.lzma2 | 3 ++ .../PngCodec_Decode.webp.lzma2 | 3 ++ .../WebpCodec_Decode.webp.lzma2 | 3 ++ .../WebpCodec_EncodeA8.webp.lzma2 | 3 ++ tgfx/src/image/webp/WebpImage.cpp | 19 +++++---- 6 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 test/baseline/PAGReadPixelsTest/JpegCodec_Decode.webp.lzma2 create mode 100644 test/baseline/PAGReadPixelsTest/PngCodec_Decode.webp.lzma2 create mode 100644 test/baseline/PAGReadPixelsTest/WebpCodec_Decode.webp.lzma2 create mode 100644 test/baseline/PAGReadPixelsTest/WebpCodec_EncodeA8.webp.lzma2 diff --git a/test/PAGReadPixelsTest.cpp b/test/PAGReadPixelsTest.cpp index e5e4d50fe4..900d1fed2a 100644 --- a/test/PAGReadPixelsTest.cpp +++ b/test/PAGReadPixelsTest.cpp @@ -29,10 +29,10 @@ namespace pag { using nlohmann::json; -#define CHECK_PIXELS(info, pixels, key) \ - { \ - PixelMap pm(info, pixels); \ - Baseline::Compare(pm, "PAGReadPixelsTest/" + std::string(key) + ".webp"); \ +#define CHECK_PIXELS(info, pixels, key) \ + { \ + PixelMap pm(info, pixels); \ + EXPECT_TRUE(Baseline::Compare(pm, "PAGReadPixelsTest/" + std::string(key) + ".webp")); \ } /** @@ -261,8 +261,10 @@ PAG_TEST(PAGReadPixelsTest, PngCodec) { auto rowBytes = image->width() * 4; auto pixels = new (std::nothrow) uint8_t[rowBytes * image->height()]; ASSERT_TRUE(pixels); - auto info = ImageInfo::Make(1280, 720, ColorType::RGBA_8888, AlphaType::Premultiplied); + auto info = ImageInfo::Make(image->width(), image->height(), ColorType::RGBA_8888, + AlphaType::Premultiplied); ASSERT_TRUE(image->readPixels(info, pixels)); + CHECK_PIXELS(info, pixels, "PngCodec_Decode"); PixelMap pixelMap(info, pixels); auto bytes = Image::Encode(pixelMap.info(), pixelMap.pixels(), EncodedFormat::PNG, 100); image = Image::MakeFrom(bytes); @@ -282,20 +284,29 @@ PAG_TEST(PAGReadPixelsTest, WebpCodec) { ASSERT_EQ(image->width(), 110); ASSERT_EQ(image->height(), 110); ASSERT_EQ(static_cast(image->orientation()), static_cast(Orientation::TopLeft)); - auto rowBytes = image->width() * 4; - auto pixels = new (std::nothrow) uint8_t[rowBytes * image->height()]; + auto info = ImageInfo::Make(image->width(), image->height(), ColorType::RGBA_8888, + AlphaType::Premultiplied); + auto pixels = new (std::nothrow) uint8_t[info.byteSize()]; ASSERT_TRUE(pixels); - auto info = ImageInfo::Make(110, 110, ColorType::RGBA_8888, AlphaType::Premultiplied); - bool res = image->readPixels(info, pixels); - ASSERT_TRUE(res); - PixelMap pixelMap(info, pixels); - auto bytes = Image::Encode(pixelMap.info(), pixelMap.pixels(), EncodedFormat::WEBP, 100); + ASSERT_TRUE(image->readPixels(info, pixels)); + CHECK_PIXELS(info, pixels, "WebpCodec_Decode"); + auto bytes = Image::Encode(info, pixels, EncodedFormat::WEBP, 100); image = Image::MakeFrom(bytes); ASSERT_TRUE(image != nullptr); ASSERT_EQ(image->width(), 110); ASSERT_EQ(image->height(), 110); ASSERT_EQ(static_cast(image->orientation()), static_cast(Orientation::TopLeft)); + + auto a8Info = ImageInfo::Make(image->width(), image->height(), ColorType::ALPHA_8, + AlphaType::Premultiplied); + auto a8Pixels = new (std::nothrow) uint8_t[a8Info.byteSize()]; + ASSERT_TRUE(image->readPixels(a8Info, a8Pixels)); + auto rgbaFromA8Data = image->Encode(a8Info, a8Pixels, EncodedFormat::WEBP, 100); + auto rgbaFromA8Image = Image::MakeFrom(rgbaFromA8Data); + rgbaFromA8Image->readPixels(info, pixels); + CHECK_PIXELS(info, pixels, "WebpCodec_EncodeA8"); delete[] pixels; + delete[] a8Pixels; } /** @@ -311,8 +322,10 @@ PAG_TEST(PAGReadPixelsTest, JpegCodec) { auto pixels = new (std::nothrow) uint8_t[image->height() * image->width() * ImageInfo::GetBytesPerPixel(outputColorType)]; ASSERT_TRUE(pixels); - auto info = ImageInfo::Make(4032, 3024, outputColorType, AlphaType::Premultiplied); + auto info = + ImageInfo::Make(image->width(), image->height(), outputColorType, AlphaType::Premultiplied); bool res = image->readPixels(info, pixels); + CHECK_PIXELS(info, pixels, "JpegCodec_Decode"); PixelMap pixelMap(info, pixels); auto bytes = Image::Encode(pixelMap.info(), pixelMap.pixels(), EncodedFormat::JPEG, 20); diff --git a/test/baseline/PAGReadPixelsTest/JpegCodec_Decode.webp.lzma2 b/test/baseline/PAGReadPixelsTest/JpegCodec_Decode.webp.lzma2 new file mode 100644 index 0000000000..5eba0a12bb --- /dev/null +++ b/test/baseline/PAGReadPixelsTest/JpegCodec_Decode.webp.lzma2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84fc223d12209146b98413093780a197875ac5cbd2a4561c5278b8b33a923c48 +size 10108473 diff --git a/test/baseline/PAGReadPixelsTest/PngCodec_Decode.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PngCodec_Decode.webp.lzma2 new file mode 100644 index 0000000000..cc530a0463 --- /dev/null +++ b/test/baseline/PAGReadPixelsTest/PngCodec_Decode.webp.lzma2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b5847c491221d016c42d295108e12531edb65d2cd93b64c710f71de58365a828 +size 208265 diff --git a/test/baseline/PAGReadPixelsTest/WebpCodec_Decode.webp.lzma2 b/test/baseline/PAGReadPixelsTest/WebpCodec_Decode.webp.lzma2 new file mode 100644 index 0000000000..9c82c9b5a5 --- /dev/null +++ b/test/baseline/PAGReadPixelsTest/WebpCodec_Decode.webp.lzma2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0bfbcdc39739add21f96ece0a447eb3c11ded927f207f9ab418ae3acc7fe627 +size 22903 diff --git a/test/baseline/PAGReadPixelsTest/WebpCodec_EncodeA8.webp.lzma2 b/test/baseline/PAGReadPixelsTest/WebpCodec_EncodeA8.webp.lzma2 new file mode 100644 index 0000000000..bc7e7145f1 --- /dev/null +++ b/test/baseline/PAGReadPixelsTest/WebpCodec_EncodeA8.webp.lzma2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:50623851ef2914ce6e2af19035c445e7529a683dca77ff1c4eff450d8cede7e2 +size 954 diff --git a/tgfx/src/image/webp/WebpImage.cpp b/tgfx/src/image/webp/WebpImage.cpp index 4411d3c0a2..a55f8e3bc4 100644 --- a/tgfx/src/image/webp/WebpImage.cpp +++ b/tgfx/src/image/webp/WebpImage.cpp @@ -134,15 +134,17 @@ static int webp_reader_write_data(const uint8_t* data, size_t data_size, std::shared_ptr WebpImage::Encode(const ImageInfo& imageInfo, const void* pixels, EncodedFormat, int quality) { - if (imageInfo.colorType() == ColorType::ALPHA_8) { - return nullptr; - } const uint8_t* srcPixels = static_cast(const_cast(pixels)); const uint8_t* convertPixels = nullptr; - if (imageInfo.alphaType() == AlphaType::Premultiplied) { - PixelMap pixelMap(imageInfo, srcPixels); - auto dstPixels = new uint8_t[imageInfo.byteSize()]; - auto dstInfo = ImageInfo::Make(imageInfo.width(), imageInfo.height(), imageInfo.colorType(), + if (imageInfo.alphaType() == AlphaType::Premultiplied || + imageInfo.colorType() == ColorType::ALPHA_8) { + auto srcInfo = ImageInfo::Make(imageInfo.width(), imageInfo.height(), imageInfo.colorType(), + AlphaType::Unpremultiplied); + PixelMap pixelMap(srcInfo, srcPixels); + auto dstPixels = new uint8_t[imageInfo.width() * imageInfo.height() * 4]; + auto colorType = + imageInfo.colorType() == ColorType::ALPHA_8 ? ColorType::RGBA_8888 : imageInfo.colorType(); + auto dstInfo = ImageInfo::Make(imageInfo.width(), imageInfo.height(), colorType, AlphaType::Unpremultiplied); if (!pixelMap.readPixels(dstInfo, dstPixels)) { delete[] dstPixels; @@ -179,7 +181,8 @@ std::shared_ptr WebpImage::Encode(const ImageInfo& imageInfo, const void* pic.custom_ptr = &webpWriter; const int rgbStride = pic.width * 4; auto importProc = WebPPictureImportRGBX; - if (ColorType::RGBA_8888 == imageInfo.colorType()) { + if (ColorType::RGBA_8888 == imageInfo.colorType() || + ColorType::ALPHA_8 == imageInfo.colorType()) { if (AlphaType::Opaque == imageInfo.alphaType()) { importProc = WebPPictureImportRGBX; } else { From 1a8387ab801d6f582cb557cce3441b8f46afd1af Mon Sep 17 00:00:00 2001 From: h3r3x3 Date: Thu, 27 Jan 2022 17:16:20 +0800 Subject: [PATCH 3/4] optimize naming for Testing --- test/PAGReadPixelsTest.cpp | 8 ++++---- ...JpegCodec_Decode.webp.lzma2 => JpegCodec_Decode.lzma2} | 0 ...GRA_to_BGRA.webp.lzma2 => PixelMap_BGRA_to_BGRA.lzma2} | 0 ...GRA_to_RGBA.webp.lzma2 => PixelMap_BGRA_to_RGBA.lzma2} | 0 ...A_Original.webp.lzma2 => PixelMap_RGBA_Original.lzma2} | 0 ...GBA_to_RGBA.webp.lzma2 => PixelMap_RGBA_to_RGBA.lzma2} | 0 ...0.webp.lzma2 => PixelMap_RGBA_to_RGBA_-100_-100.lzma2} | 0 ...00.webp.lzma2 => PixelMap_RGBA_to_RGBA_100_-100.lzma2} | 0 ...100.webp.lzma2 => PixelMap_RGBA_to_RGBA_100_100.lzma2} | 0 ...GBA_to_bgrA.webp.lzma2 => PixelMap_RGBA_to_bgrA.lzma2} | 0 ...ha_to_BGRA.webp.lzma2 => PixelMap_alpha_to_BGRA.lzma2} | 0 ...ha_to_rgbA.webp.lzma2 => PixelMap_alpha_to_rgbA.lzma2} | 0 ...A_to_alpha.webp.lzma2 => PixelMap_rgbA_to_alpha.lzma2} | 0 .../{PngCodec_Decode.webp.lzma2 => PngCodec_Decode.lzma2} | 0 ...A_to_rgbA.webp.lzma2 => Surface_BL_rgbA_to_rgbA.lzma2} | 0 ...webp.lzma2 => Surface_BL_rgbA_to_rgbA_-100_-100.lzma2} | 0 ....webp.lzma2 => Surface_BL_rgbA_to_rgbA_100_-100.lzma2} | 0 ...0.webp.lzma2 => Surface_BL_rgbA_to_rgbA_100_100.lzma2} | 0 ...a_to_alpha.webp.lzma2 => Surface_alpha_to_alpha.lzma2} | 0 ...0.webp.lzma2 => Surface_alpha_to_alpha_100_-100.lzma2} | 0 ...pha_to_rgba.webp.lzma2 => Surface_alpha_to_rgba.lzma2} | 0 ...rgbA_to_bgrA.webp.lzma2 => Surface_rgbA_to_bgrA.lzma2} | 0 ...rgbA_to_rgbA.webp.lzma2 => Surface_rgbA_to_rgbA.lzma2} | 0 ...00.webp.lzma2 => Surface_rgbA_to_rgbA_-100_-100.lzma2} | 0 ...100.webp.lzma2 => Surface_rgbA_to_rgbA_100_-100.lzma2} | 0 ..._100.webp.lzma2 => Surface_rgbA_to_rgbA_100_100.lzma2} | 0 ...WebpCodec_Decode.webp.lzma2 => WebpCodec_Decode.lzma2} | 0 ...Codec_EncodeA8.webp.lzma2 => WebpCodec_EncodeA8.lzma2} | 0 28 files changed, 4 insertions(+), 4 deletions(-) rename test/baseline/PAGReadPixelsTest/{JpegCodec_Decode.webp.lzma2 => JpegCodec_Decode.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_BGRA_to_BGRA.webp.lzma2 => PixelMap_BGRA_to_BGRA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_BGRA_to_RGBA.webp.lzma2 => PixelMap_BGRA_to_RGBA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_RGBA_Original.webp.lzma2 => PixelMap_RGBA_Original.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_RGBA_to_RGBA.webp.lzma2 => PixelMap_RGBA_to_RGBA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_RGBA_to_RGBA_-100_-100.webp.lzma2 => PixelMap_RGBA_to_RGBA_-100_-100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_RGBA_to_RGBA_100_-100.webp.lzma2 => PixelMap_RGBA_to_RGBA_100_-100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_RGBA_to_RGBA_100_100.webp.lzma2 => PixelMap_RGBA_to_RGBA_100_100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_RGBA_to_bgrA.webp.lzma2 => PixelMap_RGBA_to_bgrA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_alpha_to_BGRA.webp.lzma2 => PixelMap_alpha_to_BGRA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_alpha_to_rgbA.webp.lzma2 => PixelMap_alpha_to_rgbA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PixelMap_rgbA_to_alpha.webp.lzma2 => PixelMap_rgbA_to_alpha.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{PngCodec_Decode.webp.lzma2 => PngCodec_Decode.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_BL_rgbA_to_rgbA.webp.lzma2 => Surface_BL_rgbA_to_rgbA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_BL_rgbA_to_rgbA_-100_-100.webp.lzma2 => Surface_BL_rgbA_to_rgbA_-100_-100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_BL_rgbA_to_rgbA_100_-100.webp.lzma2 => Surface_BL_rgbA_to_rgbA_100_-100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_BL_rgbA_to_rgbA_100_100.webp.lzma2 => Surface_BL_rgbA_to_rgbA_100_100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_alpha_to_alpha.webp.lzma2 => Surface_alpha_to_alpha.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_alpha_to_alpha_100_-100.webp.lzma2 => Surface_alpha_to_alpha_100_-100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_alpha_to_rgba.webp.lzma2 => Surface_alpha_to_rgba.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_rgbA_to_bgrA.webp.lzma2 => Surface_rgbA_to_bgrA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_rgbA_to_rgbA.webp.lzma2 => Surface_rgbA_to_rgbA.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_rgbA_to_rgbA_-100_-100.webp.lzma2 => Surface_rgbA_to_rgbA_-100_-100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_rgbA_to_rgbA_100_-100.webp.lzma2 => Surface_rgbA_to_rgbA_100_-100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{Surface_rgbA_to_rgbA_100_100.webp.lzma2 => Surface_rgbA_to_rgbA_100_100.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{WebpCodec_Decode.webp.lzma2 => WebpCodec_Decode.lzma2} (100%) rename test/baseline/PAGReadPixelsTest/{WebpCodec_EncodeA8.webp.lzma2 => WebpCodec_EncodeA8.lzma2} (100%) diff --git a/test/PAGReadPixelsTest.cpp b/test/PAGReadPixelsTest.cpp index 900d1fed2a..d15edc291f 100644 --- a/test/PAGReadPixelsTest.cpp +++ b/test/PAGReadPixelsTest.cpp @@ -29,10 +29,10 @@ namespace pag { using nlohmann::json; -#define CHECK_PIXELS(info, pixels, key) \ - { \ - PixelMap pm(info, pixels); \ - EXPECT_TRUE(Baseline::Compare(pm, "PAGReadPixelsTest/" + std::string(key) + ".webp")); \ +#define CHECK_PIXELS(info, pixels, key) \ + { \ + PixelMap pm(info, pixels); \ + EXPECT_TRUE(Baseline::Compare(pm, "PAGReadPixelsTest/" + std::string(key))); \ } /** diff --git a/test/baseline/PAGReadPixelsTest/JpegCodec_Decode.webp.lzma2 b/test/baseline/PAGReadPixelsTest/JpegCodec_Decode.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/JpegCodec_Decode.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/JpegCodec_Decode.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_BGRA_to_BGRA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_BGRA_to_BGRA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_BGRA_to_BGRA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_BGRA_to_BGRA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_BGRA_to_RGBA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_BGRA_to_RGBA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_BGRA_to_RGBA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_BGRA_to_RGBA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_Original.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_Original.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_RGBA_Original.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_RGBA_Original.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_-100_-100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_-100_-100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_-100_-100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_-100_-100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_100_-100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_100_-100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_100_-100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_100_-100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_100_100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_100_100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_100_100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_RGBA_100_100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_bgrA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_bgrA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_bgrA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_RGBA_to_bgrA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_alpha_to_BGRA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_alpha_to_BGRA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_alpha_to_BGRA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_alpha_to_BGRA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_alpha_to_rgbA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_alpha_to_rgbA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_alpha_to_rgbA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_alpha_to_rgbA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PixelMap_rgbA_to_alpha.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PixelMap_rgbA_to_alpha.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PixelMap_rgbA_to_alpha.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PixelMap_rgbA_to_alpha.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/PngCodec_Decode.webp.lzma2 b/test/baseline/PAGReadPixelsTest/PngCodec_Decode.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/PngCodec_Decode.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/PngCodec_Decode.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_-100_-100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_-100_-100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_-100_-100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_-100_-100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_100_-100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_100_-100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_100_-100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_100_-100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_100_100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_100_100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_100_100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_BL_rgbA_to_rgbA_100_100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_alpha_to_alpha.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_alpha_to_alpha.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_alpha_to_alpha.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_alpha_to_alpha.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_alpha_to_alpha_100_-100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_alpha_to_alpha_100_-100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_alpha_to_alpha_100_-100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_alpha_to_alpha_100_-100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_alpha_to_rgba.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_alpha_to_rgba.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_alpha_to_rgba.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_alpha_to_rgba.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_bgrA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_bgrA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_rgbA_to_bgrA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_rgbA_to_bgrA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_-100_-100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_-100_-100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_-100_-100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_-100_-100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_100_-100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_100_-100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_100_-100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_100_-100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_100_100.webp.lzma2 b/test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_100_100.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_100_100.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/Surface_rgbA_to_rgbA_100_100.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/WebpCodec_Decode.webp.lzma2 b/test/baseline/PAGReadPixelsTest/WebpCodec_Decode.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/WebpCodec_Decode.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/WebpCodec_Decode.lzma2 diff --git a/test/baseline/PAGReadPixelsTest/WebpCodec_EncodeA8.webp.lzma2 b/test/baseline/PAGReadPixelsTest/WebpCodec_EncodeA8.lzma2 similarity index 100% rename from test/baseline/PAGReadPixelsTest/WebpCodec_EncodeA8.webp.lzma2 rename to test/baseline/PAGReadPixelsTest/WebpCodec_EncodeA8.lzma2 From 3c21b974c615473715d5ef8774dd4d693ea37de7 Mon Sep 17 00:00:00 2001 From: h3r3x3 Date: Thu, 27 Jan 2022 17:24:35 +0800 Subject: [PATCH 4/4] fix webp encode premultiplied image bug. --- tgfx/src/image/webp/WebpImage.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tgfx/src/image/webp/WebpImage.cpp b/tgfx/src/image/webp/WebpImage.cpp index a55f8e3bc4..616d0ec154 100644 --- a/tgfx/src/image/webp/WebpImage.cpp +++ b/tgfx/src/image/webp/WebpImage.cpp @@ -138,9 +138,7 @@ std::shared_ptr WebpImage::Encode(const ImageInfo& imageInfo, const void* const uint8_t* convertPixels = nullptr; if (imageInfo.alphaType() == AlphaType::Premultiplied || imageInfo.colorType() == ColorType::ALPHA_8) { - auto srcInfo = ImageInfo::Make(imageInfo.width(), imageInfo.height(), imageInfo.colorType(), - AlphaType::Unpremultiplied); - PixelMap pixelMap(srcInfo, srcPixels); + PixelMap pixelMap(imageInfo, srcPixels); auto dstPixels = new uint8_t[imageInfo.width() * imageInfo.height() * 4]; auto colorType = imageInfo.colorType() == ColorType::ALPHA_8 ? ColorType::RGBA_8888 : imageInfo.colorType();