1 /*=========================================================================
4 Module: $RCSfile: gdcmRLEFramesInfo.cxx,v $
6 Date: $Date: 2006/01/27 10:01:34 $
7 Version: $Revision: 1.20 $
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
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
74 * @param bitsAllocated Bits allocated
77 bool RLEFramesInfo::DecompressRLEFile( std::ifstream *fp , uint8_t *raw,
78 int xSize, int ySize, int zSize,
81 uint8_t *subRaw = raw;
82 long rawSegmentSize = xSize * ySize;
84 // Loop on the frame[s]
85 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
87 subRaw = (*it)->ReadAndDecompressRLEFrame( subRaw, rawSegmentSize, fp);
90 if ( bitsAllocated == 16 )
92 // Try to deal with RLE 16 Bits
93 ConvertRLE16BitsFromRLE8Bits( raw, xSize, ySize, zSize );
100 * \brief We assume Raw contains the decoded RLE pixels but as
101 * 8 bits per pixel. We convert those pixels to 16 bits
104 * @param xSize x Size
105 * @param ySize y Size
106 * @param numberOfFrames number of frames
107 * @return Boolean always true
109 bool RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits(uint8_t *raw, int xSize,
110 int ySize, int numberOfFrames)
112 size_t pixelNumber = xSize * ySize;
113 size_t rawSize = pixelNumber * numberOfFrames * 2;
115 // We assumed Raw contains the decoded RLE pixels but as
116 // 8 bits per pixel. In order to convert those pixels to 16 bits
117 // per pixel we cannot work in place within Raw and hence
118 // we copy it in a safe place, say copyRaw.
120 uint8_t *copyRaw = new uint8_t[rawSize];
121 memmove( copyRaw, raw, rawSize );
127 // Warning : unckecked patch to see the behaviour on Big Endian Processors
129 if ( !Util::IsCurrentProcessorBigEndian() )
131 a = copyRaw; // beginning of 'low bytes'
132 b = a + pixelNumber; // beginning of 'hight bytes'
136 b = copyRaw; // beginning of 'low bytes'
137 a = b + pixelNumber; // beginning of 'hight bytes'
141 for ( int i = 0; i < numberOfFrames; i++ )
143 for ( unsigned int j = 0; j < pixelNumber; j++ )
155 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
161 //-----------------------------------------------------------------------------
165 * @param indent Indentation string to be prepended during printing.
166 * @param os Stream to print to.
168 void RLEFramesInfo::Print( std::ostream &os, std::string indent )
172 << "----------------- RLE frames --------------------------------"
175 << "Total number of Frames : " << Frames.size()
178 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
181 << " frame number :" << frameNumber++
183 (*it)->Print( os, indent + " " );
187 //-----------------------------------------------------------------------------
188 } // end namespace gdcm