64 #define CACHE_SIZE (1<<(3*NBITS))
104 #define OFFSET(x) offsetof(PaletteUseContext, x)
105 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
139 if (!in || !inpal || !out) {
154 return av_clip_uint8((px >> 16 & 0xff) + ((er * scale) / (1<<shift))) << 16
155 | av_clip_uint8((px >> 8 & 0xff) + ((eg * scale) / (1<<shift))) << 8
156 | av_clip_uint8((px & 0xff) + ((eb * scale) / (1<<shift)));
162 const int dr = c1[0] - c2[0];
163 const int dg = c1[1] - c2[1];
164 const int db = c1[2] - c2[2];
165 return dr*dr + dg*dg + db*db;
170 int i, pal_id = -1, min_dist = INT_MAX;
173 const uint32_t
c = palette[i];
175 if ((c & 0xff000000) == 0xff000000) {
177 palette[i]>>16 & 0xff,
178 palette[i]>> 8 & 0xff,
181 const int d =
diff(palrgb, rgb);
203 const int s = kd->
split;
204 int dx, nearer_kd_id, further_kd_id;
206 const int current_to_target =
diff(target, current);
208 if (current_to_target < nearest->dist_sqd) {
210 nearest->
dist_sqd = current_to_target;
214 dx = target[
s] - current[
s];
219 if (nearer_kd_id != -1)
222 if (further_kd_id != -1 && dx*dx < nearest->dist_sqd)
241 int pos = 0, best_node_id = -1, best_dist = INT_MAX, cur_color_id = 0;
247 const struct color_node *kd = &root[cur_color_id];
249 const int current_to_target =
diff(target, current);
253 if (current_to_target < best_dist) {
254 best_node_id = cur_color_id;
255 if (!current_to_target)
257 best_dist = current_to_target;
263 const int dx = target[
split] - current[
split];
264 int nearer_kd_id, further_kd_id;
270 if (nearer_kd_id != -1) {
271 if (further_kd_id != -1) {
282 cur_color_id = nearer_kd_id;
284 }
else if (dx*dx < best_dist) {
289 cur_color_id = further_kd_id;
300 }
while (node->
dx2 >= best_dist);
311 #define COLORMAP_NEAREST(search, palette, root, target) \
312 search == COLOR_SEARCH_NNS_ITERATIVE ? colormap_nearest_iterative(root, target) : \
313 search == COLOR_SEARCH_NNS_RECURSIVE ? colormap_nearest_recursive(root, target) : \
314 colormap_nearest_bruteforce(palette, target)
339 if (e->
color == color)
355 int *er,
int *eg,
int *eb,
361 const int dstx =
color_get(cache, c, r, g, b, map, palette, search_method);
362 const uint32_t dstc = palette[dstx];
363 *er = r - (dstc >> 16 & 0xff);
364 *eg = g - (dstc >> 8 & 0xff);
365 *eb = b - (dstc & 0xff);
370 int x_start,
int y_start,
int w,
int h,
378 const int src_linesize = in ->
linesize[0] >> 2;
379 const int dst_linesize = out->
linesize[0];
380 uint32_t *
src = ((uint32_t *)in ->
data[0]) + y_start*src_linesize;
381 uint8_t *dst = out->
data[0] + y_start*dst_linesize;
386 for (y = y_start; y <
h; y++) {
387 for (x = x_start; x < w; x++) {
392 const uint8_t r8 = src[x] >> 16 & 0xff;
393 const uint8_t g8 = src[x] >> 8 & 0xff;
394 const uint8_t b8 = src[x] & 0xff;
395 const uint8_t r = av_clip_uint8(r8 + d);
396 const uint8_t g = av_clip_uint8(g8 + d);
397 const uint8_t b = av_clip_uint8(b8 + d);
398 const uint32_t
c = r<<16 | g<<8 |
b;
399 const int color =
color_get(cache, c, r, g, b, map, palette, search_method);
406 const int right = x < w - 1, down = y < h - 1;
413 if (right) src[ x + 1] =
dither_color(src[ x + 1], er, eg, eb, 3, 3);
414 if ( down) src[src_linesize + x ] =
dither_color(src[src_linesize + x ], er, eg, eb, 3, 3);
415 if (right && down) src[src_linesize + x + 1] =
dither_color(src[src_linesize + x + 1], er, eg, eb, 2, 3);
418 const int right = x < w - 1, down = y < h - 1, left = x > x_start;
425 if (right) src[ x + 1] =
dither_color(src[ x + 1], er, eg, eb, 7, 4);
426 if (left && down) src[src_linesize + x - 1] =
dither_color(src[src_linesize + x - 1], er, eg, eb, 3, 4);
427 if ( down) src[src_linesize + x ] =
dither_color(src[src_linesize + x ], er, eg, eb, 5, 4);
428 if (right && down) src[src_linesize + x + 1] =
dither_color(src[src_linesize + x + 1], er, eg, eb, 1, 4);
431 const int right = x < w - 1, down = y < h - 1, left = x > x_start;
432 const int right2 = x < w - 2, left2 = x > x_start + 1;
439 if (right) src[ x + 1] =
dither_color(src[ x + 1], er, eg, eb, 4, 4);
440 if (right2) src[ x + 2] =
dither_color(src[ x + 2], er, eg, eb, 3, 4);
443 if (left2) src[ src_linesize + x - 2] =
dither_color(src[ src_linesize + x - 2], er, eg, eb, 1, 4);
444 if (left) src[ src_linesize + x - 1] =
dither_color(src[ src_linesize + x - 1], er, eg, eb, 2, 4);
445 src[ src_linesize + x ] =
dither_color(src[ src_linesize + x ], er, eg, eb, 3, 4);
446 if (right) src[ src_linesize + x + 1] =
dither_color(src[ src_linesize + x + 1], er, eg, eb, 2, 4);
447 if (right2) src[ src_linesize + x + 2] =
dither_color(src[ src_linesize + x + 2], er, eg, eb, 1, 4);
451 const int right = x < w - 1, down = y < h - 1, left = x > x_start;
458 if (right) src[ x + 1] =
dither_color(src[ x + 1], er, eg, eb, 2, 2);
459 if (left && down) src[src_linesize + x - 1] =
dither_color(src[src_linesize + x - 1], er, eg, eb, 1, 2);
460 if ( down) src[src_linesize + x ] =
dither_color(src[src_linesize + x ], er, eg, eb, 1, 2);
463 const uint8_t r = src[x] >> 16 & 0xff;
464 const uint8_t g = src[x] >> 8 & 0xff;
466 const int color =
color_get(cache, src[x] & 0xffffff, r, g, b, map, palette, search_method);
482 int parent_id,
int node_id,
485 const struct color_node *node = &map[node_id];
486 const uint32_t fontcolor = node->
val[0] > 0x50 &&
487 node->
val[1] > 0x50 &&
488 node->
val[2] > 0x50 ? 0 : 0xffffff;
490 "label=\"%c%02X%c%02X%c%02X%c\" "
491 "fillcolor=\"#%02x%02x%02x\" "
492 "fontcolor=\"#%06X\"]\n",
498 node->
val[0], node->
val[1], node->
val[2],
501 av_bprintf(buf,
"%*cnode%d -> node%d\n", depth*INDENT,
' ',
523 av_bprintf(&buf,
" node [style=filled fontsize=10 shape=box]\n");
527 fwrite(buf.str, 1, buf.len, f);
536 int r,
g,
b, ret = 0;
538 for (r = 0; r < 256; r++) {
539 for (g = 0; g < 256; g++) {
540 for (b = 0; b < 256; b++) {
545 const uint32_t
c1 = palette[r1];
546 const uint32_t
c2 = palette[r2];
547 const uint8_t palrgb1[] = { c1>>16 & 0xff, c1>> 8 & 0xff, c1 & 0xff };
548 const uint8_t palrgb2[] = { c2>>16 & 0xff, c2>> 8 & 0xff, c2 & 0xff };
549 const int d1 =
diff(palrgb1, rgb);
550 const int d2 =
diff(palrgb2, rgb);
553 "/!\\ %02X%02X%02X: %d ! %d (%06X ! %06X) / dist: %d ! %d\n",
554 r, g, b, r1, r2, c1 & 0xffffff, c2 & 0xffffff, d1, d2);
574 typedef int (*
cmp_func)(
const void *,
const void *);
576 #define DECLARE_CMP_FUNC(name, pos) \
577 static int cmp_##name(const void *pa, const void *pb) \
579 const struct color *a = pa; \
580 const struct color *b = pb; \
581 return (a->value >> (8 * (2 - (pos))) & 0xff) \
582 - (b->value >> (8 * (2 - (pos))) & 0xff); \
596 unsigned nb_color = 0;
598 struct color tmp_pal[256];
601 ranges.
min[0] = ranges.
min[1] = ranges.
min[2] = 0xff;
602 ranges.
max[0] = ranges.
max[1] = ranges.
max[2] = 0x00;
605 const uint32_t
c = palette[i];
611 r < box->
min[0] || g < box->
min[1] || b < box->
min[2] ||
612 r > box->
max[0] || g > box->
max[1] || b > box->
max[2])
615 if (r < ranges.
min[0]) ranges.
min[0] =
r;
616 if (g < ranges.
min[1]) ranges.
min[1] =
g;
617 if (b < ranges.
min[2]) ranges.
min[2] =
b;
619 if (r > ranges.
max[0]) ranges.
max[0] =
r;
620 if (g > ranges.
max[1]) ranges.
max[1] =
g;
621 if (b > ranges.
max[2]) ranges.
max[2] =
b;
623 tmp_pal[nb_color].
value =
c;
624 tmp_pal[nb_color].
pal_id = i;
633 wr = ranges.
max[0] - ranges.
min[0];
634 wg = ranges.
max[1] - ranges.
min[1];
635 wb = ranges.
max[2] - ranges.
min[2];
636 if (wr >= wg && wr >= wb) longest = 0;
637 if (wg >= wr && wg >= wb) longest = 1;
638 if (wb >= wr && wb >= wg) longest = 2;
640 *component = longest;
645 return tmp_pal[nb_color >> 1].
pal_id;
655 int component, cur_id;
656 int node_left_id = -1, node_right_id = -1;
659 const int pal_id =
get_next_color(color_used, palette, &component, box);
665 cur_id = (*nb_used)++;
668 node->
split = component;
670 node->
val[0] = c>>16 & 0xff;
671 node->
val[1] = c>> 8 & 0xff;
672 node->
val[2] = c & 0xff;
674 color_used[pal_id] = 1;
678 box1.
max[component] = node->
val[component];
679 box2.
min[component] = node->
val[component] + 1;
681 node_left_id =
colormap_insert(map, color_used, nb_used, palette, &box1);
683 if (box2.
min[component] <= box2.
max[component])
684 node_right_id =
colormap_insert(map, color_used, nb_used, palette, &box2);
694 const int c1 = *(
const uint32_t *)a & 0xffffff;
695 const int c2 = *(
const uint32_t *)b & 0xffffff;
703 uint32_t last_color = 0;
710 if (i != 0 && c == last_color) {
715 if ((c & 0xff000000) != 0xff000000) {
721 box.
min[0] = box.
min[1] = box.
min[2] = 0x00;
722 box.
max[0] = box.
max[1] = box.
max[2] = 0xff;
736 const AVFrame *in2,
int frame_count)
740 uint32_t *
src1 = (uint32_t *)in1->
data[0];
742 const int src1_linesize = in1->
linesize[0] >> 2;
743 const int src2_linesize = in2->
linesize[0];
745 unsigned mean_err = 0;
748 for (x = 0; x < in1->
width; x++) {
749 const uint32_t
c1 = src1[x];
750 const uint32_t
c2 = palette[src2[x]];
751 const uint8_t rgb1[] = {c1 >> 16 & 0xff, c1 >> 8 & 0xff, c1 & 0xff};
752 const uint8_t rgb2[] = {c2 >> 16 & 0xff, c2 >> 8 & 0xff, c2 & 0xff};
753 mean_err +=
diff(rgb1, rgb2);
755 src1 += src1_linesize;
756 src2 += src2_linesize;
768 int *xp,
int *yp,
int *wp,
int *hp)
770 int x_start = 0, y_start = 0;
776 int x_end = cur_src->
width - 1,
777 y_end = cur_src->
height - 1;
778 const uint32_t *prv_srcp = (
const uint32_t *)prv_src->
data[0];
779 const uint32_t *cur_srcp = (
const uint32_t *)cur_src->
data[0];
783 const int prv_src_linesize = prv_src->
linesize[0] >> 2;
784 const int cur_src_linesize = cur_src->
linesize[0] >> 2;
785 const int prv_dst_linesize = prv_dst->
linesize[0];
786 const int cur_dst_linesize = cur_dst->
linesize[0];
789 while (y_start < y_end && !memcmp(prv_srcp + y_start*prv_src_linesize,
790 cur_srcp + y_start*cur_src_linesize,
791 cur_src->
width * 4)) {
792 memcpy(cur_dstp + y_start*cur_dst_linesize,
793 prv_dstp + y_start*prv_dst_linesize,
797 while (y_end > y_start && !memcmp(prv_srcp + y_end*prv_src_linesize,
798 cur_srcp + y_end*cur_src_linesize,
799 cur_src->
width * 4)) {
800 memcpy(cur_dstp + y_end*cur_dst_linesize,
801 prv_dstp + y_end*prv_dst_linesize,
806 height = y_end + 1 - y_start;
809 while (x_start < x_end) {
811 for (y = y_start; y <= y_end; y++) {
812 if (prv_srcp[y*prv_src_linesize + x_start] != cur_srcp[y*cur_src_linesize + x_start]) {
821 while (x_end > x_start) {
823 for (y = y_start; y <= y_end; y++) {
824 if (prv_srcp[y*prv_src_linesize + x_end] != cur_srcp[y*cur_src_linesize + x_end]) {
833 width = x_end + 1 - x_start;
836 for (y = y_start; y <= y_end; y++)
837 memcpy(cur_dstp + y*cur_dst_linesize,
838 prv_dstp + y*prv_dst_linesize, x_start);
840 if (x_end != cur_src->
width - 1) {
841 const int copy_len = cur_src->
width - 1 - x_end;
842 for (y = y_start; y <= y_end; y++)
843 memcpy(cur_dstp + y*cur_dst_linesize + x_end + 1,
844 prv_dstp + y*prv_dst_linesize + x_end + 1,
881 ff_dlog(ctx,
"%dx%d rect: (%d;%d) -> (%d,%d) [area:%dx%d]\n",
884 if (s->
set_frame(s, out, in, x, y, w, h) < 0) {
916 "Palette input must contain exactly %d pixels. "
917 "Specified input has %dx%d=%d pixels\n",
919 inlink->
w * inlink->
h);
928 const uint32_t *p = (
const uint32_t *)palette_frame->
data[0];
929 const int p_linesize = palette_frame->
linesize[0] >> 2;
932 for (y = 0; y < palette_frame->
height; y++) {
933 for (x = 0; x < palette_frame->
width; x++)
960 #define DEFINE_SET_FRAME(color_search, name, value) \
961 static int set_frame_##name(PaletteUseContext *s, AVFrame *out, AVFrame *in, \
962 int x_start, int y_start, int w, int h) \
964 return set_frame(s, out, in, x_start, y_start, w, h, value, color_search); \
967 #define DEFINE_SET_FRAME_COLOR_SEARCH(color_search, color_search_macro) \
968 DEFINE_SET_FRAME(color_search_macro, color_search##_##none, DITHERING_NONE) \
969 DEFINE_SET_FRAME(color_search_macro, color_search##_##bayer, DITHERING_BAYER) \
970 DEFINE_SET_FRAME(color_search_macro, color_search##_##heckbert, DITHERING_HECKBERT) \
971 DEFINE_SET_FRAME(color_search_macro, color_search##_##floyd_steinberg, DITHERING_FLOYD_STEINBERG) \
972 DEFINE_SET_FRAME(color_search_macro, color_search##_##sierra2, DITHERING_SIERRA2) \
973 DEFINE_SET_FRAME(color_search_macro, color_search##_##sierra2_4a, DITHERING_SIERRA2_4A) \
979 #define DITHERING_ENTRIES(color_search) { \
980 set_frame_##color_search##_none, \
981 set_frame_##color_search##_bayer, \
982 set_frame_##color_search##_heckbert, \
983 set_frame_##color_search##_floyd_steinberg, \
984 set_frame_##color_search##_sierra2, \
985 set_frame_##color_search##_sierra2_4a, \
996 const int q = p ^ (p >> 3);
997 return (p & 4) >> 2 | (q & 4) >> 1 \
998 | (p & 2) << 1 | (q & 2) << 2 \
999 | (p & 1) << 4 | (q & 1) << 5;
1045 .needs_writable = 1,
1066 .
name =
"paletteuse",
1072 .
inputs = paletteuse_inputs,
1073 .
outputs = paletteuse_outputs,
1074 .priv_class = &paletteuse_class,
int(* cmp_func)(const void *, const void *)
AVFILTER_DEFINE_CLASS(paletteuse)
void av_bprintf(AVBPrint *buf, const char *fmt,...)
static int shift(int a, int b)
static void load_palette(PaletteUseContext *s, const AVFrame *palette_frame)
static AVFrame * load_apply_palette(AVFilterContext *ctx, AVFrame *main, const AVFrame *second)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
Main libavfilter public API header.
static AVFrame * apply_palette(AVFilterLink *inlink, AVFrame *in)
int h
agreed upon image height
static int query_formats(AVFilterContext *ctx)
FILE * av_fopen_utf8(const char *path, const char *mode)
Open a file using a UTF-8 filename.
static const AVFilterPad paletteuse_outputs[]
static int debug_accuracy(const struct color_node *node, const uint32_t *palette, const enum color_search_method search_method)
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
Add an element of size elem_size to a dynamic array.
static av_always_inline int dither_color(uint32_t px, int er, int eg, int eb, int scale, int shift)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static av_cold int init(AVFilterContext *ctx)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
int(* set_frame_func)(struct PaletteUseContext *s, AVFrame *out, AVFrame *in, int x_start, int y_start, int width, int height)
AVFilter ff_vf_paletteuse
8 bits with AV_PIX_FMT_RGB32 palette
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static av_cold int end(AVCodecContext *avctx)
static const cmp_func cmp_funcs[]
static int config_input_palette(AVFilterLink *inlink)
uint32_t palette[AVPALETTE_COUNT]
static const AVOption paletteuse_options[]
A filter pad used for either input or output.
#define DEFINE_SET_FRAME_COLOR_SEARCH(color_search, color_search_macro)
static int disp_tree(const struct color_node *node, const char *fname)
A link between two filters.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_BPRINT_SIZE_UNLIMITED
static void colormap_nearest_node(const struct color_node *map, const int node_pos, const uint8_t *target, struct nearest_color *nearest)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
static const uint8_t dither[8][8]
void * priv
private data for use by the filter
static const set_frame_func set_frame_lut[NB_COLOR_SEARCHES][NB_DITHERING]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
static int request_frame(AVFilterLink *outlink)
static int dither_value(int p)
static char * split(char *message, char delim)
int w
agreed upon image width
static av_always_inline uint8_t colormap_nearest_iterative(const struct color_node *root, const uint8_t *target)
common internal API header
int skip_initial_unpaired
Skip initial frames that do not have a 2nd input.
static void disp_node(AVBPrint *buf, const struct color_node *map, int parent_id, int node_id, int depth)
static void set_processing_window(enum diff_mode diff_mode, const AVFrame *prv_src, const AVFrame *cur_src, const AVFrame *prv_dst, AVFrame *cur_dst, int *xp, int *yp, int *wp, int *hp)
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static av_always_inline int diff(const uint8_t *c1, const uint8_t *c2)
AVFilterContext * src
source filter
AVFrame *(* process)(AVFilterContext *ctx, AVFrame *main, const AVFrame *second)
static const AVFilterPad outputs[]
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
#define FF_ARRAY_ELEMS(a)
static av_always_inline int get_dst_color_err(struct cache_node *cache, uint32_t c, const struct color_node *map, const uint32_t *palette, int *er, int *eg, int *eb, const enum color_search_method search_method)
static int config_output(AVFilterLink *outlink)
#define AV_LOG_INFO
Standard information.
static const AVFilterPad inputs[]
static int cmp_pal_entry(const void *a, const void *b)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int repeatlast
repeat last second frame
Describe the class of an AVClass context structure.
#define DITHERING_ENTRIES(color_search)
static int get_next_color(const uint8_t *color_used, const uint32_t *palette, int *component, const struct color_rect *box)
const char * name
Filter name.
static void load_colormap(PaletteUseContext *s)
static int colormap_insert(struct color_node *map, uint8_t *color_used, int *nb_used, const uint32_t *palette, const struct color_rect *box)
const VDPAUPixFmtMap * map
#define DECLARE_CMP_FUNC(name, pos)
AVFilterLink ** outputs
array of pointers to output links
#define COLORMAP_NEAREST(search, palette, root, target)
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
FFDualInputContext dinput
struct cache_node cache[CACHE_SIZE]
struct cached_color * entries
static av_always_inline uint8_t colormap_nearest_recursive(const struct color_node *node, const uint8_t *rgb)
static av_always_inline int set_frame(PaletteUseContext *s, AVFrame *out, AVFrame *in, int x_start, int y_start, int w, int h, enum dithering_mode dither, const enum color_search_method search_method)
static av_cold void uninit(AVFilterContext *ctx)
static av_always_inline uint8_t colormap_nearest_bruteforce(const uint32_t *palette, const uint8_t *rgb)
AVFilterContext * dst
dest filter
static av_always_inline int color_get(struct cache_node *cache, uint32_t color, uint8_t r, uint8_t g, uint8_t b, const struct color_node *map, const uint32_t *palette, const enum color_search_method search_method)
Check if the requested color is in the cache already.
static const AVFilterPad paletteuse_inputs[]
int main(int argc, char **argv)
struct color_node map[AVPALETTE_COUNT]
AVPixelFormat
Pixel format.
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
int64_t frame_count
Number of past frames sent through the link.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static void debug_mean_error(PaletteUseContext *s, const AVFrame *in1, const AVFrame *in2, int frame_count)
AVFilterFormats * out_formats