X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmHeader.cxx;h=0dc8ef974d96b8c77a945cc488067f18b0438e7a;hb=8fa22a939771f727812c725d99ea5b75f56f0c71;hp=4318d69fb01310a6f71f958321131cc4d9ba1361;hpb=b3f903e00dbe97bcd6697ba659d0f1aa586bbbb8;p=gdcm.git diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 4318d69f..0dc8ef97 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeader.cxx,v $ Language: C++ - Date: $Date: 2004/06/21 04:18:25 $ - Version: $Revision: 1.166 $ + Date: $Date: 2004/06/28 16:00:18 $ + Version: $Revision: 1.174 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -29,7 +29,7 @@ // Constructor / Destructor /** * \brief Constructor - * @param InFilename name of the file whose header we want to analyze + * @param filename name of the file whose header we want to analyze * @param exception_on_error whether we want to throw an exception or not * @param enable_sequences = true to allow the header * to be parsed *inside* the SeQuences, when they have an actual length @@ -41,14 +41,7 @@ gdcmHeader::gdcmHeader(std::string const & filename, bool enable_sequences, bool ignore_shadow): gdcmDocument(filename,exception_on_error,enable_sequences,ignore_shadow) -{ -/* - typedef struct { - guint32 totalSQlength; - guint32 alreadyParsedlength; - } pileElem; -*/ - +{ // for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010 // We may encounter the 'RETired' (0x0028, 0x0200) tag // (Image Location") . This Element contains the number of @@ -90,7 +83,68 @@ gdcmHeader::gdcmHeader(bool exception_on_error) : * \ingroup gdcmHeader * \brief Canonical destructor. */ -gdcmHeader::~gdcmHeader (void) { +gdcmHeader::~gdcmHeader () { +} + + +/** + * \brief Performs some consistency checking on various 'File related' + * (as opposed to 'DicomDir related') entries + * then writes in a file all the (Dicom Elements) included the Pixels + * @param fp file pointer on an already open file + * @param filetype Type of the File to be written + * (ACR-NEMA, ExplicitVR, ImplicitVR) + */ +void gdcmHeader::Write(FILE* fp,FileType filetype) { + + // Bits Allocated + if ( GetEntryByNumber(0x0028,0x0100) == "12") { + SetEntryByNumber("16", 0x0028,0x0100); + } + + // correct Pixel group Length if necessary + + // TODO : create a gdcmHeader::Write method and move this part. + // (only gdcmHeader knows GrPixel, NumPixel) + + int i_lgPix = GetEntryLengthByNumber(GrPixel, NumPixel); + if (i_lgPix != -2) { // no (GrPixel, NumPixel) element + char * dumm = new char[20]; + sprintf(dumm ,"%d", i_lgPix+12); + std::string s_lgPix = dumm; + delete dumm; + ReplaceOrCreateByNumber(s_lgPix,GrPixel, 0x0000); + } + + // Drop Palette Color, if necessary + + if ( GetEntryByNumber(0x0028,0x0002).c_str()[0] == '3' ) { + // if SamplesPerPixel = 3, sure we don't need any LUT ! + // Drop 0028|1101, 0028|1102, 0028|1103 + // Drop 0028|1201, 0028|1202, 0028|1203 + + gdcmDocEntry *e; + e=GetDocEntryByNumber(0x0028,0x01101); + if (e) + RemoveEntry(e); + e=GetDocEntryByNumber(0x0028,0x1102); + if (e) + RemoveEntry(e); + e=GetDocEntryByNumber(0x0028,0x1103); + + if (e) + RemoveEntry(e); + e=GetDocEntryByNumber(0x0028,0x01201); + if (e) + RemoveEntry(e); + e=GetDocEntryByNumber(0x0028,0x1202); + if (e) + RemoveEntry(e); + e=GetDocEntryByNumber(0x0028,0x1203); + if (e) + RemoveEntry(e); + } + gdcmDocument::Write(fp,filetype); } //----------------------------------------------------------------------------- @@ -108,7 +162,7 @@ gdcmHeader::~gdcmHeader (void) { * @return true when gdcmHeader is the one of a reasonable Dicom/Acr file, * false otherwise. */ -bool gdcmHeader::IsReadable(void) { +bool gdcmHeader::IsReadable() { if(!gdcmDocument::IsReadable()) { return false; } @@ -131,7 +185,7 @@ bool gdcmHeader::IsReadable(void) { * @return The encountered size when found, 0 by default. * 0 means the file is NOT USABLE. The caller will have to check */ -int gdcmHeader::GetXSize(void) { +int gdcmHeader::GetXSize() { std::string StrSize; StrSize = GetEntryByNumber(0x0028,0x0011); if (StrSize == GDCM_UNFOUND) @@ -144,9 +198,9 @@ int gdcmHeader::GetXSize(void) { * \brief Retrieve the number of lines of image. * \warning The defaulted value is 1 as opposed to gdcmHeader::GetXSize() * @return The encountered size when found, 1 by default - * (The ACR-MEMA file contains a Signal, not an Image). + * (The ACR-NEMA file contains a Signal, not an Image). */ -int gdcmHeader::GetYSize(void) { +int gdcmHeader::GetYSize() { std::string StrSize = GetEntryByNumber(0x0028,0x0010); if (StrSize != GDCM_UNFOUND) return atoi(StrSize.c_str()); @@ -167,7 +221,7 @@ int gdcmHeader::GetYSize(void) { * being the ACR-NEMA "Planes" tag content. * @return The encountered size when found, 1 by default (single image). */ -int gdcmHeader::GetZSize(void) { +int gdcmHeader::GetZSize() { // Both DicomV3 and ACR/Nema consider the "Number of Frames" // as the third dimension. std::string StrSize = GetEntryByNumber(0x0028,0x0008); @@ -320,10 +374,10 @@ int gdcmHeader::GetNumberOfScalarComponents() { if (HasLUT()) // PALETTE COLOR is NOT enough return 3; else - return 1; + return 1; } - - //beware of trailing space at end of string + + //beware of trailing space at end of string if (PhotometricInterpretation.find(GDCM_UNFOUND) < PhotometricInterpretation.length() || PhotometricInterpretation.find("MONOCHROME1") < @@ -532,7 +586,7 @@ int gdcmHeader::GetImageNumber() { * \brief gets the info from 0008,0060 : Modality * @return Modality Type */ -ModalityType gdcmHeader::GetModality(void) { +ModalityType gdcmHeader::GetModality() { // 0008 0060 CS ID Modality std::string StrModality = GetEntryByNumber(0x0008,0x0060); if (StrModality != GDCM_UNFOUND) { @@ -609,7 +663,7 @@ int gdcmHeader::GetBitsStored() { * @return The encountered number of Bits Allocated, 0 by default. * 0 means the file is NOT USABLE. The caller has to check it ! */ -int gdcmHeader::GetBitsAllocated(void) { +int gdcmHeader::GetBitsAllocated() { std::string StrSize = GetEntryByNumber(0x0028,0x0100); if (StrSize == GDCM_UNFOUND) return 0; // It's supposed to be mandatory @@ -624,7 +678,7 @@ int gdcmHeader::GetBitsAllocated(void) { * @return The encountered number of Samples Per Pixel, 1 by default. * (Gray level Pixels) */ -int gdcmHeader::GetSamplesPerPixel(void) { +int gdcmHeader::GetSamplesPerPixel() { std::string StrSize = GetEntryByNumber(0x0028,0x0002); if (StrSize == GDCM_UNFOUND) return 1; // Well, it's supposed to be mandatory ... @@ -638,7 +692,7 @@ int gdcmHeader::GetSamplesPerPixel(void) { * (0 : RGB Pixels , 1 : R Plane + G Plane + B Plane) * @return The encountered Planar Configuration, 0 by default. */ -int gdcmHeader::GetPlanarConfiguration(void) { +int gdcmHeader::GetPlanarConfiguration() { std::string StrSize = GetEntryByNumber(0x0028,0x0006); if (StrSize == GDCM_UNFOUND) return 0; @@ -718,7 +772,7 @@ std::string gdcmHeader::GetPixelType() { * of *image* pixels (not *icone image* pixels, if any !) * @return Pixel Offset */ -size_t gdcmHeader::GetPixelOffset(void) { +size_t gdcmHeader::GetPixelOffset() { gdcmDocEntry* PixelElement = GetDocEntryByNumber(GrPixel,NumPixel); @@ -742,7 +796,7 @@ size_t gdcmHeader::GetPixelOffset(void) { * -in case of embeded compressed image-) * 0 : NOT USABLE file. The caller has to check. */ -size_t gdcmHeader::GetPixelAreaLength(void) { +size_t gdcmHeader::GetPixelAreaLength() { gdcmDocEntry* PixelElement = GetDocEntryByNumber(GrPixel,NumPixel); @@ -801,7 +855,7 @@ bool gdcmHeader::HasLUT() { * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ] * @ return bit number of each LUT item */ -int gdcmHeader::GetLUTNbits(void) { +int gdcmHeader::GetLUTNbits() { std::vector tokens; //int LutLength; //int LutDepth; @@ -836,12 +890,12 @@ int gdcmHeader::GetLUTNbits(void) { * no known Dicom reader deals with them :-( * @return a RGBA Lookup Table */ -unsigned char * gdcmHeader::GetLUTRGBA(void) { +unsigned char * gdcmHeader::GetLUTRGBA() { // Not so easy : see // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables // if Photometric Interpretation # PALETTE COLOR, no LUT to be done - if (GetEntryByNumber(0x0028,0x0004) != "PALETTE COLOR ") { + if (GetEntryByNumber(0x0028,0x0004) != "PALETTE COLOR ") { return NULL; } int lengthR, debR, nbitsR; @@ -859,7 +913,7 @@ unsigned char * gdcmHeader::GetLUTRGBA(void) { std::string LutDescriptionB = GetEntryByNumber(0x0028,0x1103); if (LutDescriptionB == GDCM_UNFOUND) return NULL; - + std::vector tokens; tokens.erase(tokens.begin(),tokens.end()); // clean any previous value @@ -890,7 +944,7 @@ unsigned char * gdcmHeader::GetLUTRGBA(void) { GetEntryVoidAreaByNumber(0x0028,0x1202); unsigned char *lutB = (unsigned char *) GetEntryVoidAreaByNumber(0x0028,0x1203); - + if (!lutR || !lutG || !lutB ) { return NULL; } @@ -957,7 +1011,7 @@ unsigned char * gdcmHeader::GetLUTRGBA(void) { * else 1. * @return The full Transfert Syntax Name (as opposed to Transfert Syntax UID) */ -std::string gdcmHeader::GetTransfertSyntaxName(void) { +std::string gdcmHeader::GetTransfertSyntaxName() { // use the gdcmTS (TS : Transfert Syntax) std::string TransfertSyntax = GetEntryByNumber(0x0002,0x0010); if (TransfertSyntax == GDCM_UNFOUND) {