2 * Copyright 2011 Stefano Sabatini <stefano.sabatini-lala poste it>
3 * Copyright 2012 Nicolas George <nicolas.george normalesup org>
5 * This file is part of FFmpeg.
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.
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.
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
24 #include "libavutil/avassert.h"
25 #include "libavutil/avutil.h"
26 #include "libavutil/colorspace.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/mem.h"
29 #include "libavutil/pixdesc.h"
30 #include "drawutils.h"
33 enum { RED = 0, GREEN, BLUE, ALPHA };
35 int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
39 case AV_PIX_FMT_ARGB: rgba_map[ALPHA] = 0; rgba_map[RED ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break;
41 case AV_PIX_FMT_ABGR: rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED ] = 3; break;
42 case AV_PIX_FMT_RGB48LE:
43 case AV_PIX_FMT_RGB48BE:
44 case AV_PIX_FMT_RGBA64BE:
45 case AV_PIX_FMT_RGBA64LE:
48 case AV_PIX_FMT_RGB24: rgba_map[RED ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break;
49 case AV_PIX_FMT_BGR48LE:
50 case AV_PIX_FMT_BGR48BE:
51 case AV_PIX_FMT_BGRA64BE:
52 case AV_PIX_FMT_BGRA64LE:
55 case AV_PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break;
56 case AV_PIX_FMT_GBRP9LE:
57 case AV_PIX_FMT_GBRP9BE:
58 case AV_PIX_FMT_GBRP10LE:
59 case AV_PIX_FMT_GBRP10BE:
60 case AV_PIX_FMT_GBRP12LE:
61 case AV_PIX_FMT_GBRP12BE:
62 case AV_PIX_FMT_GBRP14LE:
63 case AV_PIX_FMT_GBRP14BE:
64 case AV_PIX_FMT_GBRP16LE:
65 case AV_PIX_FMT_GBRP16BE:
66 case AV_PIX_FMT_GBRAP:
67 case AV_PIX_FMT_GBRAP10LE:
68 case AV_PIX_FMT_GBRAP10BE:
69 case AV_PIX_FMT_GBRAP12LE:
70 case AV_PIX_FMT_GBRAP12BE:
71 case AV_PIX_FMT_GBRAP16LE:
72 case AV_PIX_FMT_GBRAP16BE:
73 case AV_PIX_FMT_GBRPF32LE:
74 case AV_PIX_FMT_GBRPF32BE:
75 case AV_PIX_FMT_GBRAPF32LE:
76 case AV_PIX_FMT_GBRAPF32BE:
77 case AV_PIX_FMT_GBRP: rgba_map[GREEN] = 0; rgba_map[BLUE ] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break;
78 default: /* unsupported */
79 return AVERROR(EINVAL);
84 int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
86 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
87 const AVComponentDescriptor *c;
88 unsigned i, nb_planes = 0;
89 int pixelstep[MAX_PLANES] = { 0 };
92 if (!desc || !desc->name)
93 return AVERROR(EINVAL);
94 if (desc->flags & ~(AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_ALPHA))
95 return AVERROR(ENOSYS);
96 if (format == AV_PIX_FMT_P010LE || format == AV_PIX_FMT_P010BE || format == AV_PIX_FMT_P016LE || format == AV_PIX_FMT_P016BE)
97 return AVERROR(ENOSYS);
98 if (format == AV_PIX_FMT_YUVJ420P || format == AV_PIX_FMT_YUVJ422P || format == AV_PIX_FMT_YUVJ444P ||
99 format == AV_PIX_FMT_YUVJ411P || format == AV_PIX_FMT_YUVJ440P)
101 for (i = 0; i < desc->nb_components; i++) {
103 /* for now, only 8-16 bits formats */
104 if (c->depth < 8 || c->depth > 16)
105 return AVERROR(ENOSYS);
106 if (desc->flags & AV_PIX_FMT_FLAG_BE)
107 return AVERROR(ENOSYS);
108 if (c->plane >= MAX_PLANES)
109 return AVERROR(ENOSYS);
110 /* strange interleaving */
111 if (pixelstep[c->plane] != 0 &&
112 pixelstep[c->plane] != c->step)
113 return AVERROR(ENOSYS);
114 if (pixelstep[c->plane] == 6 &&
116 return AVERROR(ENOSYS);
117 pixelstep[c->plane] = c->step;
118 if (pixelstep[c->plane] >= 8)
119 return AVERROR(ENOSYS);
120 nb_planes = FFMAX(nb_planes, c->plane + 1);
122 memset(draw, 0, sizeof(*draw));
124 draw->format = format;
125 draw->nb_planes = nb_planes;
127 draw->full_range = full_range;
128 memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));
129 draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;
130 draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;
131 for (i = 0; i < (desc->nb_components - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA && !(flags & FF_DRAW_PROCESS_ALPHA))); i++)
132 draw->comp_mask[desc->comp[i].plane] |=
133 1 << desc->comp[i].offset;
137 void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
142 if (rgba != color->rgba)
143 memcpy(color->rgba, rgba, sizeof(color->rgba));
144 if ((draw->desc->flags & AV_PIX_FMT_FLAG_RGB) &&
145 ff_fill_rgba_map(rgba_map, draw->format) >= 0) {
146 if (draw->nb_planes == 1) {
147 for (i = 0; i < 4; i++) {
148 color->comp[0].u8[rgba_map[i]] = rgba[i];
149 if (draw->desc->comp[rgba_map[i]].depth > 8) {
150 color->comp[0].u16[rgba_map[i]] = color->comp[0].u8[rgba_map[i]] << 8;
154 for (i = 0; i < 4; i++) {
155 color->comp[rgba_map[i]].u8[0] = rgba[i];
156 if (draw->desc->comp[rgba_map[i]].depth > 8)
157 color->comp[rgba_map[i]].u16[0] = color->comp[rgba_map[i]].u8[0] << (draw->desc->comp[rgba_map[i]].depth - 8);
160 } else if (draw->nb_planes >= 2) {
162 const AVPixFmtDescriptor *desc = draw->desc;
163 color->comp[desc->comp[0].plane].u8[desc->comp[0].offset] = draw->full_range ? RGB_TO_Y_JPEG(rgba[0], rgba[1], rgba[2]) : RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
164 color->comp[desc->comp[1].plane].u8[desc->comp[1].offset] = draw->full_range ? RGB_TO_U_JPEG(rgba[0], rgba[1], rgba[2]) : RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
165 color->comp[desc->comp[2].plane].u8[desc->comp[2].offset] = draw->full_range ? RGB_TO_V_JPEG(rgba[0], rgba[1], rgba[2]) : RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
166 color->comp[3].u8[0] = rgba[3];
167 #define EXPAND(compn) \
168 if (desc->comp[compn].depth > 8) \
169 color->comp[desc->comp[compn].plane].u16[desc->comp[compn].offset] = \
170 color->comp[desc->comp[compn].plane].u8[desc->comp[compn].offset] << \
171 (draw->desc->comp[compn].depth + draw->desc->comp[compn].shift - 8)
176 } else if (draw->format == AV_PIX_FMT_GRAY8 || draw->format == AV_PIX_FMT_GRAY8A ||
177 draw->format == AV_PIX_FMT_GRAY16LE || draw->format == AV_PIX_FMT_YA16LE ||
178 draw->format == AV_PIX_FMT_GRAY9LE ||
179 draw->format == AV_PIX_FMT_GRAY10LE ||
180 draw->format == AV_PIX_FMT_GRAY12LE ||
181 draw->format == AV_PIX_FMT_GRAY14LE) {
182 const AVPixFmtDescriptor *desc = draw->desc;
183 color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
185 color->comp[1].u8[0] = rgba[3];
188 av_log(NULL, AV_LOG_WARNING,
189 "Color conversion not implemented for %s\n", draw->desc->name);
190 memset(color, 128, sizeof(*color));
194 static uint8_t *pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[],
195 int plane, int x, int y)
198 (y >> draw->vsub[plane]) * linesize[plane] +
199 (x >> draw->hsub[plane]) * draw->pixelstep[plane];
202 void ff_copy_rectangle2(FFDrawContext *draw,
203 uint8_t *dst[], int dst_linesize[],
204 uint8_t *src[], int src_linesize[],
205 int dst_x, int dst_y, int src_x, int src_y,
208 int plane, y, wp, hp;
211 for (plane = 0; plane < draw->nb_planes; plane++) {
212 p = pointer_at(draw, src, src_linesize, plane, src_x, src_y);
213 q = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
214 wp = AV_CEIL_RSHIFT(w, draw->hsub[plane]) * draw->pixelstep[plane];
215 hp = AV_CEIL_RSHIFT(h, draw->vsub[plane]);
216 for (y = 0; y < hp; y++) {
218 p += src_linesize[plane];
219 q += dst_linesize[plane];
224 void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color,
225 uint8_t *dst[], int dst_linesize[],
226 int dst_x, int dst_y, int w, int h)
228 int plane, x, y, wp, hp;
230 FFDrawColor color_tmp = *color;
232 for (plane = 0; plane < draw->nb_planes; plane++) {
233 p0 = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
234 wp = AV_CEIL_RSHIFT(w, draw->hsub[plane]);
235 hp = AV_CEIL_RSHIFT(h, draw->vsub[plane]);
240 if (HAVE_BIGENDIAN && draw->desc->comp[0].depth > 8) {
241 for (x = 0; 2*x < draw->pixelstep[plane]; x++)
242 color_tmp.comp[plane].u16[x] = av_bswap16(color_tmp.comp[plane].u16[x]);
245 /* copy first line from color */
246 for (x = 0; x < wp; x++) {
247 memcpy(p, color_tmp.comp[plane].u8, draw->pixelstep[plane]);
248 p += draw->pixelstep[plane];
250 wp *= draw->pixelstep[plane];
251 /* copy next lines from first line */
252 p = p0 + dst_linesize[plane];
253 for (y = 1; y < hp; y++) {
255 p += dst_linesize[plane];
261 * Clip interval [x; x+w[ within [0; wmax[.
262 * The resulting w may be negative if the final interval is empty.
263 * dx, if not null, return the difference between in and out value of x.
265 static void clip_interval(int wmax, int *x, int *w, int *dx)
280 * Decompose w pixels starting at x
281 * into start + (w starting at x) + end
282 * with x and w aligned on multiples of 1<<sub.
284 static void subsampling_bounds(int sub, int *x, int *w, int *start, int *end)
286 int mask = (1 << sub) - 1;
288 *start = (-*x) & mask;
290 *start = FFMIN(*start, *w);
296 static int component_used(FFDrawContext *draw, int plane, int comp)
298 return (draw->comp_mask[plane] >> comp) & 1;
301 /* If alpha is in the [ 0 ; 0x1010101 ] range,
302 then alpha * value is in the [ 0 ; 0xFFFFFFFF ] range,
303 and >> 24 gives a correct rounding. */
304 static void blend_line(uint8_t *dst, unsigned src, unsigned alpha,
305 int dx, int w, unsigned hsub, int left, int right)
307 unsigned asrc = alpha * src;
308 unsigned tau = 0x1010101 - alpha;
312 unsigned suba = (left * alpha) >> hsub;
313 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
316 for (x = 0; x < w; x++) {
317 *dst = (*dst * tau + asrc) >> 24;
321 unsigned suba = (right * alpha) >> hsub;
322 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
326 static void blend_line16(uint8_t *dst, unsigned src, unsigned alpha,
327 int dx, int w, unsigned hsub, int left, int right)
329 unsigned asrc = alpha * src;
330 unsigned tau = 0x10001 - alpha;
334 unsigned suba = (left * alpha) >> hsub;
335 uint16_t value = AV_RL16(dst);
336 AV_WL16(dst, (value * (0x10001 - suba) + src * suba) >> 16);
339 for (x = 0; x < w; x++) {
340 uint16_t value = AV_RL16(dst);
341 AV_WL16(dst, (value * tau + asrc) >> 16);
345 unsigned suba = (right * alpha) >> hsub;
346 uint16_t value = AV_RL16(dst);
347 AV_WL16(dst, (value * (0x10001 - suba) + src * suba) >> 16);
351 void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color,
352 uint8_t *dst[], int dst_linesize[],
353 int dst_w, int dst_h,
354 int x0, int y0, int w, int h)
356 unsigned alpha, nb_planes, nb_comp, plane, comp;
357 int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
360 /* TODO optimize if alpha = 0xFF */
361 clip_interval(dst_w, &x0, &w, NULL);
362 clip_interval(dst_h, &y0, &h, NULL);
363 if (w <= 0 || h <= 0 || !color->rgba[3])
365 if (draw->desc->comp[0].depth <= 8) {
366 /* 0x10203 * alpha + 2 is in the [ 2 ; 0x1010101 - 2 ] range */
367 alpha = 0x10203 * color->rgba[3] + 0x2;
369 /* 0x101 * alpha is in the [ 2 ; 0x1001] range */
370 alpha = 0x101 * color->rgba[3] + 0x2;
372 nb_planes = draw->nb_planes - !!(draw->desc->flags & AV_PIX_FMT_FLAG_ALPHA && !(draw->flags & FF_DRAW_PROCESS_ALPHA));
373 nb_planes += !nb_planes;
374 for (plane = 0; plane < nb_planes; plane++) {
375 nb_comp = draw->pixelstep[plane];
376 p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
381 subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
382 subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
383 for (comp = 0; comp < nb_comp; comp++) {
384 const int depth = draw->desc->comp[comp].depth;
386 if (!component_used(draw, plane, comp))
391 blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
392 draw->pixelstep[plane], w_sub,
393 draw->hsub[plane], left, right);
395 blend_line16(p, color->comp[plane].u16[comp], alpha >> 1,
396 draw->pixelstep[plane], w_sub,
397 draw->hsub[plane], left, right);
399 p += dst_linesize[plane];
402 for (y = 0; y < h_sub; y++) {
403 blend_line(p, color->comp[plane].u8[comp], alpha,
404 draw->pixelstep[plane], w_sub,
405 draw->hsub[plane], left, right);
406 p += dst_linesize[plane];
409 for (y = 0; y < h_sub; y++) {
410 blend_line16(p, color->comp[plane].u16[comp], alpha,
411 draw->pixelstep[plane], w_sub,
412 draw->hsub[plane], left, right);
413 p += dst_linesize[plane];
418 blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
419 draw->pixelstep[plane], w_sub,
420 draw->hsub[plane], left, right);
422 blend_line16(p, color->comp[plane].u16[comp], alpha >> 1,
423 draw->pixelstep[plane], w_sub,
424 draw->hsub[plane], left, right);
431 static void blend_pixel16(uint8_t *dst, unsigned src, unsigned alpha,
432 const uint8_t *mask, int mask_linesize, int l2depth,
433 unsigned w, unsigned h, unsigned shift, unsigned xm0)
435 unsigned xm, x, y, t = 0;
436 unsigned xmshf = 3 - l2depth;
437 unsigned xmmod = 7 >> l2depth;
438 unsigned mbits = (1 << (1 << l2depth)) - 1;
439 unsigned mmult = 255 / mbits;
440 uint16_t value = AV_RL16(dst);
442 for (y = 0; y < h; y++) {
444 for (x = 0; x < w; x++) {
445 t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
449 mask += mask_linesize;
451 alpha = (t >> shift) * alpha;
452 AV_WL16(dst, ((0x10001 - alpha) * value + alpha * src) >> 16);
455 static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha,
456 const uint8_t *mask, int mask_linesize, int l2depth,
457 unsigned w, unsigned h, unsigned shift, unsigned xm0)
459 unsigned xm, x, y, t = 0;
460 unsigned xmshf = 3 - l2depth;
461 unsigned xmmod = 7 >> l2depth;
462 unsigned mbits = (1 << (1 << l2depth)) - 1;
463 unsigned mmult = 255 / mbits;
465 for (y = 0; y < h; y++) {
467 for (x = 0; x < w; x++) {
468 t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
472 mask += mask_linesize;
474 alpha = (t >> shift) * alpha;
475 *dst = ((0x1010101 - alpha) * *dst + alpha * src) >> 24;
478 static void blend_line_hv16(uint8_t *dst, int dst_delta,
479 unsigned src, unsigned alpha,
480 const uint8_t *mask, int mask_linesize, int l2depth, int w,
481 unsigned hsub, unsigned vsub,
482 int xm, int left, int right, int hband)
487 blend_pixel16(dst, src, alpha, mask, mask_linesize, l2depth,
488 left, hband, hsub + vsub, xm);
492 for (x = 0; x < w; x++) {
493 blend_pixel16(dst, src, alpha, mask, mask_linesize, l2depth,
494 1 << hsub, hband, hsub + vsub, xm);
499 blend_pixel16(dst, src, alpha, mask, mask_linesize, l2depth,
500 right, hband, hsub + vsub, xm);
503 static void blend_line_hv(uint8_t *dst, int dst_delta,
504 unsigned src, unsigned alpha,
505 const uint8_t *mask, int mask_linesize, int l2depth, int w,
506 unsigned hsub, unsigned vsub,
507 int xm, int left, int right, int hband)
512 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
513 left, hband, hsub + vsub, xm);
517 for (x = 0; x < w; x++) {
518 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
519 1 << hsub, hband, hsub + vsub, xm);
524 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
525 right, hband, hsub + vsub, xm);
528 void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,
529 uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
530 const uint8_t *mask, int mask_linesize, int mask_w, int mask_h,
531 int l2depth, unsigned endianness, int x0, int y0)
533 unsigned alpha, nb_planes, nb_comp, plane, comp;
534 int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
538 clip_interval(dst_w, &x0, &mask_w, &xm0);
539 clip_interval(dst_h, &y0, &mask_h, &ym0);
540 mask += ym0 * mask_linesize;
541 if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
543 if (draw->desc->comp[0].depth <= 8) {
544 /* alpha is in the [ 0 ; 0x10203 ] range,
545 alpha * mask is in the [ 0 ; 0x1010101 - 4 ] range */
546 alpha = (0x10307 * color->rgba[3] + 0x3) >> 8;
548 alpha = (0x101 * color->rgba[3] + 0x2) >> 8;
550 nb_planes = draw->nb_planes - !!(draw->desc->flags & AV_PIX_FMT_FLAG_ALPHA && !(draw->flags & FF_DRAW_PROCESS_ALPHA));
551 nb_planes += !nb_planes;
552 for (plane = 0; plane < nb_planes; plane++) {
553 nb_comp = draw->pixelstep[plane];
554 p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
559 subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
560 subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
561 for (comp = 0; comp < nb_comp; comp++) {
562 const int depth = draw->desc->comp[comp].depth;
564 if (!component_used(draw, plane, comp))
570 blend_line_hv(p, draw->pixelstep[plane],
571 color->comp[plane].u8[comp], alpha,
572 m, mask_linesize, l2depth, w_sub,
573 draw->hsub[plane], draw->vsub[plane],
574 xm0, left, right, top);
576 blend_line_hv16(p, draw->pixelstep[plane],
577 color->comp[plane].u16[comp], alpha,
578 m, mask_linesize, l2depth, w_sub,
579 draw->hsub[plane], draw->vsub[plane],
580 xm0, left, right, top);
582 p += dst_linesize[plane];
583 m += top * mask_linesize;
586 for (y = 0; y < h_sub; y++) {
587 blend_line_hv(p, draw->pixelstep[plane],
588 color->comp[plane].u8[comp], alpha,
589 m, mask_linesize, l2depth, w_sub,
590 draw->hsub[plane], draw->vsub[plane],
591 xm0, left, right, 1 << draw->vsub[plane]);
592 p += dst_linesize[plane];
593 m += mask_linesize << draw->vsub[plane];
596 for (y = 0; y < h_sub; y++) {
597 blend_line_hv16(p, draw->pixelstep[plane],
598 color->comp[plane].u16[comp], alpha,
599 m, mask_linesize, l2depth, w_sub,
600 draw->hsub[plane], draw->vsub[plane],
601 xm0, left, right, 1 << draw->vsub[plane]);
602 p += dst_linesize[plane];
603 m += mask_linesize << draw->vsub[plane];
608 blend_line_hv(p, draw->pixelstep[plane],
609 color->comp[plane].u8[comp], alpha,
610 m, mask_linesize, l2depth, w_sub,
611 draw->hsub[plane], draw->vsub[plane],
612 xm0, left, right, bottom);
614 blend_line_hv16(p, draw->pixelstep[plane],
615 color->comp[plane].u16[comp], alpha,
616 m, mask_linesize, l2depth, w_sub,
617 draw->hsub[plane], draw->vsub[plane],
618 xm0, left, right, bottom);
625 int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
628 unsigned shift = sub_dir ? draw->vsub_max : draw->hsub_max;
633 value += round_dir ? (1 << shift) - 1 : 1 << (shift - 1);
634 return (value >> shift) << shift;
637 AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags)
639 enum AVPixelFormat i;
641 AVFilterFormats *fmts = NULL;
644 for (i = 0; av_pix_fmt_desc_get(i); i++)
645 if (ff_draw_init(&draw, i, flags) >= 0 &&
646 (ret = ff_add_format(&fmts, i)) < 0)