From 1f3fe7b9b8af3a203bf31d1522cc396ad5a299e9 Mon Sep 17 00:00:00 2001 From: Christian Beltran Date: Tue, 20 Aug 2024 11:45:05 -0500 Subject: [PATCH] Fix JPEG2000 compression rate is not obeyed #81 --- Codec/DicomJpeg2000Codec.cs | 14 +++++++------- Tests/Acceptance/AcceptanceTests.csproj | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Codec/DicomJpeg2000Codec.cs b/Codec/DicomJpeg2000Codec.cs index d3bcd5c..9d2f739 100644 --- a/Codec/DicomJpeg2000Codec.cs +++ b/Codec/DicomJpeg2000Codec.cs @@ -333,7 +333,7 @@ public unsafe struct opj_dparameters_t public class DicomJpeg2000Params : DicomCodecParams { - private int[] _rates; + private double[] _rates; public DicomJpeg2000Params() { Irreversible = true; @@ -343,7 +343,7 @@ public DicomJpeg2000Params() UpdatePhotometricInterpretation = true; EncodeSignedPixelValuesAsUnsigned = false; - _rates = new int[9]; + _rates = new double[9]; _rates[0] = 1280; _rates[1] = 640; _rates[2] = 320; @@ -358,9 +358,9 @@ public DicomJpeg2000Params() } public bool Irreversible { get; set; } - public int Rate { get; set; } + public double Rate { get; set; } public OPJ_PROG_ORDER ProgressionOrder { get; set; } = OPJ_PROG_ORDER.LRCP; - public int[] RateLevels { get; set; } + public double[] RateLevels { get; set; } public bool IsVerbose { get; set; } public bool AllowMCT { get; set; } public bool UpdatePhotometricInterpretation { get; set; } @@ -598,14 +598,14 @@ public override void Encode(DicomPixelData oldPixelData, DicomPixelData newPixel if (jparams.RateLevels[r] > jparams.Rate) { eparams.tcp_numlayers++; - eparams.tcp_rates[r] = jparams.RateLevels[r]; + eparams.tcp_rates[r] = (float)jparams.RateLevels[r]; } else break; } eparams.tcp_numlayers++; - eparams.tcp_rates[r] = jparams.Rate; + eparams.tcp_rates[r] = (float)(jparams.Rate * oldPixelData.BitsStored / oldPixelData.BitsAllocated); if (newPixelData.Syntax == DicomTransferSyntax.JPEG2000Lossless && jparams.Rate > 0) eparams.tcp_rates[eparams.tcp_numlayers++] = 0; @@ -724,7 +724,7 @@ public override void Encode(DicomPixelData oldPixelData, DicomPixelData newPixel for (int p = 0; p < pixelCount; p++) { ushort pixel = frameData16[pos]; - comp->data[p] = (pixel & mask) + 1; + comp->data[p] = pixel & mask; pos += offset; } } diff --git a/Tests/Acceptance/AcceptanceTests.csproj b/Tests/Acceptance/AcceptanceTests.csproj index 0d88e75..ed3f651 100755 --- a/Tests/Acceptance/AcceptanceTests.csproj +++ b/Tests/Acceptance/AcceptanceTests.csproj @@ -23,7 +23,7 @@ - +