Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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/11/28 16:50:33 $
00007   Version:   $Revision: 1.19 $
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 namespace gdcm 
00024 {
00025 //-------------------------------------------------------------------------
00026 // Constructor / Destructor
00027 RLEFramesInfo::~RLEFramesInfo()
00028 {
00029    for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00030    {
00031       delete (*it);
00032    }
00033    Frames.clear();
00034 }
00035 
00036 //-----------------------------------------------------------------------------
00037 // Public
00038 void RLEFramesInfo::AddFrame(RLEFrame *frame)
00039 {
00040    Frames.push_back(frame);
00041 }
00042 
00043 RLEFrame *RLEFramesInfo::GetFirstFrame()
00044 {
00045    ItFrames = Frames.begin();
00046    if (ItFrames != Frames.end())
00047       return  *ItFrames;
00048    return NULL;
00049 }
00050 
00051 RLEFrame *RLEFramesInfo::GetNextFrame()
00052 {
00053    gdcmAssertMacro (ItFrames != Frames.end());
00054 
00055    ++ItFrames;
00056    if (ItFrames != Frames.end())
00057       return  *ItFrames;
00058    return NULL;
00059 }
00060 
00073 bool RLEFramesInfo::DecompressRLEFile( std::ifstream *fp , uint8_t *raw, 
00074                                        int xSize, int ySize, int zSize, 
00075                                        int bitsAllocated )
00076 {
00077    uint8_t *subRaw = raw;
00078    long rawSegmentSize = xSize * ySize;
00079 
00080    // Loop on the frame[s]
00081    for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00082    {
00083       subRaw = (*it)->ReadAndDecompressRLEFrame( subRaw, rawSegmentSize, fp);
00084    }
00085 
00086    if ( bitsAllocated == 16 )
00087    {
00088       // Try to deal with RLE 16 Bits
00089       ConvertRLE16BitsFromRLE8Bits( raw, xSize, ySize, zSize );
00090    }
00091 
00092    return true;
00093 }
00094 
00105 bool RLEFramesInfo::ConvertRLE16BitsFromRLE8Bits(uint8_t *raw, int xSize, 
00106                                                  int ySize, int numberOfFrames)
00107 {
00108    size_t pixelNumber = xSize * ySize;
00109    size_t rawSize     = pixelNumber * numberOfFrames * 2;
00110 
00111    // We assumed Raw contains the decoded RLE pixels but as
00112    // 8 bits per pixel. In order to convert those pixels to 16 bits
00113    // per pixel we cannot work in place within Raw and hence
00114    // we copy it in a safe place, say copyRaw.
00115 
00116    uint8_t *copyRaw = new uint8_t[rawSize];
00117    memmove( copyRaw, raw, rawSize );
00118 
00119    uint8_t *x = raw;
00120    uint8_t *a;
00121    uint8_t *b;
00122 
00123    // Warning : unckecked patch to see the behaviour on Big Endian Processors
00124 
00125    if ( !Util::IsCurrentProcessorBigEndian() )
00126    { 
00127       a = copyRaw;         // beginning of 'low bytes'
00128       b = a + pixelNumber; // beginning of 'hight bytes'
00129    }
00130    else
00131    {
00132       b = copyRaw;         // beginning of 'low bytes'
00133       a = b + pixelNumber; // beginning of 'hight bytes'
00134    } 
00135 
00136    // Re order bytes
00137    for ( int i = 0; i < numberOfFrames; i++ )
00138    {
00139       for ( unsigned int j = 0; j < pixelNumber; j++ )
00140       {
00141          *(x++) = *(b++);
00142          *(x++) = *(a++);
00143       }
00144    }
00145 
00146    delete[] copyRaw;
00147 
00148    return true;
00149 }
00150 
00151 //-----------------------------------------------------------------------------
00152 // Protected
00153 
00154 //-----------------------------------------------------------------------------
00155 // Private
00156 
00157 //-----------------------------------------------------------------------------
00158 // Print
00164 void RLEFramesInfo::Print( std::ostream &os, std::string indent )
00165 {
00166    os << std::endl;
00167    os << indent
00168       << "----------------- RLE frames --------------------------------"
00169       << std::endl;
00170    os << indent
00171       << "Total number of Frames : " << Frames.size()
00172       << std::endl;
00173    int frameNumber = 0;
00174    for(RLEFrameList::iterator it = Frames.begin(); it != Frames.end(); ++it)
00175    {
00176       os << indent
00177          << "   frame number :" << frameNumber++
00178          << std::endl;
00179       (*it)->Print( os, indent + "   " );
00180    }
00181 }
00182 
00183 //-----------------------------------------------------------------------------
00184 } // end namespace gdcm

Generated on Fri Jan 20 10:14:26 2006 for gdcm by  doxygen 1.4.4