00001 /*========================================================================= 00002 00003 Program: gdcm 00004 Module: $RCSfile: gdcmJPEGFragmentsInfo.cxx,v $ 00005 Language: C++ 00006 Date: $Date: 2007/05/23 14:18:10 $ 00007 Version: $Revision: 1.21 $ 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 "gdcmJPEGFragmentsInfo.h" 00020 #include "gdcmDebug.h" 00021 00022 #include <fstream> 00023 00024 namespace GDCM_NAME_SPACE 00025 { 00026 //------------------------------------------------------------------------- 00027 // Constructor / Destructor 00028 JPEGFragmentsInfo::JPEGFragmentsInfo() 00029 { 00030 StateSuspension = 0; 00031 } 00032 00036 JPEGFragmentsInfo::~JPEGFragmentsInfo() 00037 { 00038 for(JPEGFragmentsList::iterator it = Fragments.begin(); 00039 it != Fragments.end(); 00040 ++it ) 00041 { 00042 delete *it; 00043 } 00044 Fragments.clear(); 00045 } 00046 00047 //----------------------------------------------------------------------------- 00048 // Public 00049 void JPEGFragmentsInfo::DecompressFromFile(std::ifstream *fp, uint8_t *buffer, int nBits, int , int ) 00050 { 00051 // Pointer to the Raw image 00052 uint8_t *localRaw = buffer; 00053 00054 // Loop on the fragment[s] 00055 JPEGFragmentsList::const_iterator it; 00056 for( it = Fragments.begin(); 00057 it != Fragments.end(); 00058 ++it ) 00059 { 00060 (*it)->DecompressJPEGFramesFromFile(fp, localRaw, nBits, StateSuspension); 00061 // update pointer to image after some scanlines read: 00062 localRaw = (*it)->GetImage(); 00063 } 00064 } 00065 00066 void JPEGFragmentsInfo::AddFragment(JPEGFragment *fragment) 00067 { 00068 Fragments.push_back(fragment); 00069 } 00070 00071 JPEGFragment *JPEGFragmentsInfo::GetFirstFragment() 00072 { 00073 ItFragments = Fragments.begin(); 00074 if (ItFragments != Fragments.end()) 00075 return *ItFragments; 00076 return NULL; 00077 } 00078 00079 JPEGFragment *JPEGFragmentsInfo::GetNextFragment() 00080 { 00081 gdcmAssertMacro (ItFragments != Fragments.end()); 00082 00083 ++ItFragments; 00084 if (ItFragments != Fragments.end()) 00085 return *ItFragments; 00086 return NULL; 00087 } 00088 00089 unsigned int JPEGFragmentsInfo::GetFragmentCount() 00090 { 00091 return Fragments.size(); 00092 } 00093 00094 //----------------------------------------------------------------------------- 00095 // Protected 00096 00097 //----------------------------------------------------------------------------- 00098 // Private 00099 00100 //----------------------------------------------------------------------------- 00101 // Print 00107 void JPEGFragmentsInfo::Print( std::ostream &os, std::string const &indent ) 00108 { 00109 os << std::endl; 00110 os << indent 00111 << "----------------- JPEG fragments --------------------------------" 00112 << std::endl << std::endl; 00113 os << indent 00114 << "Total number of fragments : " << Fragments.size() 00115 << std::endl; 00116 int fragmentNumber = 0; 00117 for(JPEGFragmentsList::iterator it = Fragments.begin(); 00118 it != Fragments.end(); 00119 ++it) 00120 { 00121 os << indent 00122 << " fragment number :" << fragmentNumber++; 00123 (*it)->Print( os, indent + " "); 00124 } 00125 os << std::endl; 00126 } 00127 00128 //----------------------------------------------------------------------------- 00129 } // end namespace gdcm