* @brief Get the total number of blocks in an image. * * This function also validates that the total size of the compressed image, * in bytes, would fit in a size_t. * * @param blocks_x Number of blocks in the X axis. * @param blocks_y Number of blocks in the Y axis. * @param blocks_z Number of blocks in the Z axis. * * @return The number of blocks in the image, or zero if total siz
| 180 | * fit into a size_t. |
| 181 | */ |
| 182 | static size_t get_blocks_count( |
| 183 | size_t blocks_x, |
| 184 | size_t blocks_y, |
| 185 | size_t blocks_z |
| 186 | ) { |
| 187 | bool overflow { false }; |
| 188 | |
| 189 | // Compute block count |
| 190 | size_t blocks_count = astc::mul_safe(blocks_x, blocks_y, overflow); |
| 191 | blocks_count = astc::mul_safe(blocks_count, blocks_z, overflow); |
| 192 | |
| 193 | // Also compute byte count, but we only use overflow and not the result |
| 194 | astc::mul_safe(blocks_count, 16, overflow); |
| 195 | |
| 196 | if (overflow) |
| 197 | { |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | return blocks_count; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @brief Validate CPU floating point meets assumptions made in the codec. |
no test coverage detected