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