1 /*=========================================================================
4 Module: $RCSfile: gdcmPixelReadConvert.cxx,v $
6 Date: $Date: 2005/05/30 00:24:10 $
7 Version: $Revision: 1.62 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmDebug.h"
21 #include "gdcmGlobal.h"
23 #include "gdcmPixelReadConvert.h"
24 #include "gdcmDocEntry.h"
25 #include "gdcmRLEFramesInfo.h"
26 #include "gdcmJPEGFragmentsInfo.h"
29 #include <stdio.h> //for sscanf
34 //bool ReadMPEGFile (std::ifstream *fp, void *image_buffer, size_t lenght);
35 bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* raw, size_t inputlength);
36 //-----------------------------------------------------------------------------
37 #define str2num(str, typeNum) *((typeNum *)(str))
39 //-----------------------------------------------------------------------------
40 // Constructor / Destructor
42 PixelReadConvert::PixelReadConvert()
54 /// Canonical Destructor
55 PixelReadConvert::~PixelReadConvert()
60 //-----------------------------------------------------------------------------
63 * \brief Predicate to know whether the image[s] (once Raw) is RGB.
64 * \note See comments of \ref ConvertHandleColor
66 bool PixelReadConvert::IsRawRGB()
69 || PlanarConfiguration == 2
77 * \brief Gets various usefull informations from the file header
78 * @param file gdcm::File pointer
80 void PixelReadConvert::GrabInformationsFromFile( File *file )
82 // Number of Bits Allocated for storing a Pixel is defaulted to 16
83 // when absent from the file.
84 BitsAllocated = file->GetBitsAllocated();
85 if ( BitsAllocated == 0 )
90 // Number of "Bits Stored", defaulted to number of "Bits Allocated"
91 // when absent from the file.
92 BitsStored = file->GetBitsStored();
93 if ( BitsStored == 0 )
95 BitsStored = BitsAllocated;
98 // High Bit Position, defaulted to "Bits Allocated" - 1
99 HighBitPosition = file->GetHighBitPosition();
100 if ( HighBitPosition == 0 )
102 HighBitPosition = BitsAllocated - 1;
105 XSize = file->GetXSize();
106 YSize = file->GetYSize();
107 ZSize = file->GetZSize();
108 SamplesPerPixel = file->GetSamplesPerPixel();
109 PixelSize = file->GetPixelSize();
110 PixelSign = file->IsSignedPixelData();
111 SwapCode = file->GetSwapCode();
112 std::string ts = file->GetTransferSyntax();
114 ( ! file->IsDicomV3() )
115 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndian
116 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndianDLXGE
117 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRLittleEndian
118 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian
119 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::DeflatedExplicitVRLittleEndian;
121 IsMPEG = Global::GetTS()->IsMPEG(ts);
122 IsJPEG2000 = Global::GetTS()->IsJPEG2000(ts);
123 IsJPEGLS = Global::GetTS()->IsJPEGLS(ts);
124 IsJPEGLossy = Global::GetTS()->IsJPEGLossy(ts);
125 IsJPEGLossless = Global::GetTS()->IsJPEGLossless(ts);
126 IsRLELossless = Global::GetTS()->IsRLELossless(ts);
128 PixelOffset = file->GetPixelOffset();
129 PixelDataLength = file->GetPixelAreaLength();
130 RLEInfo = file->GetRLEInfo();
131 JPEGInfo = file->GetJPEGInfo();
133 IsMonochrome = file->IsMonochrome();
134 IsMonochrome1 = file->IsMonochrome1();
135 IsPaletteColor = file->IsPaletteColor();
136 IsYBRFull = file->IsYBRFull();
138 PlanarConfiguration = file->GetPlanarConfiguration();
140 /////////////////////////////////////////////////////////////////
142 HasLUT = file->HasLUT();
145 // Just in case some access to a File element requires disk access.
146 LutRedDescriptor = file->GetEntryValue( 0x0028, 0x1101 );
147 LutGreenDescriptor = file->GetEntryValue( 0x0028, 0x1102 );
148 LutBlueDescriptor = file->GetEntryValue( 0x0028, 0x1103 );
150 // Depending on the value of Document::MAX_SIZE_LOAD_ELEMENT_VALUE
151 // [ refer to invocation of Document::SetMaxSizeLoadEntry() in
152 // Document::Document() ], the loading of the value (content) of a
153 // [Bin|Val]Entry occurence migth have been hindered (read simply NOT
154 // loaded). Hence, we first try to obtain the LUTs data from the file
155 // and when this fails we read the LUTs data directly from disk.
156 // \TODO Reading a [Bin|Val]Entry directly from disk is a kludge.
157 // We should NOT bypass the [Bin|Val]Entry class. Instead
158 // an access to an UNLOADED content of a [Bin|Val]Entry occurence
159 // (e.g. BinEntry::GetBinArea()) should force disk access from
160 // within the [Bin|Val]Entry class itself. The only problem
161 // is that the [Bin|Val]Entry is unaware of the FILE* is was
162 // parsed from. Fix that. FIXME.
165 file->LoadEntryBinArea(0x0028, 0x1201);
166 LutRedData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1201 );
169 gdcmWarningMacro( "Unable to read Red LUT data" );
173 file->LoadEntryBinArea(0x0028, 0x1202);
174 LutGreenData = (uint8_t*)file->GetEntryBinArea(0x0028, 0x1202 );
177 gdcmWarningMacro( "Unable to read Green LUT data" );
181 file->LoadEntryBinArea(0x0028, 0x1203);
182 LutBlueData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1203 );
185 gdcmWarningMacro( "Unable to read Blue LUT data" );
189 ComputeRawAndRGBSizes();
192 /// \brief Reads from disk and decompresses Pixels
193 bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp )
195 // ComputeRawAndRGBSizes is already made by
196 // ::GrabInformationsFromfile. So, the structure sizes are
200 //////////////////////////////////////////////////
201 //// First stage: get our hands on the Pixel Data.
204 gdcmWarningMacro( "Unavailable file pointer." );
208 fp->seekg( PixelOffset, std::ios::beg );
209 if( fp->fail() || fp->eof())
211 gdcmWarningMacro( "Unable to find PixelOffset in file." );
217 //////////////////////////////////////////////////
218 //// Second stage: read from disk dans decompress.
219 if ( BitsAllocated == 12 )
221 ReadAndDecompress12BitsTo16Bits( fp);
225 // This problem can be found when some obvious informations are found
226 // after the field containing the image data. In this case, these
227 // bad data are added to the size of the image (in the PixelDataLength
228 // variable). But RawSize is the right size of the image !
229 if( PixelDataLength != RawSize)
231 gdcmWarningMacro( "Mismatch between PixelReadConvert : "
232 << PixelDataLength << " and RawSize : " << RawSize );
234 if( PixelDataLength > RawSize)
236 fp->read( (char*)Raw, RawSize);
240 fp->read( (char*)Raw, PixelDataLength);
243 if ( fp->fail() || fp->eof())
245 gdcmWarningMacro( "Reading of Raw pixel data failed." );
249 else if ( IsRLELossless )
251 if ( ! RLEInfo->DecompressRLEFile( fp, Raw, XSize, YSize, ZSize, BitsAllocated ) )
253 gdcmWarningMacro( "RLE decompressor failed." );
259 //gdcmWarningMacro( "Sorry, MPEG not yet taken into account" );
261 // ReadMPEGFile(fp, Raw, PixelDataLength); // fp has already been seek to start of mpeg
266 // Default case concerns JPEG family
267 if ( ! ReadAndDecompressJPEGFile( fp ) )
269 gdcmWarningMacro( "JPEG decompressor failed." );
274 ////////////////////////////////////////////
275 //// Third stage: twigle the bytes and bits.
276 ConvertReorderEndianity();
277 ConvertReArrangeBits();
278 ConvertFixGreyLevels();
279 ConvertHandleColor();
284 /// Deletes Pixels Area
285 void PixelReadConvert::Squeeze()
301 * \brief Build the RGB image from the Raw imagage and the LUTs.
303 bool PixelReadConvert::BuildRGBImage()
307 // The job is already done.
313 // The job can't be done
320 // The job can't be done
326 uint8_t *localRGB = RGB;
327 for (size_t i = 0; i < RawSize; ++i )
330 *localRGB++ = LutRGBA[j];
331 *localRGB++ = LutRGBA[j+1];
332 *localRGB++ = LutRGBA[j+2];
337 //-----------------------------------------------------------------------------
340 //-----------------------------------------------------------------------------
343 * \brief Read from file a 12 bits per pixel image and decompress it
344 * into a 16 bits per pixel image.
346 void PixelReadConvert::ReadAndDecompress12BitsTo16Bits( std::ifstream *fp )
347 throw ( FormatError )
349 int nbPixels = XSize * YSize;
350 uint16_t *localDecompres = (uint16_t*)Raw;
352 for( int p = 0; p < nbPixels; p += 2 )
356 fp->read( (char*)&b0, 1);
357 if ( fp->fail() || fp->eof() )
359 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
360 "Unfound first block" );
363 fp->read( (char*)&b1, 1 );
364 if ( fp->fail() || fp->eof())
366 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
367 "Unfound second block" );
370 fp->read( (char*)&b2, 1 );
371 if ( fp->fail() || fp->eof())
373 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
374 "Unfound second block" );
377 // Two steps are necessary to please VC++
379 // 2 pixels 12bit = [0xABCDEF]
380 // 2 pixels 16bit = [0x0ABD] + [0x0FCE]
382 *localDecompres++ = ((b0 >> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f);
384 *localDecompres++ = ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4);
386 /// \todo JPR Troubles expected on Big-Endian processors ?
391 * \brief Reads from disk the Pixel Data of JPEG Dicom encapsulated
392 * file and decompress it.
393 * @param fp File Pointer
396 bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp )
400 // I don't think we'll ever be able to deal with multiple fragments
401 assert( JPEGInfo->GetFragmentCount() == 1 );
402 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
403 if ( ! gdcm_read_JPEG2000_file( fp,Raw,
404 JPEGInfo->GetFirstFragment()->GetLength() ) )
412 // WARNING : JPEG-LS is NOT the 'classical' Jpeg Lossless :
413 // [JPEG-LS is the basis for new lossless/near-lossless compression
414 // standard for continuous-tone images intended for JPEG2000. The standard
415 // is based on the LOCO-I algorithm (LOw COmplexity LOssless COmpression
416 // for Images) developed at Hewlett-Packard Laboratories]
418 // see http://datacompression.info/JPEGLS.shtml
421 gdcmWarningMacro( "Sorry, JPEG-LS not yet taken into account" );
422 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
423 // if ( ! gdcm_read_JPEGLS_file( fp,Raw ) )
428 // Precompute the offset localRaw will be shifted with
429 int length = XSize * YSize * SamplesPerPixel;
430 int numberBytes = BitsAllocated / 8;
432 JPEGInfo->DecompressFromFile(fp, Raw, BitsStored, numberBytes, length );
438 * \brief Build Red/Green/Blue/Alpha LUT from File
439 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
440 * and (0028,1101),(0028,1102),(0028,1102)
441 * - xxx Palette Color Lookup Table Descriptor - are found
442 * and (0028,1201),(0028,1202),(0028,1202)
443 * - xxx Palette Color Lookup Table Data - are found
444 * \warning does NOT deal with :
445 * 0028 1100 Gray Lookup Table Descriptor (Retired)
446 * 0028 1221 Segmented Red Palette Color Lookup Table Data
447 * 0028 1222 Segmented Green Palette Color Lookup Table Data
448 * 0028 1223 Segmented Blue Palette Color Lookup Table Data
449 * no known Dicom reader deals with them :-(
450 * @return a RGBA Lookup Table
452 void PixelReadConvert::BuildLUTRGBA()
459 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
461 if ( ! IsPaletteColor )
466 if ( LutRedDescriptor == GDCM_UNFOUND
467 || LutGreenDescriptor == GDCM_UNFOUND
468 || LutBlueDescriptor == GDCM_UNFOUND )
473 ////////////////////////////////////////////
474 // Extract the info from the LUT descriptors
475 int lengthR; // Red LUT length in Bytes
476 int debR; // Subscript of the first Lut Value
477 int nbitsR; // Lut item size (in Bits)
478 int nbRead = sscanf( LutRedDescriptor.c_str(),
480 &lengthR, &debR, &nbitsR );
483 gdcmWarningMacro( "Wrong Red LUT descriptor" );
486 int lengthG; // Green LUT length in Bytes
487 int debG; // Subscript of the first Lut Value
488 int nbitsG; // Lut item size (in Bits)
489 nbRead = sscanf( LutGreenDescriptor.c_str(),
491 &lengthG, &debG, &nbitsG );
494 gdcmWarningMacro( "Wrong Green LUT descriptor" );
497 int lengthB; // Blue LUT length in Bytes
498 int debB; // Subscript of the first Lut Value
499 int nbitsB; // Lut item size (in Bits)
500 nbRead = sscanf( LutRedDescriptor.c_str(),
502 &lengthB, &debB, &nbitsB );
505 gdcmWarningMacro( "Wrong Blue LUT descriptor" );
508 ////////////////////////////////////////////////////////
509 if ( ( ! LutRedData ) || ( ! LutGreenData ) || ( ! LutBlueData ) )
514 ////////////////////////////////////////////////
515 // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
516 LutRGBA = new uint8_t[ 1024 ]; // 256 * 4 (R, G, B, Alpha)
520 memset( LutRGBA, 0, 1024 );
523 if ( ( nbitsR == 16 ) && ( BitsAllocated == 8 ) )
525 // when LUT item size is different than pixel size
526 mult = 2; // high byte must be = low byte
530 // See PS 3.3-2003 C.11.1.1.2 p 619
534 // if we get a black image, let's just remove the '+1'
535 // from 'i*mult+1' and check again
536 // if it works, we shall have to check the 3 Palettes
537 // to see which byte is ==0 (first one, or second one)
539 // We give up the checking to avoid some (useless ?) overhead
540 // (optimistic asumption)
542 uint8_t *a = LutRGBA + 0;
543 for( i=0; i < lengthR; ++i )
545 *a = LutRedData[i*mult+1];
550 for( i=0; i < lengthG; ++i)
552 *a = LutGreenData[i*mult+1];
557 for(i=0; i < lengthB; ++i)
559 *a = LutBlueData[i*mult+1];
564 for(i=0; i < 256; ++i)
566 *a = 1; // Alpha component
572 * \brief Swap the bytes, according to \ref SwapCode.
574 void PixelReadConvert::ConvertSwapZone()
578 if( BitsAllocated == 16 )
580 uint16_t *im16 = (uint16_t*)Raw;
588 for( i = 0; i < RawSize / 2; i++ )
590 im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
594 gdcmWarningMacro("SwapCode value (16 bits) not allowed.");
597 else if( BitsAllocated == 32 )
602 uint32_t *im32 = (uint32_t*)Raw;
608 for( i = 0; i < RawSize / 4; i++ )
610 low = im32[i] & 0x0000ffff; // 4321
611 high = im32[i] >> 16;
612 high = ( high >> 8 ) | ( high << 8 );
613 low = ( low >> 8 ) | ( low << 8 );
615 im32[i] = ( s32 << 16 ) | high;
619 for( i = 0; i < RawSize / 4; i++ )
621 low = im32[i] & 0x0000ffff; // 2143
622 high = im32[i] >> 16;
623 high = ( high >> 8 ) | ( high << 8 );
624 low = ( low >> 8 ) | ( low << 8 );
626 im32[i] = ( s32 << 16 ) | low;
630 for( i = 0; i < RawSize / 4; i++ )
632 low = im32[i] & 0x0000ffff; // 3412
633 high = im32[i] >> 16;
635 im32[i] = ( s32 << 16 ) | high;
639 gdcmWarningMacro("SwapCode value (32 bits) not allowed." );
645 * \brief Deal with endianness i.e. re-arange bytes inside the integer
647 void PixelReadConvert::ConvertReorderEndianity()
649 if ( BitsAllocated != 8 )
654 // Special kludge in order to deal with xmedcon broken images:
655 if ( BitsAllocated == 16
656 && BitsStored < BitsAllocated
659 int l = (int)( RawSize / ( BitsAllocated / 8 ) );
660 uint16_t *deb = (uint16_t *)Raw;
661 for(int i = 0; i<l; i++)
673 * \brief Deal with Grey levels i.e. re-arange them
674 * to have low values = dark, high values = bright
676 void PixelReadConvert::ConvertFixGreyLevels()
681 uint32_t i; // to please M$VC6
686 if ( BitsAllocated == 8 )
688 uint8_t *deb = (uint8_t *)Raw;
689 for (i=0; i<RawSize; i++)
697 if ( BitsAllocated == 16 )
700 for (j=0; j<BitsStored-1; j++)
702 mask = (mask << 1) +1; // will be fff when BitsStored=12
705 uint16_t *deb = (uint16_t *)Raw;
706 for (i=0; i<RawSize/2; i++)
716 if ( BitsAllocated == 8 )
718 uint8_t smask8 = 255;
719 uint8_t *deb = (uint8_t *)Raw;
720 for (i=0; i<RawSize; i++)
722 *deb = smask8 - *deb;
727 if ( BitsAllocated == 16 )
729 uint16_t smask16 = 65535;
730 uint16_t *deb = (uint16_t *)Raw;
731 for (i=0; i<RawSize/2; i++)
733 *deb = smask16 - *deb;
742 * \brief Re-arrange the bits within the bytes.
743 * @return Boolean always true
745 bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError )
747 if ( BitsStored != BitsAllocated )
749 int l = (int)( RawSize / ( BitsAllocated / 8 ) );
750 if ( BitsAllocated == 16 )
752 uint16_t mask = 0xffff;
753 mask = mask >> ( BitsAllocated - BitsStored );
754 uint16_t *deb = (uint16_t*)Raw;
755 for(int i = 0; i<l; i++)
757 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
761 else if ( BitsAllocated == 32 )
763 uint32_t mask = 0xffffffff;
764 mask = mask >> ( BitsAllocated - BitsStored );
765 uint32_t *deb = (uint32_t*)Raw;
766 for(int i = 0; i<l; i++)
768 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
774 gdcmWarningMacro("Weird image");
775 throw FormatError( "Weird image !?" );
782 * \brief Convert (Red plane, Green plane, Blue plane) to RGB pixels
783 * \warning Works on all the frames at a time
785 void PixelReadConvert::ConvertRGBPlanesToRGBPixels()
787 uint8_t *localRaw = Raw;
788 uint8_t *copyRaw = new uint8_t[ RawSize ];
789 memmove( copyRaw, localRaw, RawSize );
791 int l = XSize * YSize * ZSize;
793 uint8_t *a = copyRaw;
794 uint8_t *b = copyRaw + l;
795 uint8_t *c = copyRaw + l + l;
797 for (int j = 0; j < l; j++)
799 *(localRaw++) = *(a++);
800 *(localRaw++) = *(b++);
801 *(localRaw++) = *(c++);
807 * \brief Convert (cY plane, cB plane, cR plane) to RGB pixels
808 * \warning Works on all the frames at a time
810 void PixelReadConvert::ConvertYcBcRPlanesToRGBPixels()
812 uint8_t *localRaw = Raw;
813 uint8_t *copyRaw = new uint8_t[ RawSize ];
814 memmove( copyRaw, localRaw, RawSize );
816 // to see the tricks about YBR_FULL, YBR_FULL_422,
817 // YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at :
818 // ftp://medical.nema.org/medical/dicom/final/sup61_ft.pdf
819 // and be *very* affraid
821 int l = XSize * YSize;
822 int nbFrames = ZSize;
824 uint8_t *a = copyRaw + 0;
825 uint8_t *b = copyRaw + l;
826 uint8_t *c = copyRaw + l+ l;
829 /// \todo : Replace by the 'well known' integer computation
830 /// counterpart. Refer to
831 /// http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
832 /// for code optimisation.
834 for ( int i = 0; i < nbFrames; i++ )
836 for ( int j = 0; j < l; j++ )
838 R = 38142 *(*a-16) + 52298 *(*c -128);
839 G = 38142 *(*a-16) - 26640 *(*c -128) - 12845 *(*b -128);
840 B = 38142 *(*a-16) + 66093 *(*b -128);
849 if (R > 255) R = 255;
850 if (G > 255) G = 255;
851 if (B > 255) B = 255;
853 *(localRaw++) = (uint8_t)R;
854 *(localRaw++) = (uint8_t)G;
855 *(localRaw++) = (uint8_t)B;
864 /// \brief Deals with the color decoding i.e. handle:
865 /// - R, G, B planes (as opposed to RGB pixels)
866 /// - YBR (various) encodings.
867 /// - LUT[s] (or "PALETTE COLOR").
869 void PixelReadConvert::ConvertHandleColor()
871 //////////////////////////////////
872 // Deal with the color decoding i.e. handle:
873 // - R, G, B planes (as opposed to RGB pixels)
874 // - YBR (various) encodings.
875 // - LUT[s] (or "PALETTE COLOR").
877 // The classification in the color decoding schema is based on the blending
878 // of two Dicom tags values:
879 // * "Photometric Interpretation" for which we have the cases:
880 // - [Photo A] MONOCHROME[1|2] pictures,
881 // - [Photo B] RGB or YBR_FULL_422 (which acts as RGB),
882 // - [Photo C] YBR_* (with the above exception of YBR_FULL_422)
883 // - [Photo D] "PALETTE COLOR" which indicates the presence of LUT[s].
884 // * "Planar Configuration" for which we have the cases:
885 // - [Planar 0] 0 then Pixels are already RGB
886 // - [Planar 1] 1 then we have 3 planes : R, G, B,
887 // - [Planar 2] 2 then we have 1 gray Plane and 3 LUTs
889 // Now in theory, one could expect some coherence when blending the above
890 // cases. For example we should not encounter files belonging at the
891 // time to case [Planar 0] and case [Photo D].
892 // Alas, this was only theory ! Because in practice some odd (read ill
893 // formated Dicom) files (e.g. gdcmData/US-PAL-8-10x-echo.dcm) we encounter:
894 // - "Planar Configuration" = 0,
895 // - "Photometric Interpretation" = "PALETTE COLOR".
896 // Hence gdcm will use the folowing "heuristic" in order to be tolerant
897 // towards Dicom-non-conformance files:
898 // << whatever the "Planar Configuration" value might be, a
899 // "Photometric Interpretation" set to "PALETTE COLOR" forces
900 // a LUT intervention >>
902 // Now we are left with the following handling of the cases:
903 // - [Planar 0] OR [Photo A] no color decoding (since respectively
904 // Pixels are already RGB and monochrome pictures have no color :),
905 // - [Planar 1] AND [Photo B] handled with ConvertRGBPlanesToRGBPixels()
906 // - [Planar 1] AND [Photo C] handled with ConvertYcBcRPlanesToRGBPixels()
907 // - [Planar 2] OR [Photo D] requires LUT intervention.
911 // [Planar 2] OR [Photo D]: LUT intervention done outside
915 if ( PlanarConfiguration == 1 )
919 // [Planar 1] AND [Photo C] (remember YBR_FULL_422 acts as RGB)
920 ConvertYcBcRPlanesToRGBPixels();
924 // [Planar 1] AND [Photo C]
925 ConvertRGBPlanesToRGBPixels();
930 // When planarConf is 0, and RLELossless (forbidden by Dicom norm)
931 // pixels need to be RGB-fied anyway
934 ConvertRGBPlanesToRGBPixels();
936 // In *normal *case, when planarConf is 0, pixels are already in RGB
939 /// Computes the Pixels Size
940 void PixelReadConvert::ComputeRawAndRGBSizes()
942 int bitsAllocated = BitsAllocated;
943 // Number of "Bits Allocated" is fixed to 16 when it's 12, since
944 // in this case we will expand the image to 16 bits (see
945 // \ref ReadAndDecompress12BitsTo16Bits() )
946 if ( BitsAllocated == 12 )
951 RawSize = XSize * YSize * ZSize
952 * ( bitsAllocated / 8 )
956 RGBSize = 3 * RawSize;
964 /// Allocates room for RGB Pixels
965 void PixelReadConvert::AllocateRGB()
969 RGB = new uint8_t[RGBSize];
972 /// Allocates room for RAW Pixels
973 void PixelReadConvert::AllocateRaw()
977 Raw = new uint8_t[RawSize];
980 //-----------------------------------------------------------------------------
984 * @param indent Indentation string to be prepended during printing.
985 * @param os Stream to print to.
987 void PixelReadConvert::Print( std::ostream &os, std::string const &indent )
990 << "--- Pixel information -------------------------"
993 << "Pixel Data: offset " << PixelOffset
994 << " x(" << std::hex << PixelOffset << std::dec
995 << ") length " << PixelDataLength
996 << " x(" << std::hex << PixelDataLength << std::dec
1003 RLEInfo->Print( os, indent );
1007 gdcmWarningMacro("Set as RLE file but NO RLEinfo present.");
1011 if ( IsJPEG2000 || IsJPEGLossless || IsJPEGLossy || IsJPEGLS )
1015 JPEGInfo->Print( os, indent );
1019 gdcmWarningMacro("Set as JPEG file but NO JPEGinfo present.");
1024 //-----------------------------------------------------------------------------
1025 } // end namespace gdcm
1027 // NOTES on File internal calls
1029 // ---> GetImageData
1030 // ---> GetImageDataIntoVector
1031 // |---> GetImageDataIntoVectorRaw
1032 // | lut intervention
1034 // ---> GetImageDataRaw
1035 // ---> GetImageDataIntoVectorRaw