diff --git a/CoreJ2K/J2kImage.cs b/CoreJ2K/J2kImage.cs index ebcbb74..8467465 100644 --- a/CoreJ2K/J2kImage.cs +++ b/CoreJ2K/J2kImage.cs @@ -248,7 +248,7 @@ public static InterleavedImage FromStream(Stream stream, ParameterList parameter // **** Copy 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); var dst = new InterleavedImage(imgWidth, decodedImage.ImgHeight, numComps, bitsUsed); @@ -488,7 +488,7 @@ public static InterleavedImage FromStream(Stream stream, out j2k.fileformat.meta // **** Copy 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); var dst = new InterleavedImage(imgWidth, decodedImage.ImgHeight, numComps, bitsUsed); diff --git a/CoreJ2K/j2k/codestream/reader/PktDecoder.cs b/CoreJ2K/j2k/codestream/reader/PktDecoder.cs index 6d45167..27e0591 100644 --- a/CoreJ2K/j2k/codestream/reader/PktDecoder.cs +++ b/CoreJ2K/j2k/codestream/reader/PktDecoder.cs @@ -1695,11 +1695,9 @@ public virtual bool readSOPMarker(int[] nBytes, int p, int c, int r) // Read marker into array 'sopArray' ehs.readFully(sopArray, 0, Markers.SOP_LENGTH); - // Check if this is the correct marker - val = sopArray[0]; - val <<= 8; - val |= sopArray[1]; - if (val != Markers.SOP) + // Check if this is the correct marker (Markers.EPH is a negative short -> cast to short) + var marker = (short)((sopArray[0] << 8) | sopArray[1]); + if (marker != Markers.SOP) { throw new InvalidOperationException("Corrupted Bitstream: Could not parse SOP " + "marker !"); } @@ -1740,7 +1738,6 @@ public virtual bool readSOPMarker(int[] nBytes, int p, int c, int r) /// public virtual void readEPHMarker(PktHeaderBitReader bin) { - int val; var ephArray = new byte[2]; if (bin.usebais) @@ -1752,11 +1749,9 @@ public virtual void readEPHMarker(PktHeaderBitReader bin) bin.in_Renamed.readFully(ephArray, 0, Markers.EPH_LENGTH); } - // Check if this is the correct marker - val = ephArray[0]; - val <<= 8; - val |= ephArray[1]; - if (val != Markers.EPH) + // Check if this is the correct marker (Markers.EPH is a negative short -> cast to short) + var marker = (short)((ephArray[0] << 8) | ephArray[1]); + if (marker != Markers.EPH) { throw new InvalidOperationException("Corrupted Bitstream: Could not parse EPH " + "marker ! "); } diff --git a/CoreJ2K/j2k/wavelet/synthesis/InvWTFull.cs b/CoreJ2K/j2k/wavelet/synthesis/InvWTFull.cs index 5371182..553b604 100644 --- a/CoreJ2K/j2k/wavelet/synthesis/InvWTFull.cs +++ b/CoreJ2K/j2k/wavelet/synthesis/InvWTFull.cs @@ -704,20 +704,10 @@ public override void setTile(int x, int y) } } - // If a reconstructed block exists, update its dimensions and Data pointer to the rented buffer - if (reconstructedComps != null && i < reconstructedComps.Length && reconstructedComps[i] != null) + // The wavelet data must be reconstructed since we've switched to a different tile. + if (reconstructedComps != null && i < reconstructedComps.Length) { - var db = reconstructedComps[i]; - db.w = newWidth; - db.h = newHeight; - if (db is DataBlkFloat && rentedFloatBuffers[i] != null) - { - db.Data = rentedFloatBuffers[i]; - } - else if (db is DataBlkInt && rentedIntBuffers[i] != null) - { - db.Data = rentedIntBuffers[i]; - } + reconstructedComps[i] = null; } } @@ -792,19 +782,10 @@ public override void nextTile() } } - if (reconstructedComps != null && i < reconstructedComps.Length && reconstructedComps[i] != null) + // The wavelet data must be reconstructed since we've switched to a different tile. + if (reconstructedComps != null && i < reconstructedComps.Length) { - var db = reconstructedComps[i]; - db.w = newWidth; - db.h = newHeight; - if (db is DataBlkFloat && rentedFloatBuffers[i] != null) - { - db.Data = rentedFloatBuffers[i]; - } - else if (db is DataBlkInt && rentedIntBuffers[i] != null) - { - db.Data = rentedIntBuffers[i]; - } + reconstructedComps[i] = null; } } }