forked from hkc/cc-stuff
1
0
Fork 0

Allocate the correct amount of intermediate centroid data

This commit is contained in:
Vftdan 2024-10-03 10:16:57 +02:00
parent c5af524dac
commit c91f4d79bd
1 changed files with 2 additions and 1 deletions

View File

@ -675,11 +675,12 @@ struct palette *custom_palette_from(const struct palette *orig) {
struct k_means_state k_means_init(const struct image *image, struct palette *starting_palette) { struct k_means_state k_means_init(const struct image *image, struct palette *starting_palette) {
size_t item_count = image->w * image->h; size_t item_count = image->w * image->h;
uint8_t cluster_count = starting_palette->count;
struct k_means_state state = { struct k_means_state state = {
.items = image, .items = image,
.clusters = starting_palette, .clusters = starting_palette,
.predicted_cluster = calloc(image->w, image->h), .predicted_cluster = calloc(image->w, image->h),
.centroid_intermediate = calloc(item_count, sizeof(struct k_means_centroid_intermediate)), .centroid_intermediate = calloc(cluster_count, sizeof(struct k_means_centroid_intermediate)),
.item_count = item_count, .item_count = item_count,
}; };
return state; return state;