Created attachment 12653 [details] Testcase PDF-file. I took the following file from openjpeg: https://github.com/uclouvain/openjpeg-data/blob/master/input/nonregression/issue411-ycc420.jp2 and embedded it in a PDF-file. Ghostscript attempts to render it but does so incorrectly, moreover it generates a few valgrind errors.
Created attachment 12654 [details] Sample image showing unpatched code using Luratech JPX decoder.
Created attachment 12655 [details] Sample image showing unpatched code using Openjpeg JPX decoder.
Created attachment 12656 [details] Sample image showing patched code using Luratech JPX decoder.
Created attachment 12657 [details] Attempt at patching Ghostscript to better handle attached sample image.
Please see 696885 for how MuPDF renders this file.
The problem is still reproducible in the current master branch. There's a patch for Luratech but no patch for openjpeg.
Now that we have dropped Luratech and openjpeg is our JPX codec, we probably should assign it to someone to actually fix it. Bumping back to Henry for assignment.
I retested this on latest git HEAD, commit 3635f4c75e54e337a4eebcf6db3eef0e60f9cebf, and the incorrect diagonal pattern is still present. The valgrind issues I mentioned were fixed in commit 9388ecefe9d8659d8434aa78d07a1fa247c8ea4e.
Created attachment 23892 [details] Proposed patch for handling subsampled j2k components better This proposed patch is under review. Maybe it can be better optimized.
Fixed in commit fd5007e72efe82dbf892bd0a5ef58c992a4d58ca Author: Sebastian Rasmussen <sebras@gmail.com> Date: Sun Mar 26 04:37:40 2023 +0200 Bug 696884: Handle subsampled components correctly for JPEG2000 images. Previously if a PDF had an JPEG2000 image using subsampling which was not a multiple of the image width, rendering would appear staggered. The upsampling code didn't take the up to dx - 1 upsampled samples into account at the end of the scanline. The JPEG2000 image in the PDF in the bug is 32 by 32 pixels where component 0 is not subsampled (dx/dy are both 1) and components 1 and 2 are subsampled (dx/dy are both 2). Thanks for the maths in this commit Robin!