88 unsigned i, nb_planes = 0;
102 for (
i = 0;
i <
desc->nb_components;
i++) {
106 if (
c->depth < 8 ||
c->depth > 16)
113 db = (
c->depth + 7) / 8;
114 if (depthb && (depthb != db))
118 if (pixelstep[
c->plane] != 0 &&
119 pixelstep[
c->plane] !=
c->step)
121 if (pixelstep[
c->plane] == 6 &&
124 pixelstep[
c->plane] =
c->step;
125 if (pixelstep[
c->plane] >= 8)
127 nb_planes =
FFMAX(nb_planes,
c->plane + 1);
129 memset(draw, 0,
sizeof(*draw));
140 1 <<
desc->comp[
i].offset;
149 if (rgba !=
color->rgba)
150 memcpy(
color->rgba, rgba,
sizeof(
color->rgba));
154 for (
i = 0;
i < 4;
i++) {
155 color->comp[0].u8[rgba_map[
i]] = rgba[
i];
157 color->comp[0].u16[rgba_map[
i]] =
color->comp[0].u8[rgba_map[
i]] << 8;
161 for (
i = 0;
i < 4;
i++) {
162 color->comp[rgba_map[
i]].u8[0] = rgba[
i];
173 color->comp[3].u8[0] = rgba[3];
174 #define EXPAND(compn) \
175 if (desc->comp[compn].depth > 8) \
176 color->comp[desc->comp[compn].plane].u16[desc->comp[compn].offset] = \
177 color->comp[desc->comp[compn].plane].u8[desc->comp[compn].offset] << \
178 (draw->desc->comp[compn].depth + draw->desc->comp[compn].shift - 8)
192 color->comp[1].u8[0] = rgba[3];
196 "Color conversion not implemented for %s\n", draw->
desc->
name);
202 int plane,
int x,
int y)
205 (y >> draw->
vsub[plane]) * linesize[plane] +
210 uint8_t *dst[],
int dst_linesize[],
212 int dst_x,
int dst_y,
int src_x,
int src_y,
215 int plane, y, wp, hp;
218 for (plane = 0; plane < draw->
nb_planes; plane++) {
219 p =
pointer_at(draw,
src, src_linesize, plane, src_x, src_y);
220 q =
pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
223 for (y = 0; y < hp; y++) {
225 p += src_linesize[plane];
226 q += dst_linesize[plane];
232 uint8_t *dst[],
int dst_linesize[],
233 int dst_x,
int dst_y,
int w,
int h)
235 int plane, x, y, wp, hp;
239 for (plane = 0; plane < draw->
nb_planes; plane++) {
240 p0 =
pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
248 for (x = 0; 2*x < draw->
pixelstep[plane]; x++)
253 for (x = 0; x < wp; x++) {
259 p = p0 + dst_linesize[plane];
260 for (y = 1; y < hp; y++) {
262 p += dst_linesize[plane];
295 *start = (-*x) &
mask;
297 *start =
FFMIN(*start, *
w);
312 int dx,
int w,
unsigned hsub,
int left,
int right)
315 unsigned tau = 0x1010101 -
alpha;
320 *dst = (*dst * (0x1010101 - suba) +
src * suba) >> 24;
323 for (x = 0; x <
w; x++) {
324 *dst = (*dst * tau + asrc) >> 24;
329 *dst = (*dst * (0x1010101 - suba) +
src * suba) >> 24;
334 int dx,
int w,
unsigned hsub,
int left,
int right)
337 unsigned tau = 0x10001 -
alpha;
346 for (x = 0; x <
w; x++) {
359 uint8_t *dst[],
int dst_linesize[],
360 int dst_w,
int dst_h,
361 int x0,
int y0,
int w,
int h)
363 unsigned alpha, nb_planes, nb_comp, plane,
comp;
364 int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
370 if (
w <= 0 || h <= 0 || !color->rgba[3])
380 nb_planes += !nb_planes;
381 for (plane = 0; plane < nb_planes; plane++) {
383 p0 =
pointer_at(draw, dst, dst_linesize, plane, x0, y0);
400 draw->
hsub[plane], left, right);
404 draw->
hsub[plane], left, right);
406 p += dst_linesize[plane];
409 for (y = 0; y < h_sub; y++) {
412 draw->
hsub[plane], left, right);
413 p += dst_linesize[plane];
416 for (y = 0; y < h_sub; y++) {
419 draw->
hsub[plane], left, right);
420 p += dst_linesize[plane];
427 draw->
hsub[plane], left, right);
431 draw->
hsub[plane], left, right);
439 const uint8_t *
mask,
int mask_linesize,
int l2depth,
440 unsigned w,
unsigned h,
unsigned shift,
unsigned xm0)
442 unsigned xm, x, y, t = 0;
443 unsigned xmshf = 3 - l2depth;
444 unsigned xmmod = 7 >> l2depth;
445 unsigned mbits = (1 << (1 << l2depth)) - 1;
446 unsigned mmult = 255 / mbits;
449 for (y = 0; y <
h; y++) {
451 for (x = 0; x <
w; x++) {
452 t += ((
mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
456 mask += mask_linesize;
463 const uint8_t *
mask,
int mask_linesize,
int l2depth,
464 unsigned w,
unsigned h,
unsigned shift,
unsigned xm0)
466 unsigned xm, x, y, t = 0;
467 unsigned xmshf = 3 - l2depth;
468 unsigned xmmod = 7 >> l2depth;
469 unsigned mbits = (1 << (1 << l2depth)) - 1;
470 unsigned mmult = 255 / mbits;
472 for (y = 0; y <
h; y++) {
474 for (x = 0; x <
w; x++) {
475 t += ((
mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
479 mask += mask_linesize;
487 const uint8_t *
mask,
int mask_linesize,
int l2depth,
int w,
488 unsigned hsub,
unsigned vsub,
489 int xm,
int left,
int right,
int hband)
495 left, hband,
hsub + vsub, xm);
499 for (x = 0; x <
w; x++) {
507 right, hband,
hsub + vsub, xm);
512 const uint8_t *
mask,
int mask_linesize,
int l2depth,
int w,
513 unsigned hsub,
unsigned vsub,
514 int xm,
int left,
int right,
int hband)
520 left, hband,
hsub + vsub, xm);
524 for (x = 0; x <
w; x++) {
532 right, hband,
hsub + vsub, xm);
536 uint8_t *dst[],
int dst_linesize[],
int dst_w,
int dst_h,
537 const uint8_t *
mask,
int mask_linesize,
int mask_w,
int mask_h,
538 int l2depth,
unsigned endianness,
int x0,
int y0)
540 unsigned alpha, nb_planes, nb_comp, plane,
comp;
541 int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
547 mask += ym0 * mask_linesize;
548 if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
553 alpha = (0x10307 *
color->rgba[3] + 0x3) >> 8;
558 nb_planes += !nb_planes;
559 for (plane = 0; plane < nb_planes; plane++) {
561 p0 =
pointer_at(draw, dst, dst_linesize, plane, x0, y0);
579 m, mask_linesize, l2depth, w_sub,
580 draw->
hsub[plane], draw->
vsub[plane],
581 xm0, left, right, top);
585 m, mask_linesize, l2depth, w_sub,
586 draw->
hsub[plane], draw->
vsub[plane],
587 xm0, left, right, top);
589 p += dst_linesize[plane];
590 m += top * mask_linesize;
593 for (y = 0; y < h_sub; y++) {
596 m, mask_linesize, l2depth, w_sub,
597 draw->
hsub[plane], draw->
vsub[plane],
598 xm0, left, right, 1 << draw->
vsub[plane]);
599 p += dst_linesize[plane];
600 m += mask_linesize << draw->
vsub[plane];
603 for (y = 0; y < h_sub; y++) {
606 m, mask_linesize, l2depth, w_sub,
607 draw->
hsub[plane], draw->
vsub[plane],
608 xm0, left, right, 1 << draw->
vsub[plane]);
609 p += dst_linesize[plane];
610 m += mask_linesize << draw->
vsub[plane];
617 m, mask_linesize, l2depth, w_sub,
618 draw->
hsub[plane], draw->
vsub[plane],
619 xm0, left, right, bottom);
623 m, mask_linesize, l2depth, w_sub,
624 draw->
hsub[plane], draw->
vsub[plane],
625 xm0, left, right, bottom);
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
Convenience header that includes libavutil's core.
#define flags(name, subs,...)
#define AV_CEIL_RSHIFT(a, b)
static enum AVPixelFormat pix_fmt
static float sub(float src0, float src1)
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_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)
Init a draw context.
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
static uint8_t * pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[], int plane, int x, int y)
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_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)
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)
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.
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
static int component_used(FFDrawContext *draw, int plane, int comp)
#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)
#define AV_LOG_WARNING
Something somehow does not look correct.
static const int16_t alpha[]
Various defines for YUV<->RGB conversion.
#define RGB_TO_V_JPEG(r1, g1, b1)
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
#define RGB_TO_Y_CCIR(r, g, b)
#define RGB_TO_Y_JPEG(r, g, b)
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
#define RGB_TO_U_JPEG(r1, g1, b1)
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static const uint16_t mask[17]
Memory handling functions.
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_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#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.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_P010LE
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits,...
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_GRAY10LE
Y , 10bpp, little-endian.
@ AV_PIX_FMT_GBRP10BE
planar GBR 4:4:4 30bpp, big-endian
@ AV_PIX_FMT_GBRPF32BE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, big-endian.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_GBRP9LE
planar GBR 4:4:4 27bpp, little-endian
@ AV_PIX_FMT_P016LE
like NV12, with 16bpp per component, little-endian
@ AV_PIX_FMT_P010BE
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits,...
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_GBRP12BE
planar GBR 4:4:4 36bpp, big-endian
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
@ AV_PIX_FMT_GRAY12LE
Y , 12bpp, little-endian.
@ AV_PIX_FMT_GBRAP12BE
planar GBR 4:4:4:4 48bpp, big-endian
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_BGR48BE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
@ AV_PIX_FMT_GRAY14LE
Y , 14bpp, little-endian.
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_P016BE
like NV12, with 16bpp per component, big-endian
@ 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_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_GBRAP16BE
planar GBRA 4:4:4:4 64bpp, big-endian
@ AV_PIX_FMT_GBRPF32LE
IEEE-754 single precision planar GBR 4:4:4, 96bpp, little-endian.
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ 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_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_GBRP12LE
planar GBR 4:4:4 36bpp, little-endian
@ AV_PIX_FMT_BGRA64BE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
@ AV_PIX_FMT_GBRAP12LE
planar GBR 4:4:4:4 48bpp, little-endian
@ AV_PIX_FMT_GBRP9BE
planar GBR 4:4:4 27bpp, big-endian
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
@ AV_PIX_FMT_GBRAPF32BE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, big-endian.
@ 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_GBRAPF32LE
IEEE-754 single precision planar GBRA 4:4:4:4, 128bpp, little-endian.
@ AV_PIX_FMT_BGR48LE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
@ AV_PIX_FMT_GBRP14LE
planar GBR 4:4:4 42bpp, little-endian
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
@ AV_PIX_FMT_GBRP10LE
planar GBR 4:4:4 30bpp, little-endian
@ AV_PIX_FMT_GBRAP10BE
planar GBR 4:4:4:4 40bpp, big-endian
@ AV_PIX_FMT_BGRA64LE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
@ AV_PIX_FMT_GBRAP10LE
planar GBR 4:4:4:4 40bpp, little-endian
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_GRAY9LE
Y , 9bpp, little-endian.
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_GBRAP16LE
planar GBRA 4:4:4:4 64bpp, little-endian
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
@ AV_PIX_FMT_GBRP14BE
planar GBR 4:4:4 42bpp, big-endian
@ 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_GBRP16LE
planar GBR 4:4:4 48bpp, little-endian
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static int shift(int a, int b)
int depth
Number of bits in the component.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
union FFDrawColor::@204 comp[MAX_PLANES]
const struct AVPixFmtDescriptor * desc
enum AVPixelFormat format
uint8_t comp_mask[MAX_PLANES]
int pixelstep[MAX_PLANES]