65 int *is_packed_rgba,
uint8_t rgba_map_ptr[4])
78 if (*is_packed_rgba) {
80 for (i = 0; i < 4; i++)
81 dst_color[rgba_map[i]] = rgba_color[i];
86 for (i = 0; i < w; i++)
87 memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]);
89 memcpy(rgba_map_ptr, rgba_map,
sizeof(rgba_map[0]) * 4);
93 dst_color[0] =
RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
94 dst_color[1] =
RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
95 dst_color[2] =
RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
96 dst_color[3] = rgba_color[3];
98 for (plane = 0; plane < 4; plane++) {
100 int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
102 pixel_step[
plane] = 1;
106 while(plane && line[plane-1])
110 memset(line[plane], dst_color[plane], line_size);
119 int hsub,
int vsub,
int x,
int y,
int w,
int h)
124 for (plane = 0; plane < 4 && dst[
plane]; plane++) {
125 int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
126 int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
130 p = dst[
plane] + (y >> vsub1) * dst_linesize[plane];
131 for (i = 0; i <
height; i++) {
132 memcpy(p + (x >> hsub1) * pixelstep[plane],
133 src[plane], width * pixelstep[plane]);
134 p += dst_linesize[
plane];
140 uint8_t *
src[4],
int src_linesize[4],
int pixelstep[4],
141 int hsub,
int vsub,
int x,
int y,
int y2,
int w,
int h)
146 for (plane = 0; plane < 4 && dst[
plane]; plane++) {
147 int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
148 int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
152 p = dst[
plane] + (y >> vsub1) * dst_linesize[plane];
153 for (i = 0; i <
height; i++) {
154 memcpy(p + (x >> hsub1) * pixelstep[plane],
155 src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), width * pixelstep[plane]);
156 p += dst_linesize[
plane];
165 unsigned i, nb_planes = 0;
168 if (!desc || !desc->
name)
180 if (pixelstep[c->
plane] != 0 &&
184 if (pixelstep[c->
plane] >= 8)
190 memset(draw, 0,
sizeof(*draw));
208 if (rgba != color->
rgba)
209 memcpy(color->
rgba, rgba,
sizeof(color->
rgba));
213 for (i = 0; i < 4; i++)
214 color->
comp[0].
u8[rgba_map[i]] = rgba[i];
216 for (i = 0; i < 4; i++)
217 color->
comp[rgba_map[i]].
u8[0] = rgba[i];
224 color->
comp[3].
u8[0] = rgba[3];
227 color->
comp[1].
u8[0] = rgba[3];
230 "Color conversion not implemented for %s\n", draw->
desc->
name);
231 memset(color, 128,
sizeof(*color));
239 (y >> draw->
vsub[
plane]) * linesize[plane] +
244 uint8_t *dst[],
int dst_linesize[],
246 int dst_x,
int dst_y,
int src_x,
int src_y,
252 for (plane = 0; plane < draw->
nb_planes; plane++) {
253 p =
pointer_at(draw, src, src_linesize, plane, src_x, src_y);
254 q =
pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
257 for (y = 0; y < hp; y++) {
259 p += src_linesize[
plane];
260 q += dst_linesize[
plane];
266 uint8_t *dst[],
int dst_linesize[],
267 int dst_x,
int dst_y,
int w,
int h)
272 for (plane = 0; plane < draw->
nb_planes; plane++) {
273 p0 =
pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
280 for (x = 0; x < wp; x++) {
286 p = p0 + dst_linesize[
plane];
287 for (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);
332 return (draw->
comp_mask[plane] >> comp) & 1;
339 int dx,
int w,
unsigned hsub,
int left,
int right)
341 unsigned asrc = alpha *
src;
342 unsigned tau = 0x1010101 -
alpha;
346 unsigned suba = (left *
alpha) >> hsub;
347 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
350 for (x = 0; x < w; x++) {
351 *dst = (*dst * tau + asrc) >> 24;
355 unsigned suba = (right *
alpha) >> hsub;
356 *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
361 uint8_t *dst[],
int dst_linesize[],
362 int dst_w,
int dst_h,
363 int x0,
int y0,
int w,
int h)
366 int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom,
y;
372 if (w <= 0 || h <= 0 || !color->rgba[3])
375 alpha = 0x10203 * color->
rgba[3] + 0x2;
377 for (plane = 0; plane < nb_planes; plane++) {
379 p0 =
pointer_at(draw, dst, dst_linesize, plane, x0, y0);
386 for (comp = 0; comp < nb_comp; comp++) {
393 draw->
hsub[plane], left, right);
394 p += dst_linesize[
plane];
396 for (y = 0; y < h_sub; y++) {
399 draw->
hsub[plane], left, right);
400 p += dst_linesize[
plane];
405 draw->
hsub[plane], left, right);
412 unsigned w,
unsigned h,
unsigned shift,
unsigned xm0)
414 unsigned xm, x,
y, t = 0;
415 unsigned xmshf = 3 - l2depth;
416 unsigned xmmod = 7 >> l2depth;
417 unsigned mbits = (1 << (1 << l2depth)) - 1;
418 unsigned mmult = 255 / mbits;
420 for (y = 0; y <
h; y++) {
422 for (x = 0; x < w; x++) {
423 t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
427 mask += mask_linesize;
429 alpha = (t >>
shift) * alpha;
430 *dst = ((0x1010101 -
alpha) * *dst + alpha * src) >> 24;
435 uint8_t *
mask,
int mask_linesize,
int l2depth,
int w,
436 unsigned hsub,
unsigned vsub,
437 int xm,
int left,
int right,
int hband)
442 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
443 left, hband, hsub + vsub, xm);
447 for (x = 0; x < w; x++) {
448 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
449 1 << hsub, hband, hsub + vsub, xm);
454 blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
455 right, hband, hsub + vsub, xm);
459 uint8_t *dst[],
int dst_linesize[],
int dst_w,
int dst_h,
460 uint8_t *
mask,
int mask_linesize,
int mask_w,
int mask_h,
461 int l2depth,
unsigned endianness,
int x0,
int y0)
464 int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom,
y;
469 mask += ym0 * mask_linesize;
470 if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
474 alpha = (0x10307 * color->
rgba[3] + 0x3) >> 8;
476 for (plane = 0; plane < nb_planes; plane++) {
478 p0 =
pointer_at(draw, dst, dst_linesize, plane, x0, y0);
485 for (comp = 0; comp < nb_comp; comp++) {
492 color->
comp[plane].
u8[comp], alpha,
493 m, mask_linesize, l2depth, w_sub,
494 draw->
hsub[plane], draw->
vsub[plane],
495 xm0, left, right, top);
496 p += dst_linesize[
plane];
497 m += top * mask_linesize;
499 for (y = 0; y < h_sub; y++) {
501 color->
comp[plane].
u8[comp], alpha,
502 m, mask_linesize, l2depth, w_sub,
503 draw->
hsub[plane], draw->
vsub[plane],
504 xm0, left, right, 1 << draw->
vsub[plane]);
505 p += dst_linesize[
plane];
510 color->
comp[plane].
u8[comp], alpha,
511 m, mask_linesize, l2depth, w_sub,
512 draw->
hsub[plane], draw->
vsub[plane],
513 xm0, left, right, bottom);
526 value += round_dir ? (1 <<
shift) - 1 : 1 << (shift - 1);
527 return (value >> shift) <<
shift;
558 printf(
"Testing %s...%*s", desc->
name,
559 (
int)(16 - strlen(desc->
name)),
"");
564 printf(
"no: %s\n", buf);
568 for (i = 0; i <
sizeof(
color); i++)
569 if (((
uint8_t *)&color)[i] != 128)
571 if (i ==
sizeof(color)) {
572 printf(
"fallback color\n");
void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h, 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 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...
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]
uint16_t depth_minus1
Number of bits in the component minus 1.
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().
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...
uint8_t nb_components
The number of components each pixel has, (1-4)
GLsizei GLboolean const GLfloat * value
#define FF_CEIL_RSHIFT(a, b)
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
static void blend_line_hv(uint8_t *dst, int dst_delta, unsigned src, unsigned alpha, uint8_t *mask, int mask_linesize, int l2depth, int w, unsigned hsub, unsigned vsub, int xm, int left, int right, int hband)
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...
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...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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)
uint16_t step_minus1
Number of elements between 2 horizontally consecutive pixels minus 1.
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)
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)
uint16_t plane
Which of the 4 planes contains the component.
planar GBRA 4:4:4:4 32bpp
union FFDrawColor::@131 comp[MAX_PLANES]
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_pixel(uint8_t *dst, unsigned src, unsigned alpha, uint8_t *mask, int mask_linesize, int l2depth, unsigned w, unsigned h, unsigned shift, unsigned xm0)
#define RGB_TO_Y_CCIR(r, g, b)
uint16_t offset_plus1
Number of elements before the component of the first pixel plus 1.
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)
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...