+2004-12-10 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
+ * src/gdcmFile.[h|cxx], gdcmPixelReadConvert.[h|cxx] : change the API.
+ Rename Decompressed to Raw
+ * Use the API changes in gdcm::File.
+ * vtk/vtkGdcmWriter.[h|cxx] : add the possibility to write in other modes
+ Memory leaks fixed
+
2004-12-10 Benoit Regrain <Benoit.Regrain@creatis.insa-lyon.fr>
* vtk/vtkGdcmWriter.cxx, Example/WriteDicomSimple.cxx : add comments for
each added entry in the header. Replace the 'Planes' field by the 'Number
Program: gdcm
Module: $RCSfile: WriteDicomSimple.cxx,v $
Language: C++
- Date: $Date: 2004/12/10 08:34:07 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2004/12/10 13:49:06 $
+ Version: $Revision: 1.3 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
std::string fileName = argv[1];
std::string mode = argv[2];
- file->SetWriteModeToDecompressed();
+ file->SetWriteModeToRaw();
switch (mode[0])
{
case 'a' : // Write an ACR file
Program: gdcm
Module: $RCSfile: TestAllEntryVerify.cxx,v $
Language: C++
- Date: $Date: 2004/12/04 08:57:20 $
- Version: $Revision: 1.16 $
+ Date: $Date: 2004/12/10 13:49:06 $
+ Version: $Revision: 1.17 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
}
Parser.SetDataPath(referenceDir);
// Parser.Print();
- std::cout << "Reference fil loaded -->\n"
+ std::cout << "Reference file loaded -->\n"
<< "Check files : \n";
int ret;
Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/12/07 13:39:33 $
- Version: $Revision: 1.149 $
+ Date: $Date: 2004/12/10 13:49:07 $
+ Version: $Revision: 1.150 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
reversedEndian--;
SwitchSwapToBigEndian();
}
-
}
/**
Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2004/12/07 17:28:50 $
- Version: $Revision: 1.174 $
+ Date: $Date: 2004/12/10 13:49:07 $
+ Version: $Revision: 1.175 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
Initialise();
}
-/**
- * \brief Factorization for various forms of constructors.
- */
-void File::Initialise()
-{
- WriteMode = WMODE_DECOMPRESSED;
- WriteType = ExplicitVR;
-
- PixelReadConverter = new PixelReadConvert;
- PixelWriteConverter = new PixelWriteConvert;
- Archive = new DocEntryArchive( HeaderInternal );
-
- if ( HeaderInternal->IsReadable() )
- {
- PixelReadConverter->GrabInformationsFromHeader( HeaderInternal );
- }
-}
-
/**
* \brief canonical destructor
* \note If the Header was created by the File constructor,
*/
size_t File::GetImageDataSize()
{
+ if ( PixelWriteConverter->GetUserData() )
+ {
+ return PixelWriteConverter->GetUserDataSize();
+ }
+
return PixelReadConverter->GetRGBSize();
}
*/
size_t File::GetImageDataRawSize()
{
- return PixelReadConverter->GetDecompressedSize();
+ if ( PixelWriteConverter->GetUserData() )
+ {
+ return PixelWriteConverter->GetUserDataSize();
+ }
+
+ return PixelReadConverter->GetRawSize();
}
/**
*/
uint8_t* File::GetImageData()
{
- if ( ! GetDecompressed() )
+ if ( PixelWriteConverter->GetUserData() )
+ {
+ return PixelWriteConverter->GetUserData();
+ }
+
+ if ( ! GetRaw() )
{
// If the decompression failed nothing can be done.
return 0;
}
else
{
- // When no LUT or LUT conversion fails, return the decompressed
- return PixelReadConverter->GetDecompressed();
+ // When no LUT or LUT conversion fails, return the Raw
+ return PixelReadConverter->GetRaw();
}
}
+/**
+ * \brief Allocates necessary memory,
+ * Transforms YBR pixels (if any) into RGB pixels
+ * Transforms 3 planes R, G, B (if any) into a single RGB Plane
+ * Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
+ * DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
+ * @return Pointer to newly allocated pixel data.
+ * \ NULL if alloc fails
+ */
+uint8_t* File::GetImageDataRaw ()
+{
+ return GetRaw();
+}
+
/**
* \brief
* Read the pixels from disk (uncompress if necessary),
*/
size_t File::GetImageDataIntoVector (void* destination, size_t maxSize)
{
- if ( ! GetDecompressed() )
+ if ( ! GetRaw() )
{
// If the decompression failed nothing can be done.
return 0;
}
// Either no LUT conversion necessary or LUT conversion failed
- if ( PixelReadConverter->GetDecompressedSize() > maxSize )
+ if ( PixelReadConverter->GetRawSize() > maxSize )
{
dbg.Verbose(0, "File::GetImageDataIntoVector: pixel data bigger"
"than caller's expected MaxSize");
return 0;
}
memcpy( destination,
- (void*)PixelReadConverter->GetDecompressed(),
- PixelReadConverter->GetDecompressedSize() );
- return PixelReadConverter->GetDecompressedSize();
-}
-
-/**
- * \brief Allocates necessary memory,
- * Transforms YBR pixels (if any) into RGB pixels
- * Transforms 3 planes R, G, B (if any) into a single RGB Plane
- * Copies the pixel data (image[s]/volume[s]) to newly allocated zone.
- * DOES NOT transform Grey plane + 3 Palettes into a RGB Plane
- * @return Pointer to newly allocated pixel data.
- * \ NULL if alloc fails
- */
-uint8_t* File::GetImageDataRaw ()
-{
- return GetDecompressed();
-}
-
-uint8_t* File::GetDecompressed()
-{
- uint8_t* decompressed = PixelReadConverter->GetDecompressed();
- if ( ! decompressed )
- {
- // The decompressed image migth not be loaded yet:
- std::ifstream* fp = HeaderInternal->OpenFile();
- PixelReadConverter->ReadAndDecompressPixelData( fp );
- if(fp)
- HeaderInternal->CloseFile();
-
- decompressed = PixelReadConverter->GetDecompressed();
- if ( ! decompressed )
- {
- dbg.Verbose(0, "File::GetDecompressed: read/decompress of "
- "pixel data apparently went wrong.");
- return 0;
- }
- }
-
- return decompressed;
+ (void*)PixelReadConverter->GetRaw(),
+ PixelReadConverter->GetRawSize() );
+ return PixelReadConverter->GetRawSize();
}
/**
*
* @return boolean
*/
-bool File::SetImageData(uint8_t* inData, size_t expectedSize)
+void File::SetImageData(uint8_t* inData, size_t expectedSize)
{
- PixelWriteConverter->SetUserData(inData,expectedSize);
+ SetUserData(inData,expectedSize);
+}
- return true;
+/**
+ * \brief Set the image datas defined by the user
+ * \warning When writting the file, this datas are get as default datas to write
+ */
+void File::SetUserData(uint8_t* data, size_t expectedSize)
+{
+ PixelWriteConverter->SetUserData(data,expectedSize);
+}
+
+/**
+ * \brief Get the image datas defined by the user
+ * \warning When writting the file, this datas are get as default datas to write
+ */
+uint8_t* File::GetUserData()
+{
+ return PixelWriteConverter->GetUserData();
+}
+
+/**
+ * \brief Get the image data size defined by the user
+ * \warning When writting the file, this datas are get as default datas to write
+ */
+size_t File::GetUserDataSize()
+{
+ return PixelWriteConverter->GetUserDataSize();
+}
+
+/**
+ * \brief Get the image datas from the file.
+ * If a LUT is found, the datas are expanded to be RGB
+ */
+uint8_t* File::GetRGBData()
+{
+ return PixelReadConverter->GetRGB();
+}
+
+/**
+ * \brief Get the image data size from the file.
+ * If a LUT is found, the datas are expanded to be RGB
+ */
+size_t File::GetRGBDataSize()
+{
+ return PixelReadConverter->GetRGBSize();
+}
+
+/**
+ * \brief Get the image datas from the file.
+ * If a LUT is found, the datas are not expanded !
+ */
+uint8_t* File::GetRawData()
+{
+ return PixelReadConverter->GetRaw();
+}
+
+/**
+ * \brief Get the image data size from the file.
+ * If a LUT is found, the datas are not expanded !
+ */
+size_t File::GetRawDataSize()
+{
+ return PixelReadConverter->GetRawSize();
}
/**
fp1.write((char*)PixelWriteConverter->GetUserData(), PixelWriteConverter->GetUserDataSize());
else if(PixelReadConverter->GetRGB())
fp1.write((char*)PixelReadConverter->GetRGB(), PixelReadConverter->GetRGBSize());
- else if(PixelReadConverter->GetDecompressed())
- fp1.write((char*)PixelReadConverter->GetDecompressed(), PixelReadConverter->GetDecompressedSize());
+ else if(PixelReadConverter->GetRaw())
+ fp1.write((char*)PixelReadConverter->GetRaw(), PixelReadConverter->GetRawSize());
fp1.close();
switch(WriteMode)
{
- case WMODE_DECOMPRESSED :
- SetWriteToDecompressed();
+ case WMODE_RAW :
+ SetWriteToRaw();
break;
case WMODE_RGB :
SetWriteToRGB();
switch(WriteMode)
{
- case WMODE_DECOMPRESSED :
+ case WMODE_RAW :
if( decSize!=PixelWriteConverter->GetUserDataSize() )
{
- dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
+ dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect (Raw)");
+ //std::cerr << "File::CheckWriteIntegrity: Data size is incorrect (Raw)\n"
+ // << decSize << " / " << PixelWriteConverter->GetUserDataSize() << "\n";
return false;
}
break;
case WMODE_RGB :
if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
{
- dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect");
+ dbg.Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect (RGB)");
+ //std::cerr << "File::CheckWriteIntegrity: Data size is incorrect (RGB)\n"
+ // << decSize << " / " << PixelWriteConverter->GetUserDataSize() << "\n";
return false;
}
break;
return true;
}
-void File::SetWriteToDecompressed()
+void File::SetWriteToRaw()
{
if(HeaderInternal->GetNumberOfScalarComponents()==3 && !HeaderInternal->HasLUT())
{
photInt->SetValue("MONOCHROME1 ");
}
- PixelWriteConverter->SetReadData(PixelReadConverter->GetDecompressed(),
- PixelReadConverter->GetDecompressedSize());
+ PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
+ PixelReadConverter->GetRawSize());
BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
pixel->SetValue(GDCM_BINLOADED);
PixelWriteConverter->SetReadData(PixelReadConverter->GetRGB(),
PixelReadConverter->GetRGBSize());
}
- else // Decompressed data
+ else // Raw data
{
- PixelWriteConverter->SetReadData(PixelReadConverter->GetDecompressed(),
- PixelReadConverter->GetDecompressedSize());
+ PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(),
+ PixelReadConverter->GetRawSize());
}
BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel());
}
else
{
- SetWriteToDecompressed();
+ SetWriteToRaw();
}
}
return(newE);
}
+//-----------------------------------------------------------------------------
+// Protected
+/**
+ * \brief Factorization for various forms of constructors.
+ */
+void File::Initialise()
+{
+ WriteMode = WMODE_RAW;
+ WriteType = ExplicitVR;
+
+ PixelReadConverter = new PixelReadConvert;
+ PixelWriteConverter = new PixelWriteConvert;
+ Archive = new DocEntryArchive( HeaderInternal );
+
+ if ( HeaderInternal->IsReadable() )
+ {
+ PixelReadConverter->GrabInformationsFromHeader( HeaderInternal );
+ }
+}
+
+uint8_t* File::GetRaw()
+{
+ uint8_t* raw = PixelReadConverter->GetRaw();
+ if ( ! raw )
+ {
+ // The Raw image migth not be loaded yet:
+ std::ifstream* fp = HeaderInternal->OpenFile();
+ PixelReadConverter->ReadAndDecompressPixelData( fp );
+ if(fp)
+ HeaderInternal->CloseFile();
+
+ raw = PixelReadConverter->GetRaw();
+ if ( ! raw )
+ {
+ dbg.Verbose(0, "File::GetRaw: read/decompress of "
+ "pixel data apparently went wrong.");
+ return 0;
+ }
+ }
+
+ return raw;
+}
+
//-----------------------------------------------------------------------------
// Private
Program: gdcm
Module: $RCSfile: gdcmFile.h,v $
Language: C++
- Date: $Date: 2004/12/07 17:28:50 $
- Version: $Revision: 1.85 $
+ Date: $Date: 2004/12/10 13:49:07 $
+ Version: $Revision: 1.86 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
public:
enum FileMode
{
- WMODE_DECOMPRESSED,
+ WMODE_RAW,
WMODE_RGB
};
uint8_t* GetImageDataRaw();
size_t GetImageDataIntoVector(void* destination, size_t maxSize);
- bool SetImageData (uint8_t* data, size_t expectedSize);
+ void SetImageData(uint8_t* data, size_t expectedSize);
+
+ // User datas
+ void SetUserData(uint8_t* data, size_t expectedSize);
+ uint8_t* GetUserData();
+ size_t GetUserDataSize();
+ // RBG datas (from file
+ uint8_t* GetRGBData();
+ size_t GetRGBDataSize();
+ // RAW datas (from file
+ uint8_t* GetRawData();
+ size_t GetRawDataSize();
// Write pixels of ONE image on hard drive
// No test is made on processor "endianity"
uint8_t* GetLutRGBA();
// Write mode
- void SetWriteModeToDecompressed() { SetWriteMode(WMODE_DECOMPRESSED); };
+ void SetWriteModeToRaw() { SetWriteMode(WMODE_RAW); };
void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); };
void SetWriteMode(FileMode mode) { WriteMode = mode; };
FileMode GetWriteMode() { return WriteMode; };
bool WriteBase(std::string const& fileName);
bool CheckWriteIntegrity();
- void SetWriteToDecompressed();
+ void SetWriteToRaw();
void SetWriteToRGB();
void RestoreWrite();
private:
void Initialise();
- uint8_t* GetDecompressed();
- int ComputeDecompressedPixelDataSizeFromHeader();
+ uint8_t* GetRaw();
private:
// members variables:
Program: gdcm
Module: $RCSfile: gdcmHeader.cxx,v $
Language: C++
- Date: $Date: 2004/12/07 17:28:50 $
- Version: $Revision: 1.214 $
+ Date: $Date: 2004/12/10 13:49:07 $
+ Version: $Revision: 1.215 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
std::ofstream* fp = new std::ofstream(fileName.c_str(),
std::ios::out | std::ios::binary);
- if (fp == NULL)
+ if (*fp == NULL)
{
dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str());
return false;
Program: gdcm
Module: $RCSfile: gdcmPixelReadConvert.cxx,v $
Language: C++
- Date: $Date: 2004/12/09 10:11:38 $
- Version: $Revision: 1.4 $
+ Date: $Date: 2004/12/10 13:49:07 $
+ Version: $Revision: 1.5 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
RGB = 0;
RGBSize = 0;
- Decompressed = 0;
- DecompressedSize = 0;
+ Raw = 0;
+ RawSize = 0;
LutRGBA = 0;
LutRedData = 0;
LutGreenData = 0;
}
RGB = 0;
- if ( Decompressed )
+ if ( Raw )
{
- delete [] Decompressed;
+ delete [] Raw;
}
- Decompressed = 0;
+ Raw = 0;
if ( LutRGBA )
{
RGB = new uint8_t[ RGBSize ];
}
-void PixelReadConvert::AllocateDecompressed()
+void PixelReadConvert::AllocateRaw()
{
- if ( Decompressed ) {
- delete [] Decompressed;
+ if ( Raw ) {
+ delete [] Raw;
}
- Decompressed = new uint8_t[ DecompressedSize ];
+ Raw = new uint8_t[ RawSize ];
}
/**
throw ( FormatError )
{
int nbPixels = XSize * YSize;
- uint16_t* localDecompres = (uint16_t*)Decompressed;
+ uint16_t* localDecompres = (uint16_t*)Raw;
for( int p = 0; p < nbPixels; p += 2 )
{
/**
* \brief Try to deal with RLE 16 Bits.
* We assume the RLE has allready been parsed and loaded in
- * Decompressed (through \ref ReadAndDecompressJPEGFile ).
+ * Raw (through \ref ReadAndDecompressJPEGFile ).
* We here need to make 16 Bits Pixels from Low Byte and
* High Byte 'Planes'...(for what it may mean)
* @return Boolean
bool PixelReadConvert::DecompressRLE16BitsFromRLE8Bits( int NumberOfFrames )
{
size_t PixelNumber = XSize * YSize;
- size_t decompressedSize = XSize * YSize * NumberOfFrames;
+ size_t RawSize = XSize * YSize * NumberOfFrames;
- // We assumed Decompressed contains the decoded RLE pixels but as
+ // We assumed Raw contains the decoded RLE pixels but as
// 8 bits per pixel. In order to convert those pixels to 16 bits
- // per pixel we cannot work in place within Decompressed and hence
- // we copy it in a safe place, say copyDecompressed.
+ // per pixel we cannot work in place within Raw and hence
+ // we copy it in a safe place, say copyRaw.
- uint8_t* copyDecompressed = new uint8_t[ decompressedSize * 2 ];
- memmove( copyDecompressed, Decompressed, decompressedSize * 2 );
+ uint8_t* copyRaw = new uint8_t[ RawSize * 2 ];
+ memmove( copyRaw, Raw, RawSize * 2 );
- uint8_t* x = Decompressed;
- uint8_t* a = copyDecompressed;
+ uint8_t* x = Raw;
+ uint8_t* a = copyRaw;
uint8_t* b = a + PixelNumber;
for ( int i = 0; i < NumberOfFrames; i++ )
}
}
- delete[] copyDecompressed;
+ delete[] copyRaw;
/// \todo check that operator new []didn't fail, and sometimes return false
return true;
/**
* \brief Implementation of the RLE decoding algorithm for decompressing
* a RLE fragment. [refer to PS 3.5-2003, section G.3.2 p 86]
- * @param subDecompressed Sub region of \ref Decompressed where the de
+ * @param subRaw Sub region of \ref Raw where the de
* decoded fragment should be placed.
* @param fragmentSize The length of the binary fragment as found on the disk.
- * @param decompressedSegmentSize The expected length of the fragment ONCE
- * decompressed.
+ * @param RawSegmentSize The expected length of the fragment ONCE
+ * Raw.
* @param fp File Pointer: on entry the position should be the one of
* the fragment to be decoded.
*/
-bool PixelReadConvert::ReadAndDecompressRLEFragment( uint8_t* subDecompressed,
+bool PixelReadConvert::ReadAndDecompressRLEFragment( uint8_t* subRaw,
long fragmentSize,
- long decompressedSegmentSize,
+ long RawSegmentSize,
std::ifstream* fp )
{
int8_t count;
long numberOfOutputBytes = 0;
long numberOfReadBytes = 0;
- while( numberOfOutputBytes < decompressedSegmentSize )
+ while( numberOfOutputBytes < RawSegmentSize )
{
fp->read( (char*)&count, 1 );
numberOfReadBytes += 1;
// signed integer of width N is 2^(N-1) - 1, which for int8_t
// is 127].
{
- fp->read( (char*)subDecompressed, count + 1);
+ fp->read( (char*)subRaw, count + 1);
numberOfReadBytes += count + 1;
- subDecompressed += count + 1;
+ subRaw += count + 1;
numberOfOutputBytes += count + 1;
}
else
numberOfReadBytes += 1;
for( int i = 0; i < -count + 1; i++ )
{
- subDecompressed[i] = newByte;
+ subRaw[i] = newByte;
}
- subDecompressed += -count + 1;
+ subRaw += -count + 1;
numberOfOutputBytes += -count + 1;
}
}
*/
bool PixelReadConvert::ReadAndDecompressRLEFile( std::ifstream* fp )
{
- uint8_t* subDecompressed = Decompressed;
- long decompressedSegmentSize = XSize * YSize;
+ uint8_t* subRaw = Raw;
+ long RawSegmentSize = XSize * YSize;
// Loop on the frame[s]
for( RLEFramesInfo::RLEFrameList::iterator
for( unsigned int k = 1; k <= (*it)->NumberFragments; k++ )
{
fp->seekg( (*it)->Offset[k] , std::ios::beg );
- (void)ReadAndDecompressRLEFragment( subDecompressed,
+ (void)ReadAndDecompressRLEFragment( subRaw,
(*it)->Length[k],
- decompressedSegmentSize,
+ RawSegmentSize,
fp );
- subDecompressed += decompressedSegmentSize;
+ subRaw += RawSegmentSize;
}
}
if( BitsAllocated == 16 )
{
- uint16_t* im16 = (uint16_t*)Decompressed;
+ uint16_t* im16 = (uint16_t*)Raw;
switch( SwapCode )
{
case 0:
case 3412:
case 2143:
case 4321:
- for( i = 0; i < DecompressedSize / 2; i++ )
+ for( i = 0; i < RawSize / 2; i++ )
{
im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
}
uint32_t s32;
uint16_t high;
uint16_t low;
- uint32_t* im32 = (uint32_t*)Decompressed;
+ uint32_t* im32 = (uint32_t*)Raw;
switch ( SwapCode )
{
case 0:
case 1234:
break;
case 4321:
- for( i = 0; i < DecompressedSize / 4; i++ )
+ for( i = 0; i < RawSize / 4; i++ )
{
low = im32[i] & 0x0000ffff; // 4321
high = im32[i] >> 16;
}
break;
case 2143:
- for( i = 0; i < DecompressedSize / 4; i++ )
+ for( i = 0; i < RawSize / 4; i++ )
{
low = im32[i] & 0x0000ffff; // 2143
high = im32[i] >> 16;
}
break;
case 3412:
- for( i = 0; i < DecompressedSize / 4; i++ )
+ for( i = 0; i < RawSize / 4; i++ )
{
low = im32[i] & 0x0000ffff; // 3412
high = im32[i] >> 16;
&& ( BitsStored < BitsAllocated )
&& ( ! PixelSign ) )
{
- int l = (int)( DecompressedSize / ( BitsAllocated / 8 ) );
- uint16_t *deb = (uint16_t *)Decompressed;
+ int l = (int)( RawSize / ( BitsAllocated / 8 ) );
+ uint16_t *deb = (uint16_t *)Raw;
for(int i = 0; i<l; i++)
{
if( *deb == 0xffff )
*/
bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream* fp )
{
- uint8_t* localDecompressed = Decompressed;
+ uint8_t* localRaw = Raw;
// Loop on the fragment[s]
for( JPEGFragmentsInfo::JPEGFragmentsList::iterator
it = JPEGInfo->Fragments.begin();
if ( IsJPEG2000 )
{
- if ( ! gdcm_read_JPEG2000_file( fp,localDecompressed ) )
+ if ( ! gdcm_read_JPEG2000_file( fp,localRaw ) )
{
return false;
}
else if ( BitsStored == 8)
{
// JPEG Lossy : call to IJG 6b
- if ( ! gdcm_read_JPEG_file8( fp, localDecompressed ) )
+ if ( ! gdcm_read_JPEG_file8( fp, localRaw ) )
{
return false;
}
else if ( BitsStored <= 12)
{
// Reading Fragment pixels
- if ( ! gdcm_read_JPEG_file12 ( fp, localDecompressed ) )
+ if ( ! gdcm_read_JPEG_file12 ( fp, localRaw ) )
{
return false;
}
else if ( BitsStored <= 16)
{
// Reading Fragment pixels
- if ( ! gdcm_read_JPEG_file16 ( fp, localDecompressed ) )
+ if ( ! gdcm_read_JPEG_file16 ( fp, localRaw ) )
{
return false;
}
return false;
}
- // Advance to next free location in Decompressed
+ // Advance to next free location in Raw
// for next fragment decompression (if any)
int length = XSize * YSize * SamplesPerPixel;
int numberBytes = BitsAllocated / 8;
- localDecompressed += length * numberBytes;
+ localRaw += length * numberBytes;
}
return true;
}
{
if ( BitsStored != BitsAllocated )
{
- int l = (int)( DecompressedSize / ( BitsAllocated / 8 ) );
+ int l = (int)( RawSize / ( BitsAllocated / 8 ) );
if ( BitsAllocated == 16 )
{
uint16_t mask = 0xffff;
mask = mask >> ( BitsAllocated - BitsStored );
- uint16_t* deb = (uint16_t*)Decompressed;
+ uint16_t* deb = (uint16_t*)Raw;
for(int i = 0; i<l; i++)
{
*deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
{
uint32_t mask = 0xffffffff;
mask = mask >> ( BitsAllocated - BitsStored );
- uint32_t* deb = (uint32_t*)Decompressed;
+ uint32_t* deb = (uint32_t*)Raw;
for(int i = 0; i<l; i++)
{
*deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
*/
void PixelReadConvert::ConvertYcBcRPlanesToRGBPixels()
{
- uint8_t* localDecompressed = Decompressed;
- uint8_t* copyDecompressed = new uint8_t[ DecompressedSize ];
- memmove( copyDecompressed, localDecompressed, DecompressedSize );
+ uint8_t* localRaw = Raw;
+ uint8_t* copyRaw = new uint8_t[ RawSize ];
+ memmove( copyRaw, localRaw, RawSize );
// to see the tricks about YBR_FULL, YBR_FULL_422,
// YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at :
int l = XSize * YSize;
int nbFrames = ZSize;
- uint8_t* a = copyDecompressed;
- uint8_t* b = copyDecompressed + l;
- uint8_t* c = copyDecompressed + l + l;
+ uint8_t* a = copyRaw;
+ uint8_t* b = copyRaw + l;
+ uint8_t* c = copyRaw + l + l;
double R, G, B;
/// \todo : Replace by the 'well known' integer computation
if (G > 255.0) G = 255.0;
if (B > 255.0) B = 255.0;
- *(localDecompressed++) = (uint8_t)R;
- *(localDecompressed++) = (uint8_t)G;
- *(localDecompressed++) = (uint8_t)B;
+ *(localRaw++) = (uint8_t)R;
+ *(localRaw++) = (uint8_t)G;
+ *(localRaw++) = (uint8_t)B;
a++;
b++;
c++;
}
}
- delete[] copyDecompressed;
+ delete[] copyRaw;
}
/**
*/
void PixelReadConvert::ConvertRGBPlanesToRGBPixels()
{
- uint8_t* localDecompressed = Decompressed;
- uint8_t* copyDecompressed = new uint8_t[ DecompressedSize ];
- memmove( copyDecompressed, localDecompressed, DecompressedSize );
+ uint8_t* localRaw = Raw;
+ uint8_t* copyRaw = new uint8_t[ RawSize ];
+ memmove( copyRaw, localRaw, RawSize );
int l = XSize * YSize * ZSize;
- uint8_t* a = copyDecompressed;
- uint8_t* b = copyDecompressed + l;
- uint8_t* c = copyDecompressed + l + l;
+ uint8_t* a = copyRaw;
+ uint8_t* b = copyRaw + l;
+ uint8_t* c = copyRaw + l + l;
for (int j = 0; j < l; j++)
{
- *(localDecompressed++) = *(a++);
- *(localDecompressed++) = *(b++);
- *(localDecompressed++) = *(c++);
+ *(localRaw++) = *(a++);
+ *(localRaw++) = *(b++);
+ *(localRaw++) = *(c++);
}
- delete[] copyDecompressed;
+ delete[] copyRaw;
}
bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream* fp )
{
- // ComputeDecompressedAndRGBSizes is already made by
+ // ComputeRawAndRGBSizes is already made by
// ::GrabInformationsFromHeader. So, the structure sizes are
// correct
Squeeze();
return false;
}
- AllocateDecompressed();
+ AllocateRaw();
//////////////////////////////////////////////////
//// Second stage: read from disk dans decompress.
{
ReadAndDecompress12BitsTo16Bits( fp);
}
- else if ( IsDecompressed )
+ else if ( IsRaw )
{
// This problem can be found when some obvious informations are found
// after the field containing the image datas. In this case, these
// bad datas are added to the size of the image (in the PixelDataLength
- // variable). But DecompressedSize is the right size of the image !
- if( PixelDataLength != DecompressedSize)
+ // variable). But RawSize is the right size of the image !
+ if( PixelDataLength != RawSize)
{
dbg.Verbose( 0, "PixelReadConvert::ReadAndDecompressPixelData: "
- "Mismatch between PixelReadConvert and DecompressedSize." );
+ "Mismatch between PixelReadConvert and RawSize." );
}
- if( PixelDataLength > DecompressedSize)
+ if( PixelDataLength > RawSize)
{
- fp->read( (char*)Decompressed, DecompressedSize);
+ fp->read( (char*)Raw, RawSize);
}
else
{
- fp->read( (char*)Decompressed, PixelDataLength);
+ fp->read( (char*)Raw, PixelDataLength);
}
if ( fp->fail() || fp->eof())//Fp->gcount() == 1
{
dbg.Verbose( 0, "PixelReadConvert::ReadAndDecompressPixelData: "
- "reading of decompressed pixel data failed." );
+ "reading of Raw pixel data failed." );
return false;
}
}
// - [Planar 1] AND [Photo C] handled with ConvertYcBcRPlanesToRGBPixels()
// - [Planar 2] OR [Photo D] requires LUT intervention.
- if ( ! IsDecompressedRGB() )
+ if ( ! IsRawRGB() )
{
// [Planar 2] OR [Photo D]: LUT intervention done outside
return;
}
/**
- * \brief Predicate to know wether the image[s] (once decompressed) is RGB.
+ * \brief Predicate to know wether the image[s] (once Raw) is RGB.
* \note See comments of \ref ConvertHandleColor
*/
-bool PixelReadConvert::IsDecompressedRGB()
+bool PixelReadConvert::IsRawRGB()
{
if ( IsMonochrome
|| PlanarConfiguration == 2
return true;
}
-void PixelReadConvert::ComputeDecompressedAndRGBSizes()
+void PixelReadConvert::ComputeRawAndRGBSizes()
{
int bitsAllocated = BitsAllocated;
// Number of "Bits Allocated" is fixed to 16 when it's 12, since
bitsAllocated = 16;
}
- DecompressedSize = XSize * YSize * ZSize
+ RawSize = XSize * YSize * ZSize
* ( bitsAllocated / 8 )
* SamplesPerPixel;
if ( HasLUT )
{
- RGBSize = 3 * DecompressedSize;
+ RGBSize = 3 * RawSize;
}
else
{
- RGBSize = DecompressedSize;
+ RGBSize = RawSize;
}
}
PixelSign = header->IsSignedPixelData();
SwapCode = header->GetSwapCode();
TransferSyntaxType ts = header->GetTransferSyntax();
- IsDecompressed =
+ IsRaw =
( ! header->IsDicomV3() )
|| ts == ImplicitVRLittleEndian
|| ts == ImplicitVRLittleEndianDLXGE
}
}
- ComputeDecompressedAndRGBSizes();
+ ComputeRawAndRGBSizes();
}
/**
}
/**
- * \brief Build the RGB image from the Decompressed imagage and the LUTs.
+ * \brief Build the RGB image from the Raw imagage and the LUTs.
*/
bool PixelReadConvert::BuildRGBImage()
{
return true;
}
- if ( ! Decompressed )
+ if ( ! Raw )
{
// The job can't be done
return false;
// Build RGB Pixels
AllocateRGB();
uint8_t* localRGB = RGB;
- for (size_t i = 0; i < DecompressedSize; ++i )
+ for (size_t i = 0; i < RawSize; ++i )
{
- int j = Decompressed[i] * 4;
+ int j = Raw[i] * 4;
*localRGB++ = LutRGBA[j];
*localRGB++ = LutRGBA[j+1];
*localRGB++ = LutRGBA[j+2];
Program: gdcm
Module: $RCSfile: gdcmPixelReadConvert.h,v $
Language: C++
- Date: $Date: 2004/12/03 20:16:58 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2004/12/10 13:49:07 $
+ Version: $Revision: 1.4 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
//// Getter accessors:
uint8_t* GetRGB() { return RGB; }
size_t GetRGBSize() { return RGBSize; }
- uint8_t* GetDecompressed() { return Decompressed; }
- size_t GetDecompressedSize() { return DecompressedSize; }
+ uint8_t* GetRaw() { return Raw; }
+ size_t GetRawSize() { return RawSize; }
uint8_t* GetLutRGBA() { return LutRGBA; }
//// Predicates:
- bool IsDecompressedRGB();
+ bool IsRawRGB();
void Print( std::string indent = "", std::ostream &os = std::cout );
void ConvertYcBcRPlanesToRGBPixels();
void ConvertHandleColor();
- void ComputeDecompressedAndRGBSizes();
+ void ComputeRawAndRGBSizes();
void AllocateRGB();
- void AllocateDecompressed();
+ void AllocateRaw();
// Variables
/// Pixel data represented as RGB after LUT color interpretation.
/// Size of \ref RGB image.
size_t RGBSize;
/// Pixel data after decompression and bit/byte rearrangement.
- uint8_t* Decompressed;
+ uint8_t* Raw;
/// Size of \ref Decompressed image.
- size_t DecompressedSize;
+ size_t RawSize;
/// \brief Red/Green/Blue/Alpha LookUpTable build out of the
/// Red/Green/Blue LUT descriptors (see \ref BuildLUTRGBA ).
uint8_t* LutRGBA;
bool PixelSign;
int SwapCode;
- bool IsDecompressed;
+ bool IsRaw;
bool IsJPEG2000;
bool IsJPEGLossless;
bool IsRLELossless;
Program: gdcm
Module: $RCSfile: vtkGdcmWriter.cxx,v $
Language: C++
- Date: $Date: 2004/12/10 08:34:08 $
- Version: $Revision: 1.7 $
+ Date: $Date: 2004/12/10 13:49:08 $
+ Version: $Revision: 1.8 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include <vtkPointData.h>
#include <vtkLookupTable.h>
-vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.7 $");
+vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.8 $");
vtkStandardNewMacro(vtkGdcmWriter);
//-----------------------------------------------------------------------------
{
this->LookupTable = NULL;
this->FileDimensionality = 3;
+ this->WriteType = VTK_GDCM_WRITE_TYPE_EXPLICIT_VR;
}
vtkGdcmWriter::~vtkGdcmWriter()
void vtkGdcmWriter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
+
+ os << indent << "Write type : " << this->GetWriteTypeAsString();
}
//-----------------------------------------------------------------------------
// Public
+const char *vtkGdcmWriter::GetWriteTypeAsString()
+{
+ switch(WriteType)
+ {
+ case VTK_GDCM_WRITE_TYPE_EXPLICIT_VR :
+ return "Explicit VR";
+ case VTK_GDCM_WRITE_TYPE_IMPLICIT_VR :
+ return "Implicit VR";
+ case VTK_GDCM_WRITE_TYPE_ACR :
+ return "ACR";
+ case VTK_GDCM_WRITE_TYPE_ACR_LIBIDO :
+ return "ACR Libido";
+ default :
+ return "Unknow type";
+ }
+}
//-----------------------------------------------------------------------------
// Protected
size_t planeSize = dim[1] * lineSize;
size_t size = dim[2] * planeSize;
- *data = new unsigned char[size];
-
- image->GetIncrements(inc);
- unsigned char *src = (unsigned char *)image->GetScalarPointerForExtent(extent);
- unsigned char *dst = *data + planeSize - lineSize;
- for (int plane = extent[4]; plane <= extent[5]; plane++)
+ if( size>0 )
{
- for (int line = extent[2]; line <= extent[3]; line++)
+ *data = new unsigned char[size];
+
+ image->GetIncrements(inc);
+ unsigned char *src = (unsigned char *)image->GetScalarPointerForExtent(extent);
+ unsigned char *dst = *data + planeSize - lineSize;
+ for (int plane = extent[4]; plane <= extent[5]; plane++)
{
- // Copy one line at proper destination:
- memcpy((void*)dst, (void*)src, lineSize);
+ for (int line = extent[2]; line <= extent[3]; line++)
+ {
+ // Copy one line at proper destination:
+ memcpy((void*)dst, (void*)src, lineSize);
- src += inc[1]*image->GetScalarSize();
- dst -= lineSize;
+ src += inc[1] * image->GetScalarSize();
+ dst -= lineSize;
+ }
+ dst += 2 * planeSize;
}
- dst += 2 * planeSize;
+ }
+ else
+ {
+ *data = NULL;
}
return size;
// Pixels
unsigned char *data;
size_t size = ReverseData(image,&data);
- file->SetImageData(data,size);
+ file->SetUserData(data,size);
}
/**
SetImageInformation(dcmFile,image);
// Write the image
+ switch(this->WriteType)
+ {
+ case VTK_GDCM_WRITE_TYPE_EXPLICIT_VR :
+ dcmFile->SetWriteTypeToDcmExplVR();
+ break;
+ case VTK_GDCM_WRITE_TYPE_IMPLICIT_VR :
+ dcmFile->SetWriteTypeToDcmImplVR();
+ break;
+ case VTK_GDCM_WRITE_TYPE_ACR :
+ dcmFile->SetWriteTypeToAcr();
+ break;
+ case VTK_GDCM_WRITE_TYPE_ACR_LIBIDO :
+ dcmFile->SetWriteTypeToAcrLibido();
+ break;
+ default :
+ dcmFile->SetWriteTypeToDcmExplVR();
+ }
+
if(!dcmFile->Write(fileName))
{
vtkErrorMacro( << "File " << this->FileName << "couldn't be written by "
std::cerr << "not written \n";
}
+ // Clean up
+ if( dcmFile->GetUserData() && dcmFile->GetUserDataSize()>0 )
+ {
+ delete[] dcmFile->GetUserData();
+ }
delete dcmFile;
}
Program: gdcm
Module: $RCSfile: vtkGdcmWriter.h,v $
Language: C++
- Date: $Date: 2004/12/09 10:59:59 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2004/12/10 13:49:08 $
+ Version: $Revision: 1.4 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include <list>
#include <string>
+//-----------------------------------------------------------------------------
+#define VTK_GDCM_WRITE_TYPE_EXPLICIT_VR 1
+#define VTK_GDCM_WRITE_TYPE_IMPLICIT_VR 2
+#define VTK_GDCM_WRITE_TYPE_ACR 3
+#define VTK_GDCM_WRITE_TYPE_ACR_LIBIDO 4
+
//-----------------------------------------------------------------------------
class VTK_EXPORT vtkGdcmWriter : public vtkImageWriter
{
vtkSetObjectMacro(LookupTable,vtkLookupTable);
vtkGetObjectMacro(LookupTable,vtkLookupTable);
+ void SetWriteTypeToDcmImplVR() { SetWriteType(VTK_GDCM_WRITE_TYPE_EXPLICIT_VR); };
+ void SetWriteTypeToDcmExplVR() { SetWriteType(VTK_GDCM_WRITE_TYPE_IMPLICIT_VR); };
+ void SetWriteTypeToAcr() { SetWriteType(VTK_GDCM_WRITE_TYPE_ACR); };
+ void SetWriteTypeToAcrLibido() { SetWriteType(VTK_GDCM_WRITE_TYPE_ACR_LIBIDO); };
+ vtkSetMacro(WriteType,int);
+ vtkGetMacro(WriteType,int);
+ const char *GetWriteTypeAsString();
+
protected:
vtkGdcmWriter();
~vtkGdcmWriter();
private:
// Variables
vtkLookupTable *LookupTable;
+ int WriteType;
};
//-----------------------------------------------------------------------------