51 for (
unsigned i = 0;
i <
desc->nb_components;
i++) {
53 unsigned db = (
desc->comp[
i].depth + 7) / 8;
54 unsigned pos =
desc->comp[
i].offset / db;
55 if (depthb && (depthb != db))
58 if (
desc->comp[
i].offset % db)
66 if (
desc->nb_components == 3)
102 unsigned nb_planes = 0;
123 for (
unsigned i = 0;
i <
desc->nb_components;
i++) {
127 if (
c->depth < 8 ||
c->depth > 16)
132 if (
c->shift && ((
c->shift +
c->depth) & 0x7))
135 db = (
c->depth + 7) / 8;
136 if (depthb && (depthb != db))
139 if (db * (
c->offset + 1) > 16)
144 if (pixelstep[
c->plane] != 0 &&
145 pixelstep[
c->plane] !=
c->step)
147 pixelstep[
c->plane] =
c->step;
148 if (pixelstep[
c->plane] >= 8)
150 nb_planes =
FFMAX(nb_planes,
c->plane + 1);
155 draw->nb_planes = nb_planes;
162 memcpy(
draw->pixelstep, pixelstep,
sizeof(
draw->pixelstep));
185 if (rgba !=
color->rgba)
186 memcpy(
color->rgba, rgba,
sizeof(
color->rgba));
190 for (
int i = 0;
i < 4;
i++)
191 rgbad[
i] =
color->rgba[
i] / 255.;
194 for (
int i = 0;
i < 3;
i++)
195 rgbad[
i] *= rgbad[3];
199 memcpy(yuvad, rgbad,
sizeof(
double) * 3);
205 for (
int i = 0;
i < 3;
i++) {
208 yuvad[
i] *= (
chroma ? 224. : 219.) / 255.;
209 yuvad[
i] += (
chroma ? 128. : 16.) / 255.;
216 if (
desc->nb_components <= 2)
219 for (
unsigned i = 0;
i <
desc->nb_components;
i++) {
220 unsigned val = yuvad[
i] * ((1 << (
draw->desc->comp[
i].depth +
draw->desc->comp[
i].shift)) - 1) + 0.5;
221 if (
desc->comp[
i].depth > 8)
229 int plane,
int x,
int y)
232 (y >>
draw->vsub[plane]) * linesize[plane] +
233 (x >>
draw->hsub[plane]) *
draw->pixelstep[plane];
237 uint8_t *
dst[],
int dst_linesize[],
238 uint8_t *
src[],
int src_linesize[],
239 int dst_x,
int dst_y,
int src_x,
int src_y,
245 for (
int plane = 0; plane <
draw->nb_planes; plane++) {
250 for (
int y = 0; y < hp; y++) {
252 p += src_linesize[plane];
253 q += dst_linesize[plane];
259 uint8_t *
dst[],
int dst_linesize[],
260 int dst_x,
int dst_y,
int w,
int h)
266 for (
int plane = 0; plane <
draw->nb_planes; plane++) {
274 if (HAVE_BIGENDIAN &&
draw->desc->comp[0].depth > 8) {
275 for (
int x = 0; 2*x <
draw->pixelstep[plane]; x++)
280 for (
int x = 0; x < wp; x++) {
281 memcpy(p, color_tmp.
comp[plane].
u8,
draw->pixelstep[plane]);
282 p +=
draw->pixelstep[plane];
284 wp *=
draw->pixelstep[plane];
286 p = p0 + dst_linesize[plane];
287 for (
int y = 1; y < hp; y++) {
289 p += dst_linesize[plane];
320 int mask = (1 << sub) - 1;
322 *start = (-*x) &
mask;
324 *start =
FFMIN(*start, *
w);
334 int dx,
int w,
unsigned hsub,
int left,
int right)
337 unsigned tau = 0x1010101 -
alpha;
341 *
dst = (*
dst * (0x1010101 - suba) +
src * suba) >> 24;
344 for (
int x = 0; x <
w; x++) {
345 *
dst = (*
dst * tau + asrc) >> 24;
350 *
dst = (*
dst * (0x1010101 - suba) +
src * suba) >> 24;
355 int dx,
int w,
unsigned hsub,
int left,
int right)
358 unsigned tau = 0x10001 -
alpha;
366 for (
int x = 0; x <
w; x++) {
379 uint8_t *
dst[],
int dst_linesize[],
380 int dst_w,
int dst_h,
381 int x0,
int y0,
int w,
int h)
383 unsigned alpha, nb_planes, nb_comp;
384 int w_sub, h_sub, x_sub, y_sub,
left, right, top, bottom;
387 nb_comp =
draw->desc->nb_components -
395 if (
draw->desc->comp[0].depth <= 8) {
403 nb_planes += !nb_planes;
404 for (
unsigned plane = 0; plane < nb_planes; plane++) {
413 const int depth =
draw->desc->comp[
comp].depth;
417 if (
draw->desc->comp[
comp].plane != plane)
423 draw->pixelstep[plane], w_sub,
427 draw->pixelstep[plane], w_sub,
430 p += dst_linesize[plane];
433 for (
int y = 0; y < h_sub; y++) {
435 draw->pixelstep[plane], w_sub,
437 p += dst_linesize[plane];
440 for (
int y = 0; y < h_sub; y++) {
442 draw->pixelstep[plane], w_sub,
444 p += dst_linesize[plane];
450 draw->pixelstep[plane], w_sub,
454 draw->pixelstep[plane], w_sub,
463 const uint8_t *
mask,
int mask_linesize,
int l2depth,
464 unsigned w,
unsigned h,
unsigned shift,
unsigned xm0)
467 unsigned xmshf = 3 - l2depth;
468 unsigned xmmod = 7 >> l2depth;
469 unsigned mbits = (1 << (1 << l2depth)) - 1;
470 unsigned mmult = 255 / mbits;
473 for (
unsigned y = 0; y <
h; y++) {
475 for (
unsigned x = 0; x <
w; x++) {
476 t += ((
mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
480 mask += mask_linesize;
487 const uint8_t *
mask,
int mask_linesize,
int l2depth,
488 unsigned w,
unsigned h,
unsigned shift,
unsigned xm0)
491 unsigned xmshf = 3 - l2depth;
492 unsigned xmmod = 7 >> l2depth;
493 unsigned mbits = (1 << (1 << l2depth)) - 1;
494 unsigned mmult = 255 / mbits;
496 for (
unsigned y = 0; y <
h; y++) {
498 for (
unsigned x = 0; x <
w; x++) {
499 t += ((
mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
503 mask += mask_linesize;
511 const uint8_t *
mask,
int mask_linesize,
int l2depth,
int w,
512 unsigned hsub,
unsigned vsub,
513 int xm,
int left,
int right,
int hband)
522 for (
int x = 0; x <
w; x++) {
530 right, hband,
hsub + vsub, xm);
535 const uint8_t *
mask,
int mask_linesize,
int l2depth,
int w,
536 unsigned hsub,
unsigned vsub,
537 int xm,
int left,
int right,
int hband)
546 for (
int x = 0; x <
w; x++) {
554 right, hband,
hsub + vsub, xm);
558 uint8_t *
dst[],
int dst_linesize[],
int dst_w,
int dst_h,
559 const uint8_t *
mask,
int mask_linesize,
int mask_w,
int mask_h,
560 int l2depth,
unsigned endianness,
int x0,
int y0)
562 unsigned alpha, nb_planes, nb_comp;
563 int xm0, ym0, w_sub, h_sub, x_sub, y_sub,
left, right, top, bottom;
567 nb_comp =
draw->desc->nb_components -
572 mask += ym0 * mask_linesize;
573 if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
575 if (
draw->desc->comp[0].depth <= 8) {
578 alpha = (0x10307 *
color->rgba[3] + 0x3) >> 8;
583 nb_planes += !nb_planes;
584 for (
unsigned plane = 0; plane < nb_planes; plane++) {
593 const int depth =
draw->desc->comp[
comp].depth;
597 if (
draw->desc->comp[
comp].plane != plane)
605 m, mask_linesize, l2depth, w_sub,
606 draw->hsub[plane],
draw->vsub[plane],
607 xm0,
left, right, top);
611 m, mask_linesize, l2depth, w_sub,
612 draw->hsub[plane],
draw->vsub[plane],
613 xm0,
left, right, top);
615 p += dst_linesize[plane];
616 m += top * mask_linesize;
619 for (
int y = 0; y < h_sub; y++) {
622 m, mask_linesize, l2depth, w_sub,
623 draw->hsub[plane],
draw->vsub[plane],
624 xm0,
left, right, 1 <<
draw->vsub[plane]);
625 p += dst_linesize[plane];
626 m += mask_linesize <<
draw->vsub[plane];
629 for (
int y = 0; y < h_sub; y++) {
632 m, mask_linesize, l2depth, w_sub,
633 draw->hsub[plane],
draw->vsub[plane],
634 xm0,
left, right, 1 <<
draw->vsub[plane]);
635 p += dst_linesize[plane];
636 m += mask_linesize <<
draw->vsub[plane];
643 m, mask_linesize, l2depth, w_sub,
644 draw->hsub[plane],
draw->vsub[plane],
645 xm0,
left, right, bottom);
649 m, mask_linesize, l2depth, w_sub,
650 draw->hsub[plane],
draw->vsub[plane],
651 xm0,
left, right, bottom);
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Convenience header that includes libavutil's core.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
#define AV_CEIL_RSHIFT(a, b)
Colorspace value utility functions for libavutil.
static enum AVPixelFormat pix_fmt
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.
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)
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.
int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt)
static uint8_t * pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[], int plane, int x, int y)
int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir, int value)
Round a dimension according to subsampling.
static void clip_interval(int wmax, int *x, int *w, int *dx)
Clip interval [x; x+w[ within [0; wmax[.
static void blend_line16(uint8_t *dst, unsigned src, unsigned alpha, int dx, int w, unsigned hsub, int left, int right)
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
static void blend_pixel16(uint8_t *dst, unsigned src, unsigned alpha, const uint8_t *mask, int mask_linesize, int l2depth, unsigned w, unsigned h, unsigned shift, unsigned xm0)
int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, enum AVColorRange range, enum AVAlphaMode alpha, unsigned flags)
Init a draw context.
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
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)
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...
static void blend_line_hv16(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)
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
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.
static void blend_line(uint8_t *dst, unsigned src, unsigned alpha, int dx, int w, unsigned hsub, int left, int right)
static int fill_map(const AVPixFmtDescriptor *desc, uint8_t *map)
int ff_draw_init_from_link(FFDrawContext *draw, const AVFilterLink *link, unsigned flags)
Init a draw context, taking the format, colorspace and range from the given filter link.
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.
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
const struct AVLumaCoefficients * av_csp_luma_coeffs_from_avcsp(enum AVColorSpace csp)
Retrieves the Luma coefficients necessary to construct a conversion matrix from an enum constant desc...
const VDPAUPixFmtMap * map
static const int16_t alpha[]
static int shift(int a, int b)
void ff_matrix_mul_3x3_vec(double dst[3], const double vec[3], const double mat[3][3])
void ff_fill_rgb2yuv_table(const AVLumaCoefficients *coeffs, double rgb2yuv[3][3])
static const uint16_t mask[17]
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
#define AV_PIX_FMT_FLAG_XYZ
The pixel format contains XYZ-like data (as opposed to YUV/RGB/grayscale).
#define AV_PIX_FMT_FLAG_BAYER
The pixel format is following a Bayer pattern.
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
AVAlphaMode
Correlation between the alpha channel and color values.
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
@ AVALPHA_MODE_PREMULTIPLIED
Alpha channel is multiplied into color values.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
A link between two filters.
enum AVColorSpace colorspace
For non-YUV links, these are respectively set to fallback values (as appropriate for that colorspace)...
enum AVAlphaMode alpha_mode
alpha mode (for videos with an alpha channel)
int format
agreed upon media format
enum AVColorRange color_range
agreed upon YUV color range
Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar calculations.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
union FFDrawColor::@125210232202265035037051142373134026157344251103 comp[MAX_PLANES]