From 09df242a0fd3c71c18ca62fc0a8d87713f53e217 Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 14 Jan 2005 15:06:36 +0000 Subject: [PATCH] * ENH - Comment out Mathieu's (dangerous) Super Hack for dealing with BIGENDIAN processors - Move equivalent stuff to BinEntry::WriteContent When necessary, 16 Bits Pixels are swapped in a small buffer and then written. This avoid allocating a huge buffer, in PixelWriteConveror, and avoid modifying the Pixel Area. Note : Probabely, the same operation will have to be done when we want to write image with Big Endian Transfert Syntax, and we are working onj Little Endian Processor --- ChangeLog | 12 ++++++++ src/gdcmBinEntry.cxx | 59 +++++++++++++++++++++++++++++++++--- src/gdcmHeader.cxx | 16 ++++++---- src/gdcmPixelReadConvert.cxx | 26 ++++++++-------- 4 files changed, 89 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2d27c58a..48e58c3d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-01-13 Jean-Pierre Roux + * ENH - Comment out Mathieu's (dangerous) Super Hack + for dealing with BIGENDIAN processors + - Move equivalent stuff to BinEntry::WriteContent + When necessary, 16 Bits Pixels are swapped in a small buffer + and then written. This avoid allocating a huge buffer, in + PixelWriteConveror, and avoid modifying the Pixel Area. + Note : + Probabely, the same operation will have to be done when we want + to write image with Big Endian Transfert Syntax, + and we are working onj Little Endian Processor + 2005-01-14 Benoit Regrain * src/gdcmDocument.[h|cxx] : comment all methods concerning a flat hash table. diff --git a/src/gdcmBinEntry.cxx b/src/gdcmBinEntry.cxx index e54c1a76..dd5c7971 100644 --- a/src/gdcmBinEntry.cxx +++ b/src/gdcmBinEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmBinEntry.cxx,v $ Language: C++ - Date: $Date: 2005/01/11 20:49:44 $ - Version: $Revision: 1.46 $ + Date: $Date: 2005/01/14 15:06:37 $ + Version: $Revision: 1.47 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -110,14 +110,63 @@ void BinEntry::Print(std::ostream &os) * @param filetype type of the file to be written */ void BinEntry::WriteContent(std::ofstream *fp, FileType filetype) -{ +{ +#define BUFFER_SIZE 4096 DocEntry::WriteContent(fp, filetype); void* binArea = GetBinArea(); int lgr = GetLength(); - if (binArea) + if (binArea) // the binArea was *actually* loaded { - // there is a 'non string' LUT, overlay, etc + + // TODO FIME + // Probabely, the same operation will have to be done when we want + // to write image with Big Endian Transfert Syntax, + // and we are working onj Little Endian Processor + +#ifdef GDCM_WORDS_BIGENDIAN + // Be carefull with *any* 16 bits words 'binEntries !' + // if ( GetVR() == "OW") // to be used later + + // TODO FIXME Right now, we only care of Pixels element + + // 8 Bits Pixels *are* OB, 16 Bits Pixels *are* OW + // -value forced while Reading process- + if (GetGroup == 0x7fe0 && GetVR() == "OW") + { + unit16_t *currPosition = (uint16_t *)binArea; + + // TODO FIXME : Maybe we should allocate somewhere a static buffer, + // in order not to have to alloc/delete for almost every BinEntry ... + unit16_t *buffer = new uint16[BUFFER_SIZE]; + + // how many BUFFER_SIZE long pieces in binArea ? + int nbPieces = lgr/BUFFER_SIZE/2; //(16 bits = 2 Bytes) + for (int j=0;j> 8 + | (uint16_t *)binArea[i] << 8; + } + fp->write ( (char*)currPosition, BUFFER_SIZE ); + currPosition += BUFFER_SIZE/2; + } + int remainingSize = lgr%BUFFER_SIZE; + if ( remainingSize != 0) + { + fp->write ( (char*)currPosition, remainingSize ); + } + delete buffer; + } + else + { + // For any other VR, BinEntry is re-written as-is + fp->write ( (char*)binArea, lgr ); + } +#else fp->write ( (char*)binArea, lgr ); // Elem value +#endif //GDCM_WORDS_BIGENDIAN + } else { diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index b5b3b07a..cab302f3 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeader.cxx,v $ Language: C++ - Date: $Date: 2005/01/11 23:06:35 $ - Version: $Revision: 1.231 $ + Date: $Date: 2005/01/14 15:06:37 $ + Version: $Revision: 1.232 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -196,11 +196,12 @@ bool Header::Write(std::string fileName, FileType filetype) } } +/* #ifdef GDCM_WORDS_BIGENDIAN - // Super Duper hack that will make gdcm a BOMB ! but should + // Super Super hack that will make gdcm a BOMB ! but should // Fix temporarily the dashboard - BinEntry *b = GetBinEntry(0x7fe0,0x0010); - if ( GetEntry(0x0028,0x0100) == "16") + BinEntry *b = GetBinEntry(GrPixel,NumPixel); + if ( GetPixelSize() == 16 ) { uint16_t *im16 = (uint16_t*)b->GetBinArea(); int lgr = b->GetLength(); @@ -210,12 +211,14 @@ bool Header::Write(std::string fileName, FileType filetype) } } #endif //GDCM_WORDS_BIGENDIAN +*/ Document::WriteContent(fp,filetype); +/* #ifdef GDCM_WORDS_BIGENDIAN // Flip back the pixel ... I told you this is a hack - if ( GetEntry(0x0028,0x0100) == "16") + if ( GetPixelSize() == 16 ) { uint16_t *im16 = (uint16_t*)b->GetBinArea(); int lgr = b->GetLength(); @@ -225,6 +228,7 @@ bool Header::Write(std::string fileName, FileType filetype) } } #endif //GDCM_WORDS_BIGENDIAN +*/ fp->close(); delete fp; diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index 53c636b4..3cddb493 100644 --- a/src/gdcmPixelReadConvert.cxx +++ b/src/gdcmPixelReadConvert.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelReadConvert.cxx,v $ Language: C++ - Date: $Date: 2005/01/13 09:24:08 $ - Version: $Revision: 1.26 $ + Date: $Date: 2005/01/14 15:06:37 $ + Version: $Revision: 1.27 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -411,7 +411,7 @@ void PixelReadConvert::ConvertReorderEndianity() /** * \brief Reads from disk the Pixel Data of JPEG Dicom encapsulated - * file and decompress it. This funciton assumes that each + * file and decompress it. This function assumes that each * jpeg fragment contains a whole frame (jpeg file). * @param fp File Pointer * @return Boolean @@ -543,7 +543,7 @@ ReadAndDecompressJPEGSingleFrameFragmentsFromFile( std::ifstream *fp ) else { // other JPEG lossy not supported - gdcmErrorMacro( "Unknown jpeg lossy compression "); + gdcmErrorMacro( "Unsupported jpeg lossy compression "); delete [] buffer; return false; } @@ -641,7 +641,7 @@ ReadAndDecompressJPEGFragmentedFramesFromFile( std::ifstream *fp ) else { // other JPEG lossy not supported - gdcmErrorMacro( "Unknown jpeg lossy compression "); + gdcmErrorMacro( "Unsupported jpeg lossy compression "); delete [] buffer; return false; } @@ -1070,7 +1070,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) // [Bin|Val]Entry occurence migth have been hindered (read simply NOT // loaded). Hence, we first try to obtain the LUTs data from the header // and when this fails we read the LUTs data directely from disk. - /// \todo Reading a [Bin|Val]Entry directly from disk is a kludge. + /// \TODO Reading a [Bin|Val]Entry directly from disk is a kludge. /// We should NOT bypass the [Bin|Val]Entry class. Instead /// an access to an UNLOADED content of a [Bin|Val]Entry occurence /// (e.g. BinEntry::GetBinArea()) should force disk access from @@ -1083,7 +1083,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) LutRedData = (uint8_t*)header->GetEntryBinArea( 0x0028, 0x1201 ); if ( ! LutRedData ) { - gdcmVerboseMacro( "Unable to read red LUT data" ); + gdcmVerboseMacro( "Unable to read Red LUT data" ); } ////// Green round: @@ -1091,7 +1091,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) LutGreenData = (uint8_t*)header->GetEntryBinArea(0x0028, 0x1202 ); if ( ! LutGreenData) { - gdcmVerboseMacro( "Unable to read green LUT data" ); + gdcmVerboseMacro( "Unable to read Green LUT data" ); } ////// Blue round: @@ -1099,7 +1099,7 @@ void PixelReadConvert::GrabInformationsFromHeader( Header *header ) LutBlueData = (uint8_t*)header->GetEntryBinArea( 0x0028, 0x1203 ); if ( ! LutBlueData ) { - gdcmVerboseMacro( "Unable to read blue LUT data" ); + gdcmVerboseMacro( "Unable to read Blue LUT data" ); } } @@ -1152,7 +1152,7 @@ void PixelReadConvert::BuildLUTRGBA() &lengthR, &debR, &nbitsR ); if( nbRead != 3 ) { - gdcmVerboseMacro( "Wrong red LUT descriptor" ); + gdcmVerboseMacro( "Wrong Red LUT descriptor" ); } int lengthG; // Green LUT length in Bytes @@ -1163,7 +1163,7 @@ void PixelReadConvert::BuildLUTRGBA() &lengthG, &debG, &nbitsG ); if( nbRead != 3 ) { - gdcmVerboseMacro( "Wrong green LUT descriptor" ); + gdcmVerboseMacro( "Wrong Green LUT descriptor" ); } int lengthB; // Blue LUT length in Bytes @@ -1174,7 +1174,7 @@ void PixelReadConvert::BuildLUTRGBA() &lengthB, &debB, &nbitsB ); if( nbRead != 3 ) { - gdcmVerboseMacro( "Wrong blue LUT descriptor" ); + gdcmVerboseMacro( "Wrong Blue LUT descriptor" ); } //////////////////////////////////////////////////////// @@ -1209,7 +1209,7 @@ void PixelReadConvert::BuildLUTRGBA() // 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 (useless ?)overhead + // We give up the checking to avoid some (useless ?) overhead // (optimistic asumption) int i; uint8_t* a = LutRGBA + 0; -- 2.45.1