History

avfilter/palettegen: use lowbias32 for color hashing

1.12x faster overall in palettegen on my machine.

Clément Bœsch committed 3 years ago

Commit c9084cd1 parent 3cafbdc1 file · +2 −17Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_palettegen.c+2−17
@@ -63,8 +63,7 @@ enum { · 62 unmodified lines
63 NB_STATS_MODE63 NB_STATS_MODE
64};64};
65 65
66#define NBITS 566#define HIST_SIZE (1<<15)
67#define HIST_SIZE (1<<(3*NBITS))
68 67
69typedef struct PaletteGenContext {68typedef 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 */
395static 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 */
407static int color_inc(struct hist_node *hist, uint32_t color)392static 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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t