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
51
52namespace 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
91
93 virtual bool WriteToNextFrame(const Picture& myframe) = 0;
94
97
98 protected:
102 std::ostream* m_op_pic_ptr;
103
106 private:
107
108 };
109
111 {
112 public:
113
119 StreamFrameOutput( std::ostream *op_ptr, const SourceParams& sp);
120
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
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;
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
288
290 private:
292 std::ostream* m_op_pic_ptr;
295 };
296
298
303 {
304 public:
305
309
314 StreamPicInput(std::istream *ip_pic_ptr, const SourceParams& sparams);
315
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
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
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:
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:
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
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
Definition of class SequenceHeaderByteIO.
Definition: accessunit_byteio.h:52
CompSort
Types of picture component.
Definition: common.h:87
Parameters relating to the source material being encoded/decoded.
Definition: common.h:289
A class for picture component data.
Definition: common.h:719
Class for outputting pictures.
Definition: pic_io.h:79
StreamPicOutput(std::ostream *op_ptr, const SourceParams &sp)
Constructor.
StreamPicOutput()
Body-less default Constructor.
SourceParams m_sparams
Source parameters.
Definition: pic_io.h:100
std::ostream * m_op_pic_ptr
Output stream.
Definition: pic_io.h:102
virtual ~StreamPicOutput()
virtual Destructor
SourceParams & GetSourceParams()
Get the source parameters.
Definition: pic_io.h:96
virtual bool WriteToNextFrame(const Picture &myframe)=0
Write a picture to the next frame to be output.
Definition: pic_io.h:111
StreamFrameOutput(std::ostream *op_ptr, const SourceParams &sp)
StreamFrameOutput()
Body-less Default Constructor.
bool WriteToNextFrame(const Picture &myframe)
Write the next frame to the output.
bool WriteFrameComponent(const PicArray &pic_data, const CompSort &cs)
Write a frame component to file.
virtual ~StreamFrameOutput()
virtual Destructor
Definition: pic_io.h:137
StreamFieldOutput()
Body-less Default Constructor.
bool WriteFieldComponent(const PicArray &pic_data, int field_num, const CompSort &cs)
Write a field component to file.
bool WriteToNextFrame(const Picture &myfield)
Write a field to the next frame to be output.
unsigned char * m_frame_store
Definition: pic_io.h:162
StreamFieldOutput(std::ostream *op_ptr, const SourceParams &sp)
Constructor.
virtual ~StreamFieldOutput()
virtual Destructor
Definition: pic_io.h:169
SourceParams & GetSourceParams()
Get source parameters.
Definition: pic_io.h:178
MemoryStreamOutput()
Body-less default Constructor.
~MemoryStreamOutput()
Destructor.
StreamPicOutput * m_op_pic_str
Pic output Stream.
Definition: pic_io.h:266
MemoryStreamOutput(const MemoryStreamOutput &)
Body-less copy constructor.
OutputMemoryBuffer m_membuf
Output stream Memory buffer.
Definition: pic_io.h:262
MemoryStreamOutput & operator=(const MemoryStreamOutput &)
Body-less assignment operator.
MemoryStreamOutput(SourceParams &sparams, bool interlace)
Constructor.
StreamPicOutput * GetStream()
Definition: pic_io.h:181
void SetMembufReference(unsigned char *buf, int buf_size)
Set the memory buffer to write the data to.
std::ostream * m_op_pic_ptr
Physical Output stream.
Definition: pic_io.h:264
local memory buffer
Definition: pic_io.h:197
int m_op_buf_size
Memory buffer size.
Definition: pic_io.h:222
unsigned char * m_op_buf
Memory buffer to write data to.
Definition: pic_io.h:220
virtual std::streamsize xsputn(const char *s, std::streamsize num)
xsputn method to write one multiple chars at a time to buffer
Definition: pic_io.h:241
OutputMemoryBuffer(const OutputMemoryBuffer &)
Body-less copy constructor.
int m_op_idx
Index of first available byte in buffer.
Definition: pic_io.h:224
virtual int overflow(int c)
Write Overflow method to write one char at a time.
Definition: pic_io.h:227
OutputMemoryBuffer & operator=(const OutputMemoryBuffer &)
Body-less assignment operator.
void SetMembufReference(unsigned char *buffer, int buffer_size)
Set the buffer variables.
Definition: pic_io.h:211
OutputMemoryBuffer()
Memory buffer constructor.
Definition: pic_io.h:200
Definition: pic_io.h:273
virtual ~FileStreamOutput()
Destructor.
FileStreamOutput(const char *output_name, const SourceParams &sp, bool interlace)
Constructor.
StreamPicOutput * m_op_pic_str
Pic output Stream.
Definition: pic_io.h:294
std::ostream * m_op_pic_ptr
Physical Output stream.
Definition: pic_io.h:292
StreamPicOutput * GetStream()
Definition: pic_io.h:289
Picture input class.
Definition: pic_io.h:303
virtual bool ReadNextPicture(Picture &mypic)=0
Read the next picture frame/field from the file.
StreamPicInput(std::istream *ip_pic_ptr, const SourceParams &sparams)
Constructor.
virtual ~StreamPicInput()
Destructor.
SourceParams & GetSourceParams() const
Get the source parameters.
Definition: pic_io.h:326
bool End() const
Returns true if we're at the end of the input, false otherwise.
virtual void Skip(const int n)=0
Skip n frames of input.
StreamPicInput()
Default Constructor.
std::istream * m_ip_pic_ptr
Input stream.
Definition: pic_io.h:337
SourceParams m_sparams
Source parameters.
Definition: pic_io.h:334
Definition: pic_io.h:342
StreamFrameInput()
Default Constructor.
bool ReadFrameComponent(PicArray &pic_data, const CompSort &cs)
Read a Frame component from the file.
virtual void Skip(const int n)
Skip n frames of input.
virtual bool ReadNextPicture(Picture &myframe)
Read the next frame from the file.
virtual ~StreamFrameInput()
Destructor.
StreamFrameInput(std::istream *ip_pic_ptr, const SourceParams &sparams)
Constructor.
Definition: pic_io.h:372
virtual bool ReadNextPicture(Picture &myfield)
Read the next field from the file.
virtual void Skip(const int n)
Skip n frames of input.
virtual ~StreamFieldInput()
Destructor.
StreamFieldInput()
Default Constructor.
bool ReadFieldComponent(PicArray &pic_data1, PicArray &pic_data2, const CompSort &cs)
Read both Field components from the file.
bool ReadNextFrame(Picture &field1, Picture &field2)
Read the next frame from the file.
StreamFieldInput(std::istream *ip_pic_ptr, const SourceParams &sparams)
Constructor.
bool ReadFieldComponent(bool is_field1, PicArray &pic_data, const CompSort &cs)
Read one Field component from the file.
Definition: pic_io.h:411
MemoryStreamInput(SourceParams &sparams, bool field_input)
Constructor.
StreamPicInput * m_inp_str
Input Stream Object.
Definition: pic_io.h:486
std::istream * m_ip_pic_ptr
Input stream.
Definition: pic_io.h:489
void SetMembufReference(unsigned char *buf, int buf_size)
Set Memory buffer.
~MemoryStreamInput()
Destructor.
StreamPicInput * GetStream()
Return the input stream.
Definition: pic_io.h:434
MemoryStreamInput & operator=(const MemoryStreamInput &)
Body-less assignment operator.
MemoryStreamInput(const MemoryStreamInput &)
Body-less copy constructor.
InputMemoryBuffer m_membuf
Input stream buffer.
Definition: pic_io.h:483
SourceParams & GetSourceParams()
Definition: pic_io.h:423
Class that defines the Input Stream Memory Buffer.
Definition: pic_io.h:444
InputMemoryBuffer & operator=(const InputMemoryBuffer &inbuf)
Body-less assignment operator.
int m_buffer_size
Input memory buffer size.
Definition: pic_io.h:478
InputMemoryBuffer(const InputMemoryBuffer &inbuf)
Body-less copy constructor.
~InputMemoryBuffer()
Destructor.
Definition: pic_io.h:453
InputMemoryBuffer()
Constructor.
Definition: pic_io.h:447
unsigned char * m_buffer
Input memory buffer.
Definition: pic_io.h:476
void SetMembufReference(unsigned char *buffer, int buffer_size)
Set Input Memory buffer variables.
Definition: pic_io.h:460
Picture input class.
Definition: pic_io.h:497
FileStreamInput(const char *input_name, const SourceParams &sparams, bool interlace)
Constructor.
StreamPicInput * GetStream()
Return the input stream.
Definition: pic_io.h:516
StreamPicInput * m_inp_str
Definition: pic_io.h:519
SourceParams & GetSourceParams()
Definition: pic_io.h:512
virtual ~FileStreamInput()
Destructor.
std::istream * m_ip_pic_ptr
Input stream.
Definition: pic_io.h:522
A class for encapsulating all the data relating to a picture.
Definition: picture.h:52

© 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.