Skip to content

Commit f57e451

Browse files
committed
Better support for fake 12bits
1 parent 858eac9 commit f57e451

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

Source/MediaStorageAndFileFormat/gdcmBitmap.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,17 @@ bool Bitmap::TryRAWCodec(char *buffer, bool &lossyflag) const
375375
Bitmap *i = (Bitmap*)this;
376376
i->SetPixelFormat( codec.GetPixelFormat() );
377377
}
378+
#else
379+
const PixelFormat pf = GetPixelFormat(); // PixelFormat::UINT8;
380+
const PixelFormat & cpf = codec.GetPixelFormat();
381+
if( cpf.GetBitsAllocated() == 16 && pf.GetBitsAllocated() == 12 )
382+
{
383+
Bitmap *i = const_cast<Bitmap*>(this);
384+
gdcmWarningMacro( "Mismatch Bits Allocated. correcting." );
385+
i->GetPixelFormat().SetBitsAllocated( cpf.GetBitsAllocated() );
386+
i->GetPixelFormat().SetBitsStored( pf.GetBitsStored() );
387+
i->GetPixelFormat().SetHighBit( pf.GetHighBit() );
388+
}
378389
#endif
379390

380391
unsigned long check; // = outbv->GetLength(); // FIXME

Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,35 @@ bool RAWCodec::DecodeBytes(const char* inBytes, size_t inBufferLength,
116116
if( this->GetPixelFormat() == PixelFormat::UINT12 ||
117117
this->GetPixelFormat() == PixelFormat::INT12 )
118118
{
119-
size_t len = str.size() * 16 / 12;
120-
char * copy = new char[len];
121-
bool b = Unpacker12Bits::Unpack(copy, str.data(), str.size() );
122-
if (!b)
123-
{
124-
delete[] copy;
125-
return false;
126-
}
127-
gdcm_assert(inOutBufferLength == len);
128-
memcpy(outBytes, copy, len);
129-
130-
delete[] copy;
131-
132119
this->GetPixelFormat().SetBitsAllocated( 16 );
120+
const size_t len = str.size() * 16 / 12;
121+
if(len == inOutBufferLength) {
122+
char * copy = new char[len];
123+
bool b = Unpacker12Bits::Unpack(copy, str.data(), str.size() );
124+
if (!b)
125+
{
126+
delete[] copy;
127+
return false;
128+
}
129+
gdcm_assert(inOutBufferLength == len);
130+
memcpy(outBytes, copy, len);
131+
132+
delete[] copy;
133+
return r;
133134
}
135+
}
136+
137+
// DermaColorLossLess.dcm
138+
//assert (check == inOutBufferLength || check == inOutBufferLength + 1);
139+
// problem with: SIEMENS_GBS_III-16-ACR_NEMA_1.acr
140+
size_t len = str.size();
141+
if( inOutBufferLength <= len )
142+
memcpy(outBytes, str.c_str(), inOutBufferLength);
134143
else
135-
{
136-
// DermaColorLossLess.dcm
137-
//assert (check == inOutBufferLength || check == inOutBufferLength + 1);
138-
// problem with: SIEMENS_GBS_III-16-ACR_NEMA_1.acr
139-
size_t len = str.size();
140-
if( inOutBufferLength <= len )
141-
memcpy(outBytes, str.c_str(), inOutBufferLength);
142-
else
143-
{
144-
gdcmWarningMacro( "Requesting too much data. Truncating result" );
145-
memcpy(outBytes, str.c_str(), len);
146-
}
147-
}
144+
{
145+
gdcmWarningMacro( "Requesting too much data. Truncating result" );
146+
memcpy(outBytes, str.c_str(), len);
147+
}
148148

149149
return r;
150150
}

0 commit comments

Comments
 (0)