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
00098 virtual void PrintOn(
00099 ostream & strm
00100 ) const;
00101
00104 PBoolean GetVFlipState()
00105 { return verticalFlip; }
00106
00109 void SetVFlipState(
00110 PBoolean vFlipState
00111 ) { verticalFlip = vFlipState; }
00112
00117 virtual PBoolean SetFrameSize(
00118 unsigned width,
00119 unsigned height
00120 );
00121
00130 virtual PBoolean SetSrcFrameInfo(
00131 const PVideoFrameInfo & info
00132 );
00133
00142 virtual PBoolean SetDstFrameInfo(
00143 const PVideoFrameInfo & info
00144 );
00145
00148 virtual void GetSrcFrameInfo(
00149 PVideoFrameInfo & info
00150 );
00151
00154 virtual void GetDstFrameInfo(
00155 PVideoFrameInfo & info
00156 );
00157
00164 virtual PBoolean SetSrcFrameSize(
00165 unsigned width,
00166 unsigned height
00167 );
00168
00175 virtual PBoolean SetDstFrameSize(
00176 unsigned width,
00177 unsigned height
00178 );
00179 virtual PBoolean SetDstFrameSize(
00180 unsigned width,
00181 unsigned height,
00182 PBoolean bScale
00183 );
00184
00187 const PString & GetSrcColourFormat() { return srcColourFormat; }
00188
00191 const PString & GetDstColourFormat() { return dstColourFormat; }
00192
00198 PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; }
00199
00205 PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; }
00206
00207
00217 virtual PBoolean Convert(
00218 const BYTE * srcFrameBuffer,
00219 BYTE * dstFrameBuffer,
00220 PINDEX * bytesReturned = NULL
00221 ) = 0;
00222
00223 virtual PBoolean Convert(
00224 const BYTE * srcFrameBuffer,
00225 BYTE * dstFrameBuffer,
00226 unsigned int srcFrameBytes,
00227 PINDEX * bytesReturned = NULL
00228 ) = 0;
00229
00246 virtual PBoolean ConvertInPlace(
00247 BYTE * frameBuffer,
00248 PINDEX * bytesReturned = NULL,
00249 PBoolean noIntermediateFrame = false
00250 );
00251
00252
00257 static PColourConverter * Create(
00258 const PVideoFrameInfo & src,
00259 const PVideoFrameInfo & dst
00260 );
00261 static PColourConverter * Create(
00262 const PString & srcColourFormat,
00263 const PString & destColourFormat,
00264 unsigned width,
00265 unsigned height
00266 );
00267
00270 PBoolean GetDstFrameSize(
00271 unsigned & width,
00272 unsigned & height
00273 ) const;
00274
00277 PBoolean GetSrcFrameSize(
00278 unsigned & width,
00279 unsigned & height
00280 ) const;
00281
00282 unsigned GetSrcFrameWidth() const { return srcFrameWidth; }
00283 unsigned GetSrcFrameHeight() const { return srcFrameHeight; }
00284 unsigned GetDstFrameWidth() const { return dstFrameWidth; }
00285 unsigned GetDstFrameHeight() const { return dstFrameHeight; }
00286
00289 void SetResizeMode(
00290 PVideoFrameInfo::ResizeMode mode
00291 ) { if (mode < PVideoFrameInfo::eMaxResizeMode) resizeMode = mode; }
00292
00295 PVideoFrameInfo::ResizeMode GetResizeMode() const { return resizeMode; }
00296
00299 static void RGBtoYUV(
00300 unsigned r, unsigned g, unsigned b,
00301 unsigned & y, unsigned & u, unsigned & v
00302 );
00303 static void RGBtoYUV(
00304 unsigned r, unsigned g, unsigned b,
00305 BYTE & y, BYTE & u, BYTE & v
00306 );
00307
00311 static bool CopyYUV420P(
00312 unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00313 unsigned srcFrameWidth, unsigned srcFrameHeight, const BYTE * srcYUV,
00314 unsigned dstX, unsigned dstY, unsigned dstWidth, unsigned dstHeight,
00315 unsigned dstFrameWidth, unsigned dstFrameHeight, BYTE * dstYUV,
00316 PVideoFrameInfo::ResizeMode resizeMode
00317 );
00318
00319 static bool FillYUV420P(
00320 unsigned x, unsigned y, int width, int height,
00321 unsigned frameWidth, unsigned frameHeight, BYTE * yuv,
00322 unsigned r, unsigned g, unsigned b
00323 );
00324
00325 protected:
00326 void Construct(
00327 const PVideoFrameInfo & src,
00328 const PVideoFrameInfo & dst
00329 );
00330
00331 PString srcColourFormat;
00332 PString dstColourFormat;
00333 unsigned srcFrameWidth;
00334 unsigned srcFrameHeight;
00335 unsigned srcFrameBytes;
00336
00337
00338 unsigned dstFrameWidth;
00339 unsigned dstFrameHeight;
00340 unsigned dstFrameBytes;
00341
00342 PVideoFrameInfo::ResizeMode resizeMode;
00343
00344 PBoolean verticalFlip;
00345
00346 PBYTEArray intermediateFrameStore;
00347
00348 #ifndef P_MACOSX
00349
00350 struct jdec_private *jdec;
00351 #endif
00352
00353 friend class PColourConverterRegistration;
00354 };
00355
00356
00362 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
00363 class cls : public ancestor { \
00364 public: \
00365 cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
00366 : ancestor(src, dst) { } \
00367 virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
00368 virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
00369 }; \
00370 static class cls##_Registration : public PColourConverterRegistration { \
00371 public: cls##_Registration() \
00372 : PColourConverterRegistration(srcFmt,dstFmt) { } \
00373 protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
00374 } p_##cls##_registration_instance; \
00375 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
00376 { return new cls(src, dst); } \
00377 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int p_srcFrameBytes, PINDEX * bytesReturned) \
00378 { srcFrameBytes = p_srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
00379 PBoolean cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
00380
00381
00387 #define PCOLOUR_CONVERTER(cls,src,dst) \
00388 PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
00389
00390
00391
00396 class PSynonymColour : public PColourConverter {
00397 public:
00398 PSynonymColour(
00399 const PVideoFrameInfo & src,
00400 const PVideoFrameInfo & dst
00401 ) : PColourConverter(src, dst) { }
00402 virtual PBoolean Convert(const BYTE *, BYTE *, PINDEX * = NULL);
00403 virtual PBoolean Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
00404 };
00405
00406
00411 class PSynonymColourRegistration : public PColourConverterRegistration {
00412 public:
00413 PSynonymColourRegistration(
00414 const char * srcFmt,
00415 const char * dstFmt
00416 );
00417
00418 protected:
00419 virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
00420 };
00421
00422
00427 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
00428 static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
00429
00430
00431 #endif // P_VIDEO
00432
00433 #endif // PTLIB_CONVERT_H
00434
00435
00436