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 priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
00077 memcpy(outpicref->data[1], picref->data[1], AVPALETTE_SIZE);
00078
00079 avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
00080 }
00081
00082 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
00083 {
00084 PixdescTestContext *priv = inlink->dst->priv;
00085 AVFilterBufferRef *inpic = inlink->cur_buf;
00086 AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
00087 int i, c, w = inlink->w;
00088
00089 for (c = 0; c < priv->pix_desc->nb_components; c++) {
00090 int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
00091 int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
00092 int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
00093
00094 for (i = y1; i < y1 + h1; i++) {
00095 av_read_image_line(priv->line,
00096 (void*)inpic->data,
00097 inpic->linesize,
00098 priv->pix_desc,
00099 0, i, c, w1, 0);
00100
00101 av_write_image_line(priv->line,
00102 outpic->data,
00103 outpic->linesize,
00104 priv->pix_desc,
00105 0, i, c, w1);
00106 }
00107 }
00108
00109 avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
00110 }
00111
00112 AVFilter avfilter_vf_pixdesctest = {
00113 .name = "pixdesctest",
00114 .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
00115
00116 .priv_size = sizeof(PixdescTestContext),
00117 .uninit = uninit,
00118
00119 .inputs = (const AVFilterPad[]) {{ .name = "default",
00120 .type = AVMEDIA_TYPE_VIDEO,
00121 .start_frame = start_frame,
00122 .draw_slice = draw_slice,
00123 .config_props = config_props,
00124 .min_perms = AV_PERM_READ, },
00125 { .name = NULL}},
00126
00127 .outputs = (const AVFilterPad[]) {{ .name = "default",
00128 .type = AVMEDIA_TYPE_VIDEO, },
00129 { .name = NULL}},
00130 };