+2004-10-21 Mathieu Malaterre <Mathieu.Malaterre@creatis.insa-lyon.fr>
+ * Removed all FILE* ref and replace by ifstream/ofstream. For now I use a temp
+ solution with the two files jdatadst.cxx and jdatasrc.cxx, this need to be
+ discussed (plus I didn't like having a 2000 lines patch not commited)
+
2004-10-21 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
* src/gdcmDocument.cxx: wrong type on return fixed (thanks dashboard)
* CLEANUP_ROUND (14) for gdcmPixelConvert
Program: gdcm
Module: $RCSfile: gdcmBinEntry.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:44 $
- Version: $Revision: 1.33 $
+ Date: $Date: 2004/10/22 03:05:40 $
+ Version: $Revision: 1.34 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmBinEntry.h"
#include "gdcmDebug.h"
+#include <fstream>
namespace gdcm
{
* @param fp already open file pointer
* @param filetype type of the file to be written
*/
-void BinEntry::Write(FILE* fp, FileType filetype)
+void BinEntry::Write(std::ofstream* fp, FileType filetype)
{
DocEntry::Write(fp, filetype);
void* binArea = GetBinArea();
if (binArea)
{
// there is a 'non string' LUT, overlay, etc
- fwrite ( binArea,(size_t)lgr ,(size_t)1 ,fp); // Elem value
+ fp->write ( (char*)binArea, lgr ); // Elem value
+
}
else
{
// nothing was loaded, but we need to skip space on disc
- fseek(fp,(size_t)lgr,SEEK_CUR);
+ fp->seekp(lgr, std::ios_base::cur);
}
}
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmBinEntry.h,v $
Language: C++
- Date: $Date: 2004/10/18 12:49:22 $
- Version: $Revision: 1.23 $
+ Date: $Date: 2004/10/22 03:05:40 $
+ Version: $Revision: 1.24 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
~BinEntry();
void Print( std::ostream &os = std::cout );
- void Write( FILE*, FileType );
+ void Write( std::ofstream*, FileType );
/// \brief Returns the area value of the current Dicom Header Entry
/// when it's not string-translatable (e.g : a LUT table)
Program: gdcm
Module: $RCSfile: gdcmDicomDir.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:44 $
- Version: $Revision: 1.73 $
+ Date: $Date: 2004/10/22 03:05:40 $
+ Version: $Revision: 1.74 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmSQItem.h"
#include "gdcmValEntry.h"
+#include <fstream>
#include <string>
#include <algorithm>
#include <sys/types.h>
uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
- FILE* fp = fopen(fileName.c_str(), "wb");
+ std::ofstream* fp = new std::ofstream(fileName.c_str(),
+ std::ios::out | std::ios::binary);
if( !fp )
{
printf("Failed to open(write) File [%s] \n", fileName.c_str());
uint8_t filePreamble[128];
memset(filePreamble, 0, 128);
- fwrite(filePreamble,128,1,fp);
- fwrite("DICM",4,1,fp);
+ fp->write((char*)filePreamble, 128);
+ fp->write("DICM",4);
DicomDirMeta *ptrMeta = GetDicomDirMeta();
ptrMeta->Write(fp, ExplicitVR);
// force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
- fwrite(&sq[0],8,1,fp); // 0004 1220 ffff ffff
+ fp->write((char*)&sq[0],8);
for(ListDicomDirPatient::iterator cc = Patients.begin();
cc != Patients.end();
}
// force writing Sequence Delimitation Item
- fwrite(&sqt[0],8,1,fp); // fffe e0dd ffff ffff
+ fp->write((char*)&sqt[0],8); // fffe e0dd ffff ffff
- fclose( fp );
+ fp->close();
return true;
}
Program: gdcm
Module: $RCSfile: gdcmDicomDirMeta.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:44 $
- Version: $Revision: 1.12 $
+ Date: $Date: 2004/10/22 03:05:40 $
+ Version: $Revision: 1.13 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* \brief Writes the Meta Elements
* @return
*/
-void DicomDirMeta::Write(FILE* fp, FileType t)
+void DicomDirMeta::Write(std::ofstream* fp, FileType t)
{
for (ListDocEntry::iterator i = docEntries.begin();
i != docEntries.end();
Program: gdcm
Module: $RCSfile: gdcmDicomDirMeta.h,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:44 $
- Version: $Revision: 1.9 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.10 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
~DicomDirMeta();
virtual void Print(std::ostream &os = std::cout);
- virtual void Write(FILE * fp, FileType t);
+ virtual void Write(std::ofstream * fp, FileType t);
};
} // end namespace gdcm
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmDicomDirPatient.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:45 $
- Version: $Revision: 1.15 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.16 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* \brief Writes the Object
* @return
*/
-void DicomDirPatient::Write(FILE* fp, FileType t)
+void DicomDirPatient::Write(std::ofstream* fp, FileType t)
{
DicomDirObject::Write(fp, t);
Program: gdcm
Module: $RCSfile: gdcmDicomDirPatient.h,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:45 $
- Version: $Revision: 1.10 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.11 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
~DicomDirPatient();
virtual void Print(std::ostream &os = std::cout);
- virtual void Write(FILE *fp, FileType t);
+ virtual void Write(std::ofstream *fp, FileType t);
/// Returns the STUDY chained List for this PATIENT.
ListDicomDirStudy &GetDicomDirStudies() { return studies; };
Program: gdcm
Module: $RCSfile: gdcmDicomDirSerie.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:45 $
- Version: $Revision: 1.17 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.18 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* \brief Writes the Object
* @return
*/
-void DicomDirSerie::Write(FILE* fp, FileType t)
+void DicomDirSerie::Write(std::ofstream* fp, FileType t)
{
DicomDirObject::Write(fp, t);
Program: gdcm
Module: $RCSfile: gdcmDicomDirSerie.h,v $
Language: C++
- Date: $Date: 2004/10/13 14:15:29 $
- Version: $Revision: 1.11 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.12 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
~DicomDirSerie();
virtual void Print( std::ostream& os = std::cout );
- virtual void Write( FILE* fp, FileType t );
+ virtual void Write( std::ofstream* fp, FileType t );
/**
* \ingroup DicomDirSerie
* \brief returns the IMAGE chained List for this SERIE.
Program: gdcm
Module: $RCSfile: gdcmDicomDirStudy.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:45 $
- Version: $Revision: 1.14 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.15 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* \brief Writes the Object
* @return
*/
-void DicomDirStudy::Write(FILE* fp, FileType t)
+void DicomDirStudy::Write(std::ofstream* fp, FileType t)
{
DicomDirObject::Write(fp, t);
Program: gdcm
Module: $RCSfile: gdcmDicomDirStudy.h,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:45 $
- Version: $Revision: 1.10 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.11 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
~DicomDirStudy();
virtual void Print(std::ostream &os = std::cout);
- virtual void Write(FILE *fp, FileType t);
+ virtual void Write(std::ofstream *fp, FileType t);
/**
* \ingroup DicomDirStudy
* \brief returns the SERIE chained List for this STUDY.
Program: gdcm
Module: $RCSfile: gdcmDocEntry.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:45 $
- Version: $Revision: 1.27 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.28 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmUtil.h"
#include <iomanip> // for std::ios::left, ...
+#include <fstream>
+
namespace gdcm
{
* @param fp already open file pointer
* @param filetype type of the file to be written
*/
-void DocEntry::Write(FILE* fp, FileType filetype)
+void DocEntry::Write(std::ofstream* fp, FileType filetype)
{
uint32_t ffff = 0xffffffff;
uint16_t group = GetGroup();
//
// ----------- Writes the common part
//
- fwrite ( &group,(size_t)2 ,(size_t)1 ,fp); //group
- fwrite ( &el, (size_t)2 ,(size_t)1 ,fp); //element
+ fp->write ((char*) &group,(size_t)2 ); //group
+ fp->write ( (char*)&el, (size_t)2 ); //element
if ( filetype == ExplicitVR )
{
// TODO : verify if the Sequence Delimitor Item was forced during Parsing
int ff = 0xffffffff;
- fwrite (&ff,(size_t)4 ,(size_t)1 ,fp);
+ fp->write ((char*)&ff,(size_t)4 );
return;
}
{
// Unknown was 'written'
// deal with Little Endian
- fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
- fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
+ fp->write ( (char*)&shortLgr,(size_t)2 );
+ fp->write ( (char*)&z, (size_t)2 );
}
else
{
- fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,fp);
+ fp->write (vr.c_str(),(size_t)2 );
+
if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
{
- fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
+ fp->write ( (char*)&z, (size_t)2 );
if (vr == "SQ")
{
// we set SQ length to ffffffff
// and we shall write a Sequence Delimitor Item
// at the end of the Sequence!
- fwrite ( &ffff,(size_t)4 ,(size_t)1 ,fp);
+ fp->write ( (char*)&ffff,(size_t)4 );
}
else
{
- fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
+ fp->write ( (char*)&lgr,(size_t)4 );
}
}
else
{
- fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
+ fp->write ( (char*)&shortLgr,(size_t)2 );
}
}
}
{
if (vr == "SQ")
{
- fwrite ( &ffff,(size_t)4 ,(size_t)1 ,fp);
+ fp->write ( (char*)&ffff,(size_t)4 );
}
else
{
- fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
+ fp->write ( (char*)&lgr,(size_t)4 );
}
}
}
Program: gdcm
Module: $RCSfile: gdcmDocEntry.h,v $
Language: C++
- Date: $Date: 2004/10/13 14:15:29 $
- Version: $Revision: 1.26 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.27 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
int GetPrintLevel() { return PrintLevel; };
virtual void Print (std::ostream & os = std::cout);
- virtual void Write(FILE *fp, FileType filetype);
+ virtual void Write(std::ofstream *fp, FileType filetype);
uint32_t GetFullLength();
Program: gdcm
Module: $RCSfile: gdcmDocEntrySet.h,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:45 $
- Version: $Revision: 1.20 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.21 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
virtual void Print (std::ostream & os = std::cout) = 0;// pure virtual
/// \brief write any type of entry to the entry set
- virtual void Write (FILE *fp, FileType filetype) = 0;// pure virtual
+ virtual void Write (std::ofstream *fp, FileType filetype) = 0;// pure virtual
virtual DocEntry* GetDocEntryByNumber(uint16_t group,
uint16_t element) = 0;
Program: gdcm
Module: $RCSfile: gdcmDocument.cxx,v $
Language: C++
- Date: $Date: 2004/10/20 22:31:52 $
- Version: $Revision: 1.107 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.108 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmDebug.h"
#include <vector>
+#include <iomanip>
// For nthos:
#ifdef _MSC_VER
#include <netinet/in.h>
#endif
-#include <iomanip>
-
namespace gdcm
{
dbg.Verbose(0, "Document::Document: starting parsing of file: ",
Filename.c_str());
- rewind(Fp);
+ Fp->seekg( 0, std::ios_base::beg);
- fseek(Fp,0L,SEEK_END);
- long lgt = ftell(Fp);
+ Fp->seekg(0, std::ios_base::end);
+ long lgt = Fp->tellg();
- rewind(Fp);
+ Fp->seekg( 0, std::ios_base::beg);
CheckSwap();
- long beg = ftell(Fp);
+ long beg = Fp->tellg();
lgt -= beg;
ParseDES( this, beg, lgt, false); // le Load sera fait a la volee
- rewind(Fp);
+ Fp->seekg( 0, std::ios_base::beg);
// Load 'non string' values
* checks the preamble when existing.
* @return The FILE pointer on success.
*/
-FILE* Document::OpenFile()
+std::ifstream* Document::OpenFile()
{
- Fp = fopen(Filename.c_str(),"rb");
+ Fp = new std::ifstream(Filename.c_str(), std::ios::in | std::ios::binary);
if(!Fp)
{
}
uint16_t zero;
- fread(&zero, (size_t)2, (size_t)1, Fp);
+ Fp->read((char*)&zero, (size_t)2 );
//ACR -- or DICOM with no Preamble --
if( zero == 0x0008 || zero == 0x0800 || zero == 0x0002 || zero == 0x0200 )
}
//DICOM
- fseek(Fp, 126L, SEEK_CUR);
+ Fp->seekg(126L, std::ios_base::cur);
char dicm[4];
- fread(dicm, (size_t)4, (size_t)1, Fp);
+ Fp->read(dicm, (size_t)4);
if( memcmp(dicm, "DICM", 4) == 0 )
{
return Fp;
}
- fclose(Fp);
+ Fp->close();
dbg.Verbose( 0,
"Document::OpenFile not DICOM/ACR (missing preamble)",
Filename.c_str());
*/
bool Document::CloseFile()
{
- int closed = fclose(Fp);
+ Fp->close();
+ delete Fp;
Fp = 0;
- if ( ! closed )
- {
- return false;
- }
- else
- {
- return true;
- }
+ return true; //FIXME how do we detect a non-close ifstream ?
}
/**
* (ACR-NEMA, ExplicitVR, ImplicitVR)
* \return Always true.
*/
-void Document::Write(FILE* fp,FileType filetype)
+void Document::Write(std::ofstream* fp, FileType filetype)
{
/// \todo move the following lines (and a lot of others, to be written)
/// to a future function CheckAndCorrectHeader
* @param element element number of the Dicom Element to modify
*/
bool Document::SetEntryByNumber(uint8_t*content,
- int lgth,
- uint16_t group,
- uint16_t element)
+ int lgth,
+ uint16_t group,
+ uint16_t element)
{
(void)lgth; //not used
TagKey key = DictEntry::TranslateToKey(group, element);
* @return true on success, false otherwise.
*/
bool Document::SetEntryLengthByNumber(uint32_t l,
- uint16_t group,
- uint16_t element)
+ uint16_t group,
+ uint16_t element)
{
/// \todo use map methods, instead of multimap JPR
TagKey key = DictEntry::TranslateToKey(group, element);
return NULL;
}
size_t o =(size_t)docElement->GetOffset();
- fseek(Fp, o, SEEK_SET);
+ Fp->seekg( o, std::ios_base::beg);
size_t l = docElement->GetLength();
uint8_t* a = new uint8_t[l];
if(!a)
dbg.Verbose(0, "Document::LoadEntryBinArea cannot allocate a");
return NULL;
}
- size_t l2 = fread(a, 1, l , Fp);
- if( l != l2 )
+ Fp->read((char*)a, l);
+ if( Fp->fail() || Fp->eof() )//Fp->gcount() == 1
{
delete[] a;
return NULL;
}
- /// \todo Drop any already existing void area! JPR
+ /// \todo Drop any already existing void area! JPR
if( !SetEntryBinAreaByNumber( a, group, elem ) )
{
dbg.Verbose(0, "Document::LoadEntryBinArea setting failed.");
void* Document::LoadEntryBinArea(BinEntry* element)
{
size_t o =(size_t)element->GetOffset();
- fseek(Fp, o, SEEK_SET);
+ Fp->seekg(o, std::ios_base::beg);
size_t l = element->GetLength();
uint8_t* a = new uint8_t[l];
if( !a )
}
element->SetBinArea((uint8_t*)a);
/// \todo check the result
- size_t l2 = fread(a, 1, l , Fp);
- if( l != l2 )
+ Fp->read((char*)a, l);
+ if( Fp->fail() || Fp->eof()) //Fp->gcount() == 1
{
delete[] a;
return NULL;
*/
void Document::LoadDocEntrySafe(DocEntry * entry)
{
- long PositionOnEntry = ftell(Fp);
+ long PositionOnEntry = Fp->tellg();
LoadDocEntry(entry);
- fseek(Fp, PositionOnEntry, SEEK_SET);
+ Fp->seekg(PositionOnEntry, std::ios_base::beg);
}
/**
* @return length of the parsed set.
*/
void Document::ParseDES(DocEntrySet *set,
- long offset,
- long l_max,
- bool delim_mode)
+ long offset,
+ long l_max,
+ bool delim_mode)
{
DocEntry *newDocEntry = 0;
while (true)
{
- if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
+ if ( !delim_mode && (Fp->tellg()-offset) >= l_max)
{
break;
}
{
break;
}
- if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
+ if ( !delim_mode && (Fp->tellg()-offset) >= l_max)
{
break;
}
{
if ( IsRLELossLessTransferSyntax() )
{
- long PositionOnEntry = ftell(Fp);
- fseek( Fp, newDocEntry->GetOffset(), SEEK_SET );
+ long PositionOnEntry = Fp->tellg();
+ Fp->seekg( newDocEntry->GetOffset(), std::ios_base::beg );
ComputeRLEInfo();
- fseek( Fp, PositionOnEntry, SEEK_SET );
+ Fp->seekg( PositionOnEntry, std::ios_base::beg );
}
else
if ( IsJPEGTransferSyntax() )
{
- long PositionOnEntry = ftell(Fp);
- fseek( Fp, newDocEntry->GetOffset(), SEEK_SET );
+ long PositionOnEntry = Fp->tellg();
+ Fp->seekg( newDocEntry->GetOffset(), std::ios_base::beg );
ComputeJPEGFragmentInfo();
- fseek( Fp, PositionOnEntry, SEEK_SET );
+ Fp->seekg( PositionOnEntry, std::ios_base::beg );
}
}
l, delim_mode);
}
set->AddEntry( newSeqEntry );
- if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
+ if ( !delim_mode && (Fp->tellg()-offset) >= l_max)
{
break;
}
break;
}
}
- if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
+ if ( !delim_mode && (Fp->tellg()-offset) >= l_max)
{
break;
}
seqEntry->AddEntry( itemSQ, SQItemNumber );
SQItemNumber++;
- if ( !delim_mode && ( ftell(Fp) - offset ) >= l_max )
+ if ( !delim_mode && ( Fp->tellg() - offset ) >= l_max )
{
break;
}
*/
void Document::LoadDocEntry(DocEntry* entry)
{
- size_t item_read;
uint16_t group = entry->GetGroup();
std::string vr = entry->GetVR();
uint32_t length = entry->GetLength();
- fseek(Fp, (long)entry->GetOffset(), SEEK_SET);
+ Fp->seekg((long)entry->GetOffset(), std::ios_base::beg);
// A SeQuence "contains" a set of Elements.
// (fffe e000) tells us an Element is beginning
}
// to be sure we are at the end of the value ...
- fseek(Fp,(long)entry->GetOffset()+(long)entry->GetLength(),SEEK_SET);
+ Fp->seekg((long)entry->GetOffset()+(long)entry->GetLength(),std::ios_base::beg);
return;
}
}
// We need an additional byte for storing \0 that is not on disk
- //std::string newValue(length,0);
- //item_read = fread(&(newValue[0]), (size_t)length, (size_t)1, Fp);
- //rah !! I can't believe it could work, normally this is a const char* !!!
char *str = new char[length+1];
- item_read = fread(str, (size_t)length, (size_t)1, Fp);
+ Fp->read(str, (size_t)length);
str[length] = '\0';
std::string newValue = str;
delete[] str;
+
if ( ValEntry* valEntry = dynamic_cast<ValEntry* >(entry) )
{
- if ( item_read != 1 )
+ if ( Fp->fail() || Fp->eof())//Fp->gcount() == 1
{
dbg.Verbose(1, "Document::LoadDocEntry",
"unread element value");
// The following reserved two bytes (see PS 3.5-2003, section
// "7.1.2 Data element structure with explicit vr", p 27) must be
// skipped before proceeding on reading the length on 4 bytes.
- fseek(Fp, 2L, SEEK_CUR);
+ Fp->seekg( 2L, std::ios_base::cur);
uint32_t length32 = ReadInt32();
if ( (vr == "OB" || vr == "OW") && length32 == 0xffffffff )
// chance to get the pixels by deciding the element goes
// until the end of the file. Hence we artificially fix the
// the length and proceed.
- long currentPosition = ftell(Fp);
- fseek(Fp,0L,SEEK_END);
- long lengthUntilEOF = ftell(Fp) - currentPosition;
- fseek(Fp, currentPosition, SEEK_SET);
+ long currentPosition = Fp->tellg();
+ Fp->seekg(0L,std::ios_base::end);
+ long lengthUntilEOF = Fp->tellg() - currentPosition;
+ Fp->seekg(currentPosition, std::ios_base::beg);
entry->SetLength(lengthUntilEOF);
return;
}
char vr[3];
- long positionOnEntry = ftell(Fp);
+ long positionOnEntry = Fp->tellg();
// Warning: we believe this is explicit VR (Value Representation) because
// we used a heuristic that found "UL" in the first tag. Alas this
// doesn't guarantee that all the tags will be in explicit VR. In some
// is in explicit VR and try to fix things if it happens not to be
// the case.
- fread (vr, (size_t)2,(size_t)1, Fp);
+ Fp->read (vr, (size_t)2);
vr[2] = 0;
if( !CheckDocEntryVR(entry, vr) )
{
- fseek(Fp, positionOnEntry, SEEK_SET);
+ Fp->seekg(positionOnEntry, std::ios_base::beg);
// When this element is known in the dictionary we shall use, e.g. for
// the semantics (see the usage of IsAnInteger), the VR proposed by the
// dictionary entry. Still we have to flag the element as implicit since
*/
void Document::SkipToNextDocEntry(DocEntry *entry)
{
- fseek(Fp, (long)(entry->GetOffset()), SEEK_SET);
- fseek(Fp, (long)(entry->GetReadLength()), SEEK_CUR);
+ Fp->seekg((long)(entry->GetOffset()), std::ios_base::beg);
+ Fp->seekg( (long)(entry->GetReadLength()), std::ios_base::cur);
}
/**
// encounter such an ill-formed image, we simply display a warning
// message and proceed on parsing (while crossing fingers).
std::ostringstream s;
- long filePosition = ftell(Fp);
+ long filePosition = Fp->tellg();
s << "Erroneous Group Length element length on : (" \
<< std::hex << group << " , " << element
<< ") -before- position x(" << filePosition << ")"
throw( FormatUnexpected )
{
// See PS 3.5-2001, section A.4 p. 49 on encapsulation of encoded pixel data.
- long positionOnEntry = ftell(Fp);
+ long positionOnEntry = Fp->tellg();
bool foundSequenceDelimiter = false;
uint32_t totalLength = 0;
{
dbg.Verbose(1, "Document::FindDocEntryLengthOB: neither an Item "
"tag nor a Sequence delimiter tag.");
- fseek(Fp, positionOnEntry, SEEK_SET);
+ Fp->seekg(positionOnEntry, std::ios_base::beg);
throw FormatUnexpected("Document::FindDocEntryLengthOB()",
"Neither an Item tag nor a Sequence "
"delimiter tag.");
break;
}
}
- fseek(Fp, positionOnEntry, SEEK_SET);
+ Fp->seekg( positionOnEntry, std::ios_base::beg);
return totalLength;
}
throw( FormatError )
{
uint16_t g;
- size_t item_read = fread (&g, (size_t)2,(size_t)1, Fp);
- if ( item_read != 1 )
+ Fp->read ((char*)&g, (size_t)2);
+ if ( Fp->fail() )
+ {
+ throw FormatError( "Document::ReadInt16()", " file error." );
+ }
+ if( Fp->eof() )
{
- if( ferror(Fp) )
- {
- throw FormatError( "Document::ReadInt16()", " file error." );
- }
throw FormatError( "Document::ReadInt16()", "EOF." );
}
g = SwapShort(g);
throw( FormatError )
{
uint32_t g;
- size_t item_read = fread (&g, (size_t)4,(size_t)1, Fp);
- if ( item_read != 1 )
+ Fp->read ((char*)&g, (size_t)4);
+ if ( Fp->fail() )
+ {
+ throw FormatError( "Document::ReadInt32()", " file error." );
+ }
+ if( Fp->eof() )
{
- if( ferror(Fp) )
- {
- throw FormatError( "Document::ReadInt16()", " file error." );
- }
throw FormatError( "Document::ReadInt32()", "EOF." );
}
g = SwapLong(g);
void Document::SkipBytes(uint32_t nBytes)
{
//FIXME don't dump the returned value
- (void)fseek(Fp, (long)nBytes, SEEK_CUR);
+ Fp->seekg((long)nBytes, std::ios_base::cur);
}
/**
// The easiest case is the one of a DICOM header, since it possesses a
// file preamble where it suffice to look for the string "DICM".
- int lgrLue = fread(deb, 1, HEADER_LENGTH_TO_READ, Fp);
- (void)lgrLue; //FIXME not used
+ Fp->read(deb, HEADER_LENGTH_TO_READ);
char *entCur = deb + 128;
if( memcmp(entCur, "DICM", (size_t)4) == 0 )
// Position the file position indicator at first tag (i.e.
// after the file preamble and the "DICM" string).
- rewind(Fp);
- fseek (Fp, 132L, SEEK_SET);
+ Fp->seekg(0, std::ios_base::beg);
+ Fp->seekg ( 132L, std::ios_base::beg);
return true;
} // End of DicomV3
// preamble. We can reset the file position indicator to where the data
// is (i.e. the beginning of the file).
dbg.Verbose(1, "Document::CheckSwap:", "not a DICOM Version3 file");
- rewind(Fp);
+ Fp->seekg(0, std::ios_base::beg);
// Our next best chance would be to be considering a 'clean' ACR/NEMA file.
// By clean we mean that the length of the first tag is written down.
return 0;
}
- newEntry->SetOffset(ftell(Fp));
+ newEntry->SetOffset(Fp->tellg());
return newEntry;
}
*/
bool Document::ReadTag(uint16_t testGroup, uint16_t testElement)
{
- long positionOnEntry = ftell(Fp);
- long currentPosition = ftell(Fp); // On debugging purposes
+ long positionOnEntry = Fp->tellg();
+ long currentPosition = Fp->tellg(); // On debugging purposes
//// Read the Item Tag group and element, and make
// sure they are what we expected:
s << " at address: " << (unsigned)currentPosition << std::endl;
dbg.Verbose(0, "Document::ReadItemTagLength: wrong Item Tag found:");
dbg.Verbose(0, s.str().c_str());
- fseek(Fp, positionOnEntry, SEEK_SET);
+ Fp->seekg(positionOnEntry, std::ios_base::beg);
return false;
}
*/
uint32_t Document::ReadTagLength(uint16_t testGroup, uint16_t testElement)
{
- long positionOnEntry = ftell(Fp);
+ long positionOnEntry = Fp->tellg();
(void)positionOnEntry;
if ( !ReadTag(testGroup, testElement) )
}
//// Then read the associated Item Length
- long currentPosition = ftell(Fp);
+ long currentPosition = Fp->tellg();
uint32_t itemLength = ReadInt32();
{
std::ostringstream s;
if ( itemLength != 0 )
{
char* basicOffsetTableItemValue = new char[itemLength + 1];
- fread(basicOffsetTableItemValue, itemLength, 1, Fp);
+ Fp->read(basicOffsetTableItemValue, itemLength);
#ifdef GDCM_DEBUG
for (unsigned int i=0; i < itemLength; i += 4 )
// Offset Table information on fragments of this current Frame.
// Note that the fragment pixels themselves are not loaded
// (but just skipped).
- long frameOffset = ftell(Fp);
+ long frameOffset = Fp->tellg();
uint32_t nbRleSegments = ReadInt32();
long fragmentLength;
while ( (fragmentLength = ReadTagLength(0xfffe, 0xe000)) )
{
- long fragmentOffset = ftell(Fp);
+ long fragmentOffset = Fp->tellg();
// Store the collected info
JPEGFragment* newFragment = new JPEGFragment;
Program: gdcm
Module: $RCSfile: gdcmDocument.h,v $
Language: C++
- Date: $Date: 2004/10/18 12:49:22 $
- Version: $Revision: 1.52 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.53 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include <map>
#include <list>
+#include <fstream>
+
namespace gdcm
{
int SwapCode;
/// File Pointer, opened during Header parsing.
- FILE* Fp;
+ std::ifstream* Fp;
/// ACR, ACR_LIBIDO, ExplicitVR, ImplicitVR, Unknown
FileType Filetype;
FileType GetFileType();
- FILE* OpenFile();
+ std::ifstream * OpenFile();
bool CloseFile();
- void Write( FILE* fp, FileType type );
+ void Write( std::ofstream* fp, FileType type );
ValEntry* ReplaceOrCreateByNumber(std::string const & value,
uint16_t group, uint16_t elem,
int GetSwapCode() { return SwapCode; }
/// File pointer
- FILE * GetFP() { return Fp; }
+ std::ifstream * GetFP() { return Fp; }
bool operator<(Document &document);
Program: gdcm
Module: $RCSfile: gdcmElementSet.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:45 $
- Version: $Revision: 1.24 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.25 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* from the H Table
* @return
*/
-void ElementSet::Write(FILE* fp, FileType filetype)
+void ElementSet::Write(std::ofstream* fp, FileType filetype)
{
for (TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
{
Program: gdcm
Module: $RCSfile: gdcmElementSet.h,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:46 $
- Version: $Revision: 1.19 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.20 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
bool RemoveEntryNoDestroy(DocEntry *EntryToRemove);
virtual void Print(std::ostream &os = std::cout);
- virtual void Write(FILE *fp, FileType filetype);
+ virtual void Write(std::ofstream *fp, FileType filetype);
/// Accessor to \ref TagHT
// Do not expose this to user (public API) !
Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2004/10/20 22:31:52 $
- Version: $Revision: 1.147 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.148 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmFile.h"
#include "gdcmDebug.h"
+#include <fstream>
namespace gdcm
{
return ImageDataSize;
}
+ std::ifstream* fp = HeaderInternal->OpenFile();
if ( PixelConverter->BuildRGBImage() )
{
memmove( destination,
if ( ! decompressed )
{
// The decompressed image migth not be loaded yet:
- FILE* fp = HeaderInternal->OpenFile();
+ std::ifstream* fp = HeaderInternal->OpenFile();
PixelConverter->ReadAndDecompressPixelData( fp );
HeaderInternal->CloseFile();
if ( ! decompressed )
return;
}
- FILE* fp = HeaderInternal->OpenFile();
+ std::ifstream* fp = HeaderInternal->OpenFile();
PixelConverter->ReadAndDecompressPixelData( fp );
HeaderInternal->CloseFile();
memmove( destination,
bool File::WriteRawData(std::string const & fileName)
{
- FILE* fp1 = fopen(fileName.c_str(), "wb");
- if (fp1 == NULL)
+ std::ofstream fp1(fileName.c_str(), std::ios::out | std::ios::binary );
+ if (!fp1)
{
printf("Fail to open (write) file [%s] \n", fileName.c_str());
return false;
}
- fwrite (Pixel_Data, ImageDataSize, 1, fp1);
- fclose (fp1);
+ fp1.write((char*)Pixel_Data, ImageDataSize);
+ fp1.close();
return true;
}
return false;
}
- FILE* fp1 = fopen(fileName.c_str(), "wb");
+ std::ofstream* fp1 = new std::ofstream(fileName.c_str(),
+ std::ios::out | std::ios::binary);
if (fp1 == NULL)
{
printf("Failed to open (write) File [%s] \n", fileName.c_str());
// writing Dicom File Preamble
uint8_t* filePreamble = new uint8_t[128];
memset(filePreamble, 0, 128);
- fwrite(filePreamble, 128, 1, fp1);
- fwrite("DICM", 4, 1, fp1);
+ fp1->write((char*)filePreamble, 128);
+ fp1->write("DICM", 4);
delete[] filePreamble;
}
HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011);
}
// ----------------- End of Special Patch ----------------
-
- // fwrite(Pixel_Data, ImageDataSize, 1, fp1); // should be useless, now
- fclose (fp1);
+
+ fp1->close ();
return true;
}
Program: gdcm
Module: $RCSfile: gdcmFile.h,v $
Language: C++
- Date: $Date: 2004/10/20 14:30:40 $
- Version: $Revision: 1.64 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.65 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
private:
void Initialise();
- // For JPEG 8 Bits, body in file gdcmJpeg.cxx
- bool gdcm_write_JPEG_file (FILE* fp, void* image_buffer,
- int image_width, int image_heigh,
- int quality);
-
- // For JPEG 12 Bits, body in file gdcmJpeg12.cxx
- bool gdcm_write_JPEG_file12 (FILE* fp, void* image_buffer,
- int image_width, int image_height,
- int quality);
-
void SaveInitialValues(); // will belong to the future PixelData class
void RestoreInitialValues(); // will belong to the future PixelData class
void DeleteInitialValues(); // will belong to the future PixelData class
Program: gdcm
Module: $RCSfile: gdcmHeader.cxx,v $
Language: C++
- Date: $Date: 2004/10/18 12:49:22 $
- Version: $Revision: 1.194 $
+ Date: $Date: 2004/10/22 03:05:41 $
+ Version: $Revision: 1.195 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* @param filetype Type of the File to be written
* (ACR-NEMA, ExplicitVR, ImplicitVR)
*/
-void Header::Write(FILE* fp,FileType filetype)
+void Header::Write(std::ofstream* fp,FileType filetype)
{
// Bits Allocated
if ( GetEntryByNumber(0x0028,0x0100) == "12")
Program: gdcm
Module: $RCSfile: gdcmHeader.h,v $
Language: C++
- Date: $Date: 2004/10/18 12:49:22 $
- Version: $Revision: 1.90 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.91 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
/// Read (used in File)
void SetImageDataSize(size_t expectedSize);
- void Write(FILE* fp, FileType filetype);
+ void Write(std::ofstream* fp, FileType filetype);
protected:
bool AnonymizeHeader();
Program: gdcm
Module: $RCSfile: gdcmJpeg.cxx,v $
Language: C++
- Date: $Date: 2004/10/18 02:17:07 $
- Version: $Revision: 1.27 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.28 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
*/
#include <setjmp.h>
+#include <fstream>
+#include "jdatasrc.cxx"
+#include "jdatadst.cxx"
namespace gdcm
{
-
/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/
/* This half of the example shows how to feed data into the JPEG compressor.
* @return 1 on success, 0 on error
*/
-bool gdcm_write_JPEG_file (FILE* fp, void* im_buf,
+bool gdcm_write_JPEG_file (std::ofstream* fp, void* im_buf,
int image_width, int image_height, int quality)
{
* @return 1 on success, 0 on error
*/
-bool gdcm_read_JPEG_file ( FILE* fp, void* image_buffer )
+bool gdcm_read_JPEG_file ( std::ifstream* fp, void* image_buffer )
{
char* pimage;
*/
/* JSAMPLEs per row in output buffer */
- row_stride = cinfo.output_width * cinfo.output_components;
+ row_stride = cinfo.output_width * cinfo.output_components*2;
#ifdef GDCM_JPG_DEBUG
printf ("cinfo.output_width %d cinfo.output_components %d row_stride %d\n",
Program: gdcm
Module: $RCSfile: gdcmJpeg12.cxx,v $
Language: C++
- Date: $Date: 2004/10/14 22:35:01 $
- Version: $Revision: 1.22 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.23 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
extern "C" {
#include "src/jpeg/libijg12/jconfig.h"
#include "src/jpeg/libijg12/jpeglib.h"
+#include "src/jpeg/libijg12/jinclude.h"
+#include "src/jpeg/libijg12/jerror.h"
}
+
#define gdcm_write_JPEG_file gdcm_write_JPEG_file12
#define gdcm_read_JPEG_file gdcm_read_JPEG_file12
Program: gdcm
Module: $RCSfile: gdcmJpeg16.cxx,v $
Language: C++
- Date: $Date: 2004/10/14 22:16:33 $
- Version: $Revision: 1.1 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.2 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
extern "C" {
#include "src/jpeg/libijg16/jconfig.h"
#include "src/jpeg/libijg16/jpeglib.h"
+#include "src/jpeg/libijg16/jinclude.h"
+#include "src/jpeg/libijg16/jerror.h"
}
+
#define gdcm_write_JPEG_file gdcm_write_JPEG_file16
#define gdcm_read_JPEG_file gdcm_read_JPEG_file16
Program: gdcm
Module: $RCSfile: gdcmJpeg2000.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:46 $
- Version: $Revision: 1.12 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.13 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* @warning : not yet made
*/
-bool gdcm_read_JPEG2000_file (FILE* fp,void* image_buffer) {
+bool gdcm_read_JPEG2000_file (std::ifstream* fp,void* image_buffer) {
(void)fp; //FIXME
(void)image_buffer; //FIXME
std::cout << "Sorry JPEG 2000 File not yet taken into account" << std::endl;
Program: gdcm
Module: $RCSfile: gdcmJpeg8.cxx,v $
Language: C++
- Date: $Date: 2004/10/14 22:35:02 $
- Version: $Revision: 1.8 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.9 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
extern "C" {
#include "src/jpeg/libijg8/jconfig.h"
#include "src/jpeg/libijg8/jpeglib.h"
+#include "src/jpeg/libijg8/jinclude.h"
+#include "src/jpeg/libijg8/jerror.h"
}
#define gdcm_write_JPEG_file gdcm_write_JPEG_file8
Program: gdcm
Module: $RCSfile: gdcmPixelConvert.cxx,v $
Language: C++
- Date: $Date: 2004/10/20 22:31:52 $
- Version: $Revision: 1.17 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.18 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmDebug.h"
#include "gdcmPixelConvert.h"
+#include <fstream>
namespace gdcm
{
#define str2num(str, typeNum) *((typeNum *)(str))
// For JPEG 2000, body in file gdcmJpeg2000.cxx
-bool gdcm_read_JPEG2000_file (FILE* fp, void* image_buffer);
+bool gdcm_read_JPEG2000_file (std::ifstream* fp, void* image_buffer);
// For JPEG 8 Bits, body in file gdcmJpeg8.cxx
-bool gdcm_read_JPEG_file8 (FILE* fp, void* image_buffer);
+bool gdcm_read_JPEG_file8 (std::ifstream* fp, void* image_buffer);
// For JPEG 12 Bits, body in file gdcmJpeg12.cxx
-bool gdcm_read_JPEG_file12 (FILE* fp, void* image_buffer);
+bool gdcm_read_JPEG_file12 (std::ifstream* fp, void* image_buffer);
// For JPEG 16 Bits, body in file gdcmJpeg16.cxx
// Beware this is misleading there is no 16bits DCT algorithm, only
// jpeg lossless compression exist in 16bits.
-bool gdcm_read_JPEG_file16 (FILE* fp, void* image_buffer);
+bool gdcm_read_JPEG_file16 (std::ifstream* fp, void* image_buffer);
//-----------------------------------------------------------------------------
* \brief Read from file a 12 bits per pixel image and decompress it
* into a 16 bits per pixel image.
*/
-void PixelConvert::ReadAndDecompress12BitsTo16Bits( FILE* fp )
+void PixelConvert::ReadAndDecompress12BitsTo16Bits( std::ifstream* fp )
throw ( FormatError )
{
int nbPixels = XSize * YSize;
for( int p = 0; p < nbPixels; p += 2 )
{
uint8_t b0, b1, b2;
- size_t ItemRead;
-
- ItemRead = fread( &b0, 1, 1, fp );
- if ( ItemRead != 1 )
+
+ fp->read( (char*)&b0, 1);
+ if ( fp->fail() || fp->eof() )//Fp->gcount() == 1
{
throw FormatError( "PixelConvert::ReadAndDecompress12BitsTo16Bits()",
"Unfound first block" );
}
-
- ItemRead = fread( &b1, 1, 1, fp );
- if ( ItemRead != 1 )
+
+ fp->read( (char*)&b1, 1 );
+ if ( fp->fail() || fp->eof())//Fp->gcount() == 1
{
throw FormatError( "PixelConvert::ReadAndDecompress12BitsTo16Bits()",
"Unfound second block" );
}
-
- ItemRead = fread( &b2, 1, 1, fp );
- if ( ItemRead != 1 )
+
+ fp->read( (char*)&b2, 1 );
+ if ( fp->fail() || fp->eof())//Fp->gcount() == 1
{
throw FormatError( "PixelConvert::ReadAndDecompress12BitsTo16Bits()",
"Unfound second block" );
bool PixelConvert::ReadAndDecompressRLEFragment( uint8_t* subDecompressed,
long fragmentSize,
long decompressedSegmentSize,
- FILE* fp )
+ std::ifstream* fp )
{
int8_t count;
long numberOfOutputBytes = 0;
while( numberOfOutputBytes < decompressedSegmentSize )
{
- fread( &count, 1, 1, fp );
+ fp->read( (char*)&count, 1 );
numberOfReadBytes += 1;
if ( count >= 0 )
// Note: count <= 127 comparison is always true due to limited range
// signed integer of width N is 2^(N-1) - 1, which for int8_t
// is 127].
{
- fread( subDecompressed, count + 1, 1, fp);
+ fp->read( (char*)subDecompressed, count + 1);
numberOfReadBytes += count + 1;
subDecompressed += count + 1;
numberOfOutputBytes += count + 1;
if ( ( count <= -1 ) && ( count >= -127 ) )
{
int8_t newByte;
- fread( &newByte, 1, 1, fp);
+ fp->read( (char*)&newByte, 1);
numberOfReadBytes += 1;
for( int i = 0; i < -count + 1; i++ )
{
* at which the pixel data should be copied
* @return Boolean
*/
-bool PixelConvert::ReadAndDecompressRLEFile( FILE* fp )
+bool PixelConvert::ReadAndDecompressRLEFile( std::ifstream* fp )
{
uint8_t* subDecompressed = Decompressed;
long decompressedSegmentSize = XSize * YSize;
// Loop on the fragments
for( int k = 1; k <= (*it)->NumberFragments; k++ )
{
- fseek( fp, (*it)->Offset[k] ,SEEK_SET );
+ //fseek( fp, (*it)->Offset[k] ,SEEK_SET );
+ fp->seekg( (*it)->Offset[k] , std::ios_base::beg );
(void)ReadAndDecompressRLEFragment( subDecompressed,
(*it)->Length[k],
decompressedSegmentSize,
* @param fp File Pointer
* @return Boolean
*/
-bool PixelConvert::ReadAndDecompressJPEGFile( FILE* fp )
+bool PixelConvert::ReadAndDecompressJPEGFile( std::ifstream* fp )
{
uint8_t* localDecompressed = Decompressed;
// Loop on the fragment[s]
it != JPEGInfo->Fragments.end();
++it )
{
- fseek( fp, (*it)->Offset, SEEK_SET );
+ //fseek( fp, (*it)->Offset, SEEK_SET );
+ fp->seekg( (*it)->Offset, std::ios_base::beg);
if ( IsJPEG2000 )
{
delete[] copyDecompressed;
}
-bool PixelConvert::ReadAndDecompressPixelData( FILE* fp )
+bool PixelConvert::ReadAndDecompressPixelData( std::ifstream* fp )
{
ComputeDecompressedAndRGBSizes();
AllocateDecompressed();
return false;
}
- if ( fseek( fp, PixelOffset, SEEK_SET ) == -1 )
+ //if ( fseek( fp, PixelOffset, SEEK_SET ) == -1 )
+ fp->seekg( PixelOffset, std::ios_base::beg );
+ if( fp->fail() || fp->eof()) //Fp->gcount() == 1
{
dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
"unable to find PixelOffset in file." );
}
else if ( IsDecompressed )
{
- size_t ItemRead = fread( Decompressed, PixelDataLength, 1, fp );
- if ( ItemRead != 1 )
+ fp->read( (char*)Decompressed, PixelDataLength);
+ if ( fp->fail() | |fp->eof())//Fp->gcount() == 1
{
dbg.Verbose( 0, "PixelConvert::ReadAndDecompressPixelData: "
"reading of decompressed pixel data failed." );
{
// Just in case some access to a Header element requires disk access.
// Note: gdcmDocument::Fp is leaved open after OpenFile.
- FILE* fp = header->OpenFile();
+ std::ifstream* fp = header->OpenFile();
// Number of Bits Allocated for storing a Pixel is defaulted to 16
// when absent from the header.
BitsAllocated = header->GetBitsAllocated();
DocEntry* lutRedDataEntry = header->GetDocEntryByNumber( 0x0028,
0x1201 );
LutRedData = new uint8_t[ lutRedDataEntry->GetLength() ];
- fseek( fp, lutRedDataEntry->GetOffset() ,SEEK_SET );
- int numberItem = fread( LutRedData,
- (size_t)lutRedDataEntry->GetLength(),
- 1, fp );
- if ( numberItem != 1 )
+ //fseek( fp, lutRedDataEntry->GetOffset() ,SEEK_SET );
+ fp->seekg( lutRedDataEntry->GetOffset() ,std::ios_base::beg );
+ fp->read( (char*)LutRedData, (size_t)lutRedDataEntry->GetLength());
+ //if ( numberItem != 1 )
+ if ( fp->fail() || fp->eof())//Fp->gcount() == 1
{
dbg.Verbose(0, "PixelConvert::GrabInformationsFromHeader: "
"unable to read red LUT data" );
DocEntry* lutGreenDataEntry = header->GetDocEntryByNumber( 0x0028,
0x1202 );
LutGreenData = new uint8_t[ lutGreenDataEntry->GetLength() ];
- fseek( fp, lutGreenDataEntry->GetOffset() ,SEEK_SET );
- int numberItem = fread( LutGreenData,
- (size_t)lutGreenDataEntry->GetLength(),
- 1, fp );
- if ( numberItem != 1 )
+ //fseek( fp, lutGreenDataEntry->GetOffset() ,SEEK_SET );
+ fp->seekg( lutGreenDataEntry->GetOffset() , std::ios_base::beg );
+ fp->read( (char*)LutGreenData, (size_t)lutGreenDataEntry->GetLength() );
+ //if ( numberItem != 1 )
+ if ( fp->fail() || fp->eof())//Fp->gcount() == 1
{
dbg.Verbose(0, "PixelConvert::GrabInformationsFromHeader: "
"unable to read green LUT data" );
DocEntry* lutBlueDataEntry = header->GetDocEntryByNumber( 0x0028,
0x1203 );
LutBlueData = new uint8_t[ lutBlueDataEntry->GetLength() ];
- fseek( fp, lutBlueDataEntry->GetOffset() ,SEEK_SET );
- int numberItem = fread( LutBlueData,
- (size_t)lutBlueDataEntry->GetLength(),
- 1, fp );
- if ( numberItem != 1 )
+ //fseek( fp, lutBlueDataEntry->GetOffset() ,SEEK_SET );
+ fp->seekg( lutBlueDataEntry->GetOffset() , std::ios_base::beg );
+ fp->read( (char*)LutBlueData, (size_t)lutBlueDataEntry->GetLength() );
+ //if ( numberItem != 1 )
+ if ( fp->fail() || fp->eof())//Fp->gcount() == 1
{
dbg.Verbose(0, "PixelConvert::GrabInformationsFromHeader: "
"unable to read blue LUT data" );
Program: gdcm
Module: $RCSfile: gdcmPixelConvert.h,v $
Language: C++
- Date: $Date: 2004/10/20 22:31:52 $
- Version: $Revision: 1.12 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.13 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// In progress
void GrabInformationsFromHeader( Header* header );
- bool ReadAndDecompressPixelData( FILE* fp );
+ bool ReadAndDecompressPixelData( std::ifstream* fp );
void Squeeze();
bool BuildRGBImage();
uint8_t* subDecompressed,
long fragmentSize,
long decompressedSegmentSize,
- FILE* fp );
- void ReadAndDecompress12BitsTo16Bits( FILE* fp ) throw ( FormatError );
- bool ReadAndDecompressRLEFile( FILE* fp );
- bool ReadAndDecompressJPEGFile( FILE* fp );
+ std::ifstream* fp );
+ void ReadAndDecompress12BitsTo16Bits( std::ifstream* fp ) throw ( FormatError );
+ bool ReadAndDecompressRLEFile( std::ifstream* fp );
+ bool ReadAndDecompressJPEGFile( std::ifstream* fp );
+ void BuildLUTRGBA( std::ifstream* fp );
// In place (within Decompressed and with no fp access) decompression
// or convertion:
Program: gdcm
Module: $RCSfile: gdcmSQItem.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:47 $
- Version: $Revision: 1.29 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.30 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmGlobal.h"
#include "gdcmUtil.h"
#include "gdcmDebug.h"
+#include <fstream>
namespace gdcm
{
* \ingroup SQItem
* \brief canonical Writer
*/
-void SQItem::Write(FILE* fp,FileType filetype)
+void SQItem::Write(std::ofstream* fp,FileType filetype)
{
uint16_t item[4] = { 0xfffe, 0xe000, 0xffff, 0xffff };
uint16_t itemt[4]= { 0xfffe, 0xe00d, 0xffff, 0xffff };
//we force the writting of an 'Item' Start Element
// because we want to write the Item as a 'no Length' item
- fwrite(&item[0],8,1,fp); // fffe e000 ffff ffff
+ fp->write((char*)&item[0],8); // fffe e000 ffff ffff
for (ListDocEntry::iterator i = docEntries.begin();
i != docEntries.end();
//we force the writting of an 'Item Delimitation' item
// because we wrote the Item as a 'no Length' item
- fwrite(&itemt[0],8,1,fp); // fffe e000 ffff ffff
+ fp->write((char*)&itemt[0],8); // fffe e000 ffff ffff
}
Program: gdcm
Module: $RCSfile: gdcmSQItem.h,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:47 $
- Version: $Revision: 1.19 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.20 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
~SQItem();
virtual void Print(std::ostream &os = std::cout);
- virtual void Write(FILE *fp, FileType filetype);
+ virtual void Write(std::ofstream *fp, FileType filetype);
/// \brief returns the DocEntry chained List for this SQ Item.
ListDocEntry &GetDocEntries() { return docEntries; };
Program: gdcm
Module: $RCSfile: gdcmSeqEntry.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:48 $
- Version: $Revision: 1.31 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.32 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include <iostream>
#include <iomanip>
+#include <fstream>
namespace gdcm
{
/*
* \brief canonical Writer
*/
-void SeqEntry::Write(FILE* fp, FileType filetype)
+void SeqEntry::Write(std::ofstream* fp, FileType filetype)
{
uint16_t seq_term_gr = 0xfffe;
uint16_t seq_term_el = 0xe0dd;
// we force the writting of a Sequence Delimitation item
// because we wrote the Sequence as a 'no Length' sequence
- fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp);
- fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp);
- fwrite ( &seq_term_lg,(size_t)4 ,(size_t)1 ,fp);
+ fp->write ( (char*)&seq_term_gr,(size_t)2 );
+ fp->write ( (char*)&seq_term_el,(size_t)2 );
+ fp->write ( (char*)&seq_term_lg,(size_t)4 );
}
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmSeqEntry.h,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:48 $
- Version: $Revision: 1.20 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.21 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
virtual ~SeqEntry();
virtual void Print(std::ostream &os = std::cout);
- virtual void Write(FILE *fp, FileType);
+ virtual void Write(std::ofstream *fp, FileType);
/// returns the SQITEM chained List for this SeQuence.
ListSQItem &GetSQItems() { return items; }
Program: gdcm
Module: $RCSfile: gdcmValEntry.cxx,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:48 $
- Version: $Revision: 1.30 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.31 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmGlobal.h"
#include "gdcmUtil.h"
+#include <fstream>
+
namespace gdcm
{
/*
* \brief canonical Writer
*/
-void ValEntry::Write(FILE* fp, FileType filetype)
+void ValEntry::Write(std::ofstream* fp, FileType filetype)
{
DocEntry::Write(fp, filetype);
{
uint16_t val_uint16 = atoi(tokens[i].c_str());
void* ptr = &val_uint16;
- fwrite ( ptr,(size_t)2 ,(size_t)1 ,fp);
+ fp->write ( (char*)ptr,(size_t)2);
}
tokens.clear();
return;
{
uint32_t val_uint32 = atoi(tokens[i].c_str());
void* ptr = &val_uint32;
- fwrite ( ptr,(size_t)4 ,(size_t)1 ,fp);
+ fp->write ( (char*)ptr,(size_t)4 );
}
tokens.clear();
return;
}
- fwrite (GetValue().c_str(), (size_t)lgr ,(size_t)1, fp); // Elem value
+ fp->write (GetValue().c_str(), (size_t)lgr ); // Elem value
}
//-----------------------------------------------------------------------------
Program: gdcm
Module: $RCSfile: gdcmValEntry.h,v $
Language: C++
- Date: $Date: 2004/10/12 04:35:48 $
- Version: $Revision: 1.26 $
+ Date: $Date: 2004/10/22 03:05:42 $
+ Version: $Revision: 1.27 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
void SetValue(std::string const & val) { Value = val; };
virtual void Print(std::ostream &os = std::cout);
- virtual void Write(FILE *fp, FileType filetype);
+ virtual void Write(std::ofstream *fp, FileType filetype);
protected:
--- /dev/null
+/*
+ * jdatadst.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains compression data destination routines for the case of
+ * emitting JPEG data to a file (or any stdio stream). While these routines
+ * are sufficient for most applications, some will want to use a different
+ * destination manager.
+ * IMPORTANT: we assume that fwrite() will correctly transcribe an array of
+ * JOCTETs into 8-bit-wide elements on external storage. If char is wider
+ * than 8 bits on your machine, you may need to do some tweaking.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+
+
+/* Expanded data destination object for stdio output */
+
+typedef struct {
+ struct jpeg_destination_mgr pub; /* public fields */
+
+ std::ofstream * outfile; /* target stream */
+ JOCTET * buffer; /* start of buffer */
+} my_destination_mgr;
+
+typedef my_destination_mgr * my_dest_ptr;
+
+#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
+
+
+/*
+ * Initialize destination --- called by jpeg_start_compress
+ * before any data is actually written.
+ */
+
+METHODDEF(void)
+init_destination (j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+
+ /* Allocate the output buffer --- it will be released when done with image */
+ dest->buffer = (JOCTET *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
+ OUTPUT_BUF_SIZE * SIZEOF(JOCTET));
+
+ dest->pub.next_output_byte = dest->buffer;
+ dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
+}
+
+
+/*
+ * Empty the output buffer --- called whenever buffer fills up.
+ *
+ * In typical applications, this should write the entire output buffer
+ * (ignoring the current state of next_output_byte & free_in_buffer),
+ * reset the pointer & count to the start of the buffer, and return TRUE
+ * indicating that the buffer has been dumped.
+ *
+ * In applications that need to be able to suspend compression due to output
+ * overrun, a FALSE return indicates that the buffer cannot be emptied now.
+ * In this situation, the compressor will return to its caller (possibly with
+ * an indication that it has not accepted all the supplied scanlines). The
+ * application should resume compression after it has made more room in the
+ * output buffer. Note that there are substantial restrictions on the use of
+ * suspension --- see the documentation.
+ *
+ * When suspending, the compressor will back up to a convenient restart point
+ * (typically the start of the current MCU). next_output_byte & free_in_buffer
+ * indicate where the restart point will be if the current call returns FALSE.
+ * Data beyond this point will be regenerated after resumption, so do not
+ * write it out when emptying the buffer externally.
+ */
+
+METHODDEF(boolean)
+empty_output_buffer (j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+
+#if 0
+ if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
+ (size_t) OUTPUT_BUF_SIZE)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+#else
+ dest->outfile->write((char*)dest->buffer, OUTPUT_BUF_SIZE);
+ if( dest->outfile->fail() )
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+#endif
+
+ dest->pub.next_output_byte = dest->buffer;
+ dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
+
+ return TRUE;
+}
+
+
+/*
+ * Terminate destination --- called by jpeg_finish_compress
+ * after all data has been written. Usually needs to flush buffer.
+ *
+ * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
+ * application must deal with any cleanup that should happen even
+ * for error exit.
+ */
+
+METHODDEF(void)
+term_destination (j_compress_ptr cinfo)
+{
+ my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
+ size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
+
+ /* Write any data remaining in the buffer */
+#if 0
+ if (datacount > 0) {
+ if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+ }
+ fflush(dest->outfile);
+ /* Make sure we wrote the output file OK */
+ if (ferror(dest->outfile))
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+#else
+ if (datacount > 0) {
+ dest->outfile->write((char*)dest->buffer, datacount);
+ if (dest->outfile->fail())
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+ dest->outfile->flush();
+ /* Make sure we wrote the output file OK */
+ if (dest->outfile->fail())
+ ERREXIT(cinfo, JERR_FILE_WRITE);
+ }
+#endif
+}
+
+
+/*
+ * Prepare for output to a stdio stream.
+ * The caller must have already opened the stream, and is responsible
+ * for closing it after finishing compression.
+ */
+
+GLOBAL(void)
+jpeg_stdio_dest (j_compress_ptr cinfo, std::ofstream * outfile)
+{
+ my_dest_ptr dest;
+
+ /* The destination object is made permanent so that multiple JPEG images
+ * can be written to the same file without re-executing jpeg_stdio_dest.
+ * This makes it dangerous to use this manager and a different destination
+ * manager serially with the same JPEG object, because their private object
+ * sizes may be different. Caveat programmer.
+ */
+ if (cinfo->dest == NULL) { /* first time for this JPEG object? */
+ cinfo->dest = (struct jpeg_destination_mgr *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ SIZEOF(my_destination_mgr));
+ }
+
+ dest = (my_dest_ptr) cinfo->dest;
+ dest->pub.init_destination = init_destination;
+ dest->pub.empty_output_buffer = empty_output_buffer;
+ dest->pub.term_destination = term_destination;
+ dest->outfile = outfile;
+}
--- /dev/null
+/*
+ * jdatasrc.c
+ *
+ * Copyright (C) 1994-1996, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains decompression data source routines for the case of
+ * reading JPEG data from a file (or any stdio stream). While these routines
+ * are sufficient for most applications, some will want to use a different
+ * source manager.
+ * IMPORTANT: we assume that fread() will correctly transcribe an array of
+ * JOCTETs from 8-bit-wide elements on external storage. If char is wider
+ * than 8 bits on your machine, you may need to do some tweaking.
+ */
+
+/* this is not a core library module, so it doesn't define JPEG_INTERNALS */
+
+/* Expanded data source object for stdio input */
+
+typedef struct {
+ struct jpeg_source_mgr pub; /* public fields */
+
+ std::ifstream *infile; /* source stream */
+ JOCTET * buffer; /* start of buffer */
+ boolean start_of_file; /* have we gotten any data yet? */
+} my_source_mgr;
+
+typedef my_source_mgr * my_src_ptr;
+
+#define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
+
+
+/*
+ * Initialize source --- called by jpeg_read_header
+ * before any data is actually read.
+ */
+
+METHODDEF(void)
+init_source (j_decompress_ptr cinfo)
+{
+ my_src_ptr src = (my_src_ptr) cinfo->src;
+
+ /* We reset the empty-input-file flag for each image,
+ * but we don't clear the input buffer.
+ * This is correct behavior for reading a series of images from one source.
+ */
+ src->start_of_file = TRUE;
+}
+
+
+/*
+ * Fill the input buffer --- called whenever buffer is emptied.
+ *
+ * In typical applications, this should read fresh data into the buffer
+ * (ignoring the current state of next_input_byte & bytes_in_buffer),
+ * reset the pointer & count to the start of the buffer, and return TRUE
+ * indicating that the buffer has been reloaded. It is not necessary to
+ * fill the buffer entirely, only to obtain at least one more byte.
+ *
+ * There is no such thing as an EOF return. If the end of the file has been
+ * reached, the routine has a choice of ERREXIT() or inserting fake data into
+ * the buffer. In most cases, generating a warning message and inserting a
+ * fake EOI marker is the best course of action --- this will allow the
+ * decompressor to output however much of the image is there. However,
+ * the resulting error message is misleading if the real problem is an empty
+ * input file, so we handle that case specially.
+ *
+ * In applications that need to be able to suspend compression due to input
+ * not being available yet, a FALSE return indicates that no more data can be
+ * obtained right now, but more may be forthcoming later. In this situation,
+ * the decompressor will return to its caller (with an indication of the
+ * number of scanlines it has read, if any). The application should resume
+ * decompression after it has loaded more data into the input buffer. Note
+ * that there are substantial restrictions on the use of suspension --- see
+ * the documentation.
+ *
+ * When suspending, the decompressor will back up to a convenient restart point
+ * (typically the start of the current MCU). next_input_byte & bytes_in_buffer
+ * indicate where the restart point will be if the current call returns FALSE.
+ * Data beyond this point must be rescanned after resumption, so move it to
+ * the front of the buffer rather than discarding it.
+ */
+
+METHODDEF(boolean)
+fill_input_buffer (j_decompress_ptr cinfo)
+{
+ my_src_ptr src = (my_src_ptr) cinfo->src;
+
+ src->infile->read( (char*)src->buffer, INPUT_BUF_SIZE);
+ size_t nbytes = src->infile->gcount();
+
+ if (nbytes <= 0) {
+ if (src->start_of_file) /* Treat empty input file as fatal error */
+ ERREXIT(cinfo, JERR_INPUT_EMPTY);
+ WARNMS(cinfo, JWRN_JPEG_EOF);
+ /* Insert a fake EOI marker */
+ src->buffer[0] = (JOCTET) 0xFF;
+ src->buffer[1] = (JOCTET) JPEG_EOI;
+ nbytes = 2;
+ }
+
+ src->pub.next_input_byte = src->buffer;
+ src->pub.bytes_in_buffer = nbytes;
+ src->start_of_file = FALSE;
+
+ return TRUE;
+}
+
+
+/*
+ * Skip data --- used to skip over a potentially large amount of
+ * uninteresting data (such as an APPn marker).
+ *
+ * Writers of suspendable-input applications must note that skip_input_data
+ * is not granted the right to give a suspension return. If the skip extends
+ * beyond the data currently in the buffer, the buffer can be marked empty so
+ * that the next read will cause a fill_input_buffer call that can suspend.
+ * Arranging for additional bytes to be discarded before reloading the input
+ * buffer is the application writer's problem.
+ */
+
+METHODDEF(void)
+skip_input_data (j_decompress_ptr cinfo, long num_bytes)
+{
+ my_src_ptr src = (my_src_ptr) cinfo->src;
+
+ /* Just a dumb implementation for now. Could use fseek() except
+ * it doesn't work on pipes. Not clear that being smart is worth
+ * any trouble anyway --- large skips are infrequent.
+ */
+ if (num_bytes > 0) {
+ while (num_bytes > (long) src->pub.bytes_in_buffer) {
+ num_bytes -= (long) src->pub.bytes_in_buffer;
+ (void) fill_input_buffer(cinfo);
+ /* note we assume that fill_input_buffer will never return FALSE,
+ * so suspension need not be handled.
+ */
+ }
+ src->pub.next_input_byte += (size_t) num_bytes;
+ src->pub.bytes_in_buffer -= (size_t) num_bytes;
+ }
+}
+
+
+/*
+ * An additional method that can be provided by data source modules is the
+ * resync_to_restart method for error recovery in the presence of RST markers.
+ * For the moment, this source module just uses the default resync method
+ * provided by the JPEG library. That method assumes that no backtracking
+ * is possible.
+ */
+
+
+/*
+ * Terminate source --- called by jpeg_finish_decompress
+ * after all data has been read. Often a no-op.
+ *
+ * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
+ * application must deal with any cleanup that should happen even
+ * for error exit.
+ */
+
+METHODDEF(void)
+term_source (j_decompress_ptr cinfo)
+{
+ cinfo=cinfo;
+ /* no work necessary here */
+}
+
+
+/*
+ * Prepare for input from a stdio stream.
+ * The caller must have already opened the stream, and is responsible
+ * for closing it after finishing decompression.
+ */
+
+GLOBAL(void)
+jpeg_stdio_src (j_decompress_ptr cinfo, std::ifstream * infile)
+{
+ my_src_ptr src;
+
+ /* The source object and input buffer are made permanent so that a series
+ * of JPEG images can be read from the same file by calling jpeg_stdio_src
+ * only before the first one. (If we discarded the buffer at the end of
+ * one image, we'd likely lose the start of the next one.)
+ * This makes it unsafe to use this manager and a different source
+ * manager serially with the same JPEG object. Caveat programmer.
+ */
+ if (cinfo->src == NULL) { /* first time for this JPEG object? */
+ cinfo->src = (struct jpeg_source_mgr *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ SIZEOF(my_source_mgr));
+ src = (my_src_ptr) cinfo->src;
+ src->buffer = (JOCTET *)
+ (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ INPUT_BUF_SIZE * SIZEOF(JOCTET));
+ }
+
+ src = (my_src_ptr) cinfo->src;
+ src->pub.init_source = init_source;
+ src->pub.fill_input_buffer = fill_input_buffer;
+ src->pub.skip_input_data = skip_input_data;
+ src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
+ src->pub.term_source = term_source;
+ src->infile = infile;
+ src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
+ src->pub.next_input_byte = NULL; /* until buffer loaded */
+}
# compression library object files
SET(compression_SRCS
-jcapimin.c jcapistd.c jctrans.c jcparam.c jdatadst.c jcinit.c
+jcapimin.c jcapistd.c jctrans.c jcparam.c jcinit.c
jcmaster.c jcmarker.c jcmainct.c jcprepct.c jccoefct.c jccolor.c
jcsample.c jchuff.c jcphuff.c jcdctmgr.c jfdctfst.c jfdctflt.c
)
-
+#jdatadst.c
# Lossy (DCT) codec:
SET(comp_lossy_SRCS
jfdctint.c
# decompression library object files
SET(decompression_SRCS
-jdapimin.c jdapistd.c jdtrans.c jdatasrc.c jdmaster.c
+jdapimin.c jdapistd.c jdtrans.c jdmaster.c
jdinput.c jdmarker.c jdhuff.c jdphuff.c jdmainct.c jdcoefct.c
jdpostct.c jddctmgr.c jidctfst.c jidctflt.c jidctint.c jidctred.c
-jdsample.c jdcolor.c jquant1.c jquant2.c jdmerge.c)
+jdsample.c jdcolor.c jquant1.c jquant2.c jdmerge.c
+) #jdatasrc.c
SET(decomp_lossy_SRCS
jdlossls.c jdlossy.c
* CAUTION: argument order is different from underlying functions!
*/
-#define JFREAD(file,buf,sizeofbuf) \
+/*#define JFREAD(file,buf,sizeofbuf) \
((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
#define JFWRITE(file,buf,sizeofbuf) \
- ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
+ ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))*/