Unified · Split
| @@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest within each release, · 1 unmodified line | |||
| 2 | releases are sorted from youngest to oldest. | 2 | releases are sorted from youngest to oldest. |
| 3 | 3 | ||
| 4 | version <next>: | 4 | version <next>: |
| 5 | - Radiance HDR image support | ||
| 5 | 6 | ||
| 6 | 7 | ||
| 7 | version 5.1: | 8 | version 5.1: |
| @@ -749,6 +749,8 @@ following image formats are supported: · 748 unmodified lines | |||
| 749 | @tab OpenEXR | 749 | @tab OpenEXR |
| 750 | @item FITS @tab X @tab X | 750 | @item FITS @tab X @tab X |
| 751 | @tab Flexible Image Transport System | 751 | @tab Flexible Image Transport System |
| 752 | @item HDR @tab X @tab X | ||
| 753 | @tab Radiance HDR RGBE Image format | ||
| 752 | @item IMG @tab @tab X | 754 | @item IMG @tab @tab X |
| 753 | @tab GEM Raster image | 755 | @tab GEM Raster image |
| 754 | @item JPEG @tab X @tab X | 756 | @item JPEG @tab X @tab X |
| @@ -403,6 +403,8 @@ OBJS-$(CONFIG_HAP_DECODER) += hapdec.o hap.o · 402 unmodified lines | |||
| 403 | OBJS-$(CONFIG_HAP_ENCODER) += hapenc.o hap.o | 403 | OBJS-$(CONFIG_HAP_ENCODER) += hapenc.o hap.o |
| 404 | OBJS-$(CONFIG_HCA_DECODER) += hcadec.o | 404 | OBJS-$(CONFIG_HCA_DECODER) += hcadec.o |
| 405 | OBJS-$(CONFIG_HCOM_DECODER) += hcom.o | 405 | OBJS-$(CONFIG_HCOM_DECODER) += hcom.o |
| 406 | OBJS-$(CONFIG_HDR_DECODER) += hdrdec.o | ||
| 407 | OBJS-$(CONFIG_HDR_ENCODER) += hdrenc.o | ||
| 406 | OBJS-$(CONFIG_HEVC_DECODER) += hevcdec.o hevc_mvs.o \ | 408 | OBJS-$(CONFIG_HEVC_DECODER) += hevcdec.o hevc_mvs.o \ |
| 407 | hevc_cabac.o hevc_refs.o hevcpred.o \ | 409 | hevc_cabac.o hevc_refs.o hevcpred.o \ |
| 408 | hevcdsp.o hevc_filter.o hevc_data.o \ | 410 | hevcdsp.o hevc_filter.o hevc_data.o \ |
| @@ -1142,6 +1144,7 @@ OBJS-$(CONFIG_H261_PARSER) += h261_parser.o · 733 unmodified lines | |||
| 1142 | OBJS-$(CONFIG_H263_PARSER) += h263_parser.o | 1144 | OBJS-$(CONFIG_H263_PARSER) += h263_parser.o |
| 1143 | OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264_sei.o h264data.o | 1145 | OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264_sei.o h264data.o |
| 1144 | OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o | 1146 | OBJS-$(CONFIG_HEVC_PARSER) += hevc_parser.o hevc_data.o |
| 1147 | OBJS-$(CONFIG_HDR_PARSER) += hdr_parser.o | ||
| 1145 | OBJS-$(CONFIG_IPU_PARSER) += ipu_parser.o | 1148 | OBJS-$(CONFIG_IPU_PARSER) += ipu_parser.o |
| 1146 | OBJS-$(CONFIG_JPEG2000_PARSER) += jpeg2000_parser.o | 1149 | OBJS-$(CONFIG_JPEG2000_PARSER) += jpeg2000_parser.o |
| 1147 | OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o | 1150 | OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o |
| @@ -469,6 +469,8 @@ extern const FFCodec ff_gsm_decoder; · 468 unmodified lines | |||
| 469 | extern const FFCodec ff_gsm_ms_decoder; | 469 | extern const FFCodec ff_gsm_ms_decoder; |
| 470 | extern const FFCodec ff_hca_decoder; | 470 | extern const FFCodec ff_hca_decoder; |
| 471 | extern const FFCodec ff_hcom_decoder; | 471 | extern const FFCodec ff_hcom_decoder; |
| 472 | extern const FFCodec ff_hdr_encoder; | ||
| 473 | extern const FFCodec ff_hdr_decoder; | ||
| 472 | extern const FFCodec ff_iac_decoder; | 474 | extern const FFCodec ff_iac_decoder; |
| 473 | extern const FFCodec ff_ilbc_decoder; | 475 | extern const FFCodec ff_ilbc_decoder; |
| 474 | extern const FFCodec ff_imc_decoder; | 476 | extern const FFCodec ff_imc_decoder; |
| @@ -1893,6 +1893,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 1892 unmodified lines | |||
| 1893 | .long_name = NULL_IF_CONFIG_SMALL("PHM (Portable HalfFloatMap) image"), | 1893 | .long_name = NULL_IF_CONFIG_SMALL("PHM (Portable HalfFloatMap) image"), |
| 1894 | .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, | 1894 | .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, |
| 1895 | }, | 1895 | }, |
| 1896 | { | ||
| 1897 | .id = AV_CODEC_ID_RADIANCE_HDR, | ||
| 1898 | .type = AVMEDIA_TYPE_VIDEO, | ||
| 1899 | .name = "hdr", | ||
| 1900 | .long_name = NULL_IF_CONFIG_SMALL("HDR (Radiance RGBE format) image"), | ||
| 1901 | .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, | ||
| 1902 | }, | ||
| 1896 | 1903 | ||
| 1897 | /* various PCM "codecs" */ | 1904 | /* various PCM "codecs" */ |
| 1898 | { | 1905 | { |
| @@ -312,6 +312,7 @@ enum AVCodecID { · 311 unmodified lines | |||
| 312 | AV_CODEC_ID_JPEGXL, | 312 | AV_CODEC_ID_JPEGXL, |
| 313 | AV_CODEC_ID_QOI, | 313 | AV_CODEC_ID_QOI, |
| 314 | AV_CODEC_ID_PHM, | 314 | AV_CODEC_ID_PHM, |
| 315 | AV_CODEC_ID_RADIANCE_HDR, | ||
| 315 | 316 | ||
| 316 | /* various PCM "codecs" */ | 317 | /* various PCM "codecs" */ |
| 317 | AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs | 318 | AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs |
| @@ -0,0 +1,79 @@ | |||
| 1 | /* | ||
| 2 | * Radiance HDR parser | ||
| 3 | * Copyright (c) 2022 Paul B Mahol | ||
| 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 | /** | ||
| 23 | * @file | ||
| 24 | * Radiance HDR parser | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include "libavutil/intreadwrite.h" | ||
| 28 | #include "parser.h" | ||
| 29 | |||
| 30 | typedef struct HDRParseContext { | ||
| 31 | ParseContext pc; | ||
| 32 | } HDRParseContext; | ||
| 33 | |||
| 34 | static int hdr_parse(AVCodecParserContext *s, AVCodecContext *avctx, | ||
| 35 | const uint8_t **poutbuf, int *poutbuf_size, | ||
| 36 | const uint8_t *buf, int buf_size) | ||
| 37 | { | ||
| 38 | HDRParseContext *ipc = s->priv_data; | ||
| 39 | uint64_t state = ipc->pc.state64; | ||
| 40 | int next = END_NOT_FOUND, i = 0; | ||
| 41 | |||
| 42 | *poutbuf_size = 0; | ||
| 43 | *poutbuf = NULL; | ||
| 44 | |||
| 45 | if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { | ||
| 46 | next = buf_size; | ||
| 47 | } else { | ||
| 48 | for (; i < buf_size; i++) { | ||
| 49 | state = (state << 8) | buf[i]; | ||
| 50 | if (state == AV_RB64("ADIANCE\n") && (i > 10 || ipc->pc.index > 10)) { | ||
| 51 | next = i - 10; | ||
| 52 | break; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | ipc->pc.state64 = state; | ||
| 57 | if (ff_combine_frame(&ipc->pc, next, &buf, &buf_size) < 0) { | ||
| 58 | *poutbuf = NULL; | ||
| 59 | *poutbuf_size = 0; | ||
| 60 | return buf_size; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | *poutbuf = buf; | ||
| 65 | *poutbuf_size = buf_size; | ||
| 66 | |||
| 67 | s->pict_type = AV_PICTURE_TYPE_I; | ||
| 68 | s->key_frame = 1; | ||
| 69 | s->duration = 1; | ||
| 70 | |||
| 71 | return next; | ||
| 72 | } | ||
| 73 | |||
| 74 | const AVCodecParser ff_hdr_parser = { | ||
| 75 | .codec_ids = { AV_CODEC_ID_RADIANCE_HDR }, | ||
| 76 | .priv_data_size = sizeof(HDRParseContext), | ||
| 77 | .parser_parse = hdr_parse, | ||
| 78 | .parser_close = ff_parse_close, | ||
| 79 | }; | ||
| @@ -0,0 +1,222 @@ | |||
| 1 | /* | ||
| 2 | * Radiance HDR image format | ||
| 3 | * | ||
| 4 | * This file is part of FFmpeg. | ||
| 5 | * | ||
| 6 | * FFmpeg is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with FFmpeg; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include <stdlib.h> | ||
| 22 | |||
| 23 | #include "libavutil/imgutils.h" | ||
| 24 | #include "avcodec.h" | ||
| 25 | #include "internal.h" | ||
| 26 | #include "bytestream.h" | ||
| 27 | #include "codec_internal.h" | ||
| 28 | #include "thread.h" | ||
| 29 | |||
| 30 | #define MINELEN 8 | ||
| 31 | #define MAXELEN 0x7fff | ||
| 32 | |||
| 33 | static int hdr_get_line(GetByteContext *gb, uint8_t *buffer, int size) | ||
| 34 | { | ||
| 35 | int n = 0, c; | ||
| 36 | |||
| 37 | memset(buffer, 0, size); | ||
| 38 | |||
| 39 | do { | ||
| 40 | c = bytestream2_get_byte(gb); | ||
| 41 | if (n < size - 1) | ||
| 42 | buffer[n++] = c; | ||
| 43 | } while (bytestream2_get_bytes_left(gb) > 0 && c != '\n'); | ||
| 44 | |||
| 45 | return 0; | ||
| 46 | } | ||
| 47 | |||
| 48 | static float convert(int expo, int val) | ||
| 49 | { | ||
| 50 | if (expo == -128) { | ||
| 51 | return 0.f; | ||
| 52 | } else { | ||
| 53 | const float v = val / 256.f; | ||
| 54 | |||
| 55 | return ldexpf(v, expo); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | static int decompress(uint8_t *scanline, int w, GetByteContext *gb, const uint8_t *start) | ||
| 60 | { | ||
| 61 | int rshift = 0; | ||
| 62 | |||
| 63 | while (w > 0) { | ||
| 64 | scanline[0] = bytestream2_get_byte(gb); | ||
| 65 | scanline[1] = bytestream2_get_byte(gb); | ||
| 66 | scanline[2] = bytestream2_get_byte(gb); | ||
| 67 | scanline[3] = bytestream2_get_byte(gb); | ||
| 68 | |||
| 69 | if (scanline[0] == 1 && | ||
| 70 | scanline[1] == 1 && | ||
| 71 | scanline[2] == 1) { | ||
| 72 | int run = scanline[3]; | ||
| 73 | for (int i = run << rshift; i > 0 && w > 0 && scanline >= start + 4; i--) { | ||
| 74 | memcpy(scanline, scanline - 4, 4); | ||
| 75 | scanline += 4; | ||
| 76 | } | ||
| 77 | w -= run << rshift; | ||
| 78 | rshift += 8; | ||
| 79 | if (rshift > 16) | ||
| 80 | break; | ||
| 81 | } else { | ||
| 82 | scanline += 4; | ||
| 83 | w--; | ||
| 84 | rshift = 0; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | return 1; | ||
| 89 | } | ||
| 90 | |||
| 91 | static int hdr_decode_frame(AVCodecContext *avctx, AVFrame *p, | ||
| 92 | int *got_frame, AVPacket *avpkt) | ||
| 93 | { | ||
| 94 | const uint8_t *buf = avpkt->data; | ||
| 95 | int ret, buf_size = avpkt->size; | ||
| 96 | int width = 0, height = 0; | ||
| 97 | GetByteContext gb; | ||
| 98 | uint8_t line[512]; | ||
| 99 | float sar; | ||
| 100 | |||
| 101 | bytestream2_init(&gb, buf, buf_size); | ||
| 102 | hdr_get_line(&gb, line, sizeof(line)); | ||
| 103 | if (memcmp("#?RADIANCE\n", line, 11)) | ||
| 104 | return AVERROR_INVALIDDATA; | ||
| 105 | |||
| 106 | do { | ||
| 107 | hdr_get_line(&gb, line, sizeof(line)); | ||
| 108 | if (sscanf(line, "PIXASPECT=%f\n", &sar) == 1) | ||
| 109 | avctx->sample_aspect_ratio = p->sample_aspect_ratio = av_inv_q(av_d2q(sar, 4096)); | ||
| 110 | } while (line[0] != '\n'); | ||
| 111 | |||
| 112 | hdr_get_line(&gb, line, sizeof(line)); | ||
| 113 | if (sscanf(line, "-Y %d +X %d\n", &height, &width) == 2) { | ||
| 114 | ; | ||
| 115 | } else if (sscanf(line, "+Y %d +X %d\n", &height, &width) == 2) { | ||
| 116 | ; | ||
| 117 | } else if (sscanf(line, "-Y %d -X %d\n", &height, &width) == 2) { | ||
| 118 | ; | ||
| 119 | } else if (sscanf(line, "+Y %d -X %d\n", &height, &width) == 2) { | ||
| 120 | ; | ||
| 121 | } else if (sscanf(line, "-X %d +Y %d\n", &width, &height) == 2) { | ||
| 122 | ; | ||
| 123 | } else if (sscanf(line, "+X %d +Y %d\n", &width, &height) == 2) { | ||
| 124 | ; | ||
| 125 | } else if (sscanf(line, "-X %d -Y %d\n", &width, &height) == 2) { | ||
| 126 | ; | ||
| 127 | } else if (sscanf(line, "+X %d -Y %d\n", &width, &height) == 2) { | ||
| 128 | ; | ||
| 129 | } | ||
| 130 | |||
| 131 | if ((ret = ff_set_dimensions(avctx, width, height)) < 0) | ||
| 132 | return ret; | ||
| 133 | |||
| 134 | avctx->pix_fmt = AV_PIX_FMT_GBRPF32; | ||
| 135 | if ((ret = ff_thread_get_buffer(avctx, p, 0)) < 0) | ||
| 136 | return ret; | ||
| 137 | |||
| 138 | for (int y = 0; y < height; y++) { | ||
| 139 | float *dst_r = (float *)(p->data[2] + y * p->linesize[2]); | ||
| 140 | float *dst_g = (float *)(p->data[0] + y * p->linesize[0]); | ||
| 141 | float *dst_b = (float *)(p->data[1] + y * p->linesize[1]); | ||
| 142 | uint8_t *scanline = p->data[0] + y * p->linesize[0]; | ||
| 143 | int i; | ||
| 144 | |||
| 145 | if (width < MINELEN || width > MAXELEN) { | ||
| 146 | decompress(scanline, width, &gb, scanline); | ||
| 147 | goto convert; | ||
| 148 | } | ||
| 149 | |||
| 150 | i = bytestream2_peek_byte(&gb); | ||
| 151 | if (i != 2) { | ||
| 152 | decompress(scanline, width, &gb, scanline); | ||
| 153 | goto convert; | ||
| 154 | } | ||
| 155 | bytestream2_skip(&gb, 1); | ||
| 156 | |||
| 157 | scanline[1] = bytestream2_get_byte(&gb); | ||
| 158 | scanline[2] = bytestream2_get_byte(&gb); | ||
| 159 | i = bytestream2_get_byte(&gb); | ||
| 160 | |||
| 161 | if (scanline[1] != 2 || scanline[2] & 128) { | ||
| 162 | scanline[0] = 2; | ||
| 163 | scanline[3] = i; | ||
| 164 | decompress(scanline + 4, width - 1, &gb, scanline); | ||
| 165 | goto convert; | ||
| 166 | } | ||
| 167 | |||
| 168 | for (int i = 0; i < 4; i++) { | ||
| 169 | uint8_t *scanline = p->data[0] + y * p->linesize[0] + i; | ||
| 170 | |||
| 171 | for (int j = 0; j < width * 4 && bytestream2_get_bytes_left(&gb) > 0;) { | ||
| 172 | int run = bytestream2_get_byte(&gb); | ||
| 173 | if (run > 128) { | ||
| 174 | uint8_t val = bytestream2_get_byte(&gb); | ||
| 175 | run &= 127; | ||
| 176 | while (run--) { | ||
| 177 | if (j >= width * 4) | ||
| 178 | break; | ||
| 179 | scanline[j] = val; | ||
| 180 | j += 4; | ||
| 181 | } | ||
| 182 | } else if (run > 0) { | ||
| 183 | while (run--) { | ||
| 184 | if (j >= width * 4) | ||
| 185 | break; | ||
| 186 | scanline[j] = bytestream2_get_byte(&gb); | ||
| 187 | j += 4; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | } | ||
| 191 | } | ||
| 192 | |||
| 193 | convert: | ||
| 194 | for (int x = 0; x < width; x++) { | ||
| 195 | uint8_t rgbe[4]; | ||
| 196 | int expo; | ||
| 197 | |||
| 198 | memcpy(rgbe, p->data[0] + y * p->linesize[0] + x * 4, 4); | ||
| 199 | expo = rgbe[3] - 128; | ||
| 200 | |||
| 201 | dst_r[x] = convert(expo, rgbe[0]); | ||
| 202 | dst_b[x] = convert(expo, rgbe[2]); | ||
| 203 | dst_g[x] = convert(expo, rgbe[1]); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 207 | p->key_frame = 1; | ||
| 208 | p->pict_type = AV_PICTURE_TYPE_I; | ||
| 209 | |||
| 210 | *got_frame = 1; | ||
| 211 | |||
| 212 | return buf_size; | ||
| 213 | } | ||
| 214 | |||
| 215 | const FFCodec ff_hdr_decoder = { | ||
| 216 | .p.name = "hdr", | ||
| 217 | .p.long_name = NULL_IF_CONFIG_SMALL("HDR (Radiance RGBE format) image"), | ||
| 218 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 219 | .p.id = AV_CODEC_ID_RADIANCE_HDR, | ||
| 220 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, | ||
| 221 | FF_CODEC_DECODE_CB(hdr_decode_frame), | ||
| 222 | }; | ||
| @@ -0,0 +1,189 @@ | |||
| 1 | /* | ||
| 2 | * Radiance HDR image format | ||
| 3 | * | ||
| 4 | * This file is part of FFmpeg. | ||
| 5 | * | ||
| 6 | * FFmpeg is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with FFmpeg; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include "libavutil/imgutils.h" | ||
| 22 | #include "avcodec.h" | ||
| 23 | #include "bytestream.h" | ||
| 24 | #include "codec_internal.h" | ||
| 25 | #include "encode.h" | ||
| 26 | |||
| 27 | typedef struct HDREncContext { | ||
| 28 | uint8_t *scanline; | ||
| 29 | } HDREncContext; | ||
| 30 | |||
| 31 | static av_cold int hdr_encode_init(AVCodecContext *avctx) | ||
| 32 | { | ||
| 33 | HDREncContext *s = avctx->priv_data; | ||
| 34 | |||
| 35 | s->scanline = av_calloc(avctx->width * 4, sizeof(*s->scanline)); | ||
| 36 | if (!s->scanline) | ||
| 37 | return AVERROR(ENOMEM); | ||
| 38 | |||
| 39 | return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | static av_cold int hdr_encode_close(AVCodecContext *avctx) | ||
| 43 | { | ||
| 44 | HDREncContext *s = avctx->priv_data; | ||
| 45 | |||
| 46 | av_freep(&s->scanline); | ||
| 47 | |||
| 48 | return 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | static void bytestream_put_str(uint8_t **buf, const char *const line) | ||
| 52 | { | ||
| 53 | bytestream_put_buffer(buf, line, strlen(line)); | ||
| 54 | } | ||
| 55 | |||
| 56 | static void float2rgbe(uint8_t *rgbe, float red, float green, float blue) | ||
| 57 | { | ||
| 58 | float v; | ||
| 59 | int e; | ||
| 60 | |||
| 61 | v = FFMAX3(red, green, blue); | ||
| 62 | |||
| 63 | if (v < 1e-32f) { | ||
| 64 | rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0; | ||
| 65 | } else { | ||
| 66 | v = frexpf(v, &e) * 256.f / v; | ||
| 67 | |||
| 68 | rgbe[0] = av_clip_uint8(red * v); | ||
| 69 | rgbe[1] = av_clip_uint8(green * v); | ||
| 70 | rgbe[2] = av_clip_uint8(blue * v); | ||
| 71 | rgbe[3] = av_clip_uint8(e + 128); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | static void rle(uint8_t **buffer, const uint8_t *data, int width) | ||
| 76 | { | ||
| 77 | #define MIN_RLE 4 | ||
| 78 | int cur = 0; | ||
| 79 | |||
| 80 | while (cur < width) { | ||
| 81 | int run_count = 0, old_run_count = 0; | ||
| 82 | int beg_run = cur; | ||
| 83 | uint8_t buf[2]; | ||
| 84 | |||
| 85 | while (run_count < MIN_RLE && beg_run < width) { | ||
| 86 | beg_run += run_count; | ||
| 87 | old_run_count = run_count; | ||
| 88 | run_count = 1; | ||
| 89 | while ((beg_run + run_count < width) && (run_count < 127) && | ||
| 90 | (data[beg_run * 4] == data[(beg_run + run_count) * 4])) | ||
| 91 | run_count++; | ||
| 92 | } | ||
| 93 | |||
| 94 | if ((old_run_count > 1) && (old_run_count == beg_run - cur)) { | ||
| 95 | buf[0] = 128 + old_run_count; | ||
| 96 | buf[1] = data[cur * 4]; | ||
| 97 | bytestream_put_buffer(buffer, buf, sizeof(buf)); | ||
| 98 | cur = beg_run; | ||
| 99 | } | ||
| 100 | |||
| 101 | while (cur < beg_run) { | ||
| 102 | int nonrun_count = FFMIN(128, beg_run - cur); | ||
| 103 | buf[0] = nonrun_count; | ||
| 104 | bytestream_put_byte(buffer, buf[0]); | ||
| 105 | for (int n = 0; n < nonrun_count; n++) | ||
| 106 | bytestream_put_byte(buffer, data[(cur + n) * 4]); | ||
| 107 | cur += nonrun_count; | ||
| 108 | } | ||
| 109 | |||
| 110 | if (run_count >= MIN_RLE) { | ||
| 111 | buf[0] = 128 + run_count; | ||
| 112 | buf[1] = data[beg_run * 4]; | ||
| 113 | bytestream_put_buffer(buffer, buf, sizeof(buf)); | ||
| 114 | cur += run_count; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | static int hdr_encode_frame(AVCodecContext *avctx, AVPacket *pkt, | ||
| 120 | const AVFrame *frame, int *got_packet) | ||
| 121 | { | ||
| 122 | HDREncContext *s = avctx->priv_data; | ||
| 123 | int64_t packet_size; | ||
| 124 | uint8_t *buf; | ||
| 125 | int ret; | ||
| 126 | |||
| 127 | packet_size = avctx->width * avctx->height * 4LL + 1024LL; | ||
| 128 | if ((ret = ff_get_encode_buffer(avctx, pkt, packet_size, 0)) < 0) | ||
| 129 | return ret; | ||
| 130 | |||
| 131 | buf = pkt->data; | ||
| 132 | bytestream_put_str(&buf, "#?RADIANCE\n"); | ||
| 133 | bytestream_put_str(&buf, "SOFTWARE=lavc\n"); | ||
| 134 | ret = snprintf(buf, 32, "PIXASPECT=%f\n", av_q2d(av_inv_q(avctx->sample_aspect_ratio))); | ||
| 135 | if (ret > 0) | ||
| 136 | buf += ret; | ||
| 137 | bytestream_put_str(&buf, "FORMAT=32-bit_rle_rgbe\n\n"); | ||
| 138 | ret = snprintf(buf, 32, "-Y %d +X %d\n", avctx->height, avctx->width); | ||
| 139 | if (ret > 0) | ||
| 140 | buf += ret; | ||
| 141 | |||
| 142 | for (int y = 0; y < avctx->height; y++) { | ||
| 143 | const float *red = (const float *)(frame->data[2] + y * frame->linesize[2]); | ||
| 144 | const float *green = (const float *)(frame->data[0] + y * frame->linesize[0]); | ||
| 145 | const float *blue = (const float *)(frame->data[1] + y * frame->linesize[1]); | ||
| 146 | |||
| 147 | if (avctx->width < 8 || avctx->width > 0x7fff) { | ||
| 148 | for (int x = 0; x < avctx->width; x++) { | ||
| 149 | float2rgbe(buf, red[x], green[x], blue[x]); | ||
| 150 | buf += 4; | ||
| 151 | } | ||
| 152 | } else { | ||
| 153 | bytestream_put_byte(&buf, 2); | ||
| 154 | bytestream_put_byte(&buf, 2); | ||
| 155 | bytestream_put_byte(&buf, avctx->width >> 8); | ||
| 156 | bytestream_put_byte(&buf, avctx->width & 0xFF); | ||
| 157 | |||
| 158 | for (int x = 0; x < avctx->width; x++) | ||
| 159 | float2rgbe(s->scanline + 4 * x, red[x], green[x], blue[x]); | ||
| 160 | for (int p = 0; p < 4; p++) | ||
| 161 | rle(&buf, s->scanline + p, avctx->width); | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | pkt->flags |= AV_PKT_FLAG_KEY; | ||
| 166 | |||
| 167 | av_shrink_packet(pkt, buf - pkt->data); | ||
| 168 | |||
| 169 | *got_packet = 1; | ||
| 170 | |||
| 171 | return 0; | ||
| 172 | } | ||
| 173 | |||
| 174 | const FFCodec ff_hdr_encoder = { | ||
| 175 | .p.name = "hdr", | ||
| 176 | .p.long_name = NULL_IF_CONFIG_SMALL("HDR (Radiance RGBE format) image"), | ||
| 177 | .priv_data_size = sizeof(HDREncContext), | ||
| 178 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 179 | .p.id = AV_CODEC_ID_RADIANCE_HDR, | ||
| 180 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, | ||
| 181 | .init = hdr_encode_init, | ||
| 182 | FF_CODEC_ENCODE_CB(hdr_encode_frame), | ||
| 183 | .close = hdr_encode_close, | ||
| 184 | .p.pix_fmts = (const enum AVPixelFormat[]){ | ||
| 185 | AV_PIX_FMT_GBRPF32, | ||
| 186 | AV_PIX_FMT_NONE | ||
| 187 | }, | ||
| 188 | .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, | ||
| 189 | }; | ||
| @@ -50,6 +50,7 @@ extern const AVCodecParser ff_h261_parser; · 49 unmodified lines | |||
| 50 | extern const AVCodecParser ff_h263_parser; | 50 | extern const AVCodecParser ff_h263_parser; |
| 51 | extern const AVCodecParser ff_h264_parser; | 51 | extern const AVCodecParser ff_h264_parser; |
| 52 | extern const AVCodecParser ff_hevc_parser; | 52 | extern const AVCodecParser ff_hevc_parser; |
| 53 | extern const AVCodecParser ff_hdr_parser; | ||
| 53 | extern const AVCodecParser ff_ipu_parser; | 54 | extern const AVCodecParser ff_ipu_parser; |
| 54 | extern const AVCodecParser ff_jpeg2000_parser; | 55 | extern const AVCodecParser ff_jpeg2000_parser; |
| 55 | extern const AVCodecParser ff_mjpeg_parser; | 56 | extern const AVCodecParser ff_mjpeg_parser; |
| @@ -29,7 +29,7 @@ · 28 unmodified lines | |||
| 29 | 29 | ||
| 30 | #include "version_major.h" | 30 | #include "version_major.h" |
| 31 | 31 | ||
| 32 | #define LIBAVCODEC_VERSION_MINOR 38 | 32 | #define LIBAVCODEC_VERSION_MINOR 39 |
| 33 | #define LIBAVCODEC_VERSION_MICRO 100 | 33 | #define LIBAVCODEC_VERSION_MICRO 100 |
| 34 | 34 | ||
| 35 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | 35 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| @@ -273,6 +273,7 @@ OBJS-$(CONFIG_IMAGE_DPX_PIPE_DEMUXER) += img2dec.o img2.o · 272 unmodified lines | |||
| 273 | OBJS-$(CONFIG_IMAGE_EXR_PIPE_DEMUXER) += img2dec.o img2.o | 273 | OBJS-$(CONFIG_IMAGE_EXR_PIPE_DEMUXER) += img2dec.o img2.o |
| 274 | OBJS-$(CONFIG_IMAGE_GEM_PIPE_DEMUXER) += img2dec.o img2.o | 274 | OBJS-$(CONFIG_IMAGE_GEM_PIPE_DEMUXER) += img2dec.o img2.o |
| 275 | OBJS-$(CONFIG_IMAGE_GIF_PIPE_DEMUXER) += img2dec.o img2.o | 275 | OBJS-$(CONFIG_IMAGE_GIF_PIPE_DEMUXER) += img2dec.o img2.o |
| 276 | OBJS-$(CONFIG_IMAGE_HDR_PIPE_DEMUXER) += img2dec.o img2.o | ||
| 276 | OBJS-$(CONFIG_IMAGE_J2K_PIPE_DEMUXER) += img2dec.o img2.o | 277 | OBJS-$(CONFIG_IMAGE_J2K_PIPE_DEMUXER) += img2dec.o img2.o |
| 277 | OBJS-$(CONFIG_IMAGE_JPEG_PIPE_DEMUXER) += img2dec.o img2.o | 278 | OBJS-$(CONFIG_IMAGE_JPEG_PIPE_DEMUXER) += img2dec.o img2.o |
| 278 | OBJS-$(CONFIG_IMAGE_JPEGLS_PIPE_DEMUXER) += img2dec.o img2.o | 279 | OBJS-$(CONFIG_IMAGE_JPEGLS_PIPE_DEMUXER) += img2dec.o img2.o |
| @@ -508,6 +508,7 @@ extern const AVInputFormat ff_image_dpx_pipe_demuxer; · 507 unmodified lines | |||
| 508 | extern const AVInputFormat ff_image_exr_pipe_demuxer; | 508 | extern const AVInputFormat ff_image_exr_pipe_demuxer; |
| 509 | extern const AVInputFormat ff_image_gem_pipe_demuxer; | 509 | extern const AVInputFormat ff_image_gem_pipe_demuxer; |
| 510 | extern const AVInputFormat ff_image_gif_pipe_demuxer; | 510 | extern const AVInputFormat ff_image_gif_pipe_demuxer; |
| 511 | extern const AVInputFormat ff_image_hdr_pipe_demuxer; | ||
| 511 | extern const AVInputFormat ff_image_j2k_pipe_demuxer; | 512 | extern const AVInputFormat ff_image_j2k_pipe_demuxer; |
| 512 | extern const AVInputFormat ff_image_jpeg_pipe_demuxer; | 513 | extern const AVInputFormat ff_image_jpeg_pipe_demuxer; |
| 513 | extern const AVInputFormat ff_image_jpegls_pipe_demuxer; | 514 | extern const AVInputFormat ff_image_jpegls_pipe_demuxer; |
| @@ -91,6 +91,7 @@ const IdStrMap ff_img_tags[] = { · 90 unmodified lines | |||
| 91 | { AV_CODEC_ID_VBN, "vbn" }, | 91 | { AV_CODEC_ID_VBN, "vbn" }, |
| 92 | { AV_CODEC_ID_JPEGXL, "jxl" }, | 92 | { AV_CODEC_ID_JPEGXL, "jxl" }, |
| 93 | { AV_CODEC_ID_QOI, "qoi" }, | 93 | { AV_CODEC_ID_QOI, "qoi" }, |
| 94 | { AV_CODEC_ID_RADIANCE_HDR, "hdr" }, | ||
| 94 | { AV_CODEC_ID_NONE, NULL } | 95 | { AV_CODEC_ID_NONE, NULL } |
| 95 | }; | 96 | }; |
| 96 | 97 | ||
| @@ -1070,6 +1070,13 @@ static int pam_probe(const AVProbeData *p) · 1069 unmodified lines | |||
| 1070 | return pnm_magic_check(p, 7) ? pnm_probe(p) : 0; | 1070 | return pnm_magic_check(p, 7) ? pnm_probe(p) : 0; |
| 1071 | } | 1071 | } |
| 1072 | 1072 | ||
| 1073 | static int hdr_probe(const AVProbeData *p) | ||
| 1074 | { | ||
| 1075 | if (!memcmp(p->buf, "#?RADIANCE\n", 11)) | ||
| 1076 | return AVPROBE_SCORE_MAX; | ||
| 1077 | return 0; | ||
| 1078 | } | ||
| 1079 | |||
| 1073 | static int xbm_probe(const AVProbeData *p) | 1080 | static int xbm_probe(const AVProbeData *p) |
| 1074 | { | 1081 | { |
| 1075 | if (!memcmp(p->buf, "/* XBM X10 format */", 20)) | 1082 | if (!memcmp(p->buf, "/* XBM X10 format */", 20)) |
| @@ -1221,6 +1228,7 @@ IMAGEAUTO_DEMUXER(dpx, DPX) · 145 unmodified lines | |||
| 1221 | IMAGEAUTO_DEMUXER(exr, EXR) | 1228 | IMAGEAUTO_DEMUXER(exr, EXR) |
| 1222 | IMAGEAUTO_DEMUXER(gem, GEM) | 1229 | IMAGEAUTO_DEMUXER(gem, GEM) |
| 1223 | IMAGEAUTO_DEMUXER(gif, GIF) | 1230 | IMAGEAUTO_DEMUXER(gif, GIF) |
| 1231 | IMAGEAUTO_DEMUXER(hdr, RADIANCE_HDR) | ||
| 1224 | IMAGEAUTO_DEMUXER_EXT(j2k, JPEG2000, J2K) | 1232 | IMAGEAUTO_DEMUXER_EXT(j2k, JPEG2000, J2K) |
| 1225 | IMAGEAUTO_DEMUXER_EXT(jpeg, MJPEG, JPEG) | 1233 | IMAGEAUTO_DEMUXER_EXT(jpeg, MJPEG, JPEG) |
| 1226 | IMAGEAUTO_DEMUXER(jpegls, JPEGLS) | 1234 | IMAGEAUTO_DEMUXER(jpegls, JPEGLS) |
| @@ -273,7 +273,7 @@ const AVOutputFormat ff_image2_muxer = { · 272 unmodified lines | |||
| 273 | .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), | 273 | .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), |
| 274 | .extensions = "bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,phm," | 274 | .extensions = "bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,phm," |
| 275 | "png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8," | 275 | "png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8," |
| 276 | "im24,sunras,vbn,xbm,xface,pix,y,avif,qoi", | 276 | "im24,sunras,vbn,xbm,xface,pix,y,avif,qoi,hdr", |
| 277 | .priv_data_size = sizeof(VideoMuxData), | 277 | .priv_data_size = sizeof(VideoMuxData), |
| 278 | .video_codec = AV_CODEC_ID_MJPEG, | 278 | .video_codec = AV_CODEC_ID_MJPEG, |
| 279 | .write_header = write_header, | 279 | .write_header = write_header, |
| @@ -31,7 +31,7 @@ · 30 unmodified lines | |||
| 31 | 31 | ||
| 32 | #include "version_major.h" | 32 | #include "version_major.h" |
| 33 | 33 | ||
| 34 | #define LIBAVFORMAT_VERSION_MINOR 28 | 34 | #define LIBAVFORMAT_VERSION_MINOR 29 |
| 35 | #define LIBAVFORMAT_VERSION_MICRO 100 | 35 | #define LIBAVFORMAT_VERSION_MICRO 100 |
| 36 | 36 | ||
| 37 | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ | 37 | #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |