From cc045239856249b2168cd594df8fd2cb6a0c5240 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 8 Aug 2021 12:23:51 -0700 Subject: [PATCH] libpng: Patch out 100% opaque optimization. This optimization seems to work fine if you want RGB, but if you want RGBA, it forgets to add the fixed values back. See #14628. --- ext/libpng17/pngread.c | 3 +-- ext/libpng17/pngrtran.c | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ext/libpng17/pngread.c b/ext/libpng17/pngread.c index 71ddc01fe1..96a5a1b4b4 100644 --- a/ext/libpng17/pngread.c +++ b/ext/libpng17/pngread.c @@ -3997,8 +3997,7 @@ png_image_read_direct(png_voidp argument) # endif /* This is actually an internal error. */ - // HACK to prevent crash: See issue #14628 - // affirm(out_format == format /* else unimplemented transformations */); + affirm(out_format == format /* else unimplemented transformations */); } /* Now read the rows. If do_local_compose is set then it is necessary to use diff --git a/ext/libpng17/pngrtran.c b/ext/libpng17/pngrtran.c index c5fb837bee..6a6583eff2 100644 --- a/ext/libpng17/pngrtran.c +++ b/ext/libpng17/pngrtran.c @@ -6603,7 +6603,9 @@ check_tRNS_for_alpha(png_structrp png_ptr) } /* All entries opaque; remove the tRNS data: */ - png_ptr->num_trans = 0U; + // TODO: This optimization doesn't handle adding it back if RGBA is requested. + // See PPSSPP issue #14628. + //png_ptr->num_trans = 0U; } #endif /* READ_tRNS */