| 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 |
M(hlg_ootf_scale) \ |
| 76 |
\ |
| 77 |
M(hlginv_r) \ |
| 78 |
M(hlginv_g) \ |
| 79 |
M(hlginv_b) \ |
| 80 |
M(hlginv_a) \ |
| 81 |
M(hlginv_rgb) \ |
| 82 |
M(hlginv_ootf_scale) \ |
| 83 |
\ |
| 84 |
M(table_r) \ |
| 85 |
M(table_g) \ |
| 86 |
M(table_b) \ |
| 87 |
M(table_a) \ |
| 88 |
\ |
| 89 |
M(clut_A2B) \ |
| 90 |
M(clut_B2A) |
| 91 |
|
| 92 |
#define SKCMS_STORE_OPS(M) \ |
| 93 |
M(store_a8) \ |
| 94 |
M(store_g8) \ |
| 95 |
M(store_ga88) \ |
| 96 |
M(store_4444) \ |
| 97 |
M(store_565) \ |
| 98 |
M(store_888) \ |
| 99 |
M(store_8888) \ |
| 100 |
M(store_1010102) \ |
| 101 |
M(store_161616LE) \ |
| 102 |
M(store_16161616LE) \ |
| 103 |
M(store_161616BE) \ |
| 104 |
M(store_16161616BE) \ |
| 105 |
M(store_101010x_XR) \ |
| 106 |
M(store_10101010_XR) \ |
| 107 |
M(store_hhh) \ |
| 108 |
M(store_hhhh) \ |
| 109 |
M(store_fff) \ |
| 110 |
M(store_ffff) |
| 111 |
|
| 112 |
enum class Op : int { |
| 113 |
#define M(op) op, |
| 114 |
SKCMS_WORK_OPS(M) |
| 115 |
SKCMS_STORE_OPS(M) |
| 116 |
#undef M |
| 117 |
}; |
| 118 |
|
| 119 |
/** Constants */ |
| 120 |
|
| 121 |
#if defined(__clang__) || defined(__GNUC__) |
| 122 |
static constexpr float INFINITY_ = __builtin_inff(); |
| 123 |
#else |
| 124 |
static const union { |
| 125 |
uint32_t bits; |
| 126 |
float f; |
| 127 |
} inf_ = { 0x7f800000 }; |
| 128 |
#define INFINITY_ inf_.f |
| 129 |
#endif |
| 130 |
|
| 131 |
/** Vector type */ |
| 132 |
|
| 133 |
#if defined(__clang__) |
| 134 |
template <int N, typename T> using Vec = T __attribute__((ext_vector_type(N))); |
| 135 |
#elif defined(__GNUC__) |
| 136 |
// Unfortunately, GCC does not allow us to omit the struct. This will not compile: |
| 137 |
// template <int N, typename T> using Vec = T __attribute__((vector_size(N*sizeof(T)))); |
| 138 |
template <int N, typename T> struct VecHelper { |
| 139 |
typedef T __attribute__((vector_size(N * sizeof(T)))) V; |
| 140 |
}; |
| 141 |
template <int N, typename T> using Vec = typename VecHelper<N, T>::V; |
| 142 |
#endif |
| 143 |
|
| 144 |
/** Interface */ |
| 145 |
|
| 146 |
namespace baseline { |
| 147 |
|
| 148 |
void run_program(const Op* program, const void** contexts, ptrdiff_t programSize, |
| 149 |
const char* src, char* dst, int n, |
| 150 |
size_t src_bpp, size_t dst_bpp); |
| 151 |
|
| 152 |
} |
| 153 |
namespace hsw { |
| 154 |
|
| 155 |
void run_program(const Op* program, const void** contexts, ptrdiff_t programSize, |
| 156 |
const char* src, char* dst, int n, |
| 157 |
size_t src_bpp, size_t dst_bpp); |
| 158 |
|
| 159 |
} |
| 160 |
namespace skx { |
| 161 |
|
| 162 |
void run_program(const Op* program, const void** contexts, ptrdiff_t programSize, |
| 163 |
const char* src, char* dst, int n, |
| 164 |
size_t src_bpp, size_t dst_bpp); |
| 165 |
|
| 166 |
} |
| 167 |
} // namespace skcms_private |