# Dirac - A Video Codec

Created by the British Broadcasting Corporation.

# pic_io.h

Go to the documentation of this file.

    00001 /* ***** BEGIN LICENSE BLOCK *****
    00002 *
    00003 * $Id: pic_io.h,v 1.13 2006/04/20 10:41:57 asuraparaju Exp $ $Name: Dirac_0_7_0 $
    00004 *
    00005 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
    00006 *
    00007 * The contents of this file are subject to the Mozilla Public License
    00008 * Version 1.1 (the "License"); you may not use this file except in compliance
    00009 * with the License. You may obtain a copy of the License at
    00010 * http://www.mozilla.org/MPL/
    00011 *
    00012 * Software distributed under the License is distributed on an "AS IS" basis,
    00013 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
    00014 * the specific language governing rights and limitations under the License.
    00015 *
    00016 * The Original Code is BBC Research and Development code.
    00017 *
    00018 * The Initial Developer of the Original Code is the British Broadcasting
    00019 * Corporation.
    00020 * Portions created by the Initial Developer are Copyright (C) 2004.
    00021 * All Rights Reserved.
    00022 *
    00023 * Contributor(s): Thomas Davies (Original Author),
    00024 *                 Scott Robert Ladd,
    00025 *                 Stuart Cunningham,
    00026 *                 Tim Borer,
    00027 *                 Anuradha Suraparaju
    00028 *
    00029 * Alternatively, the contents of this file may be used under the terms of
    00030 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
    00031 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
    00032 * the GPL or the LGPL are applicable instead of those above. If you wish to
    00033 * allow use of your version of this file only under the terms of the either
    00034 * the GPL or LGPL and not to allow others to use your version of this file
    00035 * under the MPL, indicate your decision by deleting the provisions above
    00036 * and replace them with the notice and other provisions required by the GPL
    00037 * or LGPL. If you do not delete the provisions above, a recipient may use
    00038 * your version of this file under the terms of any one of the MPL, the GPL
    00039 * or the LGPL.
    00040 * ***** END LICENSE BLOCK ***** */
    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     //-Uncompressed picture file IO wrapper-//
    00058     //-                                    -//
    00059     //--------------------------------------//
    00061
    00062     // Stream classes for writing/reading frames of uncompressed/decoded data
    00063     // to stream. Streams currently supported are Memory based streams and
    00064     // File based streams. These classes need further restructuring.
    00065     // Anu - 19-11-2004
    00066
    00067     // Subclass these to provide functionality for different file formats and
    00068     // for streaming.
    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
    00223             FileStreamOutput (const char* output_name,
    00224               const SeqParams& sp);
    00225
    00227             virtual ~FileStreamOutput ();
    00228
    00229         protected:
    00230
    00232             virtual bool OpenYUV(const char* output_name);
    00233     };
    00234
    00236
    00240     class StreamPicInput
    00241     {
    00242         public:
    00243
    00245             StreamPicInput();
    00247
    00252             StreamPicInput(std::istream *ip_pic_ptr, const SeqParams& sparams);
    00253
    00255             virtual ~StreamPicInput();
    00256
    00258             virtual void Skip( const int n) = 0;
    00259
    00261             void SetPadding(const int xpd, const int ypd);
    00262
    00264             virtual bool ReadNextFrame(Frame& myframe);
    00265
    00267             SeqParams& GetSeqParams() const {return m_sparams;}
    00268
    00270             bool End() const ;
    00271
    00272         protected:
    00273
    00275             mutable SeqParams m_sparams;
    00276
    00278             std::istream* m_ip_pic_ptr;
    00279
    00281             int m_xpad,m_ypad;
    00282
    00284             virtual bool ReadComponent(PicArray& pic_data,const CompSort& cs);
    00285     };
    00286
    00290     class MemoryStreamInput : public StreamPicInput
    00291     {
    00292         public:
    00294             MemoryStreamInput();
    00295
    00297             ~MemoryStreamInput();
    00298
    00300             void SetSequenceParams ( SeqParams &sparams)
    00301             { m_sparams = sparams; }
    00302
    00304
    00308             void SetMembufReference (unsigned char *buf, int buf_size);
    00309
    00311             bool End() const ;
    00312
    00314             virtual void Skip( const int n);
    00315
    00316         protected:
    00318             MemoryStreamInput(const MemoryStreamInput&);
    00320             MemoryStreamInput & operator =(const MemoryStreamInput&);
    00321
    00322         protected:
    00324             class InputMemoryBuffer : public std::streambuf
    00325             {
    00326             public:
    00328                 InputMemoryBuffer() : m_buffer(0), m_buffer_size(0)
    00329                 {
    00330                     setg ((char *)m_buffer, (char *)m_buffer, (char *)m_buffer);
    00331                 }
    00332
    00334                 ~InputMemoryBuffer(){}
    00335
    00337
    00341                 void SetMembufReference (unsigned char *buffer, int buffer_size)
    00342                 {
    00343                     m_buffer = buffer;
    00344                     m_buffer_size = buffer_size;
    00345
    00346                     setg ((char *)m_buffer, (char *)m_buffer,
    00347                                 (char *)(m_buffer + buffer_size));
    00348                 }
    00349
    00350             private:
    00352                 InputMemoryBuffer (const InputMemoryBuffer& inbuf);
    00354                 InputMemoryBuffer& operator = (const InputMemoryBuffer& inbuf);
    00355
    00357                 unsigned char *m_buffer;
    00359                 int m_buffer_size;
    00360             };
    00361
    00363             InputMemoryBuffer m_membuf;
    00364     };
    00365
    00367
    00370     class FileStreamInput : public StreamPicInput
    00371     {
    00372         public:
    00373
    00375
    00380             FileStreamInput (const char* input_name, const SeqParams &sparams);
    00381
    00383             virtual ~FileStreamInput ();
    00384
    00386             virtual void Skip( const int n);
    00387
    00388     };
    00389
    00390 } // namespace dirac
    00391
    00392 #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.