ImfConvert.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMF_CONVERT_H
  6. #define INCLUDED_IMF_CONVERT_H
  7. //-----------------------------------------------------------------------------
  8. //
  9. // Routines for converting between pixel data types,
  10. // with well-defined behavior for exceptional cases,
  11. // without depending on how hardware and operating
  12. // system handle integer overflows and floating-point
  13. // exceptions.
  14. //
  15. //-----------------------------------------------------------------------------
  16. #include "ImfExport.h"
  17. #include "ImfNamespace.h"
  18. #include <half.h>
  19. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  20. //---------------------------------------------------------
  21. // Conversion from half or float to unsigned int:
  22. //
  23. // input result
  24. // ---------------------------------------------------
  25. //
  26. // finite, >= 0 input, cast to unsigned int
  27. // (rounds towards zero)
  28. //
  29. // finite, < 0 0
  30. //
  31. // NaN 0
  32. //
  33. // +infinity UINT_MAX
  34. //
  35. // -infinity 0
  36. //
  37. //---------------------------------------------------------
  38. IMF_EXPORT unsigned int halfToUint (half h);
  39. IMF_EXPORT unsigned int floatToUint (float f);
  40. //---------------------------------------------------------
  41. // Conversion from unsigned int or float to half:
  42. //
  43. // input result
  44. // ---------------------------------------------------
  45. //
  46. // finite, closest possible half
  47. // magnitude <= HALF_MAX
  48. //
  49. // finite, > HALF_MAX +infinity
  50. //
  51. // finite, < -HALF_MAX -infinity
  52. //
  53. // NaN NaN
  54. //
  55. // +infinity +infinity
  56. //
  57. // -infinity -infinity
  58. //
  59. //---------------------------------------------------------
  60. IMF_EXPORT half uintToHalf (unsigned int ui);
  61. IMF_EXPORT half floatToHalf (float f);
  62. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  63. #endif