1 /*=========================================================================
4 Module: $RCSfile: gdcmRLEFramesInfo.cxx,v $
6 Date: $Date: 2005/01/31 06:17:22 $
7 Version: $Revision: 1.10 $
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 "gdcmRLEFramesInfo.h"
20 #include "gdcmDebug.h"
25 RLEFramesInfo::~RLEFramesInfo()
27 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
36 * @param indent Indentation string to be prepended during printing.
37 * @param os Stream to print to.
39 void RLEFramesInfo::Print( std::ostream &os, std::string indent )
43 << "----------------- RLE frames --------------------------------"
46 << "Total number of Frames : " << Frames.size()
49 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
52 << " frame number :" << frameNumber++
54 (*it)->Print( os, indent + " " );
58 void RLEFramesInfo::AddFrame(RLEFrame *frame)
60 Frames.push_back(frame);
63 RLEFrame *RLEFramesInfo::GetFirstFrame()
65 ItFrames = Frames.begin();
66 if (ItFrames != Frames.end())
71 RLEFrame *RLEFramesInfo::GetNextFrame()
73 gdcmAssertMacro (ItFrames != Frames.end());
76 if (ItFrames != Frames.end())
82 * \brief Reads from disk the Pixel Data of 'Run Length Encoded'
83 * Dicom encapsulated file and decompress it.
84 * @param fp already open File Pointer
85 * at which the pixel data should be copied
88 bool RLEFramesInfo::DecompressRLEFile( std::ifstream *fp , uint8_t *raw, int xSize, int ySize, int zSize, int bitsAllocated )
90 uint8_t *subRaw = raw;
91 long rawSegmentSize = xSize * ySize;
93 // Loop on the frame[s]
94 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
96 subRaw = (*it)->ReadAndDecompressRLEFrame( subRaw, rawSegmentSize, fp);
99 if ( bitsAllocated == 16 )
101 // Try to deal with RLE 16 Bits
102 ConvertRLE16BitsFromRLE8Bits( raw, xSize, ySize, zSize );
109 * \brief Try to deal with RLE 16 Bits.
110 * We assume the RLE has already been parsed and loaded in
111 * Raw (through \ref ReadAndDecompressJPEGFile ).
112 * We here need to make 16 Bits Pixels from Low Byte and
113 * High Byte 'Planes'...(for what it may mean)
116 bool RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits( uint8_t* raw, int xSize,
117 int ySize,int numberOfFrames )
119 size_t pixelNumber = xSize * ySize;
120 size_t rawSize = xSize * ySize * numberOfFrames;
122 // We assumed Raw contains the decoded RLE pixels but as
123 // 8 bits per pixel. In order to convert those pixels to 16 bits
124 // per pixel we cannot work in place within Raw and hence
125 // we copy it in a safe place, say copyRaw.
127 uint8_t* copyRaw = new uint8_t[rawSize * 2];
128 memmove( copyRaw, raw, rawSize * 2 );
131 uint8_t* a = copyRaw;
132 uint8_t* b = a + pixelNumber;
134 for ( int i = 0; i < numberOfFrames; i++ )
136 for ( unsigned int j = 0; j < pixelNumber; j++ )
145 /// \todo check that operator new []didn't fail, and sometimes return false
150 } // end namespace gdcm