1 /*=========================================================================
4 Module: $RCSfile: gdcmPixelReadConvert.cxx,v $
6 Date: $Date: 2005/05/23 13:28:19 $
7 Version: $Revision: 1.59 $
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 // gdcmWarningMacro( "Sorry, JPEG2000 not yet taken into account" );
401 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
402 // if ( ! gdcm_read_JPEG2000_file( fp,Raw, JPEGInfo->GetFirstFragment()->GetLength() ) )
408 gdcmWarningMacro( "Sorry, JPEG-LS not yet taken into account" );
409 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
410 // if ( ! gdcm_read_JPEGLS_file( fp,Raw ) )
415 // Precompute the offset localRaw will be shifted with
416 int length = XSize * YSize * SamplesPerPixel;
417 int numberBytes = BitsAllocated / 8;
419 JPEGInfo->DecompressFromFile(fp, Raw, BitsStored, numberBytes, length );
424 * \brief Build Red/Green/Blue/Alpha LUT from File
425 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
426 * and (0028,1101),(0028,1102),(0028,1102)
427 * - xxx Palette Color Lookup Table Descriptor - are found
428 * and (0028,1201),(0028,1202),(0028,1202)
429 * - xxx Palette Color Lookup Table Data - are found
430 * \warning does NOT deal with :
431 * 0028 1100 Gray Lookup Table Descriptor (Retired)
432 * 0028 1221 Segmented Red Palette Color Lookup Table Data
433 * 0028 1222 Segmented Green Palette Color Lookup Table Data
434 * 0028 1223 Segmented Blue Palette Color Lookup Table Data
435 * no known Dicom reader deals with them :-(
436 * @return a RGBA Lookup Table
438 void PixelReadConvert::BuildLUTRGBA()
445 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
447 if ( ! IsPaletteColor )
452 if ( LutRedDescriptor == GDCM_UNFOUND
453 || LutGreenDescriptor == GDCM_UNFOUND
454 || LutBlueDescriptor == GDCM_UNFOUND )
459 ////////////////////////////////////////////
460 // Extract the info from the LUT descriptors
461 int lengthR; // Red LUT length in Bytes
462 int debR; // Subscript of the first Lut Value
463 int nbitsR; // Lut item size (in Bits)
464 int nbRead = sscanf( LutRedDescriptor.c_str(),
466 &lengthR, &debR, &nbitsR );
469 gdcmWarningMacro( "Wrong Red LUT descriptor" );
472 int lengthG; // Green LUT length in Bytes
473 int debG; // Subscript of the first Lut Value
474 int nbitsG; // Lut item size (in Bits)
475 nbRead = sscanf( LutGreenDescriptor.c_str(),
477 &lengthG, &debG, &nbitsG );
480 gdcmWarningMacro( "Wrong Green LUT descriptor" );
483 int lengthB; // Blue LUT length in Bytes
484 int debB; // Subscript of the first Lut Value
485 int nbitsB; // Lut item size (in Bits)
486 nbRead = sscanf( LutRedDescriptor.c_str(),
488 &lengthB, &debB, &nbitsB );
491 gdcmWarningMacro( "Wrong Blue LUT descriptor" );
494 ////////////////////////////////////////////////////////
495 if ( ( ! LutRedData ) || ( ! LutGreenData ) || ( ! LutBlueData ) )
500 ////////////////////////////////////////////////
501 // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
502 LutRGBA = new uint8_t[ 1024 ]; // 256 * 4 (R, G, B, Alpha)
506 memset( LutRGBA, 0, 1024 );
509 if ( ( nbitsR == 16 ) && ( BitsAllocated == 8 ) )
511 // when LUT item size is different than pixel size
512 mult = 2; // high byte must be = low byte
516 // See PS 3.3-2003 C.11.1.1.2 p 619
520 // if we get a black image, let's just remove the '+1'
521 // from 'i*mult+1' and check again
522 // if it works, we shall have to check the 3 Palettes
523 // to see which byte is ==0 (first one, or second one)
525 // We give up the checking to avoid some (useless ?) overhead
526 // (optimistic asumption)
528 uint8_t *a = LutRGBA + 0;
529 for( i=0; i < lengthR; ++i )
531 *a = LutRedData[i*mult+1];
536 for( i=0; i < lengthG; ++i)
538 *a = LutGreenData[i*mult+1];
543 for(i=0; i < lengthB; ++i)
545 *a = LutBlueData[i*mult+1];
550 for(i=0; i < 256; ++i)
552 *a = 1; // Alpha component
558 * \brief Swap the bytes, according to \ref SwapCode.
560 void PixelReadConvert::ConvertSwapZone()
564 if( BitsAllocated == 16 )
566 uint16_t *im16 = (uint16_t*)Raw;
574 for( i = 0; i < RawSize / 2; i++ )
576 im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
580 gdcmWarningMacro("SwapCode value (16 bits) not allowed.");
583 else if( BitsAllocated == 32 )
588 uint32_t *im32 = (uint32_t*)Raw;
594 for( i = 0; i < RawSize / 4; i++ )
596 low = im32[i] & 0x0000ffff; // 4321
597 high = im32[i] >> 16;
598 high = ( high >> 8 ) | ( high << 8 );
599 low = ( low >> 8 ) | ( low << 8 );
601 im32[i] = ( s32 << 16 ) | high;
605 for( i = 0; i < RawSize / 4; i++ )
607 low = im32[i] & 0x0000ffff; // 2143
608 high = im32[i] >> 16;
609 high = ( high >> 8 ) | ( high << 8 );
610 low = ( low >> 8 ) | ( low << 8 );
612 im32[i] = ( s32 << 16 ) | low;
616 for( i = 0; i < RawSize / 4; i++ )
618 low = im32[i] & 0x0000ffff; // 3412
619 high = im32[i] >> 16;
621 im32[i] = ( s32 << 16 ) | high;
625 gdcmWarningMacro("SwapCode value (32 bits) not allowed." );
631 * \brief Deal with endianness i.e. re-arange bytes inside the integer
633 void PixelReadConvert::ConvertReorderEndianity()
635 if ( BitsAllocated != 8 )
640 // Special kludge in order to deal with xmedcon broken images:
641 if ( BitsAllocated == 16
642 && BitsStored < BitsAllocated
645 int l = (int)( RawSize / ( BitsAllocated / 8 ) );
646 uint16_t *deb = (uint16_t *)Raw;
647 for(int i = 0; i<l; i++)
659 * \brief Deal with Grey levels i.e. re-arange them
660 * to have low values = dark, high values = bright
662 void PixelReadConvert::ConvertFixGreyLevels()
667 uint32_t i; // to please M$VC6
672 if ( BitsAllocated == 8 )
674 uint8_t *deb = (uint8_t *)Raw;
675 for (i=0; i<RawSize; i++)
683 if ( BitsAllocated == 16 )
686 for (j=0; j<BitsStored-1; j++)
688 mask = (mask << 1) +1; // will be fff when BitsStored=12
691 uint16_t *deb = (uint16_t *)Raw;
692 for (i=0; i<RawSize/2; i++)
702 if ( BitsAllocated == 8 )
704 uint8_t smask8 = 255;
705 uint8_t *deb = (uint8_t *)Raw;
706 for (i=0; i<RawSize; i++)
708 *deb = smask8 - *deb;
713 if ( BitsAllocated == 16 )
715 uint16_t smask16 = 65535;
716 uint16_t *deb = (uint16_t *)Raw;
717 for (i=0; i<RawSize/2; i++)
719 *deb = smask16 - *deb;
728 * \brief Re-arrange the bits within the bytes.
729 * @return Boolean always true
731 bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError )
733 if ( BitsStored != BitsAllocated )
735 int l = (int)( RawSize / ( BitsAllocated / 8 ) );
736 if ( BitsAllocated == 16 )
738 uint16_t mask = 0xffff;
739 mask = mask >> ( BitsAllocated - BitsStored );
740 uint16_t *deb = (uint16_t*)Raw;
741 for(int i = 0; i<l; i++)
743 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
747 else if ( BitsAllocated == 32 )
749 uint32_t mask = 0xffffffff;
750 mask = mask >> ( BitsAllocated - BitsStored );
751 uint32_t *deb = (uint32_t*)Raw;
752 for(int i = 0; i<l; i++)
754 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
760 gdcmWarningMacro("Weird image");
761 throw FormatError( "Weird image !?" );
768 * \brief Convert (Red plane, Green plane, Blue plane) to RGB pixels
769 * \warning Works on all the frames at a time
771 void PixelReadConvert::ConvertRGBPlanesToRGBPixels()
773 uint8_t *localRaw = Raw;
774 uint8_t *copyRaw = new uint8_t[ RawSize ];
775 memmove( copyRaw, localRaw, RawSize );
777 int l = XSize * YSize * ZSize;
779 uint8_t *a = copyRaw;
780 uint8_t *b = copyRaw + l;
781 uint8_t *c = copyRaw + l + l;
783 for (int j = 0; j < l; j++)
785 *(localRaw++) = *(a++);
786 *(localRaw++) = *(b++);
787 *(localRaw++) = *(c++);
793 * \brief Convert (cY plane, cB plane, cR plane) to RGB pixels
794 * \warning Works on all the frames at a time
796 void PixelReadConvert::ConvertYcBcRPlanesToRGBPixels()
798 uint8_t *localRaw = Raw;
799 uint8_t *copyRaw = new uint8_t[ RawSize ];
800 memmove( copyRaw, localRaw, RawSize );
802 // to see the tricks about YBR_FULL, YBR_FULL_422,
803 // YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at :
804 // ftp://medical.nema.org/medical/dicom/final/sup61_ft.pdf
805 // and be *very* affraid
807 int l = XSize * YSize;
808 int nbFrames = ZSize;
810 uint8_t *a = copyRaw + 0;
811 uint8_t *b = copyRaw + l;
812 uint8_t *c = copyRaw + l+ l;
815 /// \todo : Replace by the 'well known' integer computation
816 /// counterpart. Refer to
817 /// http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
818 /// for code optimisation.
820 for ( int i = 0; i < nbFrames; i++ )
822 for ( int j = 0; j < l; j++ )
824 R = 38142 *(*a-16) + 52298 *(*c -128);
825 G = 38142 *(*a-16) - 26640 *(*c -128) - 12845 *(*b -128);
826 B = 38142 *(*a-16) + 66093 *(*b -128);
835 if (R > 255) R = 255;
836 if (G > 255) G = 255;
837 if (B > 255) B = 255;
839 *(localRaw++) = (uint8_t)R;
840 *(localRaw++) = (uint8_t)G;
841 *(localRaw++) = (uint8_t)B;
850 /// \brief Deals with the color decoding i.e. handle:
851 /// - R, G, B planes (as opposed to RGB pixels)
852 /// - YBR (various) encodings.
853 /// - LUT[s] (or "PALETTE COLOR").
855 void PixelReadConvert::ConvertHandleColor()
857 //////////////////////////////////
858 // Deal with the color decoding i.e. handle:
859 // - R, G, B planes (as opposed to RGB pixels)
860 // - YBR (various) encodings.
861 // - LUT[s] (or "PALETTE COLOR").
863 // The classification in the color decoding schema is based on the blending
864 // of two Dicom tags values:
865 // * "Photometric Interpretation" for which we have the cases:
866 // - [Photo A] MONOCHROME[1|2] pictures,
867 // - [Photo B] RGB or YBR_FULL_422 (which acts as RGB),
868 // - [Photo C] YBR_* (with the above exception of YBR_FULL_422)
869 // - [Photo D] "PALETTE COLOR" which indicates the presence of LUT[s].
870 // * "Planar Configuration" for which we have the cases:
871 // - [Planar 0] 0 then Pixels are already RGB
872 // - [Planar 1] 1 then we have 3 planes : R, G, B,
873 // - [Planar 2] 2 then we have 1 gray Plane and 3 LUTs
875 // Now in theory, one could expect some coherence when blending the above
876 // cases. For example we should not encounter files belonging at the
877 // time to case [Planar 0] and case [Photo D].
878 // Alas, this was only theory ! Because in practice some odd (read ill
879 // formated Dicom) files (e.g. gdcmData/US-PAL-8-10x-echo.dcm) we encounter:
880 // - "Planar Configuration" = 0,
881 // - "Photometric Interpretation" = "PALETTE COLOR".
882 // Hence gdcm will use the folowing "heuristic" in order to be tolerant
883 // towards Dicom-non-conformance files:
884 // << whatever the "Planar Configuration" value might be, a
885 // "Photometric Interpretation" set to "PALETTE COLOR" forces
886 // a LUT intervention >>
888 // Now we are left with the following handling of the cases:
889 // - [Planar 0] OR [Photo A] no color decoding (since respectively
890 // Pixels are already RGB and monochrome pictures have no color :),
891 // - [Planar 1] AND [Photo B] handled with ConvertRGBPlanesToRGBPixels()
892 // - [Planar 1] AND [Photo C] handled with ConvertYcBcRPlanesToRGBPixels()
893 // - [Planar 2] OR [Photo D] requires LUT intervention.
897 // [Planar 2] OR [Photo D]: LUT intervention done outside
901 if ( PlanarConfiguration == 1 )
905 // [Planar 1] AND [Photo C] (remember YBR_FULL_422 acts as RGB)
906 ConvertYcBcRPlanesToRGBPixels();
910 // [Planar 1] AND [Photo C]
911 ConvertRGBPlanesToRGBPixels();
916 // When planarConf is 0, and RLELossless (forbidden by Dicom norm)
917 // pixels need to be RGB-fied anyway
920 ConvertRGBPlanesToRGBPixels();
922 // In *normal *case, when planarConf is 0, pixels are already in RGB
925 /// Computes the Pixels Size
926 void PixelReadConvert::ComputeRawAndRGBSizes()
928 int bitsAllocated = BitsAllocated;
929 // Number of "Bits Allocated" is fixed to 16 when it's 12, since
930 // in this case we will expand the image to 16 bits (see
931 // \ref ReadAndDecompress12BitsTo16Bits() )
932 if ( BitsAllocated == 12 )
937 RawSize = XSize * YSize * ZSize
938 * ( bitsAllocated / 8 )
942 RGBSize = 3 * RawSize;
950 /// Allocates room for RGB Pixels
951 void PixelReadConvert::AllocateRGB()
955 RGB = new uint8_t[RGBSize];
958 /// Allocates room for RAW Pixels
959 void PixelReadConvert::AllocateRaw()
963 Raw = new uint8_t[RawSize];
966 //-----------------------------------------------------------------------------
970 * @param indent Indentation string to be prepended during printing.
971 * @param os Stream to print to.
973 void PixelReadConvert::Print( std::ostream &os, std::string const &indent )
976 << "--- Pixel information -------------------------"
979 << "Pixel Data: offset " << PixelOffset
980 << " x(" << std::hex << PixelOffset << std::dec
981 << ") length " << PixelDataLength
982 << " x(" << std::hex << PixelDataLength << std::dec
989 RLEInfo->Print( os, indent );
993 gdcmWarningMacro("Set as RLE file but NO RLEinfo present.");
997 if ( IsJPEG2000 || IsJPEGLossless || IsJPEGLossy || IsJPEGLS )
1001 JPEGInfo->Print( os, indent );
1005 gdcmWarningMacro("Set as JPEG file but NO JPEGinfo present.");
1010 //-----------------------------------------------------------------------------
1011 } // end namespace gdcm
1013 // NOTES on File internal calls
1015 // ---> GetImageData
1016 // ---> GetImageDataIntoVector
1017 // |---> GetImageDataIntoVectorRaw
1018 // | lut intervention
1020 // ---> GetImageDataRaw
1021 // ---> GetImageDataIntoVectorRaw