FFmpeg
Loading...
Searching...
No Matches
drawutils.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stdio.h>
20
21#include "libavutil/pixdesc.h"
23
24int main(void)
25{
26 enum AVPixelFormat f;
30 int r, i;
31
32 for (f = 0; av_pix_fmt_desc_get(f); f++) {
34 if (!desc->name)
35 continue;
36 printf("Testing %s...%*s", desc->name,
37 (int)(16 - strlen(desc->name)), "");
38 r = ff_draw_init(&draw, f, 0);
39 if (r < 0) {
40 printf("no: %s\n", r == AVERROR(ENOSYS) ? "unsupported" : av_err2str(r));
41 continue;
42 }
43 ff_draw_color(&draw, &color, (uint8_t[]) { 1, 0, 0, 1 });
44 for (i = 0; i < sizeof(color); i++)
45 if (((uint8_t *)&color)[i] != 128)
46 break;
47 if (i == sizeof(color)) {
48 printf("fallback color\n");
49 continue;
50 }
51 printf("ok\n");
52 }
53
55 ff_draw_color(&draw, &color, (uint8_t[]) { 255, 0, 0, 128 });
56 for (int pass = 0; pass < 2; pass++) {
57 uint8_t pixel[4] = { 0 };
58 uint8_t *dst[4] = { pixel }, mask = 0xFF;
59 int linesize[4] = { 4 };
60
61 if (pass)
62 ff_blend_rectangle(&draw, &color, dst, linesize, 1, 1, 0, 0, 1, 1);
63 else
64 ff_blend_mask(&draw, &color, dst, linesize, 1, 1, &mask, 1, 1, 1, 3, 0, 0, 0);
65 printf("half transparent red over transparent rgba by %s: %d %d %d %d\n",
66 pass ? "rectangle" : "mask", pixel[0], pixel[1], pixel[2], pixel[3]);
67 }
68 return 0;
69}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static int draw(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define pixel
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
__device__ int printf(const char *,...)
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.
Definition drawutils.c:394
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Definition drawutils.c:174
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
Definition drawutils.c:179
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.
Definition drawutils.c:574
misc drawing utilities
#define FF_DRAW_PROCESS_ALPHA
Process alpha pixel component.
Definition drawutils.h:64
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define r
Definition input.c:42
const char * desc
Definition libsvtav1.c:83
static const uint16_t mask[17]
Definition lzw.c:38
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
int main(void)
Definition drawutils.c:24