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  * $Log: vconvert.h,v $
00029  * Revision 1.25  2007/04/24 08:28:52  csoutheren
00030  * Add backwards compatible API
00031  *
00032  * Revision 1.24  2007/04/20 06:47:02  csoutheren
00033  * Really disable video code when video is turned off
00034  *
00035  * Revision 1.23  2007/04/20 06:11:22  csoutheren
00036  * Add backwards compatible API for PColourConverter
00037  *
00038  * Revision 1.22  2007/04/20 05:40:33  csoutheren
00039  * Add backwards compatible API for PColourConverter
00040  *
00041  * Revision 1.21  2007/04/13 07:13:13  rjongbloed
00042  * Major update of video subsystem:
00043  *   Abstracted video frame info (width, height etc) into separate class.
00044  *   Changed devices, converter and video file to use above.
00045  *   Enhanced video file hint detection for frame rate and more
00046  *     flexible formats.
00047  *   Fixed issue if need to convert both colour format and size, had to do
00048  *     colour format first or it didn't convert size.
00049  *   Win32 video output device can be selected by "MSWIN" alone.
00050  *
00051  * Revision 1.20  2006/03/12 11:09:48  dsandras
00052  * Applied patch from Luc Saillard to fix problems with MJPEG. Thanks!
00053  *
00054  * Revision 1.19  2006/02/22 11:17:53  csoutheren
00055  * Applied patch #1425825
00056  * MaxOSX compatibility
00057  *
00058  * Revision 1.18  2006/02/20 06:12:10  csoutheren
00059  * Added guard defines
00060  *
00061  * Revision 1.17  2006/01/29 22:46:41  csoutheren
00062  * Added support for cameras that return MJPEG streams
00063  * Thanks to Luc Saillard and Damien Sandras
00064  *
00065  * Revision 1.16  2005/11/30 12:47:38  csoutheren
00066  * Removed tabs, reformatted some code, and changed tags for Doxygen
00067  *
00068  * Revision 1.15  2005/11/25 03:43:47  csoutheren
00069  * Fixed function argument comments to be compatible with Doxygen
00070  *
00071  * Revision 1.14  2005/08/09 09:08:09  rjongbloed
00072  * Merged new video code from branch back to the trunk.
00073  *
00074  * Revision 1.13.14.1  2005/07/17 09:27:04  rjongbloed
00075  * Major revisions of the PWLib video subsystem including:
00076  *   removal of F suffix on colour formats for vertical flipping, all done with existing bool
00077  *   working through use of RGB and BGR formats so now consistent
00078  *   cleaning up the plug in system to use virtuals instead of pointers to functions.
00079  *   rewrite of SDL to be a plug in compatible video output device.
00080  *   extensive enhancement of video test program
00081  *
00082  * Revision 1.13  2003/03/17 07:44:20  robertj
00083  * Removed redundant toggle function.
00084  *
00085  * Revision 1.12  2002/09/16 01:08:59  robertj
00086  * Added #define so can select if #pragma interface/implementation is used on
00087  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00088  *
00089  * Revision 1.11  2002/01/04 04:11:45  dereks
00090  * Add video flip code from Walter Whitlock, which flips code at the grabber.
00091  *
00092  * Revision 1.10  2001/11/28 04:41:28  robertj
00093  * Added synonym colour class for equivalent colour format strings.
00094  * Allowed for setting ancestor classes in PCOLOUR_CONVERTER() macro.
00095  *
00096  * Revision 1.9  2001/05/14 05:10:38  robertj
00097  * Fixed problems with video colour converters registration, could not rely
00098  *   on static PList being initialised before all registration instances.
00099  *
00100  * Revision 1.8  2001/03/20 02:21:57  robertj
00101  * More enhancements from Mark Cooke
00102  *
00103  * Revision 1.7  2001/03/08 23:36:02  robertj
00104  * Added backward compatibility SetFrameSize() function.
00105  * Added internal SimpleConvert() function for same type converters.
00106  * Fixed some documentation.
00107  *
00108  * Revision 1.6  2001/03/08 08:31:34  robertj
00109  * Numerous enhancements to the video grabbing code including resizing
00110  *   infrastructure to converters. Thanks a LOT, Mark Cooke.
00111  *
00112  * Revision 1.5  2001/03/07 01:42:59  dereks
00113  * miscellaneous video fixes. Works on linux now. Add debug statements
00114  * (at PTRACE level of 1)
00115  *
00116  * Revision 1.4  2001/03/03 23:25:07  robertj
00117  * Fixed use of video conversion function, returning bytes in destination frame.
00118  *
00119  * Revision 1.3  2001/03/03 05:06:31  robertj
00120  * Major upgrade of video conversion and grabbing classes.
00121  *
00122  * Revision 1.2  2000/12/19 23:58:14  robertj
00123  * Fixed MSVC compatibility issues.
00124  *
00125  * Revision 1.1  2000/12/19 22:20:26  dereks
00126  * Add video channel classes to connect to the PwLib PVideoInputDevice class.
00127  * Add PFakeVideoInput class to generate test images for video.
00128  *
00129  *
00130  */
00131 
00132 #ifndef _PCONVERT
00133 #define _PCONVERT
00134 
00135 #ifdef P_USE_PRAGMA
00136 #ifndef P_MACOSX
00137 #pragma interface
00138 #endif
00139 #endif
00140 
00141 #include <ptbuildopts.h>
00142 
00143 #if P_VIDEO
00144 
00145 #include <ptlib/videoio.h>
00146 
00147 struct jdec_private;
00148 
00149 
00155 class PColourConverterRegistration : public PCaselessString
00156 {
00157     PCLASSINFO(PColourConverterRegistration, PCaselessString);
00158   public:
00159     PColourConverterRegistration(
00160       const PString & srcColourFormat,  
00161       const PString & destColourFormat  
00162     );
00163 
00164   protected:
00165     virtual PColourConverter * Create(
00166       const PVideoFrameInfo & src, 
00167       const PVideoFrameInfo & dst  
00168     ) const = 0;
00169 
00170     PColourConverterRegistration * link;
00171 
00172   friend class PColourConverter;
00173 };
00174 
00175 
00179 class PColourConverter : public PObject
00180 {
00181     PCLASSINFO(PColourConverter, PObject);
00182   public:
00185     PColourConverter(
00186       const PString & srcColourFormat,  
00187       const PString & dstColourFormat,  
00188       unsigned width,   
00189       unsigned height   
00190     );
00191     PColourConverter(
00192       const PVideoFrameInfo & src, 
00193       const PVideoFrameInfo & dst  
00194     );
00195 
00198     BOOL GetVFlipState() 
00199       { return verticalFlip; }
00200     
00203     void SetVFlipState(BOOL vFlipState) 
00204       { verticalFlip = vFlipState; }
00205     
00210     virtual BOOL SetFrameSize(
00211       unsigned width,   
00212       unsigned height   
00213     );
00214 
00223     virtual BOOL SetSrcFrameInfo(
00224       const PVideoFrameInfo & info   
00225     );
00226 
00235     virtual BOOL SetDstFrameInfo(
00236       const PVideoFrameInfo & info  
00237     );
00238 
00241     virtual void GetSrcFrameInfo(
00242       PVideoFrameInfo & info   
00243     );
00244 
00247     virtual void GetDstFrameInfo(
00248       PVideoFrameInfo & info  
00249     );
00250 
00257     virtual BOOL SetSrcFrameSize(
00258       unsigned width,   
00259       unsigned height   
00260     );
00261 
00268     virtual BOOL SetDstFrameSize(
00269       unsigned width,  
00270       unsigned height 
00271     );
00272     virtual BOOL SetDstFrameSize(
00273       unsigned width,  
00274       unsigned height, 
00275       BOOL bScale
00276     );
00277 
00280     const PString & GetSrcColourFormat() { return srcColourFormat; }
00281 
00284     const PString & GetDstColourFormat() { return dstColourFormat; }
00285 
00291     PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; }
00292 
00298     PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; }
00299 
00300 
00310     virtual BOOL Convert(
00311       const BYTE * srcFrameBuffer,  
00312       BYTE * dstFrameBuffer,        
00313       PINDEX * bytesReturned = NULL 
00314     ) = 0;
00315 
00316     virtual BOOL Convert(
00317       const BYTE * srcFrameBuffer,  
00318       BYTE * dstFrameBuffer,        
00319       unsigned int srcFrameBytes,
00320       PINDEX * bytesReturned = NULL 
00321     ) = 0;
00322 
00339     virtual BOOL ConvertInPlace(
00340       BYTE * frameBuffer,               
00341       PINDEX * bytesReturned = NULL,    
00342       BOOL noIntermediateFrame = FALSE  
00343     );
00344 
00345 
00350     static PColourConverter * Create(
00351       const PVideoFrameInfo & src, 
00352       const PVideoFrameInfo & dst  
00353     );
00354     static PColourConverter * Create(
00355       const PString & srcColourFormat,
00356       const PString & destColourFormat,
00357       unsigned width,
00358       unsigned height
00359     );
00360 
00363     BOOL GetDstFrameSize(
00364       unsigned & width, 
00365       unsigned & height 
00366     ) const;
00367 
00370     BOOL GetSrcFrameSize(
00371       unsigned & width, 
00372       unsigned & height 
00373     ) const;
00374 
00375     unsigned GetSrcFrameWidth()  const { return srcFrameWidth;  }
00376     unsigned GetSrcFrameHeight() const { return srcFrameHeight; }
00377     unsigned GetDstFrameWidth()  const { return dstFrameWidth;  }
00378     unsigned GetDstFrameHeight() const { return dstFrameHeight; }
00379 
00382     void SetResizeMode(
00383       PVideoFrameInfo::ResizeMode mode
00384     ) { if (mode < PVideoFrameInfo::eMaxResizeMode) resizeMode = mode; }
00385 
00388     PVideoFrameInfo::ResizeMode GetResizeMode() const { return resizeMode; }
00389 
00390   protected:
00391     PString  srcColourFormat;
00392     PString  dstColourFormat;
00393     unsigned srcFrameWidth;
00394     unsigned srcFrameHeight;
00395     unsigned srcFrameBytes;
00396 
00397     // Needed for resizing
00398     unsigned dstFrameWidth;
00399     unsigned dstFrameHeight;
00400     unsigned dstFrameBytes;
00401 
00402     PVideoFrameInfo::ResizeMode resizeMode;
00403      
00404     BOOL     verticalFlip;
00405 
00406     PBYTEArray intermediateFrameStore;
00407 
00408 #ifndef P_MACOSX
00409       /* Use by the jpeg decompressor */
00410     struct jdec_private *jdec;
00411 #endif
00412 
00413   friend class PColourConverterRegistration;
00414 };
00415 
00416 
00422 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
00423 class cls : public ancestor { \
00424   public: \
00425   cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
00426     : ancestor(src, dst) { } \
00427   virtual BOOL Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
00428   virtual BOOL Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
00429 }; \
00430 static class cls##_Registration : public PColourConverterRegistration { \
00431   public: cls##_Registration() \
00432     : PColourConverterRegistration(srcFmt,dstFmt) { } \
00433   protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
00434 } p_##cls##_registration_instance; \
00435 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
00436   { return new cls(src, dst); } \
00437 BOOL cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int __srcFrameBytes, PINDEX * bytesReturned) \
00438   { srcFrameBytes = __srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
00439 BOOL cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
00440 
00441 
00447 #define PCOLOUR_CONVERTER(cls,src,dst) \
00448         PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
00449 
00450 
00451 
00456 class PSynonymColour : public PColourConverter {
00457   public:
00458     PSynonymColour(
00459       const PVideoFrameInfo & src,
00460       const PVideoFrameInfo & dst
00461     ) : PColourConverter(src, dst) { }
00462     virtual BOOL Convert(const BYTE *, BYTE *, PINDEX * = NULL);
00463     virtual BOOL Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
00464 };
00465 
00466 
00471 class PSynonymColourRegistration : public PColourConverterRegistration {
00472   public:
00473     PSynonymColourRegistration(
00474       const char * srcFmt,
00475       const char * dstFmt
00476     );
00477 
00478   protected:
00479     virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
00480 };
00481 
00482 
00487 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
00488   static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
00489 
00490 #endif // P_VIDEO
00491 
00492 
00493 #endif // _PCONVERT
00494 
00495 // End of file ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:03 2008 for PTLib by  doxygen 1.5.1