diff mbox series

[FFmpeg-devel] lavc/pnm: Support decoding gray float pbm images.

Message ID CAB0OVGrz2nsYE73NnwjU48BMHvVvYOMgC-DobVVJPc=gFGN68g@mail.gmail.com
State Accepted
Commit ca781761d61de20f28b5c6486c64dbf2c2c4c944
Headers show
Series [FFmpeg-devel] lavc/pnm: Support decoding gray float pbm images. | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Carl Eugen Hoyos Feb. 11, 2021, 10:41 p.m. UTC
Hi!

Attached patch allows to decode gray float pbm images, sample by ami_stuff.

Please comment, Carl Eugen
Subject: [PATCH] lavc/pnm: Allow decoding of gray float pbm images.

---
 libavcodec/pnm.c    |  5 ++++-
 libavcodec/pnmdec.c | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

Comments

Paul B Mahol Feb. 11, 2021, 11:18 p.m. UTC | #1
This is variant of PFM images, PBM image format is only fixed point gray.
Carl Eugen Hoyos Feb. 11, 2021, 11:21 p.m. UTC | #2
Am Fr., 12. Feb. 2021 um 00:18 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
>
> This is variant of PFM images, PBM image format is only fixed point gray.

Should I change the commit message or the patch?

Thank you, Carl Eugen
Paul B Mahol Feb. 11, 2021, 11:23 p.m. UTC | #3
On Fri, Feb 12, 2021 at 12:21 AM Carl Eugen Hoyos <ceffmpeg@gmail.com>
wrote:

> Am Fr., 12. Feb. 2021 um 00:18 Uhr schrieb Paul B Mahol <onemda@gmail.com
> >:
> >
> > This is variant of PFM images, PBM image format is only fixed point gray.
>
> Should I change the commit message or the patch?
>

commit message


>
> Thank you, Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Carl Eugen Hoyos Feb. 14, 2021, 11:24 p.m. UTC | #4
Am Fr., 12. Feb. 2021 um 00:24 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
>
> On Fri, Feb 12, 2021 at 12:21 AM Carl Eugen Hoyos <ceffmpeg@gmail.com>
> wrote:
>
> > Am Fr., 12. Feb. 2021 um 00:18 Uhr schrieb Paul B Mahol <onemda@gmail.com
> > >:
> > >
> > > This is variant of PFM images, PBM image format is only fixed point gray.
> >
> > Should I change the commit message or the patch?
>
> commit message

Patch applied.

Thank you, Carl Eugen
Paul B Mahol Feb. 15, 2021, 1:39 a.m. UTC | #5
Why you use pbm decoder for probing of pfm files?
Carl Eugen Hoyos Feb. 15, 2021, 6:13 p.m. UTC | #6
Am Mo., 15. Feb. 2021 um 02:39 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
>
> Why you use pbm decoder for probing of pfm files?

The only samples I found have the extension pbm and I
simply misunderstood how you designed this since my
samples were detected as pbm (because of their
extension).

Will fix, Carl Eugen
Carl Eugen Hoyos Feb. 15, 2021, 7:16 p.m. UTC | #7
Am Mo., 15. Feb. 2021 um 19:13 Uhr schrieb Carl Eugen Hoyos
<ceffmpeg@gmail.com>:
>
> Am Mo., 15. Feb. 2021 um 02:39 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
> >
> > Why you use pbm decoder for probing of pfm files?
>
> The only samples I found have the extension pbm and I
> simply misunderstood how you designed this since my
> samples were detected as pbm (because of their
> extension).
>
> Will fix, Carl Eugen

AVParserContext->codec_ids is limited to five elements,
therefore no additional AV_CODEC_ID can be added to
the pnm_parser and AV_CODEC_ID_PFM cannot be used
for the autodetection.

Carl Eugen
Paul B Mahol Feb. 15, 2021, 7:17 p.m. UTC | #8
then add new parser bellow

On Mon, Feb 15, 2021 at 8:16 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Am Mo., 15. Feb. 2021 um 19:13 Uhr schrieb Carl Eugen Hoyos
> <ceffmpeg@gmail.com>:
> >
> > Am Mo., 15. Feb. 2021 um 02:39 Uhr schrieb Paul B Mahol <
> onemda@gmail.com>:
> > >
> > > Why you use pbm decoder for probing of pfm files?
> >
> > The only samples I found have the extension pbm and I
> > simply misunderstood how you designed this since my
> > samples were detected as pbm (because of their
> > extension).
> >
> > Will fix, Carl Eugen
>
> AVParserContext->codec_ids is limited to five elements,
> therefore no additional AV_CODEC_ID can be added to
> the pnm_parser and AV_CODEC_ID_PFM cannot be used
> for the autodetection.
>
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Carl Eugen Hoyos Feb. 15, 2021, 7:21 p.m. UTC | #9
Am Mo., 15. Feb. 2021 um 20:18 Uhr schrieb Paul B Mahol <onemda@gmail.com>:
>
> then add new parser bellow

Already working on it:
ff_pnm2_parser or ff_pfm_parser?
Or another idea?

Thank you, Carl Eugen
Paul B Mahol Feb. 15, 2021, 7:29 p.m. UTC | #10
ff_pfm_parser

On Mon, Feb 15, 2021 at 8:29 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:

> Am Mo., 15. Feb. 2021 um 20:18 Uhr schrieb Paul B Mahol <onemda@gmail.com
> >:
> >
> > then add new parser bellow
>
> Already working on it:
> ff_pnm2_parser or ff_pfm_parser?
> Or another idea?
>
> Thank you, Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c
index aad23c7ae2..5af04965e7 100644
--- a/libavcodec/pnm.c
+++ b/libavcodec/pnm.c
@@ -72,6 +72,7 @@  int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
         s->bytestream[0] != 'P' ||
         (s->bytestream[1] < '1' ||
          s->bytestream[1] > '7' &&
+         s->bytestream[1] != 'f' &&
          s->bytestream[1] != 'F')) {
         s->bytestream += s->bytestream_end > s->bytestream;
         s->bytestream += s->bytestream_end > s->bytestream;
@@ -82,6 +83,8 @@  int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
 
     if (buf1[1] == 'F') {
         avctx->pix_fmt = AV_PIX_FMT_GBRPF32;
+    } else if (buf1[1] == 'f') {
+        avctx->pix_fmt = AV_PIX_FMT_GRAYF32;
     } else if (s->type==1 || s->type==4) {
         avctx->pix_fmt = AV_PIX_FMT_MONOWHITE;
     } else if (s->type==2 || s->type==5) {
@@ -177,7 +180,7 @@  int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s)
     if (ret < 0)
         return ret;
 
-    if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32) {
+    if (avctx->pix_fmt == AV_PIX_FMT_GBRPF32 || avctx->pix_fmt == AV_PIX_FMT_GRAYF32) {
         pnm_get(s, buf1, sizeof(buf1));
         if (av_sscanf(buf1, "%f", &s->scale) != 1 || s->scale == 0.0 || !isfinite(s->scale)) {
             av_log(avctx, AV_LOG_ERROR, "Invalid scale.\n");
diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c
index 9add5cfc84..4d5ce0bcb5 100644
--- a/libavcodec/pnmdec.c
+++ b/libavcodec/pnmdec.c
@@ -297,6 +297,30 @@  static int pnm_decode_frame(AVCodecContext *avctx, void *data,
             }
         }
         break;
+    case AV_PIX_FMT_GRAYF32:
+        if (avctx->width * avctx->height * 4 > s->bytestream_end - s->bytestream)
+            return AVERROR_INVALIDDATA;
+        scale = 1.f / s->scale;
+        if (s->endian) {
+            float *g = (float *)p->data[0];
+            for (int i = 0; i < avctx->height; i++) {
+                for (int j = 0; j < avctx->width; j++) {
+                    g[j] = av_int2float(AV_RL32(s->bytestream)) * scale;
+                    s->bytestream += 4;
+                }
+                g += p->linesize[0] / 4;
+            }
+        } else {
+            float *g = (float *)p->data[0];
+            for (int i = 0; i < avctx->height; i++) {
+                for (int j = 0; j < avctx->width; j++) {
+                    g[j] = av_int2float(AV_RB32(s->bytestream)) * scale;
+                    s->bytestream += 4;
+                }
+                g += p->linesize[0] / 4;
+            }
+        }
+        break;
     }
     *got_frame = 1;