]> git.sesse.net Git - ffmpeg/blob - libavfilter/drawutils.c
Merge commit '799f57ac96f9891d1a0f7d6c4b218ed536e8aca5'
[ffmpeg] / libavfilter / drawutils.c
1 /*
2  * Copyright 2011 Stefano Sabatini <stefano.sabatini-lala poste it>
3  * Copyright 2012 Nicolas George <nicolas.george normalesup org>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include <string.h>
23
24 #include "libavutil/avutil.h"
25 #include "libavutil/colorspace.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/pixdesc.h"
28 #include "drawutils.h"
29 #include "formats.h"
30
31 enum { RED = 0, GREEN, BLUE, ALPHA };
32
33 int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
34 {
35     switch (pix_fmt) {
36     case AV_PIX_FMT_0RGB:
37     case AV_PIX_FMT_ARGB:  rgba_map[ALPHA] = 0; rgba_map[RED  ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break;
38     case AV_PIX_FMT_0BGR:
39     case AV_PIX_FMT_ABGR:  rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED  ] = 3; break;
40     case AV_PIX_FMT_RGB48LE:
41     case AV_PIX_FMT_RGB48BE:
42     case AV_PIX_FMT_RGBA64BE:
43     case AV_PIX_FMT_RGBA64LE:
44     case AV_PIX_FMT_RGB0:
45     case AV_PIX_FMT_RGBA:
46     case AV_PIX_FMT_RGB24: rgba_map[RED  ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break;
47     case AV_PIX_FMT_BGR48LE:
48     case AV_PIX_FMT_BGR48BE:
49     case AV_PIX_FMT_BGRA64BE:
50     case AV_PIX_FMT_BGRA64LE:
51     case AV_PIX_FMT_BGRA:
52     case AV_PIX_FMT_BGR0:
53     case AV_PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED  ] = 2; rgba_map[ALPHA] = 3; break;
54     case AV_PIX_FMT_GBRAP:
55     case AV_PIX_FMT_GBRP:  rgba_map[GREEN] = 0; rgba_map[BLUE ] = 1; rgba_map[RED  ] = 2; rgba_map[ALPHA] = 3; break;
56     default:                    /* unsupported */
57         return AVERROR(EINVAL);
58     }
59     return 0;
60 }
61
62 int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t dst_color[4],
63                             enum AVPixelFormat pix_fmt, uint8_t rgba_color[4],
64                             int *is_packed_rgba, uint8_t rgba_map_ptr[4])
65 {
66     uint8_t rgba_map[4] = {0};
67     int i;
68     const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(pix_fmt);
69     int hsub = pix_desc->log2_chroma_w;
70
71     *is_packed_rgba = ff_fill_rgba_map(rgba_map, pix_fmt) >= 0;
72
73     if (*is_packed_rgba) {
74         pixel_step[0] = (av_get_bits_per_pixel(pix_desc))>>3;
75         for (i = 0; i < 4; i++)
76             dst_color[rgba_map[i]] = rgba_color[i];
77
78         line[0] = av_malloc(w * pixel_step[0]);
79         for (i = 0; i < w; i++)
80             memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]);
81         if (rgba_map_ptr)
82             memcpy(rgba_map_ptr, rgba_map, sizeof(rgba_map[0]) * 4);
83     } else {
84         int plane;
85
86         dst_color[0] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]);
87         dst_color[1] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
88         dst_color[2] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0);
89         dst_color[3] = rgba_color[3];
90
91         for (plane = 0; plane < 4; plane++) {
92             int line_size;
93             int hsub1 = (plane == 1 || plane == 2) ? hsub : 0;
94
95             pixel_step[plane] = 1;
96             line_size = FF_CEIL_RSHIFT(w, hsub1) * pixel_step[plane];
97             line[plane] = av_malloc(line_size);
98             memset(line[plane], dst_color[plane], line_size);
99         }
100     }
101
102     return 0;
103 }
104
105 void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4],
106                        uint8_t *src[4], int pixelstep[4],
107                        int hsub, int vsub, int x, int y, int w, int h)
108 {
109     int i, plane;
110     uint8_t *p;
111
112     for (plane = 0; plane < 4 && dst[plane]; plane++) {
113         int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
114         int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
115         int width  = FF_CEIL_RSHIFT(w, hsub1);
116         int height = FF_CEIL_RSHIFT(h, vsub1);
117
118         p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
119         for (i = 0; i < height; i++) {
120             memcpy(p + (x >> hsub1) * pixelstep[plane],
121                    src[plane], width * pixelstep[plane]);
122             p += dst_linesize[plane];
123         }
124     }
125 }
126
127 void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4],
128                        uint8_t *src[4], int src_linesize[4], int pixelstep[4],
129                        int hsub, int vsub, int x, int y, int y2, int w, int h)
130 {
131     int i, plane;
132     uint8_t *p;
133
134     for (plane = 0; plane < 4 && dst[plane]; plane++) {
135         int hsub1 = plane == 1 || plane == 2 ? hsub : 0;
136         int vsub1 = plane == 1 || plane == 2 ? vsub : 0;
137         int width  = FF_CEIL_RSHIFT(w, hsub1);
138         int height = FF_CEIL_RSHIFT(h, vsub1);
139
140         p = dst[plane] + (y >> vsub1) * dst_linesize[plane];
141         for (i = 0; i < height; i++) {
142             memcpy(p + (x >> hsub1) * pixelstep[plane],
143                    src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), width * pixelstep[plane]);
144             p += dst_linesize[plane];
145         }
146     }
147 }
148
149 int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
150 {
151     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
152     const AVComponentDescriptor *c;
153     unsigned i, nb_planes = 0;
154     int pixelstep[MAX_PLANES] = { 0 };
155
156     if (!desc->name)
157         return AVERROR(EINVAL);
158     if (desc->flags & ~(AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PSEUDOPAL | AV_PIX_FMT_FLAG_ALPHA))
159         return AVERROR(ENOSYS);
160     for (i = 0; i < desc->nb_components; i++) {
161         c = &desc->comp[i];
162         /* for now, only 8-bits formats */
163         if (c->depth_minus1 != 8 - 1)
164             return AVERROR(ENOSYS);
165         if (c->plane >= MAX_PLANES)
166             return AVERROR(ENOSYS);
167         /* strange interleaving */
168         if (pixelstep[c->plane] != 0 &&
169             pixelstep[c->plane] != c->step_minus1 + 1)
170             return AVERROR(ENOSYS);
171         pixelstep[c->plane] = c->step_minus1 + 1;
172         if (pixelstep[c->plane] >= 8)
173             return AVERROR(ENOSYS);
174         nb_planes = FFMAX(nb_planes, c->plane + 1);
175     }
176     if ((desc->log2_chroma_w || desc->log2_chroma_h) && nb_planes < 3)
177         return AVERROR(ENOSYS); /* exclude NV12 and NV21 */
178     memset(draw, 0, sizeof(*draw));
179     draw->desc      = desc;
180     draw->format    = format;
181     draw->nb_planes = nb_planes;
182     memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));
183     if (nb_planes >= 3 && !(desc->flags & AV_PIX_FMT_FLAG_RGB)) {
184         draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;
185         draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;
186     }
187     for (i = 0; i < ((desc->nb_components - 1) | 1); i++)
188         draw->comp_mask[desc->comp[i].plane] |=
189             1 << (desc->comp[i].offset_plus1 - 1);
190     return 0;
191 }
192
193 void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
194 {
195     unsigned i;
196     uint8_t rgba_map[4];
197
198     if (rgba != color->rgba)
199         memcpy(color->rgba, rgba, sizeof(color->rgba));
200     if ((draw->desc->flags & AV_PIX_FMT_FLAG_RGB) && draw->nb_planes == 1 &&
201         ff_fill_rgba_map(rgba_map, draw->format) >= 0) {
202         for (i = 0; i < 4; i++)
203             color->comp[0].u8[rgba_map[i]] = rgba[i];
204     } else if (draw->nb_planes == 3 || draw->nb_planes == 4) {
205         /* assume YUV */
206         color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
207         color->comp[1].u8[0] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
208         color->comp[2].u8[0] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
209         color->comp[3].u8[0] = rgba[3];
210     } else if (draw->format == AV_PIX_FMT_GRAY8 || draw->format == AV_PIX_FMT_GRAY8A) {
211         color->comp[0].u8[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
212         color->comp[1].u8[0] = rgba[3];
213     } else {
214         av_log(NULL, AV_LOG_WARNING,
215                "Color conversion not implemented for %s\n", draw->desc->name);
216         memset(color, 128, sizeof(*color));
217     }
218 }
219
220 static uint8_t *pointer_at(FFDrawContext *draw, uint8_t *data[], int linesize[],
221                            int plane, int x, int y)
222 {
223     return data[plane] +
224            (y >> draw->vsub[plane]) * linesize[plane] +
225            (x >> draw->hsub[plane]) * draw->pixelstep[plane];
226 }
227
228 void ff_copy_rectangle2(FFDrawContext *draw,
229                         uint8_t *dst[], int dst_linesize[],
230                         uint8_t *src[], int src_linesize[],
231                         int dst_x, int dst_y, int src_x, int src_y,
232                         int w, int h)
233 {
234     int plane, y, wp, hp;
235     uint8_t *p, *q;
236
237     for (plane = 0; plane < draw->nb_planes; plane++) {
238         p = pointer_at(draw, src, src_linesize, plane, src_x, src_y);
239         q = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
240         wp = FF_CEIL_RSHIFT(w, draw->hsub[plane]) * draw->pixelstep[plane];
241         hp = FF_CEIL_RSHIFT(h, draw->vsub[plane]);
242         for (y = 0; y < hp; y++) {
243             memcpy(q, p, wp);
244             p += src_linesize[plane];
245             q += dst_linesize[plane];
246         }
247     }
248 }
249
250 void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color,
251                        uint8_t *dst[], int dst_linesize[],
252                        int dst_x, int dst_y, int w, int h)
253 {
254     int plane, x, y, wp, hp;
255     uint8_t *p0, *p;
256
257     for (plane = 0; plane < draw->nb_planes; plane++) {
258         p0 = pointer_at(draw, dst, dst_linesize, plane, dst_x, dst_y);
259         wp = FF_CEIL_RSHIFT(w, draw->hsub[plane]);
260         hp = FF_CEIL_RSHIFT(h, draw->vsub[plane]);
261         if (!hp)
262             return;
263         p = p0;
264         /* copy first line from color */
265         for (x = 0; x < wp; x++) {
266             memcpy(p, color->comp[plane].u8, draw->pixelstep[plane]);
267             p += draw->pixelstep[plane];
268         }
269         wp *= draw->pixelstep[plane];
270         /* copy next lines from first line */
271         p = p0 + dst_linesize[plane];
272         for (y = 1; y < hp; y++) {
273             memcpy(p, p0, wp);
274             p += dst_linesize[plane];
275         }
276     }
277 }
278
279 /**
280  * Clip interval [x; x+w[ within [0; wmax[.
281  * The resulting w may be negative if the final interval is empty.
282  * dx, if not null, return the difference between in and out value of x.
283  */
284 static void clip_interval(int wmax, int *x, int *w, int *dx)
285 {
286     if (dx)
287         *dx = 0;
288     if (*x < 0) {
289         if (dx)
290             *dx = -*x;
291         *w += *x;
292         *x = 0;
293     }
294     if (*x + *w > wmax)
295         *w = wmax - *x;
296 }
297
298 /**
299  * Decompose w pixels starting at x
300  * into start + (w starting at x) + end
301  * with x and w aligned on multiples of 1<<sub.
302  */
303 static void subsampling_bounds(int sub, int *x, int *w, int *start, int *end)
304 {
305     int mask = (1 << sub) - 1;
306
307     *start = (-*x) & mask;
308     *x += *start;
309     *start = FFMIN(*start, *w);
310     *w -= *start;
311     *end = *w & mask;
312     *w >>= sub;
313 }
314
315 static int component_used(FFDrawContext *draw, int plane, int comp)
316 {
317     return (draw->comp_mask[plane] >> comp) & 1;
318 }
319
320 /* If alpha is in the [ 0 ; 0x1010101 ] range,
321    then alpha * value is in the [ 0 ; 0xFFFFFFFF ] range,
322    and >> 24 gives a correct rounding. */
323 static void blend_line(uint8_t *dst, unsigned src, unsigned alpha,
324                        int dx, int w, unsigned hsub, int left, int right)
325 {
326     unsigned asrc = alpha * src;
327     unsigned tau = 0x1010101 - alpha;
328     int x;
329
330     if (left) {
331         unsigned suba = (left * alpha) >> hsub;
332         *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
333         dst += dx;
334     }
335     for (x = 0; x < w; x++) {
336         *dst = (*dst * tau + asrc) >> 24;
337         dst += dx;
338     }
339     if (right) {
340         unsigned suba = (right * alpha) >> hsub;
341         *dst = (*dst * (0x1010101 - suba) + src * suba) >> 24;
342     }
343 }
344
345 void ff_blend_rectangle(FFDrawContext *draw, FFDrawColor *color,
346                         uint8_t *dst[], int dst_linesize[],
347                         int dst_w, int dst_h,
348                         int x0, int y0, int w, int h)
349 {
350     unsigned alpha, nb_planes, nb_comp, plane, comp;
351     int w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
352     uint8_t *p0, *p;
353
354     /* TODO optimize if alpha = 0xFF */
355     clip_interval(dst_w, &x0, &w, NULL);
356     clip_interval(dst_h, &y0, &h, NULL);
357     if (w <= 0 || h <= 0 || !color->rgba[3])
358         return;
359     /* 0x10203 * alpha + 2 is in the [ 2 ; 0x1010101 - 2 ] range */
360     alpha = 0x10203 * color->rgba[3] + 0x2;
361     nb_planes = (draw->nb_planes - 1) | 1; /* eliminate alpha */
362     for (plane = 0; plane < nb_planes; plane++) {
363         nb_comp = draw->pixelstep[plane];
364         p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
365         w_sub = w;
366         h_sub = h;
367         x_sub = x0;
368         y_sub = y0;
369         subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
370         subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
371         for (comp = 0; comp < nb_comp; comp++) {
372             if (!component_used(draw, plane, comp))
373                 continue;
374             p = p0 + comp;
375             if (top) {
376                 blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
377                            draw->pixelstep[plane], w_sub,
378                            draw->hsub[plane], left, right);
379                 p += dst_linesize[plane];
380             }
381             for (y = 0; y < h_sub; y++) {
382                 blend_line(p, color->comp[plane].u8[comp], alpha,
383                            draw->pixelstep[plane], w_sub,
384                            draw->hsub[plane], left, right);
385                 p += dst_linesize[plane];
386             }
387             if (bottom)
388                 blend_line(p, color->comp[plane].u8[comp], alpha >> 1,
389                            draw->pixelstep[plane], w_sub,
390                            draw->hsub[plane], left, right);
391         }
392     }
393 }
394
395 static void blend_pixel(uint8_t *dst, unsigned src, unsigned alpha,
396                         uint8_t *mask, int mask_linesize, int l2depth,
397                         unsigned w, unsigned h, unsigned shift, unsigned xm0)
398 {
399     unsigned xm, x, y, t = 0;
400     unsigned xmshf = 3 - l2depth;
401     unsigned xmmod = 7 >> l2depth;
402     unsigned mbits = (1 << (1 << l2depth)) - 1;
403     unsigned mmult = 255 / mbits;
404
405     for (y = 0; y < h; y++) {
406         xm = xm0;
407         for (x = 0; x < w; x++) {
408             t += ((mask[xm >> xmshf] >> ((~xm & xmmod) << l2depth)) & mbits)
409                  * mmult;
410             xm++;
411         }
412         mask += mask_linesize;
413     }
414     alpha = (t >> shift) * alpha;
415     *dst = ((0x1010101 - alpha) * *dst + alpha * src) >> 24;
416 }
417
418 static void blend_line_hv(uint8_t *dst, int dst_delta,
419                           unsigned src, unsigned alpha,
420                           uint8_t *mask, int mask_linesize, int l2depth, int w,
421                           unsigned hsub, unsigned vsub,
422                           int xm, int left, int right, int hband)
423 {
424     int x;
425
426     if (left) {
427         blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
428                     left, hband, hsub + vsub, xm);
429         dst += dst_delta;
430         xm += left;
431     }
432     for (x = 0; x < w; x++) {
433         blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
434                     1 << hsub, hband, hsub + vsub, xm);
435         dst += dst_delta;
436         xm += 1 << hsub;
437     }
438     if (right)
439         blend_pixel(dst, src, alpha, mask, mask_linesize, l2depth,
440                     right, hband, hsub + vsub, xm);
441 }
442
443 void ff_blend_mask(FFDrawContext *draw, FFDrawColor *color,
444                    uint8_t *dst[], int dst_linesize[], int dst_w, int dst_h,
445                    uint8_t *mask,  int mask_linesize, int mask_w, int mask_h,
446                    int l2depth, unsigned endianness, int x0, int y0)
447 {
448     unsigned alpha, nb_planes, nb_comp, plane, comp;
449     int xm0, ym0, w_sub, h_sub, x_sub, y_sub, left, right, top, bottom, y;
450     uint8_t *p0, *p, *m;
451
452     clip_interval(dst_w, &x0, &mask_w, &xm0);
453     clip_interval(dst_h, &y0, &mask_h, &ym0);
454     mask += ym0 * mask_linesize;
455     if (mask_w <= 0 || mask_h <= 0 || !color->rgba[3])
456         return;
457     /* alpha is in the [ 0 ; 0x10203 ] range,
458        alpha * mask is in the [ 0 ; 0x1010101 - 4 ] range */
459     alpha = (0x10307 * color->rgba[3] + 0x3) >> 8;
460     nb_planes = (draw->nb_planes - 1) | 1; /* eliminate alpha */
461     for (plane = 0; plane < nb_planes; plane++) {
462         nb_comp = draw->pixelstep[plane];
463         p0 = pointer_at(draw, dst, dst_linesize, plane, x0, y0);
464         w_sub = mask_w;
465         h_sub = mask_h;
466         x_sub = x0;
467         y_sub = y0;
468         subsampling_bounds(draw->hsub[plane], &x_sub, &w_sub, &left, &right);
469         subsampling_bounds(draw->vsub[plane], &y_sub, &h_sub, &top, &bottom);
470         for (comp = 0; comp < nb_comp; comp++) {
471             if (!component_used(draw, plane, comp))
472                 continue;
473             p = p0 + comp;
474             m = mask;
475             if (top) {
476                 blend_line_hv(p, draw->pixelstep[plane],
477                               color->comp[plane].u8[comp], alpha,
478                               m, mask_linesize, l2depth, w_sub,
479                               draw->hsub[plane], draw->vsub[plane],
480                               xm0, left, right, top);
481                 p += dst_linesize[plane];
482                 m += top * mask_linesize;
483             }
484             for (y = 0; y < h_sub; y++) {
485                 blend_line_hv(p, draw->pixelstep[plane],
486                               color->comp[plane].u8[comp], alpha,
487                               m, mask_linesize, l2depth, w_sub,
488                               draw->hsub[plane], draw->vsub[plane],
489                               xm0, left, right, 1 << draw->vsub[plane]);
490                 p += dst_linesize[plane];
491                 m += mask_linesize << draw->vsub[plane];
492             }
493             if (bottom)
494                 blend_line_hv(p, draw->pixelstep[plane],
495                               color->comp[plane].u8[comp], alpha,
496                               m, mask_linesize, l2depth, w_sub,
497                               draw->hsub[plane], draw->vsub[plane],
498                               xm0, left, right, bottom);
499         }
500     }
501 }
502
503 int ff_draw_round_to_sub(FFDrawContext *draw, int sub_dir, int round_dir,
504                          int value)
505 {
506     unsigned shift = sub_dir ? draw->vsub_max : draw->hsub_max;
507
508     if (!shift)
509         return value;
510     if (round_dir >= 0)
511         value += round_dir ? (1 << shift) - 1 : 1 << (shift - 1);
512     return (value >> shift) << shift;
513 }
514
515 AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags)
516 {
517     enum AVPixelFormat i, pix_fmts[AV_PIX_FMT_NB + 1];
518     unsigned n = 0;
519     FFDrawContext draw;
520
521     for (i = 0; i < AV_PIX_FMT_NB; i++)
522         if (ff_draw_init(&draw, i, flags) >= 0)
523             pix_fmts[n++] = i;
524     pix_fmts[n++] = AV_PIX_FMT_NONE;
525     return ff_make_format_list(pix_fmts);
526 }
527
528 #ifdef TEST
529
530 #undef printf
531
532 int main(void)
533 {
534     enum AVPixelFormat f;
535     const AVPixFmtDescriptor *desc;
536     FFDrawContext draw;
537     FFDrawColor color;
538     int r, i;
539
540     for (f = 0; f < AV_PIX_FMT_NB; f++) {
541         desc = av_pix_fmt_desc_get(f);
542         if (!desc->name)
543             continue;
544         printf("Testing %s...%*s", desc->name,
545                (int)(16 - strlen(desc->name)), "");
546         r = ff_draw_init(&draw, f, 0);
547         if (r < 0) {
548             char buf[128];
549             av_strerror(r, buf, sizeof(buf));
550             printf("no: %s\n", buf);
551             continue;
552         }
553         ff_draw_color(&draw, &color, (uint8_t[]) { 1, 0, 0, 1 });
554         for (i = 0; i < sizeof(color); i++)
555             if (((uint8_t *)&color)[i] != 128)
556                 break;
557         if (i == sizeof(color)) {
558             printf("fallback color\n");
559             continue;
560         }
561         printf("ok\n");
562     }
563     return 0;
564 }
565
566 #endif