sharpyuv_csp.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. kSharpYuvMatrixWebp = 0,
  38. kSharpYuvMatrixRec601Limited,
  39. kSharpYuvMatrixRec601Full,
  40. kSharpYuvMatrixRec709Limited,
  41. kSharpYuvMatrixRec709Full,
  42. kSharpYuvMatrixNum
  43. } SharpYuvMatrixType;
  44. // Returns a pointer to a matrix for one of the predefined colorspaces.
  45. SHARPYUV_EXTERN const SharpYuvConversionMatrix* SharpYuvGetConversionMatrix(
  46. SharpYuvMatrixType matrix_type);
  47. #ifdef __cplusplus
  48. } // extern "C"
  49. #endif
  50. #endif // WEBP_SHARPYUV_SHARPYUV_CSP_H_