Created by the British Broadcasting Corporation.
00001 /* ***** BEGIN LICENSE BLOCK ***** 00002 * 00003 * $Id: pic_io.h,v 1.16 2007/09/26 12:23:31 asuraparaju Exp $ $Name: Dirac_0_8_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_buffer.h> 00051 00052 namespace dirac 00053 { 00054 class FrameBuffer; 00055 00057 //--------------------------------------// 00058 //- -// 00059 //-Uncompressed picture file IO wrapper-// 00060 //- -// 00061 //--------------------------------------// 00063 00064 // Stream classes for writing/reading frames of uncompressed/decoded data 00065 // to stream. Streams currently supported are Memory based streams and 00066 // File based streams. These classes need further restructuring. 00067 // Anu - 19-11-2004 00068 00069 // Subclass these to provide functionality for different file formats and 00070 // for streaming. 00071 00072 00074 00075 00079 class StreamPicOutput 00080 { 00081 public: 00083 00088 StreamPicOutput( std::ostream* op_ptr, const SourceParams& sp); 00089 00091 virtual ~StreamPicOutput(); 00092 00094 virtual bool WriteNextFrame(const Frame& myframe) = 0; 00095 00097 SourceParams& GetSourceParams() {return m_sparams;} 00098 00099 protected: 00101 SourceParams m_sparams; 00103 std::ostream* m_op_pic_ptr; 00104 00106 StreamPicOutput(); 00107 private: 00108 00109 }; 00110 00111 class StreamFrameOutput : public StreamPicOutput 00112 { 00113 public: 00114 00120 StreamFrameOutput( std::ostream *op_ptr, const SourceParams& sp); 00121 00123 virtual ~StreamFrameOutput(); 00124 00126 bool WriteNextFrame(const Frame& myframe); 00127 00128 protected: 00130 bool WriteFrameComponent(const PicArray& pic_data, 00131 const CompSort& cs); 00132 private: 00134 StreamFrameOutput(); 00135 }; 00136 00137 class StreamFieldOutput : public StreamPicOutput 00138 { 00139 public: 00141 00146 StreamFieldOutput( std::ostream *op_ptr, const SourceParams& sp); 00147 00149 virtual ~StreamFieldOutput(); 00150 00152 bool WriteNextFrame(const Frame& myframe); 00153 00154 protected: 00156 bool WriteFieldComponent(const PicArray& pic_data, 00157 int field_num, 00158 const CompSort& cs); 00159 00160 private: 00162 StreamFieldOutput(); 00163 unsigned char *m_frame_store; 00164 }; 00165 00169 class MemoryStreamOutput 00170 { 00171 public: 00173 MemoryStreamOutput(SourceParams &sparams, bool interlace); 00174 00176 ~MemoryStreamOutput(); 00177 00179 SourceParams& GetSourceParams() 00180 { return m_op_pic_str->GetSourceParams();} 00181 00182 StreamPicOutput *GetStream() { return m_op_pic_str; } 00184 void SetMembufReference (unsigned char *buf, int buf_size); 00185 00186 protected: 00188 MemoryStreamOutput(); 00190 MemoryStreamOutput(const MemoryStreamOutput&); 00192 MemoryStreamOutput & operator =(const MemoryStreamOutput&); 00193 00194 protected: 00195 00197 class OutputMemoryBuffer : public std::streambuf 00198 { 00199 public: 00201 OutputMemoryBuffer () : 00202 m_op_buf(0), 00203 m_op_buf_size(0), 00204 m_op_idx(0) 00205 {} 00206 00208 00212 void SetMembufReference (unsigned char *buffer, int buffer_size) 00213 { 00214 m_op_buf = buffer; 00215 m_op_buf_size = buffer_size; 00216 m_op_idx = 0; 00217 } 00218 00219 protected: 00221 unsigned char *m_op_buf; 00223 int m_op_buf_size; 00225 int m_op_idx; 00226 00228 virtual int overflow (int c) 00229 { 00230 if ( c != EOF) 00231 { 00232 if (m_op_idx == m_op_buf_size) 00233 return EOF; 00234 00235 m_op_buf[m_op_idx] = (char)c; 00236 m_op_idx++; 00237 } 00238 return c; 00239 } 00240 00242 virtual std::streamsize xsputn (const char *s, 00243 std::streamsize num) 00244 { 00245 std::streamsize bytes_left = m_op_buf_size - m_op_idx; 00246 std::streamsize bytes_written = bytes_left > num 00247 ? num : bytes_left; 00248 memcpy (&m_op_buf[m_op_idx], (unsigned char *)s, 00249 bytes_written); 00250 m_op_idx += bytes_written; 00251 return bytes_written; 00252 } 00253 00254 private: 00256 OutputMemoryBuffer(const OutputMemoryBuffer&); 00258 OutputMemoryBuffer& operator =(const OutputMemoryBuffer&); 00259 }; 00260 00261 private: 00263 OutputMemoryBuffer m_membuf; 00265 std::ostream* m_op_pic_ptr; 00267 StreamPicOutput *m_op_pic_str; 00268 }; 00269 00273 class FileStreamOutput 00274 { 00275 public: 00276 00278 00284 FileStreamOutput (const char* output_name, 00285 const SourceParams& sp, bool interlace); 00286 00288 virtual ~FileStreamOutput (); 00289 00290 StreamPicOutput *GetStream() { return m_op_pic_str; } 00291 private: 00293 std::ostream* m_op_pic_ptr; 00295 StreamPicOutput *m_op_pic_str; 00296 }; 00297 00299 00303 class StreamPicInput 00304 { 00305 public: 00306 00308 StreamPicInput(); 00310 00315 StreamPicInput(std::istream *ip_pic_ptr, const SourceParams& sparams); 00316 00318 virtual ~StreamPicInput(); 00319 00321 virtual void Skip( const int n)= 0; 00322 00324 virtual bool ReadNextPicture(Frame& myframe) = 0; 00325 00327 00332 virtual bool ReadNextFrame(FrameBuffer &my_fbuf, int fnum) = 0; 00333 00335 SourceParams& GetSourceParams() const {return m_sparams;} 00336 00338 bool End() const ; 00339 00340 protected: 00341 00343 mutable SourceParams m_sparams; 00344 00346 std::istream* m_ip_pic_ptr; 00347 00348 }; 00349 00350 class StreamFrameInput : public StreamPicInput 00351 { 00352 public: 00353 00355 StreamFrameInput(); 00357 00362 StreamFrameInput(std::istream *ip_pic_ptr, const SourceParams& sparams); 00363 00365 virtual ~StreamFrameInput(); 00366 00368 virtual void Skip( const int n); 00369 00371 virtual bool ReadNextPicture(Frame& myframe); 00372 00374 00379 virtual bool ReadNextFrame(FrameBuffer &my_fbuf, int fnum); 00380 00381 private: 00382 00384 bool ReadFrameComponent(PicArray& pic_data,const CompSort& cs); 00385 00386 }; 00387 00388 class StreamFieldInput : public StreamPicInput 00389 { 00390 public: 00391 00393 StreamFieldInput(); 00395 00400 StreamFieldInput(std::istream *ip_pic_ptr, const SourceParams& sparams); 00401 00403 virtual ~StreamFieldInput(); 00404 00406 virtual void Skip( const int n); 00407 00409 virtual bool ReadNextPicture(Frame& myframe); 00410 00412 00417 virtual bool ReadNextFrame(FrameBuffer &my_fbuf, int fnum); 00418 00419 protected: 00421 bool ReadFieldComponent(PicArray& pic_data1, 00422 PicArray& pic_data2, 00423 const CompSort& cs); 00424 00426 bool ReadFieldComponent(bool is_field1, PicArray& pic_data, 00427 const CompSort& cs); 00428 }; 00432 class MemoryStreamInput 00433 { 00434 public: 00436 00440 MemoryStreamInput(SourceParams& sparams, bool interlace); 00441 00443 ~MemoryStreamInput(); 00444 00445 SourceParams& GetSourceParams ( ) 00446 { return m_inp_str->GetSourceParams(); } 00447 00449 00453 void SetMembufReference (unsigned char *buf, int buf_size); 00454 00456 StreamPicInput *GetStream() { return m_inp_str; } 00457 protected: 00459 MemoryStreamInput(const MemoryStreamInput&); 00461 MemoryStreamInput & operator =(const MemoryStreamInput&); 00462 00463 protected: 00465 class InputMemoryBuffer : public std::streambuf 00466 { 00467 public: 00469 InputMemoryBuffer() : m_buffer(0), m_buffer_size(0) 00470 { 00471 setg ((char *)m_buffer, (char *)m_buffer, (char *)m_buffer); 00472 } 00473 00475 ~InputMemoryBuffer(){} 00476 00478 00482 void SetMembufReference (unsigned char *buffer, int buffer_size) 00483 { 00484 m_buffer = buffer; 00485 m_buffer_size = buffer_size; 00486 00487 setg ((char *)m_buffer, (char *)m_buffer, 00488 (char *)(m_buffer + buffer_size)); 00489 } 00490 00491 private: 00493 InputMemoryBuffer (const InputMemoryBuffer& inbuf); 00495 InputMemoryBuffer& operator = (const InputMemoryBuffer& inbuf); 00496 00498 unsigned char *m_buffer; 00500 int m_buffer_size; 00501 }; 00502 00503 private: 00505 InputMemoryBuffer m_membuf; 00506 00508 StreamPicInput *m_inp_str; 00509 00511 std::istream* m_ip_pic_ptr; 00512 }; 00513 00515 00518 class FileStreamInput 00519 { 00520 public: 00521 00523 00529 FileStreamInput (const char* input_name, const SourceParams &sparams, bool interlace); 00530 00532 virtual ~FileStreamInput (); 00533 00534 SourceParams& GetSourceParams ( ) 00535 { return m_inp_str->GetSourceParams(); } 00536 00538 StreamPicInput *GetStream() { return m_inp_str; } 00539 00540 private: 00541 StreamPicInput *m_inp_str; 00542 00544 std::istream* m_ip_pic_ptr; 00545 00546 }; 00547 00548 } // namespace dirac 00549 00550 #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.