From 013f14a47ab5e890dc1715e1ef9591e9825350d0 Mon Sep 17 00:00:00 2001 From: Ed Asriyan Date: Sat, 3 Feb 2024 16:58:47 +0400 Subject: [PATCH] Remove grey outline on transparent animations fixes #87 --- src/render.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/render.cpp b/src/render.cpp index 8605640..b13be4d 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -40,6 +40,19 @@ void write_png( PNG_FILTER_TYPE_DEFAULT ); + // remove outline on tranparent images. references: + // https://github.com/smohantty/ImageTest/blob/6427edb586fd9a2d92087e25a9ff0b361fc85870/imagetest.cpp#L83-L105 + // https://github.com/Samsung/rlottie/issues/466 + size_t total_bytes = width * height * lp_COLOR_BYTES; + for (size_t i = 0; i < total_bytes; i += lp_COLOR_BYTES) { + unsigned char a = buffer[i + 3]; + if (a != 0 && a != 255) { + buffer[i] = (buffer[i] * 255) / a; + buffer[i + 1] = (buffer[i + 1] * 255) / a; + buffer[i + 2] = (buffer[i + 2] * 255) / a; + } + } + unsigned char** row_pointers = (unsigned char**)png_malloc(png_ptr, height * sizeof(png_byte*)); if (row_pointers == nullptr) { png_destroy_write_struct(&png_ptr, &info_ptr);