Skip to content

Commit

Permalink
Fix JPEG2000 compression rate is not obeyed #81
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Beltran committed Aug 20, 2024
1 parent 2dca34d commit 1f3fe7b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Codec/DicomJpeg2000Codec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public unsafe struct opj_dparameters_t

public class DicomJpeg2000Params : DicomCodecParams
{
private int[] _rates;
private double[] _rates;
public DicomJpeg2000Params()
{
Irreversible = true;
Expand All @@ -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;
Expand All @@ -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; }
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Acceptance/AcceptanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<!--PackageReference Include="fo-dicom.Codecs" Version="5.14.3" /-->
<!--PackageReference Include="fo-dicom.Codecs" Version="5.14.4" /-->
<ProjectReference Include="../../Platform/fo-dicom/fo-dicom.Codecs.csproj" />
</ItemGroup>
</Project>

0 comments on commit 1f3fe7b

Please sign in to comment.