// SPDX-License-Identifier: Apache-2.0 // ---------------------------------------------------------------------------- // Copyright 2011-2023 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. // ---------------------------------------------------------------------------- /** * @brief Functions for generating partition tables on demand. */ #include "astcenc_internal.h" /** @brief The number of 64-bit words needed to represent a canonical partition bit pattern. */ #define BIT_PATTERN_WORDS … /** * @brief Generate a canonical representation of a partition pattern. * * The returned value stores two bits per texel, for up to 6x6x6 texels, where the two bits store * the remapped texel index. Remapping ensures that we only match on the partition pattern, * independent of the partition order generated by the hash. * * @param texel_count The number of texels in the block. * @param partition_of_texel The partition assignments, in hash order. * @param[out] bit_pattern The output bit pattern representation. */ static void generate_canonical_partitioning( unsigned int texel_count, const uint8_t* partition_of_texel, uint64_t bit_pattern[BIT_PATTERN_WORDS] ) { … } /** * @brief Compare two canonical patterns to see if they are the same. * * @param part1 The first canonical bit pattern to check. * @param part2 The second canonical bit pattern to check. * * @return @c true if the patterns are the same, @c false otherwise. */ static bool compare_canonical_partitionings( const uint64_t part1[BIT_PATTERN_WORDS], const uint64_t part2[BIT_PATTERN_WORDS] ) { … } /** * @brief Hash function used for procedural partition assignment. * * @param inp The hash seed. * * @return The hashed value. */ static uint32_t hash52( uint32_t inp ) { … } /** * @brief Select texel assignment for a single coordinate. * * @param seed The seed - the partition index from the block. * @param x The texel X coordinate in the block. * @param y The texel Y coordinate in the block. * @param z The texel Z coordinate in the block. * @param partition_count The total partition count of this encoding. * @param small_block @c true if the block has fewer than 32 texels. * * @return The assigned partition index for this texel. */ static uint8_t select_partition( int seed, int x, int y, int z, int partition_count, bool small_block ) { … } /** * @brief Generate a single partition info structure. * * @param[out] bsd The block size information. * @param partition_count The partition count of this partitioning. * @param partition_index The partition index / seed of this partitioning. * @param partition_remap_index The remapped partition index of this partitioning. * @param[out] pi The partition info structure to populate. * * @return True if this is a useful partition index, False if we can skip it. */ static bool generate_one_partition_info_entry( block_size_descriptor& bsd, unsigned int partition_count, unsigned int partition_index, unsigned int partition_remap_index, partition_info& pi ) { … } static void build_partition_table_for_one_partition_count( block_size_descriptor& bsd, bool can_omit_partitionings, unsigned int partition_count_cutoff, unsigned int partition_count, partition_info* ptab, uint64_t* canonical_patterns ) { … } /* See header for documentation. */ void init_partition_tables( block_size_descriptor& bsd, bool can_omit_partitionings, unsigned int partition_count_cutoff ) { … }