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
6363 NB_STATS_MODE
6464 };
6565
66−#define NBITS 5
67−#define HIST_SIZE (1<<(3*NBITS))
66+#define HIST_SIZE (1<<15)
6867
6968 typedef struct PaletteGenContext {
7069 const AVClass *class;
@@ -387,27 +386,13 @@ static AVFrame *get_palette_frame(AVFilterContext *ctx) · 316 unmodified lines
387386 return out;
388387 }
389388
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−
404389 /**
405390 * Locate the color in the hash table and increment its counter.
406391 */
407392 static int color_inc(struct hist_node *hist, uint32_t color)
408393 {
409394 int i;
410− const unsigned hash = color_hash(color);
395+ const uint32_t hash = ff_lowbias32(color) & (HIST_SIZE - 1);
411396 struct hist_node *node = &hist[hash];
412397 struct color_ref *e;
413398

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