00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "libavutil/pixdesc.h"
00027 #include "avfilter.h"
00028
00029 typedef struct {
00030 const AVPixFmtDescriptor *pix_desc;
00031 uint16_t *line;
00032 } PixdescTestContext;
00033
00034 static av_cold void uninit(AVFilterContext *ctx)
00035 {
00036 PixdescTestContext *priv = ctx->priv;
00037 av_freep(&priv->line);
00038 }
00039
00040 static int config_props(AVFilterLink *inlink)
00041 {
00042 PixdescTestContext *priv = inlink->dst->priv;
00043
00044 priv->pix_desc = &av_pix_fmt_descriptors[inlink->format];
00045
00046 if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
00047 return AVERROR(ENOMEM);
00048
00049 return 0;
00050 }
00051
00052 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
00053 {
00054 PixdescTestContext *priv = inlink->dst->priv;
00055 AVFilterLink *outlink = inlink->dst->outputs[0];
00056 AVFilterBufferRef *outpicref;
00057 int i;
00058
00059 outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE,
00060 outlink->w, outlink->h);
00061 outpicref = outlink->out_buf;
00062 avfilter_copy_buffer_ref_props(outpicref, picref);
00063
00064 for (i = 0; i < 4; i++) {
00065 int h = outlink->h;
00066 h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
00067 if (outpicref->data[i]) {
00068 uint8_t *data = outpicref->data[i] +
00069 (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1));
00070 memset(data, 0, FFABS(outpicref->linesize[i]) * h);
00071 }
00072 }
00073
00074
00075 if (priv->pix_desc->flags & PIX_FMT_PAL)
00076 memcpy(outpicref->data[1], outpicref->data[1], 256*4);
00077
00078 avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
00079 }
00080
00081 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
00082 {
00083 PixdescTestContext *priv = inlink->dst->priv;
00084 AVFilterBufferRef *inpic = inlink->cur_buf;
00085 AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
00086 int i, c, w = inlink->w;
00087
00088 for (c = 0; c < priv->pix_desc->nb_components; c++) {
00089 int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
00090 int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
00091 int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
00092
00093 for (i = y1; i < y1 + h1; i++) {
00094 av_read_image_line(priv->line,
00095 (void*)inpic->data,
00096 inpic->linesize,
00097 priv->pix_desc,
00098 0, i, c, w1, 0);
00099
00100 av_write_image_line(priv->line,
00101 outpic->data,
00102 outpic->linesize,
00103 priv->pix_desc,
00104 0, i, c, w1);
00105 }
00106 }
00107
00108 avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
00109 }
00110
00111 AVFilter avfilter_vf_pixdesctest = {
00112 .name = "pixdesctest",
00113 .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
00114
00115 .priv_size = sizeof(PixdescTestContext),
00116 .uninit = uninit,
00117
00118 .inputs = (const AVFilterPad[]) {{ .name = "default",
00119 .type = AVMEDIA_TYPE_VIDEO,
00120 .start_frame = start_frame,
00121 .draw_slice = draw_slice,
00122 .config_props = config_props,
00123 .min_perms = AV_PERM_READ, },
00124 { .name = NULL}},
00125
00126 .outputs = (const AVFilterPad[]) {{ .name = "default",
00127 .type = AVMEDIA_TYPE_VIDEO, },
00128 { .name = NULL}},
00129 };