History

avcodec: add PFM image decoder

Paul B Mahol committed 6 years ago

Commit d49db991 parent 439128910 files · +87 −5Browse files

Unified · Split

10 files
  1. Changelog +1 −0
  2. libavcodec/Makefile +1 −0
  3. libavcodec/allcodecs.c +1 −0
  4. libavcodec/codec_desc.c +7 −0
  5. libavcodec/codec_id.h +1 −0
  6. libavcodec/pnm.c +17 −4
  7. libavcodec/pnm.h +2 −0
  8. libavcodec/pnmdec.c +55 −0
  9. libavcodec/version.h +1 −1
  10. libavformat/img2.c +1 −0
Changelog+1−0
@@ -72,6 +72,7 @@ version <next>: · 71 unmodified lines
72- MediaFoundation encoder wrapper72- MediaFoundation encoder wrapper
73- untile filter73- untile filter
74- Simon & Schuster Interactive ADPCM encoder74- Simon & Schuster Interactive ADPCM encoder
75- PFM decoder
75 76
76 77
77version 4.2:78version 4.2:
libavcodec/Makefile+1−0
@@ -530,6 +530,7 @@ OBJS-$(CONFIG_PBM_DECODER) += pnmdec.o pnm.o · 529 unmodified lines
530OBJS-$(CONFIG_PBM_ENCODER) += pnmenc.o530OBJS-$(CONFIG_PBM_ENCODER) += pnmenc.o
531OBJS-$(CONFIG_PCX_DECODER) += pcx.o531OBJS-$(CONFIG_PCX_DECODER) += pcx.o
532OBJS-$(CONFIG_PCX_ENCODER) += pcxenc.o532OBJS-$(CONFIG_PCX_ENCODER) += pcxenc.o
533OBJS-$(CONFIG_PFM_DECODER) += pnmdec.o pnm.o
533OBJS-$(CONFIG_PGM_DECODER) += pnmdec.o pnm.o534OBJS-$(CONFIG_PGM_DECODER) += pnmdec.o pnm.o
534OBJS-$(CONFIG_PGM_ENCODER) += pnmenc.o535OBJS-$(CONFIG_PGM_ENCODER) += pnmenc.o
535OBJS-$(CONFIG_PGMYUV_DECODER) += pnmdec.o pnm.o536OBJS-$(CONFIG_PGMYUV_DECODER) += pnmdec.o pnm.o
libavcodec/allcodecs.c+1−0
@@ -233,6 +233,7 @@ extern AVCodec ff_pbm_encoder; · 232 unmodified lines
233extern AVCodec ff_pbm_decoder;233extern AVCodec ff_pbm_decoder;
234extern AVCodec ff_pcx_encoder;234extern AVCodec ff_pcx_encoder;
235extern AVCodec ff_pcx_decoder;235extern AVCodec ff_pcx_decoder;
236extern AVCodec ff_pfm_decoder;
236extern AVCodec ff_pgm_encoder;237extern AVCodec ff_pgm_encoder;
237extern AVCodec ff_pgm_decoder;238extern AVCodec ff_pgm_decoder;
238extern AVCodec ff_pgmyuv_encoder;239extern AVCodec ff_pgmyuv_encoder;
libavcodec/codec_desc.c+7−0
@@ -1770,6 +1770,13 @@ static const AVCodecDescriptor codec_descriptors[] = { · 1769 unmodified lines
1770 .long_name = NULL_IF_CONFIG_SMALL("NotchLC"),1770 .long_name = NULL_IF_CONFIG_SMALL("NotchLC"),
1771 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,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 /* various PCM "codecs" */1781 /* various PCM "codecs" */
1775 {1782 {
libavcodec/codec_id.h+1−0
@@ -294,6 +294,7 @@ enum AVCodecID { · 293 unmodified lines
294 AV_CODEC_ID_CDTOONS,294 AV_CODEC_ID_CDTOONS,
295 AV_CODEC_ID_MV30,295 AV_CODEC_ID_MV30,
296 AV_CODEC_ID_NOTCHLC,296 AV_CODEC_ID_NOTCHLC,
297 AV_CODEC_ID_PFM,
297 298
298 /* various PCM "codecs" */299 /* various PCM "codecs" */
299 AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs300 AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
libavcodec/pnm.c+17−4
@@ -24,6 +24,7 @@ · 23 unmodified lines
24 24
25#include "libavutil/avassert.h"25#include "libavutil/avassert.h"
26#include "libavutil/imgutils.h"26#include "libavutil/imgutils.h"
27#include "libavutil/avstring.h"
27#include "avcodec.h"28#include "avcodec.h"
28#include "internal.h"29#include "internal.h"
29#include "pnm.h"30#include "pnm.h"
@@ -69,8 +70,9 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) · 39 unmodified lines
69 70
70 if (s->bytestream_end - s->bytestream < 3 ||71 if (s->bytestream_end - s->bytestream < 3 ||
71 s->bytestream[0] != 'P' ||72 s->bytestream[0] != 'P' ||
72 s->bytestream[1] < '1' ||73 (s->bytestream[1] < '1' ||
73 s->bytestream[1] > '7') {74 s->bytestream[1] > '7' &&
75 s->bytestream[1] != 'F')) {
74 s->bytestream += s->bytestream_end > s->bytestream;76 s->bytestream += s->bytestream_end > s->bytestream;
75 s->bytestream += s->bytestream_end > s->bytestream;77 s->bytestream += s->bytestream_end > s->bytestream;
76 return AVERROR_INVALIDDATA;78 return AVERROR_INVALIDDATA;
@@ -78,7 +80,9 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) · 1 unmodified line
78 pnm_get(s, buf1, sizeof(buf1));80 pnm_get(s, buf1, sizeof(buf1));
79 s->type= buf1[1]-'0';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 avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;86 avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
83 } else if (s->type==2 || s->type==5) {87 } else if (s->type==2 || s->type==5) {
84 if (avctx->codec_id == AV_CODEC_ID_PGMYUV)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 if (ret < 0)177 if (ret < 0)
174 return ret;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 pnm_get(s, buf1, sizeof(buf1));190 pnm_get(s, buf1, sizeof(buf1));
178 s->maxval = atoi(buf1);191 s->maxval = atoi(buf1);
179 if (s->maxval <= 0 || s->maxval > UINT16_MAX) {192 if (s->maxval <= 0 || s->maxval > UINT16_MAX) {
libavcodec/pnm.h+2−0
@@ -30,6 +30,8 @@ typedef struct PNMContext { · 29 unmodified lines
30 uint8_t *bytestream_end;30 uint8_t *bytestream_end;
31 int maxval; ///< maximum value of a pixel31 int maxval; ///< maximum value of a pixel
32 int type;32 int type;
33 int endian;
34 float scale;
33} PNMContext;35} PNMContext;
34 36
35int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s);37int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s);
libavcodec/pnmdec.c+55−0
@@ -46,6 +46,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, · 45 unmodified lines
46 int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0;46 int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0;
47 unsigned char *ptr;47 unsigned char *ptr;
48 int components, sample_len, ret;48 int components, sample_len, ret;
49 float scale;
49 50
50 s->bytestream_start =51 s->bytestream_start =
51 s->bytestream = (uint8_t *)buf;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 break;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 *got_frame = 1;301 *got_frame = 1;
259 302
@@ -320,3 +363,15 @@ AVCodec ff_pam_decoder = { · 60 unmodified lines
320 .capabilities = AV_CODEC_CAP_DR1,363 .capabilities = AV_CODEC_CAP_DR1,
321};364};
322#endif365#endif
366
367#if CONFIG_PFM_DECODER
368AVCodec 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
libavcodec/version.h+1−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
28#include "libavutil/version.h"28#include "libavutil/version.h"
29 29
30#define LIBAVCODEC_VERSION_MAJOR 5830#define LIBAVCODEC_VERSION_MAJOR 58
31#define LIBAVCODEC_VERSION_MINOR 8931#define LIBAVCODEC_VERSION_MINOR 90
32#define LIBAVCODEC_VERSION_MICRO 10032#define LIBAVCODEC_VERSION_MICRO 100
33 33
34#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \34#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
libavformat/img2.c+1−0
@@ -40,6 +40,7 @@ const IdStrMap ff_img_tags[] = { · 39 unmodified lines
40 { AV_CODEC_ID_PGMYUV, "pgmyuv" },40 { AV_CODEC_ID_PGMYUV, "pgmyuv" },
41 { AV_CODEC_ID_PBM, "pbm" },41 { AV_CODEC_ID_PBM, "pbm" },
42 { AV_CODEC_ID_PAM, "pam" },42 { AV_CODEC_ID_PAM, "pam" },
43 { AV_CODEC_ID_PFM, "pfm" },
43 { AV_CODEC_ID_ALIAS_PIX, "pix" },44 { AV_CODEC_ID_ALIAS_PIX, "pix" },
44 { AV_CODEC_ID_DDS, "dds" },45 { AV_CODEC_ID_DDS, "dds" },
45 { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" },46 { AV_CODEC_ID_MPEG1VIDEO, "mpg1-img" },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t