00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "gdcmRLEFramesInfo.h"
00020 #include "gdcmDebug.h"
00021
00022 namespace gdcm
00023 {
00024
00025
00026 RLEFramesInfo::~RLEFramesInfo()
00027 {
00028 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00029 {
00030 delete (*it);
00031 }
00032 Frames.clear();
00033 }
00034
00035
00036
00037 void RLEFramesInfo::AddFrame(RLEFrame *frame)
00038 {
00039 Frames.push_back(frame);
00040 }
00041
00042 RLEFrame *RLEFramesInfo::GetFirstFrame()
00043 {
00044 ItFrames = Frames.begin();
00045 if (ItFrames != Frames.end())
00046 return *ItFrames;
00047 return NULL;
00048 }
00049
00050 RLEFrame *RLEFramesInfo::GetNextFrame()
00051 {
00052 gdcmAssertMacro (ItFrames != Frames.end());
00053
00054 ++ItFrames;
00055 if (ItFrames != Frames.end())
00056 return *ItFrames;
00057 return NULL;
00058 }
00059
00072 bool RLEFramesInfo::DecompressRLEFile( std::ifstream *fp , uint8_t *raw,
00073 int xSize, int ySize, int zSize,
00074 int bitsAllocated )
00075 {
00076 uint8_t *subRaw = raw;
00077 long rawSegmentSize = xSize * ySize;
00078
00079
00080 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00081 {
00082 subRaw = (*it)->ReadAndDecompressRLEFrame( subRaw, rawSegmentSize, fp);
00083 }
00084
00085 if ( bitsAllocated == 16 )
00086 {
00087
00088 ConvertRLE16BitsFromRLE8Bits( raw, xSize, ySize, zSize );
00089 }
00090
00091 return true;
00092 }
00093
00104 bool RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits(uint8_t *raw, int xSize,
00105 int ySize, int numberOfFrames)
00106 {
00107 size_t pixelNumber = xSize * ySize;
00108 size_t rawSize = xSize * ySize * numberOfFrames;
00109
00110
00111
00112
00113
00114
00115 uint8_t *copyRaw = new uint8_t[rawSize * 2];
00116 memmove( copyRaw, raw, rawSize * 2 );
00117
00118 uint8_t *x = raw;
00119 uint8_t *a = copyRaw;
00120 uint8_t *b = a + pixelNumber;
00121
00122 for ( int i = 0; i < numberOfFrames; i++ )
00123 {
00124 for ( unsigned int j = 0; j < pixelNumber; j++ )
00125 {
00126 *(x++) = *(b++);
00127 *(x++) = *(a++);
00128 }
00129 }
00130 delete[] copyRaw;
00131
00133
00134 return true;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143
00144
00150 void RLEFramesInfo::Print( std::ostream &os, std::string indent )
00151 {
00152 os << std::endl;
00153 os << indent
00154 << "----------------- RLE frames --------------------------------"
00155 << std::endl;
00156 os << indent
00157 << "Total number of Frames : " << Frames.size()
00158 << std::endl;
00159 int frameNumber = 0;
00160 for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00161 {
00162 os << indent
00163 << " frame number :" << frameNumber++
00164 << std::endl;
00165 (*it)->Print( os, indent + " " );
00166 }
00167 }
00168
00169
00170 }