zoh_utils.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright 2007 nVidia, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  5. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
  6. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7. See the License for the specific language governing permissions and limitations under the License.
  8. */
  9. // utility class holding common routines
  10. #ifndef _ZOH_UTILS_H
  11. #define _ZOH_UTILS_H
  12. #include "nvmath/vector.h"
  13. namespace ZOH {
  14. inline int SIGN_EXTEND(int x, int nb) { return ((((signed(x))&(1<<((nb)-1)))?((~0)<<(nb)):0)|(signed(x))); }
  15. enum Field {
  16. FIELD_M = 1, // mode
  17. FIELD_D = 2, // distribution/shape
  18. FIELD_RW = 10+0, FIELD_RX = 10+1, FIELD_RY = 10+2, FIELD_RZ = 10+3, // red channel endpoints or deltas
  19. FIELD_GW = 20+0, FIELD_GX = 20+1, FIELD_GY = 20+2, FIELD_GZ = 20+3, // green channel endpoints or deltas
  20. FIELD_BW = 30+0, FIELD_BX = 30+1, FIELD_BY = 30+2, FIELD_BZ = 30+3, // blue channel endpoints or deltas
  21. };
  22. // some constants
  23. static const int F16S_MASK = 0x8000; // f16 sign mask
  24. static const int F16EM_MASK = 0x7fff; // f16 exp & mantissa mask
  25. static const int U16MAX = 0xffff;
  26. static const int S16MIN = -0x8000;
  27. static const int S16MAX = 0x7fff;
  28. static const int INT16_MASK = 0xffff;
  29. static const int F16MAX = 0x7bff; // MAXFLT bit pattern for halfs
  30. enum Format { UNSIGNED_F16, SIGNED_F16 };
  31. class Utils
  32. {
  33. public:
  34. static Format FORMAT; // this is a global -- we're either handling unsigned or unsigned half values
  35. // error metrics
  36. static float norm(const nv::Vector3 &a, const nv::Vector3 &b);
  37. static float mpsnr_norm(const nv::Vector3 &a, int exposure, const nv::Vector3 &b);
  38. // conversion & clamp
  39. static int ushort_to_format(unsigned short input);
  40. static unsigned short format_to_ushort(int input);
  41. // clamp to format
  42. static void clamp(nv::Vector3 &v);
  43. // quantization and unquantization
  44. static int finish_unquantize(int q, int prec);
  45. static int unquantize(int q, int prec);
  46. static int quantize(float value, int prec);
  47. static void parse(const char *encoding, int &ptr, Field & field, int &endbit, int &len);
  48. // lerping
  49. static int lerp(int a, int b, int i, int denom);
  50. static nv::Vector3 lerp(const nv::Vector3 & a, const nv::Vector3 & b, int i, int denom);
  51. };
  52. }
  53. #endif // _ZOH_UTILS_H