X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFileHelper.cxx;h=50183d7004aa0ab93119013bf7a83d99fd9e1a7d;hb=e51bf0565bbe4c0e269dd941cb4071ebde6012e4;hp=fb243911fb23958c2dbc29f83c7e23ffd2ebe0a7;hpb=3e82e8b67eddf5d4b95b6aa2a2e2615aced4c452;p=gdcm.git diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index fb243911..50183d70 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/02/02 10:02:18 $ - Version: $Revision: 1.10 $ + Date: $Date: 2005/02/11 11:22:59 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -124,6 +124,82 @@ FileHelper::~FileHelper() //----------------------------------------------------------------------------- // Public +/** + * \brief Accesses an existing DocEntry (i.e. a Dicom Element) + * through it's (group, element) and modifies it's content with + * the given value. + * @param content new value (string) to substitute with + * @param group group number of the Dicom Element to modify + * @param elem element number of the Dicom Element to modify + */ +bool FileHelper::SetValEntry(std::string const &content, + uint16_t group, uint16_t elem) +{ + return FileInternal->SetValEntry(content,group,elem); +} + + +/** + * \brief Accesses an existing DocEntry (i.e. a Dicom Element) + * through it's (group, element) and modifies it's content with + * the given value. + * @param content new value (void* -> uint8_t*) to substitute with + * @param lgth new value length + * @param group group number of the Dicom Element to modify + * @param elem element number of the Dicom Element to modify + */ +bool FileHelper::SetBinEntry(uint8_t *content, int lgth, + uint16_t group, uint16_t elem) +{ + return FileInternal->SetBinEntry(content,lgth,group,elem); +} + +/** + * \brief Modifies the value of a given DocEntry (Dicom entry) + * when it exists. Create it with the given value when unexistant. + * @param content (string) Value to be set + * @param group Group number of the Entry + * @param elem Element number of the Entry + * \return pointer to the modified/created Dicom entry (NULL when creation + * failed). + */ +ValEntry *FileHelper::InsertValEntry(std::string const &content, + uint16_t group, uint16_t elem) +{ + return FileInternal->InsertValEntry(content,group,elem); +} + +/** + * \brief Modifies the value of a given DocEntry (Dicom entry) + * when it exists. Create it with the given value when unexistant. + * A copy of the binArea is made to be kept in the Document. + * @param binArea (binary) value to be set + * @param lgth new value length + * @param group Group number of the Entry + * @param elem Element number of the Entry + * \return pointer to the modified/created Dicom entry (NULL when creation + * failed). + */ +BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth, + uint16_t group, uint16_t elem) +{ + return FileInternal->InsertBinEntry(binArea,lgth,group,elem); +} + +/** + * \brief Modifies the value of a given DocEntry (Dicom entry) + * when it exists. Create it with the given value when unexistant. + * A copy of the binArea is made to be kept in the Document. + * @param group Group number of the Entry + * @param elem Element number of the Entry + * \return pointer to the modified/created Dicom entry (NULL when creation + * failed). + */ +SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem) +{ + return FileInternal->InsertSeqEntry(group,elem); +} + /** * \brief Get the size of the image data * If the image can be RGB (with a lut or by default), the size @@ -160,9 +236,9 @@ size_t FileHelper::GetImageDataRawSize() } /** - * \brief - Allocates necessary memory, + * \brief - Allocates necessary memory, * - Reads the pixels from disk (uncompress if necessary), - * - Transforms YBR pixels, if any, into RGB pixels + * - Transforms YBR pixels, if any, into RGB pixels, * - Transforms 3 planes R, G, B, if any, into a single RGB Plane * - Transforms single Grey plane + 3 Palettes into a RGB Plane * - Copies the pixel data (image[s]/volume[s]) to newly allocated zone. @@ -244,7 +320,7 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize) { if ( PixelReadConverter->GetRGBSize() > maxSize ) { - gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize"); + gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize"); return 0; } memcpy( destination, @@ -256,7 +332,7 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize) // Either no LUT conversion necessary or LUT conversion failed if ( PixelReadConverter->GetRawSize() > maxSize ) { - gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize"); + gdcmWarningMacro( "Pixel data bigger than caller's expected MaxSize"); return 0; } memcpy( destination, @@ -272,9 +348,11 @@ size_t FileHelper::GetImageDataIntoVector (void *destination, size_t maxSize) * 'volume'Pixels are presented as C-like 3D arrays : plane per plane * \warning Since the pixels are not copied, it is the caller's responsability * not to deallocate its data before gdcm uses them (e.g. with - * the Write() method. - * @param inData user supplied pixel area - * @param expectedSize total image size, in Bytes + * the Write() method ) + * @param inData user supplied pixel area (uint8_t* is just for the compiler. + * user is allowed to pass any kind of pixelsn since the size is + * given in bytes) + * @param expectedSize total image size, *in Bytes* * * @return boolean */ @@ -286,10 +364,15 @@ void FileHelper::SetImageData(uint8_t *inData, size_t expectedSize) /** * \brief Set the image data defined by the user * \warning When writting the file, this data are get as default data to write + * @param inData user supplied pixel area (uint8_t* is just for the compiler. + * user is allowed to pass any kind of pixelsn since the size is + * given in bytes) + * @param expectedSize total image size, *in Bytes* + */ -void FileHelper::SetUserData(uint8_t *data, size_t expectedSize) +void FileHelper::SetUserData(uint8_t *inData, size_t expectedSize) { - PixelWriteConverter->SetUserData(data,expectedSize); + PixelWriteConverter->SetUserData(inData,expectedSize); } /** @@ -346,6 +429,14 @@ size_t FileHelper::GetRawDataSize() return PixelReadConverter->GetRawSize(); } +/** + * \brief Access to the underlying \ref PixelReadConverter RGBA LUT + */ +uint8_t* FileHelper::GetLutRGBA() +{ + return PixelReadConverter->GetLutRGBA(); +} + /** * \brief Writes on disk A SINGLE Dicom file * NO test is performed on processor "Endiannity". @@ -354,13 +445,12 @@ size_t FileHelper::GetRawDataSize() * (any already existing file is over written) * @return false if write fails */ - bool FileHelper::WriteRawData(std::string const &fileName) { std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary ); if (!fp1) { - gdcmVerboseMacro( "Fail to open (write) file:" << fileName.c_str()); + gdcmWarningMacro( "Fail to open (write) file:" << fileName.c_str()); return false; } @@ -511,89 +601,6 @@ bool FileHelper::Write(std::string const &fileName) return check; } -/** - * \brief Accesses an existing DocEntry (i.e. a Dicom Element) - * through it's (group, element) and modifies it's content with - * the given value. - * @param content new value (string) to substitute with - * @param group group number of the Dicom Element to modify - * @param elem element number of the Dicom Element to modify - */ -bool FileHelper::SetValEntry(std::string const &content, - uint16_t group, uint16_t elem) -{ - return FileInternal->SetValEntry(content,group,elem); -} - - -/** - * \brief Accesses an existing DocEntry (i.e. a Dicom Element) - * through it's (group, element) and modifies it's content with - * the given value. - * @param content new value (void* -> uint8_t*) to substitute with - * @param lgth new value length - * @param group group number of the Dicom Element to modify - * @param elem element number of the Dicom Element to modify - */ -bool FileHelper::SetBinEntry(uint8_t *content, int lgth, - uint16_t group, uint16_t elem) -{ - return FileInternal->SetBinEntry(content,lgth,group,elem); -} - -/** - * \brief Modifies the value of a given DocEntry (Dicom entry) - * when it exists. Create it with the given value when unexistant. - * @param content (string) Value to be set - * @param group Group number of the Entry - * @param elem Element number of the Entry - * \return pointer to the modified/created Dicom entry (NULL when creation - * failed). - */ -ValEntry *FileHelper::InsertValEntry(std::string const &content, - uint16_t group, uint16_t elem) -{ - return FileInternal->InsertValEntry(content,group,elem); -} - -/* - * \brief Modifies the value of a given DocEntry (Dicom entry) - * when it exists. Create it with the given value when unexistant. - * A copy of the binArea is made to be kept in the Document. - * @param binArea (binary) value to be set - * @param group Group number of the Entry - * @param elem Element number of the Entry - * \return pointer to the modified/created Dicom entry (NULL when creation - * failed). - */ -BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth, - uint16_t group, uint16_t elem) -{ - return FileInternal->InsertBinEntry(binArea,lgth,group,elem); -} - -/* - * \brief Modifies the value of a given DocEntry (Dicom entry) - * when it exists. Create it with the given value when unexistant. - * A copy of the binArea is made to be kept in the Document. - * @param group Group number of the Entry - * @param elem Element number of the Entry - * \return pointer to the modified/created Dicom entry (NULL when creation - * failed). - */ -SeqEntry *FileHelper::InsertSeqEntry(uint16_t group, uint16_t elem) -{ - return FileInternal->InsertSeqEntry(group,elem); -} - -/** - * \brief Access to the underlying \ref PixelReadConverter RGBA LUT - */ -uint8_t* FileHelper::GetLutRGBA() -{ - return PixelReadConverter->GetLutRGBA(); -} - //----------------------------------------------------------------------------- // Protected /** @@ -628,7 +635,7 @@ bool FileHelper::CheckWriteIntegrity() case WMODE_RAW : if( decSize!=PixelWriteConverter->GetUserDataSize() ) { - gdcmVerboseMacro( "Data size (Raw) is incorrect. Should be " + gdcmWarningMacro( "Data size (Raw) is incorrect. Should be " << decSize << " / Found :" << PixelWriteConverter->GetUserDataSize() ); return false; @@ -637,7 +644,7 @@ bool FileHelper::CheckWriteIntegrity() case WMODE_RGB : if( rgbSize!=PixelWriteConverter->GetUserDataSize() ) { - gdcmVerboseMacro( "Data size (RGB) is incorrect. Should be " + gdcmWarningMacro( "Data size (RGB) is incorrect. Should be " << decSize << " / Found " << PixelWriteConverter->GetUserDataSize() ); return false; @@ -650,7 +657,7 @@ bool FileHelper::CheckWriteIntegrity() } /** - * \brief + * \brief Update the File to write RAW datas */ void FileHelper::SetWriteToRaw() { @@ -668,14 +675,19 @@ void FileHelper::SetWriteToRaw() } else { - photInt->SetValue("MONOCHROME1 "); + photInt->SetValue("MONOCHROME2 "); } PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(), PixelReadConverter->GetRawSize()); + std::string vr = "OB"; + if( FileInternal->GetBitsAllocated()>8 ) + vr = "OW"; + if( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files + vr = "OB"; BinEntry *pixel = - CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel()); + CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr); pixel->SetValue(GDCM_BINLOADED); pixel->SetBinArea(PixelWriteConverter->GetData(),false); pixel->SetLength(PixelWriteConverter->GetDataSize()); @@ -686,7 +698,7 @@ void FileHelper::SetWriteToRaw() } /** - * \brief + * \brief Update the File to write RGB datas */ void FileHelper::SetWriteToRGB() { @@ -714,8 +726,13 @@ void FileHelper::SetWriteToRGB() PixelReadConverter->GetRawSize()); } + std::string vr = "OB"; + if( FileInternal->GetBitsAllocated()>8 ) + vr = "OW"; + if( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files + vr = "OB"; BinEntry *pixel = - CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel()); + CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr); pixel->SetValue(GDCM_BINLOADED); pixel->SetBinArea(PixelWriteConverter->GetData(),false); pixel->SetLength(PixelWriteConverter->GetDataSize()); @@ -759,7 +776,7 @@ void FileHelper::SetWriteToRGB() } /** - * \brief + * \brief Restore the File write mode */ void FileHelper::RestoreWrite() { @@ -783,7 +800,7 @@ void FileHelper::RestoreWrite() } /** - * \brief + * \brief Set in the File the write type to ACR */ void FileHelper::SetWriteFileTypeToACR() { @@ -791,7 +808,7 @@ void FileHelper::SetWriteFileTypeToACR() } /** - * \brief + * \brief Set in the File the write type to Explicit VR */ void FileHelper::SetWriteFileTypeToExplicitVR() { @@ -805,7 +822,7 @@ void FileHelper::SetWriteFileTypeToExplicitVR() } /** - * \brief + * \brief Set in the File the write type to Implicit VR */ void FileHelper::SetWriteFileTypeToImplicitVR() { @@ -820,13 +837,16 @@ void FileHelper::SetWriteFileTypeToImplicitVR() /** - * \brief + * \brief Restore in the File the write type */ void FileHelper::RestoreWriteFileType() { Archive->Restore(0x0002,0x0010); } +/** + * \brief Set the Write not to Libido format + */ void FileHelper::SetWriteToLibido() { ValEntry *oldRow = dynamic_cast @@ -857,7 +877,7 @@ void FileHelper::SetWriteToLibido() } /** - * \brief + * \brief Set the Write not to No Libido format */ void FileHelper::SetWriteToNoLibido() { @@ -875,7 +895,7 @@ void FileHelper::SetWriteToNoLibido() } /** - * \brief + * \brief Restore the Write format */ void FileHelper::RestoreWriteOfLibido() { @@ -884,12 +904,19 @@ void FileHelper::RestoreWriteOfLibido() Archive->Restore(0x0008,0x0010); } +/** + * \brief Copy a ValEntry content + * @param group Group number of the Entry + * @param elem Element number of the Entry + * \return pointer to the modified/created Val Entry (NULL when creation + * failed). + */ ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem) { DocEntry *oldE = FileInternal->GetDocEntry(group, elem); ValEntry *newE; - if(oldE) + if( oldE ) { newE = new ValEntry(oldE->GetDictEntry()); newE->Copy(oldE); @@ -907,22 +934,28 @@ ValEntry *FileHelper::CopyValEntry(uint16_t group,uint16_t elem) * when it exists. Create it with the given value when unexistant. * @param group Group number of the Entry * @param elem Element number of the Entry + * @param vr Value Representation of the Entry * \return pointer to the modified/created Bin Entry (NULL when creation * failed). */ -BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem) +BinEntry *FileHelper::CopyBinEntry(uint16_t group,uint16_t elem, + const std::string &vr) { DocEntry *oldE = FileInternal->GetDocEntry(group, elem); BinEntry *newE; - if(oldE) + if( oldE ) + if( oldE->GetVR()!=vr ) + oldE = NULL; + + if( oldE ) { newE = new BinEntry(oldE->GetDictEntry()); newE->Copy(oldE); } else { - newE = GetFile()->NewBinEntry(group,elem); + newE = GetFile()->NewBinEntry(group,elem,vr); } return newE; @@ -965,7 +998,7 @@ uint8_t *FileHelper::GetRaw() raw = PixelReadConverter->GetRaw(); if ( ! raw ) { - gdcmVerboseMacro( "Read/decompress of pixel data apparently went wrong."); + gdcmWarningMacro( "Read/decompress of pixel data apparently went wrong."); return 0; } }