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