sharpyuv_csp.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. SHARPYUV_EXTERN void SharpYuvComputeConversionMatrix(
  33. const SharpYuvColorSpace* yuv_color_space,
  34. SharpYuvConversionMatrix* matrix);
  35. // Enums for precomputed conversion matrices.
  36. typedef enum {
  37. // WebP's matrix, similar but not identical to kSharpYuvMatrixRec601Limited
  38. kSharpYuvMatrixWebp = 0,
  39. // Kr=0.2990f Kb=0.1140f bit_depth=8 range=kSharpYuvRangeLimited
  40. kSharpYuvMatrixRec601Limited,
  41. // Kr=0.2990f Kb=0.1140f bit_depth=8 range=kSharpYuvRangeFull
  42. kSharpYuvMatrixRec601Full,
  43. // Kr=0.2126f Kb=0.0722f bit_depth=8 range=kSharpYuvRangeLimited
  44. kSharpYuvMatrixRec709Limited,
  45. // Kr=0.2126f Kb=0.0722f bit_depth=8 range=kSharpYuvRangeFull
  46. kSharpYuvMatrixRec709Full,
  47. kSharpYuvMatrixNum
  48. } SharpYuvMatrixType;
  49. // Returns a pointer to a matrix for one of the predefined colorspaces.
  50. SHARPYUV_EXTERN const SharpYuvConversionMatrix* SharpYuvGetConversionMatrix(
  51. SharpYuvMatrixType matrix_type);
  52. #ifdef __cplusplus
  53. } // extern "C"
  54. #endif
  55. #endif // WEBP_SHARPYUV_SHARPYUV_CSP_H_