69 int *is_packed_rgba,
uint8_t rgba_map_ptr[4])
82 if (*is_packed_rgba) {
84 for (i = 0; i < 4; i++)
85 dst_color[rgba_map[i]] = rgba_color[i];
90 for (i = 0; i < w; i++)
91 memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]);
93 memcpy(rgba_map_ptr, rgba_map,
sizeof(rgba_map[0]) * 4);
97 dst_color[0] =
RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
98 dst_color[1] =
RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
99 dst_color[2] =
RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
100 dst_color[3] = rgba_color[3];
102 for (plane = 0; plane < 4; plane++) {
104 int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
106 pixel_step[
plane] = 1;
110 while(plane && line[plane-1])
114 memset(line[plane], dst_color[plane], line_size);
123 int hsub,
int vsub,
int x,
int y,
int w,
int h)
128 for (plane = 0; plane < 4 && dst[
plane]; plane++) {
129 int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
130 int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
134 p = dst[
plane] + (y >> vsub1) * dst_linesize[plane];
135 for (i = 0; i <
height; i++) {
136 memcpy(p + (x >> hsub1) * pixelstep[plane],
137 src[plane], width * pixelstep[plane]);
138 p += dst_linesize[
plane];
144 uint8_t *
src[4],
int src_linesize[4],
int pixelstep[4],
145 int hsub,
int vsub,
int x,
int y,
int y2,
int w,
int h)
150 for (plane = 0; plane < 4 && dst[
plane]; plane++) {
151 int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
152 int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
156 p = dst[
plane] + (y >> vsub1) * dst_linesize[plane];
157 for (i = 0; i <
height; i++) {
158 memcpy(p + (x >> hsub1) * pixelstep[plane],
159 src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), width * pixelstep[plane]);
160 p += dst_linesize[
plane];
169 unsigned i, nb_planes = 0;
172 if (!desc || !desc->
name)
184 if (pixelstep[c->
plane] != 0 &&
188 if (pixelstep[c->
plane] >= 8)
194 memset(draw, 0,
sizeof(*draw));
212 if (rgba != color->
rgba)
213 memcpy(color->
rgba, rgba,
sizeof(color->
rgba));
217 for (i = 0; i < 4; i++)
218 color->
comp[0].
u8[rgba_map[i]] = rgba[i];
220 for (i = 0; i < 4; i++)
221 color->
comp[rgba_map[i]].
u8[0] = rgba[i];
228 color->
comp[3].
u8[0] = rgba[3];
231 color->
comp[1].
u8[0] = rgba[3];
234 "Color conversion not implemented for %s\n", draw->
desc->
name);
235 memset(color, 128,
sizeof(*color));
240 int plane,
int x,
int y)
243 (y >> draw->
vsub[
plane]) * linesize[plane] +
248 uint8_t *dst[],
int dst_linesize[],
250 int dst_x,
int dst_y,
int src_x,
int src_y,
253 int plane, y, wp, hp;
256 for (plane = 0; plane < draw->
nb_planes; plane++) {
257 p =
pointer_at(draw, src, src_linesize, plane, src_x, src_y);
258 q =
pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
261 for (y = 0; y < hp; y++) {
263 p += src_linesize[
plane];
264 q += dst_linesize[
plane];
270 uint8_t *dst[],
int dst_linesize[],
271 int dst_x,
int dst_y,
int w,
int h)
273 int plane, x, y, wp, hp;
276 for (plane = 0; plane < draw->
nb_planes; plane++) {
277 p0 =
pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
284 for (x = 0; x < wp; x++) {
290 p = p0 + dst_linesize[
plane];
291 for (y = 1; y < hp; y++) {
293 p += dst_linesize[
plane];
324 int mask = (1 << sub) - 1;
326 *start = (-*x) & mask;
328 *start =
FFMIN(*start, *w);
336 return (draw->
comp_mask[plane] >> comp) & 1;
343 int dx,
int w,
unsigned hsub,
int left,
int right)
345 unsigned asrc = alpha *
src;
346 unsigned tau = 0x1010101 -
alpha;
350 unsigned suba = (left *
alpha) >> hsub;
351 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
354 for (x = 0; x < w; x++) {
355 *dst = (*dst * tau + asrc) >> 24;
359 unsigned suba = (right *
alpha) >> hsub;
360 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
365 uint8_t *dst[],
int dst_linesize[],
366 int dst_w,
int dst_h,
367 int x0,
int y0,
int w,
int h)
370 int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
376 if (w <= 0 || h <= 0 || !color->rgba[3])
379 alpha = 0x10203 * color->
rgba[3] + 0x2;
381 for (plane = 0; plane < nb_planes; plane++) {
383 p0 =
pointer_at(draw, dst, dst_linesize, plane, x0, y0);
390 for (comp = 0; comp < nb_comp; comp++) {
397 draw->
hsub[plane], left, right);
398 p += dst_linesize[
plane];
400 for (y = 0; y < h_sub; y++) {
403 draw->
hsub[plane], left, right);
404 p += dst_linesize[
plane];
409 draw->
hsub[plane], left, right);
415 const uint8_t *
mask,
int mask_linesize,
int l2depth,
416 unsigned w,
unsigned h,
unsigned shift,
unsigned xm0)
418 unsigned xm, x, y, t = 0;
419 unsigned xmshf = 3 - l2depth;
420 unsigned xmmod = 7 >> l2depth;
421 unsigned mbits = (1 << (1 << l2depth)) - 1;
422 unsigned mmult = 255 / mbits;
424 for (y = 0; y <
h; y++) {
426 for (x = 0; x < w; x++) {
427 t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
431 mask += mask_linesize;
433 alpha = (t >>
shift) * alpha;
434 *dst = ((0x1010101 -
alpha) * *dst + alpha * src) >> 24;
439 const uint8_t *
mask,
int mask_linesize,
int l2depth,
int w,
440 unsigned hsub,
unsigned vsub,
441 int xm,
int left,
int right,
int hband)
446 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
447 left, hband, hsub + vsub, xm);
451 for (x = 0; x < w; x++) {
452 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
453 1 << hsub, hband, hsub + vsub, xm);
458 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
459 right, hband, hsub + vsub, xm);
463 uint8_t *dst[],
int dst_linesize[],
int dst_w,
int dst_h,
464 const uint8_t *
mask,
int mask_linesize,
int mask_w,
int mask_h,
465 int l2depth,
unsigned endianness,
int x0,
int y0)
468 int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
474 mask += ym0 * mask_linesize;
475 if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
479 alpha = (0x10307 * color->
rgba[3] + 0x3) >> 8;
481 for (plane = 0; plane < nb_planes; plane++) {
483 p0 =
pointer_at(draw, dst, dst_linesize, plane, x0, y0);
490 for (comp = 0; comp < nb_comp; comp++) {
497 color->
comp[plane].
u8[comp], alpha,
498 m, mask_linesize, l2depth, w_sub,
499 draw->
hsub[plane], draw->
vsub[plane],
500 xm0, left, right, top);
501 p += dst_linesize[
plane];
502 m += top * mask_linesize;
504 for (y = 0; y < h_sub; y++) {
506 color->
comp[plane].
u8[comp], alpha,
507 m, mask_linesize, l2depth, w_sub,
508 draw->
hsub[plane], draw->
vsub[plane],
509 xm0, left, right, 1 << draw->
vsub[plane]);
510 p += dst_linesize[
plane];
515 color->
comp[plane].
u8[comp], alpha,
516 m, mask_linesize, l2depth, w_sub,
517 draw->
hsub[plane], draw->
vsub[plane],
518 xm0, left, right, bottom);
531 value += round_dir ? (1 <<
shift) - 1 : 1 << (shift - 1);
532 return (value >> shift) <<
shift;
565 printf(
"Testing %s...%*s", desc->
name,
566 (
int)(16 - strlen(desc->
name)),
"");
571 printf(
"no: %s\n", buf);
575 for (i = 0; i <
sizeof(
color); i++)
576 if (((
uint8_t *)&color)[i] != 128)
578 if (i ==
sizeof(color)) {
579 printf(
"fallback color\n");
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
int plane
Which of the 4 planes contains the component.
static enum AVPixelFormat pix_fmt
static int shift(int a, int b)
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...
#define AV_PIX_FMT_GBRP10
Various defines for YUV<->RGB conversion.
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
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.
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]
union FFDrawColor::@137 comp[MAX_PLANES]
static double alpha(void *priv, double x, double y)
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...
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)
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_...
uint8_t nb_components
The number of components each pixel has, (1-4)
GLsizei GLboolean const GLfloat * value
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
packed RGB 8:8:8, 24bpp, BGRBGR...
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
#define AV_PIX_FMT_GBRP14
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...
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...
static const char * format
BYTE int const BYTE int int int height
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.
static int component_used(FFDrawContext *draw, int plane, int comp)
#define RGB_TO_U_CCIR(r1, g1, b1, shift)
#define AV_PIX_FMT_GBRP12
int offset
Number of elements before the component of the first pixel.
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
#define RGB_TO_V_CCIR(r1, g1, b1, shift)
planar GBRA 4:4:4:4 32bpp
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
#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])
int pixelstep[MAX_PLANES]
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.
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
#define av_malloc_array(a, b)
int main(int argc, char **argv)
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.
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
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)