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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 #ifndef _PCONVERT
00133 #define _PCONVERT
00134
00135 #ifdef P_USE_PRAGMA
00136 #ifndef P_MACOSX
00137 #pragma interface
00138 #endif
00139 #endif
00140
00141 #include <ptbuildopts.h>
00142
00143 #if P_VIDEO
00144
00145 #include <ptlib/videoio.h>
00146
00147 struct jdec_private;
00148
00149
00155 class PColourConverterRegistration : public PCaselessString
00156 {
00157 PCLASSINFO(PColourConverterRegistration, PCaselessString);
00158 public:
00159 PColourConverterRegistration(
00160 const PString & srcColourFormat,
00161 const PString & destColourFormat
00162 );
00163
00164 protected:
00165 virtual PColourConverter * Create(
00166 const PVideoFrameInfo & src,
00167 const PVideoFrameInfo & dst
00168 ) const = 0;
00169
00170 PColourConverterRegistration * link;
00171
00172 friend class PColourConverter;
00173 };
00174
00175
00179 class PColourConverter : public PObject
00180 {
00181 PCLASSINFO(PColourConverter, PObject);
00182 public:
00185 PColourConverter(
00186 const PString & srcColourFormat,
00187 const PString & dstColourFormat,
00188 unsigned width,
00189 unsigned height
00190 );
00191 PColourConverter(
00192 const PVideoFrameInfo & src,
00193 const PVideoFrameInfo & dst
00194 );
00195
00198 BOOL GetVFlipState()
00199 { return verticalFlip; }
00200
00203 void SetVFlipState(BOOL vFlipState)
00204 { verticalFlip = vFlipState; }
00205
00210 virtual BOOL SetFrameSize(
00211 unsigned width,
00212 unsigned height
00213 );
00214
00223 virtual BOOL SetSrcFrameInfo(
00224 const PVideoFrameInfo & info
00225 );
00226
00235 virtual BOOL SetDstFrameInfo(
00236 const PVideoFrameInfo & info
00237 );
00238
00241 virtual void GetSrcFrameInfo(
00242 PVideoFrameInfo & info
00243 );
00244
00247 virtual void GetDstFrameInfo(
00248 PVideoFrameInfo & info
00249 );
00250
00257 virtual BOOL SetSrcFrameSize(
00258 unsigned width,
00259 unsigned height
00260 );
00261
00268 virtual BOOL SetDstFrameSize(
00269 unsigned width,
00270 unsigned height
00271 );
00272 virtual BOOL SetDstFrameSize(
00273 unsigned width,
00274 unsigned height,
00275 BOOL bScale
00276 );
00277
00280 const PString & GetSrcColourFormat() { return srcColourFormat; }
00281
00284 const PString & GetDstColourFormat() { return dstColourFormat; }
00285
00291 PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; }
00292
00298 PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; }
00299
00300
00310 virtual BOOL Convert(
00311 const BYTE * srcFrameBuffer,
00312 BYTE * dstFrameBuffer,
00313 PINDEX * bytesReturned = NULL
00314 ) = 0;
00315
00316 virtual BOOL Convert(
00317 const BYTE * srcFrameBuffer,
00318 BYTE * dstFrameBuffer,
00319 unsigned int srcFrameBytes,
00320 PINDEX * bytesReturned = NULL
00321 ) = 0;
00322
00339 virtual BOOL ConvertInPlace(
00340 BYTE * frameBuffer,
00341 PINDEX * bytesReturned = NULL,
00342 BOOL noIntermediateFrame = FALSE
00343 );
00344
00345
00350 static PColourConverter * Create(
00351 const PVideoFrameInfo & src,
00352 const PVideoFrameInfo & dst
00353 );
00354 static PColourConverter * Create(
00355 const PString & srcColourFormat,
00356 const PString & destColourFormat,
00357 unsigned width,
00358 unsigned height
00359 );
00360
00363 BOOL GetDstFrameSize(
00364 unsigned & width,
00365 unsigned & height
00366 ) const;
00367
00370 BOOL GetSrcFrameSize(
00371 unsigned & width,
00372 unsigned & height
00373 ) const;
00374
00375 unsigned GetSrcFrameWidth() const { return srcFrameWidth; }
00376 unsigned GetSrcFrameHeight() const { return srcFrameHeight; }
00377 unsigned GetDstFrameWidth() const { return dstFrameWidth; }
00378 unsigned GetDstFrameHeight() const { return dstFrameHeight; }
00379
00382 void SetResizeMode(
00383 PVideoFrameInfo::ResizeMode mode
00384 ) { if (mode < PVideoFrameInfo::eMaxResizeMode) resizeMode = mode; }
00385
00388 PVideoFrameInfo::ResizeMode GetResizeMode() const { return resizeMode; }
00389
00390 protected:
00391 PString srcColourFormat;
00392 PString dstColourFormat;
00393 unsigned srcFrameWidth;
00394 unsigned srcFrameHeight;
00395 unsigned srcFrameBytes;
00396
00397
00398 unsigned dstFrameWidth;
00399 unsigned dstFrameHeight;
00400 unsigned dstFrameBytes;
00401
00402 PVideoFrameInfo::ResizeMode resizeMode;
00403
00404 BOOL verticalFlip;
00405
00406 PBYTEArray intermediateFrameStore;
00407
00408 #ifndef P_MACOSX
00409
00410 struct jdec_private *jdec;
00411 #endif
00412
00413 friend class PColourConverterRegistration;
00414 };
00415
00416
00422 #define PCOLOUR_CONVERTER2(cls,ancestor,srcFmt,dstFmt) \
00423 class cls : public ancestor { \
00424 public: \
00425 cls(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) \
00426 : ancestor(src, dst) { } \
00427 virtual BOOL Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
00428 virtual BOOL Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
00429 }; \
00430 static class cls##_Registration : public PColourConverterRegistration { \
00431 public: cls##_Registration() \
00432 : PColourConverterRegistration(srcFmt,dstFmt) { } \
00433 protected: virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const; \
00434 } p_##cls##_registration_instance; \
00435 PColourConverter * cls##_Registration::Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const \
00436 { return new cls(src, dst); } \
00437 BOOL cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int __srcFrameBytes, PINDEX * bytesReturned) \
00438 { srcFrameBytes = __srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
00439 BOOL cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
00440
00441
00447 #define PCOLOUR_CONVERTER(cls,src,dst) \
00448 PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
00449
00450
00451
00456 class PSynonymColour : public PColourConverter {
00457 public:
00458 PSynonymColour(
00459 const PVideoFrameInfo & src,
00460 const PVideoFrameInfo & dst
00461 ) : PColourConverter(src, dst) { }
00462 virtual BOOL Convert(const BYTE *, BYTE *, PINDEX * = NULL);
00463 virtual BOOL Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
00464 };
00465
00466
00471 class PSynonymColourRegistration : public PColourConverterRegistration {
00472 public:
00473 PSynonymColourRegistration(
00474 const char * srcFmt,
00475 const char * dstFmt
00476 );
00477
00478 protected:
00479 virtual PColourConverter * Create(const PVideoFrameInfo & src, const PVideoFrameInfo & dst) const;
00480 };
00481
00482
00487 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
00488 static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
00489
00490 #endif // P_VIDEO
00491
00492
00493 #endif // _PCONVERT
00494
00495