00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef _PIC_IO_H_
00043 #define _PIC_IO_H_
00044
00045 #include <iostream>
00046 #include <fstream>
00047 #include <streambuf>
00048
00049 #include <libdirac_common/common.h>
00050 #include <libdirac_common/frame.h>
00051
00052 namespace dirac
00053 {
00055
00056
00057
00058
00059
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00072
00073
00077 class StreamPicOutput
00078 {
00079 public:
00080
00082 StreamPicOutput();
00084
00088 StreamPicOutput( const SeqParams& sp);
00089
00091 virtual ~StreamPicOutput();
00092
00094 virtual bool WriteNextFrame(const Frame& myframe);
00095
00097 SeqParams& GetSeqParams() {return m_sparams;}
00098
00099 protected:
00100
00102 SeqParams m_sparams;
00104 std::ostream* m_op_pic_ptr;
00105
00107 virtual bool WriteComponent(const PicArray& pic_data,
00108 const CompSort& cs);
00109 };
00110
00114 class MemoryStreamOutput : public StreamPicOutput
00115 {
00116 public:
00118 MemoryStreamOutput();
00119
00121 ~MemoryStreamOutput();
00122
00124 void SetSequenceParams ( SeqParams &sparams)
00125 { m_sparams = sparams; }
00126
00128 void SetMembufReference (unsigned char *buf, int buf_size);
00129
00131 bool End() const ;
00132
00133 protected:
00135 MemoryStreamOutput(const MemoryStreamOutput&);
00137 MemoryStreamOutput & operator =(const MemoryStreamOutput&);
00138
00139 protected:
00140
00142 class OutputMemoryBuffer : public std::streambuf
00143 {
00144 public:
00146 OutputMemoryBuffer () :
00147 m_op_buf(0),
00148 m_op_buf_size(0),
00149 m_op_idx(0)
00150 {}
00151
00153
00157 void SetMembufReference (unsigned char *buffer, int buffer_size)
00158 {
00159 m_op_buf = buffer;
00160 m_op_buf_size = buffer_size;
00161 m_op_idx = 0;
00162 }
00163
00164 protected:
00166 unsigned char *m_op_buf;
00168 int m_op_buf_size;
00170 int m_op_idx;
00171
00173 virtual int overflow (int c)
00174 {
00175 if ( c != EOF)
00176 {
00177 if (m_op_idx == m_op_buf_size)
00178 return EOF;
00179
00180 m_op_buf[m_op_idx] = (char)c;
00181 m_op_idx++;
00182 }
00183 return c;
00184 }
00185
00187 virtual std::streamsize xsputn (const char *s,
00188 std::streamsize num)
00189 {
00190 std::streamsize bytes_left = m_op_buf_size - m_op_idx;
00191 std::streamsize bytes_written = bytes_left > num
00192 ? num : bytes_left;
00193 memcpy (&m_op_buf[m_op_idx], (unsigned char *)s,
00194 bytes_written);
00195 m_op_idx += bytes_written;
00196 return bytes_written;
00197 }
00198
00199 private:
00201 OutputMemoryBuffer(const OutputMemoryBuffer&);
00203 OutputMemoryBuffer& operator =(const OutputMemoryBuffer&);
00204 };
00205
00207 OutputMemoryBuffer m_membuf;
00208 };
00209
00213 class FileStreamOutput : public StreamPicOutput
00214 {
00215 public:
00216
00218
00224 FileStreamOutput (const char* output_name,
00225 const SeqParams& sp,
00226 bool write_header_only = false);
00227
00229 virtual ~FileStreamOutput ();
00230
00232 virtual bool WritePicHeader();
00233
00234 protected:
00235
00237 std::ofstream* m_op_head_ptr;
00238
00240 virtual bool OpenHeader(const char* output_name);
00241
00243 virtual bool OpenYUV(const char* output_name);
00244 };
00245
00247
00251 class StreamPicInput
00252 {
00253 public:
00254
00256 StreamPicInput();
00258
00263 StreamPicInput(std::istream *ip_pic_ptr, const SeqParams& sparams);
00264
00266 virtual ~StreamPicInput();
00267
00269 virtual void Skip( const int n) = 0;
00270
00272 void SetPadding(const int xpd, const int ypd);
00273
00275 virtual bool ReadNextFrame(Frame& myframe);
00276
00278 const SeqParams& GetSeqParams() const {return m_sparams;}
00279
00281 bool End() const ;
00282
00283 protected:
00284
00286 SeqParams m_sparams;
00287
00289 std::istream* m_ip_pic_ptr;
00290
00292 int m_xpad,m_ypad;
00293
00295 virtual bool ReadComponent(PicArray& pic_data,const CompSort& cs);
00296 };
00297
00301 class MemoryStreamInput : public StreamPicInput
00302 {
00303 public:
00305 MemoryStreamInput();
00306
00308 ~MemoryStreamInput();
00309
00311 void SetSequenceParams ( SeqParams &sparams)
00312 { m_sparams = sparams; }
00313
00315
00319 void SetMembufReference (unsigned char *buf, int buf_size);
00320
00322 bool End() const ;
00323
00325 virtual void Skip( const int n);
00326
00327 protected:
00329 MemoryStreamInput(const MemoryStreamInput&);
00331 MemoryStreamInput & operator =(const MemoryStreamInput&);
00332
00333 protected:
00335 class InputMemoryBuffer : public std::streambuf
00336 {
00337 public:
00339 InputMemoryBuffer() : m_buffer(0), m_buffer_size(0)
00340 {
00341 setg ((char *)m_buffer, (char *)m_buffer, (char *)m_buffer);
00342 }
00343
00345 ~InputMemoryBuffer(){}
00346
00348
00352 void SetMembufReference (unsigned char *buffer, int buffer_size)
00353 {
00354 m_buffer = buffer;
00355 m_buffer_size = buffer_size;
00356
00357 setg ((char *)m_buffer, (char *)m_buffer,
00358 (char *)(m_buffer + buffer_size));
00359 }
00360
00361 private:
00363 InputMemoryBuffer (const InputMemoryBuffer& inbuf);
00365 InputMemoryBuffer& operator = (const InputMemoryBuffer& inbuf);
00366
00368 unsigned char *m_buffer;
00370 int m_buffer_size;
00371 };
00372
00374 InputMemoryBuffer m_membuf;
00375 };
00376
00378
00381 class FileStreamInput : public StreamPicInput
00382 {
00383 public:
00384
00386
00390 FileStreamInput (const char* input_name);
00391
00393 virtual ~FileStreamInput ();
00394
00396 virtual bool ReadPicHeader();
00397
00399 virtual void Skip( const int n);
00400
00401
00402 protected:
00404 std::ifstream* m_ip_head_ptr;
00405 };
00406
00407 }
00408
00409 #endif