MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / select_partition

Function select_partition

Source/astcenc_partition_tables.cpp:142–263  ·  view source on GitHub ↗

* @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 encodin

Source from the content-addressed store, hash-verified

140 * @return The assigned partition index for this texel.
141 */
142static uint8_t select_partition(
143 int seed,
144 int x,
145 int y,
146 int z,
147 int partition_count,
148 bool small_block
149) {
150 // For small blocks bias the coordinates to get better distribution
151 if (small_block)
152 {
153 x <<= 1;
154 y <<= 1;
155 z <<= 1;
156 }
157
158 seed += (partition_count - 1) * 1024;
159
160 uint32_t rnum = hash52(seed);
161
162 uint8_t seed1 = rnum & 0xF;
163 uint8_t seed2 = (rnum >> 4) & 0xF;
164 uint8_t seed3 = (rnum >> 8) & 0xF;
165 uint8_t seed4 = (rnum >> 12) & 0xF;
166 uint8_t seed5 = (rnum >> 16) & 0xF;
167 uint8_t seed6 = (rnum >> 20) & 0xF;
168 uint8_t seed7 = (rnum >> 24) & 0xF;
169 uint8_t seed8 = (rnum >> 28) & 0xF;
170 uint8_t seed9 = (rnum >> 18) & 0xF;
171 uint8_t seed10 = (rnum >> 22) & 0xF;
172 uint8_t seed11 = (rnum >> 26) & 0xF;
173 uint8_t seed12 = ((rnum >> 30) | (rnum << 2)) & 0xF;
174
175 // Squaring all the seeds in order to bias their distribution towards lower values.
176 seed1 *= seed1;
177 seed2 *= seed2;
178 seed3 *= seed3;
179 seed4 *= seed4;
180 seed5 *= seed5;
181 seed6 *= seed6;
182 seed7 *= seed7;
183 seed8 *= seed8;
184 seed9 *= seed9;
185 seed10 *= seed10;
186 seed11 *= seed11;
187 seed12 *= seed12;
188
189 int sh1, sh2;
190 if (seed & 1)
191 {
192 sh1 = (seed & 2 ? 4 : 5);
193 sh2 = (partition_count == 3 ? 6 : 5);
194 }
195 else
196 {
197 sh1 = (partition_count == 3 ? 6 : 5);
198 sh2 = (seed & 2 ? 4 : 5);
199 }

Callers 1

Calls 1

hash52Function · 0.85

Tested by

no test coverage detected