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: 2007/05/23 14:18:11 $
00007   Version:   $Revision: 1.22 $
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 #include "gdcmUtil.h"
00022 
00023 #if defined(__BORLANDC__)
00024    #include <mem.h> // for memset
00025 #endif 
00026 
00027 namespace GDCM_NAME_SPACE 
00028 {
00029 //-------------------------------------------------------------------------
00030 // Constructor / Destructor
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 // Public
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    // Loop on the frame[s]
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       // Try to deal with RLE 16 Bits
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    // We assumed Raw contains the decoded RLE pixels but as
00119    // 8 bits per pixel. In order to convert those pixels to 16 bits
00120    // per pixel we cannot work in place within Raw and hence
00121    // we copy it in a safe place, say copyRaw.
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    // Warning : unckecked patch to see the behaviour on Big Endian Processors
00131 
00132    if ( !Util::IsCurrentProcessorBigEndian() )
00133    { 
00134       a = copyRaw;         // beginning of 'low bytes'
00135       b = a + pixelNumber; // beginning of 'hight bytes'
00136    }
00137    else
00138    {
00139       b = copyRaw;         // beginning of 'low bytes'
00140       a = b + pixelNumber; // beginning of 'hight bytes'
00141    } 
00142 
00143    // Re order bytes
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 // Protected
00160 
00161 //-----------------------------------------------------------------------------
00162 // Private
00163 
00164 //-----------------------------------------------------------------------------
00165 // Print
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 } // end namespace gdcm

Generated on Fri Aug 24 12:59:31 2007 for gdcm by  doxygen 1.4.6