Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CoreJ2K/J2kImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
17 changes: 6 additions & 11 deletions CoreJ2K/j2k/codestream/reader/PktDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 !");
}
Expand Down Expand Up @@ -1740,7 +1738,6 @@ public virtual bool readSOPMarker(int[] nBytes, int p, int c, int r)
/// </param>
public virtual void readEPHMarker(PktHeaderBitReader bin)
{
int val;
var ephArray = new byte[2];

if (bin.usebais)
Expand All @@ -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 ! ");
}
Expand Down
31 changes: 6 additions & 25 deletions CoreJ2K/j2k/wavelet/synthesis/InvWTFull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}
}
Expand Down