// SPDX-License-Identifier: Apache-2.0 // ---------------------------------------------------------------------------- // Copyright 2011-2024 Arm Limited // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy // of the License at: // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. // ---------------------------------------------------------------------------- #if !defined(ASTCENC_DECOMPRESS_ONLY) /** * @brief Functions for computing color endpoints and texel weights. */ #include <cassert> #include "astcenc_internal.h" #include "astcenc_vecmathlib.h" /** * @brief Compute the infilled weight for N texel indices in a decimated grid. * * @param di The weight grid decimation to use. * @param weights The decimated weight values to use. * @param index The first texel index to interpolate. * * @return The interpolated weight for the given set of SIMD_WIDTH texels. */ static vfloat bilinear_infill_vla( const decimation_info& di, const float* weights, unsigned int index ) { … } /** * @brief Compute the infilled weight for N texel indices in a decimated grid. * * This is specialized version which computes only two weights per texel for * encodings that are only decimated in a single axis. * * @param di The weight grid decimation to use. * @param weights The decimated weight values to use. * @param index The first texel index to interpolate. * * @return The interpolated weight for the given set of SIMD_WIDTH texels. */ static vfloat bilinear_infill_vla_2( const decimation_info& di, const float* weights, unsigned int index ) { … } /** * @brief Compute the ideal endpoints and weights for 1 color component. * * @param blk The image block color data to compress. * @param pi The partition info for the current trial. * @param[out] ei The computed ideal endpoints and weights. * @param component The color component to compute. */ static void compute_ideal_colors_and_weights_1_comp( const image_block& blk, const partition_info& pi, endpoints_and_weights& ei, unsigned int component ) { … } /** * @brief Compute the ideal endpoints and weights for 2 color components. * * @param blk The image block color data to compress. * @param pi The partition info for the current trial. * @param[out] ei The computed ideal endpoints and weights. * @param component1 The first color component to compute. * @param component2 The second color component to compute. */ static void compute_ideal_colors_and_weights_2_comp( const image_block& blk, const partition_info& pi, endpoints_and_weights& ei, int component1, int component2 ) { … } /** * @brief Compute the ideal endpoints and weights for 3 color components. * * @param blk The image block color data to compress. * @param pi The partition info for the current trial. * @param[out] ei The computed ideal endpoints and weights. * @param omitted_component The color component excluded from the calculation. */ static void compute_ideal_colors_and_weights_3_comp( const image_block& blk, const partition_info& pi, endpoints_and_weights& ei, unsigned int omitted_component ) { … } /** * @brief Compute the ideal endpoints and weights for 4 color components. * * @param blk The image block color data to compress. * @param pi The partition info for the current trial. * @param[out] ei The computed ideal endpoints and weights. */ static void compute_ideal_colors_and_weights_4_comp( const image_block& blk, const partition_info& pi, endpoints_and_weights& ei ) { … } /* See header for documentation. */ void compute_ideal_colors_and_weights_1plane( const image_block& blk, const partition_info& pi, endpoints_and_weights& ei ) { … } /* See header for documentation. */ void compute_ideal_colors_and_weights_2planes( const block_size_descriptor& bsd, const image_block& blk, unsigned int plane2_component, endpoints_and_weights& ei1, endpoints_and_weights& ei2 ) { … } /* See header for documentation. */ float compute_error_of_weight_set_1plane( const endpoints_and_weights& eai, const decimation_info& di, const float* dec_weight_quant_uvalue ) { … } /* See header for documentation. */ float compute_error_of_weight_set_2planes( const endpoints_and_weights& eai1, const endpoints_and_weights& eai2, const decimation_info& di, const float* dec_weight_quant_uvalue_plane1, const float* dec_weight_quant_uvalue_plane2 ) { … } /* See header for documentation. */ void compute_ideal_weights_for_decimation( const endpoints_and_weights& ei, const decimation_info& di, float* dec_weight_ideal_value ) { … } /* See header for documentation. */ void compute_quantized_weights_for_decimation( const decimation_info& di, float low_bound, float high_bound, const float* dec_weight_ideal_value, float* weight_set_out, uint8_t* quantized_weight_set, quant_method quant_level ) { … } /** * @brief Compute the RGB + offset for a HDR endpoint mode #7. * * Since the matrix needed has a regular structure we can simplify the inverse calculation. This * gives us ~24 multiplications vs. 96 for a generic inverse. * * mat[0] = vfloat4(rgba_ws.x, 0.0f, 0.0f, wght_ws.x); * mat[1] = vfloat4( 0.0f, rgba_ws.y, 0.0f, wght_ws.y); * mat[2] = vfloat4( 0.0f, 0.0f, rgba_ws.z, wght_ws.z); * mat[3] = vfloat4(wght_ws.x, wght_ws.y, wght_ws.z, psum); * mat = invert(mat); * * @param rgba_weight_sum Sum of partition component error weights. * @param weight_weight_sum Sum of partition component error weights * texel weight. * @param rgbq_sum Sum of partition component error weights * texel weight * color data. * @param psum Sum of RGB color weights * texel weight^2. */ static inline vfloat4 compute_rgbo_vector( vfloat4 rgba_weight_sum, vfloat4 weight_weight_sum, vfloat4 rgbq_sum, float psum ) { … } /* See header for documentation. */ void recompute_ideal_colors_1plane( const image_block& blk, const partition_info& pi, const decimation_info& di, const uint8_t* dec_weights_uquant, endpoints& ep, vfloat4 rgbs_vectors[BLOCK_MAX_PARTITIONS], vfloat4 rgbo_vectors[BLOCK_MAX_PARTITIONS] ) { … } /* See header for documentation. */ void recompute_ideal_colors_2planes( const image_block& blk, const block_size_descriptor& bsd, const decimation_info& di, const uint8_t* dec_weights_uquant_plane1, const uint8_t* dec_weights_uquant_plane2, endpoints& ep, vfloat4& rgbs_vector, vfloat4& rgbo_vector, int plane2_component ) { … } #endif