Skip to content

Conversation

@lofcz
Copy link

@lofcz lofcz commented Jan 4, 2026

First off: you are doing an AMAZING work here with no praise! ❤️

I found three bugs when loading the following image: https://filesamples.com/samples/image/jp2/sample1.jp2

  1. SOP marker validation in PktDecoder is wrong (short casting):
-val = sopArray[0];
-val <<= 8;
-val |= sopArray[1];
-if (val != Markers.SOP)
+var marker = (short)((sopArray[0] << 8) | sopArray[1]);
+if (marker != Markers.SOP)
  1. InvWTFull.cs tile reconstruction:
if (reconstructedComps[compIndex] == null)
{
    // Only reconstructs if buffer is null
    waveletTreeReconstruction(...);
}

When setTile() is called, it updates buffer dimensions, but never sets reconstructedComps[i] = null to force reconstruction of the new tile. So all tiles after the first one keep returning data from tile (0,0).

if (reconstructedComps != null && i < reconstructedComps.Length)
{
-// reconstructedComps[i] logic
+reconstructedComps[i] = null;
}
  1. J2kImage.cs copying to bitmap:
var bitsUsed = new int[numComps];
-for (var j = 0; j < numComps; ++j) bitsUsed[j] = decodedImage.getNomRangeBits(numComps - 1 - j);
+for (var j = 0; j < numComps; ++j) bitsUsed[j] = decodedImage.getNomRangeBits(j);

We pass bitsUsed to InterleavedImage, which expects bitsUsed[i] to correspond to component i, so we can't reverse the order here.

@lofcz lofcz changed the title Fix SOP validation & setTile reconstruction Fix a few bugs Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant