From 1a57b1cdd381b9e1c7a2cfde196907788575162b Mon Sep 17 00:00:00 2001 From: jpr Date: Wed, 22 Jun 2005 08:37:54 +0000 Subject: [PATCH] Waiting for a clever idea on the way to userfriendly manage them, LUT Data (*not* Palette Color) extraction and display is let in the application. Wiil probabely be moved to method of PixelReadConvert. --- Example/PrintFile.cxx | 160 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 150 insertions(+), 10 deletions(-) diff --git a/Example/PrintFile.cxx b/Example/PrintFile.cxx index 9ff3a681..de9dca99 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 14:36:19 $ - Version: $Revision: 1.40 $ + Date: $Date: 2005/06/22 08:37:54 $ + Version: $Revision: 1.41 $ 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[]) { @@ -141,20 +235,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 +296,20 @@ int main(int argc, char *argv[]) { uint16_t* lutrgba16 = (uint16_t*)lutrgba; for (int i=0;iGetLutItemNumber();i++) - std::cout << lutrgba16[i*4] << " " - << lutrgba16[i*4+1] << " " - << lutrgba16[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 <