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/avutil.h"
25 #include "libavutil/colorspace.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/pixdesc.h"
28 #include "drawutils.h"
29 #include "formats.h"
30 
31 enum { RED = 0, GREEN, BLUE, ALPHA };
32 
34 {
35  switch (pix_fmt) {
36  case AV_PIX_FMT_0RGB:
37  case AV_PIX_FMT_ARGB: rgba_map[ALPHA] = 0; rgba_map[RED ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break;
38  case AV_PIX_FMT_0BGR:
39  case AV_PIX_FMT_ABGR: rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED ] = 3; break;
40  case AV_PIX_FMT_RGB48LE:
41  case AV_PIX_FMT_RGB48BE:
44  case AV_PIX_FMT_RGB0:
45  case AV_PIX_FMT_RGBA:
46  case AV_PIX_FMT_RGB24: rgba_map[RED ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break;
47  case AV_PIX_FMT_BGR48LE:
48  case AV_PIX_FMT_BGR48BE:
51  case AV_PIX_FMT_BGRA:
52  case AV_PIX_FMT_BGR0:
53  case AV_PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break;
54  case AV_PIX_FMT_GBRAP:
55  case AV_PIX_FMT_GBRP: rgba_map[GREEN] = 0; rgba_map[BLUE ] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break;
56  default: /* unsupported */
57  return AVERROR(EINVAL);
58  }
59  return 0;
60 }
61 
62 int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t dst_color[4],
63  enum AVPixelFormat pix_fmt, uint8_t rgba_color[4],
64  int *is_packed_rgba, uint8_t rgba_map_ptr[4])
65 {
66  uint8_t rgba_map[4] = {0};
67  int i;
68  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(pix_fmt);
69  int hsub = pix_desc->log2_chroma_w;
70 
71  *is_packed_rgba = ff_fill_rgba_map(rgba_map, pix_fmt) >= 0;
72 
73  if (*is_packed_rgba) {
74  pixel_step[0] = (av_get_bits_per_pixel(pix_desc))>>3;
75  for (i = 0; i < 4; i++)
76  dst_color[rgba_map[i]] = rgba_color[i];
77 
78  line[0] = av_malloc_array(w, pixel_step[0]);
79  if (!line[0])
80  return AVERROR(ENOMEM);
81  for (i = 0; i < w; i++)
82  memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]);
83  if (rgba_map_ptr)
84  memcpy(rgba_map_ptr, rgba_map, sizeof(rgba_map[0]) * 4);
85  } else {
86  int plane;
87 
88  dst_color[0] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
89  dst_color[1] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
90  dst_color[2] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
91  dst_color[3] = rgba_color[3];
92 
93  for (plane = 0; plane < 4; plane++) {
94  int line_size;
95  int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
96 
97  pixel_step[plane] = 1;
98  line_size = FF_CEIL_RSHIFT(w, hsub1) * pixel_step[plane];
99  line[plane] = av_malloc(line_size);
100  if (!line[plane]) {
101  while(plane && line[plane-1])
102  av_freep(&line[--plane]);
103  return AVERROR(ENOMEM);
104  }
105  memset(line[plane], dst_color[plane], line_size);
106  }
107  }
108 
109  return 0;
110 }
111 
112 void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4],
113  uint8_t *src[4], int pixelstep[4],
114  int hsub, int vsub, int x, int y, int w, int h)
115 {
116  int i, plane;
117  uint8_t *p;
118 
119  for (plane = 0; plane < 4 && dst[plane]; plane++) {
120  int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
121  int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
122  int width = FF_CEIL_RSHIFT(w, hsub1);
123  int height = FF_CEIL_RSHIFT(h, vsub1);
124 
125  p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
126  for (i = 0; i < height; i++) {
127  memcpy(p + (x >> hsub1) * pixelstep[plane],
128  src[plane], width * pixelstep[plane]);
129  p += dst_linesize[plane];
130  }
131  }
132 }
133 
134 void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4],
135  uint8_t *src[4], int src_linesize[4], int pixelstep[4],
136  int hsub, int vsub, int x, int y, int y2, int w, int h)
137 {
138  int i, plane;
139  uint8_t *p;
140 
141  for (plane = 0; plane < 4 && dst[plane]; plane++) {
142  int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
143  int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
144  int width = FF_CEIL_RSHIFT(w, hsub1);
145  int height = FF_CEIL_RSHIFT(h, vsub1);
146 
147  p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
148  for (i = 0; i < height; i++) {
149  memcpy(p + (x >> hsub1) * pixelstep[plane],
150  src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), width * pixelstep[plane]);
151  p += dst_linesize[plane];
152  }
153  }
154 }
155 
156 int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
157 {
158  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
159  const AVComponentDescriptor *c;
160  unsigned i, nb_planes = 0;
161  int pixelstep[MAX_PLANES] = { 0 };
162 
163  if (!desc->name)
164  return AVERROR(EINVAL);
166  return AVERROR(ENOSYS);
167  for (i = 0; i < desc->nb_components; i++) {
168  c = &desc->comp[i];
169  /* for now, only 8-bits formats */
170  if (c->depth_minus1 != 8 - 1)
171  return AVERROR(ENOSYS);
172  if (c->plane >= MAX_PLANES)
173  return AVERROR(ENOSYS);
174  /* strange interleaving */
175  if (pixelstep[c->plane] != 0 &&
176  pixelstep[c->plane] != c->step_minus1 + 1)
177  return AVERROR(ENOSYS);
178  pixelstep[c->plane] = c->step_minus1 + 1;
179  if (pixelstep[c->plane] >= 8)
180  return AVERROR(ENOSYS);
181  nb_planes = FFMAX(nb_planes, c->plane + 1);
182  }
183  if ((desc->log2_chroma_w || desc->log2_chroma_h) && nb_planes < 3)
184  return AVERROR(ENOSYS); /* exclude NV12 and NV21 */
185  memset(draw, 0, sizeof(*draw));
186  draw->desc = desc;
187  draw->format = format;
188  draw->nb_planes = nb_planes;
189  memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));
190  draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;
191  draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;
192  for (i = 0; i < ((desc->nb_components - 1) | 1); i++)
193  draw->comp_mask[desc->comp[i].plane] |=
194  1 << (desc->comp[i].offset_plus1 - 1);
195  return 0;
196 }
197 
199 {
200  unsigned i;
201  uint8_t rgba_map[4];
202 
203  if (rgba != color->rgba)
204  memcpy(color->rgba, rgba, sizeof(color->rgba));
205  if ((draw->desc->flags & AV_PIX_FMT_FLAG_RGB) &&
206  ff_fill_rgba_map(rgba_map, draw->format) >= 0) {
207  if (draw->nb_planes == 1) {
208  for (i = 0; i < 4; i++)
209  color->comp[0].u8[rgba_map[i]] = rgba[i];
210  } else {
211  for (i = 0; i < 4; i++)
212  color->comp[rgba_map[i]].u8[0] = rgba[i];
213  }
214  } else if (draw->nb_planes == 3 || draw->nb_planes == 4) {
215  /* assume YUV */
216  color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
217  color->comp[1].u8[0] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
218  color->comp[2].u8[0] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
219  color->comp[3].u8[0] = rgba[3];
220  } else if (draw->format == AV_PIX_FMT_GRAY8 || draw->format == AV_PIX_FMT_GRAY8A) {
221  color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
222  color->comp[1].u8[0] = rgba[3];
223  } else {
225  "Color conversion not implemented for %s\n", draw->desc->name);
226  memset(color, 128, sizeof(*color));
227  }
228 }
229 
230 static uint8_t *pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[],
231  int plane, int x, int y)
232 {
233  return data[plane] +
234  (y >> draw->vsub[plane]) * linesize[plane] +
235  (x >> draw->hsub[plane]) * draw->pixelstep[plane];
236 }
237 
239  uint8_t *dst[], int dst_linesize[],
240  uint8_t *src[], int src_linesize[],
241  int dst_x, int dst_y, int src_x, int src_y,
242  int w, int h)
243 {
244  int plane, y, wp, hp;
245  uint8_t *p, *q;
246 
247  for (plane = 0; plane < draw->nb_planes; plane++) {
248  p = pointer_at(draw, src, src_linesize, plane, src_x, src_y);
249  q = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
250  wp = FF_CEIL_RSHIFT(w, draw->hsub[plane]) * draw->pixelstep[plane];
251  hp = FF_CEIL_RSHIFT(h, draw->vsub[plane]);
252  for (y = 0; y < hp; y++) {
253  memcpy(q, p, wp);
254  p += src_linesize[plane];
255  q += dst_linesize[plane];
256  }
257  }
258 }
259 
261  uint8_t *dst[], int dst_linesize[],
262  int dst_x, int dst_y, int w, int h)
263 {
264  int plane, x, y, wp, hp;
265  uint8_t *p0, *p;
266 
267  for (plane = 0; plane < draw->nb_planes; plane++) {
268  p0 = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
269  wp = FF_CEIL_RSHIFT(w, draw->hsub[plane]);
270  hp = FF_CEIL_RSHIFT(h, draw->vsub[plane]);
271  if (!hp)
272  return;
273  p = p0;
274  /* copy first line from color */
275  for (x = 0; x < wp; x++) {
276  memcpy(p, color->comp[plane].u8, draw->pixelstep[plane]);
277  p += draw->pixelstep[plane];
278  }
279  wp *= draw->pixelstep[plane];
280  /* copy next lines from first line */
281  p = p0 + dst_linesize[plane];
282  for (y = 1; y < hp; y++) {
283  memcpy(p, p0, wp);
284  p += dst_linesize[plane];
285  }
286  }
287 }
288 
289 /**
290  * Clip interval [x; x+w[ within [0; wmax[.
291  * The resulting w may be negative if the final interval is empty.
292  * dx, if not null, return the difference between in and out value of x.
293  */
294 static void clip_interval(int wmax, int *x, int *w, int *dx)
295 {
296  if (dx)
297  *dx = 0;
298  if (*x < 0) {
299  if (dx)
300  *dx = -*x;
301  *w += *x;
302  *x = 0;
303  }
304  if (*x + *w > wmax)
305  *w = wmax - *x;
306 }
307 
308 /**
309  * Decompose w pixels starting at x
310  * into start + (w starting at x) + end
311  * with x and w aligned on multiples of 1<<sub.
312  */
313 static void subsampling_bounds(int sub, int *x, int *w, int *start, int *end)
314 {
315  int mask = (1 << sub) - 1;
316 
317  *start = (-*x) & mask;
318  *x += *start;
319  *start = FFMIN(*start, *w);
320  *w -= *start;
321  *end = *w & mask;
322  *w >>= sub;
323 }
324 
325 static int component_used(FFDrawContext *draw, int plane, int comp)
326 {
327  return (draw->comp_mask[plane] >> comp) & 1;
328 }
329 
330 /* If alpha is in the [ 0 ; 0x1010101 ] range,
331  then alpha * value is in the [ 0 ; 0xFFFFFFFF ] range,
332  and >> 24 gives a correct rounding. */
333 static void blend_line(uint8_t *dst, unsigned src, unsigned alpha,
334  int dx, int w, unsigned hsub, int left, int right)
335 {
336  unsigned asrc = alpha * src;
337  unsigned tau = 0x1010101 - alpha;
338  int x;
339 
340  if (left) {
341  unsigned suba = (left * alpha) >> hsub;
342  *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
343  dst += dx;
344  }
345  for (x = 0; x < w; x++) {
346  *dst = (*dst * tau + asrc) >> 24;
347  dst += dx;
348  }
349  if (right) {
350  unsigned suba = (right * alpha) >> hsub;
351  *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
352  }
353 }
354 
356  uint8_t *dst[], int dst_linesize[],
357  int dst_w, int dst_h,
358  int x0, int y0, int w, int h)
359 {
360  unsigned alpha, nb_planes, nb_comp, plane, comp;
361  int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
362  uint8_t *p0, *p;
363 
364  /* TODO optimize if alpha = 0xFF */
365  clip_interval(dst_w, &x0, &w, NULL);
366  clip_interval(dst_h, &y0, &h, NULL);
367  if (w <= 0 || h <= 0 || !color->rgba[3])
368  return;
369  /* 0x10203 * alpha + 2 is in the [ 2 ; 0x1010101 - 2 ] range */
370  alpha = 0x10203 * color->rgba[3] + 0x2;
371  nb_planes = (draw->nb_planes - 1) | 1; /* eliminate alpha */
372  for (plane = 0; plane < nb_planes; plane++) {
373  nb_comp = draw->pixelstep[plane];
374  p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
375  w_sub = w;
376  h_sub = h;
377  x_sub = x0;
378  y_sub = y0;
379  subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
380  subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
381  for (comp = 0; comp < nb_comp; comp++) {
382  if (!component_used(draw, plane, comp))
383  continue;
384  p = p0 + comp;
385  if (top) {
386  blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
387  draw->pixelstep[plane], w_sub,
388  draw->hsub[plane], left, right);
389  p += dst_linesize[plane];
390  }
391  for (y = 0; y < h_sub; y++) {
392  blend_line(p, color->comp[plane].u8[comp], alpha,
393  draw->pixelstep[plane], w_sub,
394  draw->hsub[plane], left, right);
395  p += dst_linesize[plane];
396  }
397  if (bottom)
398  blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
399  draw->pixelstep[plane], w_sub,
400  draw->hsub[plane], left, right);
401  }
402  }
403 }
404 
405 static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha,
406  uint8_t *mask, int mask_linesize, int l2depth,
407  unsigned w, unsigned h, unsigned shift, unsigned xm0)
408 {
409  unsigned xm, x, y, t = 0;
410  unsigned xmshf = 3 - l2depth;
411  unsigned xmmod = 7 >> l2depth;
412  unsigned mbits = (1 << (1 << l2depth)) - 1;
413  unsigned mmult = 255 / mbits;
414 
415  for (y = 0; y < h; y++) {
416  xm = xm0;
417  for (x = 0; x < w; x++) {
418  t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
419  * mmult;
420  xm++;
421  }
422  mask += mask_linesize;
423  }
424  alpha = (t >> shift) * alpha;
425  *dst = ((0x1010101 - alpha) * *dst + alpha * src) >> 24;
426 }
427 
428 static void blend_line_hv(uint8_t *dst, int dst_delta,
429  unsigned src, unsigned alpha,
430  uint8_t *mask, int mask_linesize, int l2depth, int w,
431  unsigned hsub, unsigned vsub,
432  int xm, int left, int right, int hband)
433 {
434  int x;
435 
436  if (left) {
437  blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
438  left, hband, hsub + vsub, xm);
439  dst += dst_delta;
440  xm += left;
441  }
442  for (x = 0; x < w; x++) {
443  blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
444  1 << hsub, hband, hsub + vsub, xm);
445  dst += dst_delta;
446  xm += 1 << hsub;
447  }
448  if (right)
449  blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
450  right, hband, hsub + vsub, xm);
451 }
452 
454  uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
455  uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
456  int l2depth, unsigned endianness, int x0, int y0)
457 {
458  unsigned alpha, nb_planes, nb_comp, plane, comp;
459  int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
460  uint8_t *p0, *p, *m;
461 
462  clip_interval(dst_w, &x0, &mask_w, &xm0);
463  clip_interval(dst_h, &y0, &mask_h, &ym0);
464  mask += ym0 * mask_linesize;
465  if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
466  return;
467  /* alpha is in the [ 0 ; 0x10203 ] range,
468  alpha * mask is in the [ 0 ; 0x1010101 - 4 ] range */
469  alpha = (0x10307 * color->rgba[3] + 0x3) >> 8;
470  nb_planes = (draw->nb_planes - 1) | 1; /* eliminate alpha */
471  for (plane = 0; plane < nb_planes; plane++) {
472  nb_comp = draw->pixelstep[plane];
473  p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
474  w_sub = mask_w;
475  h_sub = mask_h;
476  x_sub = x0;
477  y_sub = y0;
478  subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
479  subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
480  for (comp = 0; comp < nb_comp; comp++) {
481  if (!component_used(draw, plane, comp))
482  continue;
483  p = p0 + comp;
484  m = mask;
485  if (top) {
486  blend_line_hv(p, draw->pixelstep[plane],
487  color->comp[plane].u8[comp], alpha,
488  m, mask_linesize, l2depth, w_sub,
489  draw->hsub[plane], draw->vsub[plane],
490  xm0, left, right, top);
491  p += dst_linesize[plane];
492  m += top * mask_linesize;
493  }
494  for (y = 0; y < h_sub; y++) {
495  blend_line_hv(p, draw->pixelstep[plane],
496  color->comp[plane].u8[comp], alpha,
497  m, mask_linesize, l2depth, w_sub,
498  draw->hsub[plane], draw->vsub[plane],
499  xm0, left, right, 1 << draw->vsub[plane]);
500  p += dst_linesize[plane];
501  m += mask_linesize << draw->vsub[plane];
502  }
503  if (bottom)
504  blend_line_hv(p, draw->pixelstep[plane],
505  color->comp[plane].u8[comp], alpha,
506  m, mask_linesize, l2depth, w_sub,
507  draw->hsub[plane], draw->vsub[plane],
508  xm0, left, right, bottom);
509  }
510  }
511 }
512 
513 int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
514  int value)
515 {
516  unsigned shift = sub_dir ? draw->vsub_max : draw->hsub_max;
517 
518  if (!shift)
519  return value;
520  if (round_dir >= 0)
521  value += round_dir ? (1 << shift) - 1 : 1 << (shift - 1);
522  return (value >> shift) << shift;
523 }
524 
526 {
527  enum AVPixelFormat i;
528  FFDrawContext draw;
529  AVFilterFormats *fmts = NULL;
530 
531  for (i = 0; av_pix_fmt_desc_get(i); i++)
532  if (ff_draw_init(&draw, i, flags) >= 0)
533  ff_add_format(&fmts, i);
534  return fmts;
535 }
536 
537 #ifdef TEST
538 
539 #undef printf
540 
541 int main(void)
542 {
543  enum AVPixelFormat f;
544  const AVPixFmtDescriptor *desc;
545  FFDrawContext draw;
547  int r, i;
548 
549  for (f = 0; av_pix_fmt_desc_get(f); f++) {
550  desc = av_pix_fmt_desc_get(f);
551  if (!desc->name)
552  continue;
553  printf("Testing %s...%*s", desc->name,
554  (int)(16 - strlen(desc->name)), "");
555  r = ff_draw_init(&draw, f, 0);
556  if (r < 0) {
557  char buf[128];
558  av_strerror(r, buf, sizeof(buf));
559  printf("no: %s\n", buf);
560  continue;
561  }
562  ff_draw_color(&draw, &color, (uint8_t[]) { 1, 0, 0, 1 });
563  for (i = 0; i < sizeof(color); i++)
564  if (((uint8_t *)&color)[i] != 128)
565  break;
566  if (i == sizeof(color)) {
567  printf("fallback color\n");
568  continue;
569  }
570  printf("ok\n");
571  }
572  return 0;
573 }
574 
575 #endif
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, 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:453
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:525
#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:2090
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:238
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:262
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:2042
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:176
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:261
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:333
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:266
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
static void clip_interval(int wmax, int *x, int *w, int *dx)
Clip interval [x; x+w[ within [0; wmax[.
Definition: drawutils.c:294
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:513
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:100
uint8_t
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:156
#define av_malloc(s)
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:265
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:67
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:259
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:70
uint16_t depth_minus1
Number of bits in the component minus 1.
Definition: pixdesc.h:57
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:98
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
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:131
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:198
Definition: graph2dot.c:48
uint8_t u8[4]
Definition: drawutils.h:65
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:323
uint8_t vsub_max
Definition: drawutils.h:57
#define FFMAX(a, b)
Definition: common.h:64
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:94
Definition: drawutils.c:31
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:149
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:95
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:146
#define FFMIN(a, b)
Definition: common.h:66
float y
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:141
#define MAX_PLANES
Definition: ffv1.h:50
union FFDrawColor::@122 comp[MAX_PLANES]
static void blend_line_hv(uint8_t *dst, int dst_delta, unsigned src, unsigned alpha, 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:428
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:66
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:148
static uint8_t * pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[], int plane, int x, int y)
Definition: drawutils.c:230
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
Definition: drawutils.c:33
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:313
AVS_Value src
Definition: avisynth_c.h:482
misc drawing utilities
unsigned nb_planes
Definition: drawutils.h:51
uint8_t flags
Definition: pixdesc.h:90
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
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:355
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:134
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
Definition: pixdesc.h:40
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
Definition: pixfmt.h:267
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
Definition: drawutils.c:156
static int component_used(FFDrawContext *draw, int plane, int comp)
Definition: drawutils.c:325
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
Definition: colorspace.h:91
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:68
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
Definition: colorspace.h:95
uint16_t plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:34
Y , 8bpp.
Definition: pixfmt.h:71
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:287
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
static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha, uint8_t *mask, int mask_linesize, int l2depth, unsigned w, unsigned h, unsigned shift, unsigned xm0)
Definition: drawutils.c:405
#define RGB_TO_Y_CCIR(r, g, b)
Definition: colorspace.h:87
Definition: drawutils.c:31
uint16_t offset_plus1
Number of elements before the component of the first pixel plus 1.
Definition: pixdesc.h:46
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:62
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:260
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:112
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:264
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:127
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:260
uint8_t rgba[4]
Definition: drawutils.h:61
static int width