1 /*=========================================================================
4 Module: $RCSfile: gdcmRLEFramesInfo.cxx,v $
6 Date: $Date: 2005/06/17 12:27:52 $
7 Version: $Revision: 1.16 $
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 //-------------------------------------------------------------------------
26 // Constructor / Destructor
27 RLEFramesInfo::~RLEFramesInfo()
29 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
36 //-----------------------------------------------------------------------------
38 void RLEFramesInfo::AddFrame(RLEFrame *frame)
40 Frames.push_back(frame);
43 RLEFrame *RLEFramesInfo::GetFirstFrame()
45 ItFrames = Frames.begin();
46 if (ItFrames != Frames.end())
51 RLEFrame *RLEFramesInfo::GetNextFrame()
53 gdcmAssertMacro (ItFrames != Frames.end());
56 if (ItFrames != Frames.end())
62 * \brief Reads from disk the Pixel Data of 'Run Length Encoded'
63 * Dicom encapsulated file and decompress it.
64 * @param fp already open File Pointer
65 * from which the pixel data should be read
70 * @param bitsAllocated Bits allocated
73 bool RLEFramesInfo::DecompressRLEFile( std::ifstream *fp , uint8_t *raw,
74 int xSize, int ySize, int zSize,
77 uint8_t *subRaw = raw;
78 long rawSegmentSize = xSize * ySize;
80 // Loop on the frame[s]
81 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
83 subRaw = (*it)->ReadAndDecompressRLEFrame( subRaw, rawSegmentSize, fp);
86 if ( bitsAllocated == 16 )
88 // Try to deal with RLE 16 Bits
89 ConvertRLE16BitsFromRLE8Bits( raw, xSize, ySize, zSize );
96 * \brief We assume Raw contains the decoded RLE pixels but as
97 * 8 bits per pixel. We convert those pixels to 16 bits
100 * @param xSize x Size
101 * @param ySize y Size
102 * @param numberOfFrames number of frames
103 * @return Boolean always true
105 bool RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits(uint8_t *raw, int xSize,
106 int ySize, int numberOfFrames)
108 size_t pixelNumber = xSize * ySize;
109 size_t rawSize = pixelNumber * numberOfFrames * 2;
111 // We assumed Raw contains the decoded RLE pixels but as
112 // 8 bits per pixel. In order to convert those pixels to 16 bits
113 // per pixel we cannot work in place within Raw and hence
114 // we copy it in a safe place, say copyRaw.
116 uint8_t *copyRaw = new uint8_t[rawSize];
117 memmove( copyRaw, raw, rawSize );
123 // Warning : unckecked patch to see the behaviour on Big Endian Processors
125 if ( !Util::IsCurrentProcessorBigEndian() )
127 a = copyRaw; // begining of 'low bytes'
128 b = a + pixelNumber; // begining of 'hight bytes'
132 b = copyRaw; // begining of 'low bytes'
133 a = b + pixelNumber; // begining of 'hight bytes'
137 for ( int i = 0; i < numberOfFrames; i++ )
139 for ( unsigned int j = 0; j < pixelNumber; j++ )
152 //-----------------------------------------------------------------------------
155 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
162 * @param indent Indentation string to be prepended during printing.
163 * @param os Stream to print to.
165 void RLEFramesInfo::Print( std::ostream &os, std::string indent )
169 << "----------------- RLE frames --------------------------------"
172 << "Total number of Frames : " << Frames.size()
175 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
178 << " frame number :" << frameNumber++
180 (*it)->Print( os, indent + " " );
184 //-----------------------------------------------------------------------------
185 } // end namespace gdcm