00001 #include <vil/vil_config.h> 00002 #if HAS_DCMTK 00003 00004 #include "vil_dicom_stream.h" 00005 #include <vil/vil_stream.h> 00006 #include <dcerror.h> 00007 00008 #include <vcl_cassert.h> 00009 #include <vcl_limits.h> 00010 00011 // =========================================================================== 00012 // stream producer 00013 00014 vil_dicom_stream_producer:: 00015 vil_dicom_stream_producer( vil_stream* in_vs ) 00016 : vs_( in_vs ) 00017 { 00018 vs_->ref(); 00019 } 00020 00021 00022 vil_dicom_stream_producer:: 00023 ~vil_dicom_stream_producer() 00024 { 00025 vs_->unref(); 00026 } 00027 00028 00029 OFBool 00030 vil_dicom_stream_producer:: 00031 good() const 00032 { 00033 return vs_->ok(); 00034 } 00035 00036 00037 OFCondition 00038 vil_dicom_stream_producer:: 00039 status() const 00040 { 00041 return good() ? EC_Normal : EC_InvalidStream; 00042 } 00043 00044 00045 OFBool 00046 vil_dicom_stream_producer:: 00047 eos() const 00048 { 00049 return vs_->tell() >= vs_->file_size(); 00050 } 00051 00052 00053 Uint32 00054 vil_dicom_stream_producer:: 00055 avail() const 00056 { 00057 vil_streampos n = vs_->file_size() - vs_->tell(); 00058 assert( n >= 0 ); 00059 //assert ensures that the cast will succeed. 00060 //apparently dicom streams only support 32 bit positions 00061 //whereas vil_streams now support 64 bit positions (when 00062 //available) 00063 assert( n <= vcl_numeric_limits<Uint32>::max() ); 00064 return (Uint32)n; 00065 } 00066 00067 00068 Uint32 00069 vil_dicom_stream_producer:: 00070 read( void *buf, Uint32 buflen ) 00071 { 00072 vil_streampos n = vs_->read( buf, buflen ); 00073 //assert ensures that the cast will succeed. 00074 //apparently dicom streams only support 32 bit positions 00075 //whereas vil_streams now support 64 bit positions (when 00076 //available) 00077 assert( n <= vcl_numeric_limits<Uint32>::max() ); 00078 return (Uint32)n; 00079 } 00080 00081 00082 Uint32 00083 vil_dicom_stream_producer:: 00084 skip(Uint32 skiplen) 00085 { 00086 vs_->seek( vs_->tell() + skiplen ); 00087 return skiplen; 00088 } 00089 00090 00091 void 00092 vil_dicom_stream_producer:: 00093 putback(Uint32 num) 00094 { 00095 vs_->seek( vs_->tell() - (long int)num ); 00096 } 00097 00098 00099 // =========================================================================== 00100 // stream factory 00101 00102 vil_dicom_stream_factory:: 00103 vil_dicom_stream_factory( vil_stream* in_vs ) 00104 : vs_( in_vs ) 00105 { 00106 vs_->ref(); 00107 } 00108 00109 vil_dicom_stream_factory:: 00110 ~vil_dicom_stream_factory() 00111 { 00112 vs_->unref(); 00113 } 00114 00115 00116 DcmInputStream* 00117 vil_dicom_stream_factory:: 00118 create() const 00119 { 00120 return new vil_dicom_stream_input( vs_ ); 00121 } 00122 00123 00124 // =========================================================================== 00125 // stream input 00126 00127 vil_dicom_stream_input:: 00128 vil_dicom_stream_input( vil_stream* vs ) 00129 : DcmInputStream( new vil_dicom_stream_producer( vs ) ) 00130 { 00131 } 00132 00133 00134 vil_dicom_stream_input:: 00135 ~vil_dicom_stream_input() 00136 { 00137 delete currentProducer(); 00138 } 00139 00140 00141 DcmInputStreamFactory* 00142 vil_dicom_stream_input:: 00143 newFactory() const 00144 { 00145 return 0; 00146 } 00147 00148 #endif // HAS_DCMTK