opsin_params.cc (1433B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #include "lib/jxl/opsin_params.h" 7 8 #include "lib/jxl/cms/opsin_params.h" 9 10 #define INVERSE_OPSIN_FROM_SPEC 1 11 12 #if not(INVERSE_OPSIN_FROM_SPEC) 13 #include "lib/jxl/base/matrix_ops.h" 14 #endif 15 16 namespace jxl { 17 18 const float* GetOpsinAbsorbanceInverseMatrix() { 19 #if INVERSE_OPSIN_FROM_SPEC 20 return jxl::cms::DefaultInverseOpsinAbsorbanceMatrix(); 21 #else // INVERSE_OPSIN_FROM_SPEC 22 // Compute the inverse opsin matrix from the forward matrix. Less precise 23 // than taking the values from the specification, but must be used if the 24 // forward transform is changed and the spec will require updating. 25 static const float* const kInverse = [] { 26 static float inverse[9]; 27 for (int i = 0; i < 9; i++) { 28 inverse[i] = kOpsinAbsorbanceMatrix[i]; 29 } 30 Inv3x3Matrix(inverse); 31 return inverse; 32 }(); 33 return kInverse; 34 #endif // INVERSE_OPSIN_FROM_SPEC 35 } 36 37 void InitSIMDInverseMatrix(const float* JXL_RESTRICT inverse, 38 float* JXL_RESTRICT simd_inverse, 39 float intensity_target) { 40 for (size_t i = 0; i < 9; ++i) { 41 simd_inverse[4 * i] = simd_inverse[4 * i + 1] = simd_inverse[4 * i + 2] = 42 simd_inverse[4 * i + 3] = inverse[i] * (255.0f / intensity_target); 43 } 44 } 45 46 } // namespace jxl