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 #include "gdcmUtil.h"
00022 
00023 #if defined(__BORLANDC__)
00024    #include <mem.h> 
00025 #endif 
00026 
00027 namespace GDCM_NAME_SPACE 
00028 {
00029 
00030 
00031 RLEFramesInfo::~RLEFramesInfo()
00032 {
00033    for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00034    {
00035       delete (*it);
00036    }
00037    Frames.clear();
00038 }
00039 
00040 
00041 
00042 void RLEFramesInfo::AddFrame(RLEFrame *frame)
00043 {
00044    Frames.push_back(frame);
00045 }
00046 
00047 RLEFrame *RLEFramesInfo::GetFirstFrame()
00048 {
00049    ItFrames = Frames.begin();
00050    if (ItFrames != Frames.end())
00051       return  *ItFrames;
00052    return NULL;
00053 }
00054 
00055 RLEFrame *RLEFramesInfo::GetNextFrame()
00056 {
00057    gdcmAssertMacro (ItFrames != Frames.end());
00058 
00059    ++ItFrames;
00060    if (ItFrames != Frames.end())
00061       return  *ItFrames;
00062    return NULL;
00063 }
00064 
00078 bool RLEFramesInfo::DecompressRLEFile( std::ifstream *fp , uint8_t *raw, 
00079                                        int xSize, int ySize, int zSize, 
00080                                        int tSize, int bitsAllocated )
00081 {
00082    uint8_t *subRaw = raw;
00083    long rawSegmentSize = xSize * ySize * tSize;
00084 
00085    
00086    for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00087    {
00088       subRaw = (*it)->ReadAndDecompressRLEFrame( subRaw, rawSegmentSize, fp);
00089    }
00090 
00091    if ( bitsAllocated == 16 )
00092    {
00093       
00094       ConvertRLE16BitsFromRLE8Bits( raw, xSize, ySize, zSize, tSize );
00095    }
00096 
00097    return true;
00098 }
00099 
00111 bool RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits(uint8_t *raw, int xSize, 
00112                                                  int ySize, int tSize,
00113                                                  int numberOfFrames)
00114 {
00115    size_t pixelNumber = xSize * ySize * tSize;
00116    size_t rawSize     = pixelNumber * numberOfFrames * 2;
00117 
00118    
00119    
00120    
00121    
00122 
00123    uint8_t *copyRaw = new uint8_t[rawSize];
00124    memmove( copyRaw, raw, rawSize );
00125 
00126    uint8_t *x = raw;
00127    uint8_t *a;
00128    uint8_t *b;
00129 
00130    
00131 
00132    if ( !Util::IsCurrentProcessorBigEndian() )
00133    { 
00134       a = copyRaw;         
00135       b = a + pixelNumber; 
00136    }
00137    else
00138    {
00139       b = copyRaw;         
00140       a = b + pixelNumber; 
00141    } 
00142 
00143    
00144    for ( int i = 0; i < numberOfFrames; i++ )
00145    {
00146       for ( unsigned int j = 0; j < pixelNumber; j++ )
00147       {
00148          *(x++) = *(b++);
00149          *(x++) = *(a++);
00150       }
00151    }
00152 
00153    delete[] copyRaw;
00154 
00155    return true;
00156 }
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00171 void RLEFramesInfo::Print( std::ostream &os, std::string indent )
00172 {
00173    os << std::endl;
00174    os << indent
00175       << "----------------- RLE frames --------------------------------"
00176       << std::endl;
00177    os << indent
00178       << "Total number of Frames : " << Frames.size()
00179       << std::endl;
00180    int frameNumber = 0;
00183    for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00184    {
00185       os << indent
00186          << "   frame number :" << frameNumber++
00187          << std::endl;
00188       (*it)->Print( os, indent + "   " );
00189    }
00190 }
00191 
00192 
00193 }