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 #ifndef _PCONVERT
00111 #define _PCONVERT
00112
00113 #ifdef P_USE_PRAGMA
00114 #ifndef P_MACOSX
00115 #pragma interface
00116 #endif
00117 #endif
00118
00119 struct jdec_private;
00120
00121 class PColourConverter;
00122
00128 class PColourConverterRegistration : public PCaselessString
00129 {
00130 PCLASSINFO(PColourConverterRegistration, PCaselessString);
00131 public:
00132 PColourConverterRegistration(
00133 const PString & srcColourFormat,
00134 const PString & destColourFormat
00135 );
00136
00137 virtual PColourConverter * Create(
00138 unsigned width,
00139 unsigned height
00140 ) const = 0;
00141
00142 protected:
00143 PColourConverterRegistration * link;
00144
00145 friend class PColourConverter;
00146 };
00147
00148
00152 class PColourConverter : public PObject
00153 {
00154 PCLASSINFO(PColourConverter, PObject);
00155 public:
00158 PColourConverter(
00159 const PString & srcColourFormat,
00160 const PString & dstColourFormat,
00161 unsigned width,
00162 unsigned height
00163 );
00164
00167 BOOL GetVFlipState()
00168 { return verticalFlip; }
00169
00172 void SetVFlipState(BOOL vFlipState)
00173 { verticalFlip = vFlipState; }
00174
00179 virtual BOOL SetFrameSize(
00180 unsigned width,
00181 unsigned height
00182 );
00183
00190 virtual BOOL SetSrcFrameSize(
00191 unsigned width,
00192 unsigned height
00193 );
00194
00201 virtual BOOL SetDstFrameSize(
00202 unsigned width,
00203 unsigned height,
00204 BOOL bScale
00205 );
00206
00209 const PString & GetSrcColourFormat() { return srcColourFormat; }
00210
00213 const PString & GetDstColourFormat() { return dstColourFormat; }
00214
00220 PINDEX GetMaxSrcFrameBytes() { return srcFrameBytes; }
00221
00227 PINDEX GetMaxDstFrameBytes() { return dstFrameBytes; }
00228
00229
00239 virtual BOOL Convert(
00240 const BYTE * srcFrameBuffer,
00241 BYTE * dstFrameBuffer,
00242 PINDEX * bytesReturned = NULL
00243 ) = 0;
00244
00245 virtual BOOL Convert(
00246 const BYTE * srcFrameBuffer,
00247 BYTE * dstFrameBuffer,
00248 unsigned int srcFrameBytes,
00249 PINDEX * bytesReturned = NULL
00250 ) = 0;
00251
00268 virtual BOOL ConvertInPlace(
00269 BYTE * frameBuffer,
00270 PINDEX * bytesReturned = NULL,
00271 BOOL noIntermediateFrame = FALSE
00272 );
00273
00274
00279 static PColourConverter * Create(
00280 const PString & srcColourFormat,
00281 const PString & dstColourFormat,
00282 unsigned width,
00283 unsigned height
00284 );
00285
00288 BOOL GetDstFrameSize(
00289 unsigned & width,
00290 unsigned & height
00291 ) const;
00292
00295 BOOL GetSrcFrameSize(
00296 unsigned & width,
00297 unsigned & height
00298 ) const;
00299
00300 protected:
00301 PString srcColourFormat;
00302 PString dstColourFormat;
00303 unsigned srcFrameWidth;
00304 unsigned srcFrameHeight;
00305 unsigned srcFrameBytes;
00306 unsigned dstFrameBytes;
00307
00308
00309 unsigned dstFrameWidth;
00310 unsigned dstFrameHeight;
00311 BOOL scaleNotCrop;
00312
00313 BOOL verticalFlip;
00314
00315 PBYTEArray intermediateFrameStore;
00316
00317 #ifndef P_MACOSX
00318
00319 struct jdec_private *jdec;
00320 #endif
00321
00322 friend class PColourConverterRegistration;
00323 };
00324
00325
00331 #define PCOLOUR_CONVERTER2(cls,ancestor,src,dst) \
00332 class cls : public ancestor { \
00333 public: \
00334 cls(const PString & srcFmt, const PString & dstFmt, unsigned w, unsigned h) \
00335 : ancestor(srcFmt, dstFmt, w, h) { } \
00336 virtual BOOL Convert(const BYTE *, BYTE *, PINDEX * = NULL); \
00337 virtual BOOL Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL); \
00338 }; \
00339 static class cls##_Registration : public PColourConverterRegistration { \
00340 public: \
00341 cls##_Registration() \
00342 : PColourConverterRegistration(src,dst) { } \
00343 virtual PColourConverter * Create(unsigned w, unsigned h) const; \
00344 } p_##cls##_registration_instance; \
00345 PColourConverter * cls##_Registration::Create(unsigned w, unsigned h) const \
00346 { PINDEX tab = Find('\t'); return new cls(Left(tab), Mid(tab+1), w, h); } \
00347 BOOL cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, unsigned int __srcFrameBytes, PINDEX * bytesReturned) \
00348 { srcFrameBytes = __srcFrameBytes;return Convert(srcFrameBuffer, dstFrameBuffer, bytesReturned); } \
00349 BOOL cls::Convert(const BYTE *srcFrameBuffer, BYTE *dstFrameBuffer, PINDEX * bytesReturned)
00350
00351
00357 #define PCOLOUR_CONVERTER(cls,src,dst) \
00358 PCOLOUR_CONVERTER2(cls,PColourConverter,src,dst)
00359
00360
00361
00366 class PSynonymColour : public PColourConverter {
00367 public:
00368 PSynonymColour(
00369 const PString & srcFmt,
00370 const PString & dstFmt,
00371 unsigned w, unsigned h
00372 ) : PColourConverter(srcFmt, dstFmt, w, h) { }
00373 virtual BOOL Convert(const BYTE *, BYTE *, PINDEX * = NULL);
00374 virtual BOOL Convert(const BYTE *, BYTE *, unsigned int , PINDEX * = NULL);
00375 };
00376
00377
00382 class PSynonymColourRegistration : public PColourConverterRegistration {
00383 public:
00384 PSynonymColourRegistration(
00385 const char * srcFmt,
00386 const char * dstFmt
00387 );
00388
00389 virtual PColourConverter * Create(unsigned w, unsigned h) const;
00390 };
00391
00392
00397 #define PSYNONYM_COLOUR_CONVERTER(from,to) \
00398 static PSynonymColourRegistration p_##from##_##to##_registration_instance(#from,#to)
00399
00400 #endif
00401
00402