Dirac - A Video Codec

Created by the British Broadcasting Corporation.


pic_io.h
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: pic_io.h,v 1.19 2008/06/19 10:17:17 tjdwave Exp $ $Name: Dirac_1_0_2 $
4 *
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 *
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 * the specific language governing rights and limitations under the License.
15 *
16 * The Original Code is BBC Research and Development code.
17 *
18 * The Initial Developer of the Original Code is the British Broadcasting
19 * Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
22 *
23 * Contributor(s): Thomas Davies (Original Author),
24 * Scott Robert Ladd,
25 * Stuart Cunningham,
26 * Tim Borer,
27 * Anuradha Suraparaju
28 *
29 * Alternatively, the contents of this file may be used under the terms of
30 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
31 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
32 * the GPL or the LGPL are applicable instead of those above. If you wish to
33 * allow use of your version of this file only under the terms of the either
34 * the GPL or LGPL and not to allow others to use your version of this file
35 * under the MPL, indicate your decision by deleting the provisions above
36 * and replace them with the notice and other provisions required by the GPL
37 * or LGPL. If you do not delete the provisions above, a recipient may use
38 * your version of this file under the terms of any one of the MPL, the GPL
39 * or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
41 
42 #ifndef _PIC_IO_H_
43 #define _PIC_IO_H_
44 
45 #include <iostream>
46 #include <fstream>
47 #include <streambuf>
48 
49 #include <libdirac_common/common.h>
51 
52 namespace dirac
53 {
54 
56  //--------------------------------------//
57  //- -//
58  //-Uncompressed picture file IO wrapper-//
59  //- -//
60  //--------------------------------------//
62 
63  // Stream classes for writing/reading frames of uncompressed/decoded data
64  // to stream. Streams currently supported are Memory based streams and
65  // File based streams. These classes need further restructuring.
66  // Anu - 19-11-2004
67 
68  // Subclass these to provide functionality for different file formats and
69  // for streaming.
70 
71 
73 
74 
79  {
80  public:
82 
87  StreamPicOutput( std::ostream* op_ptr, const SourceParams& sp);
88 
90  virtual ~StreamPicOutput();
91 
93  virtual bool WriteToNextFrame(const Picture& myframe) = 0;
94 
97 
98  protected:
102  std::ostream* m_op_pic_ptr;
103 
105  StreamPicOutput();
106  private:
107 
108  };
109 
111  {
112  public:
113 
119  StreamFrameOutput( std::ostream *op_ptr, const SourceParams& sp);
120 
122  virtual ~StreamFrameOutput();
123 
125  bool WriteToNextFrame(const Picture& myframe);
126 
127  protected:
129  bool WriteFrameComponent(const PicArray& pic_data,
130  const CompSort& cs);
131  private:
134  };
135 
137  {
138  public:
140 
145  StreamFieldOutput( std::ostream *op_ptr, const SourceParams& sp);
146 
148  virtual ~StreamFieldOutput();
149 
151  bool WriteToNextFrame(const Picture& myfield);
152 
153  protected:
155  bool WriteFieldComponent(const PicArray& pic_data,
156  int field_num,
157  const CompSort& cs);
158 
159  private:
162  unsigned char *m_frame_store;
163  };
164 
169  {
170  public:
172  MemoryStreamOutput(SourceParams &sparams, bool interlace);
173 
176 
179  { return m_op_pic_str->GetSourceParams();}
180 
183  void SetMembufReference (unsigned char *buf, int buf_size);
184 
185  protected:
192 
193  protected:
194 
196  class OutputMemoryBuffer : public std::streambuf
197  {
198  public:
201  m_op_buf(0),
202  m_op_buf_size(0),
203  m_op_idx(0)
204  {}
205 
207 
211  void SetMembufReference (unsigned char *buffer, int buffer_size)
212  {
213  m_op_buf = buffer;
214  m_op_buf_size = buffer_size;
215  m_op_idx = 0;
216  }
217 
218  protected:
220  unsigned char *m_op_buf;
224  int m_op_idx;
225 
227  virtual int overflow (int c)
228  {
229  if ( c != EOF)
230  {
231  if (m_op_idx == m_op_buf_size)
232  return EOF;
233 
234  m_op_buf[m_op_idx] = (char)c;
235  m_op_idx++;
236  }
237  return c;
238  }
239 
241  virtual std::streamsize xsputn (const char *s,
242  std::streamsize num)
243  {
244  std::streamsize bytes_left = m_op_buf_size - m_op_idx;
245  std::streamsize bytes_written = bytes_left > num
246  ? num : bytes_left;
247  memcpy (&m_op_buf[m_op_idx], (unsigned char *)s,
248  bytes_written);
249  m_op_idx += bytes_written;
250  return bytes_written;
251  }
252 
253  private:
258  };
259 
260  private:
264  std::ostream* m_op_pic_ptr;
267  };
268 
273  {
274  public:
275 
277 
283  FileStreamOutput (const char* output_name,
284  const SourceParams& sp, bool interlace);
285 
287  virtual ~FileStreamOutput ();
288 
290  private:
292  std::ostream* m_op_pic_ptr;
295  };
296 
298 
303  {
304  public:
305 
307  StreamPicInput();
309 
314  StreamPicInput(std::istream *ip_pic_ptr, const SourceParams& sparams);
315 
317  virtual ~StreamPicInput();
318 
320  virtual void Skip( const int n)= 0;
321 
323  virtual bool ReadNextPicture(Picture& mypic) = 0;
324 
327 
329  bool End() const ;
330 
331  protected:
332 
335 
337  std::istream* m_ip_pic_ptr;
338 
339  };
340 
342  {
343  public:
344 
348 
353  StreamFrameInput(std::istream *ip_pic_ptr, const SourceParams& sparams);
354 
356  virtual ~StreamFrameInput();
357 
359  virtual void Skip( const int n);
360 
362  virtual bool ReadNextPicture(Picture& myframe);
363 
364  private:
365 
367  bool ReadFrameComponent(PicArray& pic_data,const CompSort& cs);
368 
369  };
370 
372  {
373  public:
374 
378 
383  StreamFieldInput(std::istream *ip_pic_ptr, const SourceParams& sparams);
384 
386  virtual ~StreamFieldInput();
387 
389  virtual void Skip( const int n);
390 
392  virtual bool ReadNextPicture(Picture& myfield);
393 
395  bool ReadNextFrame(Picture& field1, Picture& field2);
396 
397  protected:
399  bool ReadFieldComponent(PicArray& pic_data1,
400  PicArray& pic_data2,
401  const CompSort& cs);
402 
404  bool ReadFieldComponent(bool is_field1, PicArray& pic_data,
405  const CompSort& cs);
406  };
411  {
412  public:
414 
418  MemoryStreamInput(SourceParams& sparams, bool field_input);
419 
422 
424  { return m_inp_str->GetSourceParams(); }
425 
427 
431  void SetMembufReference (unsigned char *buf, int buf_size);
432 
435  protected:
440 
441  protected:
443  class InputMemoryBuffer : public std::streambuf
444  {
445  public:
448  {
449  setg ((char *)m_buffer, (char *)m_buffer, (char *)m_buffer);
450  }
451 
454 
456 
460  void SetMembufReference (unsigned char *buffer, int buffer_size)
461  {
462  m_buffer = buffer;
463  m_buffer_size = buffer_size;
464 
465  setg ((char *)m_buffer, (char *)m_buffer,
466  (char *)(m_buffer + buffer_size));
467  }
468 
469  private:
471  InputMemoryBuffer (const InputMemoryBuffer& inbuf);
474 
476  unsigned char *m_buffer;
479  };
480 
481  private:
484 
487 
489  std::istream* m_ip_pic_ptr;
490  };
491 
493 
497  {
498  public:
499 
501 
507  FileStreamInput (const char* input_name, const SourceParams &sparams, bool interlace);
508 
510  virtual ~FileStreamInput ();
511 
513  { return m_inp_str->GetSourceParams(); }
514 
517 
518  private:
520 
522  std::istream* m_ip_pic_ptr;
523 
524  };
525 
526 } // namespace dirac
527 
528 #endif

© 2004 British Broadcasting Corporation. Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.