1.12x faster overall in palettegen on my machine.
Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -63,8 +63,7 @@ enum { · 62 unmodified lines | |||
| 63 | NB_STATS_MODE | 63 | NB_STATS_MODE |
| 64 | }; | 64 | }; |
| 65 | 65 | ||
| 66 | #define NBITS 5 | 66 | #define HIST_SIZE (1<<15) |
| 67 | #define HIST_SIZE (1<<(3*NBITS)) | ||
| 68 | 67 | ||
| 69 | typedef struct PaletteGenContext { | 68 | typedef struct PaletteGenContext { |
| 70 | const AVClass *class; | 69 | const AVClass *class; |
| @@ -387,27 +386,13 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) · 316 unmodified lines | |||
| 387 | return out; | 386 | return out; |
| 388 | } | 387 | } |
| 389 | 388 | ||
| 390 | /** | ||
| 391 | * Hashing function for the color. | ||
| 392 | * It keeps the NBITS least significant bit of each component to make it | ||
| 393 | * "random" even if the scene doesn't have much different colors. | ||
| 394 | */ | ||
| 395 | static inline unsigned color_hash(uint32_t color) | ||
| 396 | { | ||
| 397 | const uint8_t r = color >> 16 & ((1<<NBITS)-1); | ||
| 398 | const uint8_t g = color >> 8 & ((1<<NBITS)-1); | ||
| 399 | const uint8_t b = color & ((1<<NBITS)-1); | ||
| 400 | |||
| 401 | return r << (NBITS * 2) | g << NBITS | b; | ||
| 402 | } | ||
| 403 | |||
| 404 | /** | 389 | /** |
| 405 | * Locate the color in the hash table and increment its counter. | 390 | * Locate the color in the hash table and increment its counter. |
| 406 | */ | 391 | */ |
| 407 | static int color_inc(struct hist_node *hist, uint32_t color) | 392 | static int color_inc(struct hist_node *hist, uint32_t color) |
| 408 | { | 393 | { |
| 409 | int i; | 394 | int i; |
| 410 | const unsigned hash = color_hash(color); | 395 | const uint32_t hash = ff_lowbias32(color) & (HIST_SIZE - 1); |
| 411 | struct hist_node *node = &hist[hash]; | 396 | struct hist_node *node = &hist[hash]; |
| 412 | struct color_ref *e; | 397 | struct color_ref *e; |
| 413 | 398 | ||