| Line | Branch | Exec | Source |
|---|---|---|---|
| 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/avassert.h" | ||
| 22 | #include "libavutil/common.h" | ||
| 23 | #include "libavutil/error.h" | ||
| 24 | #include "libavutil/gain_map.h" | ||
| 25 | #include "libavutil/mem.h" | ||
| 26 | #include "libavutil/rational.h" | ||
| 27 | |||
| 28 | #include "bytestream.h" | ||
| 29 | #include "gain_map.h" | ||
| 30 | |||
| 31 | 3 | int ff_gain_map_params_check_xmp(const AVGainMapParams *p) | |
| 32 | { | ||
| 33 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (av_gain_map_params_validate(p) < 0) |
| 34 | ✗ | return 0; | |
| 35 | |||
| 36 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (p->version > FF_GAIN_MAP_VERSION) |
| 37 | ✗ | return 0; /* e.g. libraries out of sync */ | |
| 38 | |||
| 39 | /* XMP gain maps only store one set of parameters (shared across channels), | ||
| 40 | * have no way to describe a map applied in the alternate rendition's | ||
| 41 | * color space, and explicitly reject no-op parameters */ | ||
| 42 | ✗ | return (p->nb_channels == 1 || av_gain_map_channels_identical(p)) && | |
| 43 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
6 | p->use_base_color_space && |
| 44 | 3 | av_cmp_q(p->alternate_hdr_headroom, p->base_hdr_headroom) != 0; | |
| 45 | } | ||
| 46 | |||
| 47 | #define XMP_GAIN_MAP_TEMPLATE \ | ||
| 48 | "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"XMP Core 5.5.0\">\n" \ | ||
| 49 | " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" \ | ||
| 50 | " <rdf:Description rdf:about=\"\"\n" \ | ||
| 51 | " xmlns:hdrgm=\"" FF_GAIN_MAP_XMP_NAMESPACE "\"\n" \ | ||
| 52 | " hdrgm:Version=\"1.0\"\n" \ | ||
| 53 | " hdrgm:GainMapMin=\"%g\"\n" \ | ||
| 54 | " hdrgm:GainMapMax=\"%g\"\n" \ | ||
| 55 | " hdrgm:Gamma=\"%g\"\n" \ | ||
| 56 | " hdrgm:OffsetSDR=\"%g\"\n" \ | ||
| 57 | " hdrgm:OffsetHDR=\"%g\"\n" \ | ||
| 58 | " hdrgm:HDRCapacityMin=\"%g\"\n" \ | ||
| 59 | " hdrgm:HDRCapacityMax=\"%g\"\n" \ | ||
| 60 | " hdrgm:BaseRenditionIsHDR=\"%s\"/>\n" \ | ||
| 61 | " </rdf:RDF>\n" \ | ||
| 62 | "</x:xmpmeta>" | ||
| 63 | |||
| 64 | static_assert(FF_GAIN_MAP_XMP_MAX_LEN > sizeof(XMP_GAIN_MAP_TEMPLATE) + 8 * 10, | ||
| 65 | "XMP buffer too small for template and values"); | ||
| 66 | |||
| 67 | 1 | int ff_gain_map_params_to_xmp(const AVGainMapParams *p, char *buf) | |
| 68 | { | ||
| 69 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (!p || !buf) |
| 70 | ✗ | return AVERROR(EINVAL); | |
| 71 | |||
| 72 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!ff_gain_map_params_check_xmp(p)) |
| 73 | ✗ | return AVERROR(ENOTSUP); | |
| 74 | |||
| 75 | 1 | const struct AVGainMapChannel *const ch = &p->channels[0]; | |
| 76 | 1 | AVRational offset_sdr = ch->base_offset; | |
| 77 | 1 | AVRational offset_hdr = ch->alternate_offset; | |
| 78 | 1 | AVRational hdr_cap_min = p->base_hdr_headroom; | |
| 79 | 1 | AVRational hdr_cap_max = p->alternate_hdr_headroom; | |
| 80 | |||
| 81 | 1 | const int base_is_hdr = av_cmp_q(p->base_hdr_headroom, | |
| 82 | 1 | p->alternate_hdr_headroom) > 0; | |
| 83 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (base_is_hdr) { |
| 84 | ✗ | FFSWAP(AVRational, offset_sdr, offset_hdr); | |
| 85 | ✗ | FFSWAP(AVRational, hdr_cap_min, hdr_cap_max); | |
| 86 | } | ||
| 87 | |||
| 88 | 1 | const size_t size = FF_GAIN_MAP_XMP_MAX_LEN; | |
| 89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | int ret = snprintf(buf, size, XMP_GAIN_MAP_TEMPLATE, |
| 90 | av_q2d(ch->gain_map_min), av_q2d(ch->gain_map_max), | ||
| 91 | av_q2d(ch->gamma), | ||
| 92 | av_q2d(offset_sdr), av_q2d(offset_hdr), | ||
| 93 | av_q2d(hdr_cap_min), av_q2d(hdr_cap_max), | ||
| 94 | base_is_hdr ? "True" : "False"); | ||
| 95 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (ret < 0 || ret >= size) |
| 96 | ✗ | return AVERROR_BUG; | |
| 97 | |||
| 98 | 1 | return ret; | |
| 99 | } | ||
| 100 |