jpayne@69: // Copyright 2022 Google Inc. All Rights Reserved. jpayne@69: // jpayne@69: // Use of this source code is governed by a BSD-style license jpayne@69: // that can be found in the COPYING file in the root of the source jpayne@69: // tree. An additional intellectual property rights grant can be found jpayne@69: // in the file PATENTS. All contributing project authors may jpayne@69: // be found in the AUTHORS file in the root of the source tree. jpayne@69: // ----------------------------------------------------------------------------- jpayne@69: // jpayne@69: // Colorspace utilities. jpayne@69: jpayne@69: #ifndef WEBP_SHARPYUV_SHARPYUV_CSP_H_ jpayne@69: #define WEBP_SHARPYUV_SHARPYUV_CSP_H_ jpayne@69: jpayne@69: #include "sharpyuv/sharpyuv.h" jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: // Range of YUV values. jpayne@69: typedef enum { jpayne@69: kSharpYuvRangeFull, // YUV values between [0;255] (for 8 bit) jpayne@69: kSharpYuvRangeLimited // Y in [16;235], YUV in [16;240] (for 8 bit) jpayne@69: } SharpYuvRange; jpayne@69: jpayne@69: // Constants that define a YUV color space. jpayne@69: typedef struct { jpayne@69: // Kr and Kb are defined such that: jpayne@69: // Y = Kr * r + Kg * g + Kb * b where Kg = 1 - Kr - Kb. jpayne@69: float kr; jpayne@69: float kb; jpayne@69: int bit_depth; // 8, 10 or 12 jpayne@69: SharpYuvRange range; jpayne@69: } SharpYuvColorSpace; jpayne@69: jpayne@69: // Fills in 'matrix' for the given YUVColorSpace. jpayne@69: SHARPYUV_EXTERN void SharpYuvComputeConversionMatrix( jpayne@69: const SharpYuvColorSpace* yuv_color_space, jpayne@69: SharpYuvConversionMatrix* matrix); jpayne@69: jpayne@69: // Enums for precomputed conversion matrices. jpayne@69: typedef enum { jpayne@69: // WebP's matrix, similar but not identical to kSharpYuvMatrixRec601Limited jpayne@69: kSharpYuvMatrixWebp = 0, jpayne@69: // Kr=0.2990f Kb=0.1140f bit_depth=8 range=kSharpYuvRangeLimited jpayne@69: kSharpYuvMatrixRec601Limited, jpayne@69: // Kr=0.2990f Kb=0.1140f bit_depth=8 range=kSharpYuvRangeFull jpayne@69: kSharpYuvMatrixRec601Full, jpayne@69: // Kr=0.2126f Kb=0.0722f bit_depth=8 range=kSharpYuvRangeLimited jpayne@69: kSharpYuvMatrixRec709Limited, jpayne@69: // Kr=0.2126f Kb=0.0722f bit_depth=8 range=kSharpYuvRangeFull jpayne@69: kSharpYuvMatrixRec709Full, jpayne@69: kSharpYuvMatrixNum jpayne@69: } SharpYuvMatrixType; jpayne@69: jpayne@69: // Returns a pointer to a matrix for one of the predefined colorspaces. jpayne@69: SHARPYUV_EXTERN const SharpYuvConversionMatrix* SharpYuvGetConversionMatrix( jpayne@69: SharpYuvMatrixType matrix_type); jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } // extern "C" jpayne@69: #endif jpayne@69: jpayne@69: #endif // WEBP_SHARPYUV_SHARPYUV_CSP_H_