openjpeg icon indicating copy to clipboard operation
openjpeg copied to clipboard

Inconsistent decompression results on macOS arm64

Open zcronix opened this issue 1 month ago • 2 comments

I'm decompressing lossy encoded JPEG2000 images using OpenJPEG 2.5.4 on three different platforms: Windows x86_64, macOS x86_64, and macOS arm64. For these images, I get the exact same results on the two x86_64 platforms, but the output on arm64 differs by a value of 1 at some scattered pixels.

I had previously been using OpenJPEG 2.4.0 for this task, and noticed this issue when performing consistency checks after upgrading. However, I discovered that freshly compiled macOS arm64 binaries of both version 2.4.0 and 2.5.4 exhibited the same issue. The old 2.4.0 binary that gave consistent results had been compiled on macOS 12. This appears to be the differentiator. Building for macOS arm64 on macOS 12 results in a binary that produces decompression results consistent with the other platforms. Building on macOS 26 (or 14, or 13, it turns out) causes the results to differ. This seems to happen regardless of the version of macOS being used to run the binary.

I ran the testing suite in these different scenarios to try to verify what I was seeing. Using OpenJPEG 2.5.4, for macOS x86_64 and for macOS arm64 built on macOS 12, I get this output (running the tests on macOS 26):

The following tests FAILED: 1147 - NR-DEC-issue226.j2k-74-decode (Failed) 1148 - NR-DEC-issue226.j2k-74-decode-md5 (Failed)

Using macOS arm64 built on macOS 26, I get:

The following tests FAILED: 38 - NR-C1P0-p0_04.j2k-compare2base (Failed) 41 - NR-C1P0-p0_05.j2k-compare2base (Failed) 44 - NR-C1P0-p0_06.j2k-compare2base (Failed) 80 - NR-C1P1-p1_02.j2k-compare2base (Failed) 83 - NR-C1P1-p1_03.j2k-compare2base (Failed) 86 - NR-C1P1-p1_04.j2k-compare2base (Failed) 89 - NR-C1P1-p1_05.j2k-compare2base (Failed) 101 - NR-JP2-file2.jp2-compare2base (Failed) 188 - NR-RIC-subsampling_1.jp2-compare2base (Failed) 191 - NR-RIC-subsampling_2.jp2-compare2base (Failed) 194 - NR-RIC-zoo1.jp2-compare2base (Failed) 197 - NR-RIC-zoo2.jp2-compare2base (Failed) 1034 - NR-DEC-_00042.j2k-2-decode-md5 (Failed) 1044 - NR-DEC-buxI.j2k-9-decode-md5 (Failed) 1052 - NR-DEC-CT_Phillips_JPEG2K_Decompr_Problem.j2k-13-decode-md5 (Failed) 1062 - NR-DEC-Marrin.jp2-18-decode-md5 (Failed) 1088 - NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 (Failed) 1090 - NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 (Failed) 1101 - NR-DEC-file409752.jp2-40-decode-md5 (Failed) 1103 - NR-DEC-issue188_beach_64bitsbox.jp2-41-decode-md5 (Failed) 1105 - NR-DEC-issue206_image-000.jp2-42-decode-md5 (Failed) 1107 - NR-DEC-issue205.jp2-43-decode-md5 (Failed) 1125 - NR-DEC-issue228.j2k-60-decode-md5 (Failed) 1133 - NR-DEC-issue142.j2k-66-decode-md5 (Failed) 1135 - NR-DEC-issue134.jp2-67-decode-md5 (Failed) 1137 - NR-DEC-issue135.j2k-68-decode-md5 (Failed) 1139 - NR-DEC-issue208.jp2-69-decode-md5 (Failed) 1141 - NR-DEC-issue211.jp2-70-decode-md5 (Failed) 1147 - NR-DEC-issue226.j2k-74-decode (Failed) 1148 - NR-DEC-issue226.j2k-74-decode-md5 (Failed) 1207 - NR-DEC-p1_04.j2k-124-decode-md5 (Failed) 1209 - NR-DEC-p1_04.j2k-125-decode-md5 (Failed) 1211 - NR-DEC-p1_04.j2k-126-decode-md5 (Failed) 1213 - NR-DEC-p1_04.j2k-127-decode-md5 (Failed) 1215 - NR-DEC-p1_04.j2k-128-decode-md5 (Failed) 1217 - NR-DEC-p1_04.j2k-129-decode-md5 (Failed) 1221 - NR-DEC-p1_04.j2k-131-decode-md5 (Failed) 1235 - NR-DEC-p1_04.j2k-138-decode-md5 (Failed) 1239 - NR-DEC-p1_04.j2k-140-decode-md5 (Failed) 1289 - NR-DEC-p0_04.j2k-166-decode-md5 (Failed) 1291 - NR-DEC-p0_04.j2k-167-decode-md5 (Failed) 1293 - NR-DEC-p0_04.j2k-168-decode-md5 (Failed) 1301 - NR-DEC-p0_04.j2k-172-decode-md5 (Failed) 1462 - NR-DEC-issue205.jp2-253-decode-md5 (Failed) 1464 - NR-DEC-issue236-ESYCC-CDEF.jp2-254-decode-md5 (Failed) 1466 - NR-DEC-issue559-eci-090-CIELab.jp2-255-decode-md5 (Failed) 1468 - NR-DEC-issue559-eci-091-CIELab.jp2-256-decode-md5 (Failed) 1558 - NR-DEC-db11217111510058.jp2-306-decode-md5 (Failed) 1560 - NR-DEC-tnsot_zero.jp2-307-decode-md5 (Failed) 1567 - NR-DEC-Bretagne1_ht_lossy.j2k-311-decode-md5 (Failed)

Since the problem occurs with the exact same source code, and independent of the macOS version used at runtime, I am led to wonder if there was a compiler change after macOS 12 that is affecting the behavior of OpenJPEG on arm64.

zcronix avatar Nov 21 '25 19:11 zcronix

if there was a compiler change after macOS 12

likely. If the differences in pixels values are just one, nothing to worry about. There are floating point operations involved in lossy decompression and I don't think there's a bit-to-bit perfect reconstruction to be expected

rouault avatar Nov 21 '25 19:11 rouault

While I agree that a small difference is not meaningful in the context of lossy image decompression, I do think that OpenJPEG should be consistent across different platforms.

zcronix avatar Nov 21 '25 20:11 zcronix