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.20  2006/03/12 11:09:48  dsandras
00030  * Applied patch from Luc Saillard to fix problems with MJPEG. Thanks!
00031  *
00032  * Revision 1.19  2006/02/22 11:17:53  csoutheren
00033  * Applied patch #1425825
00034  * MaxOSX compatibility
00035  *
00036  * Revision 1.18  2006/02/20 06:12:10  csoutheren
00037  * Added guard defines
00038  *
00039  * Revision 1.17  2006/01/29 22:46:41  csoutheren
00040  * Added support for cameras that return MJPEG streams
00041  * Thanks to Luc Saillard and Damien Sandras
00042  *
00043  * Revision 1.16  2005/11/30 12:47:38  csoutheren
00044  * Removed tabs, reformatted some code, and changed tags for Doxygen
00045  *
00046  * Revision 1.15  2005/11/25 03:43:47  csoutheren
00047  * Fixed function argument comments to be compatible with Doxygen
00048  *
00049  * Revision 1.14  2005/08/09 09:08:09  rjongbloed
00050  * Merged new video code from branch back to the trunk.
00051  *
00052  * Revision 1.13.14.1  2005/07/17 09:27:04  rjongbloed
00053  * Major revisions of the PWLib video subsystem including:
00054  *   removal of F suffix on colour formats for vertical flipping, all done with existing bool
00055  *   working through use of RGB and BGR formats so now consistent
00056  *   cleaning up the plug in system to use virtuals instead of pointers to functions.
00057  *   rewrite of SDL to be a plug in compatible video output device.
00058  *   extensive enhancement of video test program
00059  *
00060  * Revision 1.13  2003/03/17 07:44:20  robertj
00061  * Removed redundant toggle function.
00062  *
00063  * Revision 1.12  2002/09/16 01:08:59  robertj
00064  * Added #define so can select if #pragma interface/implementation is used on
00065  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00066  *
00067  * Revision 1.11  2002/01/04 04:11:45  dereks
00068  * Add video flip code from Walter Whitlock, which flips code at the grabber.
00069  *
00070  * Revision 1.10  2001/11/28 04:41:28  robertj
00071  * Added synonym colour class for equivalent colour format strings.
00072  * Allowed for setting ancestor classes in PCOLOUR_CONVERTER() macro.
00073  *
00074  * Revision 1.9  2001/05/14 05:10:38  robertj
00075  * Fixed problems with video colour converters registration, could not rely
00076  *   on static PList being initialised before all registration instances.
00077  *
00078  * Revision 1.8  2001/03/20 02:21:57  robertj
00079  * More enhancements from Mark Cooke
00080  *
00081  * Revision 1.7  2001/03/08 23:36:02  robertj
00082  * Added backward compatibility SetFrameSize() function.
00083  * Added internal SimpleConvert() function for same type converters.
00084  * Fixed some documentation.
00085  *
00086  * Revision 1.6  2001/03/08 08:31:34  robertj
00087  * Numerous enhancements to the video grabbing code including resizing
00088  *   infrastructure to converters. Thanks a LOT, Mark Cooke.
00089  *
00090  * Revision 1.5  2001/03/07 01:42:59  dereks
00091  * miscellaneous video fixes. Works on linux now. Add debug statements
00092  * (at PTRACE level of 1)
00093  *
00094  * Revision 1.4  2001/03/03 23:25:07  robertj
00095  * Fixed use of video conversion function, returning bytes in destination frame.
00096  *
00097  * Revision 1.3  2001/03/03 05:06:31  robertj
00098  * Major upgrade of video conversion and grabbing classes.
00099  *
00100  * Revision 1.2  2000/12/19 23:58:14  robertj
00101  * Fixed MSVC compatibility issues.
00102  *
00103  * Revision 1.1  2000/12/19 22:20:26  dereks
00104  * Add video channel classes to connect to the PwLib PVideoInputDevice class.
00105  * Add PFakeVideoInput class to generate test images for video.
00106  *
00107  *
00108  */
00109 
00110 #ifndef _PCONVERT
00111 #define _PCONVERT
00112 
00113 #ifdef P_USE_PRAGMA
00114 #ifndef P_MACOSX
00115 #pragma interface
00116 #endif
00117 #endif
00118 
00119 struct jdec_private;
00120 
00121 class PColourConverter;
00122 
00128 class PColourConverterRegistration : public PCaselessString
00129 {
00130     PCLASSINFO(PColourConverterRegistration, PCaselessString);
00131   public:
00132     PColourConverterRegistration(
00133       const PString & srcColourFormat,  
00134       const PString & destColourFormat  
00135     );
00136 
00137     virtual PColourConverter * Create(
00138       unsigned width,   
00139       unsigned height   
00140     ) const = 0;
00141 
00142   protected:
00143     PColourConverterRegistration * link;
00144 
00145   friend class PColourConverter;
00146 };
00147 
00148 
00152 class PColourConverter : public PObject
00153 {
00154     PCLASSINFO(PColourConverter, PObject);
00155   public:
00158     PColourConverter(
00159       const PString & srcColourFormat,  
00160       const PString & dstColourFormat,  
00161       unsigned width,   
00162       unsigned height   
00163     );
00164 
00167     BOOL GetVFlipState() 
00168       { return verticalFlip; }
00169     
00172     void SetVFlipState(BOOL vFlipState) 
00173       { verticalFlip = vFlipState; }
00174     
00179     virtual BOOL SetFrameSize(
00180       unsigned width,   
00181       unsigned height   
00182     );
00183 
00190     virtual BOOL SetSrcFrameSize(
00191       unsigned width,   
00192       unsigned height   
00193     );
00194 
00201     virtual BOOL SetDstFrameSize(
00202       unsigned width,   
00203       unsigned height,  
00204       BOOL     bScale   
00205     );
00206 
00209     const PString & GetSrcColourFormat() { return srcColourFormat; }
00210 
00213     const PString & GetDstColourFormat() { return dstColourFormat; }
00214 
00220     PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; }
00221 
00227     PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; }
00228 
00229 
00239     virtual BOOL Convert(
00240       const BYTE * srcFrameBuffer,  
00241       BYTE * dstFrameBuffer,        
00242       PINDEX * bytesReturned = NULL 
00243     ) = 0;
00244 
00245     virtual BOOL Convert(
00246       const BYTE * srcFrameBuffer,  
00247       BYTE * dstFrameBuffer,        
00248       unsigned int srcFrameBytes,
00249       PINDEX * bytesReturned = NULL 
00250     ) = 0;
00251 
00268     virtual BOOL ConvertInPlace(
00269       BYTE * frameBuffer,               
00270       PINDEX * bytesReturned = NULL,    
00271       BOOL noIntermediateFrame = FALSE  
00272     );
00273 
00274 
00279     static PColourConverter * Create(
00280       const PString & srcColourFormat,  
00281       const PString & dstColourFormat,  
00282       unsigned width,   
00283       unsigned height   
00284     );
00285 
00288     BOOL GetDstFrameSize(
00289       unsigned & width, 
00290       unsigned & height 
00291     ) const;
00292 
00295     BOOL GetSrcFrameSize(
00296       unsigned & width, 
00297       unsigned & height 
00298     ) const;
00299 
00300   protected:
00301     PString  srcColourFormat;
00302     PString  dstColourFormat;
00303     unsigned srcFrameWidth;
00304     unsigned srcFrameHeight;
00305     unsigned srcFrameBytes;
00306     unsigned dstFrameBytes;
00307 
00308     // Needed for resizing
00309     unsigned dstFrameWidth;
00310     unsigned dstFrameHeight;
00311     BOOL     scaleNotCrop;
00312      
00313     BOOL     verticalFlip;
00314 
00315     PBYTEArray intermediateFrameStore;
00316 
00317 #ifndef P_MACOSX
00318       /* Use by the jpeg decompressor */
00319     struct jdec_private *jdec;
00320 #endif
00321 
00322   friend class PColourConverterRegistration;
00323 };
00324 
00325 
00331 #define PCOLOUR_CONVERTER2(cls,ancestor,src,dst) \
00332 class cls : public ancestor { \
00333   public: \
00334   cls(const PString & srcFmt, const PString & dstFmt, unsigned w, unsigned h) \
00335     : ancestor(srcFmt, dstFmt, w, h) { } \
00336   virtual BOOL Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
00337   virtual BOOL Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
00338 }; \
00339 static class cls##_Registration : public PColourConverterRegistration { \
00340   public: \
00341   cls##_Registration() \
00342     : PColourConverterRegistration(src,dst) { } \
00343   virtual PColourConverter * Create(unsigned w, unsigned h) const; \
00344 } p_##cls##_registration_instance; \
00345 PColourConverter * cls##_Registration::Create(unsigned w, unsigned h) const \
00346   { PINDEX tab = Find('\t'); return new cls(Left(tab), Mid(tab+1), w, h); } \
00347 BOOL cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int __srcFrameBytes, PINDEX * bytesReturned) \
00348   { srcFrameBytes = __srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
00349 BOOL cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
00350 
00351 
00357 #define PCOLOUR_CONVERTER(cls,src,dst) \
00358         PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
00359 
00360 
00361 
00366 class PSynonymColour : public PColourConverter {
00367   public:
00368     PSynonymColour(
00369       const PString & srcFmt,
00370       const PString & dstFmt,
00371       unsigned w, unsigned h
00372     ) : PColourConverter(srcFmt, dstFmt, w, h) { }
00373     virtual BOOL Convert(const BYTE *, BYTE *, PINDEX * = NULL);
00374     virtual BOOL Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
00375 };
00376 
00377 
00382 class PSynonymColourRegistration : public PColourConverterRegistration {
00383   public:
00384     PSynonymColourRegistration(
00385       const char * srcFmt,
00386       const char * dstFmt
00387     );
00388 
00389     virtual PColourConverter * Create(unsigned w, unsigned h) const;
00390 };
00391 
00392 
00397 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
00398   static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
00399 
00400 #endif
00401 
00402 // End of file ///////////////////////////////////////////////////////////////

Generated on Mon Sep 1 09:41:07 2008 for PWLib by  doxygen 1.5.6