00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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 PString srcColourFormat;
00322 PString dstColourFormat;
00323 unsigned srcFrameWidth;
00324 unsigned srcFrameHeight;
00325 unsigned srcFrameBytes;
00326
00327
00328 unsigned dstFrameWidth;
00329 unsigned dstFrameHeight;
00330 unsigned dstFrameBytes;
00331
00332 PVideoFrameInfo::ResizeMode resizeMode;
00333
00334 PBoolean verticalFlip;
00335
00336 PBYTEArray intermediateFrameStore;
00337
00338 #ifndef P_MACOSX
00339
00340 struct jdec_private *jdec;
00341 #endif
00342
00343 friend class PColourConverterRegistration;
00344 };
00345
00346
00352 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
00353 class cls : public ancestor { \
00354 public: \
00355 cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
00356 : ancestor(src, dst) { } \
00357 virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
00358 virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
00359 }; \
00360 static class cls##_Registration : public PColourConverterRegistration { \
00361 public: cls##_Registration() \
00362 : PColourConverterRegistration(srcFmt,dstFmt) { } \
00363 protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
00364 } p_##cls##_registration_instance; \
00365 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
00366 { return new cls(src, dst); } \
00367 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int p_srcFrameBytes, PINDEX * bytesReturned) \
00368 { srcFrameBytes = p_srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
00369 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
00370
00371
00377 #define PCOLOUR_CONVERTER(cls,src,dst) \
00378 PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
00379
00380
00381
00386 class PSynonymColour : public PColourConverter {
00387 public:
00388 PSynonymColour(
00389 const PVideoFrameInfo & src,
00390 const PVideoFrameInfo & dst
00391 ) : PColourConverter(src, dst) { }
00392 virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL);
00393 virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
00394 };
00395
00396
00401 class PSynonymColourRegistration : public PColourConverterRegistration {
00402 public:
00403 PSynonymColourRegistration(
00404 const char * srcFmt,
00405 const char * dstFmt
00406 );
00407
00408 protected:
00409 virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
00410 };
00411
00412
00417 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
00418 static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
00419
00420
00421 #endif // P_VIDEO
00422
00423 #endif // PTLIB_CONVERT_H
00424
00425
00426