1 /*=========================================================================
4 Module: $RCSfile: gdcmPixelReadConvert.cxx,v $
6 Date: $Date: 2005/02/17 10:53:21 $
7 Version: $Revision: 1.52 $
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
33 //-----------------------------------------------------------------------------
34 #define str2num(str, typeNum) *((typeNum *)(str))
36 //-----------------------------------------------------------------------------
37 // Constructor / Destructor
39 PixelReadConvert::PixelReadConvert()
51 /// Canonical Destructor
52 PixelReadConvert::~PixelReadConvert()
57 //-----------------------------------------------------------------------------
60 * \brief Predicate to know whether the image[s] (once Raw) is RGB.
61 * \note See comments of \ref ConvertHandleColor
63 bool PixelReadConvert::IsRawRGB()
66 || PlanarConfiguration == 2
74 * \brief Gets various usefull informations from the file header
75 * @param file gdcm::File pointer
77 void PixelReadConvert::GrabInformationsFromFile( File *file )
79 // Number of Bits Allocated for storing a Pixel is defaulted to 16
80 // when absent from the file.
81 BitsAllocated = file->GetBitsAllocated();
82 if ( BitsAllocated == 0 )
87 // Number of "Bits Stored", defaulted to number of "Bits Allocated"
88 // when absent from the file.
89 BitsStored = file->GetBitsStored();
90 if ( BitsStored == 0 )
92 BitsStored = BitsAllocated;
95 // High Bit Position, defaulted to "Bits Allocated" - 1
96 HighBitPosition = file->GetHighBitPosition();
97 if ( HighBitPosition == 0 )
99 HighBitPosition = BitsAllocated - 1;
102 XSize = file->GetXSize();
103 YSize = file->GetYSize();
104 ZSize = file->GetZSize();
105 SamplesPerPixel = file->GetSamplesPerPixel();
106 PixelSize = file->GetPixelSize();
107 PixelSign = file->IsSignedPixelData();
108 SwapCode = file->GetSwapCode();
109 std::string ts = file->GetTransferSyntax();
111 ( ! file->IsDicomV3() )
112 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndian
113 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndianDLXGE
114 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRLittleEndian
115 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian
116 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::DeflatedExplicitVRLittleEndian;
118 IsJPEG2000 = Global::GetTS()->IsJPEG2000(ts);
119 IsJPEGLS = Global::GetTS()->IsJPEGLS(ts);
120 IsJPEGLossy = Global::GetTS()->IsJPEGLossy(ts);
121 IsJPEGLossless = Global::GetTS()->IsJPEGLossless(ts);
122 IsRLELossless = Global::GetTS()->IsRLELossless(ts);
124 PixelOffset = file->GetPixelOffset();
125 PixelDataLength = file->GetPixelAreaLength();
126 RLEInfo = file->GetRLEInfo();
127 JPEGInfo = file->GetJPEGInfo();
129 IsMonochrome = file->IsMonochrome();
130 IsMonochrome1 = file->IsMonochrome1();
131 IsPaletteColor = file->IsPaletteColor();
132 IsYBRFull = file->IsYBRFull();
134 PlanarConfiguration = file->GetPlanarConfiguration();
136 /////////////////////////////////////////////////////////////////
138 HasLUT = file->HasLUT();
141 // Just in case some access to a File element requires disk access.
142 LutRedDescriptor = file->GetEntryValue( 0x0028, 0x1101 );
143 LutGreenDescriptor = file->GetEntryValue( 0x0028, 0x1102 );
144 LutBlueDescriptor = file->GetEntryValue( 0x0028, 0x1103 );
146 // Depending on the value of Document::MAX_SIZE_LOAD_ELEMENT_VALUE
147 // [ refer to invocation of Document::SetMaxSizeLoadEntry() in
148 // Document::Document() ], the loading of the value (content) of a
149 // [Bin|Val]Entry occurence migth have been hindered (read simply NOT
150 // loaded). Hence, we first try to obtain the LUTs data from the file
151 // and when this fails we read the LUTs data directly from disk.
152 // \TODO Reading a [Bin|Val]Entry directly from disk is a kludge.
153 // We should NOT bypass the [Bin|Val]Entry class. Instead
154 // an access to an UNLOADED content of a [Bin|Val]Entry occurence
155 // (e.g. BinEntry::GetBinArea()) should force disk access from
156 // within the [Bin|Val]Entry class itself. The only problem
157 // is that the [Bin|Val]Entry is unaware of the FILE* is was
158 // parsed from. Fix that. FIXME.
161 file->LoadEntryBinArea(0x0028, 0x1201);
162 LutRedData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1201 );
165 gdcmWarningMacro( "Unable to read Red LUT data" );
169 file->LoadEntryBinArea(0x0028, 0x1202);
170 LutGreenData = (uint8_t*)file->GetEntryBinArea(0x0028, 0x1202 );
173 gdcmWarningMacro( "Unable to read Green LUT data" );
177 file->LoadEntryBinArea(0x0028, 0x1203);
178 LutBlueData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1203 );
181 gdcmWarningMacro( "Unable to read Blue LUT data" );
185 ComputeRawAndRGBSizes();
188 /// \brief Reads from disk and decompresses Pixels
189 bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp )
191 // ComputeRawAndRGBSizes is already made by
192 // ::GrabInformationsFromfile. So, the structure sizes are
196 //////////////////////////////////////////////////
197 //// First stage: get our hands on the Pixel Data.
200 gdcmWarningMacro( "Unavailable file pointer." );
204 fp->seekg( PixelOffset, std::ios::beg );
205 if( fp->fail() || fp->eof())
207 gdcmWarningMacro( "Unable to find PixelOffset in file." );
213 //////////////////////////////////////////////////
214 //// Second stage: read from disk dans decompress.
215 if ( BitsAllocated == 12 )
217 ReadAndDecompress12BitsTo16Bits( fp);
221 // This problem can be found when some obvious informations are found
222 // after the field containing the image data. In this case, these
223 // bad data are added to the size of the image (in the PixelDataLength
224 // variable). But RawSize is the right size of the image !
225 if( PixelDataLength != RawSize)
227 gdcmWarningMacro( "Mismatch between PixelReadConvert : "
228 << PixelDataLength << " and RawSize : " << RawSize );
230 if( PixelDataLength > RawSize)
232 fp->read( (char*)Raw, RawSize);
236 fp->read( (char*)Raw, PixelDataLength);
239 if ( fp->fail() || fp->eof())
241 gdcmWarningMacro( "Reading of Raw pixel data failed." );
245 else if ( IsRLELossless )
247 if ( ! RLEInfo->DecompressRLEFile( fp, Raw, XSize, YSize, ZSize, BitsAllocated ) )
249 gdcmWarningMacro( "RLE decompressor failed." );
255 // Default case concerns JPEG family
256 if ( ! ReadAndDecompressJPEGFile( fp ) )
258 gdcmWarningMacro( "JPEG decompressor failed." );
263 ////////////////////////////////////////////
264 //// Third stage: twigle the bytes and bits.
265 ConvertReorderEndianity();
266 ConvertReArrangeBits();
267 ConvertFixGreyLevels();
268 ConvertHandleColor();
273 /// Deletes Pixels Area
274 void PixelReadConvert::Squeeze()
290 * \brief Build the RGB image from the Raw imagage and the LUTs.
292 bool PixelReadConvert::BuildRGBImage()
296 // The job is already done.
302 // The job can't be done
309 // The job can't be done
315 uint8_t *localRGB = RGB;
316 for (size_t i = 0; i < RawSize; ++i )
319 *localRGB++ = LutRGBA[j];
320 *localRGB++ = LutRGBA[j+1];
321 *localRGB++ = LutRGBA[j+2];
326 //-----------------------------------------------------------------------------
329 //-----------------------------------------------------------------------------
332 * \brief Read from file a 12 bits per pixel image and decompress it
333 * into a 16 bits per pixel image.
335 void PixelReadConvert::ReadAndDecompress12BitsTo16Bits( std::ifstream *fp )
336 throw ( FormatError )
338 int nbPixels = XSize * YSize;
339 uint16_t *localDecompres = (uint16_t*)Raw;
341 for( int p = 0; p < nbPixels; p += 2 )
345 fp->read( (char*)&b0, 1);
346 if ( fp->fail() || fp->eof() )
348 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
349 "Unfound first block" );
352 fp->read( (char*)&b1, 1 );
353 if ( fp->fail() || fp->eof())
355 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
356 "Unfound second block" );
359 fp->read( (char*)&b2, 1 );
360 if ( fp->fail() || fp->eof())
362 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
363 "Unfound second block" );
366 // Two steps are necessary to please VC++
368 // 2 pixels 12bit = [0xABCDEF]
369 // 2 pixels 16bit = [0x0ABD] + [0x0FCE]
371 *localDecompres++ = ((b0 >> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f);
373 *localDecompres++ = ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4);
375 /// \todo JPR Troubles expected on Big-Endian processors ?
380 * \brief Reads from disk the Pixel Data of JPEG Dicom encapsulated
381 * file and decompress it.
382 * @param fp File Pointer
385 bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp )
389 gdcmWarningMacro( "Sorry, JPEG2000 not yet taken into account" );
390 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
391 // if ( ! gdcm_read_JPEG2000_file( fp,Raw ) )
397 gdcmWarningMacro( "Sorry, JPEG-LS not yet taken into account" );
398 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
399 // if ( ! gdcm_read_JPEGLS_file( fp,Raw ) )
404 // Precompute the offset localRaw will be shifted with
405 int length = XSize * YSize * SamplesPerPixel;
406 int numberBytes = BitsAllocated / 8;
408 JPEGInfo->DecompressFromFile(fp, Raw, BitsStored, numberBytes, length );
413 * \brief Build Red/Green/Blue/Alpha LUT from File
414 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
415 * and (0028,1101),(0028,1102),(0028,1102)
416 * - xxx Palette Color Lookup Table Descriptor - are found
417 * and (0028,1201),(0028,1202),(0028,1202)
418 * - xxx Palette Color Lookup Table Data - are found
419 * \warning does NOT deal with :
420 * 0028 1100 Gray Lookup Table Descriptor (Retired)
421 * 0028 1221 Segmented Red Palette Color Lookup Table Data
422 * 0028 1222 Segmented Green Palette Color Lookup Table Data
423 * 0028 1223 Segmented Blue Palette Color Lookup Table Data
424 * no known Dicom reader deals with them :-(
425 * @return a RGBA Lookup Table
427 void PixelReadConvert::BuildLUTRGBA()
434 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
436 if ( ! IsPaletteColor )
441 if ( LutRedDescriptor == GDCM_UNFOUND
442 || LutGreenDescriptor == GDCM_UNFOUND
443 || LutBlueDescriptor == GDCM_UNFOUND )
448 ////////////////////////////////////////////
449 // Extract the info from the LUT descriptors
450 int lengthR; // Red LUT length in Bytes
451 int debR; // Subscript of the first Lut Value
452 int nbitsR; // Lut item size (in Bits)
453 int nbRead = sscanf( LutRedDescriptor.c_str(),
455 &lengthR, &debR, &nbitsR );
458 gdcmWarningMacro( "Wrong Red LUT descriptor" );
461 int lengthG; // Green LUT length in Bytes
462 int debG; // Subscript of the first Lut Value
463 int nbitsG; // Lut item size (in Bits)
464 nbRead = sscanf( LutGreenDescriptor.c_str(),
466 &lengthG, &debG, &nbitsG );
469 gdcmWarningMacro( "Wrong Green LUT descriptor" );
472 int lengthB; // Blue LUT length in Bytes
473 int debB; // Subscript of the first Lut Value
474 int nbitsB; // Lut item size (in Bits)
475 nbRead = sscanf( LutRedDescriptor.c_str(),
477 &lengthB, &debB, &nbitsB );
480 gdcmWarningMacro( "Wrong Blue LUT descriptor" );
483 ////////////////////////////////////////////////////////
484 if ( ( ! LutRedData ) || ( ! LutGreenData ) || ( ! LutBlueData ) )
489 ////////////////////////////////////////////////
490 // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
491 LutRGBA = new uint8_t[ 1024 ]; // 256 * 4 (R, G, B, Alpha)
495 memset( LutRGBA, 0, 1024 );
498 if ( ( nbitsR == 16 ) && ( BitsAllocated == 8 ) )
500 // when LUT item size is different than pixel size
501 mult = 2; // high byte must be = low byte
505 // See PS 3.3-2003 C.11.1.1.2 p 619
509 // if we get a black image, let's just remove the '+1'
510 // from 'i*mult+1' and check again
511 // if it works, we shall have to check the 3 Palettes
512 // to see which byte is ==0 (first one, or second one)
514 // We give up the checking to avoid some (useless ?) overhead
515 // (optimistic asumption)
517 uint8_t *a = LutRGBA + 0;
518 for( i=0; i < lengthR; ++i )
520 *a = LutRedData[i*mult+1];
525 for( i=0; i < lengthG; ++i)
527 *a = LutGreenData[i*mult+1];
532 for(i=0; i < lengthB; ++i)
534 *a = LutBlueData[i*mult+1];
539 for(i=0; i < 256; ++i)
541 *a = 1; // Alpha component
547 * \brief Swap the bytes, according to \ref SwapCode.
549 void PixelReadConvert::ConvertSwapZone()
553 if( BitsAllocated == 16 )
555 uint16_t *im16 = (uint16_t*)Raw;
563 for( i = 0; i < RawSize / 2; i++ )
565 im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
569 gdcmWarningMacro("SwapCode value (16 bits) not allowed.");
572 else if( BitsAllocated == 32 )
577 uint32_t *im32 = (uint32_t*)Raw;
583 for( i = 0; i < RawSize / 4; i++ )
585 low = im32[i] & 0x0000ffff; // 4321
586 high = im32[i] >> 16;
587 high = ( high >> 8 ) | ( high << 8 );
588 low = ( low >> 8 ) | ( low << 8 );
590 im32[i] = ( s32 << 16 ) | high;
594 for( i = 0; i < RawSize / 4; i++ )
596 low = im32[i] & 0x0000ffff; // 2143
597 high = im32[i] >> 16;
598 high = ( high >> 8 ) | ( high << 8 );
599 low = ( low >> 8 ) | ( low << 8 );
601 im32[i] = ( s32 << 16 ) | low;
605 for( i = 0; i < RawSize / 4; i++ )
607 low = im32[i] & 0x0000ffff; // 3412
608 high = im32[i] >> 16;
610 im32[i] = ( s32 << 16 ) | high;
614 gdcmWarningMacro("SwapCode value (32 bits) not allowed." );
620 * \brief Deal with endianness i.e. re-arange bytes inside the integer
622 void PixelReadConvert::ConvertReorderEndianity()
624 if ( BitsAllocated != 8 )
629 // Special kludge in order to deal with xmedcon broken images:
630 if ( BitsAllocated == 16
631 && BitsStored < BitsAllocated
634 int l = (int)( RawSize / ( BitsAllocated / 8 ) );
635 uint16_t *deb = (uint16_t *)Raw;
636 for(int i = 0; i<l; i++)
648 * \brief Deal with Grey levels i.e. re-arange them
649 * to have low values = dark, high values = bright
651 void PixelReadConvert::ConvertFixGreyLevels()
656 uint32_t i; // to please M$VC6
661 if ( BitsAllocated == 8 )
663 uint8_t *deb = (uint8_t *)Raw;
664 for (i=0; i<RawSize; i++)
672 if ( BitsAllocated == 16 )
675 for (j=0; j<BitsStored-1; j++)
677 mask = (mask << 1) +1; // will be fff when BitsStored=12
680 uint16_t *deb = (uint16_t *)Raw;
681 for (i=0; i<RawSize/2; i++)
691 if ( BitsAllocated == 8 )
694 int8_t *deb = (int8_t *)Raw;
695 for (i=0; i<RawSize; i++)
697 *deb = smask8 - *deb;
702 if ( BitsAllocated == 16 )
704 int16_t smask16 = 65535;
705 int16_t *deb = (int16_t *)Raw;
706 for (i=0; i<RawSize/2; i++)
708 *deb = smask16 - *deb;
717 * \brief Re-arrange the bits within the bytes.
718 * @return Boolean always true
720 bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError )
722 if ( BitsStored != BitsAllocated )
724 int l = (int)( RawSize / ( BitsAllocated / 8 ) );
725 if ( BitsAllocated == 16 )
727 uint16_t mask = 0xffff;
728 mask = mask >> ( BitsAllocated - BitsStored );
729 uint16_t *deb = (uint16_t*)Raw;
730 for(int i = 0; i<l; i++)
732 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
736 else if ( BitsAllocated == 32 )
738 uint32_t mask = 0xffffffff;
739 mask = mask >> ( BitsAllocated - BitsStored );
740 uint32_t *deb = (uint32_t*)Raw;
741 for(int i = 0; i<l; i++)
743 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
749 gdcmWarningMacro("Weird image");
750 throw FormatError( "Weird image !?" );
757 * \brief Convert (Red plane, Green plane, Blue plane) to RGB pixels
758 * \warning Works on all the frames at a time
760 void PixelReadConvert::ConvertRGBPlanesToRGBPixels()
762 uint8_t *localRaw = Raw;
763 uint8_t *copyRaw = new uint8_t[ RawSize ];
764 memmove( copyRaw, localRaw, RawSize );
766 int l = XSize * YSize * ZSize;
768 uint8_t *a = copyRaw;
769 uint8_t *b = copyRaw + l;
770 uint8_t *c = copyRaw + l + l;
772 for (int j = 0; j < l; j++)
774 *(localRaw++) = *(a++);
775 *(localRaw++) = *(b++);
776 *(localRaw++) = *(c++);
782 * \brief Convert (cY plane, cB plane, cR plane) to RGB pixels
783 * \warning Works on all the frames at a time
785 void PixelReadConvert::ConvertYcBcRPlanesToRGBPixels()
787 uint8_t *localRaw = Raw;
788 uint8_t *copyRaw = new uint8_t[ RawSize ];
789 memmove( copyRaw, localRaw, RawSize );
791 // to see the tricks about YBR_FULL, YBR_FULL_422,
792 // YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at :
793 // ftp://medical.nema.org/medical/dicom/final/sup61_ft.pdf
794 // and be *very* affraid
796 int l = XSize * YSize;
797 int nbFrames = ZSize;
799 uint8_t *a = copyRaw;
800 uint8_t *b = copyRaw + l;
801 uint8_t *c = copyRaw + l + l;
804 /// \todo : Replace by the 'well known' integer computation
805 /// counterpart. Refer to
806 /// http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
807 /// for code optimisation.
809 for ( int i = 0; i < nbFrames; i++ )
811 for ( int j = 0; j < l; j++ )
813 R = 1.164 *(*a-16) + 1.596 *(*c -128) + 0.5;
814 G = 1.164 *(*a-16) - 0.813 *(*c -128) - 0.392 *(*b -128) + 0.5;
815 B = 1.164 *(*a-16) + 2.017 *(*b -128) + 0.5;
817 if (R < 0.0) R = 0.0;
818 if (G < 0.0) G = 0.0;
819 if (B < 0.0) B = 0.0;
820 if (R > 255.0) R = 255.0;
821 if (G > 255.0) G = 255.0;
822 if (B > 255.0) B = 255.0;
824 *(localRaw++) = (uint8_t)R;
825 *(localRaw++) = (uint8_t)G;
826 *(localRaw++) = (uint8_t)B;
835 /// \brief Deals with the color decoding i.e. handle:
836 /// - R, G, B planes (as opposed to RGB pixels)
837 /// - YBR (various) encodings.
838 /// - LUT[s] (or "PALETTE COLOR").
840 void PixelReadConvert::ConvertHandleColor()
842 //////////////////////////////////
843 // Deal with the color decoding i.e. handle:
844 // - R, G, B planes (as opposed to RGB pixels)
845 // - YBR (various) encodings.
846 // - LUT[s] (or "PALETTE COLOR").
848 // The classification in the color decoding schema is based on the blending
849 // of two Dicom tags values:
850 // * "Photometric Interpretation" for which we have the cases:
851 // - [Photo A] MONOCHROME[1|2] pictures,
852 // - [Photo B] RGB or YBR_FULL_422 (which acts as RGB),
853 // - [Photo C] YBR_* (with the above exception of YBR_FULL_422)
854 // - [Photo D] "PALETTE COLOR" which indicates the presence of LUT[s].
855 // * "Planar Configuration" for which we have the cases:
856 // - [Planar 0] 0 then Pixels are already RGB
857 // - [Planar 1] 1 then we have 3 planes : R, G, B,
858 // - [Planar 2] 2 then we have 1 gray Plane and 3 LUTs
860 // Now in theory, one could expect some coherence when blending the above
861 // cases. For example we should not encounter files belonging at the
862 // time to case [Planar 0] and case [Photo D].
863 // Alas, this was only theory ! Because in practice some odd (read ill
864 // formated Dicom) files (e.g. gdcmData/US-PAL-8-10x-echo.dcm) we encounter:
865 // - "Planar Configuration" = 0,
866 // - "Photometric Interpretation" = "PALETTE COLOR".
867 // Hence gdcm will use the folowing "heuristic" in order to be tolerant
868 // towards Dicom-non-conformance files:
869 // << whatever the "Planar Configuration" value might be, a
870 // "Photometric Interpretation" set to "PALETTE COLOR" forces
871 // a LUT intervention >>
873 // Now we are left with the following handling of the cases:
874 // - [Planar 0] OR [Photo A] no color decoding (since respectively
875 // Pixels are already RGB and monochrome pictures have no color :),
876 // - [Planar 1] AND [Photo B] handled with ConvertRGBPlanesToRGBPixels()
877 // - [Planar 1] AND [Photo C] handled with ConvertYcBcRPlanesToRGBPixels()
878 // - [Planar 2] OR [Photo D] requires LUT intervention.
882 // [Planar 2] OR [Photo D]: LUT intervention done outside
886 if ( PlanarConfiguration == 1 )
890 // [Planar 1] AND [Photo C] (remember YBR_FULL_422 acts as RGB)
891 ConvertYcBcRPlanesToRGBPixels();
895 // [Planar 1] AND [Photo C]
896 ConvertRGBPlanesToRGBPixels();
901 // When planarConf is 0, and RLELossless (forbidden by Dicom norm)
902 // pixels need to be RGB-fied anyway
905 ConvertRGBPlanesToRGBPixels();
907 // In *normal *case, when planarConf is 0, pixels are already in RGB
910 /// Computes the Pixels Size
911 void PixelReadConvert::ComputeRawAndRGBSizes()
913 int bitsAllocated = BitsAllocated;
914 // Number of "Bits Allocated" is fixed to 16 when it's 12, since
915 // in this case we will expand the image to 16 bits (see
916 // \ref ReadAndDecompress12BitsTo16Bits() )
917 if ( BitsAllocated == 12 )
922 RawSize = XSize * YSize * ZSize
923 * ( bitsAllocated / 8 )
927 RGBSize = 3 * RawSize;
935 /// Allocates room for RGB Pixels
936 void PixelReadConvert::AllocateRGB()
940 RGB = new uint8_t[RGBSize];
943 /// Allocates room for RAW Pixels
944 void PixelReadConvert::AllocateRaw()
948 Raw = new uint8_t[RawSize];
951 //-----------------------------------------------------------------------------
955 * @param indent Indentation string to be prepended during printing.
956 * @param os Stream to print to.
958 void PixelReadConvert::Print( std::ostream &os, std::string const &indent )
961 << "--- Pixel information -------------------------"
964 << "Pixel Data: offset " << PixelOffset
965 << " x(" << std::hex << PixelOffset << std::dec
966 << ") length " << PixelDataLength
967 << " x(" << std::hex << PixelDataLength << std::dec
974 RLEInfo->Print( os, indent );
978 gdcmWarningMacro("Set as RLE file but NO RLEinfo present.");
982 if ( IsJPEG2000 || IsJPEGLossless || IsJPEGLossy || IsJPEGLS )
986 JPEGInfo->Print( os, indent );
990 gdcmWarningMacro("Set as JPEG file but NO JPEGinfo present.");
995 //-----------------------------------------------------------------------------
996 } // end namespace gdcm
998 // NOTES on File internal calls
1000 // ---> GetImageData
1001 // ---> GetImageDataIntoVector
1002 // |---> GetImageDataIntoVectorRaw
1003 // | lut intervention
1005 // ---> GetImageDataRaw
1006 // ---> GetImageDataIntoVectorRaw