Copy what's done for rgbtest_fill_picture. It will be useful for the following commit.
Showing the changes to libavfilter/drawutils.c (1 of 3 files). Show all
Unified · Split
| @@ -32,19 +32,17 @@ · 31 unmodified lines | ||
| 32 | 32 | |
| 33 | 33 | enum { RED = 0, GREEN, BLUE, ALPHA }; |
| 34 | 34 | |
| 35 | −int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt) | |
| 35 | +static int fill_map(const AVPixFmtDescriptor *desc, uint8_t *map) | |
| 36 | 36 | { |
| 37 | − const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 38 | − if (!(desc->flags & AV_PIX_FMT_FLAG_RGB)) | |
| 39 | − return AVERROR(EINVAL); | |
| 40 | − if (desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) | |
| 37 | + if (desc->flags & (AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_HWACCEL | | |
| 38 | + AV_PIX_FMT_FLAG_BAYER | AV_PIX_FMT_FLAG_XYZ | AV_PIX_FMT_FLAG_PAL)) | |
| 41 | 39 | return AVERROR(EINVAL); |
| 42 | 40 | av_assert0(desc->nb_components == 3 + !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA)); |
| 43 | 41 | if (desc->flags & AV_PIX_FMT_FLAG_PLANAR) { |
| 44 | − rgba_map[RED] = desc->comp[0].plane; | |
| 45 | − rgba_map[GREEN] = desc->comp[1].plane; | |
| 46 | − rgba_map[BLUE] = desc->comp[2].plane; | |
| 47 | − rgba_map[ALPHA] = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? desc->comp[3].plane : 3; | |
| 42 | + map[RED] = desc->comp[0].plane; | |
| 43 | + map[GREEN] = desc->comp[1].plane; | |
| 44 | + map[BLUE] = desc->comp[2].plane; | |
| 45 | + map[ALPHA] = (desc->flags & AV_PIX_FMT_FLAG_ALPHA) ? desc->comp[3].plane : 3; | |
| 48 | 46 | } else { |
| 49 | 47 | int had0 = 0; |
| 50 | 48 | unsigned depthb = 0; |
| @@ -60,24 +58,40 @@ int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt) · 9 unmodified lines | ||
| 60 | 58 | return AVERROR(ENOSYS); |
| 61 | 59 | |
| 62 | 60 | had0 |= pos == 0; |
| 63 | − rgba_map[i] = pos; | |
| 61 | + map[i] = pos; | |
| 64 | 62 | depthb = db; |
| 65 | 63 | } |
| 66 | 64 | |
| 67 | 65 | if (desc->nb_components == 3) |
| 68 | − rgba_map[ALPHA] = had0 ? 3 : 0; | |
| 66 | + map[ALPHA] = had0 ? 3 : 0; | |
| 69 | 67 | } |
| 70 | 68 | |
| 71 | − av_assert0(rgba_map[RED] != rgba_map[GREEN]); | |
| 72 | − av_assert0(rgba_map[GREEN] != rgba_map[BLUE]); | |
| 73 | − av_assert0(rgba_map[BLUE] != rgba_map[RED]); | |
| 74 | − av_assert0(rgba_map[RED] != rgba_map[ALPHA]); | |
| 75 | − av_assert0(rgba_map[GREEN] != rgba_map[ALPHA]); | |
| 76 | − av_assert0(rgba_map[BLUE] != rgba_map[ALPHA]); | |
| 69 | + av_assert0(map[RED] != map[GREEN]); | |
| 70 | + av_assert0(map[GREEN] != map[BLUE]); | |
| 71 | + av_assert0(map[BLUE] != map[RED]); | |
| 72 | + av_assert0(map[RED] != map[ALPHA]); | |
| 73 | + av_assert0(map[GREEN] != map[ALPHA]); | |
| 74 | + av_assert0(map[BLUE] != map[ALPHA]); | |
| 77 | 75 | |
| 78 | 76 | return 0; |
| 79 | 77 | } |
| 80 | 78 | |
| 79 | +int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt) | |
| 80 | +{ | |
| 81 | + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 82 | + if (!(desc->flags & AV_PIX_FMT_FLAG_RGB)) | |
| 83 | + return AVERROR(EINVAL); | |
| 84 | + return fill_map(desc, rgba_map); | |
| 85 | +} | |
| 86 | + | |
| 87 | +int ff_fill_ayuv_map(uint8_t *ayuv_map, enum AVPixelFormat pix_fmt) | |
| 88 | +{ | |
| 89 | + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 90 | + if (desc->flags & AV_PIX_FMT_FLAG_RGB) | |
| 91 | + return AVERROR(EINVAL); | |
| 92 | + return fill_map(desc, ayuv_map); | |
| 93 | +} | |
| 94 | + | |
| 81 | 95 | int ff_draw_init2(FFDrawContext *draw, enum AVPixelFormat format, enum AVColorSpace csp, |
| 82 | 96 | enum AVColorRange range, unsigned flags) |
| 83 | 97 | { |