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_desc_get(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 filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
00056 {
00057 PixdescTestContext *priv = inlink->dst->priv;
00058 AVFilterLink *outlink = inlink->dst->outputs[0];
00059 AVFilterBufferRef *out;
00060 int i, c, w = inlink->w, h = inlink->h;
00061
00062 out = ff_get_video_buffer(outlink, AV_PERM_WRITE,
00063 outlink->w, outlink->h);
00064 if (!out) {
00065 avfilter_unref_bufferp(&in);
00066 return AVERROR(ENOMEM);
00067 }
00068
00069 avfilter_copy_buffer_ref_props(out, in);
00070
00071 for (i = 0; i < 4; i++) {
00072 int h = outlink->h;
00073 h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
00074 if (out->data[i]) {
00075 uint8_t *data = out->data[i] +
00076 (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h-1));
00077 memset(data, 0, FFABS(out->linesize[i]) * h);
00078 }
00079 }
00080
00081
00082 if (priv->pix_desc->flags & PIX_FMT_PAL ||
00083 priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
00084 memcpy(out->data[1], in->data[1], AVPALETTE_SIZE);
00085
00086 for (c = 0; c < priv->pix_desc->nb_components; c++) {
00087 int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
00088 int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
00089
00090 for (i = 0; i < h1; i++) {
00091 av_read_image_line(priv->line,
00092 (void*)in->data,
00093 in->linesize,
00094 priv->pix_desc,
00095 0, i, c, w1, 0);
00096
00097 av_write_image_line(priv->line,
00098 out->data,
00099 out->linesize,
00100 priv->pix_desc,
00101 0, i, c, w1);
00102 }
00103 }
00104
00105 avfilter_unref_bufferp(&in);
00106 return ff_filter_frame(outlink, out);
00107 }
00108
00109 static const AVFilterPad avfilter_vf_pixdesctest_inputs[] = {
00110 {
00111 .name = "default",
00112 .type = AVMEDIA_TYPE_VIDEO,
00113 .filter_frame = filter_frame,
00114 .config_props = config_props,
00115 .min_perms = AV_PERM_READ,
00116 },
00117 { NULL }
00118 };
00119
00120 static const AVFilterPad avfilter_vf_pixdesctest_outputs[] = {
00121 {
00122 .name = "default",
00123 .type = AVMEDIA_TYPE_VIDEO,
00124 },
00125 { NULL }
00126 };
00127
00128 AVFilter avfilter_vf_pixdesctest = {
00129 .name = "pixdesctest",
00130 .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
00131
00132 .priv_size = sizeof(PixdescTestContext),
00133 .uninit = uninit,
00134
00135 .inputs = avfilter_vf_pixdesctest_inputs,
00136
00137 .outputs = avfilter_vf_pixdesctest_outputs,
00138 };