See header for documentation. */
| 1111 | |
| 1112 | /* See header for documentation. */ |
| 1113 | astcenc_error astcenc_compress_image( |
| 1114 | astcenc_context* ctxo, |
| 1115 | astcenc_image* imagep, |
| 1116 | const astcenc_swizzle* swizzle, |
| 1117 | uint8_t* data_out, |
| 1118 | size_t data_len, |
| 1119 | unsigned int thread_index |
| 1120 | ) { |
| 1121 | #if defined(ASTCENC_DECOMPRESS_ONLY) |
| 1122 | (void)ctxo; |
| 1123 | (void)imagep; |
| 1124 | (void)swizzle; |
| 1125 | (void)data_out; |
| 1126 | (void)data_len; |
| 1127 | (void)thread_index; |
| 1128 | return ASTCENC_ERR_BAD_CONTEXT; |
| 1129 | #else |
| 1130 | astcenc_contexti* ctx = &ctxo->context; |
| 1131 | astcenc_error status; |
| 1132 | astcenc_image& image = *imagep; |
| 1133 | |
| 1134 | if (ctx->config.flags & ASTCENC_FLG_DECOMPRESS_ONLY) |
| 1135 | { |
| 1136 | return ASTCENC_ERR_BAD_CONTEXT; |
| 1137 | } |
| 1138 | |
| 1139 | status = validate_compression_swizzle(*swizzle); |
| 1140 | if (status != ASTCENC_SUCCESS) |
| 1141 | { |
| 1142 | return status; |
| 1143 | } |
| 1144 | |
| 1145 | if (thread_index >= ctx->thread_count) |
| 1146 | { |
| 1147 | return ASTCENC_ERR_BAD_PARAM; |
| 1148 | } |
| 1149 | |
| 1150 | size_t dim_x = image.dim_x; |
| 1151 | size_t dim_y = image.dim_y; |
| 1152 | size_t dim_z = image.dim_z; |
| 1153 | |
| 1154 | size_t texel_count = get_texels_count(dim_x, dim_y, dim_z); |
| 1155 | // Cumulative texel sizes would overflow a size_t |
| 1156 | if (texel_count == 0) |
| 1157 | { |
| 1158 | return ASTCENC_ERR_BAD_PARAM; |
| 1159 | } |
| 1160 | |
| 1161 | size_t block_x = ctx->config.block_x; |
| 1162 | size_t block_y = ctx->config.block_y; |
| 1163 | size_t block_z = ctx->config.block_z; |
| 1164 | |
| 1165 | size_t blocks_x = astc::get_block_count_safe(dim_x, block_x); |
| 1166 | size_t blocks_y = astc::get_block_count_safe(dim_y, block_y); |
| 1167 | size_t blocks_z = astc::get_block_count_safe(dim_z, block_z); |
| 1168 | |
| 1169 | size_t block_count = get_blocks_count(blocks_x, blocks_y, blocks_z); |
| 1170 | // Cumulative block sizes would overflow a size_t |