|
PTLib Version 2.10.2
|
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: 24425 $ 00029 * $Author: rjongbloed $ 00030 * $Date: 2010-05-28 04:19:22 -0500 (Fri, 28 May 2010) $ 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( 00105 PBoolean vFlipState 00106 ) { verticalFlip = vFlipState; } 00107 00112 virtual PBoolean SetFrameSize( 00113 unsigned width, 00114 unsigned height 00115 ); 00116 00125 virtual PBoolean SetSrcFrameInfo( 00126 const PVideoFrameInfo & info 00127 ); 00128 00137 virtual PBoolean SetDstFrameInfo( 00138 const PVideoFrameInfo & info 00139 ); 00140 00143 virtual void GetSrcFrameInfo( 00144 PVideoFrameInfo & info 00145 ); 00146 00149 virtual void GetDstFrameInfo( 00150 PVideoFrameInfo & info 00151 ); 00152 00159 virtual PBoolean SetSrcFrameSize( 00160 unsigned width, 00161 unsigned height 00162 ); 00163 00170 virtual PBoolean SetDstFrameSize( 00171 unsigned width, 00172 unsigned height 00173 ); 00174 virtual PBoolean SetDstFrameSize( 00175 unsigned width, 00176 unsigned height, 00177 PBoolean bScale 00178 ); 00179 00182 const PString & GetSrcColourFormat() { return srcColourFormat; } 00183 00186 const PString & GetDstColourFormat() { return dstColourFormat; } 00187 00193 PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; } 00194 00200 PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; } 00201 00202 00212 virtual PBoolean Convert( 00213 const BYTE * srcFrameBuffer, 00214 BYTE * dstFrameBuffer, 00215 PINDEX * bytesReturned = NULL 00216 ) = 0; 00217 00218 virtual PBoolean Convert( 00219 const BYTE * srcFrameBuffer, 00220 BYTE * dstFrameBuffer, 00221 unsigned int srcFrameBytes, 00222 PINDEX * bytesReturned = NULL 00223 ) = 0; 00224 00241 virtual PBoolean ConvertInPlace( 00242 BYTE * frameBuffer, 00243 PINDEX * bytesReturned = NULL, 00244 PBoolean noIntermediateFrame = false 00245 ); 00246 00247 00252 static PColourConverter * Create( 00253 const PVideoFrameInfo & src, 00254 const PVideoFrameInfo & dst 00255 ); 00256 static PColourConverter * Create( 00257 const PString & srcColourFormat, 00258 const PString & destColourFormat, 00259 unsigned width, 00260 unsigned height 00261 ); 00262 00265 PBoolean GetDstFrameSize( 00266 unsigned & width, 00267 unsigned & height 00268 ) const; 00269 00272 PBoolean GetSrcFrameSize( 00273 unsigned & width, 00274 unsigned & height 00275 ) const; 00276 00277 unsigned GetSrcFrameWidth() const { return srcFrameWidth; } 00278 unsigned GetSrcFrameHeight() const { return srcFrameHeight; } 00279 unsigned GetDstFrameWidth() const { return dstFrameWidth; } 00280 unsigned GetDstFrameHeight() const { return dstFrameHeight; } 00281 00284 void SetResizeMode( 00285 PVideoFrameInfo::ResizeMode mode 00286 ) { if (mode < PVideoFrameInfo::eMaxResizeMode) resizeMode = mode; } 00287 00290 PVideoFrameInfo::ResizeMode GetResizeMode() const { return resizeMode; } 00291 00294 static void RGBtoYUV( 00295 unsigned r, unsigned g, unsigned b, 00296 unsigned & y, unsigned & u, unsigned & v 00297 ); 00298 static void RGBtoYUV( 00299 unsigned r, unsigned g, unsigned b, 00300 BYTE & y, BYTE & u, BYTE & v 00301 ); 00302 00306 static bool CopyYUV420P( 00307 unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, 00308 unsigned srcFrameWidth, unsigned srcFrameHeight, const BYTE * srcYUV, 00309 unsigned dstX, unsigned dstY, unsigned dstWidth, unsigned dstHeight, 00310 unsigned dstFrameWidth, unsigned dstFrameHeight, BYTE * dstYUV, 00311 PVideoFrameInfo::ResizeMode resizeMode 00312 ); 00313 00314 static bool FillYUV420P( 00315 unsigned x, unsigned y, int width, int height, 00316 unsigned frameWidth, unsigned frameHeight, BYTE * yuv, 00317 unsigned r, unsigned g, unsigned b 00318 ); 00319 00320 protected: 00321 void Construct( 00322 const PVideoFrameInfo & src, 00323 const PVideoFrameInfo & dst 00324 ); 00325 00326 PString srcColourFormat; 00327 PString dstColourFormat; 00328 unsigned srcFrameWidth; 00329 unsigned srcFrameHeight; 00330 unsigned srcFrameBytes; 00331 00332 // Needed for resizing 00333 unsigned dstFrameWidth; 00334 unsigned dstFrameHeight; 00335 unsigned dstFrameBytes; 00336 00337 PVideoFrameInfo::ResizeMode resizeMode; 00338 00339 PBoolean verticalFlip; 00340 00341 PBYTEArray intermediateFrameStore; 00342 00343 #ifndef P_MACOSX 00344 /* Use by the jpeg decompressor */ 00345 struct jdec_private *jdec; 00346 #endif 00347 00348 friend class PColourConverterRegistration; 00349 }; 00350 00351 00357 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \ 00358 class cls : public ancestor { \ 00359 public: \ 00360 cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \ 00361 : ancestor(src, dst) { } \ 00362 virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); \ 00363 virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \ 00364 }; \ 00365 static class cls##_Registration : public PColourConverterRegistration { \ 00366 public: cls##_Registration() \ 00367 : PColourConverterRegistration(srcFmt,dstFmt) { } \ 00368 protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \ 00369 } p_##cls##_registration_instance; \ 00370 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \ 00371 { return new cls(src, dst); } \ 00372 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int p_srcFrameBytes, PINDEX * bytesReturned) \ 00373 { srcFrameBytes = p_srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \ 00374 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned) 00375 00376 00382 #define PCOLOUR_CONVERTER(cls,src,dst) \ 00383 PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst) 00384 00385 00386 00391 class PSynonymColour : public PColourConverter { 00392 public: 00393 PSynonymColour( 00394 const PVideoFrameInfo & src, 00395 const PVideoFrameInfo & dst 00396 ) : PColourConverter(src, dst) { } 00397 virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); 00398 virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); 00399 }; 00400 00401 00406 class PSynonymColourRegistration : public PColourConverterRegistration { 00407 public: 00408 PSynonymColourRegistration( 00409 const char * srcFmt, 00410 const char * dstFmt 00411 ); 00412 00413 protected: 00414 virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; 00415 }; 00416 00417 00422 #define PSYNONYM_COLOUR_CONVERTER(from,to) \ 00423 static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to) 00424 00425 00426 #endif // P_VIDEO 00427 00428 #endif // PTLIB_CONVERT_H 00429 00430 00431 // End of file ///////////////////////////////////////////////////////////////