1 /*=========================================================================
4 Module: $RCSfile: gdcmPixelReadConvert.cxx,v $
6 Date: $Date: 2005/05/21 18:43:53 $
7 Version: $Revision: 1.56 $
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 extern bool ReadMPEGFile (std::ifstream *fp, void *image_buffer);
35 //-----------------------------------------------------------------------------
36 #define str2num(str, typeNum) *((typeNum *)(str))
38 //-----------------------------------------------------------------------------
39 // Constructor / Destructor
41 PixelReadConvert::PixelReadConvert()
53 /// Canonical Destructor
54 PixelReadConvert::~PixelReadConvert()
59 //-----------------------------------------------------------------------------
62 * \brief Predicate to know whether the image[s] (once Raw) is RGB.
63 * \note See comments of \ref ConvertHandleColor
65 bool PixelReadConvert::IsRawRGB()
68 || PlanarConfiguration == 2
76 * \brief Gets various usefull informations from the file header
77 * @param file gdcm::File pointer
79 void PixelReadConvert::GrabInformationsFromFile( File *file )
81 // Number of Bits Allocated for storing a Pixel is defaulted to 16
82 // when absent from the file.
83 BitsAllocated = file->GetBitsAllocated();
84 if ( BitsAllocated == 0 )
89 // Number of "Bits Stored", defaulted to number of "Bits Allocated"
90 // when absent from the file.
91 BitsStored = file->GetBitsStored();
92 if ( BitsStored == 0 )
94 BitsStored = BitsAllocated;
97 // High Bit Position, defaulted to "Bits Allocated" - 1
98 HighBitPosition = file->GetHighBitPosition();
99 if ( HighBitPosition == 0 )
101 HighBitPosition = BitsAllocated - 1;
104 XSize = file->GetXSize();
105 YSize = file->GetYSize();
106 ZSize = file->GetZSize();
107 SamplesPerPixel = file->GetSamplesPerPixel();
108 PixelSize = file->GetPixelSize();
109 PixelSign = file->IsSignedPixelData();
110 SwapCode = file->GetSwapCode();
111 std::string ts = file->GetTransferSyntax();
113 ( ! file->IsDicomV3() )
114 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndian
115 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndianDLXGE
116 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRLittleEndian
117 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian
118 || Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::DeflatedExplicitVRLittleEndian;
120 IsMPEG = Global::GetTS()->IsMPEG(ts);
121 IsJPEG2000 = Global::GetTS()->IsJPEG2000(ts);
122 IsJPEGLS = Global::GetTS()->IsJPEGLS(ts);
123 IsJPEGLossy = Global::GetTS()->IsJPEGLossy(ts);
124 IsJPEGLossless = Global::GetTS()->IsJPEGLossless(ts);
125 IsRLELossless = Global::GetTS()->IsRLELossless(ts);
127 PixelOffset = file->GetPixelOffset();
128 PixelDataLength = file->GetPixelAreaLength();
129 RLEInfo = file->GetRLEInfo();
130 JPEGInfo = file->GetJPEGInfo();
132 IsMonochrome = file->IsMonochrome();
133 IsMonochrome1 = file->IsMonochrome1();
134 IsPaletteColor = file->IsPaletteColor();
135 IsYBRFull = file->IsYBRFull();
137 PlanarConfiguration = file->GetPlanarConfiguration();
139 /////////////////////////////////////////////////////////////////
141 HasLUT = file->HasLUT();
144 // Just in case some access to a File element requires disk access.
145 LutRedDescriptor = file->GetEntryValue( 0x0028, 0x1101 );
146 LutGreenDescriptor = file->GetEntryValue( 0x0028, 0x1102 );
147 LutBlueDescriptor = file->GetEntryValue( 0x0028, 0x1103 );
149 // Depending on the value of Document::MAX_SIZE_LOAD_ELEMENT_VALUE
150 // [ refer to invocation of Document::SetMaxSizeLoadEntry() in
151 // Document::Document() ], the loading of the value (content) of a
152 // [Bin|Val]Entry occurence migth have been hindered (read simply NOT
153 // loaded). Hence, we first try to obtain the LUTs data from the file
154 // and when this fails we read the LUTs data directly from disk.
155 // \TODO Reading a [Bin|Val]Entry directly from disk is a kludge.
156 // We should NOT bypass the [Bin|Val]Entry class. Instead
157 // an access to an UNLOADED content of a [Bin|Val]Entry occurence
158 // (e.g. BinEntry::GetBinArea()) should force disk access from
159 // within the [Bin|Val]Entry class itself. The only problem
160 // is that the [Bin|Val]Entry is unaware of the FILE* is was
161 // parsed from. Fix that. FIXME.
164 file->LoadEntryBinArea(0x0028, 0x1201);
165 LutRedData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1201 );
168 gdcmWarningMacro( "Unable to read Red LUT data" );
172 file->LoadEntryBinArea(0x0028, 0x1202);
173 LutGreenData = (uint8_t*)file->GetEntryBinArea(0x0028, 0x1202 );
176 gdcmWarningMacro( "Unable to read Green LUT data" );
180 file->LoadEntryBinArea(0x0028, 0x1203);
181 LutBlueData = (uint8_t*)file->GetEntryBinArea( 0x0028, 0x1203 );
184 gdcmWarningMacro( "Unable to read Blue LUT data" );
188 ComputeRawAndRGBSizes();
191 /// \brief Reads from disk and decompresses Pixels
192 bool PixelReadConvert::ReadAndDecompressPixelData( std::ifstream *fp )
194 // ComputeRawAndRGBSizes is already made by
195 // ::GrabInformationsFromfile. So, the structure sizes are
199 //////////////////////////////////////////////////
200 //// First stage: get our hands on the Pixel Data.
203 gdcmWarningMacro( "Unavailable file pointer." );
207 fp->seekg( PixelOffset, std::ios::beg );
208 if( fp->fail() || fp->eof())
210 gdcmWarningMacro( "Unable to find PixelOffset in file." );
216 //////////////////////////////////////////////////
217 //// Second stage: read from disk dans decompress.
218 if ( BitsAllocated == 12 )
220 ReadAndDecompress12BitsTo16Bits( fp);
224 // This problem can be found when some obvious informations are found
225 // after the field containing the image data. In this case, these
226 // bad data are added to the size of the image (in the PixelDataLength
227 // variable). But RawSize is the right size of the image !
228 if( PixelDataLength != RawSize)
230 gdcmWarningMacro( "Mismatch between PixelReadConvert : "
231 << PixelDataLength << " and RawSize : " << RawSize );
233 if( PixelDataLength > RawSize)
235 fp->read( (char*)Raw, RawSize);
239 fp->read( (char*)Raw, PixelDataLength);
242 if ( fp->fail() || fp->eof())
244 gdcmWarningMacro( "Reading of Raw pixel data failed." );
248 else if ( IsRLELossless )
250 if ( ! RLEInfo->DecompressRLEFile( fp, Raw, XSize, YSize, ZSize, BitsAllocated ) )
252 gdcmWarningMacro( "RLE decompressor failed." );
258 //gdcmWarningMacro( "Sorry, MPEG not yet taken into account" );
260 ReadMPEGFile(fp, Raw); // fp has already been seek to start of mpeg
265 // Default case concerns JPEG family
266 if ( ! ReadAndDecompressJPEGFile( fp ) )
268 gdcmWarningMacro( "JPEG decompressor failed." );
273 ////////////////////////////////////////////
274 //// Third stage: twigle the bytes and bits.
275 ConvertReorderEndianity();
276 ConvertReArrangeBits();
277 ConvertFixGreyLevels();
278 ConvertHandleColor();
283 /// Deletes Pixels Area
284 void PixelReadConvert::Squeeze()
300 * \brief Build the RGB image from the Raw imagage and the LUTs.
302 bool PixelReadConvert::BuildRGBImage()
306 // The job is already done.
312 // The job can't be done
319 // The job can't be done
325 uint8_t *localRGB = RGB;
326 for (size_t i = 0; i < RawSize; ++i )
329 *localRGB++ = LutRGBA[j];
330 *localRGB++ = LutRGBA[j+1];
331 *localRGB++ = LutRGBA[j+2];
336 //-----------------------------------------------------------------------------
339 //-----------------------------------------------------------------------------
342 * \brief Read from file a 12 bits per pixel image and decompress it
343 * into a 16 bits per pixel image.
345 void PixelReadConvert::ReadAndDecompress12BitsTo16Bits( std::ifstream *fp )
346 throw ( FormatError )
348 int nbPixels = XSize * YSize;
349 uint16_t *localDecompres = (uint16_t*)Raw;
351 for( int p = 0; p < nbPixels; p += 2 )
355 fp->read( (char*)&b0, 1);
356 if ( fp->fail() || fp->eof() )
358 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
359 "Unfound first block" );
362 fp->read( (char*)&b1, 1 );
363 if ( fp->fail() || fp->eof())
365 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
366 "Unfound second block" );
369 fp->read( (char*)&b2, 1 );
370 if ( fp->fail() || fp->eof())
372 throw FormatError( "PixelReadConvert::ReadAndDecompress12BitsTo16Bits()",
373 "Unfound second block" );
376 // Two steps are necessary to please VC++
378 // 2 pixels 12bit = [0xABCDEF]
379 // 2 pixels 16bit = [0x0ABD] + [0x0FCE]
381 *localDecompres++ = ((b0 >> 4) << 8) + ((b0 & 0x0f) << 4) + (b1 & 0x0f);
383 *localDecompres++ = ((b2 & 0x0f) << 8) + ((b1 >> 4) << 4) + (b2 >> 4);
385 /// \todo JPR Troubles expected on Big-Endian processors ?
390 * \brief Reads from disk the Pixel Data of JPEG Dicom encapsulated
391 * file and decompress it.
392 * @param fp File Pointer
395 bool PixelReadConvert::ReadAndDecompressJPEGFile( std::ifstream *fp )
399 gdcmWarningMacro( "Sorry, JPEG2000 not yet taken into account" );
400 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
401 // if ( ! gdcm_read_JPEG2000_file( fp,Raw ) )
407 gdcmWarningMacro( "Sorry, JPEG-LS not yet taken into account" );
408 fp->seekg( JPEGInfo->GetFirstFragment()->GetOffset(), std::ios::beg);
409 // if ( ! gdcm_read_JPEGLS_file( fp,Raw ) )
414 // Precompute the offset localRaw will be shifted with
415 int length = XSize * YSize * SamplesPerPixel;
416 int numberBytes = BitsAllocated / 8;
418 JPEGInfo->DecompressFromFile(fp, Raw, BitsStored, numberBytes, length );
423 * \brief Build Red/Green/Blue/Alpha LUT from File
424 * when (0028,0004),Photometric Interpretation = [PALETTE COLOR ]
425 * and (0028,1101),(0028,1102),(0028,1102)
426 * - xxx Palette Color Lookup Table Descriptor - are found
427 * and (0028,1201),(0028,1202),(0028,1202)
428 * - xxx Palette Color Lookup Table Data - are found
429 * \warning does NOT deal with :
430 * 0028 1100 Gray Lookup Table Descriptor (Retired)
431 * 0028 1221 Segmented Red Palette Color Lookup Table Data
432 * 0028 1222 Segmented Green Palette Color Lookup Table Data
433 * 0028 1223 Segmented Blue Palette Color Lookup Table Data
434 * no known Dicom reader deals with them :-(
435 * @return a RGBA Lookup Table
437 void PixelReadConvert::BuildLUTRGBA()
444 // http://www.barre.nom.fr/medical/dicom2/limitations.html#Color%20Lookup%20Tables
446 if ( ! IsPaletteColor )
451 if ( LutRedDescriptor == GDCM_UNFOUND
452 || LutGreenDescriptor == GDCM_UNFOUND
453 || LutBlueDescriptor == GDCM_UNFOUND )
458 ////////////////////////////////////////////
459 // Extract the info from the LUT descriptors
460 int lengthR; // Red LUT length in Bytes
461 int debR; // Subscript of the first Lut Value
462 int nbitsR; // Lut item size (in Bits)
463 int nbRead = sscanf( LutRedDescriptor.c_str(),
465 &lengthR, &debR, &nbitsR );
468 gdcmWarningMacro( "Wrong Red LUT descriptor" );
471 int lengthG; // Green LUT length in Bytes
472 int debG; // Subscript of the first Lut Value
473 int nbitsG; // Lut item size (in Bits)
474 nbRead = sscanf( LutGreenDescriptor.c_str(),
476 &lengthG, &debG, &nbitsG );
479 gdcmWarningMacro( "Wrong Green LUT descriptor" );
482 int lengthB; // Blue LUT length in Bytes
483 int debB; // Subscript of the first Lut Value
484 int nbitsB; // Lut item size (in Bits)
485 nbRead = sscanf( LutRedDescriptor.c_str(),
487 &lengthB, &debB, &nbitsB );
490 gdcmWarningMacro( "Wrong Blue LUT descriptor" );
493 ////////////////////////////////////////////////////////
494 if ( ( ! LutRedData ) || ( ! LutGreenData ) || ( ! LutBlueData ) )
499 ////////////////////////////////////////////////
500 // forge the 4 * 8 Bits Red/Green/Blue/Alpha LUT
501 LutRGBA = new uint8_t[ 1024 ]; // 256 * 4 (R, G, B, Alpha)
505 memset( LutRGBA, 0, 1024 );
508 if ( ( nbitsR == 16 ) && ( BitsAllocated == 8 ) )
510 // when LUT item size is different than pixel size
511 mult = 2; // high byte must be = low byte
515 // See PS 3.3-2003 C.11.1.1.2 p 619
519 // if we get a black image, let's just remove the '+1'
520 // from 'i*mult+1' and check again
521 // if it works, we shall have to check the 3 Palettes
522 // to see which byte is ==0 (first one, or second one)
524 // We give up the checking to avoid some (useless ?) overhead
525 // (optimistic asumption)
527 uint8_t *a = LutRGBA + 0;
528 for( i=0; i < lengthR; ++i )
530 *a = LutRedData[i*mult+1];
535 for( i=0; i < lengthG; ++i)
537 *a = LutGreenData[i*mult+1];
542 for(i=0; i < lengthB; ++i)
544 *a = LutBlueData[i*mult+1];
549 for(i=0; i < 256; ++i)
551 *a = 1; // Alpha component
557 * \brief Swap the bytes, according to \ref SwapCode.
559 void PixelReadConvert::ConvertSwapZone()
563 if( BitsAllocated == 16 )
565 uint16_t *im16 = (uint16_t*)Raw;
573 for( i = 0; i < RawSize / 2; i++ )
575 im16[i]= (im16[i] >> 8) | (im16[i] << 8 );
579 gdcmWarningMacro("SwapCode value (16 bits) not allowed.");
582 else if( BitsAllocated == 32 )
587 uint32_t *im32 = (uint32_t*)Raw;
593 for( i = 0; i < RawSize / 4; i++ )
595 low = im32[i] & 0x0000ffff; // 4321
596 high = im32[i] >> 16;
597 high = ( high >> 8 ) | ( high << 8 );
598 low = ( low >> 8 ) | ( low << 8 );
600 im32[i] = ( s32 << 16 ) | high;
604 for( i = 0; i < RawSize / 4; i++ )
606 low = im32[i] & 0x0000ffff; // 2143
607 high = im32[i] >> 16;
608 high = ( high >> 8 ) | ( high << 8 );
609 low = ( low >> 8 ) | ( low << 8 );
611 im32[i] = ( s32 << 16 ) | low;
615 for( i = 0; i < RawSize / 4; i++ )
617 low = im32[i] & 0x0000ffff; // 3412
618 high = im32[i] >> 16;
620 im32[i] = ( s32 << 16 ) | high;
624 gdcmWarningMacro("SwapCode value (32 bits) not allowed." );
630 * \brief Deal with endianness i.e. re-arange bytes inside the integer
632 void PixelReadConvert::ConvertReorderEndianity()
634 if ( BitsAllocated != 8 )
639 // Special kludge in order to deal with xmedcon broken images:
640 if ( BitsAllocated == 16
641 && BitsStored < BitsAllocated
644 int l = (int)( RawSize / ( BitsAllocated / 8 ) );
645 uint16_t *deb = (uint16_t *)Raw;
646 for(int i = 0; i<l; i++)
658 * \brief Deal with Grey levels i.e. re-arange them
659 * to have low values = dark, high values = bright
661 void PixelReadConvert::ConvertFixGreyLevels()
666 uint32_t i; // to please M$VC6
671 if ( BitsAllocated == 8 )
673 uint8_t *deb = (uint8_t *)Raw;
674 for (i=0; i<RawSize; i++)
682 if ( BitsAllocated == 16 )
685 for (j=0; j<BitsStored-1; j++)
687 mask = (mask << 1) +1; // will be fff when BitsStored=12
690 uint16_t *deb = (uint16_t *)Raw;
691 for (i=0; i<RawSize/2; i++)
701 if ( BitsAllocated == 8 )
703 uint8_t smask8 = 255;
704 uint8_t *deb = (uint8_t *)Raw;
705 for (i=0; i<RawSize; i++)
707 *deb = smask8 - *deb;
712 if ( BitsAllocated == 16 )
714 uint16_t smask16 = 65535;
715 uint16_t *deb = (uint16_t *)Raw;
716 for (i=0; i<RawSize/2; i++)
718 *deb = smask16 - *deb;
727 * \brief Re-arrange the bits within the bytes.
728 * @return Boolean always true
730 bool PixelReadConvert::ConvertReArrangeBits() throw ( FormatError )
732 if ( BitsStored != BitsAllocated )
734 int l = (int)( RawSize / ( BitsAllocated / 8 ) );
735 if ( BitsAllocated == 16 )
737 uint16_t mask = 0xffff;
738 mask = mask >> ( BitsAllocated - BitsStored );
739 uint16_t *deb = (uint16_t*)Raw;
740 for(int i = 0; i<l; i++)
742 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
746 else if ( BitsAllocated == 32 )
748 uint32_t mask = 0xffffffff;
749 mask = mask >> ( BitsAllocated - BitsStored );
750 uint32_t *deb = (uint32_t*)Raw;
751 for(int i = 0; i<l; i++)
753 *deb = (*deb >> (BitsStored - HighBitPosition - 1)) & mask;
759 gdcmWarningMacro("Weird image");
760 throw FormatError( "Weird image !?" );
767 * \brief Convert (Red plane, Green plane, Blue plane) to RGB pixels
768 * \warning Works on all the frames at a time
770 void PixelReadConvert::ConvertRGBPlanesToRGBPixels()
772 uint8_t *localRaw = Raw;
773 uint8_t *copyRaw = new uint8_t[ RawSize ];
774 memmove( copyRaw, localRaw, RawSize );
776 int l = XSize * YSize * ZSize;
778 uint8_t *a = copyRaw;
779 uint8_t *b = copyRaw + l;
780 uint8_t *c = copyRaw + l + l;
782 for (int j = 0; j < l; j++)
784 *(localRaw++) = *(a++);
785 *(localRaw++) = *(b++);
786 *(localRaw++) = *(c++);
792 * \brief Convert (cY plane, cB plane, cR plane) to RGB pixels
793 * \warning Works on all the frames at a time
795 void PixelReadConvert::ConvertYcBcRPlanesToRGBPixels()
797 uint8_t *localRaw = Raw;
798 uint8_t *copyRaw = new uint8_t[ RawSize ];
799 memmove( copyRaw, localRaw, RawSize );
801 // to see the tricks about YBR_FULL, YBR_FULL_422,
802 // YBR_PARTIAL_422, YBR_ICT, YBR_RCT have a look at :
803 // ftp://medical.nema.org/medical/dicom/final/sup61_ft.pdf
804 // and be *very* affraid
806 int l = XSize * YSize;
807 int nbFrames = ZSize;
809 uint8_t *a = copyRaw + 0;
810 uint8_t *b = copyRaw + l;
811 uint8_t *c = copyRaw + l+ l;
814 /// \todo : Replace by the 'well known' integer computation
815 /// counterpart. Refer to
816 /// http://lestourtereaux.free.fr/papers/data/yuvrgb.pdf
817 /// for code optimisation.
819 for ( int i = 0; i < nbFrames; i++ )
821 for ( int j = 0; j < l; j++ )
823 R = 38142 *(*a-16) + 52298 *(*c -128);
824 G = 38142 *(*a-16) - 26640 *(*c -128) - 12845 *(*b -128);
825 B = 38142 *(*a-16) + 66093 *(*b -128);
834 if (R > 255) R = 255;
835 if (G > 255) G = 255;
836 if (B > 255) B = 255;
838 *(localRaw++) = (uint8_t)R;
839 *(localRaw++) = (uint8_t)G;
840 *(localRaw++) = (uint8_t)B;
849 /// \brief Deals with the color decoding i.e. handle:
850 /// - R, G, B planes (as opposed to RGB pixels)
851 /// - YBR (various) encodings.
852 /// - LUT[s] (or "PALETTE COLOR").
854 void PixelReadConvert::ConvertHandleColor()
856 //////////////////////////////////
857 // Deal with the color decoding i.e. handle:
858 // - R, G, B planes (as opposed to RGB pixels)
859 // - YBR (various) encodings.
860 // - LUT[s] (or "PALETTE COLOR").
862 // The classification in the color decoding schema is based on the blending
863 // of two Dicom tags values:
864 // * "Photometric Interpretation" for which we have the cases:
865 // - [Photo A] MONOCHROME[1|2] pictures,
866 // - [Photo B] RGB or YBR_FULL_422 (which acts as RGB),
867 // - [Photo C] YBR_* (with the above exception of YBR_FULL_422)
868 // - [Photo D] "PALETTE COLOR" which indicates the presence of LUT[s].
869 // * "Planar Configuration" for which we have the cases:
870 // - [Planar 0] 0 then Pixels are already RGB
871 // - [Planar 1] 1 then we have 3 planes : R, G, B,
872 // - [Planar 2] 2 then we have 1 gray Plane and 3 LUTs
874 // Now in theory, one could expect some coherence when blending the above
875 // cases. For example we should not encounter files belonging at the
876 // time to case [Planar 0] and case [Photo D].
877 // Alas, this was only theory ! Because in practice some odd (read ill
878 // formated Dicom) files (e.g. gdcmData/US-PAL-8-10x-echo.dcm) we encounter:
879 // - "Planar Configuration" = 0,
880 // - "Photometric Interpretation" = "PALETTE COLOR".
881 // Hence gdcm will use the folowing "heuristic" in order to be tolerant
882 // towards Dicom-non-conformance files:
883 // << whatever the "Planar Configuration" value might be, a
884 // "Photometric Interpretation" set to "PALETTE COLOR" forces
885 // a LUT intervention >>
887 // Now we are left with the following handling of the cases:
888 // - [Planar 0] OR [Photo A] no color decoding (since respectively
889 // Pixels are already RGB and monochrome pictures have no color :),
890 // - [Planar 1] AND [Photo B] handled with ConvertRGBPlanesToRGBPixels()
891 // - [Planar 1] AND [Photo C] handled with ConvertYcBcRPlanesToRGBPixels()
892 // - [Planar 2] OR [Photo D] requires LUT intervention.
896 // [Planar 2] OR [Photo D]: LUT intervention done outside
900 if ( PlanarConfiguration == 1 )
904 // [Planar 1] AND [Photo C] (remember YBR_FULL_422 acts as RGB)
905 ConvertYcBcRPlanesToRGBPixels();
909 // [Planar 1] AND [Photo C]
910 ConvertRGBPlanesToRGBPixels();
915 // When planarConf is 0, and RLELossless (forbidden by Dicom norm)
916 // pixels need to be RGB-fied anyway
919 ConvertRGBPlanesToRGBPixels();
921 // In *normal *case, when planarConf is 0, pixels are already in RGB
924 /// Computes the Pixels Size
925 void PixelReadConvert::ComputeRawAndRGBSizes()
927 int bitsAllocated = BitsAllocated;
928 // Number of "Bits Allocated" is fixed to 16 when it's 12, since
929 // in this case we will expand the image to 16 bits (see
930 // \ref ReadAndDecompress12BitsTo16Bits() )
931 if ( BitsAllocated == 12 )
936 RawSize = XSize * YSize * ZSize
937 * ( bitsAllocated / 8 )
941 RGBSize = 3 * RawSize;
949 /// Allocates room for RGB Pixels
950 void PixelReadConvert::AllocateRGB()
954 RGB = new uint8_t[RGBSize];
957 /// Allocates room for RAW Pixels
958 void PixelReadConvert::AllocateRaw()
962 Raw = new uint8_t[RawSize];
965 //-----------------------------------------------------------------------------
969 * @param indent Indentation string to be prepended during printing.
970 * @param os Stream to print to.
972 void PixelReadConvert::Print( std::ostream &os, std::string const &indent )
975 << "--- Pixel information -------------------------"
978 << "Pixel Data: offset " << PixelOffset
979 << " x(" << std::hex << PixelOffset << std::dec
980 << ") length " << PixelDataLength
981 << " x(" << std::hex << PixelDataLength << std::dec
988 RLEInfo->Print( os, indent );
992 gdcmWarningMacro("Set as RLE file but NO RLEinfo present.");
996 if ( IsJPEG2000 || IsJPEGLossless || IsJPEGLossy || IsJPEGLS )
1000 JPEGInfo->Print( os, indent );
1004 gdcmWarningMacro("Set as JPEG file but NO JPEGinfo present.");
1009 //-----------------------------------------------------------------------------
1010 } // end namespace gdcm
1012 // NOTES on File internal calls
1014 // ---> GetImageData
1015 // ---> GetImageDataIntoVector
1016 // |---> GetImageDataIntoVectorRaw
1017 // | lut intervention
1019 // ---> GetImageDataRaw
1020 // ---> GetImageDataIntoVectorRaw