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