1 /*=========================================================================
4 Module: $RCSfile: gdcmRLEFramesInfo.cxx,v $
6 Date: $Date: 2007/05/23 14:18:11 $
7 Version: $Revision: 1.22 $
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"
23 #if defined(__BORLANDC__)
24 #include <mem.h> // for memset
27 namespace GDCM_NAME_SPACE
29 //-------------------------------------------------------------------------
30 // Constructor / Destructor
31 RLEFramesInfo::~RLEFramesInfo()
33 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
40 //-----------------------------------------------------------------------------
42 void RLEFramesInfo::AddFrame(RLEFrame *frame)
44 Frames.push_back(frame);
47 RLEFrame *RLEFramesInfo::GetFirstFrame()
49 ItFrames = Frames.begin();
50 if (ItFrames != Frames.end())
55 RLEFrame *RLEFramesInfo::GetNextFrame()
57 gdcmAssertMacro (ItFrames != Frames.end());
60 if (ItFrames != Frames.end())
66 * \brief Reads from disk the Pixel Data of 'Run Length Encoded'
67 * Dicom encapsulated file and decompress it.
68 * @param fp already open File Pointer
69 * from which the pixel data should be read
75 * @param bitsAllocated Bits allocated
78 bool RLEFramesInfo::DecompressRLEFile( std::ifstream *fp , uint8_t *raw,
79 int xSize, int ySize, int zSize,
80 int tSize, int bitsAllocated )
82 uint8_t *subRaw = raw;
83 long rawSegmentSize = xSize * ySize * tSize;
85 // Loop on the frame[s]
86 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
88 subRaw = (*it)->ReadAndDecompressRLEFrame( subRaw, rawSegmentSize, fp);
91 if ( bitsAllocated == 16 )
93 // Try to deal with RLE 16 Bits
94 ConvertRLE16BitsFromRLE8Bits( raw, xSize, ySize, zSize, tSize );
101 * \brief We assume Raw contains the decoded RLE pixels but as
102 * 8 bits per pixel. We convert those pixels to 16 bits
105 * @param xSize x Size
106 * @param ySize y Size
107 * @param tSize t Size
108 * @param numberOfFrames number of frames
109 * @return Boolean always true
111 bool RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits(uint8_t *raw, int xSize,
112 int ySize, int tSize,
115 size_t pixelNumber = xSize * ySize * tSize;
116 size_t rawSize = pixelNumber * numberOfFrames * 2;
118 // We assumed Raw contains the decoded RLE pixels but as
119 // 8 bits per pixel. In order to convert those pixels to 16 bits
120 // per pixel we cannot work in place within Raw and hence
121 // we copy it in a safe place, say copyRaw.
123 uint8_t *copyRaw = new uint8_t[rawSize];
124 memmove( copyRaw, raw, rawSize );
130 // Warning : unckecked patch to see the behaviour on Big Endian Processors
132 if ( !Util::IsCurrentProcessorBigEndian() )
134 a = copyRaw; // beginning of 'low bytes'
135 b = a + pixelNumber; // beginning of 'hight bytes'
139 b = copyRaw; // beginning of 'low bytes'
140 a = b + pixelNumber; // beginning of 'hight bytes'
144 for ( int i = 0; i < numberOfFrames; i++ )
146 for ( unsigned int j = 0; j < pixelNumber; j++ )
158 //-----------------------------------------------------------------------------
161 //-----------------------------------------------------------------------------
164 //-----------------------------------------------------------------------------
168 * @param indent Indentation string to be prepended during printing.
169 * @param os Stream to print to.
171 void RLEFramesInfo::Print( std::ostream &os, std::string indent )
175 << "----------------- RLE frames --------------------------------"
178 << "Total number of Frames : " << Frames.size()
181 /// \todo : find an example, to know haow 3rd and 4th dimension
183 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
186 << " frame number :" << frameNumber++
188 (*it)->Print( os, indent + " " );
192 //-----------------------------------------------------------------------------
193 } // end namespace gdcm