From f5d6e67978dff569e38c19df24f14aea254ecd7b Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 30 Oct 2003 17:04:21 +0000 Subject: [PATCH] 2003-10-29 Jean-Pierre Roux * adding gdcmHeader::GetLUTRGBA returns a 4 * 256 Bytes Reg/Green/Blue/Alpha vtk compliant LUT --> Mathieu, the modif u're waiting for is not yet committed * removal of now useless GetLUTRed,GetLUTGreen,GetLUTBlue,GetLUTRGB --- src/gdcmHeader.cxx | 349 ++++++++++++++++++++++----------------------- 1 file changed, 173 insertions(+), 176 deletions(-) diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 7cb2cad0..d9e26448 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -1,4 +1,4 @@ -// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.103 2003/10/23 12:08:32 jpr Exp $ +// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.104 2003/10/30 17:04:21 jpr Exp $ #include "gdcmHeader.h" @@ -812,8 +812,7 @@ void gdcmHeader::FixFoundLength(gdcmElValue * ElVal, guint32 FoundLength) { * \ingroup gdcmHeader * \brief Swaps back the bytes of 4-byte long integer accordingly to * processor order. - * - * @return The suggested integer. + * @return The properly swaped 32 bits integer. */ guint32 gdcmHeader::SwapLong(guint32 a) { switch (sw) { @@ -912,13 +911,10 @@ void gdcmHeader::LoadElementValue(gdcmElValue * ElVal) { if( vr == "SQ" ) SkipLoad = true; - // Heuristic : a sequence "contains" a set of tags (called items). It looks - // like the last tag of a sequence (the one that terminates the sequence) - // has a group of 0xfffe (with a dummy length). - // Well ... - // Actually (fffe e000) tells us an Element is beginning + // A sequence "contains" a set of Elements. + // (fffe e000) tells us an Element is beginning // (fffe e00d) tells us an Element just ended - // (fffe e0dd) tells us the current SEQuence just ended + // (fffe e0dd) tells us the current SQuence just ended if( group == 0xfffe ) SkipLoad = true; @@ -1302,6 +1298,40 @@ size_t gdcmHeader::GetPixelOffset(void) { return 0; } +/** + * \ingroup gdcmHeader + * \brief Recover the pixel area length (in Bytes) . + */ +size_t gdcmHeader::GetPixelAreaLength(void) { + // If this file complies with the norm we should encounter the + // "Image Location" tag (0x0028, 0x0200). This tag contains the + // the group that contains the pixel data (hence the "Pixel Data" + // is found by indirection through the "Image Location"). + // Inside the group pointed by "Image Location" the searched element + // is conventionally the element 0x0010 (when the norm is respected). + // When the "Image Location" is absent we default to group 0x7fe0. + guint16 grPixel; + guint16 numPixel; + std::string ImageLocation = GetPubElValByName("Image Location"); + if ( ImageLocation == GDCM_UNFOUND ) { + grPixel = 0x7fe0; + } else { + grPixel = (guint16) atoi( ImageLocation.c_str() ); + } + if (grPixel != 0x7fe0) + // This is a kludge for old dirty Philips imager. + numPixel = 0x1010; + else + numPixel = 0x0010; + + gdcmElValue* PixelElement = PubElValSet.GetElementByNumber(grPixel, + numPixel); + if (PixelElement) + return PixelElement->GetLength(); + else + return 0; +} + /** * \ingroup gdcmHeader * \brief Searches both the public and the shadow dictionary (when they @@ -2084,39 +2114,22 @@ std::string gdcmHeader::GetTransferSyntaxName(void) { /** * \ingroup gdcmHeader - * \brief gets the info from 0028,1101 : Lookup Table Desc-Red - * \ else 0 - * @return Lookup Table Length - * \ when (0028,0004),Photometric Interpretation = [PALETTE COLOR ] + * \brief tells us if LUT are used + * @return int acts as a Boolean */ -int gdcmHeader::GetLUTLength(void) { - std::vector tokens; - int LutLength; - //int LutDepth; - //int LutNbits; - // Just hope Lookup Table Desc-Red = Lookup Table Desc-Red = Lookup Table Desc-Blue - std::string LutDescriptionR = GetPubElValByNumber(0x0028,0x1101); - if (LutDescriptionR == GDCM_UNFOUND) - return 0; - std::string LutDescriptionG = GetPubElValByNumber(0x0028,0x1102); - if (LutDescriptionG == GDCM_UNFOUND) +int gdcmHeader::HasLUT(void) { + + // Just hope checking the presence of the LUT Descriptors is enough + if (GetPubElValByNumber(0x0028,0x1101) == GDCM_UNFOUND) return 0; - std::string LutDescriptionB = GetPubElValByNumber(0x0028,0x1103); - if (LutDescriptionB == GDCM_UNFOUND) + // LutDescriptorGreen + if (GetPubElValByNumber(0x0028,0x1102) == GDCM_UNFOUND) return 0; - if( (LutDescriptionR != LutDescriptionG) || (LutDescriptionR != LutDescriptionB) ) { - dbg.Verbose(0, "gdcmHeader::GetLUTLength: The CLUT R,G,B are not equal"); - return 0; - } - std::cout << "Lut Description " << LutDescriptionR < tokens; + + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Tokenize (LutDescriptionR, tokens, "\\"); + lengthR=atoi(tokens[0].c_str()); // Red LUT length in Bytes + debR =atoi(tokens[1].c_str()); // subscript of the first Lut Value + nbitsR =atoi(tokens[2].c_str()); // Lut item size (in Bits) + tokens.clear(); - // Warning : Any value for nBits as to be considered as 8 - // Any value for Length as to be considered as 256 - // That's DICOM ... + tokens.erase(tokens.begin(),tokens.end()); // clean any previous value + Tokenize (LutDescriptionG, tokens, "\\"); + lengthG=atoi(tokens[0].c_str()); // Green LUT length in Bytes + debG =atoi(tokens[1].c_str()); + nbitsG =atoi(tokens[2].c_str()); + tokens.clear(); - // Just wait before removing the following code - /* - if (nBits == 16) { - guint16 * LUTRGB, *rgb; - LUTRGB = rgb = (guint16 *) malloc(3*l*sizeof( guint16)); - guint16 * r = (guint16 *)LutR; - guint16 * g = (guint16 *)LutG; - guint16 * b = (guint16 *)LutB; - for(int i=0;i tokens; - tokens.erase(tokens.begin(),tokens.end()); // clean any previous value - Tokenize ((const std::string)x, tokens, "\\"); - for (unsigned int i=0; i