Skip to content

Commit

Permalink
MDCM sync
Browse files Browse the repository at this point in the history
  • Loading branch information
issakomi committed May 15, 2024
1 parent 9aaa540 commit 8631e4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 52 deletions.
44 changes: 22 additions & 22 deletions mdcm/Source/MediaStorageAndFileFormat/mdcmBitmap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Bitmap::GetBufferLength() const
const unsigned short bits_allocated = PF.GetBitsAllocated();
if (bits_allocated % 8 != 0)
{
mdcmAlwaysWarnMacro("Bits Allocated " << bits_allocated << " is invalid");
mdcmWarningMacro("Bits Allocated " << bits_allocated);
if (PF == PixelFormat::UINT12 || PF == PixelFormat::INT12)
{
tmp0 *= 2ull;
Expand Down Expand Up @@ -504,7 +504,7 @@ Bitmap::TryEncapsulatedRAWCodec(char * buffer, bool & lossyflag) const
const SequenceOfFragments * sf = PixelData.GetSequenceOfFragments();
if (!sf)
{
mdcmAlwaysWarnMacro("EncapsulatedRAWCodec: SequenceOfFragments is null");
mdcmWarningMacro("EncapsulatedRAWCodec: SequenceOfFragments is null");
return false;
}
if (codec.CanDecode(ts))
Expand Down Expand Up @@ -546,7 +546,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
const SequenceOfFragments * sf = PixelData.GetSequenceOfFragments();
if (!sf)
{
mdcmAlwaysWarnMacro("TryJPEGCodec: SequenceOfFragments is null");
mdcmWarningMacro("JPEGCodec: SequenceOfFragments is null");
return false;
}
const Fragment & frag = sf->GetFragment(0);
Expand All @@ -557,7 +557,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
ss.write(bv2.GetPointer(), bv2.GetLength());
if (!codec.GetHeaderInfo(ss))
{
mdcmAlwaysWarnMacro("TryJPEGCodec: !codec.GetHeaderInfo(ss)");
mdcmWarningMacro("JPEGCodec: !codec.GetHeaderInfo(ss)");
return false;
}
lossyflag = codec.IsLossy();
Expand All @@ -579,7 +579,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
if (cpf.GetBitsStored() != pf.GetBitsStored())
{
mdcmAlwaysWarnMacro(
"TryJPEGCodec:: encapsulated stream precision " << cpf.GetBitsStored() <<
"JPEGCodec:: encapsulated stream precision " << cpf.GetBitsStored() <<
" bits, but DICOM bits stored " << pf.GetBitsStored());
if (ImageHelper::GetFixJpegBits())
{
Expand All @@ -596,7 +596,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
if (Dimensions[0] != codec.GetDimensions()[0] || Dimensions[1] != codec.GetDimensions()[1])
{
// JPEGNote_bogus.dcm
mdcmAlwaysWarnMacro("TryJPEGCodec: dimension mismatch for JPEG");
mdcmAlwaysWarnMacro("JPEGCodec: dimension mismatch for JPEG");
(const_cast<Bitmap *>(this))->SetDimensions(codec.GetDimensions());
}
return true;
Expand All @@ -617,7 +617,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
if (!codec.Decode2(PixelData, os))
{
// PHILIPS_Gyroscan-12-MONO2-Jpeg_Lossless.dcm
mdcmAlwaysWarnMacro("TryJPEGCodec: !codec.Decode2(PixelData, os)");
mdcmWarningMacro("JPEGCodec: !codec.Decode2(PixelData, os)");
return false;
}
if (GetPlanarConfiguration() != codec.GetPlanarConfiguration())
Expand All @@ -643,7 +643,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
const size_t len2 = os.tellp();
if (len != len2)
{
mdcmAlwaysWarnMacro("TryJPEGCodec: len=" << len << " len2=" << len2);
mdcmAlwaysWarnMacro("JPEGCodec: len=" << len << " len2=" << len2);
if (len > len2)
{
memset(buffer, 0, len);
Expand All @@ -653,11 +653,11 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
std::stringbuf * pbuf = os.rdbuf();
const long long sgetn_s = pbuf->sgetn(buffer, ((len < len2) ? len : len2));
#if 0
std::cout << "TryJPEGCodec: sizes should be the equal: " << len << " " << len2 << " " << sgetn_s << std::endl;
std::cout << "JPEGCodec: sizes should be the equal: " << len << " " << len2 << " " << sgetn_s << std::endl;
#endif
if (sgetn_s <= 0)
{
mdcmAlwaysWarnMacro("TryJPEGCodec: pbuf->sgetn returned " << sgetn_s);
mdcmAlwaysWarnMacro("JPEGCodec: pbuf->sgetn returned " << sgetn_s);
}
#else
const std::string & tmp0 = os.str();
Expand All @@ -682,7 +682,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
const SequenceOfFragments * sf = PixelData.GetSequenceOfFragments();
if (!sf)
{
mdcmAlwaysWarnMacro("JPEG: SequenceOfFragments is null");
mdcmWarningMacro("JPEG: SequenceOfFragments is null");
return false;
}
const Fragment & frag = sf->GetFragment(0);
Expand All @@ -693,7 +693,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
ss.write(bv2.GetPointer(), bv2.GetLength());
if (!codec.GetHeaderInfo(ss))
{
mdcmAlwaysWarnMacro("JPEG: !codec.GetHeaderInfo(ss)");
mdcmWarningMacro("JPEG: !codec.GetHeaderInfo(ss)");
return false;
}
lossyflag = codec.IsLossy();
Expand All @@ -715,7 +715,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
if (cpf.GetBitsStored() != pf.GetBitsStored())
{
mdcmAlwaysWarnMacro(
"Encapsulated stream reports precision " << cpf.GetBitsStored() <<
"JPEGCodec: encapsulated stream reports precision " << cpf.GetBitsStored() <<
" bits, but DICOM bits stored " << pf.GetBitsStored());
if (ImageHelper::GetFixJpegBits())
{
Expand All @@ -731,7 +731,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
#endif
if (Dimensions[0] != codec.GetDimensions()[0] || Dimensions[1] != codec.GetDimensions()[1])
{
mdcmAlwaysWarnMacro("TryJPEGCodec: dimension mismatch");
mdcmAlwaysWarnMacro("JPEGCodec: dimension mismatch");
(const_cast<Bitmap *>(this))->SetDimensions(codec.GetDimensions());
}
return true;
Expand All @@ -741,7 +741,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
const unsigned long long len = GetBufferLength();
if (len > 0xffffffff)
{
mdcmAlwaysWarnMacro("TryJPEGCodec: size " << len << " is not supported");
mdcmWarningMacro("JPEGCodec: size " << len << " is not supported");
return false;
}
if (codec.CanDecode(ts))
Expand All @@ -757,7 +757,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
if (!codec.Decode(PixelData, out))
{
// PHILIPS_Gyroscan-12-MONO2-Jpeg_Lossless.dcm
mdcmAlwaysWarnMacro("JPEG: !codec.Decode(PixelData, out)");
mdcmWarningMacro("JPEG: !codec.Decode(PixelData, out)");
return false;
}
if (GetPlanarConfiguration() != codec.GetPlanarConfiguration())
Expand Down Expand Up @@ -793,8 +793,8 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
{
if (cpf.GetBitsStored() != pf.GetBitsStored())
{
mdcmAlwaysWarnMacro(
"Encapsulated stream reports precision " << cpf.GetBitsStored() <<
mdcmWarningMacro(
"JPEG: encapsulated stream reports precision " << cpf.GetBitsStored() <<
" bits, but DICOM bits stored " << pf.GetBitsStored());
if (ImageHelper::GetFixJpegBits())
{
Expand All @@ -811,7 +811,7 @@ Bitmap::TryJPEGCodec(char * buffer, bool & lossyflag) const
const ByteValue * outbv = out.GetByteValue();
if (!outbv)
{
mdcmAlwaysWarnMacro("JPEG: !out.GetByteValue()");
mdcmWarningMacro("JPEG: !out.GetByteValue()");
return false;
}
if (len != static_cast<unsigned long long>(outbv->GetLength()))
Expand Down Expand Up @@ -902,7 +902,7 @@ Bitmap::TryJPEGLSCodec(char * buffer, bool & lossyflag) const
const unsigned long long len = GetBufferLength();
if (len > 0xffffffff)
{
mdcmAlwaysWarnMacro("TryJPEGLSCodec: size " << len << " is not supported");
mdcmAlwaysWarnMacro("JPEGLSCodec: size " << len << " is not supported");
return false;
}
if (codec.CanDecode(ts))
Expand Down Expand Up @@ -1070,7 +1070,7 @@ Bitmap::TryJPEG2000Codec(char * buffer, bool & lossyflag) const
const unsigned long long len = GetBufferLength();
if (len > 0xffffffff)
{
mdcmAlwaysWarnMacro("TryJPEG2000Codec: size " << len << " is not supported");
mdcmAlwaysWarnMacro("JPEG2000Codec: size " << len << " is not supported");
return false;
}
if (codec.CanDecode(ts))
Expand Down Expand Up @@ -1128,7 +1128,7 @@ Bitmap::TryRLECodec(char * buffer, bool & lossyflag) const
const unsigned long long len = GetBufferLength();
if (len > 0xffffffff)
{
mdcmAlwaysWarnMacro("TryRLECodec: size " << len << " is not supported");
mdcmAlwaysWarnMacro("RLECodec: size " << len << " is not supported");
return false;
}
const TransferSyntax & ts = GetTransferSyntax();
Expand Down
33 changes: 3 additions & 30 deletions mdcm/Source/MediaStorageAndFileFormat/mdcmRAWCodec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,14 @@
#include "mdcmByteSwap.h"
#include "mdcmDataElement.h"
#include "mdcmSequenceOfFragments.h"
#include "mdcmUnpacker12Bits.h"
#include <limits>
#include <sstream>
#include <cstring>

namespace mdcm
{

// Unpack an array of 'packed' 12bits data into a more conventional 16bits
// array. n is the length in bytes of array in, out will be a 16bits
// array of size (n / 3) * 2
static bool
Unpack12Bits(char * out, const char * in, size_t n)
{
// 3 bytes = 2 words
// http:https://groups.google.com/group/comp.lang.c/msg/572bc9b085c717f3
if (n % 3)
{
return false;
}
void * vout = static_cast<void*>(out);
const void * vin = static_cast<const void*>(in);
short * q = static_cast<short *>(vout);
const unsigned char * p = static_cast<const unsigned char *>(vin);
const unsigned char * end = p + n;
while (p != end)
{
const unsigned char b0 = *p++;
const unsigned char b1 = *p++;
const unsigned char b2 = *p++;
*q++ = static_cast<short>(((b1 & 0xf) << 8) + b0);
*q++ = static_cast<short>((b1 >> 4) + (b2 << 4));
}
return true;
}

bool
RAWCodec::CanCode(const TransferSyntax & ts) const
{
Expand Down Expand Up @@ -124,7 +97,7 @@ RAWCodec::Decode(const DataElement & in, DataElement & out)
{
return false;
}
const bool b = Unpack12Bits(copy, str.data(), str.size());
const bool b = Unpacker12Bits::Unpack(copy, str.data(), str.size());
if (!b)
{
delete[] copy;
Expand Down Expand Up @@ -206,7 +179,7 @@ RAWCodec::DecodeBytes(const char * inBytes, size_t inBufferLength, char * outByt
{
return false;
}
const bool b = Unpack12Bits(copy, str.data(), str.size());
const bool b = Unpacker12Bits::Unpack(copy, str.data(), str.size());
if (!b)
{
delete[] copy;
Expand Down

0 comments on commit 8631e4a

Please sign in to comment.