Unified · Split
| @@ -72,6 +72,7 @@ version <next>: · 71 unmodified lines | ||
| 72 | 72 | - MediaFoundation encoder wrapper |
| 73 | 73 | - untile filter |
| 74 | 74 | - Simon & Schuster Interactive ADPCM encoder |
| 75 | +- PFM decoder | |
| 75 | 76 | |
| 76 | 77 | |
| 77 | 78 | version 4.2: |
| @@ -530,6 +530,7 @@ OBJS-$(CONFIG_PBM_DECODER) += pnmdec.o pnm.o · 529 unmodified lines | ||
| 530 | 530 | OBJS-$(CONFIG_PBM_ENCODER) += pnmenc.o |
| 531 | 531 | OBJS-$(CONFIG_PCX_DECODER) += pcx.o |
| 532 | 532 | OBJS-$(CONFIG_PCX_ENCODER) += pcxenc.o |
| 533 | +OBJS-$(CONFIG_PFM_DECODER) += pnmdec.o pnm.o | |
| 533 | 534 | OBJS-$(CONFIG_PGM_DECODER) += pnmdec.o pnm.o |
| 534 | 535 | OBJS-$(CONFIG_PGM_ENCODER) += pnmenc.o |
| 535 | 536 | OBJS-$(CONFIG_PGMYUV_DECODER) += pnmdec.o pnm.o |
| @@ -233,6 +233,7 @@ extern AVCodec ff_pbm_encoder; · 232 unmodified lines | ||
| 233 | 233 | extern AVCodec ff_pbm_decoder; |
| 234 | 234 | extern AVCodec ff_pcx_encoder; |
| 235 | 235 | extern AVCodec ff_pcx_decoder; |
| 236 | +extern AVCodec ff_pfm_decoder; | |
| 236 | 237 | extern AVCodec ff_pgm_encoder; |
| 237 | 238 | extern AVCodec ff_pgm_decoder; |
| 238 | 239 | extern AVCodec ff_pgmyuv_encoder; |
| @@ -1770,6 +1770,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 1769 unmodified lines | ||
| 1770 | 1770 | .long_name = NULL_IF_CONFIG_SMALL("NotchLC"), |
| 1771 | 1771 | .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY, |
| 1772 | 1772 | }, |
| 1773 | + { | |
| 1774 | + .id = AV_CODEC_ID_PFM, | |
| 1775 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 1776 | + .name = "pfm", | |
| 1777 | + .long_name = NULL_IF_CONFIG_SMALL("PFM (Portable FloatMap) image"), | |
| 1778 | + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, | |
| 1779 | + }, | |
| 1773 | 1780 | |
| 1774 | 1781 | /* various PCM "codecs" */ |
| 1775 | 1782 | { |
| @@ -294,6 +294,7 @@ enum AVCodecID { · 293 unmodified lines | ||
| 294 | 294 | AV_CODEC_ID_CDTOONS, |
| 295 | 295 | AV_CODEC_ID_MV30, |
| 296 | 296 | AV_CODEC_ID_NOTCHLC, |
| 297 | + AV_CODEC_ID_PFM, | |
| 297 | 298 | |
| 298 | 299 | /* various PCM "codecs" */ |
| 299 | 300 | AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs |
| @@ -24,6 +24,7 @@ · 23 unmodified lines | ||
| 24 | 24 | |
| 25 | 25 | #include "libavutil/avassert.h" |
| 26 | 26 | #include "libavutil/imgutils.h" |
| 27 | +#include "libavutil/avstring.h" | |
| 27 | 28 | #include "avcodec.h" |
| 28 | 29 | #include "internal.h" |
| 29 | 30 | #include "pnm.h" |
| @@ -69,8 +70,9 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) · 39 unmodified lines | ||
| 69 | 70 | |
| 70 | 71 | if (s->bytestream_end - s->bytestream < 3 || |
| 71 | 72 | s->bytestream[0] != 'P' || |
| 72 | − s->bytestream[1] < '1' || | |
| 73 | − s->bytestream[1] > '7') { | |
| 73 | + (s->bytestream[1] < '1' || | |
| 74 | + s->bytestream[1] > '7' && | |
| 75 | + s->bytestream[1] != 'F')) { | |
| 74 | 76 | s->bytestream += s->bytestream_end > s->bytestream; |
| 75 | 77 | s->bytestream += s->bytestream_end > s->bytestream; |
| 76 | 78 | return AVERROR_INVALIDDATA; |
| @@ -78,7 +80,9 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) · 1 unmodified line | ||
| 78 | 80 | pnm_get(s, buf1, sizeof(buf1)); |
| 79 | 81 | s->type= buf1[1]-'0'; |
| 80 | 82 | |
| 81 | − if (s->type==1 || s->type==4) { | |
| 83 | + if (buf1[1] == 'F') { | |
| 84 | + avctx->pix_fmt = AV_PIX_FMT_GBRPF32; | |
| 85 | + } else if (s->type==1 || s->type==4) { | |
| 82 | 86 | avctx->pix_fmt = AV_PIX_FMT_MONOWHITE; |
| 83 | 87 | } else if (s->type==2 || s->type==5) { |
| 84 | 88 | if (avctx->codec_id == AV_CODEC_ID_PGMYUV) |
| @@ -173,7 +177,16 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) · 88 unmodified lines | ||
| 173 | 177 | if (ret < 0) |
| 174 | 178 | return ret; |
| 175 | 179 | |
| 176 | − if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE && avctx->pix_fmt != AV_PIX_FMT_MONOBLACK) { | |
| 180 | + if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32) { | |
| 181 | + pnm_get(s, buf1, sizeof(buf1)); | |
| 182 | + if (av_sscanf(buf1, "%f", &s->scale) != 1) { | |
| 183 | + av_log(avctx, AV_LOG_ERROR, "Invalid scale.\n"); | |
| 184 | + return AVERROR_INVALIDDATA; | |
| 185 | + } | |
| 186 | + s->endian = s->scale < 0.f; | |
| 187 | + s->scale = fabsf(s->scale); | |
| 188 | + s->maxval = (1ULL << 32) - 1; | |
| 189 | + } else if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE && avctx->pix_fmt != AV_PIX_FMT_MONOBLACK) { | |
| 177 | 190 | pnm_get(s, buf1, sizeof(buf1)); |
| 178 | 191 | s->maxval = atoi(buf1); |
| 179 | 192 | if (s->maxval <= 0 || s->maxval > UINT16_MAX) { |
| @@ -30,6 +30,8 @@ typedef struct PNMContext { · 29 unmodified lines | ||
| 30 | 30 | uint8_t *bytestream_end; |
| 31 | 31 | int maxval; ///< maximum value of a pixel |
| 32 | 32 | int type; |
| 33 | + int endian; | |
| 34 | + float scale; | |
| 33 | 35 | } PNMContext; |
| 34 | 36 | |
| 35 | 37 | int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s); |
| @@ -46,6 +46,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, · 45 unmodified lines | ||
| 46 | 46 | int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0; |
| 47 | 47 | unsigned char *ptr; |
| 48 | 48 | int components, sample_len, ret; |
| 49 | + float scale; | |
| 49 | 50 | |
| 50 | 51 | s->bytestream_start = |
| 51 | 52 | s->bytestream = (uint8_t *)buf; |
| @@ -254,6 +255,48 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, · 202 unmodified lines | ||
| 254 | 255 | } |
| 255 | 256 | } |
| 256 | 257 | break; |
| 258 | + case AV_PIX_FMT_GBRPF32: | |
| 259 | + if (avctx->width * avctx->height * 12 > s->bytestream_end - s->bytestream) | |
| 260 | + return AVERROR_INVALIDDATA; | |
| 261 | + scale = 1.f / s->scale; | |
| 262 | + if (s->endian) { | |
| 263 | + float *r, *g, *b; | |
| 264 | + | |
| 265 | + r = (float *)p->data[2]; | |
| 266 | + g = (float *)p->data[0]; | |
| 267 | + b = (float *)p->data[1]; | |
| 268 | + for (int i = 0; i < avctx->height; i++) { | |
| 269 | + for (int j = 0; j < avctx->width; j++) { | |
| 270 | + r[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[0])) * scale; | |
| 271 | + g[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[4])) * scale; | |
| 272 | + b[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[8])) * scale; | |
| 273 | + s->bytestream += 12; | |
| 274 | + } | |
| 275 | + | |
| 276 | + r += p->linesize[2] / 4; | |
| 277 | + g += p->linesize[0] / 4; | |
| 278 | + b += p->linesize[1] / 4; | |
| 279 | + } | |
| 280 | + } else { | |
| 281 | + float *r, *g, *b; | |
| 282 | + | |
| 283 | + r = (float *)p->data[2]; | |
| 284 | + g = (float *)p->data[0]; | |
| 285 | + b = (float *)p->data[1]; | |
| 286 | + for (int i = 0; i < avctx->height; i++) { | |
| 287 | + for (int j = 0; j < avctx->width; j++) { | |
| 288 | + r[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[0])) * scale; | |
| 289 | + g[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[4])) * scale; | |
| 290 | + b[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[8])) * scale; | |
| 291 | + s->bytestream += 12; | |
| 292 | + } | |
| 293 | + | |
| 294 | + r += p->linesize[2] / 4; | |
| 295 | + g += p->linesize[0] / 4; | |
| 296 | + b += p->linesize[1] / 4; | |
| 297 | + } | |
| 298 | + } | |
| 299 | + break; | |
| 257 | 300 | } |
| 258 | 301 | *got_frame = 1; |
| 259 | 302 | |
| @@ -320,3 +363,15 @@ AVCodec ff_pam_decoder = { · 60 unmodified lines | ||
| 320 | 363 | .capabilities = AV_CODEC_CAP_DR1, |
| 321 | 364 | }; |
| 322 | 365 | #endif |
| 366 | + | |
| 367 | +#if CONFIG_PFM_DECODER | |
| 368 | +AVCodec ff_pfm_decoder = { | |
| 369 | + .name = "pfm", | |
| 370 | + .long_name = NULL_IF_CONFIG_SMALL("PFM (Portable FloatMap) image"), | |
| 371 | + .type = AVMEDIA_TYPE_VIDEO, | |
| 372 | + .id = AV_CODEC_ID_PFM, | |
| 373 | + .priv_data_size = sizeof(PNMContext), | |
| 374 | + .decode = pnm_decode_frame, | |
| 375 | + .capabilities = AV_CODEC_CAP_DR1, | |
| 376 | +}; | |
| 377 | +#endif | |
| @@ -28,7 +28,7 @@ · 27 unmodified lines | ||
| 28 | 28 | #include "libavutil/version.h" |
| 29 | 29 | |
| 30 | 30 | #define LIBAVCODEC_VERSION_MAJOR 58 |
| 31 | −#define LIBAVCODEC_VERSION_MINOR 89 | |
| 31 | +#define LIBAVCODEC_VERSION_MINOR 90 | |
| 32 | 32 | #define LIBAVCODEC_VERSION_MICRO 100 |
| 33 | 33 | |
| 34 | 34 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
| @@ -40,6 +40,7 @@ const IdStrMap ff_img_tags[] = { · 39 unmodified lines | ||
| 40 | 40 | { AV_CODEC_ID_PGMYUV, "pgmyuv" }, |
| 41 | 41 | { AV_CODEC_ID_PBM, "pbm" }, |
| 42 | 42 | { AV_CODEC_ID_PAM, "pam" }, |
| 43 | + { AV_CODEC_ID_PFM, "pfm" }, | |
| 43 | 44 | { AV_CODEC_ID_ALIAS_PIX, "pix" }, |
| 44 | 45 | { AV_CODEC_ID_DDS, "dds" }, |
| 45 | 46 | { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" }, |