xref: /aosp_15_r20/external/skia/modules/skcms/src/skcms_Transform.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2018 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #pragma once
9 
10 #include <stddef.h>
11 #include <stdint.h>
12 
13 // skcms_Transform.h contains skcms implementation details.
14 // Please don't use this header from outside the skcms repo.
15 
16 namespace skcms_private {
17 
18 /** All transform ops */
19 
20 #define SKCMS_WORK_OPS(M) \
21     M(load_a8)            \
22     M(load_g8)            \
23     M(load_ga88)          \
24     M(load_4444)          \
25     M(load_565)           \
26     M(load_888)           \
27     M(load_8888)          \
28     M(load_1010102)       \
29     M(load_101010x_XR)    \
30     M(load_10101010_XR)   \
31     M(load_161616LE)      \
32     M(load_16161616LE)    \
33     M(load_161616BE)      \
34     M(load_16161616BE)    \
35     M(load_hhh)           \
36     M(load_hhhh)          \
37     M(load_fff)           \
38     M(load_ffff)          \
39                           \
40     M(swap_rb)            \
41     M(clamp)              \
42     M(invert)             \
43     M(force_opaque)       \
44     M(premul)             \
45     M(unpremul)           \
46     M(matrix_3x3)         \
47     M(matrix_3x4)         \
48                           \
49     M(lab_to_xyz)         \
50     M(xyz_to_lab)         \
51                           \
52     M(gamma_r)            \
53     M(gamma_g)            \
54     M(gamma_b)            \
55     M(gamma_a)            \
56     M(gamma_rgb)          \
57                           \
58     M(tf_r)               \
59     M(tf_g)               \
60     M(tf_b)               \
61     M(tf_a)               \
62     M(tf_rgb)             \
63                           \
64     M(pq_r)               \
65     M(pq_g)               \
66     M(pq_b)               \
67     M(pq_a)               \
68     M(pq_rgb)             \
69                           \
70     M(hlg_r)              \
71     M(hlg_g)              \
72     M(hlg_b)              \
73     M(hlg_a)              \
74     M(hlg_rgb)            \
75                           \
76     M(hlginv_r)           \
77     M(hlginv_g)           \
78     M(hlginv_b)           \
79     M(hlginv_a)           \
80     M(hlginv_rgb)         \
81                           \
82     M(table_r)            \
83     M(table_g)            \
84     M(table_b)            \
85     M(table_a)            \
86                           \
87     M(clut_A2B)           \
88     M(clut_B2A)
89 
90 #define SKCMS_STORE_OPS(M) \
91     M(store_a8)            \
92     M(store_g8)            \
93     M(store_ga88)          \
94     M(store_4444)          \
95     M(store_565)           \
96     M(store_888)           \
97     M(store_8888)          \
98     M(store_1010102)       \
99     M(store_161616LE)      \
100     M(store_16161616LE)    \
101     M(store_161616BE)      \
102     M(store_16161616BE)    \
103     M(store_101010x_XR)    \
104     M(store_hhh)           \
105     M(store_hhhh)          \
106     M(store_fff)           \
107     M(store_ffff)
108 
109 enum class Op : int {
110 #define M(op) op,
111     SKCMS_WORK_OPS(M)
112     SKCMS_STORE_OPS(M)
113 #undef M
114 };
115 
116 /** Constants */
117 
118 #if defined(__clang__) || defined(__GNUC__)
119     static constexpr float INFINITY_ = __builtin_inff();
120 #else
121     static const union {
122         uint32_t bits;
123         float    f;
124     } inf_ = { 0x7f800000 };
125     #define INFINITY_ inf_.f
126 #endif
127 
128 /** Vector type */
129 
130 #if defined(__clang__)
131     template <int N, typename T> using Vec = T __attribute__((ext_vector_type(N)));
132 #elif defined(__GNUC__)
133     // Unfortunately, GCC does not allow us to omit the struct. This will not compile:
134     //   template <int N, typename T> using Vec = T __attribute__((vector_size(N*sizeof(T))));
135     template <int N, typename T> struct VecHelper {
136         typedef T __attribute__((vector_size(N * sizeof(T)))) V;
137     };
138     template <int N, typename T> using Vec = typename VecHelper<N, T>::V;
139 #endif
140 
141 /** Interface */
142 
143 namespace baseline {
144 
145 void run_program(const Op* program, const void** contexts, ptrdiff_t programSize,
146                  const char* src, char* dst, int n,
147                  const size_t src_bpp, const size_t dst_bpp);
148 
149 }
150 namespace hsw {
151 
152 void run_program(const Op* program, const void** contexts, ptrdiff_t programSize,
153                  const char* src, char* dst, int n,
154                  const size_t src_bpp, const size_t dst_bpp);
155 
156 }
157 namespace skx {
158 
159 void run_program(const Op* program, const void** contexts, ptrdiff_t programSize,
160                  const char* src, char* dst, int n,
161                  const size_t src_bpp, const size_t dst_bpp);
162 
163 }
164 }  // namespace skcms_private
165