Message ID | CAB0OVGoUFvRTDNmc3j09=8LRurcNq3GkFUJ8mNyUT19E3+2h2w@mail.gmail.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel] lavc/pnm: Support signed pgm files from jasper | expand |
Context | Check | Description |
---|---|---|
andriy/default | pending | |
andriy/make | success | Make finished |
andriy/make_fate | success | Make fate finished |
Carl Eugen Hoyos (12020-04-25): > Hi! > > Attached patch allows reading the pgm file that jasper creates > using the jpeg 2000 reference file p0_03.j2k as input. > > Please comment, Carl Eugen > From 5da97c417d66b1e840b1feae31f0852cf3755c39 Mon Sep 17 00:00:00 2001 > From: Carl Eugen Hoyos <ceffmpeg@gmail.com> > Date: Sat, 25 Apr 2020 17:05:40 +0200 > Subject: [PATCH] lavc/pnm: Allow reading signed pgm values as written by > jasper. > > --- > libavcodec/pnm.c | 4 ++++ > libavcodec/pnm.h | 1 + > libavcodec/pnmdec.c | 2 +- > 3 files changed, 6 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c > index b5c2881948..c9b9eb9ccd 100644 > --- a/libavcodec/pnm.c > +++ b/libavcodec/pnm.c > @@ -176,6 +176,10 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) > if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE && avctx->pix_fmt != AV_PIX_FMT_MONOBLACK) { > pnm_get(s, buf1, sizeof(buf1)); > s->maxval = atoi(buf1); > + if (s->maxval < 0) { > + s->maxval *= -1; > + s->jasper_signed = 1; > + } > if (s->maxval <= 0 || s->maxval > UINT16_MAX) { The s->maxval <= 0 test here has become redundant. I do not know if the patch itself is correct and wanted. > av_log(avctx, AV_LOG_ERROR, "Invalid maxval: %d\n", s->maxval); > s->maxval = 255; > diff --git a/libavcodec/pnm.h b/libavcodec/pnm.h > index 5bc0aad29f..2550cef92b 100644 > --- a/libavcodec/pnm.h > +++ b/libavcodec/pnm.h > @@ -30,6 +30,7 @@ typedef struct PNMContext { > uint8_t *bytestream_end; > int maxval; ///< maximum value of a pixel > int type; > + int jasper_signed; > } PNMContext; > > int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s); > diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c > index dbcaef3884..6e5f5b6c3b 100644 > --- a/libavcodec/pnmdec.c > +++ b/libavcodec/pnmdec.c > @@ -168,7 +168,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, > else if (upgrade == 1) { > unsigned int j, f = (255 * 128 + s->maxval / 2) / s->maxval; > for (j = 0; j < n; j++) > - ptr[j] = (s->bytestream[j] * f + 64) >> 7; > + ptr[j] = ((s->bytestream[j] - (s->maxval / 2 - 1) * s->jasper_signed) * f + 64) >> 7; > } else if (upgrade == 2) { > unsigned int j, v, f = (65535 * 32768 + s->maxval / 2) / s->maxval; > for (j = 0; j < n / 2; j++) { Regards,
Am Sa., 25. Apr. 2020 um 17:13 Uhr schrieb Nicolas George <george@nsup.org>: > > Carl Eugen Hoyos (12020-04-25): > > Hi! > > > > Attached patch allows reading the pgm file that jasper creates > > using the jpeg 2000 reference file p0_03.j2k as input. > > > > Please comment, Carl Eugen > > > From 5da97c417d66b1e840b1feae31f0852cf3755c39 Mon Sep 17 00:00:00 2001 > > From: Carl Eugen Hoyos <ceffmpeg@gmail.com> > > Date: Sat, 25 Apr 2020 17:05:40 +0200 > > Subject: [PATCH] lavc/pnm: Allow reading signed pgm values as written by > > jasper. > > > > --- > > libavcodec/pnm.c | 4 ++++ > > libavcodec/pnm.h | 1 + > > libavcodec/pnmdec.c | 2 +- > > 3 files changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c > > index b5c2881948..c9b9eb9ccd 100644 > > --- a/libavcodec/pnm.c > > +++ b/libavcodec/pnm.c > > @@ -176,6 +176,10 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) > > if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE && avctx->pix_fmt != AV_PIX_FMT_MONOBLACK) { > > pnm_get(s, buf1, sizeof(buf1)); > > s->maxval = atoi(buf1); > > > + if (s->maxval < 0) { > > + s->maxval *= -1; > > + s->jasper_signed = 1; > > + } > > if (s->maxval <= 0 || s->maxval > UINT16_MAX) { > > The s->maxval <= 0 test here has become redundant. I did not consider it redundant... Carl Eugen
From 5da97c417d66b1e840b1feae31f0852cf3755c39 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos <ceffmpeg@gmail.com> Date: Sat, 25 Apr 2020 17:05:40 +0200 Subject: [PATCH] lavc/pnm: Allow reading signed pgm values as written by jasper. --- libavcodec/pnm.c | 4 ++++ libavcodec/pnm.h | 1 + libavcodec/pnmdec.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libavcodec/pnm.c b/libavcodec/pnm.c index b5c2881948..c9b9eb9ccd 100644 --- a/libavcodec/pnm.c +++ b/libavcodec/pnm.c @@ -176,6 +176,10 @@ int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s) if (avctx->pix_fmt != AV_PIX_FMT_MONOWHITE && avctx->pix_fmt != AV_PIX_FMT_MONOBLACK) { pnm_get(s, buf1, sizeof(buf1)); s->maxval = atoi(buf1); + if (s->maxval < 0) { + s->maxval *= -1; + s->jasper_signed = 1; + } if (s->maxval <= 0 || s->maxval > UINT16_MAX) { av_log(avctx, AV_LOG_ERROR, "Invalid maxval: %d\n", s->maxval); s->maxval = 255; diff --git a/libavcodec/pnm.h b/libavcodec/pnm.h index 5bc0aad29f..2550cef92b 100644 --- a/libavcodec/pnm.h +++ b/libavcodec/pnm.h @@ -30,6 +30,7 @@ typedef struct PNMContext { uint8_t *bytestream_end; int maxval; ///< maximum value of a pixel int type; + int jasper_signed; } PNMContext; int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s); diff --git a/libavcodec/pnmdec.c b/libavcodec/pnmdec.c index dbcaef3884..6e5f5b6c3b 100644 --- a/libavcodec/pnmdec.c +++ b/libavcodec/pnmdec.c @@ -168,7 +168,7 @@ static int pnm_decode_frame(AVCodecContext *avctx, void *data, else if (upgrade == 1) { unsigned int j, f = (255 * 128 + s->maxval / 2) / s->maxval; for (j = 0; j < n; j++) - ptr[j] = (s->bytestream[j] * f + 64) >> 7; + ptr[j] = ((s->bytestream[j] - (s->maxval / 2 - 1) * s->jasper_signed) * f + 64) >> 7; } else if (upgrade == 2) { unsigned int j, v, f = (65535 * 32768 + s->maxval / 2) / s->maxval; for (j = 0; j < n / 2; j++) { -- 2.24.1