FFmpeg
Loading...
Searching...
No Matches
vf_showpalette.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * @file
21 * Display frame palette (AV_PIX_FMT_PAL8)
22 */
23
24#include "libavutil/opt.h"
25#include "avfilter.h"
26#include "filters.h"
27#include "formats.h"
28#include "video.h"
29
30typedef struct ShowPaletteContext {
31 const AVClass *class;
32 int size;
34
35#define OFFSET(x) offsetof(ShowPaletteContext, x)
36#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
37static const AVOption showpalette_options[] = {
38 { "s", "set pixel box size", OFFSET(size), AV_OPT_TYPE_INT, {.i64=30}, 1, 100, FLAGS },
39 { NULL }
40};
41
43
45 AVFilterFormatsConfig **cfg_in,
46 AVFilterFormatsConfig **cfg_out)
47{
48 static const enum AVPixelFormat in_fmts[] = {AV_PIX_FMT_PAL8, AV_PIX_FMT_NONE};
49 static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
51 &cfg_in[0]->formats);
52 if (ret < 0)
53 return ret;
54
56 &cfg_out[0]->formats);
57}
58
59static int config_output(AVFilterLink *outlink)
60{
61 AVFilterContext *ctx = outlink->src;
62 const ShowPaletteContext *s = ctx->priv;
63 outlink->w = outlink->h = 16 * s->size;
64 return 0;
65}
66
67static void disp_palette(AVFrame *out, const AVFrame *in, int size)
68{
69 int x, y, i, j;
70 uint32_t *dst = (uint32_t *)out->data[0];
71 const int dst_linesize = out->linesize[0] >> 2;
72 const uint32_t *pal = (uint32_t *)in->data[1];
73
74 for (y = 0; y < 16; y++)
75 for (x = 0; x < 16; x++)
76 for (j = 0; j < size; j++)
77 for (i = 0; i < size; i++)
78 dst[(y*dst_linesize + x) * size + j*dst_linesize + i] = pal[y*16 + x];
79}
80
81static int filter_frame(AVFilterLink *inlink, AVFrame *in)
82{
83 AVFrame *out;
84 AVFilterContext *ctx = inlink->dst;
85 const ShowPaletteContext *s = ctx->priv;
86 AVFilterLink *outlink = ctx->outputs[0];
87
88 out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
89 if (!out) {
90 av_frame_free(&in);
91 return AVERROR(ENOMEM);
92 }
94 disp_palette(out, in, s->size);
95 av_frame_free(&in);
96 return ff_filter_frame(outlink, out);
97}
98
100 {
101 .name = "default",
102 .type = AVMEDIA_TYPE_VIDEO,
103 .filter_frame = filter_frame,
104 },
105};
106
108 {
109 .name = "default",
110 .type = AVMEDIA_TYPE_VIDEO,
111 .config_props = config_output,
112 },
113};
114
116 .p.name = "showpalette",
117 .p.description = NULL_IF_CONFIG_SMALL("Display frame palette."),
118 .p.priv_class = &showpalette_class,
119 .priv_size = sizeof(ShowPaletteContext),
123};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
const FFFilter ff_vf_showpalette
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition formats.c:756
av_warn_unused_result AVFilterFormats * ff_make_pixel_format_list(const enum AVPixelFormat *fmts)
Create a list of supported pixel formats.
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static int config_output(AVBitStreamFilterLink *outlink)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
AVOptions.
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
#define AV_PIX_FMT_RGB32
Definition pixfmt.h:517
formats
Definition signature.h:47
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
Lists of formats / etc.
Definition avfilter.h:120
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
AVOption.
Definition opt.h:428
static FILE * out
Definition movenc.c:55
static AVFormatContext * ctx
Definition movenc.c:49
int size
static void disp_palette(AVFrame *out, const AVFrame *in, int size)
static const AVFilterPad showpalette_inputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
#define OFFSET(x)
static const AVFilterPad showpalette_outputs[]
static int config_output(AVFilterLink *outlink)
static const AVOption showpalette_options[]
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:89