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: 22477 $
00029  * $Author: rjongbloed $
00030  * $Date: 2009-04-29 06:03:51 +0000 (Wed, 29 Apr 2009) $
00031  */
00032 
00033 #ifndef PTLIB_CONVERT_H
00034 #define PTLIB_CONVERT_H
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 
00293     static void RGBtoYUV(
00294       unsigned   r, unsigned   g, unsigned   b,
00295       unsigned & y, unsigned & u, unsigned & v
00296     );
00297     static void RGBtoYUV(
00298       unsigned r, unsigned g, unsigned b,
00299       BYTE   & y, BYTE   & u, BYTE   & v
00300     );
00301 
00305     static bool CopyYUV420P(
00306       unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00307       unsigned srcFrameWidth, unsigned srcFrameHeight, const BYTE * srcYUV,
00308       unsigned dstX, unsigned dstY, unsigned dstWidth, unsigned dstHeight,
00309       unsigned dstFrameWidth, unsigned dstFrameHeight, BYTE * dstYUV,
00310       PVideoFrameInfo::ResizeMode resizeMode
00311     );
00312 
00313     static bool FillYUV420P(
00314       unsigned x, unsigned y, int width, int height,
00315       unsigned frameWidth, unsigned frameHeight, BYTE * yuv,
00316       unsigned r, unsigned g, unsigned b
00317     );
00318 
00319   protected:
00320     PString  srcColourFormat;
00321     PString  dstColourFormat;
00322     unsigned srcFrameWidth;
00323     unsigned srcFrameHeight;
00324     unsigned srcFrameBytes;
00325 
00326     // Needed for resizing
00327     unsigned dstFrameWidth;
00328     unsigned dstFrameHeight;
00329     unsigned dstFrameBytes;
00330 
00331     PVideoFrameInfo::ResizeMode resizeMode;
00332      
00333     PBoolean     verticalFlip;
00334 
00335     PBYTEArray intermediateFrameStore;
00336 
00337 #ifndef P_MACOSX
00338       /* Use by the jpeg decompressor */
00339     struct jdec_private *jdec;
00340 #endif
00341 
00342   friend class PColourConverterRegistration;
00343 };
00344 
00345 
00351 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
00352 class cls : public ancestor { \
00353   public: \
00354   cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
00355     : ancestor(src, dst) { } \
00356   virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
00357   virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
00358 }; \
00359 static class cls##_Registration : public PColourConverterRegistration { \
00360   public: cls##_Registration() \
00361     : PColourConverterRegistration(srcFmt,dstFmt) { } \
00362   protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
00363 } p_##cls##_registration_instance; \
00364 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
00365   { return new cls(src, dst); } \
00366 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int p_srcFrameBytes, PINDEX * bytesReturned) \
00367   { srcFrameBytes = p_srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
00368 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
00369 
00370 
00376 #define PCOLOUR_CONVERTER(cls,src,dst) \
00377         PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
00378 
00379 
00380 
00385 class PSynonymColour : public PColourConverter {
00386   public:
00387     PSynonymColour(
00388       const PVideoFrameInfo & src,
00389       const PVideoFrameInfo & dst
00390     ) : PColourConverter(src, dst) { }
00391     virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL);
00392     virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
00393 };
00394 
00395 
00400 class PSynonymColourRegistration : public PColourConverterRegistration {
00401   public:
00402     PSynonymColourRegistration(
00403       const char * srcFmt,
00404       const char * dstFmt
00405     );
00406 
00407   protected:
00408     virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
00409 };
00410 
00411 
00416 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
00417   static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
00418 
00419 
00420 #endif // P_VIDEO
00421 
00422 #endif // PTLIB_CONVERT_H
00423 
00424 
00425 // End of file ///////////////////////////////////////////////////////////////

Generated on Mon Aug 3 20:41:51 2009 for PTLib by  doxygen 1.5.1