1 /*=========================================================================
4 Module: $RCSfile: gdcmRLEFramesInfo.cxx,v $
6 Date: $Date: 2005/02/01 10:29:56 $
7 Version: $Revision: 1.11 $
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"
24 //-------------------------------------------------------------------------
25 // Constructor / Destructor
26 RLEFramesInfo::~RLEFramesInfo()
28 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
35 //-----------------------------------------------------------------------------
37 void RLEFramesInfo::AddFrame(RLEFrame *frame)
39 Frames.push_back(frame);
42 RLEFrame *RLEFramesInfo::GetFirstFrame()
44 ItFrames = Frames.begin();
45 if (ItFrames != Frames.end())
50 RLEFrame *RLEFramesInfo::GetNextFrame()
52 gdcmAssertMacro (ItFrames != Frames.end());
55 if (ItFrames != Frames.end())
61 * \brief Reads from disk the Pixel Data of 'Run Length Encoded'
62 * Dicom encapsulated file and decompress it.
63 * @param fp already open File Pointer
64 * at which the pixel data should be copied
67 bool RLEFramesInfo::DecompressRLEFile( std::ifstream *fp , uint8_t *raw, int xSize, int ySize, int zSize, int bitsAllocated )
69 uint8_t *subRaw = raw;
70 long rawSegmentSize = xSize * ySize;
72 // Loop on the frame[s]
73 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
75 subRaw = (*it)->ReadAndDecompressRLEFrame( subRaw, rawSegmentSize, fp);
78 if ( bitsAllocated == 16 )
80 // Try to deal with RLE 16 Bits
81 ConvertRLE16BitsFromRLE8Bits( raw, xSize, ySize, zSize );
88 * \brief Try to deal with RLE 16 Bits.
89 * We assume the RLE has already been parsed and loaded in
90 * Raw (through \ref ReadAndDecompressJPEGFile ).
91 * We here need to make 16 Bits Pixels from Low Byte and
92 * High Byte 'Planes'...(for what it may mean)
95 bool RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits( uint8_t* raw, int xSize,
96 int ySize,int numberOfFrames )
98 size_t pixelNumber = xSize * ySize;
99 size_t rawSize = xSize * ySize * numberOfFrames;
101 // We assumed Raw contains the decoded RLE pixels but as
102 // 8 bits per pixel. In order to convert those pixels to 16 bits
103 // per pixel we cannot work in place within Raw and hence
104 // we copy it in a safe place, say copyRaw.
106 uint8_t* copyRaw = new uint8_t[rawSize * 2];
107 memmove( copyRaw, raw, rawSize * 2 );
110 uint8_t* a = copyRaw;
111 uint8_t* b = a + pixelNumber;
113 for ( int i = 0; i < numberOfFrames; i++ )
115 for ( unsigned int j = 0; j < pixelNumber; j++ )
124 /// \todo check that operator new []didn't fail, and sometimes return false
128 //-----------------------------------------------------------------------------
131 //-----------------------------------------------------------------------------
134 //-----------------------------------------------------------------------------
138 * @param indent Indentation string to be prepended during printing.
139 * @param os Stream to print to.
141 void RLEFramesInfo::Print( std::ostream &os, std::string indent )
145 << "----------------- RLE frames --------------------------------"
148 << "Total number of Frames : " << Frames.size()
151 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
154 << " frame number :" << frameNumber++
156 (*it)->Print( os, indent + " " );
160 //-----------------------------------------------------------------------------
161 } // end namespace gdcm