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 #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
00316 unsigned dstFrameWidth;
00317 unsigned dstFrameHeight;
00318 BOOL scaleNotCrop;
00319
00320 BOOL verticalFlip;
00321
00322 PBYTEArray intermediateFrameStore;
00323
00324 #ifndef P_MACOSX
00325
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