Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gdcmRLEFramesInfo.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmRLEFramesInfo.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2005/02/02 10:16:02 $
00007   Version:   $Revision: 1.14 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #include "gdcmRLEFramesInfo.h"
00020 #include "gdcmDebug.h"
00021 
00022 namespace gdcm 
00023 {
00024 //-------------------------------------------------------------------------
00025 // Constructor / Destructor
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 // Public
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    // Loop on the frame[s]
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       // Try to deal with RLE 16 Bits
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    // We assumed Raw contains the decoded RLE pixels but as
00111    // 8 bits per pixel. In order to convert those pixels to 16 bits
00112    // per pixel we cannot work in place within Raw and hence
00113    // we copy it in a safe place, say copyRaw.
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 // Protected
00139 
00140 //-----------------------------------------------------------------------------
00141 // Private
00142 
00143 //-----------------------------------------------------------------------------
00144 // Print
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 } // end namespace gdcm

Generated on Thu Feb 10 22:18:00 2005 for gdcm by doxygen 1.3.6