-
- 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();
-
- tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
- Tokenize (LutDescriptionB, tokens, "\\");
- lengthB=atoi(tokens[0].c_str()); // Blue LUT length in Bytes
- debB =atoi(tokens[1].c_str());
- nbitsB =atoi(tokens[2].c_str());
- tokens.clear();
-
-// Load LUTs into memory, (as they were stored on disk)
- unsigned char *lutR = (unsigned char *)
- GetPubEntryVoidAreaByNumber(0x0028,0x1201);
- unsigned char *lutG = (unsigned char *)
- GetPubEntryVoidAreaByNumber(0x0028,0x1202);
- unsigned char *lutB = (unsigned char *)
- GetPubEntryVoidAreaByNumber(0x0028,0x1203);
-
- if (!lutR || !lutG || !lutB ) {
- return NULL;
- }
- // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
-
- unsigned char *LUTRGBA = (unsigned char *)calloc(1024,1); // 256 * 4 (R, G, B, Alpha)
- if (!LUTRGBA) {
- return NULL;
- }
- memset(LUTRGBA, 0, 1024);
- // Bits Allocated
- int nb;
- std::string str_nb = GetEntryByNumber(0x0028,0x0100);
- if (str_nb == GDCM_UNFOUND ) {
- nb = 16;
- } else {
- nb = atoi(str_nb.c_str() );
- }
- int mult;
-
- if (nbitsR==16 && nb==8) // when LUT item size is different than pixel size
- mult=2; // high byte must be = low byte
- else // See PS 3.3-2003 C.11.1.1.2 p 619
- mult=1;
-
- // if we get a black image, let's just remove the '+1'
- // from 'i*mult+1' and check again
- // if it works, we shall have to check the 3 Palettes
- // to see which byte is ==0 (first one, or second one)
- // and fix the code
- // We give up the checking to avoid some overhead
- unsigned char *a;
- int i;
-
- a = LUTRGBA+0;
- for(i=0;i<lengthR;i++) {
- *a = lutR[i*mult+1];
- a+=4;
- }
- a = LUTRGBA+1;
- for(i=0;i<lengthG;i++) {
- *a = lutG[i*mult+1];
- a+=4;
- }
- a = LUTRGBA+2;
- for(i=0;i<lengthB;i++) {
- *a = lutB[i*mult+1];
- a+=4;
- }
- a = LUTRGBA+3;
- for(i=0;i<256;i++) {
- *a = 1; // Alpha component
- a+=4;
- }
-
-//How to free the now useless LUTs?
-
-//free(LutR); free(LutB); free(LutG); // Seg Fault when used
- return(LUTRGBA);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief gets the info from 0002,0010 : Transfert Syntax
- * \ else 1.
- * @return Transfert Syntax Name (as oposite to Transfert Syntax UID)
- */
-std::string gdcmHeader::GetTransfertSyntaxName(void) {
- // use the gdcmTS (TS : Transfert Syntax)
- std::string TransfertSyntax = GetEntryByNumber(0x0002,0x0010);
- if (TransfertSyntax == GDCM_UNFOUND) {
- dbg.Verbose(0, "gdcmHeader::GetTransfertSyntaxName: unfound Transfert Syntax (0002,0010)");
- return "Uncompressed ACR-NEMA";
- }
- // we do it only when we need it
- gdcmTS * ts = gdcmGlobal::GetTS();
- std::string tsName=ts->GetValue(TransfertSyntax);
- //delete ts; // Seg Fault when deleted ?!
- return tsName;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within the file Header for element value of
- * a given tag.
- * @param tagName name of the searched element.
- * @return Corresponding element value when it exists, and the string
- * GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetPubEntryByName(std::string tagName) {
- gdcmDictEntry *dictEntry = RefPubDict->GetTagByName(tagName);
- if( dictEntry == NULL)
- return GDCM_UNFOUND;
-
- return(GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()));
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within the elements parsed with the file Header for
- * the element value representation of a given tag.
- *
- * Obtaining the VR (Value Representation) might be needed by caller
- * to convert the string typed content to caller's native type
- * (think of C++ vs Python). The VR is actually of a higher level
- * of semantics than just the native C++ type.
- * @param tagName name of the searched element.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetPubEntryVRByName(std::string tagName) {
- gdcmDictEntry *dictEntry = RefPubDict->GetTagByName(tagName);
- if( dictEntry == NULL)
- return GDCM_UNFOUND;
-
- gdcmHeaderEntry* elem = GetHeaderEntryByNumber(dictEntry->GetGroup(),
- dictEntry->GetElement());
- return elem->GetVR();
-}
-
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within the public dictionary for element value
- * representation of a given tag.
- *
- * Obtaining the VR (Value Representation) might be needed by caller
- * to convert the string typed content to caller's native type
- * (think of C++ vs Python). The VR is actually of a higher level
- * of semantics than just the native C++ type.
- * @param group Group of the researched tag.
- * @param element Element of the researched tag.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetPubEntryVRByNumber(guint16 group, guint16 element) {
- gdcmHeaderEntry* elem = GetHeaderEntryByNumber(group, element);
- if ( !elem )
- return GDCM_UNFOUND;
- return elem->GetVR();
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element)
- * in the PubHeaderEntrySet of this instance
- * through tag name and modifies it's content with the given value.
- * @param content new value to substitute with
- * @param tagName name of the Header Entry (Dicom Element) to be modified
- */
-bool gdcmHeader::SetPubEntryByName(std::string content, std::string tagName) {
- //return ( PubHeaderEntrySet.SetHeaderEntryByName (content, tagName) );
- gdcmDictEntry *dictEntry = RefPubDict->GetTagByName(tagName);
- if( dictEntry == NULL)
- return false;
- return(SetEntryByNumber(content,
- dictEntry->GetGroup(),
- dictEntry->GetElement()));
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element)
- * through it's (group, element) and modifies it's content with
- * the given value.
- * @param content new value to substitute with
- * @param group group of the Dicom Element to modify
- * @param element element of the Dicom Element to modify
- */
-bool gdcmHeader::SetPubEntryByNumber(std::string content,
- guint16 group,
- guint16 element) {
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
- if ( ! tagHT.count(key))
- return false;
- int l = content.length();
- if(l%2) { // Odd length are padded with a space (020H).
- l++;
- content = content + '\0';
- }
-
- //tagHT[key]->SetValue(content);
- gdcmHeaderEntry * a;
- IterHT p;
- TagHeaderEntryHT::iterator p2;
- // DO NOT remove the following lines : they explain the stuff
- //p= tagHT.equal_range(key); // get a pair of iterators first-last synonym
- //p2=p.first; // iterator on the first synonym
- //a=p2->second; // H Table target column (2-nd col)
-
- // or, easier :
- a = ((tagHT.equal_range(key)).first)->second;
-
- a-> SetValue(content);
-
- //std::string vr = tagHT[key]->GetVR();
- std::string vr = a->GetVR();
-
- guint32 lgr;
- if( (vr == "US") || (vr == "SS") )
- lgr = 2;
- else if( (vr == "UL") || (vr == "SL") )
- lgr = 4;
- else
- lgr = l;
- //tagHT[key]->SetLength(lgr);
- a->SetLength(lgr);
- return true;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element)
- * through it's (group, element) and modifies it's content with
- * the given value.
- * \warning Don't use any longer : use SetPubEntryByNumber
- * @param content new value to substitute with
- * @param group group of the Dicom Element to modify
- * @param element element of the Dicom Element to modify
- */
-bool gdcmHeader::SetEntryByNumber(std::string content,
- guint16 group,
- guint16 element) {
- return SetPubEntryByNumber(content, group, element);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element)
- * in the PubHeaderEntrySet of this instance
- * through it's (group, element) and modifies it's length with
- * the given value.
- * \warning Use with extreme caution.
- * @param length new length to substitute with
- * @param group group of the ElVal to modify
- * @param element element of the ElVal to modify
- * @return 1 on success, 0 otherwise.
- */
-
-bool gdcmHeader::SetPubEntryLengthByNumber(guint32 length,
- guint16 group, guint16 element) {
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
- if ( ! tagHT.count(key))
- return false;
- if (length%2) length++; // length must be even
- //tagHT[key]->SetLength(length);
- ( ((tagHT.equal_range(key)).first)->second )->SetLength(length);
-
- return true ;
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Accesses an existing gdcmHeaderEntry (i.e. a Dicom Element)
- * in the PubHeaderEntrySet of this instance
- * through it's (group, element) and modifies it's length with
- * the given value.
- * \warning Don't use any longer : use SetPubEntryLengthByNumber
- * @param length new length to substitute with
- * @param group group of the ElVal to modify
- * @param element element of the ElVal to modify
- * @return 1 on success, 0 otherwise.
- */
-
-bool gdcmHeader::SetEntryLengthByNumber(guint32 length,
- guint16 group, guint16 element) {
- return SetPubEntryLengthByNumber( length, group,element);
-}
-/**
- * \ingroup gdcmHeader
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the element value of a given tag.
- * \warning Don't use any longer : use GetPubEntryByName
- * @param tagName name of the searched element.
- * @return Corresponding element value when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetEntryByName(std::string tagName) {
- return GetPubEntryByName(tagName);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the element value representation of a given tag.
- *
- * Obtaining the VR (Value Representation) might be needed by caller
- * to convert the string typed content to caller's native type
- * (think of C++ vs Python). The VR is actually of a higher level
- * of semantics than just the native C++ type.
- * @param tagName name of the searched element.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetEntryVRByName(std::string tagName) {
- return GetPubEntryVRByName(tagName);
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within Header Entries (Dicom Elements) parsed with
- * the public and private dictionaries
- * for the element value representation of a given tag.
- * @param group Group of the searched tag.
- * @param element Element of the searched tag.
- * @return Corresponding element value representation when it exists,
- * and the string GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetEntryByNumber(guint16 group, guint16 element) {
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
- if ( ! tagHT.count(key))
- return GDCM_UNFOUND;
- return tagHT.find(key)->second->GetValue();
-}
-
-/**
- * \ingroup gdcmHeader
- * \brief Searches within the public dictionary for element value of
- * a given tag.
- * @param group Group of the researched tag.
- * @param element Element of the researched tag.
- * @return Corresponding element value when it exists, and the string
- * GDCM_UNFOUND ("gdcm::Unfound") otherwise.
- */
-std::string gdcmHeader::GetPubEntryByNumber(guint16 group, guint16 element) {
- return GetEntryByNumber(group, element);
-}
-