colorspace.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright 2011-2013 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __COLORSPACE_H__
  17. #define __COLORSPACE_H__
  18. #include "util/util_map.h"
  19. #include "util/util_param.h"
  20. CCL_NAMESPACE_BEGIN
  21. extern ustring u_colorspace_auto;
  22. extern ustring u_colorspace_raw;
  23. extern ustring u_colorspace_srgb;
  24. class ColorSpaceProcessor;
  25. class ColorSpaceManager {
  26. public:
  27. /* Convert used specified colorspace to a colorspace that we are able to
  28. * convert to and from. If the colorspace is u_colorspace_auto, we auto
  29. * detect a colospace. */
  30. static ustring detect_known_colorspace(ustring colorspace,
  31. const char *file_format,
  32. bool is_float);
  33. /* Test if colorspace is for non-color data. */
  34. static bool colorspace_is_data(ustring colorspace);
  35. /* Convert pixels in the specified colorspace to scene linear color for
  36. * rendering. Must be a colorspace returned from detect_known_colorspace. */
  37. template<typename T>
  38. static void to_scene_linear(ustring colorspace,
  39. T *pixels,
  40. size_t width,
  41. size_t height,
  42. size_t depth,
  43. bool compress_as_srgb);
  44. /* Efficiently convert pixels to scene linear colorspace at render time,
  45. * for OSL where the image texture cache contains original pixels. The
  46. * handle is valid for the lifetime of the application. */
  47. static ColorSpaceProcessor *get_processor(ustring colorspace);
  48. static void to_scene_linear(ColorSpaceProcessor *processor, float *pixel, int channels);
  49. /* Clear memory when the application exits. Invalidates all processors. */
  50. static void free_memory();
  51. private:
  52. static void is_builtin_colorspace(ustring colorspace, bool &is_no_op, bool &is_srgb);
  53. };
  54. CCL_NAMESPACE_END
  55. #endif /* __COLORSPACE_H__ */