summaryrefslogtreecommitdiff
path: root/libavcodec/pnmdec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/pnmdec.c')
-rw-r--r--libavcodec/pnmdec.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c
index e03e52297f..05bd11b147 100644
--- a/libavcodec/pnmdec.c
+++ b/libavcodec/pnmdec.c
@@ -46,6 +46,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
int i, j, k, n, linesize, h, upgrade = 0, is_mono = 0;
unsigned char *ptr;
int components, sample_len, ret;
+ float scale;
s->bytestream_start =
s->bytestream = (uint8_t *)buf;
@@ -254,6 +255,48 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data,
}
}
break;
+ case AV_PIX_FMT_GBRPF32:
+ if (avctx->width * avctx->height * 12 > s->bytestream_end - s->bytestream)
+ return AVERROR_INVALIDDATA;
+ scale = 1.f / s->scale;
+ if (s->endian) {
+ float *r, *g, *b;
+
+ r = (float *)p->data[2];
+ g = (float *)p->data[0];
+ b = (float *)p->data[1];
+ for (int i = 0; i < avctx->height; i++) {
+ for (int j = 0; j < avctx->width; j++) {
+ r[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[0])) * scale;
+ g[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[4])) * scale;
+ b[j] = av_int2float(av_le2ne32(((uint32_t *)s->bytestream)[8])) * scale;
+ s->bytestream += 12;
+ }
+
+ r += p->linesize[2] / 4;
+ g += p->linesize[0] / 4;
+ b += p->linesize[1] / 4;
+ }
+ } else {
+ float *r, *g, *b;
+
+ r = (float *)p->data[2];
+ g = (float *)p->data[0];
+ b = (float *)p->data[1];
+ for (int i = 0; i < avctx->height; i++) {
+ for (int j = 0; j < avctx->width; j++) {
+ r[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[0])) * scale;
+ g[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[4])) * scale;
+ b[j] = av_int2float(av_be2ne32(((uint32_t *)s->bytestream)[8])) * scale;
+ s->bytestream += 12;
+ }
+
+ r += p->linesize[2] / 4;
+ g += p->linesize[0] / 4;
+ b += p->linesize[1] / 4;
+ }
+ }
+ break;
}
*got_frame = 1;
@@ -320,3 +363,15 @@ AVCodec ff_pam_decoder = {
.capabilities = AV_CODEC_CAP_DR1,
};
#endif
+
+#if CONFIG_PFM_DECODER
+AVCodec ff_pfm_decoder = {
+ .name = "pfm",
+ .long_name = NULL_IF_CONFIG_SMALL("PFM (Portable FloatMap) image"),
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_PFM,
+ .priv_data_size = sizeof(PNMContext),
+ .decode = pnm_decode_frame,
+ .capabilities = AV_CODEC_CAP_DR1,
+};
+#endif