vconvert.h

Go to the documentation of this file.
00001 /*
00002  * vconvert.h
00003  *
00004  * Classes to support streaming video input (grabbing) and output.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-2000 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): Derek Smithies (derek@indranet.co.nz)
00025  *                 Thorsten Westheider (thorsten.westheider@teleos-web.de)
00026  *                 Mark Cooke (mpc@star.sr.bham.ac.uk)
00027  *
00028  * $Revision: 20385 $
00029  * $Author: rjongbloed $
00030  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00031  */
00032 
00033 #ifndef _PCONVERT
00034 #define _PCONVERT
00035 
00036 #ifdef P_USE_PRAGMA
00037 #ifndef P_MACOSX
00038 #pragma interface
00039 #endif
00040 #endif
00041 
00042 #include <ptbuildopts.h>
00043 
00044 #if P_VIDEO
00045 
00046 #include <ptlib/videoio.h>
00047 
00048 struct jdec_private;
00049 
00050 
00056 class PColourConverterRegistration : public PCaselessString
00057 {
00058     PCLASSINFO(PColourConverterRegistration, PCaselessString);
00059   public:
00060     PColourConverterRegistration(
00061       const PString & srcColourFormat,  
00062       const PString & destColourFormat  
00063     );
00064 
00065   protected:
00066     virtual PColourConverter * Create(
00067       const PVideoFrameInfo & src, 
00068       const PVideoFrameInfo & dst  
00069     ) const = 0;
00070 
00071     PColourConverterRegistration * link;
00072 
00073   friend class PColourConverter;
00074 };
00075 
00076 
00080 class PColourConverter : public PObject
00081 {
00082     PCLASSINFO(PColourConverter, PObject);
00083   public:
00086     PColourConverter(
00087       const PString & srcColourFormat,  
00088       const PString & dstColourFormat,  
00089       unsigned width,   
00090       unsigned height   
00091     );
00092     PColourConverter(
00093       const PVideoFrameInfo & src, 
00094       const PVideoFrameInfo & dst  
00095     );
00096 
00099     PBoolean GetVFlipState() 
00100       { return verticalFlip; }
00101     
00104     void SetVFlipState(PBoolean vFlipState) 
00105       { verticalFlip = vFlipState; }
00106     
00111     virtual PBoolean SetFrameSize(
00112       unsigned width,   
00113       unsigned height   
00114     );
00115 
00124     virtual PBoolean SetSrcFrameInfo(
00125       const PVideoFrameInfo & info   
00126     );
00127 
00136     virtual PBoolean SetDstFrameInfo(
00137       const PVideoFrameInfo & info  
00138     );
00139 
00142     virtual void GetSrcFrameInfo(
00143       PVideoFrameInfo & info   
00144     );
00145 
00148     virtual void GetDstFrameInfo(
00149       PVideoFrameInfo & info  
00150     );
00151 
00158     virtual PBoolean SetSrcFrameSize(
00159       unsigned width,   
00160       unsigned height   
00161     );
00162 
00169     virtual PBoolean SetDstFrameSize(
00170       unsigned width,  
00171       unsigned height 
00172     );
00173     virtual PBoolean SetDstFrameSize(
00174       unsigned width,  
00175       unsigned height, 
00176       PBoolean bScale
00177     );
00178 
00181     const PString & GetSrcColourFormat() { return srcColourFormat; }
00182 
00185     const PString & GetDstColourFormat() { return dstColourFormat; }
00186 
00192     PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; }
00193 
00199     PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; }
00200 
00201 
00211     virtual PBoolean Convert(
00212       const BYTE * srcFrameBuffer,  
00213       BYTE * dstFrameBuffer,        
00214       PINDEX * bytesReturned = NULL 
00215     ) = 0;
00216 
00217     virtual PBoolean Convert(
00218       const BYTE * srcFrameBuffer,  
00219       BYTE * dstFrameBuffer,        
00220       unsigned int srcFrameBytes,
00221       PINDEX * bytesReturned = NULL 
00222     ) = 0;
00223 
00240     virtual PBoolean ConvertInPlace(
00241       BYTE * frameBuffer,               
00242       PINDEX * bytesReturned = NULL,    
00243       PBoolean noIntermediateFrame = PFalse  
00244     );
00245 
00246 
00251     static PColourConverter * Create(
00252       const PVideoFrameInfo & src, 
00253       const PVideoFrameInfo & dst  
00254     );
00255     static PColourConverter * Create(
00256       const PString & srcColourFormat,
00257       const PString & destColourFormat,
00258       unsigned width,
00259       unsigned height
00260     );
00261 
00264     PBoolean GetDstFrameSize(
00265       unsigned & width, 
00266       unsigned & height 
00267     ) const;
00268 
00271     PBoolean GetSrcFrameSize(
00272       unsigned & width, 
00273       unsigned & height 
00274     ) const;
00275 
00276     unsigned GetSrcFrameWidth()  const { return srcFrameWidth;  }
00277     unsigned GetSrcFrameHeight() const { return srcFrameHeight; }
00278     unsigned GetDstFrameWidth()  const { return dstFrameWidth;  }
00279     unsigned GetDstFrameHeight() const { return dstFrameHeight; }
00280 
00283     void SetResizeMode(
00284       PVideoFrameInfo::ResizeMode mode
00285     ) { if (mode < PVideoFrameInfo::eMaxResizeMode) resizeMode = mode; }
00286 
00289     PVideoFrameInfo::ResizeMode GetResizeMode() const { return resizeMode; }
00290 
00291   protected:
00292     PString  srcColourFormat;
00293     PString  dstColourFormat;
00294     unsigned srcFrameWidth;
00295     unsigned srcFrameHeight;
00296     unsigned srcFrameBytes;
00297 
00298     // Needed for resizing
00299     unsigned dstFrameWidth;
00300     unsigned dstFrameHeight;
00301     unsigned dstFrameBytes;
00302 
00303     PVideoFrameInfo::ResizeMode resizeMode;
00304      
00305     PBoolean     verticalFlip;
00306 
00307     PBYTEArray intermediateFrameStore;
00308 
00309 #ifndef P_MACOSX
00310       /* Use by the jpeg decompressor */
00311     struct jdec_private *jdec;
00312 #endif
00313 
00314   friend class PColourConverterRegistration;
00315 };
00316 
00317 
00323 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
00324 class cls : public ancestor { \
00325   public: \
00326   cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
00327     : ancestor(src, dst) { } \
00328   virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
00329   virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
00330 }; \
00331 static class cls##_Registration : public PColourConverterRegistration { \
00332   public: cls##_Registration() \
00333     : PColourConverterRegistration(srcFmt,dstFmt) { } \
00334   protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
00335 } p_##cls##_registration_instance; \
00336 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
00337   { return new cls(src, dst); } \
00338 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int __srcFrameBytes, PINDEX * bytesReturned) \
00339   { srcFrameBytes = __srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
00340 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
00341 
00342 
00348 #define PCOLOUR_CONVERTER(cls,src,dst) \
00349         PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
00350 
00351 
00352 
00357 class PSynonymColour : public PColourConverter {
00358   public:
00359     PSynonymColour(
00360       const PVideoFrameInfo & src,
00361       const PVideoFrameInfo & dst
00362     ) : PColourConverter(src, dst) { }
00363     virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL);
00364     virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
00365 };
00366 
00367 
00372 class PSynonymColourRegistration : public PColourConverterRegistration {
00373   public:
00374     PSynonymColourRegistration(
00375       const char * srcFmt,
00376       const char * dstFmt
00377     );
00378 
00379   protected:
00380     virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
00381 };
00382 
00383 
00388 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
00389   static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
00390 
00391 
00392 class PVideoTools {
00393   public:
00394     static void GenerateYUV420NTSCTestFrame(BYTE *resFrame, unsigned frameWidth, unsigned frameHeight, unsigned bytesPerPixel, unsigned scanLineWidth);
00395     static void FillYUV420Rect(BYTE * frame, unsigned bytesPerPixel, unsigned scanLineWidth,
00396                                unsigned frameWidth, unsigned frameHeight, 
00397                                int xPos, int initialYPos, int rectWidth, int rectHeight, int r, int g,  int b);
00398 };
00399 
00400 #endif // P_VIDEO
00401 
00402 
00403 #endif // _PCONVERT
00404 
00405 // End of file ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 01:57:54 2009 for PTLib by  doxygen 1.5.1