sharpyuv_csp.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2022 Google Inc. All Rights Reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the COPYING file in the root of the source
  5. // tree. An additional intellectual property rights grant can be found
  6. // in the file PATENTS. All contributing project authors may
  7. // be found in the AUTHORS file in the root of the source tree.
  8. // -----------------------------------------------------------------------------
  9. //
  10. // Colorspace utilities.
  11. #ifndef WEBP_SHARPYUV_SHARPYUV_CSP_H_
  12. #define WEBP_SHARPYUV_SHARPYUV_CSP_H_
  13. #include "sharpyuv/sharpyuv.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. // Range of YUV values.
  18. typedef enum {
  19. kSharpYuvRangeFull, // YUV values between [0;255] (for 8 bit)
  20. kSharpYuvRangeLimited // Y in [16;235], YUV in [16;240] (for 8 bit)
  21. } SharpYuvRange;
  22. // Constants that define a YUV color space.
  23. typedef struct {
  24. // Kr and Kb are defined such that:
  25. // Y = Kr * r + Kg * g + Kb * b where Kg = 1 - Kr - Kb.
  26. float kr;
  27. float kb;
  28. int bit_depth; // 8, 10 or 12
  29. SharpYuvRange range;
  30. } SharpYuvColorSpace;
  31. // Fills in 'matrix' for the given YUVColorSpace.
  32. void SharpYuvComputeConversionMatrix(const SharpYuvColorSpace* yuv_color_space,
  33. SharpYuvConversionMatrix* matrix);
  34. // Enums for precomputed conversion matrices.
  35. typedef enum {
  36. kSharpYuvMatrixWebp = 0,
  37. kSharpYuvMatrixRec601Limited,
  38. kSharpYuvMatrixRec601Full,
  39. kSharpYuvMatrixRec709Limited,
  40. kSharpYuvMatrixRec709Full,
  41. kSharpYuvMatrixNum
  42. } SharpYuvMatrixType;
  43. // Returns a pointer to a matrix for one of the predefined colorspaces.
  44. const SharpYuvConversionMatrix* SharpYuvGetConversionMatrix(
  45. SharpYuvMatrixType matrix_type);
  46. #ifdef __cplusplus
  47. } // extern "C"
  48. #endif
  49. #endif // WEBP_SHARPYUV_SHARPYUV_CSP_H_