eLynx SDK
v3.0.1 C++ image processing API reference |
00001 //============================================================================ 00002 // PixelBase.h Image.Component package 00003 //============================================================================ 00004 // Usage : define common functionality for different types of pixels 00005 //---------------------------------------------------------------------------- 00006 // Copyright (C) 2006 by eLynx project 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 // See the GNU Library General Public License for more details. 00017 //---------------------------------------------------------------------------- 00018 #ifndef __PixelBase_h__ 00019 #define __PixelBase_h__ 00020 00021 namespace eLynx { 00022 namespace Image { 00023 00025 enum { PC_MAX=4 }; 00026 00027 bool elxUseChannel(uint32 iChannel, uint32 iChannelMask); 00028 00029 template<typename T> 00030 struct ExportedByImage SampleTypeTraits 00031 { 00032 static const T _black; 00033 static const T _white; 00034 }; 00035 00038 00039 template <class Pixel> 00040 struct PixelBase 00041 { 00044 Pixel Add(const Pixel& iOther) const; 00045 Pixel AddClamp(const Pixel& iOther) const; 00046 Pixel Add(const Pixel& iOther, const uint32 iChannelMask) const; 00047 Pixel AddClamp(const Pixel& iOther, const uint32 iChannelMask) const; 00048 Pixel& AddSelf(const Pixel& iOther); 00049 Pixel& AddClampSelf(const Pixel& iOther); 00050 template <typename U> Pixel Add(const U iValue) const; 00051 template <typename U> Pixel AddClamp(const U iValue) const; 00052 template <typename U> Pixel Add(const U iValue, const uint32 iChannelMask) const; 00053 template <typename U> Pixel AddClamp(const U iValue, const uint32 iChannelMask) const; 00054 template <typename U> Pixel& AddSelf(const U iValue); 00055 template <typename U> Pixel& AddClampSelf(const U iValue); 00057 00060 Pixel Sub(const Pixel& iOther) const; 00061 Pixel SubClamp(const Pixel& iOther) const; 00062 Pixel Sub(const Pixel& iOther, const uint32 iChannelMask) const; 00063 Pixel SubClamp(const Pixel& iOther, const uint32 iChannelMask) const; 00064 Pixel SubAbsClamp(const Pixel& iOther) const; 00065 Pixel SubAbsClamp(const Pixel& iOther, const uint32 iChannelMask) const; 00066 Pixel& SubSelf(const Pixel& iOther); 00067 Pixel& SubClampSelf(const Pixel& iOther); 00068 template <typename U> Pixel Sub(const U iValue) const; 00069 template <typename U> Pixel SubClamp(const U iValue) const; 00070 template <typename U> Pixel Sub(const U iValue, const uint32 iChannelMask) const; 00071 template <typename U> Pixel SubClamp(const U iValue, const uint32 iChannelMask) const; 00072 template <typename U> Pixel& SubSelf(const U iValue); 00073 template <typename U> Pixel& SubClampSelf(const U iValue); 00075 00078 Pixel Mul(const Pixel& iOther) const; 00079 Pixel MulClamp(const Pixel& iOther) const; 00080 Pixel Mul(const Pixel& iOther, const uint32 iChannelMask) const; 00081 Pixel MulClamp(const Pixel& iOther, const uint32 iChannelMask) const; 00082 Pixel& MulSelf(const Pixel& iOther); 00083 Pixel& MulClampSelf(const Pixel& iOther); 00084 template <typename U> Pixel Mul(const U iValue) const; 00085 template <typename U> Pixel MulClamp(const U iValue) const; 00086 template <typename U> Pixel Mul(const U iValue, const uint32 iChannelMask) const; 00087 template <typename U> Pixel MulClamp(const U iValue, const uint32 iChannelMask) const; 00088 template <typename U> Pixel& MulSelf(const U iValue); 00089 template <typename U> Pixel& MulClampSelf(const U iValue); 00091 00094 00095 Pixel Div(const Pixel& iOther, FloatType) const; 00096 Pixel Div(const Pixel& iOther, IntegerType) const; 00097 Pixel Div(const Pixel& iOther, FloatType, const uint32 iChannelMask) const; 00098 Pixel Div(const Pixel& iOther, IntegerType, const uint32 iChannelMask) const; 00099 Pixel& DivSelf(const Pixel& iOther, FloatType); 00100 Pixel& DivSelf(const Pixel& iOther, IntegerType); 00101 00102 template <typename U> Pixel Div(const U iValue, FloatType) const; 00103 template <typename U> Pixel Div(const U iValue, IntegerType) const; 00104 template <typename U> Pixel Div(const U iValue, FloatType, const uint32 iChannelMask) const; 00105 template <typename U> Pixel Div(const U iValue, IntegerType, const uint32 iChannelMask) const; 00106 template <typename U> Pixel& DivSelf(const U iValue, FloatType); 00107 template <typename U> Pixel& DivSelf(const U iValue, IntegerType); 00109 00110 00113 00114 bool Equal(const Pixel& iOther) const; 00116 00119 00120 template <typename U> 00121 Pixel& PowSelf(const U& iValue, FloatType); 00122 00123 template <typename U> 00124 Pixel& PowSelf(const U& iValue, IntegerType); 00125 00126 template <typename U> 00127 Pixel& PowSelf(const U& iValue); 00128 00129 Pixel& PowSelf(const Pixel& iOther, FloatType); 00130 Pixel& PowSelf(const Pixel& iOther, IntegerType); 00131 00132 Pixel& ExpSelf(FloatType); 00133 Pixel& ExpSelf(IntegerType); 00134 00135 Pixel& LogSelf(FloatType); 00136 Pixel& LogSelf(IntegerType); 00137 00138 Pixel& Log10Self(FloatType); 00139 Pixel& Log10Self(IntegerType); 00140 00141 Pixel& SqrtSelf(FloatType); 00142 Pixel& SqrtSelf(IntegerType); 00143 00144 template <typename U> 00145 Pixel Pow(const U& iValue, FloatType) const; 00146 00147 template <typename U> 00148 Pixel Pow(const U& iValue, IntegerType) const; 00149 00150 Pixel Pow(const Pixel& iOther, FloatType) const; 00151 Pixel Pow(const Pixel& iOther, IntegerType) const; 00152 00153 Pixel Exp(FloatType) const; 00154 Pixel Exp(IntegerType) const; 00155 00156 Pixel Log(FloatType) const; 00157 Pixel Log(IntegerType) const; 00158 00159 Pixel Log10(FloatType) const; 00160 Pixel Log10(IntegerType) const; 00161 00162 Pixel Sqrt(FloatType) const; 00163 Pixel Sqrt(IntegerType) const; 00165 00166 }; 00167 00170 00171 template <class Pixel> 00172 Pixel operator+ (const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00173 00174 template <class Pixel> 00175 Pixel operator+ (const PixelBase<Pixel>& iPixel, const typename Pixel::type iValue); 00176 00177 template <class Pixel> 00178 Pixel operator+ (const typename Pixel::type iValue, const PixelBase<Pixel>& iPixel); 00179 00180 template <class Pixel> 00181 Pixel& operator+= (PixelBase<Pixel>& ioFirst, const Pixel& iSecond); 00182 00183 template <class Pixel> 00184 Pixel& operator+= (PixelBase<Pixel>& ioPixel, const typename Pixel::type iValue); 00186 00187 00190 00191 template <class Pixel> 00192 Pixel operator- (const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00193 00194 template <class Pixel> 00195 Pixel operator- (const PixelBase<Pixel>& iPixel, const typename Pixel::type iValue); 00196 00197 template <class Pixel> 00198 Pixel operator- (const typename Pixel::type iValue, const PixelBase<Pixel>& iPixel); 00199 00200 template <class Pixel> 00201 Pixel& operator-= (PixelBase<Pixel>& ioFirst, const Pixel& iSecond); 00202 00203 template <class Pixel> 00204 Pixel& operator-= (PixelBase<Pixel>& ioPixel, const typename Pixel::type iValue); 00206 00207 00210 template <class Pixel> 00211 Pixel operator* (const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00212 00213 template <class Pixel> 00214 Pixel operator* (const PixelBase<Pixel>& iPixel, const typename Pixel::type iValue); 00215 00216 template <class Pixel> 00217 Pixel operator* (const typename Pixel::type iValue, const PixelBase<Pixel>& iPixel); 00218 00219 template <class Pixel> 00220 Pixel& operator*= (PixelBase<Pixel>& ioFirst, const Pixel& iSecond); 00221 00222 template <class Pixel> 00223 Pixel& operator*= (PixelBase<Pixel>& ioPixel, const typename Pixel::type iValue); 00225 00228 00229 template <class Pixel> 00230 Pixel operator/ (const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00231 00232 template <class Pixel> 00233 Pixel operator/ (const PixelBase<Pixel>& iPixel, const typename Pixel::type iValue); 00234 00235 template <class Pixel> 00236 Pixel& operator/= (PixelBase<Pixel>& ioFirst, const Pixel& iSecond); 00237 00238 template <class Pixel> 00239 Pixel& operator/= (PixelBase<Pixel>& ioPixel, const typename Pixel::type iValue); 00241 00244 00245 template <class Pixel> 00246 bool operator == (const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00247 00248 template <class Pixel> 00249 bool operator != (const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00250 00251 template <class Pixel> 00252 bool elxPixelEqual(const Pixel& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00254 00255 00256 00259 00260 template <class Pixel> 00261 Pixel elxPixelAdd(const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00262 00263 template <class Pixel> 00264 Pixel elxPixelAdd(const PixelBase<Pixel>& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00265 00266 template <class Pixel, typename U> 00267 Pixel elxPixelAdd(const PixelBase<Pixel>& iPixel, const U& iValue); 00268 00269 template <class Pixel, typename U> 00270 Pixel elxPixelAdd(const PixelBase<Pixel>& iPixel, const U& iValue, const uint32 iChannelMask); 00271 00272 template <class Pixel> 00273 Pixel elxPixelAddClamp(const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00274 00275 template <class Pixel> 00276 Pixel elxPixelAddClamp(const PixelBase<Pixel>& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00277 00278 template <class Pixel, typename U> 00279 Pixel elxPixelAddClamp(const PixelBase<Pixel>& iPixel, const U& iValue); 00280 00281 template <class Pixel, typename U> 00282 Pixel elxPixelAddClamp(const PixelBase<Pixel>& iPixel, const U& iValue, const uint32 iChannelMask); 00284 00287 template <class Pixel> 00288 Pixel elxPixelSub(const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00289 00290 template <class Pixel> 00291 Pixel elxPixelSub(const PixelBase<Pixel>& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00292 00293 template <class Pixel, typename U> 00294 Pixel elxPixelSub(const PixelBase<Pixel>& iPixel, const U& iValue); 00295 00296 template <class Pixel, typename U> 00297 Pixel elxPixelSub(const PixelBase<Pixel>& iPixel, const U& iValue, const uint32 iChannelMask); 00298 00299 template <class Pixel> 00300 Pixel elxPixelSubClamp(const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00301 00302 template <class Pixel> 00303 Pixel elxPixelSubClamp(const PixelBase<Pixel>& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00304 00305 template <class Pixel, typename U> 00306 Pixel elxPixelSubClamp(const PixelBase<Pixel>& iPixel, const U& iValue); 00307 00308 template <class Pixel, typename U> 00309 Pixel elxPixelSubClamp(const PixelBase<Pixel>& iPixel, const U& iValue, const uint32 iChannelMask); 00310 00311 template <class Pixel> 00312 Pixel elxPixelSubAbsClamp(const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00313 00314 template <class Pixel> 00315 Pixel elxPixelSubAbsClamp(const PixelBase<Pixel>& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00317 00320 00321 template <class Pixel> 00322 Pixel elxPixelMul(const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00323 00324 template <class Pixel> 00325 Pixel elxPixelMul(const PixelBase<Pixel>& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00326 00327 template <class Pixel, typename U> 00328 Pixel elxPixelMul(const PixelBase<Pixel>& iPixel, const U& iValue); 00329 00330 template <class Pixel, typename U> 00331 Pixel elxPixelMul(const PixelBase<Pixel>& iPixel, const U& iValue, const uint32 iChannelMask); 00332 00333 template <class Pixel> 00334 Pixel elxPixelMulClamp(const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00335 00336 template <class Pixel> 00337 Pixel elxPixelMulClamp(const PixelBase<Pixel>& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00338 00340 00343 00344 template <class Pixel> 00345 Pixel elxPixelDiv(const PixelBase<Pixel>& iFirst, const Pixel& iSecond); 00346 00347 template <class Pixel> 00348 Pixel elxPixelDiv(const PixelBase<Pixel>& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00349 00350 template <class Pixel, typename U> 00351 Pixel elxPixelDiv(const PixelBase<Pixel>& iPixel, const U& iValue); 00352 00353 template <class Pixel, typename U> 00354 Pixel elxPixelDiv(const PixelBase<Pixel>& iPixel, const U& iValue, const uint32 iChannelMask); 00356 00359 00360 template <class Pixel> 00361 Pixel& elxSqrtSelf(PixelBase<Pixel>& ioPixel); 00362 00363 template <typename U, class Pixel> 00364 Pixel& elxPowSelf(PixelBase<Pixel>& ioPixel, const U& iValue); 00365 00366 template <class Pixel> 00367 Pixel& elxPixelPowSelf(PixelBase<Pixel>& ioPixel1, const Pixel& iPixel2); 00368 00369 template <class Pixel> 00370 Pixel& elxPixelExpSelf(PixelBase<Pixel>& ioPixel); 00371 00372 template <class Pixel> 00373 Pixel& elxPixelLogSelf(PixelBase<Pixel>& ioPixel); 00374 00375 template <class Pixel> 00376 Pixel& elxPixelLog10Self(PixelBase<Pixel>& ioPixel); 00377 00378 template <class Pixel> 00379 Pixel& elxPixelSqrtSelf(PixelBase<Pixel>& ioPixel); 00380 00381 template <typename U, class Pixel> 00382 Pixel elxPixelPow(const PixelBase<Pixel>& iPixel, const U& iValue); 00383 00384 template <class Pixel> 00385 Pixel elxPixelPow(const PixelBase<Pixel>& iPixel1, const Pixel& iPixel2); 00386 00387 template <class Pixel> 00388 Pixel elxPixelExp(const PixelBase<Pixel>& iPixel); 00389 00390 template <class Pixel> 00391 Pixel elxPixelLog(const PixelBase<Pixel>& iPixel); 00392 00393 template <class Pixel> 00394 Pixel elxPixelLog10(const PixelBase<Pixel>& iPixel); 00395 00396 template <class Pixel> 00397 Pixel elxPixelSqrt(const PixelBase<Pixel>& iPixel); 00398 00400 00403 00404 template <typename In, typename Out, template <typename> class Pixel> 00405 void elxPixelClamp(const PixelBase<Pixel<In> >& iPixelIn, PixelBase<Pixel<Out> >& oPixelOut); 00406 00407 template <typename In, typename Out, template <typename> class Pixel> 00408 void elxPixelClamp(const PixelBase<Pixel<In> >& iPixelIn, PixelBase<Pixel<Out> >& oPixelOut, FloatType); 00409 00410 template <typename In, typename Out, template <typename> class Pixel> 00411 void elxPixelClamp(const PixelBase<Pixel<In> >& iPixelIn, PixelBase<Pixel<Out> >& oPixelOut, IntegerType); 00412 00413 00414 template <typename In, typename Out, template <typename> class Pixel> 00415 void elxPixelClamp(const PixelBase<Pixel<In> >& iPixelIn, PixelBase<Pixel<Out> >& oPixelOut, const uint32 iChannelMask); 00416 00417 template <typename In, typename Out, template <typename> class Pixel> 00418 void elxPixelClamp(const PixelBase< Pixel<In> >& iPixelIn, PixelBase< Pixel<Out> >& oPixelOut, FloatType, const uint32 iChannelMask); 00419 00420 template <typename In, typename Out, template <typename> class Pixel> 00421 void elxPixelClamp(const PixelBase<Pixel<In> >& iPixelIn, PixelBase<Pixel<Out> >& oPixelOut, IntegerType, const uint32 iChannelMask); 00422 00424 00425 00428 template <class Pixel> 00429 Pixel elxPixelAbs(const Pixel& iPixel); 00430 00431 template <class Pixel> 00432 Pixel elxPixelAbs(const Pixel& iPixel, const uint32 iChannelMask); 00433 00434 template <class Pixel, typename U> 00435 Pixel elxPixelAbsDiff(const Pixel& iPixel, const U& iValue); 00436 00437 template <class Pixel, typename U> 00438 Pixel elxPixelAbsDiff(const Pixel& iPixel, const U& iValue, const uint32 iChannelMask); 00439 00440 template <class Pixel> 00441 Pixel elxPixelAbsDiff(const Pixel& iFirst, const Pixel& iSecond); 00442 00443 template <class Pixel> 00444 Pixel elxPixelAbsDiff(const Pixel& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00445 00447 00450 00451 template <class Pixel, typename U> 00452 Pixel elxPixelMin(const Pixel& iPixel, const U& iValue); 00453 00454 template <class Pixel, typename U> 00455 Pixel elxPixelMin(const Pixel& iPixel, const U& iValue, const uint32 iChannelMask); 00456 00457 template <class Pixel> 00458 Pixel elxPixelMin(const Pixel& iFirst, const Pixel& iSecond); 00459 00460 template <class Pixel> 00461 Pixel elxPixelMin(const Pixel& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00462 00463 00464 template <class Pixel, typename U> 00465 Pixel elxPixelMax(const Pixel& iPixel, const U& iValue); 00466 00467 template <class Pixel, typename U> 00468 Pixel elxPixelMax(const Pixel& iPixel, const U& iValue, const uint32 iChannelMask); 00469 00470 template <class Pixel> 00471 Pixel elxPixelMax(const Pixel& iFirst, const Pixel& iSecond); 00472 00473 template <class Pixel> 00474 Pixel elxPixelMax(const Pixel& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00475 00476 00477 template <class Pixel, typename U> 00478 Pixel elxPixelMean(const Pixel& iPixel, const U& iValue); 00479 00480 template <class Pixel, typename U> 00481 Pixel elxPixelMean(const Pixel& iPixel, const U& iValue, const uint32 iChannelMask); 00482 00483 template <class Pixel> 00484 Pixel elxPixelMean(const Pixel& iFirst, const Pixel& iSecond); 00485 00486 template <class Pixel> 00487 Pixel elxPixelMean(const Pixel& iFirst, const Pixel& iSecond, const uint32 iChannelMask); 00488 00490 00491 template <class Pixel> 00492 void elxPixelNegative(Pixel& ioPixel); 00493 00494 template <class Pixel> 00495 void elxPixelNegative(Pixel& ioPixel, const uint32 iChannelMask); 00496 00497 template <class Pixel> 00498 Pixel elxPixelBlend(const PixelBase<Pixel>& iPixel1, const Pixel& iPixel2, double iScalar); 00499 00500 template <class Pixel> 00501 Pixel elxPixelBlend(const PixelBase<Pixel>& iPixel1, const Pixel& iPixel2, double iScalar, const uint32 iChannelMask); 00502 00503 template <class Pixel> 00504 void elxPixelSet(Pixel& ioPixel, double iValue, const uint32 iChannelMask); 00505 00506 template <class Pixel> 00507 void elxPixelSet(Pixel& ioPixel, const Pixel& iPixel, const uint32 iChannelMask); 00508 00509 template <class Pixel, typename U> 00510 Pixel elxPixelThreshold(const Pixel& iPixel, const U& iValue, const uint32 iChannelMask); 00511 00512 #define PIXEL_INTEGER_TYPE \ 00513 (IntegerToType< ResolutionTypeTraits< typename Pixel::type >::_bInteger >()) 00514 00515 #define PIXEL_LUT_TYPE \ 00516 (LutToType< ResolutionTypeTraits< typename Pixel::type >::_bLUT >()) 00517 00518 //---------------------------------------------------------------------------- 00520 00521 template<bool B> 00522 struct ColorToType{ enum {_Type = B}; }; 00523 00524 typedef ColorToType<true> ColorType; 00525 typedef ColorToType<false> NonColorType; 00526 00527 #define PIXEL_COLOR_TYPE(_PIXEL_) (ColorToType< _PIXEL_::_bColor >()) 00528 00529 //---------------------------------------------------------------------------- 00531 00532 template<bool B> 00533 struct GreyToType{ enum {_Type = B}; }; 00534 00535 typedef GreyToType<true> GreyType; 00536 typedef GreyToType<false> NonGreyType; 00537 00538 #define PIXEL_GREY_TYPE(_PIXEL_) (GreyToType< _PIXEL_::_bGrey >()) 00539 00540 //---------------------------------------------------------------------------- 00542 00543 template<bool B> 00544 struct AlphaToType{ enum {_Type = B}; }; 00545 00546 typedef AlphaToType<true> AlphaType; 00547 typedef AlphaToType<false> NonAlphaType; 00548 00549 #define PIXEL_ALPHA_TYPE(_PIXEL_) (AlphaToType< _PIXEL_::_bHasAlpha >()) 00550 00551 } // namespace Image 00552 } // namespace eLynx 00553 00554 #include "inl/Pixel/PixelBase.inl" 00555 #include "inl/Pixel/Add.inl" 00556 #include "inl/Pixel/Sub.inl" 00557 #include "inl/Pixel/Mul.inl" 00558 #include "inl/Pixel/Div.inl" 00559 #include "inl/Pixel/Power.inl" 00560 00561 #endif // __Pixels_h__