eLynx SDK
v3.0.1 C++ image processing API reference |
00001 //============================================================================ 00002 // CoreTypes.h Core.Component package 00003 //============================================================================ 00004 // Usage : definitions of every resolution types for multi-platform purpose. 00005 //---------------------------------------------------------------------------- 00006 // 00007 // +----+---------+---------+----------+ 00008 // | | unsigned| signed | floating | 00009 // |bits| integer | integer | point | 00010 // +----+---------+---------+----------+ 00011 // | 8 | uint8 | int8 | - | 00012 // +----+---------+---------+----------+ 00013 // | 16 | uint16 | int16 | - | 00014 // +----+---------+---------+----------+ 00015 // | 32 | uint32 | int32 | float | 00016 // +----+---------+---------+----------+ 00017 // | 64 | uint64 | int64 | double | 00018 // +----+---------+---------+----------+ 00019 // 00020 // For every type, defines to be used 00021 // - typeZERO : zero value of type 00022 // - typeUNIT : unit value of type 00023 // - typeMIN : min limit of type 00024 // - typeMAX : max limit of type 00025 // 00026 // For boolean type use c++ standard bool with value true and false. 00027 //---------------------------------------------------------------------------- 00028 // Copyright (C) 2006 by eLynx project 00029 // 00030 // This library is free software; you can redistribute it and/or 00031 // modify it under the terms of the GNU Library General Public 00032 // License as published by the Free Software Foundation; either 00033 // version 2 of the License, or (at your option) any later version. 00034 // 00035 // This library is distributed in the hope that it will be useful, 00036 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00037 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00038 // See the GNU Library General Public License for more details. 00039 //---------------------------------------------------------------------------- 00040 #ifndef __CoreTypes_h__ 00041 #define __CoreTypes_h__ 00042 00043 #include "elx/core/CoreLib.h" 00044 #include "elx/core/CoreOS.h" 00045 00046 namespace eLynx { 00047 00048 //---------------------------------------------------------------------------- 00049 // invalid pointeur 00050 //---------------------------------------------------------------------------- 00051 #ifndef NULL 00052 #define NULL (0L) 00053 #endif 00054 00057 #define uint8ZERO uint8(0) 00058 #define uint8UNIT uint8(1) 00059 #define uint8MIN uint8(0x00) 00060 #define uint8MAX uint8(0xFF) 00061 00064 #define int8ZERO int8(0) 00065 #define int8UNIT int8(1) 00066 #define int8MIN int8(0x80) 00067 #define int8MAX int8(0x7F) 00068 00071 #define uint16ZERO uint16(0) 00072 #define uint16UNIT uint16(1) 00073 #define uint16MIN uint16(0x0000) 00074 #define uint16MAX uint16(0xFFFF) 00075 00078 #define int16ZERO int16(0) 00079 #define int16UNIT int16(1) 00080 #define int16MIN int16(0x8000) 00081 #define int16MAX int16(0x7FFF) 00082 00085 #define uint32ZERO uint32(0) 00086 #define uint32UNIT uint32(1) 00087 #define uint32MIN uint32(0x00000000) 00088 #define uint32MAX uint32(0xFFFFFFFF) 00089 00092 #define int32ZERO int32(0) 00093 #define int32UNIT int32(1) 00094 #define int32MIN int32(0x80000000) 00095 #define int32MAX int32(0x7FFFFFFF) 00096 00097 00100 #define int64ZERO int64(0) 00101 #define int64UNIT int64(1) 00102 #ifdef elxWINDOWS 00103 #define int64MIN int64(0x8000000000000000) 00104 #define int64MAX int64(0x7FFFFFFFFFFFFFFF) 00105 #else 00106 #define int64MIN (0x8000000000000000LL) 00107 #define int64MAX (0x7FFFFFFFFFFFFFFFLL) 00108 #endif 00109 00110 00113 #define uint64ZERO uint64(0) 00114 #define uint64UNIT uint64(1) 00115 #ifdef elxWINDOWS 00116 #define uint64MIN uint64(0x0000000000000000) 00117 #define uint64MAX uint64(0xFFFFFFFFFFFFFFFF) 00118 #else 00119 #define uint64MIN (0x0000000000000000ULL) 00120 #define uint64MAX (0xFFFFFFFFFFFFFFFFULL) 00121 #endif 00122 00125 #define floatZERO float(0.0f) 00126 #define floatUNIT float(1.0f) 00127 #define floatMIN float(1.175494351e-38f) 00128 #define floatMAX float(3.402823466e+38f) 00129 00131 #define doubleZERO double(0.0) 00132 #define doubleUNIT double(1.0) 00133 #define doubleMIN double(1.7E-308) 00134 #define doubleMAX double(1.7E+308) 00135 00138 enum EResolution 00139 { 00140 RT_INT8, 00141 RT_UINT8, 00142 RT_INT16, 00143 RT_UINT16, 00144 RT_INT32, 00145 RT_UINT32, 00146 RT_INT64, 00147 RT_UINT64, 00148 RT_Float, 00149 RT_Double, 00150 RT_Undefined 00151 }; 00152 00156 ExportedByCore const char * elxToString(EResolution iResolution); 00157 00161 ExportedByCore uint32 elxGetBits(EResolution iResolution); 00162 00163 //---------------------------------------------------------------------------- 00166 template<typename T> 00167 struct ResolutionTypeTraits 00168 { 00169 static const EResolution _Resolution; 00170 static const size_t _Bits; 00171 static const bool _bSigned; 00172 static const bool _bInteger; 00173 static const bool _bLUT; 00174 static const T _Min; 00175 static const T _Max; 00176 static const T _Norm; 00177 static const double _MinInDouble; 00178 static const double _MaxInDouble; 00179 static const double _MaxNormInDouble; 00180 static const double _NormScale; 00181 }; 00182 00183 //---------------------------------------------------------------------------- 00186 template<> 00187 struct ExportedByCore ResolutionTypeTraits<uint8> 00188 { 00189 static const EResolution _Resolution = RT_UINT8; 00190 static const size_t _Bits = 8; 00191 static const bool _bSigned = false; 00192 static const bool _bInteger = true; 00193 static const bool _bLUT = true; 00194 static const uint8 _Min; 00195 static const uint8 _Max; 00196 static const uint8 _Norm; 00197 static const double _MinInDouble; 00198 static const double _MaxInDouble; 00199 static const double _MaxNormInDouble; 00200 static const double _NormScale; 00201 00202 typedef int16 SumOverflow_type; 00203 typedef int32 MulOverflow_type; 00204 typedef int64 BigOverflow_type; 00205 typedef float Floating_type; 00206 00207 static const SumOverflow_type _MinS; 00208 static const SumOverflow_type _MaxS; 00209 static const MulOverflow_type _MinM; 00210 static const MulOverflow_type _MaxM; 00211 static const BigOverflow_type _MinB; 00212 static const BigOverflow_type _MaxB; 00213 static const Floating_type _MinF; 00214 static const Floating_type _MaxF; 00215 00216 static uint8 ClampS(SumOverflow_type iValue) 00217 { 00218 if (iValue < _MinS) return _Min; 00219 if (iValue > _MaxS) return _Max; 00220 return uint8(iValue); 00221 } 00222 static uint8 ClampM(MulOverflow_type iValue) 00223 { 00224 if (iValue < _MinM) return _Min; 00225 if (iValue > _MaxM) return _Max; 00226 return uint8(iValue); 00227 } 00228 static uint8 ClampB(BigOverflow_type iValue) 00229 { 00230 if (iValue < _MinB) return _Min; 00231 if (iValue > _MaxB) return _Max; 00232 return uint8(iValue); 00233 } 00234 static uint8 ClampF(Floating_type iValue) 00235 { 00236 if (iValue < _MinF) return _Min; 00237 if (iValue > _MaxF) return _Max; 00238 return uint8(iValue + 0.5f); 00239 } 00240 static uint8 Clamp(double iValue) 00241 { 00242 if (iValue < _MinInDouble) return _Min; 00243 if (iValue > _MaxInDouble) return _Max; 00244 return uint8(iValue + 0.5); 00245 } 00246 00247 // specific 00248 static const size_t _Cardinality = 1<<_Bits; 00249 static const uint16 _MinInShort = uint16(0x00); 00250 static const uint16 _MaxInShort = uint16(0xFF); 00251 static const int32 _MinInInt = int32(0x00); 00252 static const int32 _MaxInInt = int32(0xFF); 00253 static const float _MinInFloat; 00254 static const float _MaxInFloat; 00255 }; 00256 00257 //---------------------------------------------------------------------------- 00260 template<> 00261 struct ExportedByCore ResolutionTypeTraits<uint16> 00262 { 00263 static const EResolution _Resolution = RT_UINT16; 00264 static const size_t _Bits = 16; 00265 static const bool _bSigned = false; 00266 static const bool _bInteger = true; 00267 static const bool _bLUT = true; 00268 static const uint16 _Min; 00269 static const uint16 _Max; 00270 static const uint16 _Norm; 00271 static const double _MinInDouble; 00272 static const double _MaxInDouble; 00273 static const double _MaxNormInDouble; 00274 static const double _NormScale; 00275 00276 typedef int32 SumOverflow_type; 00277 typedef int32 MulOverflow_type; 00278 typedef int64 BigOverflow_type; 00279 typedef float Floating_type; 00280 00281 static const SumOverflow_type _MinS; 00282 static const SumOverflow_type _MaxS; 00283 static const MulOverflow_type _MinM; 00284 static const MulOverflow_type _MaxM; 00285 static const BigOverflow_type _MinB; 00286 static const BigOverflow_type _MaxB; 00287 static const Floating_type _MinF; 00288 static const Floating_type _MaxF; 00289 00290 static uint16 ClampS(SumOverflow_type iValue) 00291 { 00292 if (iValue < _MinS) return _Min; 00293 if (iValue > _MaxS) return _Max; 00294 return uint16(iValue); 00295 } 00296 static uint16 ClampM(MulOverflow_type iValue) 00297 { 00298 if (iValue < _MinM) return _Min; 00299 if (iValue > _MaxM) return _Max; 00300 return uint16(iValue); 00301 } 00302 static uint16 ClampB(BigOverflow_type iValue) 00303 { 00304 if (iValue < _MinB) return _Min; 00305 if (iValue > _MaxB) return _Max; 00306 return uint16(iValue); 00307 } 00308 static uint16 ClampF(Floating_type iValue) 00309 { 00310 if (iValue < _MinF) return _Min; 00311 if (iValue > _MaxF) return _Max; 00312 return uint16(iValue + 0.5f); 00313 } 00314 static uint16 Clamp(double iValue) 00315 { 00316 if (iValue < _MinInDouble) return _Min; 00317 if (iValue > _MaxInDouble) return _Max; 00318 return uint16(iValue + 0.5); 00319 } 00320 00321 // specific 00322 static const size_t _Cardinality = 1<<_Bits; 00323 static const int32 _MinInInt = int32(0x0000); 00324 static const int32 _MaxInInt = int32(0xFFFF); 00325 static const float _MinInFloat; 00326 static const float _MaxInFloat; 00327 }; 00328 00329 //---------------------------------------------------------------------------- 00332 template<> 00333 struct ExportedByCore ResolutionTypeTraits<int32> 00334 { 00335 static const EResolution _Resolution = RT_INT32; 00336 static const size_t _Bits = 32; 00337 static const bool _bSigned = true; 00338 static const bool _bInteger = true; 00339 static const bool _bLUT = false; 00340 static const int32 _Min; 00341 static const int32 _Max; 00342 static const int32 _Norm; 00343 static const double _MinInDouble; 00344 static const double _MaxInDouble; 00345 static const double _MaxNormInDouble; 00346 static const double _NormScale; 00347 00348 typedef int64 SumOverflow_type; 00349 typedef int64 MulOverflow_type; 00350 typedef int64 BigOverflow_type; 00351 typedef double Floating_type; 00352 00353 static const SumOverflow_type _MinS; 00354 static const SumOverflow_type _MaxS; 00355 static const MulOverflow_type _MinM; 00356 static const MulOverflow_type _MaxM; 00357 static const BigOverflow_type _MinB; 00358 static const BigOverflow_type _MaxB; 00359 static const Floating_type _MinF; 00360 static const Floating_type _MaxF; 00361 00362 static int32 ClampS(SumOverflow_type iValue) 00363 { 00364 if (iValue < _MinS) return _Min; 00365 if (iValue > _MaxS) return _Max; 00366 return int32(iValue); 00367 } 00368 static int32 ClampM(MulOverflow_type iValue) 00369 { 00370 if (iValue < _MinM) return _Min; 00371 if (iValue > _MaxM) return _Max; 00372 return int32(iValue); 00373 } 00374 static int32 ClampB(BigOverflow_type iValue) 00375 { 00376 if (iValue < _MinB) return _Min; 00377 if (iValue > _MaxB) return _Max; 00378 return int32(iValue); 00379 } 00380 static int32 ClampF(Floating_type iValue) 00381 { 00382 if (iValue < _MinF) return _Min; 00383 if (iValue > _MaxF) return _Max; 00384 return int32(iValue + 0.5); 00385 } 00386 static int32 Clamp(double iValue) 00387 { 00388 if (iValue < _MinInDouble) return _Min; 00389 if (iValue > _MaxInDouble) return _Max; 00390 return int32(iValue + 0.5); 00391 } 00392 }; 00393 00394 //---------------------------------------------------------------------------- 00397 template<> 00398 struct ExportedByCore ResolutionTypeTraits<uint32> 00399 { 00400 static const EResolution _Resolution = RT_INT32; 00401 static const size_t _Bits = 32; 00402 static const bool _bSigned = false; 00403 static const bool _bInteger = true; 00404 static const bool _bLUT = false; 00405 static const uint32 _Min; 00406 static const uint32 _Max; 00407 static const uint32 _Norm; 00408 static const double _MinInDouble; 00409 static const double _MaxInDouble; 00410 static const double _MaxNormInDouble; 00411 static const double _NormScale; 00412 00413 typedef int64 SumOverflow_type; 00414 typedef int64 MulOverflow_type; 00415 typedef int64 BigOverflow_type; 00416 typedef double Floating_type; 00417 00418 static const SumOverflow_type _MinS; 00419 static const SumOverflow_type _MaxS; 00420 static const MulOverflow_type _MinM; 00421 static const MulOverflow_type _MaxM; 00422 static const BigOverflow_type _MinB; 00423 static const BigOverflow_type _MaxB; 00424 static const Floating_type _MinF; 00425 static const Floating_type _MaxF; 00426 00427 static uint32 ClampS(SumOverflow_type iValue) 00428 { 00429 if (iValue < _MinS) return _Min; 00430 if (iValue > _MaxS) return _Max; 00431 return uint32(iValue); 00432 } 00433 static uint32 ClampM(MulOverflow_type iValue) 00434 { 00435 if (iValue < _MinM) return _Min; 00436 if (iValue > _MaxM) return _Max; 00437 return uint32(iValue); 00438 } 00439 static uint32 ClampB(BigOverflow_type iValue) 00440 { 00441 if (iValue < _MinB) return _Min; 00442 if (iValue > _MaxB) return _Max; 00443 return uint32(iValue); 00444 } 00445 static uint32 ClampF(Floating_type iValue) 00446 { 00447 if (iValue < _MinF) return _Min; 00448 if (iValue > _MaxF) return _Max; 00449 return uint32(iValue + 0.5); 00450 } 00451 static uint32 Clamp(double iValue) 00452 { 00453 if (iValue < _MinInDouble) return _Min; 00454 if (iValue > _MaxInDouble) return _Max; 00455 return uint32(iValue + 0.5); 00456 } 00457 }; 00458 00459 //---------------------------------------------------------------------------- 00462 template<> 00463 struct ExportedByCore ResolutionTypeTraits<int64> 00464 { 00465 static const EResolution _Resolution = RT_INT64; 00466 static const size_t _Bits = 64; 00467 static const bool _bSigned = true; 00468 static const bool _bInteger = true; 00469 static const bool _bLUT = false; 00470 static const int64 _Min; 00471 static const int64 _Max; 00472 static const int64 _Norm; 00473 static const double _MinInDouble; 00474 static const double _MaxInDouble; 00475 static const double _MaxNormInDouble; 00476 static const double _NormScale; 00477 00478 typedef int64 SumOverflow_type; 00479 typedef int64 MulOverflow_type; 00480 typedef int64 BigOverflow_type; 00481 typedef double Floating_type; 00482 00483 static const SumOverflow_type _MinS; 00484 static const SumOverflow_type _MaxS; 00485 static const MulOverflow_type _MinM; 00486 static const MulOverflow_type _MaxM; 00487 static const BigOverflow_type _MinB; 00488 static const BigOverflow_type _MaxB; 00489 static const Floating_type _MinF; 00490 static const Floating_type _MaxF; 00491 00492 static int64 ClampS(SumOverflow_type iValue) 00493 { 00494 if (iValue < _MinS) return _Min; 00495 if (iValue > _MaxS) return _Max; 00496 return int64(iValue); 00497 } 00498 static int64 ClampM(MulOverflow_type iValue) 00499 { 00500 if (iValue < _MinM) return _Min; 00501 if (iValue > _MaxM) return _Max; 00502 return int64(iValue); 00503 } 00504 static int64 ClampB(BigOverflow_type iValue) 00505 { 00506 if (iValue < _MinB) return _Min; 00507 if (iValue > _MaxB) return _Max; 00508 return int64(iValue); 00509 } 00510 static int64 ClampF(Floating_type iValue) 00511 { 00512 if (iValue < _MinF) return _Min; 00513 if (iValue > _MaxF) return _Max; 00514 return int32(iValue + 0.5); 00515 } 00516 static int64 Clamp(double iValue) 00517 { 00518 if (iValue < _MinInDouble) return _Min; 00519 if (iValue > _MaxInDouble) return _Max; 00520 return int64(iValue + 0.5); 00521 } 00522 }; 00523 00524 //---------------------------------------------------------------------------- 00527 template<> 00528 struct ExportedByCore ResolutionTypeTraits<float> 00529 { 00530 static const EResolution _Resolution = RT_Float; 00531 static const size_t _Bits = 32; 00532 static const bool _bSigned = true; 00533 static const bool _bInteger = false; 00534 static const bool _bLUT = false; 00535 static const float _Min; 00536 static const float _Max; 00537 static const float _Norm; 00538 static const double _MinInDouble; 00539 static const double _MaxInDouble; 00540 static const double _MaxNormInDouble; 00541 static const double _NormScale; 00542 00543 typedef double SumOverflow_type; 00544 typedef double MulOverflow_type; 00545 typedef double BigOverflow_type; 00546 typedef double Floating_type; 00547 00548 static const SumOverflow_type _MinS; 00549 static const SumOverflow_type _MaxS; 00550 static const MulOverflow_type _MinM; 00551 static const MulOverflow_type _MaxM; 00552 static const BigOverflow_type _MinB; 00553 static const BigOverflow_type _MaxB; 00554 static const Floating_type _MinF; 00555 static const Floating_type _MaxF; 00556 00557 static float ClampS(SumOverflow_type iValue) 00558 { 00559 if (iValue < _MinS) return _Min; 00560 if (iValue > _MaxS) return _Max; 00561 return float(iValue); 00562 } 00563 static float ClampM(MulOverflow_type iValue) 00564 { 00565 if (iValue < _MinM) return _Min; 00566 if (iValue > _MaxM) return _Max; 00567 return float(iValue); 00568 } 00569 static float ClampB(BigOverflow_type iValue) 00570 { 00571 if (iValue < _MinB) return _Min; 00572 if (iValue > _MaxB) return _Max; 00573 return float(iValue); 00574 } 00575 static float ClampF(Floating_type iValue) 00576 { 00577 if (iValue < _MinF) return _Min; 00578 if (iValue > _MaxF) return _Max; 00579 return float(iValue); 00580 } 00581 static float Clamp(double iValue) 00582 { 00583 if (iValue < _MinInDouble) return _Min; 00584 if (iValue > _MaxInDouble) return _Max; 00585 return float(iValue); 00586 } 00587 00588 // specific 00589 static const float _NaN; // not a number 00590 static const float _InfNeg; // -infini 00591 static const float _InfPos; // +infini 00592 }; 00593 00594 //---------------------------------------------------------------------------- 00597 template<> 00598 struct ExportedByCore ResolutionTypeTraits<double> 00599 { 00600 static const EResolution _Resolution = RT_Double; 00601 static const size_t _Bits = 64; 00602 static const bool _bSigned = true; 00603 static const bool _bInteger = false; 00604 static const bool _bLUT = false; 00605 static const double _Min; 00606 static const double _Max; 00607 static const double _Norm; 00608 static const double _MinInDouble; 00609 static const double _MaxInDouble; 00610 static const double _MaxNormInDouble; 00611 static const double _NormScale; 00612 00613 typedef double SumOverflow_type; 00614 typedef double MulOverflow_type; 00615 typedef double BigOverflow_type; 00616 typedef double Floating_type; 00617 00618 static const SumOverflow_type _MinS; 00619 static const SumOverflow_type _MaxS; 00620 static const MulOverflow_type _MinM; 00621 static const MulOverflow_type _MaxM; 00622 static const BigOverflow_type _MinB; 00623 static const BigOverflow_type _MaxB; 00624 static const Floating_type _MinF; 00625 static const Floating_type _MaxF; 00626 00627 static double ClampS(SumOverflow_type iValue) { return iValue; } 00628 static double ClampM(MulOverflow_type iValue) { return iValue; } 00629 static double ClampB(BigOverflow_type iValue) { return iValue; } 00630 static double ClampF(Floating_type iValue) { return iValue; } 00631 static double Clamp(double iValue) { return iValue; } 00632 00633 // specific 00634 static const double _NaN; // not a number 00635 static const double _InfNeg; // -infini 00636 static const double _InfPos; // +infini 00637 }; 00638 00639 } // namespace eLynx 00640 00641 // out of namespace 00642 00643 template<int N> 00644 struct IntToType { enum {_Type = N}; }; 00645 00646 //---------------------------------------------------------------------------- 00649 template<bool B> 00650 struct IntegerToType { enum {_Type = B}; }; 00651 00652 typedef IntegerToType<true> IntegerType; 00653 typedef IntegerToType<false> FloatType; 00654 00655 #define INTEGER_TYPE(_T_) (IntegerToType< ResolutionTypeTraits<_T_>::_bInteger >()) 00656 00657 //---------------------------------------------------------------------------- 00660 template<bool B> 00661 struct LutToType{ enum {_Type = B}; }; 00662 00663 typedef LutToType<true> LutType; 00664 typedef LutToType<false> NonLutType; 00665 00666 #define LUT_TYPE(_T_) (LutToType< ResolutionTypeTraits<_T_>::_bLUT >()) 00667 00668 #endif // __CoreTypes_h__