X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmFile.cxx;h=b016e992e73844f3288e61104e8c91904706f456;hb=a5477cb88aa763acdea8f3fbd6e58d70cec8f42e;hp=6e25ca5e6b2852cdf9122306d78bca2c4860b03a;hpb=3fc41aea775ed21181d7ff48903483b3218cf8a6;p=gdcm.git diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 6e25ca5e..b016e992 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2004/06/28 14:12:03 $ - Version: $Revision: 1.112 $ + Date: $Date: 2004/08/02 16:42:14 $ + Version: $Revision: 1.120 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -62,26 +62,10 @@ gdcmFile::gdcmFile(gdcmHeader *header) * one sets an a posteriori shadow dictionary (efficiency can be * seen as a side effect). * @param filename file to be opened for parsing - * @param exception_on_error whether we 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 - * \warning enable_sequences *has to be* true for reading PAPYRUS 3.0 files - * @param ignore_shadow to allow skipping the shadow elements, - * to save memory space. - * \warning The TRUE value for this param has to be used - * with a FALSE value for the 'enable_sequence' param. - * ('public elements' may be embedded in 'shadow Sequences') */ -gdcmFile::gdcmFile(std::string const & filename, - bool exception_on_error, - bool enable_sequences, - bool ignore_shadow) +gdcmFile::gdcmFile(std::string const & filename ) { - Header = new gdcmHeader( filename, - exception_on_error, - enable_sequences, - ignore_shadow ); + Header = new gdcmHeader( filename ); SelfHeader = true; PixelRead = -1; // no ImageData read yet. @@ -169,7 +153,7 @@ void gdcmFile::SetPixelDataSizeFromHeader() std::string str_PhotometricInterpretation = Header->GetEntryByNumber(0x0028,0x0004); - /*if ( str_PhotometricInterpretation == "PALETTE COLOR " )*/ + // if ( str_PhotometricInterpretation == "PALETTE COLOR " ) // pb when undealt Segmented Palette Color if ( Header->HasLUT() ) @@ -244,7 +228,7 @@ void *gdcmFile::GetImageData() * * @param destination Address (in caller's memory space) at which the * pixel data should be copied - * @param MaxSize Maximum number of bytes to be copied. When MaxSize + * @param maxSize Maximum number of bytes to be copied. When MaxSize * is not sufficient to hold the pixel data the copy is not * executed (i.e. no partial copy). * @return On success, the number of bytes actually copied. Zero on @@ -263,7 +247,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t maxSize) // from Lut R + Lut G + Lut B uint8_t *newDest = new uint8_t[ImageDataSize]; uint8_t *a = (uint8_t *)destination; - uint8_t *lutRGBA = Header->GetLUTRGBA(); + uint8_t *lutRGBA = Header->GetLUTRGBA(); if ( lutRGBA ) { @@ -288,7 +272,7 @@ size_t gdcmFile::GetImageDataIntoVector (void* destination, size_t maxSize) std::string spp = "3"; // Samples Per Pixel Header->SetEntryByNumber(spp,0x0028,0x0002); - std::string rgb= "RGB "; // Photometric Interpretation + std::string rgb = "RGB "; // Photometric Interpretation Header->SetEntryByNumber(rgb,0x0028,0x0004); std::string planConfig = "0"; // Planar Configuration Header->SetEntryByNumber(planConfig,0x0028,0x0006); @@ -330,7 +314,6 @@ void * gdcmFile::GetImageDataRaw () if ( Header->HasLUT() ) { /// \todo Let gdcmHeader user a chance to get the right value - // ImageDataSize /= 3; //dangerous imgDataSize = ImageDataSizeRaw; } @@ -366,7 +349,7 @@ void * gdcmFile::GetImageDataRaw () * * @param destination Address (in caller's memory space) at which the * pixel data should be copied - * @param MaxSize Maximum number of bytes to be copied. When MaxSize + * @param maxSize Maximum number of bytes to be copied. When MaxSize * is not sufficient to hold the pixel data the copy is not * executed (i.e. no partial copy). * @return On success, the number of bytes actually copied. Zero on @@ -473,9 +456,9 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void *destination, size_t maxSize) } else if ( nb == 32 ) { - guint32 mask = 0xffffffff; + uint32_t mask = 0xffffffff; mask = mask >> (nb - nbu); - guint32 *deb = (guint32 *)destination; + uint32_t *deb = (uint32_t *)destination; for(int i = 0; i> (nbu - highBit - 1)) & mask; @@ -635,7 +618,7 @@ size_t gdcmFile::GetImageDataIntoVectorRaw (void *destination, size_t maxSize) * 'volume'Pixels are presented as C-like 3D arrays : lane per plane * \warning user is kindly requested NOT TO 'free' the Pixel area * @param inData user supplied pixel area - * @param ExpectedSize total image size, in Bytes + * @param expectedSize total image size, in Bytes * * @return boolean */ @@ -661,14 +644,13 @@ bool gdcmFile::SetImageData(void *inData, size_t expectedSize) bool gdcmFile::WriteRawData(std::string const & fileName) { - FILE *fp1; - fp1 = fopen(fileName.c_str(), "wb"); + FILE *fp1 = fopen(fileName.c_str(), "wb"); if (fp1 == NULL) { printf("Fail to open (write) file [%s] \n", fileName.c_str()); return false; } - fwrite (PixelData,ImageDataSize, 1, fp1); + fwrite (PixelData, ImageDataSize, 1, fp1); fclose (fp1); return true; @@ -736,14 +718,12 @@ bool gdcmFile::WriteAcr (std::string const & fileName) */ bool gdcmFile::WriteBase (std::string const & fileName, FileType type) { - FILE *fp1; - if ( PixelRead == -1 && type != gdcmExplicitVR) { return false; } - fp1 = fopen(fileName.c_str(), "wb"); + FILE *fp1 = fopen(fileName.c_str(), "wb"); if (fp1 == NULL) { printf("Failed to open (write) File [%s] \n", fileName.c_str()); @@ -781,45 +761,24 @@ bool gdcmFile::WriteBase (std::string const & fileName, FileType type) Header->SetEntryByNumber(rows , 0x0028, 0x0011); } // ----------------- End of Special Patch ---------------- - - /// \todo get the grPixel, numPixel values (for some ACR-NEMA images only) - + uint16_t grPixel = Header->GetGrPixel(); uint16_t numPixel = Header->GetNumPixel();; - - // Update Pixel Data Length - // the *last* of the (GrPixel, NumPixel), if many. - TagKey key = gdcmDictEntry::TranslateToKey(grPixel, numPixel); - TagDocEntryHT::iterator p2; - gdcmDocEntry* PixelElement; - - IterHT it = Header->GetEntry().equal_range(key); // get a pair of iterators first-last synonym - - if ( Header->GetEntry().count(key) == 1 ) // only the first is significant - { - p2 = it.first; // iterator on the first (unique) synonym - } - else - { - p2 = it.second;// iterator on the last synonym - } - - PixelElement = p2->second; // H Table target column (2-nd col) - // PixelElement->SetPrintLevel(2); - // PixelElement->Print(); + gdcmDocEntry* PixelElement = + GetHeader()->GetDocEntryByNumber(grPixel, numPixel); if ( PixelRead == 1 ) { + // we read pixel 'as is' (no tranformation LUT -> RGB) PixelElement->SetLength( ImageDataSizeRaw ); } else if ( PixelRead == 0 ) { + // we tranformed GrayLevel pixels + LUT into RGB Pixel PixelElement->SetLength( ImageDataSize ); } - - //PixelElement->SetPrintLevel(2); - //PixelElement->Print(); + Header->Write(fp1, type); // -------------------------------------------------------------- @@ -871,7 +830,7 @@ void gdcmFile::SwapZone(void *im, int swap, int lgr, int nb) case 4321: for(i=0; i < lgr/2; i++) { - im16[i]= (im16[i] >> 8) | (im16[i] << 8 ); + im16[i]= (im16[i] >> 8) | (im16[i] << 8 ); } break; default: @@ -1000,7 +959,7 @@ bool gdcmFile::ReadPixelData(void *destination) // ---------------------- Run Length Encoding if ( Header->IsRLELossLessTransferSyntax() ) { - bool res = (bool)gdcm_read_RLE_file (fp,destination); + bool res = gdcm_read_RLE_file (fp,destination); Header->CloseFile(); return res; } @@ -1080,7 +1039,7 @@ bool gdcmFile::ReadPixelData(void *destination) if ( jpg2000 ) { // JPEG 2000 : call to ??? - res = (bool)gdcm_read_JPEG2000_file (fp,destination); // Not Yet written + res = gdcm_read_JPEG2000_file (fp,destination); // Not Yet written // ------------------------------------- endif (JPEG2000) } else if (jpgLossless) @@ -1098,12 +1057,12 @@ bool gdcmFile::ReadPixelData(void *destination) if ( Header->GetBitsStored() == 8) { // Reading Fragment pixels - res = (bool)gdcm_read_JPEG_file (fp,destination); + res = gdcm_read_JPEG_file (fp,destination); } else { // Reading Fragment pixels - res = (bool)gdcm_read_JPEG_file12 (fp,destination); + res = gdcm_read_JPEG_file12 (fp,destination); } // ------------------------------------- endif (JPEGLossy) }