X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=5b43dc21a688f13cff19db848afc7cfe17a98ee5;hb=5887c4beef24959af83e43efad0bb86acac9339e;hp=52ef22eec83d8a0a80183d6b25a6006a41daff91;hpb=70b9dde9da207191fa6d799fdf03c2aff7941273;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 52ef22ee..5b43dc21 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2005/01/07 16:26:12 $ - Version: $Revision: 1.184 $ + Date: $Date: 2005/01/12 11:33:39 $ + Version: $Revision: 1.191 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,6 +17,8 @@ =========================================================================*/ #include "gdcmFile.h" +#include "gdcmGlobal.h" +#include "gdcmTS.h" #include "gdcmDocument.h" #include "gdcmDebug.h" #include "gdcmUtil.h" @@ -138,9 +140,10 @@ void File::Print(std::ostream &os) // Public /** * \brief Get the size of the image data - * * If the image can be RGB (with a lut or by default), the size * corresponds to the RGB image + * (use GetImageDataRawSize if you want to be sure to get *only* + * the size of the pixels) * @return The image size */ size_t File::GetImageDataSize() @@ -155,9 +158,9 @@ size_t File::GetImageDataSize() /** * \brief Get the size of the image data - * - * If the image can be RGB by transformation in a LUT, this - * transformation isn't considered + * If the image could be converted to RGB using a LUT, + * this transformation is not taken into account by GetImageDataRawSize + * (use GetImageDataSize if you wish) * @return The raw image size */ size_t File::GetImageDataRawSize() @@ -255,8 +258,7 @@ size_t File::GetImageDataIntoVector (void *destination, size_t maxSize) { if ( PixelReadConverter->GetRGBSize() > maxSize ) { - Debug::Verbose(0, "File::GetImageDataIntoVector: pixel data bigger" - "than caller's expected MaxSize"); + gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize"); return 0; } memcpy( destination, @@ -268,8 +270,7 @@ size_t File::GetImageDataIntoVector (void *destination, size_t maxSize) // Either no LUT conversion necessary or LUT conversion failed if ( PixelReadConverter->GetRawSize() > maxSize ) { - Debug::Verbose(0, "File::GetImageDataIntoVector: pixel data bigger" - "than caller's expected MaxSize"); + gdcmVerboseMacro( "Pixel data bigger than caller's expected MaxSize"); return 0; } memcpy( destination, @@ -373,16 +374,29 @@ bool File::WriteRawData(std::string const &fileName) std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary ); if (!fp1) { - Debug::Verbose(2, "Fail to open (write) file:", fileName.c_str()); + gdcmVerboseMacro( "Fail to open (write) file:" << fileName.c_str()); return false; } - if(PixelWriteConverter->GetUserData()) - fp1.write((char*)PixelWriteConverter->GetUserData(), PixelWriteConverter->GetUserDataSize()); - else if(PixelReadConverter->GetRGB()) - fp1.write((char*)PixelReadConverter->GetRGB(), PixelReadConverter->GetRGBSize()); - else if(PixelReadConverter->GetRaw()) - fp1.write((char*)PixelReadConverter->GetRaw(), PixelReadConverter->GetRawSize()); + if( PixelWriteConverter->GetUserData() ) + { + fp1.write( (char*)PixelWriteConverter->GetUserData(), + PixelWriteConverter->GetUserDataSize() ); + } + else if ( PixelReadConverter->GetRGB() ) + { + fp1.write( (char*)PixelReadConverter->GetRGB(), + PixelReadConverter->GetRGBSize()); + } + else if ( PixelReadConverter->GetRaw() ) + { + fp1.write( (char*)PixelReadConverter->GetRaw(), + PixelReadConverter->GetRawSize()); + } + else + { + gdcmErrorMacro( "Nothing written." ); + } fp1.close(); @@ -517,12 +531,12 @@ bool File::Write(std::string const &fileName) * the given value. * @param content new value (string) to substitute with * @param group group number of the Dicom Element to modify - * @param element element number of the Dicom Element to modify + * @param elem element number of the Dicom Element to modify */ -bool File::SetEntryByNumber(std::string const &content, - uint16_t group, uint16_t element) +bool File::SetEntry(std::string const &content, + uint16_t group, uint16_t elem) { - return HeaderInternal->SetEntryByNumber(content,group,element); + return HeaderInternal->SetEntry(content,group,elem); } @@ -533,12 +547,12 @@ bool File::SetEntryByNumber(std::string const &content, * @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 element element number of the Dicom Element to modify + * @param elem element number of the Dicom Element to modify */ -bool File::SetEntryByNumber(uint8_t *content, int lgth, - uint16_t group, uint16_t element) +bool File::SetEntry(uint8_t *content, int lgth, + uint16_t group, uint16_t elem) { - return HeaderInternal->SetEntryByNumber(content,lgth,group,element); + return HeaderInternal->SetEntry(content,lgth,group,elem); } /** @@ -546,14 +560,14 @@ bool File::SetEntryByNumber(uint8_t *content, int lgth, * 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 element Element number of the Entry + * @param elem Element number of the Entry * \return pointer to the modified/created Header Entry (NULL when creation * failed). */ -bool File::ReplaceOrCreateByNumber(std::string const &content, - uint16_t group, uint16_t element) +bool File::ReplaceOrCreate(std::string const &content, + uint16_t group, uint16_t elem) { - return HeaderInternal->ReplaceOrCreateByNumber(content,group,element) != NULL; + return HeaderInternal->ReplaceOrCreate(content,group,elem) != NULL; } /* @@ -562,14 +576,14 @@ bool File::ReplaceOrCreateByNumber(std::string const &content, * 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 element Element number of the Entry + * @param elem Element number of the Entry * \return pointer to the modified/created Header Entry (NULL when creation * failed). */ -bool File::ReplaceOrCreateByNumber(uint8_t *binArea, int lgth, - uint16_t group, uint16_t element) +bool File::ReplaceOrCreate(uint8_t *binArea, int lgth, + uint16_t group, uint16_t elem) { - return HeaderInternal->ReplaceOrCreateByNumber(binArea,lgth,group,element) != NULL; + return HeaderInternal->ReplaceOrCreate(binArea,lgth,group,elem) != NULL; } /** @@ -615,18 +629,16 @@ bool File::CheckWriteIntegrity() case WMODE_RAW : if( decSize!=PixelWriteConverter->GetUserDataSize() ) { - Debug::Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect (Raw)"); - //std::cerr << "File::CheckWriteIntegrity: Data size is incorrect (Raw)\n" - // << decSize << " / " << PixelWriteConverter->GetUserDataSize() << "\n"; + gdcmVerboseMacro( "Data size is incorrect (Raw)" << decSize + << " / " << PixelWriteConverter->GetUserDataSize() ); return false; } break; case WMODE_RGB : if( rgbSize!=PixelWriteConverter->GetUserDataSize() ) { - Debug::Verbose(0, "File::CheckWriteIntegrity: Data size is incorrect (RGB)"); - //std::cerr << "File::CheckWriteIntegrity: Data size is incorrect (RGB)\n" - // << decSize << " / " << PixelWriteConverter->GetUserDataSize() << "\n"; + gdcmVerboseMacro( "Data size is incorrect (RGB)" << decSize + << " / " << PixelWriteConverter->GetUserDataSize() ); return false; } break; @@ -638,7 +650,8 @@ bool File::CheckWriteIntegrity() void File::SetWriteToRaw() { - if(HeaderInternal->GetNumberOfScalarComponents()==3 && !HeaderInternal->HasLUT()) + if( HeaderInternal->GetNumberOfScalarComponents() == 3 + && !HeaderInternal->HasLUT()) { SetWriteToRGB(); } @@ -657,7 +670,8 @@ void File::SetWriteToRaw() PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(), PixelReadConverter->GetRawSize()); - BinEntry *pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); + BinEntry *pixel = + CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); pixel->SetValue(GDCM_BINLOADED); pixel->SetBinArea(PixelWriteConverter->GetData(),false); pixel->SetLength(PixelWriteConverter->GetDataSize()); @@ -693,7 +707,8 @@ void File::SetWriteToRGB() PixelReadConverter->GetRawSize()); } - BinEntry *pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); + BinEntry *pixel = + CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); pixel->SetValue(GDCM_BINLOADED); pixel->SetBinArea(PixelWriteConverter->GetData(),false); pixel->SetLength(PixelWriteConverter->GetDataSize()); @@ -765,7 +780,7 @@ void File::SetWriteFileTypeToACR() void File::SetWriteFileTypeToExplicitVR() { std::string ts = Util::DicomString( - Document::GetTransferSyntaxValue(ExplicitVRLittleEndian).c_str() ); + Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) ); ValEntry *tss = CopyValEntry(0x0002,0x0010); tss->SetValue(ts); @@ -776,7 +791,7 @@ void File::SetWriteFileTypeToExplicitVR() void File::SetWriteFileTypeToImplicitVR() { std::string ts = Util::DicomString( - Document::GetTransferSyntaxValue(ImplicitVRLittleEndian).c_str() ); + Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) ); ValEntry *tss = CopyValEntry(0x0002,0x0010); tss->SetValue(ts); @@ -792,9 +807,9 @@ void File::RestoreWriteFileType() void File::SetWriteToLibido() { ValEntry *oldRow = dynamic_cast - (HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010)); + (HeaderInternal->GetDocEntry(0x0028, 0x0010)); ValEntry *oldCol = dynamic_cast - (HeaderInternal->GetDocEntryByNumber(0x0028, 0x0011)); + (HeaderInternal->GetDocEntry(0x0028, 0x0011)); if( oldRow && oldCol ) { @@ -821,7 +836,7 @@ void File::SetWriteToLibido() void File::SetWriteToNoLibido() { ValEntry *recCode = dynamic_cast - (HeaderInternal->GetDocEntryByNumber(0x0008,0x0010)); + (HeaderInternal->GetDocEntry(0x0008,0x0010)); if( recCode ) { if( recCode->GetValue() == "ACRNEMA_LIBIDO_1.1" ) @@ -840,9 +855,9 @@ void File::RestoreWriteOfLibido() Archive->Restore(0x0008,0x0010); } -ValEntry *File::CopyValEntry(uint16_t group,uint16_t element) +ValEntry *File::CopyValEntry(uint16_t group,uint16_t elem) { - DocEntry *oldE = HeaderInternal->GetDocEntryByNumber(group, element); + DocEntry *oldE = HeaderInternal->GetDocEntry(group, elem); ValEntry *newE; if(oldE) @@ -852,15 +867,15 @@ ValEntry *File::CopyValEntry(uint16_t group,uint16_t element) } else { - newE = GetHeader()->NewValEntryByNumber(group,element); + newE = GetHeader()->NewValEntry(group,elem); } - return(newE); + return newE; } -BinEntry *File::CopyBinEntry(uint16_t group,uint16_t element) +BinEntry *File::CopyBinEntry(uint16_t group,uint16_t elem) { - DocEntry *oldE = HeaderInternal->GetDocEntryByNumber(group, element); + DocEntry *oldE = HeaderInternal->GetDocEntry(group, elem); BinEntry *newE; if(oldE) @@ -870,10 +885,10 @@ BinEntry *File::CopyBinEntry(uint16_t group,uint16_t element) } else { - newE = GetHeader()->NewBinEntryByNumber(group,element); + newE = GetHeader()->NewBinEntry(group,elem); } - return(newE); + return newE; } //----------------------------------------------------------------------------- @@ -910,8 +925,7 @@ uint8_t *File::GetRaw() raw = PixelReadConverter->GetRaw(); if ( ! raw ) { - Debug::Verbose(0, "File::GetRaw: read/decompress of " - "pixel data apparently went wrong."); + gdcmVerboseMacro( "Read/decompress of pixel data apparently went wrong."); return 0; } }