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/common.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "internal.h"
30 #include "video.h"
31 
32 typedef struct {
34  uint16_t *line;
36 
37 static av_cold void uninit(AVFilterContext *ctx)
38 {
39  PixdescTestContext *priv = ctx->priv;
40  av_freep(&priv->line);
41 }
42 
43 static int config_props(AVFilterLink *inlink)
44 {
45  PixdescTestContext *priv = inlink->dst->priv;
46 
47  priv->pix_desc = av_pix_fmt_desc_get(inlink->format);
48 
49  if (!(priv->line = av_malloc(sizeof(*priv->line) * inlink->w)))
50  return AVERROR(ENOMEM);
51 
52  return 0;
53 }
54 
56 {
57  PixdescTestContext *priv = inlink->dst->priv;
58  AVFilterLink *outlink = inlink->dst->outputs[0];
59  AVFilterBufferRef *out;
60  int i, c, w = inlink->w, h = inlink->h;
61 
62  out = ff_get_video_buffer(outlink, AV_PERM_WRITE,
63  outlink->w, outlink->h);
64  if (!out) {
66  return AVERROR(ENOMEM);
67  }
68 
70 
71  for (i = 0; i < 4; i++) {
72  int h = outlink->h;
73  h = i == 1 || i == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
74  if (out->data[i]) {
75  uint8_t *data = out->data[i] +
76  (out->linesize[i] > 0 ? 0 : out->linesize[i] * (h-1));
77  memset(data, 0, FFABS(out->linesize[i]) * h);
78  }
79  }
80 
81  /* copy palette */
82  if (priv->pix_desc->flags & PIX_FMT_PAL ||
84  memcpy(out->data[1], in->data[1], 256*4);
85 
86  for (c = 0; c < priv->pix_desc->nb_components; c++) {
87  int w1 = c == 1 || c == 2 ? w>>priv->pix_desc->log2_chroma_w : w;
88  int h1 = c == 1 || c == 2 ? h>>priv->pix_desc->log2_chroma_h : h;
89 
90  for (i = 0; i < h1; i++) {
92  in->data,
93  in->linesize,
94  priv->pix_desc,
95  0, i, c, w1, 0);
96 
98  out->data,
99  out->linesize,
100  priv->pix_desc,
101  0, i, c, w1);
102  }
103  }
104 
106  return ff_filter_frame(outlink, out);
107 }
108 
110  {
111  .name = "default",
112  .type = AVMEDIA_TYPE_VIDEO,
113  .filter_frame = filter_frame,
114  .config_props = config_props,
115  .min_perms = AV_PERM_READ,
116  },
117  { NULL }
118 };
119 
121  {
122  .name = "default",
123  .type = AVMEDIA_TYPE_VIDEO,
124  },
125  { NULL }
126 };
127 
129  .name = "pixdesctest",
130  .description = NULL_IF_CONFIG_SMALL("Test pixel format definitions."),
131 
132  .priv_size = sizeof(PixdescTestContext),
133  .uninit = uninit,
134 
135  .inputs = avfilter_vf_pixdesctest_inputs,
136 
137  .outputs = avfilter_vf_pixdesctest_outputs,
138 };
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:61
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1435
int linesize[8]
number of bytes per line
Definition: avfilter.h:157
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:122
static av_cold void uninit(AVFilterContext *ctx)
int ff_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:459
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:151
#define AV_PERM_READ
can read from the buffer
Definition: avfilter.h:97
const char * name
Pad name.
Definition: internal.h:39
static const AVFilterPad avfilter_vf_pixdesctest_inputs[]
static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *in)
uint8_t
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:79
void avfilter_unref_bufferp(AVFilterBufferRef **ref)
Remove a reference to a buffer and set the pointer to NULL.
Definition: buffer.c:88
const char data[16]
Definition: mxf.c:66
A filter pad used for either input or output.
Definition: internal.h:33
AVFilterBufferRef * ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:145
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
static int config_props(AVFilterLink *inlink)
void * priv
private data for use by the filter
Definition: avfilter.h:439
#define PIX_FMT_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:87
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
AVFilter avfilter_vf_pixdesctest
static const AVFilterPad avfilter_vf_pixdesctest_outputs[]
A reference to an AVFilterBuffer.
Definition: avfilter.h:139
NULL
Definition: eval.c:52
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
Filter definition.
Definition: avfilter.h:371
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:110
const char * name
filter name
Definition: avfilter.h:372
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:433
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:31
common internal and external API header
void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
Copy properties of src to dst, without copying the actual data.
Definition: buffer.c:164
#define AV_PERM_WRITE
can write to the buffer
Definition: avfilter.h:98
#define PIX_FMT_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:97
uint8_t * data[8]
picture/audio data for each plane
Definition: avfilter.h:141
const AVPixFmtDescriptor * pix_desc
An instance of a filter.
Definition: avfilter.h:418
internal API functions