vf_pixdesctest.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Stefano Sabatini
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 
29 typedef struct {
31  uint16_t *line;
33 
34 static av_cold void uninit(AVFilterContext *ctx)
35 {
36  PixdescTestContext *priv = ctx->priv;
37  av_freep(&priv->line);
38 }
39 
40 static int config_props(AVFilterLink *inlink)
41 {
42  PixdescTestContext *priv = inlink->dst->priv;
43 
44  priv->pix_desc = &av_pix_fmt_descriptors[inlink->format];
45 
46  if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
47  return AVERROR(ENOMEM);
48 
49  return 0;
50 }
51 
52 static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
53 {
54  PixdescTestContext *priv = inlink->dst->priv;
55  AVFilterLink *outlink = inlink->dst->outputs[0];
56  AVFilterBufferRef *outpicref;
57  int i;
58 
60  outlink->w, outlink->h);
61  outpicref = outlink->out_buf;
62  avfilter_copy_buffer_ref_props(outpicref, picref);
63 
64  for (i = 0; i < 4; i++) {
65  int h = outlink->h;
66  h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
67  if (outpicref->data[i]) {
68  uint8_t *data = outpicref->data[i] +
69  (outpicref->linesize[i] > 0 ? 0 : outpicref->linesize[i] * (h-1));
70  memset(data, 0, FFABS(outpicref->linesize[i]) * h);
71  }
72  }
73 
74  /* copy palette */
75  if (priv->pix_desc->flags & PIX_FMT_PAL)
76  memcpy(outpicref->data[1], outpicref->data[1], 256*4);
77 
78  avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
79 }
80 
81 static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
82 {
83  PixdescTestContext *priv = inlink->dst->priv;
84  AVFilterBufferRef *inpic = inlink->cur_buf;
85  AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
86  int i, c, w = inlink->w;
87 
88  for (c = 0; c < priv->pix_desc->nb_components; c++) {
89  int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
90  int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
91  int y1 = c == 1 || c == 2 ? y>>priv->pix_desc->log2_chroma_h : y;
92 
93  for (i = y1; i < y1 + h1; i++) {
95  inpic->data,
96  inpic->linesize,
97  priv->pix_desc,
98  0, i, c, w1, 0);
99 
101  outpic->data,
102  outpic->linesize,
103  priv->pix_desc,
104  0, i, c, w1);
105  }
106  }
107 
108  avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
109 }
110 
112  .name = "pixdesctest",
113  .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
114 
115  .priv_size = sizeof(PixdescTestContext),
116  .uninit = uninit,
117 
118  .inputs = (AVFilterPad[]) {{ .name = "default",
119  .type = AVMEDIA_TYPE_VIDEO,
120  .start_frame = start_frame,
121  .draw_slice = draw_slice,
122  .config_props = config_props,
123  .min_perms = AV_PERM_READ, },
124  { .name = NULL}},
125 
126  .outputs = (AVFilterPad[]) {{ .name = "default",
127  .type = AVMEDIA_TYPE_VIDEO, },
128  { .name = NULL}},
129 };
AVFilterBufferRef * avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: avfilter.c:289
int linesize[8]
number of bytes per line
Definition: avfilter.h:127
static void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
Copy properties of src to dst, without copying the actual data.
Definition: avfilter.h:148
static av_cold void uninit(AVFilterContext *ctx)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:66
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:147
#define AV_PERM_READ
can read from the buffer
Definition: avfilter.h:81
#define av_cold
Definition: attributes.h:71
void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w)
Write the values from src to the pixel format component c of an image line.
Definition: pixdesc.c:74
static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
const char data[16]
Definition: mxf.c:60
A filter pad used for either input or output.
Definition: avfilter.h:312
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
static int config_props(AVFilterLink *inlink)
void * priv
private data for use by the filter
Definition: avfilter.h:553
#define PIX_FMT_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:87
const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB]
The array of all the pixel format descriptors.
Definition: pixdesc.c:119
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
AVFilter avfilter_vf_pixdesctest
#define FFABS(a)
Definition: common.h:50
void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
Send a slice to the next filter.
Definition: avfilter.c:447
A reference to an AVFilterBuffer.
Definition: avfilter.h:124
NULL
Definition: eval.c:50
uint8_t flags
Definition: pixdesc.h:76
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:64
Filter definition.
Definition: avfilter.h:497
AVFilterBufferRef * avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
Add a new reference to a buffer.
Definition: avfilter.c:47
void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
Notify the next filter of the start of a frame.
Definition: avfilter.c:400
const char * name
filter name
Definition: avfilter.h:498
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:551
void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component)
Read a line from an image, and write the values of the pixel format component c to dst...
Definition: pixdesc.c:29
#define AV_PERM_WRITE
can write to the buffer
Definition: avfilter.h:82
uint8_t * data[8]
picture/audio data for each plane
Definition: avfilter.h:126
const AVPixFmtDescriptor * pix_desc
An instance of a filter.
Definition: avfilter.h:538