"Variance" wasn't exactly the correct word; "cut score" is more agnostic, which will be useful when changing the algorithm in the next commit.
Unified · Split
| @@ -42,7 +42,7 @@ struct range_box { · 41 unmodified lines | ||
| 42 | 42 | uint32_t color; // average color |
| 43 | 43 | int major_axis; // best axis candidate for cutting the box |
| 44 | 44 | uint64_t weight; // sum of all the weights of the colors |
| 45 | − int64_t variance; // overall variance of the box (how much the colors are spread) | |
| 45 | + int64_t cut_score; // how likely the box is to be cut down (higher implying more likely) | |
| 46 | 46 | int start; // index in PaletteGenContext->refs |
| 47 | 47 | int len; // number of referenced colors |
| 48 | 48 | int sorted_by; // whether range of colors is sorted by red (0), green (1) or blue (2) |
| @@ -171,25 +171,25 @@ static void compute_box_stats(PaletteGenContext *s, struct range_box *box) · 122 unmodified lines | ||
| 171 | 171 | if (er2[0] >= er2[1] && er2[0] >= er2[2]) box->major_axis = 0; |
| 172 | 172 | if (er2[1] >= er2[0] && er2[1] >= er2[2]) box->major_axis = 1; // prefer green again |
| 173 | 173 | |
| 174 | − box->variance = er2[0] + er2[1] + er2[2]; | |
| 174 | + box->cut_score = er2[0] + er2[1] + er2[2]; | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | − * Find the next box to split: pick the one with the highest variance | |
| 178 | + * Find the next box to split: pick the one with the highest cut score | |
| 179 | 179 | */ |
| 180 | 180 | static int get_next_box_id_to_split(PaletteGenContext *s) |
| 181 | 181 | { |
| 182 | 182 | int box_id, best_box_id = -1; |
| 183 | − int64_t max_variance = -1; | |
| 183 | + int64_t max_score = -1; | |
| 184 | 184 | |
| 185 | 185 | if (s->nb_boxes == s->max_colors - s->reserve_transparent) |
| 186 | 186 | return -1; |
| 187 | 187 | |
| 188 | 188 | for (box_id = 0; box_id < s->nb_boxes; box_id++) { |
| 189 | 189 | struct range_box *box = &s->boxes[box_id]; |
| 190 | − if (s->boxes[box_id].len >= 2 && box->variance > max_variance) { | |
| 190 | + if (s->boxes[box_id].len >= 2 && box->cut_score > max_score) { | |
| 191 | 191 | best_box_id = box_id; |
| 192 | − max_variance = box->variance; | |
| 192 | + max_score = box->cut_score; | |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | return best_box_id; |