Skip to content
Commits on Source (4)
......@@ -1203,9 +1203,9 @@ int main (int argc, char *argv[])
gdcm::ByteValue *bv = new gdcm::ByteValue();
bv->SetLength( (uint32_t)len );
//memcpy( bv->GetPointer(), imageori
imageori.GetBuffer( (char*)bv->GetPointer() );
imageori.GetBuffer( (char*)bv->GetVoidPointer() );
// Rub out pixels:
char *p = (char*)bv->GetPointer();
char *p = (char*)bv->GetVoidPointer();
switch(pixeltype)
{
case gdcm::PixelFormat::UINT8:
......
......@@ -1415,7 +1415,7 @@ int main (int argc, char *argv[])
//std::cout << image << std::endl;
const gdcm::DataElement &pixeldata = image.GetDataElement();
//const gdcm::ByteValue *bv = pixeldata.GetByteValue();
gdcm::SmartPointer<gdcm::ByteValue> bv = (gdcm::ByteValue*)pixeldata.GetByteValue();
gdcm::SmartPointer<gdcm::ByteValue> bv = const_cast<gdcm::ByteValue*>(pixeldata.GetByteValue());
unsigned long slice_len = image.GetBufferLength() / dims[2];
assert( slice_len * dims[2] == image.GetBufferLength() );
//assert( image.GetBufferLength() == bv->GetLength() );
......
......@@ -17,7 +17,7 @@ endif()
#----------------------------------------------------------------------------
project(GDCM
VERSION 3.0.3
VERSION 3.0.4
LANGUAGES CXX C
)
## NOTE: the "DESCRIPTION" feature of project() was introduced in cmake 3.10.0
......
......@@ -131,7 +131,7 @@ static bool ProcessDeflate( const char *outfilename, const int nslices, const
uLongf destLen = buf_size; // >= 608,427
Bytef *dest = (Bytef*)&outbuf[0];
assert( is.tellg() == offsets[r] + 16 );
const Bytef *source = (Bytef*)buf + offsets[r] + 16;
const Bytef *source = (const Bytef*)buf + offsets[r] + 16;
uLong sourceLen;
if( r + 1 == nframes )
sourceLen = (uLong)totalsize - (uLong)offsets[r] - 16;
......
......@@ -43,7 +43,7 @@ bool dumpargs(std::ostream & os, T c1, T c2, T c3, T c4, T c5, T c6, T c7, T c8)
bool wave2stream( std::ostream &text_file, const char *in, size_t len )
{
short * buffer = (short*)in;
const short * buffer = (const short*)in;
size_t length = len / sizeof( short );
text_file << "COMPLETE_WAVE" << '\t' << "MASK" << '\t' << "AQUISITION_PROFIL" << '\t' << "END-INHALE" << '\t' << "END-EXHALE" << '\t' << "AQUISITION_WAVE" << '\t' << "WAVE_STATISTICS" << '\t' << "MASK" << std::endl;
for (size_t i=0;i<length-76;i+=2)
......
......@@ -62,8 +62,8 @@ int main(int argc, char *argv[])
}
const gdcm::Fragment &frag0 = sqf->GetFragment(0);
const gdcm::ByteValue *bv = frag0.GetByteValue();
const char *ptr = bv->GetPointer();
gdcm::ByteValue *bv = const_cast<gdcm::ByteValue*>(frag0.GetByteValue());
char *ptr = (char*)bv->GetVoidPointer();
size_t len = bv->GetLength();
static const unsigned char sig[] = {0,0,0,0,0x6A,0x70,0x32,0x63};
......@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
// Apparently the flag to enable a color transform on 3 color components is set in
// the COD marker. (YCC is byte[6] in the COD marker)
// we need to disable this flag;
const char *cod_marker = ptr + 0x35; /* 0x2d + 0x8 */ // FIXME
char *cod_marker = ptr + 0x35; /* 0x2d + 0x8 */ // FIXME
if( cod_marker[0] == (char)0xff && cod_marker[1] == 0x52 )
{
// found start of COD
......
......@@ -54,7 +54,7 @@ void delta_decode(const unsigned char *data_in, size_t data_size,
REPEATMODE = 0x83
};
byte* src = (byte*)data_in;
const byte* src = (const byte*)data_in;
byte* dest = (byte*)&new_stream[0];
union { byte gray; byte rgb[3]; } pixel;
pixel.rgb[0] = pixel.rgb[1] = pixel.rgb[2] = 0;
......
......@@ -75,7 +75,7 @@ bool ASN1::ParseDump(const char *array, size_t length)
out=BIO_new(BIO_s_file());
assert( out );
BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT);
if (!ASN1_parse_dump(out,(unsigned char*)array,length,indent,dump) )
if (!ASN1_parse_dump(out,(const unsigned char*)array,length,indent,dump) )
{
return false;
}
......@@ -119,14 +119,14 @@ int ASN1::TestPBKDF2()
unsigned char buf[1024];
ic = 1;
PKCS5_PBKDF2_HMAC_SHA1(pass, (int)strlen(pass), (unsigned char*)salt,
PKCS5_PBKDF2_HMAC_SHA1(pass, (int)strlen(pass), (const unsigned char*)salt,
(int)strlen(salt), ic, 32+16, buf);
printf("PKCS5_PBKDF2_HMAC_SHA1(\"%s\", \"%s\", %d)=\n", pass, salt, ic);
print_hex(buf, 32+16);
ic = 1;
EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), (unsigned char*)salt,
(unsigned char*)pass, (int)strlen(pass), ic, buf, buf+32);
EVP_BytesToKey(EVP_aes_256_cbc(), EVP_sha1(), (const unsigned char*)salt,
(const unsigned char*)pass, (int)strlen(pass), ic, buf, buf+32);
printf("EVP_BytesToKey(\"%s\", \"%s\", %d)=\n", pass, salt, ic);
print_hex(buf, 32+16);
......
......@@ -97,7 +97,7 @@ bool OpenSSLCryptographicMessageSyntax::Encrypt(char *output, size_t &outlen, co
goto err;
}
in = BIO_new_mem_buf((void*)array, (int)len);
in = BIO_new_mem_buf((const void*)array, (int)len);
if(!in)
{
gdcmErrorMacro( "Error at creating the input memory buffer." );
......@@ -183,7 +183,7 @@ bool OpenSSLCryptographicMessageSyntax::Decrypt(char *output, size_t &outlen, co
goto err;
}
in = BIO_new_mem_buf((void*)array, (int)len);
in = BIO_new_mem_buf((const void*)array, (int)len);
if (!in)
{
gdcmErrorMacro( "Error at creating the input memory buffer." );
......
......@@ -153,7 +153,7 @@ public:
gdcmErrorMacro( "len is too big: " << len );
return false;
}
BIO *data = BIO_new_mem_buf((void*)array, (int)len);
BIO *data = BIO_new_mem_buf((const void*)array, (int)len);
if(!data)
{
gdcmErrorMacro( "BIO_new_mem_buf" );
......@@ -308,7 +308,7 @@ bool OpenSSLP7CryptographicMessageSyntax::Decrypt(char *output, size_t &outlen,
gdcmErrorMacro( "len is too big: " << len );
return false;
}
data = BIO_new_mem_buf((void*)array, (int)len);
data = BIO_new_mem_buf((const void*)array, (int)len);
if(!data) goto err;
......
......@@ -446,6 +446,7 @@ static const LossyFile gdcmLossyFilenames[] = {
{ 0,"EnhancedWithIPPPerFrameIOPShared.dcm" },
{ 0,"FUJI-ffff-MONO1-J2K.dcm" },
{ 0,"JPEGLosslessSeNonZero.dcm" },
{ 1,"US-YBR_FULL_422-EVRLE.dcm" },
{ 0, nullptr }
};
......
......@@ -40,8 +40,8 @@ bool Unpacker12Bits::Pack(char *out, const char *in, size_t n)
{
if( n % 4 ) return false; // we need an even number of 'words' so that 2 words are split in 3 bytes
unsigned char *q = (unsigned char*)out;
const unsigned short *p = (const unsigned short*)(void*)in;
const unsigned short *end = (const unsigned short*)(void*)(in+n);
const unsigned short *p = (const unsigned short*)(const void*)in;
const unsigned short *end = (const unsigned short*)(const void*)(in+n);
unsigned short b0,b1;
while(p!=end)
......
......@@ -39,7 +39,7 @@ bool ByteSwapFilter::ByteSwap()
const DataElement &de = *it;
VR const & vr = de.GetVR();
//assert( vr & VR::VRASCII || vr & VR::VRBINARY );
const ByteValue *bv = de.GetByteValue();
ByteValue *bv = const_cast<ByteValue*>(de.GetByteValue());
gdcm::SmartPointer<gdcm::SequenceOfItems> si = de.GetValueAsSQ();
if( de.IsEmpty() )
{
......
......@@ -117,6 +117,10 @@ public:
if(!Internal.empty()) return &Internal[0];
return nullptr;
}
void *GetVoidPointer() {
if(!Internal.empty()) return &Internal[0];
return nullptr;
}
void Fill(char c) {
//if( Internal.empty() ) return;
std::vector<char>::iterator it = Internal.begin();
......
......@@ -38,7 +38,7 @@ template <typename TSwap>
std::istream &CP246ExplicitDataElement::ReadPreValue(std::istream &is)
{
TagField.Read<TSwap>(is);
// See PS 3.5, Data Element Structure With CP246Explicit VR
// See PS 3.5, Data Element Structure With Explicit VR
// Read Tag
if( !is )
{
......
......@@ -993,7 +993,7 @@ bool CSAHeader::LoadFromDataElement(DataElement const &de)
// Some silly software consider the tag to be OW, therefore they byteswap it !!! sigh
if( strcmp( signature, "VS01" ) == 0 )
{
SwapperDoOp::SwapArray( (unsigned short*)(void*)s.c_str(), (s.size() + 1) / 2 );
SwapperDoOp::SwapArray( (unsigned short*)(void*)&s[0], (s.size() + 1) / 2 );
ss.str( s );
ss.read(signature, 4);
}
......
......@@ -419,6 +419,24 @@ namespace gdcm_ns
is.seekg(-6, std::ios::cur );
length = locallength = l;
}
else if( /*pe.GetLastElement().GetTag() == Tag(0xffd8,0xffe0) &&*/ de.GetTag() == Tag(0x7fe0,0x0010) && de.IsUndefinedLength() )
{
// PET-GE-dicomwrite-PixelDataSQUN.dcm
// some bozo crafted an undefined length Pixel Data but is actually
// defined length. Since inside SQ/Item it should be possible to
// compute the proper length
is.seekg(-16, std::ios::cur );
TDE pd;
pd.template ReadPreValue<TSwap>(is);
gdcmAssertAlwaysMacro( pd.GetTag() == Tag(0x7fe0,0x0010) );
gdcmAssertAlwaysMacro( pd.GetVR() == VR::OB );
gdcmAssertAlwaysMacro( pd.IsUndefinedLength() );
const VL pdlen = locallength - l - 12;
pd.SetVL( pdlen );
pd.template ReadValue<TSwap>(is, true);
InsertDataElement( pd );
length = locallength = l;
}
else
{
// Could be the famous :
......
......@@ -829,29 +829,78 @@ bool Reader::CanRead() const
#ifdef _MSC_VER
namespace {
static inline std::wstring ToUtf16(std::string str) {
static inline std::wstring ToUtf16(std::string const & str) {
std::wstring ret;
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0);
int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.length(), nullptr, 0);
if (len > 0) {
ret.resize(len);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &ret[0], len);
MultiByteToWideChar(CP_UTF8, 0, str.c_str(), (int)str.length(), &ret[0], len);
}
return ret;
}
// http://arsenmk.blogspot.com/2015/12/handling-long-paths-on-windows.html
static inline bool ComputeFullPath(std::wstring const &in, std::wstring &out) {
// consider an input fileName of type PCWSTR (const wchar_t*)
const wchar_t *fileName = in.c_str();
DWORD requiredBufferLength = GetFullPathNameW(fileName, 0, nullptr, nullptr);
if (0 == requiredBufferLength) // means failure
{
return false;
}
out.resize(requiredBufferLength);
wchar_t *buffer = &out[0];
DWORD result =
GetFullPathNameW(fileName, requiredBufferLength, buffer, nullptr);
if (0 == result) {
return false;
}
// buffer now contains the full path name of fileName, use it.
return true;
}
static inline std::wstring HandleMaxPath(std::wstring const &in) {
if (in.size() >= MAX_PATH) {
std::wstring out;
bool ret = ComputeFullPath(in, out);
if (!ret) return in;
if (out.size() < 4) return in;
if (out[0] == '\\' && out[1] == '\\' && out[2] == '?') {
// nothing to do
} else if (out[0] == '\\' && out[1] == '\\' && out[2] != '?') {
// server path
const std::wstring prefix = LR"(\\?\UNC\)";
out = prefix + (out.c_str() + 2);
} else {
// regular C:\ style path:
assert(out[1] == ':');
const std::wstring prefix = LR"(\\?\)";
out = prefix + out.c_str();
}
return out;
}
return in;
}
} // namespace
#endif
void Reader::SetFileName(const char *uft8path)
{
if(Ifstream) delete Ifstream;
Ifstream = new std::ifstream();
Ifstream->open(
if (uft8path && *uft8path) {
#ifdef _MSC_VER
ToUtf16(uft8path).c_str()
const std::wstring uft16path = ToUtf16(uft8path);
const std::wstring uncpath = HandleMaxPath(uft16path);
Ifstream->open(uncpath.c_str(), std::ios::binary);
#else
uft8path
Ifstream->open( uft8path, std::ios::binary);
#endif
, std::ios::binary);
}
if( Ifstream->is_open() )
{
Stream = Ifstream;
......
......@@ -264,7 +264,7 @@ unsigned long Bitmap::GetBufferLength() const
std::vector<unsigned int>::const_iterator it = Dimensions.begin();
for(; it != Dimensions.end(); ++it)
{
assert( *it );
if( *it == 0 ) gdcmWarningMacro("Dimension has been found to be zero" );
mul *= *it;
}
// Multiply by the pixel size:
......@@ -313,7 +313,7 @@ unsigned long Bitmap::GetBufferLength() const
}
len = mul;
assert( len != 0 );
//assert( len != 0 );
return len;
}
......@@ -326,6 +326,10 @@ bool Bitmap::TryRAWCodec(char *buffer, bool &lossyflag) const
if( codec.CanDecode( ts ) ) // short path
{
lossyflag = false;
if( GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL_422 )
{
lossyflag = true;
}
return true;
}
return false;
......@@ -408,12 +412,31 @@ bool Bitmap::TryJPEGCodec(char *buffer, bool &lossyflag) const
Bitmap *i = (Bitmap*)this;
i->SetPixelFormat( codec.GetPixelFormat() );
}
#else
const PixelFormat & cpf = codec.GetPixelFormat();
// SC16BitsAllocated_8BitsStoredJPEG.dcm
if( cpf.GetBitsAllocated() <= pf.GetBitsAllocated() )
{
if( cpf.GetPixelRepresentation() == pf.GetPixelRepresentation() )
{
if( cpf.GetSamplesPerPixel() == pf.GetSamplesPerPixel() )
{
if( cpf.GetBitsStored() < pf.GetBitsStored() )
{
Bitmap *i = const_cast<Bitmap*>(this);
gdcmWarningMacro( "Encapsulated stream has fewer bits actually stored on disk. correcting." );
i->GetPixelFormat().SetBitsAllocated( cpf.GetBitsAllocated() );
i->GetPixelFormat().SetBitsStored( cpf.GetBitsStored() );
}
}
}
}
#endif
if( GetDimensions()[0] != codec.GetDimensions()[0]
|| GetDimensions()[1] != codec.GetDimensions()[1] )
{
gdcmWarningMacro( "dimension mismatch for JPEG" );
((Bitmap*)this)->SetDimensions( codec.GetDimensions() ); //JPEGNote_bogus.dcm
(const_cast<Bitmap*>(this))->SetDimensions( codec.GetDimensions() ); //JPEGNote_bogus.dcm
}
return true;
......@@ -441,7 +464,7 @@ bool Bitmap::TryJPEGCodec(char *buffer, bool &lossyflag) const
// Did PI change or not ?
if ( GetPlanarConfiguration() != codec.GetPlanarConfiguration() )
{
Bitmap *i = (Bitmap*)this; (void)i;
Bitmap *i = const_cast<Bitmap*>(this); (void)i;
//i->SetPlanarConfiguration( codec.GetPlanarConfiguration() );
}
// I cannot re-activate the following since I would loose the palette color information
......@@ -454,16 +477,38 @@ bool Bitmap::TryJPEGCodec(char *buffer, bool &lossyflag) const
// i->SetPhotometricInterpretation( codec.GetPhotometricInterpretation() );
// }
#if 1
if ( GetPixelFormat() != codec.GetPixelFormat() )
const PixelFormat & cpf = codec.GetPixelFormat();
const PixelFormat & pf = GetPixelFormat();
if ( pf != cpf )
{
// gdcmData/DCMTK_JPEGExt_12Bits.dcm
assert( GetPixelFormat().GetPixelRepresentation() ==
codec.GetPixelFormat().GetPixelRepresentation() );
// assert( GetPixelFormat().GetBitsStored() ==
// codec.GetPixelFormat().GetBitsStored() );
assert( GetPixelFormat().GetBitsAllocated() == 12 );
Bitmap *i = (Bitmap*)this;
i->SetPixelFormat( codec.GetPixelFormat() );
if( pf.GetPixelRepresentation() == cpf.GetPixelRepresentation() ) {
if( pf.GetBitsAllocated() == 12 ) {
Bitmap *i = const_cast<Bitmap*>(this);
i->GetPixelFormat().SetBitsAllocated( 16 );
i->GetPixelFormat().SetBitsStored( 12 );
}
}
}
#else
const PixelFormat & cpf = codec.GetPixelFormat();
const PixelFormat & pf = GetPixelFormat();
// SC16BitsAllocated_8BitsStoredJPEG.dcm
if( cpf.GetBitsAllocated() <= pf.GetBitsAllocated() )
{
if( cpf.GetPixelRepresentation() == pf.GetPixelRepresentation() )
{
if( cpf.GetSamplesPerPixel() == pf.GetSamplesPerPixel() )
{
if( cpf.GetBitsStored() < pf.GetBitsStored() )
{
Bitmap *i = const_cast<Bitmap*>(this);
gdcmWarningMacro( "Encapsulated stream has fewer bits actually stored on disk. correcting." );
i->GetPixelFormat().SetBitsAllocated( cpf.GetBitsAllocated() );
i->GetPixelFormat().SetBitsStored( cpf.GetBitsStored() );
}
}
}
}
#endif
//if ( GetPhotometricInterpretation() == PhotometricInterpretation::YBR_FULL_422
......@@ -557,7 +602,7 @@ bool Bitmap::TryPVRGCodec(char *buffer, bool &lossyflag) const
assert( r );
if ( GetPlanarConfiguration() != codec.GetPlanarConfiguration() )
{
Bitmap *i = (Bitmap*)this;
Bitmap *i = const_cast<Bitmap*>(this);
i->PlanarConfiguration = codec.GetPlanarConfiguration();
}
const ByteValue *outbv = out.GetByteValue();
......@@ -750,7 +795,7 @@ bool Bitmap::TryJPEG2000Codec(char *buffer, bool &lossyflag) const
{
if( cpf.GetBitsStored() < pf.GetBitsStored() )
{
Bitmap *i = (Bitmap*)this;
Bitmap *i = const_cast<Bitmap*>(this);
gdcmWarningMacro( "Encapsulated stream has fewer bits actually stored on disk. correcting." );
i->GetPixelFormat().SetBitsStored( cpf.GetBitsStored() );
}
......@@ -761,7 +806,7 @@ bool Bitmap::TryJPEG2000Codec(char *buffer, bool &lossyflag) const
{
// SC16BitsAllocated_8BitsStoredJ2K.dcm
gdcmWarningMacro( "Bits Allocated are different. This is pretty bad using info from codestream" );
Bitmap *i = (Bitmap*)this;
Bitmap *i = const_cast<Bitmap*>(this);
i->SetPixelFormat( codec.GetPixelFormat() );
}
#endif
......@@ -817,7 +862,7 @@ bool Bitmap::TryJPEG2000Codec(char *buffer, bool &lossyflag) const
{
if( cpf.GetBitsStored() < pf.GetBitsStored() )
{
Bitmap *i = (Bitmap*)this;
Bitmap *i = const_cast<Bitmap*>(this);
gdcmWarningMacro( "Encapsulated stream has fewer bits actually stored on disk. correcting." );
i->GetPixelFormat().SetBitsStored( cpf.GetBitsStored() );
}
......
......@@ -78,7 +78,7 @@ public:
os << "TypeOfData :" << TypeOfData << std::endl;
os << "CurveDescription :" << CurveDescription << std::endl;
os << "DataValueRepresentation :" << DataValueRepresentation << std::endl;
const unsigned short * p = (const unsigned short*)(void*)&Data[0];
const unsigned short * p = (const unsigned short*)(const void*)&Data[0];
for(int i = 0; i < NumberOfPoints; i+=2)
{
os << p[i] << "," << p[i+1] << std::endl;
......