X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FPrintFile.cxx;h=b2eb2dec424c8eb2a6be387e06e9ad9a4d480c5a;hb=986a43287516de55e51b476572366c85e9fa2b8d;hp=475c258b31ac1618d493eacc1179f55c0d379e82;hpb=6a7113502bc94c39a4dad73df086351f5390a1ef;p=gdcm.git diff --git a/Example/PrintFile.cxx b/Example/PrintFile.cxx index 475c258b..b2eb2dec 100644 --- a/Example/PrintFile.cxx +++ b/Example/PrintFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: PrintFile.cxx,v $ Language: C++ - Date: $Date: 2005/06/17 12:46:15 $ - Version: $Revision: 1.39 $ + Date: $Date: 2005/06/29 16:00:13 $ + Version: $Revision: 1.42 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -16,6 +16,10 @@ =========================================================================*/ #include "gdcmFile.h" +#include "gdcmSeqEntry.h" +#include "gdcmSQItem.h" +#include "gdcmBinEntry.h" + #include "gdcmFileHelper.h" #include "gdcmDebug.h" @@ -23,6 +27,96 @@ #include + +void ShowLutData(gdcm::File *e1); + +void ShowLutData(gdcm::File *e1) +{ + // Nothing is written yet to get LUT Data user friendly + // The following is to be moved into a PixelReadConvert method + // Let here, waiting for a clever idea on the way to do it. + + gdcm::SeqEntry *modLutSeq = e1->GetSeqEntry(0x0028,0x3000); + if ( modLutSeq !=0 ) + { + gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem(); + if ( sqi != 0 ) + { + std::string lutDescriptor = sqi->GetEntryValue(0x0028,0x3002); + if ( /*lutDescriptor == GDCM_UNFOUND*/ 0 ) + { + //gdcmWarningMacro( "LUT Descriptor is missing" ); + std::cout << "LUT Descriptor is missing" << std::endl; + return; + } + int length; // LUT length in Bytes + int deb; // Subscript of the first Lut Value + int nbits; // Lut item size (in Bits) + + int nbRead; // nb of items in LUT descriptor (must be = 3) + + nbRead = sscanf( lutDescriptor.c_str(), + "%d\\%d\\%d", + &length, &deb, &nbits ); + std::cout << "length " << length + << " deb " << deb + << " nbits " << nbits + << std::endl; + if ( nbRead != 3 ) + { + //gdcmWarningMacro( "Wrong LUT descriptor" ); + std::cout << "Wrong LUT descriptor" << std::endl; + } + //LUT Data (CTX dependent) + gdcm::BinEntry *b = sqi->GetBinEntry(0x0028,0x3006); + if ( b != 0 ) + { + int BitsAllocated = e1->GetBitsAllocated(); + if ( BitsAllocated <= 8 ) + { + int mult; + if ( ( nbits == 16 ) && ( BitsAllocated == 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; + } + uint8_t *lut = b->GetBinArea(); + for( int i=0; i < length; ++i ) + { + std::cout << i+deb << " : \t" + << (int) (lut[i*mult + 1]) << std::endl; + } + } + else + { + uint16_t *lut = (uint16_t *)(b->GetBinArea()); + for( int i=0; i < length; ++i ) + { + std::cout << i+deb << " : \t" + << (int) (((uint16_t *)lut)[i]) + << std::endl; + } + } + } + else + std::cout << "No LUT Data BinEntry (0x0028,0x3006) found?!? " + << std::endl; + } + else + std::cout << "No First SQ Item within (0x0028,0x3000) ?!? " + << std::endl; + } + else + std::cout << "No LUT Data SeqEntry (0x0028,0x3000) found " + << std::endl; + + } + int main(int argc, char *argv[]) { @@ -50,8 +144,10 @@ int main(int argc, char *argv[]) char *fileName = am->ArgMgrWantString("filein",usage); int loadMode; - if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") ) - loadMode = NO_SEQ | NO_SHADOW; + if ( am->ArgMgrDefined("noshadowseq") ) + loadMode = NO_SHADOWSEQ; + else if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") ) + loadMode = NO_SEQ | NO_SHADOW; else if ( am->ArgMgrDefined("noshadow") ) loadMode = NO_SHADOW; else if ( am->ArgMgrDefined("noseq") ) @@ -141,20 +237,60 @@ int main(int argc, char *argv[]) << std::endl; std::cout << " SwapCode= " << e1->GetSwapCode() << std::endl; - // Display the LUT as an int array (for degugging purpose) + // Display the LUT as an int array (for debugging purpose) if ( e1->HasLUT() && showlut ) { uint8_t* lutrgba = f1->GetLutRGBA(); if ( lutrgba == 0 ) { - std::cout << "Lut RGBA not built ?!?" << std::endl; - } + std::cout << "Lut RGBA (Palette Color) not built " << std::endl; + + // Nothing is written yet to get LUT Data user friendly + // The following is to be moved into a PixelRedaConvert method + + gdcm::SeqEntry *modLutSeq = e1->GetSeqEntry(0x0028,0x3000); + if ( modLutSeq !=0 ) + { + gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem(); + if ( !sqi ) + { + std::string lutDescriptor = sqi->GetEntryValue(0x0028,0x3002); + int length; // LUT length in Bytes + int deb; // Subscript of the first Lut Value + int nbits; // Lut item size (in Bits) + int nbRead; // nb of items in LUT descriptor (must be = 3) + + nbRead = sscanf( lutDescriptor.c_str(), + "%d\\%d\\%d", + &length, &deb, &nbits ); + if ( nbRead != 3 ) + { + //gdcmWarningMacro( "Wrong LUT descriptor" ); + std::cout << "Wrong LUT descriptor" << std::endl; + } + gdcm::BinEntry *b = sqi->GetBinEntry(0x0028,0x3006); + if ( b != 0 ) + { + if ( b->GetLength() != 0 ) + { + std::cout << "---------------------------------------" + << " We should never reach this point " + << std::endl; + //LoadEntryBinArea(b); //LUT Data (CTX dependent) + } + } + } + } + else + std::cout << "No LUT Data (0x0028,0x3000) found " << std::endl; + } else { if ( f1->GetLutItemSize() == 8 ) { for (int i=0;iGetLutItemNumber();i++) - std::cout << (int)(lutrgba[i*4]) << " " + std::cout << i << " : \t" + << (int)(lutrgba[i*4]) << " " << (int)(lutrgba[i*4+1]) << " " << (int)(lutrgba[i*4+2]) << std::endl; } @@ -162,14 +298,20 @@ int main(int argc, char *argv[]) { uint16_t* lutrgba16 = (uint16_t*)lutrgba; for (int i=0;iGetLutItemNumber();i++) - std::cout << lutrgba[i*4] << " " - << lutrgba[i*4+1] << " " - << lutrgba[i*4+2] << std::endl; + std::cout << i << " : \t" + << (int)(lutrgba16[i*4]) << " " + << (int)(lutrgba16[i*4+1]) << " " + << (int)(lutrgba16[i*4+2]) << std::endl; } } } + else if (showlut) + { + std::cout << "Try LUT Data "<< std::endl; + ShowLutData(e1); + } - if(e1->IsReadable()) + if (e1->IsReadable()) std::cout <