FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
drawutils.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Stefano Sabatini <stefano.sabatini-lala poste it>
3  * Copyright 2012 Nicolas George <nicolas.george normalesup org>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <string.h>
23 
24 #include "libavutil/avassert.h"
25 #include "libavutil/avutil.h"
26 #include "libavutil/colorspace.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/pixdesc.h"
29 #include "drawutils.h"
30 #include "formats.h"
31 
32 enum { RED = 0, GREEN, BLUE, ALPHA };
33 
35 {
36  switch (pix_fmt) {
37  case AV_PIX_FMT_0RGB:
38  case AV_PIX_FMT_ARGB: rgba_map[ALPHA] = 0; rgba_map[RED ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break;
39  case AV_PIX_FMT_0BGR:
40  case AV_PIX_FMT_ABGR: rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED ] = 3; break;
41  case AV_PIX_FMT_RGB48LE:
42  case AV_PIX_FMT_RGB48BE:
45  case AV_PIX_FMT_RGB0:
46  case AV_PIX_FMT_RGBA:
47  case AV_PIX_FMT_RGB24: rgba_map[RED ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break;
48  case AV_PIX_FMT_BGR48LE:
49  case AV_PIX_FMT_BGR48BE:
52  case AV_PIX_FMT_BGRA:
53  case AV_PIX_FMT_BGR0:
54  case AV_PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break;
55  case AV_PIX_FMT_GBRP9:
56  case AV_PIX_FMT_GBRP10:
57  case AV_PIX_FMT_GBRP12:
58  case AV_PIX_FMT_GBRP14:
59  case AV_PIX_FMT_GBRAP:
60  case AV_PIX_FMT_GBRP: rgba_map[GREEN] = 0; rgba_map[BLUE ] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break;
61  default: /* unsupported */
62  return AVERROR(EINVAL);
63  }
64  return 0;
65 }
66 
67 int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t dst_color[4],
68  enum AVPixelFormat pix_fmt, uint8_t rgba_color[4],
69  int *is_packed_rgba, uint8_t rgba_map_ptr[4])
70 {
71  uint8_t rgba_map[4] = {0};
72  int i;
73  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(pix_fmt);
74  int hsub;
75 
76  av_assert0(pix_desc);
77 
78  hsub = pix_desc->log2_chroma_w;
79 
80  *is_packed_rgba = ff_fill_rgba_map(rgba_map, pix_fmt) >= 0;
81 
82  if (*is_packed_rgba) {
83  pixel_step[0] = (av_get_bits_per_pixel(pix_desc))>>3;
84  for (i = 0; i < 4; i++)
85  dst_color[rgba_map[i]] = rgba_color[i];
86 
87  line[0] = av_malloc_array(w, pixel_step[0]);
88  if (!line[0])
89  return AVERROR(ENOMEM);
90  for (i = 0; i < w; i++)
91  memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]);
92  if (rgba_map_ptr)
93  memcpy(rgba_map_ptr, rgba_map, sizeof(rgba_map[0]) * 4);
94  } else {
95  int plane;
96 
97  dst_color[0] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
98  dst_color[1] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
99  dst_color[2] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
100  dst_color[3] = rgba_color[3];
101 
102  for (plane = 0; plane < 4; plane++) {
103  int line_size;
104  int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
105 
106  pixel_step[plane] = 1;
107  line_size = AV_CEIL_RSHIFT(w, hsub1) * pixel_step[plane];
108  line[plane] = av_malloc(line_size);
109  if (!line[plane]) {
110  while(plane && line[plane-1])
111  av_freep(&line[--plane]);
112  return AVERROR(ENOMEM);
113  }
114  memset(line[plane], dst_color[plane], line_size);
115  }
116  }
117 
118  return 0;
119 }
120 
121 void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4],
122  uint8_t *src[4], int pixelstep[4],
123  int hsub, int vsub, int x, int y, int w, int h)
124 {
125  int i, plane;
126  uint8_t *p;
127 
128  for (plane = 0; plane < 4 && dst[plane]; plane++) {
129  int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
130  int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
131  int width = AV_CEIL_RSHIFT(w, hsub1);
132  int height = AV_CEIL_RSHIFT(h, vsub1);
133 
134  p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
135  for (i = 0; i < height; i++) {
136  memcpy(p + (x >> hsub1) * pixelstep[plane],
137  src[plane], width * pixelstep[plane]);
138  p += dst_linesize[plane];
139  }
140  }
141 }
142 
143 void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4],
144  uint8_t *src[4], int src_linesize[4], int pixelstep[4],
145  int hsub, int vsub, int x, int y, int y2, int w, int h)
146 {
147  int i, plane;
148  uint8_t *p;
149 
150  for (plane = 0; plane < 4 && dst[plane]; plane++) {
151  int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
152  int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
153  int width = AV_CEIL_RSHIFT(w, hsub1);
154  int height = AV_CEIL_RSHIFT(h, vsub1);
155 
156  p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
157  for (i = 0; i < height; i++) {
158  memcpy(p + (x >> hsub1) * pixelstep[plane],
159  src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), width * pixelstep[plane]);
160  p += dst_linesize[plane];
161  }
162  }
163 }
164 
166 {
167  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
168  const AVComponentDescriptor *c;
169  unsigned i, nb_planes = 0;
170  int pixelstep[MAX_PLANES] = { 0 };
171 
172  if (!desc || !desc->name)
173  return AVERROR(EINVAL);
175  return AVERROR(ENOSYS);
176  for (i = 0; i < desc->nb_components; i++) {
177  c = &desc->comp[i];
178  /* for now, only 8-bits formats */
179  if (c->depth != 8)
180  return AVERROR(ENOSYS);
181  if (c->plane >= MAX_PLANES)
182  return AVERROR(ENOSYS);
183  /* strange interleaving */
184  if (pixelstep[c->plane] != 0 &&
185  pixelstep[c->plane] != c->step)
186  return AVERROR(ENOSYS);
187  pixelstep[c->plane] = c->step;
188  if (pixelstep[c->plane] >= 8)
189  return AVERROR(ENOSYS);
190  nb_planes = FFMAX(nb_planes, c->plane + 1);
191  }
192  if ((desc->log2_chroma_w || desc->log2_chroma_h) && nb_planes < 3)
193  return AVERROR(ENOSYS); /* exclude NV12 and NV21 */
194  memset(draw, 0, sizeof(*draw));
195  draw->desc = desc;
196  draw->format = format;
197  draw->nb_planes = nb_planes;
198  memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));
199  draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;
200  draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;
201  for (i = 0; i < ((desc->nb_components - 1) | 1); i++)
202  draw->comp_mask[desc->comp[i].plane] |=
203  1 << desc->comp[i].offset;
204  return 0;
205 }
206 
208 {
209  unsigned i;
210  uint8_t rgba_map[4];
211 
212  if (rgba != color->rgba)
213  memcpy(color->rgba, rgba, sizeof(color->rgba));
214  if ((draw->desc->flags & AV_PIX_FMT_FLAG_RGB) &&
215  ff_fill_rgba_map(rgba_map, draw->format) >= 0) {
216  if (draw->nb_planes == 1) {
217  for (i = 0; i < 4; i++)
218  color->comp[0].u8[rgba_map[i]] = rgba[i];
219  } else {
220  for (i = 0; i < 4; i++)
221  color->comp[rgba_map[i]].u8[0] = rgba[i];
222  }
223  } else if (draw->nb_planes == 3 || draw->nb_planes == 4) {
224  /* assume YUV */
225  color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
226  color->comp[1].u8[0] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
227  color->comp[2].u8[0] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
228  color->comp[3].u8[0] = rgba[3];
229  } else if (draw->format == AV_PIX_FMT_GRAY8 || draw->format == AV_PIX_FMT_GRAY8A) {
230  color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
231  color->comp[1].u8[0] = rgba[3];
232  } else {
234  "Color conversion not implemented for %s\n", draw->desc->name);
235  memset(color, 128, sizeof(*color));
236  }
237 }
238 
239 static uint8_t *pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[],
240  int plane, int x, int y)
241 {
242  return data[plane] +
243  (y >> draw->vsub[plane]) * linesize[plane] +
244  (x >> draw->hsub[plane]) * draw->pixelstep[plane];
245 }
246 
248  uint8_t *dst[], int dst_linesize[],
249  uint8_t *src[], int src_linesize[],
250  int dst_x, int dst_y, int src_x, int src_y,
251  int w, int h)
252 {
253  int plane, y, wp, hp;
254  uint8_t *p, *q;
255 
256  for (plane = 0; plane < draw->nb_planes; plane++) {
257  p = pointer_at(draw, src, src_linesize, plane, src_x, src_y);
258  q = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
259  wp = AV_CEIL_RSHIFT(w, draw->hsub[plane]) * draw->pixelstep[plane];
260  hp = AV_CEIL_RSHIFT(h, draw->vsub[plane]);
261  for (y = 0; y < hp; y++) {
262  memcpy(q, p, wp);
263  p += src_linesize[plane];
264  q += dst_linesize[plane];
265  }
266  }
267 }
268 
270  uint8_t *dst[], int dst_linesize[],
271  int dst_x, int dst_y, int w, int h)
272 {
273  int plane, x, y, wp, hp;
274  uint8_t *p0, *p;
275 
276  for (plane = 0; plane < draw->nb_planes; plane++) {
277  p0 = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
278  wp = AV_CEIL_RSHIFT(w, draw->hsub[plane]);
279  hp = AV_CEIL_RSHIFT(h, draw->vsub[plane]);
280  if (!hp)
281  return;
282  p = p0;
283  /* copy first line from color */
284  for (x = 0; x < wp; x++) {
285  memcpy(p, color->comp[plane].u8, draw->pixelstep[plane]);
286  p += draw->pixelstep[plane];
287  }
288  wp *= draw->pixelstep[plane];
289  /* copy next lines from first line */
290  p = p0 + dst_linesize[plane];
291  for (y = 1; y < hp; y++) {
292  memcpy(p, p0, wp);
293  p += dst_linesize[plane];
294  }
295  }
296 }
297 
298 /**
299  * Clip interval [x; x+w[ within [0; wmax[.
300  * The resulting w may be negative if the final interval is empty.
301  * dx, if not null, return the difference between in and out value of x.
302  */
303 static void clip_interval(int wmax, int *x, int *w, int *dx)
304 {
305  if (dx)
306  *dx = 0;
307  if (*x < 0) {
308  if (dx)
309  *dx = -*x;
310  *w += *x;
311  *x = 0;
312  }
313  if (*x + *w > wmax)
314  *w = wmax - *x;
315 }
316 
317 /**
318  * Decompose w pixels starting at x
319  * into start + (w starting at x) + end
320  * with x and w aligned on multiples of 1<<sub.
321  */
322 static void subsampling_bounds(int sub, int *x, int *w, int *start, int *end)
323 {
324  int mask = (1 << sub) - 1;
325 
326  *start = (-*x) & mask;
327  *x += *start;
328  *start = FFMIN(*start, *w);
329  *w -= *start;
330  *end = *w & mask;
331  *w >>= sub;
332 }
333 
334 static int component_used(FFDrawContext *draw, int plane, int comp)
335 {
336  return (draw->comp_mask[plane] >> comp) & 1;
337 }
338 
339 /* If alpha is in the [ 0 ; 0x1010101 ] range,
340  then alpha * value is in the [ 0 ; 0xFFFFFFFF ] range,
341  and >> 24 gives a correct rounding. */
342 static void blend_line(uint8_t *dst, unsigned src, unsigned alpha,
343  int dx, int w, unsigned hsub, int left, int right)
344 {
345  unsigned asrc = alpha * src;
346  unsigned tau = 0x1010101 - alpha;
347  int x;
348 
349  if (left) {
350  unsigned suba = (left * alpha) >> hsub;
351  *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
352  dst += dx;
353  }
354  for (x = 0; x < w; x++) {
355  *dst = (*dst * tau + asrc) >> 24;
356  dst += dx;
357  }
358  if (right) {
359  unsigned suba = (right * alpha) >> hsub;
360  *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
361  }
362 }
363 
365  uint8_t *dst[], int dst_linesize[],
366  int dst_w, int dst_h,
367  int x0, int y0, int w, int h)
368 {
369  unsigned alpha, nb_planes, nb_comp, plane, comp;
370  int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
371  uint8_t *p0, *p;
372 
373  /* TODO optimize if alpha = 0xFF */
374  clip_interval(dst_w, &x0, &w, NULL);
375  clip_interval(dst_h, &y0, &h, NULL);
376  if (w <= 0 || h <= 0 || !color->rgba[3])
377  return;
378  /* 0x10203 * alpha + 2 is in the [ 2 ; 0x1010101 - 2 ] range */
379  alpha = 0x10203 * color->rgba[3] + 0x2;
380  nb_planes = (draw->nb_planes - 1) | 1; /* eliminate alpha */
381  for (plane = 0; plane < nb_planes; plane++) {
382  nb_comp = draw->pixelstep[plane];
383  p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
384  w_sub = w;
385  h_sub = h;
386  x_sub = x0;
387  y_sub = y0;
388  subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
389  subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
390  for (comp = 0; comp < nb_comp; comp++) {
391  if (!component_used(draw, plane, comp))
392  continue;
393  p = p0 + comp;
394  if (top) {
395  blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
396  draw->pixelstep[plane], w_sub,
397  draw->hsub[plane], left, right);
398  p += dst_linesize[plane];
399  }
400  for (y = 0; y < h_sub; y++) {
401  blend_line(p, color->comp[plane].u8[comp], alpha,
402  draw->pixelstep[plane], w_sub,
403  draw->hsub[plane], left, right);
404  p += dst_linesize[plane];
405  }
406  if (bottom)
407  blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
408  draw->pixelstep[plane], w_sub,
409  draw->hsub[plane], left, right);
410  }
411  }
412 }
413 
414 static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha,
415  const uint8_t *mask, int mask_linesize, int l2depth,
416  unsigned w, unsigned h, unsigned shift, unsigned xm0)
417 {
418  unsigned xm, x, y, t = 0;
419  unsigned xmshf = 3 - l2depth;
420  unsigned xmmod = 7 >> l2depth;
421  unsigned mbits = (1 << (1 << l2depth)) - 1;
422  unsigned mmult = 255 / mbits;
423 
424  for (y = 0; y < h; y++) {
425  xm = xm0;
426  for (x = 0; x < w; x++) {
427  t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
428  * mmult;
429  xm++;
430  }
431  mask += mask_linesize;
432  }
433  alpha = (t >> shift) * alpha;
434  *dst = ((0x1010101 - alpha) * *dst + alpha * src) >> 24;
435 }
436 
437 static void blend_line_hv(uint8_t *dst, int dst_delta,
438  unsigned src, unsigned alpha,
439  const uint8_t *mask, int mask_linesize, int l2depth, int w,
440  unsigned hsub, unsigned vsub,
441  int xm, int left, int right, int hband)
442 {
443  int x;
444 
445  if (left) {
446  blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
447  left, hband, hsub + vsub, xm);
448  dst += dst_delta;
449  xm += left;
450  }
451  for (x = 0; x < w; x++) {
452  blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
453  1 << hsub, hband, hsub + vsub, xm);
454  dst += dst_delta;
455  xm += 1 << hsub;
456  }
457  if (right)
458  blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
459  right, hband, hsub + vsub, xm);
460 }
461 
463  uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
464  const uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
465  int l2depth, unsigned endianness, int x0, int y0)
466 {
467  unsigned alpha, nb_planes, nb_comp, plane, comp;
468  int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
469  uint8_t *p0, *p;
470  const uint8_t *m;
471 
472  clip_interval(dst_w, &x0, &mask_w, &xm0);
473  clip_interval(dst_h, &y0, &mask_h, &ym0);
474  mask += ym0 * mask_linesize;
475  if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
476  return;
477  /* alpha is in the [ 0 ; 0x10203 ] range,
478  alpha * mask is in the [ 0 ; 0x1010101 - 4 ] range */
479  alpha = (0x10307 * color->rgba[3] + 0x3) >> 8;
480  nb_planes = (draw->nb_planes - 1) | 1; /* eliminate alpha */
481  for (plane = 0; plane < nb_planes; plane++) {
482  nb_comp = draw->pixelstep[plane];
483  p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
484  w_sub = mask_w;
485  h_sub = mask_h;
486  x_sub = x0;
487  y_sub = y0;
488  subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
489  subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
490  for (comp = 0; comp < nb_comp; comp++) {
491  if (!component_used(draw, plane, comp))
492  continue;
493  p = p0 + comp;
494  m = mask;
495  if (top) {
496  blend_line_hv(p, draw->pixelstep[plane],
497  color->comp[plane].u8[comp], alpha,
498  m, mask_linesize, l2depth, w_sub,
499  draw->hsub[plane], draw->vsub[plane],
500  xm0, left, right, top);
501  p += dst_linesize[plane];
502  m += top * mask_linesize;
503  }
504  for (y = 0; y < h_sub; y++) {
505  blend_line_hv(p, draw->pixelstep[plane],
506  color->comp[plane].u8[comp], alpha,
507  m, mask_linesize, l2depth, w_sub,
508  draw->hsub[plane], draw->vsub[plane],
509  xm0, left, right, 1 << draw->vsub[plane]);
510  p += dst_linesize[plane];
511  m += mask_linesize << draw->vsub[plane];
512  }
513  if (bottom)
514  blend_line_hv(p, draw->pixelstep[plane],
515  color->comp[plane].u8[comp], alpha,
516  m, mask_linesize, l2depth, w_sub,
517  draw->hsub[plane], draw->vsub[plane],
518  xm0, left, right, bottom);
519  }
520  }
521 }
522 
523 int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
524  int value)
525 {
526  unsigned shift = sub_dir ? draw->vsub_max : draw->hsub_max;
527 
528  if (!shift)
529  return value;
530  if (round_dir >= 0)
531  value += round_dir ? (1 << shift) - 1 : 1 << (shift - 1);
532  return (value >> shift) << shift;
533 }
534 
536 {
537  enum AVPixelFormat i;
538  FFDrawContext draw;
539  AVFilterFormats *fmts = NULL;
540  int ret;
541 
542  for (i = 0; av_pix_fmt_desc_get(i); i++)
543  if (ff_draw_init(&draw, i, flags) >= 0 &&
544  (ret = ff_add_format(&fmts, i)) < 0)
545  return NULL;
546  return fmts;
547 }
548 
549 #ifdef TEST
550 
551 #undef printf
552 
553 int main(void)
554 {
555  enum AVPixelFormat f;
556  const AVPixFmtDescriptor *desc;
557  FFDrawContext draw;
559  int r, i;
560 
561  for (f = 0; av_pix_fmt_desc_get(f); f++) {
562  desc = av_pix_fmt_desc_get(f);
563  if (!desc->name)
564  continue;
565  printf("Testing %s...%*s", desc->name,
566  (int)(16 - strlen(desc->name)), "");
567  r = ff_draw_init(&draw, f, 0);
568  if (r < 0) {
569  char buf[128];
570  av_strerror(r, buf, sizeof(buf));
571  printf("no: %s\n", buf);
572  continue;
573  }
574  ff_draw_color(&draw, &color, (uint8_t[]) { 1, 0, 0, 1 });
575  for (i = 0; i < sizeof(color); i++)
576  if (((uint8_t *)&color)[i] != 128)
577  break;
578  if (i == sizeof(color)) {
579  printf("fallback color\n");
580  continue;
581  }
582  printf("ok\n");
583  }
584  return 0;
585 }
586 
587 #endif
int plane
Definition: avisynth_c.h:291
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
Definition: drawutils.c:535
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:35
#define NULL
Definition: coverity.c:32
static enum AVPixelFormat pix_fmt
static int shift(int a, int b)
Definition: sonic.c:82
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2157
void ff_copy_rectangle2(FFDrawContext *draw, uint8_t *dst[], int dst_linesize[], uint8_t *src[], int src_linesize[], int dst_x, int dst_y, int src_x, int src_y, int w, int h)
Copy a rectangle from an image to another.
Definition: drawutils.c:247
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:220
uint8_t hsub[MAX_PLANES]
Definition: drawutils.h:54
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:65
memory handling functions
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:2109
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:181
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:219
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:346
Various defines for YUV<->RGB conversion.
external API header
static void blend_line(uint8_t *dst, unsigned src, unsigned alpha, int dx, int w, unsigned hsub, int left, int right)
Definition: drawutils.c:342
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:247
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
static void clip_interval(int wmax, int *x, int *w, int *dx)
Clip interval [x; x+w[ within [0; wmax[.
Definition: drawutils.c:303
int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir, int value)
Round a dimension according to subsampling.
Definition: drawutils.c:523
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:173
#define av_malloc(s)
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:246
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:112
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
Definition: log.c:94
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:217
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:345
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:96
uint8_t comp_mask[MAX_PLANES]
Definition: drawutils.h:53
#define av_log(a,...)
unsigned m
Definition: audioconvert.c:187
const char * name
Definition: pixdesc.h:82
union FFDrawColor::@137 comp[MAX_PLANES]
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:99
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static const uint16_t mask[17]
Definition: lzw.c:38
#define AVERROR(e)
Definition: error.h:43
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:97
const char * r
Definition: vf_curves.c:107
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition: drawutils.c:207
Definition: graph2dot.c:48
simple assert() macros that are a bit more flexible than ISO C assert().
uint8_t u8[4]
Definition: drawutils.h:65
static void blend_line_hv(uint8_t *dst, int dst_delta, unsigned src, unsigned alpha, const uint8_t *mask, int mask_linesize, int l2depth, int w, unsigned hsub, unsigned vsub, int xm, int left, int right, int hband)
Definition: drawutils.c:437
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:337
uint8_t vsub_max
Definition: drawutils.h:57
#define FFMAX(a, b)
Definition: common.h:94
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:94
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:161
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:95
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:158
#define FFMIN(a, b)
Definition: common.h:96
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:158
#define MAX_PLANES
Definition: ffv1.h:50
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:66
#define src
Definition: vp9dsp.c:530
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:160
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:348
static uint8_t * pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[], int plane, int x, int y)
Definition: drawutils.c:239
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:34
static void subsampling_bounds(int sub, int *x, int *w, int *start, int *end)
Decompose w pixels starting at x into start + (w starting at x) + end with x and w aligned on multipl...
Definition: drawutils.c:322
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, const uint8_t *mask, int mask_linesize, int mask_w, int mask_h, int l2depth, unsigned endianness, int x0, int y0)
Blend an alpha mask with an uniform color.
Definition: drawutils.c:462
misc drawing utilities
Definition: drawutils.c:32
static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha, const uint8_t *mask, int mask_linesize, int l2depth, unsigned w, unsigned h, unsigned shift, unsigned xm0)
Definition: drawutils.c:414
unsigned nb_planes
Definition: drawutils.h:51
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static const char * format
Definition: movenc-test.c:47
void * buf
Definition: avisynth_c.h:553
uint8_t hsub_max
Definition: drawutils.h:56
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, int x0, int y0, int w, int h)
Blend a rectangle with an uniform color.
Definition: drawutils.c:364
void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4], uint8_t *src[4], int src_linesize[4], int pixelstep[4], int hsub, int vsub, int x, int y, int y2, int w, int h)
Definition: drawutils.c:143
Definition: drawutils.c:32
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:248
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:165
static int component_used(FFDrawContext *draw, int plane, int comp)
Definition: drawutils.c:334
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
Definition: colorspace.h:91
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:347
int offset
Number of elements before the component of the first pixel.
Definition: pixdesc.h:47
static int flags
Definition: cpu.c:47
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:105
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
Definition: colorspace.h:95
Y , 8bpp.
Definition: pixfmt.h:71
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
static double c[64]
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:111
#define RGB_TO_Y_CCIR(r, g, b)
Definition: colorspace.h:87
int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t dst_color[4], enum AVPixelFormat pix_fmt, uint8_t rgba_color[4], int *is_packed_rgba, uint8_t rgba_map_ptr[4])
Definition: drawutils.c:67
int pixelstep[MAX_PLANES]
Definition: drawutils.h:52
A list of supported formats for one end of a filter link.
Definition: formats.h:64
const struct AVPixFmtDescriptor * desc
Definition: drawutils.h:49
void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_x, int dst_y, int w, int h)
Fill a rectangle with an uniform color.
Definition: drawutils.c:269
uint8_t vsub[MAX_PLANES]
Definition: drawutils.h:55
#define av_freep(p)
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:83
void INT64 start
Definition: avisynth_c.h:553
#define av_malloc_array(a, b)
int main(int argc, char **argv)
Definition: main.c:22
void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4], uint8_t *src[4], int pixelstep[4], int hsub, int vsub, int x, int y, int w, int h)
Definition: drawutils.c:121
int depth
Number of bits in the component.
Definition: pixdesc.h:58
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:245
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:144
enum AVPixelFormat format
Definition: drawutils.h:50
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:218
int step
Number of elements between 2 horizontally consecutive pixels.
Definition: pixdesc.h:41
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
uint8_t rgba[4]
Definition: drawutils.h:61
static int width