82 int *is_packed_rgba,
uint8_t rgba_map_ptr[4])
95 if (*is_packed_rgba) {
97 for (i = 0; i < 4; i++)
98 dst_color[rgba_map[i]] = rgba_color[i];
103 for (i = 0; i < w; i++)
104 memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]);
106 memcpy(rgba_map_ptr, rgba_map,
sizeof(rgba_map[0]) * 4);
110 dst_color[0] =
RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
111 dst_color[1] =
RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
112 dst_color[2] =
RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
113 dst_color[3] = rgba_color[3];
115 for (plane = 0; plane < 4; plane++) {
117 int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
119 pixel_step[
plane] = 1;
123 while(plane && line[plane-1])
127 memset(line[plane], dst_color[plane], line_size);
136 int hsub,
int vsub,
int x,
int y,
int w,
int h)
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;
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], width * pixelstep[plane]);
151 p += dst_linesize[
plane];
157 uint8_t *
src[4],
int src_linesize[4],
int pixelstep[4],
158 int hsub,
int vsub,
int x,
int y,
int y2,
int w,
int h)
163 for (plane = 0; plane < 4 && dst[
plane]; plane++) {
164 int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
165 int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
169 p = dst[
plane] + (y >> vsub1) * dst_linesize[plane];
170 for (i = 0; i <
height; i++) {
171 memcpy(p + (x >> hsub1) * pixelstep[plane],
172 src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), width * pixelstep[plane]);
173 p += dst_linesize[
plane];
182 unsigned i, nb_planes = 0;
185 if (!desc || !desc->
name)
201 if (pixelstep[c->
plane] != 0 &&
204 if (pixelstep[c->
plane] == 6 &&
208 if (pixelstep[c->
plane] >= 8)
212 memset(draw, 0,
sizeof(*draw));
231 if (rgba != color->
rgba)
232 memcpy(color->
rgba, rgba,
sizeof(color->
rgba));
236 for (i = 0; i < 4; i++) {
237 color->
comp[0].
u8[rgba_map[i]] = rgba[i];
239 color->
comp[0].
u16[rgba_map[i]] = color->
comp[0].
u8[rgba_map[i]] << 8;
243 for (i = 0; i < 4; i++) {
244 color->
comp[rgba_map[i]].
u8[0] = rgba[i];
255 color->
comp[3].
u8[0] = rgba[3];
256 #define EXPAND(compn) \
257 if (desc->comp[compn].depth > 8) \
258 color->comp[desc->comp[compn].plane].u16[desc->comp[compn].offset] = \
259 color->comp[desc->comp[compn].plane].u8[desc->comp[compn].offset] << \
260 (draw->desc->comp[compn].depth + draw->desc->comp[compn].shift - 8)
273 color->
comp[1].
u8[0] = rgba[3];
277 "Color conversion not implemented for %s\n", draw->
desc->
name);
278 memset(color, 128,
sizeof(*color));
283 int plane,
int x,
int y)
286 (y >> draw->
vsub[
plane]) * linesize[plane] +
291 uint8_t *dst[],
int dst_linesize[],
293 int dst_x,
int dst_y,
int src_x,
int src_y,
296 int plane, y, wp, hp;
299 for (plane = 0; plane < draw->
nb_planes; plane++) {
300 p =
pointer_at(draw, src, src_linesize, plane, src_x, src_y);
301 q =
pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
304 for (y = 0; y < hp; y++) {
306 p += src_linesize[
plane];
307 q += dst_linesize[
plane];
313 uint8_t *dst[],
int dst_linesize[],
314 int dst_x,
int dst_y,
int w,
int h)
316 int plane, x, y, wp, hp;
320 for (plane = 0; plane < draw->
nb_planes; plane++) {
321 p0 =
pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
334 for (x = 0; x < wp; x++) {
340 p = p0 + dst_linesize[
plane];
341 for (y = 1; y < hp; y++) {
343 p += dst_linesize[
plane];
374 int mask = (1 << sub) - 1;
376 *start = (-*x) & mask;
378 *start =
FFMIN(*start, *w);
386 return (draw->
comp_mask[plane] >> comp) & 1;
393 int dx,
int w,
unsigned hsub,
int left,
int right)
395 unsigned asrc = alpha *
src;
396 unsigned tau = 0x1010101 -
alpha;
400 unsigned suba = (left *
alpha) >> hsub;
401 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
404 for (x = 0; x < w; x++) {
405 *dst = (*dst * tau + asrc) >> 24;
409 unsigned suba = (right *
alpha) >> hsub;
410 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
415 int dx,
int w,
unsigned hsub,
int left,
int right)
417 unsigned asrc = alpha *
src;
418 unsigned tau = 0x10001 -
alpha;
422 unsigned suba = (left *
alpha) >> hsub;
424 AV_WL16(dst, (value * (0x10001 - suba) + src * suba) >> 16);
427 for (x = 0; x < w; x++) {
429 AV_WL16(dst, (value * tau + asrc) >> 16);
433 unsigned suba = (right *
alpha) >> hsub;
435 AV_WL16(dst, (value * (0x10001 - suba) + src * suba) >> 16);
440 uint8_t *dst[],
int dst_linesize[],
441 int dst_w,
int dst_h,
442 int x0,
int y0,
int w,
int h)
445 int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
451 if (w <= 0 || h <= 0 || !color->rgba[3])
455 alpha = 0x10203 * color->
rgba[3] + 0x2;
458 alpha = 0x101 * color->
rgba[3] + 0x2;
461 nb_planes += !nb_planes;
462 for (plane = 0; plane < nb_planes; plane++) {
464 p0 =
pointer_at(draw, dst, dst_linesize, plane, x0, y0);
471 for (comp = 0; comp < nb_comp; comp++) {
481 draw->
hsub[plane], left, right);
485 draw->
hsub[plane], left, right);
487 p += dst_linesize[
plane];
490 for (y = 0; y < h_sub; y++) {
493 draw->
hsub[plane], left, right);
494 p += dst_linesize[
plane];
497 for (y = 0; y < h_sub; y++) {
500 draw->
hsub[plane], left, right);
501 p += dst_linesize[
plane];
508 draw->
hsub[plane], left, right);
512 draw->
hsub[plane], left, right);
520 const uint8_t *
mask,
int mask_linesize,
int l2depth,
521 unsigned w,
unsigned h,
unsigned shift,
unsigned xm0)
523 unsigned xm, x, y, t = 0;
524 unsigned xmshf = 3 - l2depth;
525 unsigned xmmod = 7 >> l2depth;
526 unsigned mbits = (1 << (1 << l2depth)) - 1;
527 unsigned mmult = 255 / mbits;
530 for (y = 0; y <
h; y++) {
532 for (x = 0; x < w; x++) {
533 t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
537 mask += mask_linesize;
539 alpha = (t >>
shift) * alpha;
540 AV_WL16(dst, ((0x10001 - alpha) * value + alpha * src) >> 16);
544 const uint8_t *
mask,
int mask_linesize,
int l2depth,
545 unsigned w,
unsigned h,
unsigned shift,
unsigned xm0)
547 unsigned xm, x, y, t = 0;
548 unsigned xmshf = 3 - l2depth;
549 unsigned xmmod = 7 >> l2depth;
550 unsigned mbits = (1 << (1 << l2depth)) - 1;
551 unsigned mmult = 255 / mbits;
553 for (y = 0; y <
h; y++) {
555 for (x = 0; x < w; x++) {
556 t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
560 mask += mask_linesize;
562 alpha = (t >>
shift) * alpha;
563 *dst = ((0x1010101 -
alpha) * *dst + alpha * src) >> 24;
568 const uint8_t *
mask,
int mask_linesize,
int l2depth,
int w,
569 unsigned hsub,
unsigned vsub,
570 int xm,
int left,
int right,
int hband)
576 left, hband, hsub + vsub, xm);
580 for (x = 0; x < w; x++) {
582 1 << hsub, hband, hsub + vsub, xm);
588 right, hband, hsub + vsub, xm);
593 const uint8_t *
mask,
int mask_linesize,
int l2depth,
int w,
594 unsigned hsub,
unsigned vsub,
595 int xm,
int left,
int right,
int hband)
600 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
601 left, hband, hsub + vsub, xm);
605 for (x = 0; x < w; x++) {
606 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
607 1 << hsub, hband, hsub + vsub, xm);
612 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
613 right, hband, hsub + vsub, xm);
617 uint8_t *dst[],
int dst_linesize[],
int dst_w,
int dst_h,
618 const uint8_t *
mask,
int mask_linesize,
int mask_w,
int mask_h,
619 int l2depth,
unsigned endianness,
int x0,
int y0)
622 int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
628 mask += ym0 * mask_linesize;
629 if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
634 alpha = (0x10307 * color->
rgba[3] + 0x3) >> 8;
636 alpha = (0x101 * color->
rgba[3] + 0x2) >> 8;
639 nb_planes += !nb_planes;
640 for (plane = 0; plane < nb_planes; plane++) {
642 p0 =
pointer_at(draw, dst, dst_linesize, plane, x0, y0);
649 for (comp = 0; comp < nb_comp; comp++) {
659 color->
comp[plane].
u8[comp], alpha,
660 m, mask_linesize, l2depth, w_sub,
661 draw->
hsub[plane], draw->
vsub[plane],
662 xm0, left, right, top);
665 color->
comp[plane].
u16[comp], alpha,
666 m, mask_linesize, l2depth, w_sub,
667 draw->
hsub[plane], draw->
vsub[plane],
668 xm0, left, right, top);
670 p += dst_linesize[
plane];
671 m += top * mask_linesize;
674 for (y = 0; y < h_sub; y++) {
676 color->
comp[plane].
u8[comp], alpha,
677 m, mask_linesize, l2depth, w_sub,
678 draw->
hsub[plane], draw->
vsub[plane],
679 xm0, left, right, 1 << draw->
vsub[plane]);
680 p += dst_linesize[
plane];
684 for (y = 0; y < h_sub; y++) {
686 color->
comp[plane].
u16[comp], alpha,
687 m, mask_linesize, l2depth, w_sub,
688 draw->
hsub[plane], draw->
vsub[plane],
689 xm0, left, right, 1 << draw->
vsub[plane]);
690 p += dst_linesize[
plane];
697 color->
comp[plane].
u8[comp], alpha,
698 m, mask_linesize, l2depth, w_sub,
699 draw->
hsub[plane], draw->
vsub[plane],
700 xm0, left, right, bottom);
703 color->
comp[plane].
u16[comp], alpha,
704 m, mask_linesize, l2depth, w_sub,
705 draw->
hsub[plane], draw->
vsub[plane],
706 xm0, left, right, bottom);
721 value += round_dir ? (1 <<
shift) - 1 : 1 << (shift - 1);
722 return (value >> shift) <<
shift;
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
planar GBR 4:4:4:4 40bpp, little-endian
int plane
Which of the 4 planes contains the component.
static enum AVPixelFormat pix_fmt
static int shift(int a, int b)
static float alpha(float a)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
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.
ptrdiff_t const GLvoid * data
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
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.
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Various defines for YUV<->RGB conversion.
Convenience header that includes libavutil's core.
planar GBR 4:4:4 36bpp, little-endian
static void blend_line(uint8_t *dst, unsigned src, unsigned alpha, int dx, int w, unsigned hsub, int left, int right)
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Y , 12bpp, little-endian.
planar GBR 4:4:4 36bpp, big-endian
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
static void clip_interval(int wmax, int *x, int *w, int *dx)
Clip interval [x; x+w[ within [0; wmax[.
int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir, int value)
Round a dimension according to subsampling.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
planar GBRA 4:4:4:4 64bpp, big-endian
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
static const uint32_t color[16+AV_CLASS_CATEGORY_NB]
static av_cold int end(AVCodecContext *avctx)
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
uint8_t comp_mask[MAX_PLANES]
planar GBR 4:4:4 48bpp, big-endian
Y , 10bpp, little-endian.
planar GBR 4:4:4 27bpp, big-endian
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static const uint16_t mask[17]
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
static void blend_line16(uint8_t *dst, unsigned src, unsigned alpha, int dx, int w, unsigned hsub, int left, int right)
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
simple assert() macros that are a bit more flexible than ISO C assert().
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)
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, big-endian
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
planar GBR 4:4:4:4 48bpp, big-endian
uint8_t nb_components
The number of components each pixel has, (1-4)
planar GBR 4:4:4:4 40bpp, big-endian
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
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)
GLsizei GLboolean const GLfloat * value
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
packed RGB 8:8:8, 24bpp, BGRBGR...
union FFDrawColor::@173 comp[MAX_PLANES]
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
static uint8_t * pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[], int plane, int x, int y)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
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 comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
planar GBR 4:4:4:4 48bpp, little-endian
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.
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)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
planar GBR 4:4:4 30bpp, big-endian
planar GBR 4:4:4 42bpp, little-endian
static const char * format
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.
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)
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
planar GBR 4:4:4 42bpp, big-endian
static int component_used(FFDrawContext *draw, int plane, int comp)
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
int offset
Number of elements before the component of the first pixel.
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
planar GBRA 4:4:4:4 32bpp
planar GBR 4:4:4 27bpp, little-endian
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
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)
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
#define RGB_TO_Y_CCIR(r, g, b)
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])
Y , 16bpp, little-endian.
int pixelstep[MAX_PLANES]
16 bits gray, 16 bits alpha (little-endian)
const struct AVPixFmtDescriptor * desc
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.
planar GBR 4:4:4 48bpp, little-endian
#define av_malloc_array(a, b)
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)
int depth
Number of bits in the component.
planar GBRA 4:4:4:4 64bpp, little-endian
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
AVPixelFormat
Pixel format.
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
enum AVPixelFormat format
planar GBR 4:4:4 30bpp, little-endian
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
int step
Number of elements between 2 horizontally consecutive pixels.
#define AV_CEIL_RSHIFT(a, b)