diff mbox series

[FFmpeg-devel] avcodec/exr: preserve half-float NaN bits and add fate test

Message ID 20201123043215.3278-1-mindmark@gmail.com
State Accepted
Commit 8d19b3c4a5176c181dc1751e08834193b549162c
Headers show
Series [FFmpeg-devel] avcodec/exr: preserve half-float NaN bits and add fate test
Related show

Checks

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

Commit Message

Mark Reid Nov. 23, 2020, 4:32 a.m. UTC
From: Mark Reid <mindmark@gmail.com>

Hi,
This patch handles NaNs more like the offical implentation handles them, preserving
the original bits.

https://github.com/AcademySoftwareFoundation/openexr/blob/RB-2.5/IlmBase/Half/toFloat.cpp#L111

It also adds a fate test that is a 256x256 exr containing all possible 16bit half-float values. 

Here is a link to download the fate test file, if someone could add it to fate me
https://www.dropbox.com/s/2q4jg8w489aunsf/rgb_scanline_zip_half_float_0x0_to_0xFFFF.exr

---
 libavcodec/exr.c                                    | 3 +--
 tests/fate/image.mak                                | 2 ++
 tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF | 6 ++++++
 3 files changed, 9 insertions(+), 2 deletions(-)
 create mode 100644 tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF

Comments

Mark Reid Dec. 6, 2020, 3:11 a.m. UTC | #1
On Sun, Nov 22, 2020 at 8:32 PM <mindmark@gmail.com> wrote:

> From: Mark Reid <mindmark@gmail.com>
>
> Hi,
> This patch handles NaNs more like the offical implentation handles them,
> preserving
> the original bits.
>
>
> https://github.com/AcademySoftwareFoundation/openexr/blob/RB-2.5/IlmBase/Half/toFloat.cpp#L111
>
> It also adds a fate test that is a 256x256 exr containing all possible
> 16bit half-float values.
>
> Here is a link to download the fate test file, if someone could add it to
> fate me
>
> https://www.dropbox.com/s/2q4jg8w489aunsf/rgb_scanline_zip_half_float_0x0_to_0xFFFF.exr
>
> ---
>  libavcodec/exr.c                                    | 3 +--
>  tests/fate/image.mak                                | 2 ++
>  tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF | 6 ++++++
>  3 files changed, 9 insertions(+), 2 deletions(-)
>  create mode 100644 tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
>
> diff --git a/libavcodec/exr.c b/libavcodec/exr.c
> index d233dd43fb..6e6ce4275c 100644
> --- a/libavcodec/exr.c
> +++ b/libavcodec/exr.c
> @@ -193,8 +193,7 @@ static union av_intfloat32 exr_half2float(uint16_t hf)
>          // half-float NaNs will be converted to a single precision NaN
>          // half-float Infs will be converted to a single precision Inf
>          exp = FLOAT_MAX_BIASED_EXP;
> -        if (mantissa)
> -            mantissa = (1 << 23) - 1;    // set all bits to indicate a NaN
> +        mantissa <<= 13; // preserve half-float NaN bits if set
>      } else if (exp == 0x0) {
>          // convert half-float zero/denorm to single precision value
>          if (mantissa) {
> diff --git a/tests/fate/image.mak b/tests/fate/image.mak
> index 22072a62f1..c453f0f79c 100644
> --- a/tests/fate/image.mak
> +++ b/tests/fate/image.mak
> @@ -317,6 +317,8 @@ fate-exr-rgb-scanline-half-zip-dw-outside: CMD =
> framecrc -i $(TARGET_SAMPLES)/e
>  FATE_EXR += fate-exr-rgb-tile-half-zip-dw-outside
>  fate-exr-rgb-tile-half-zip-dw-outside: CMD = framecrc -i
> $(TARGET_SAMPLES)/exr/rgb_tile_half_zip_dw_outside.exr -pix_fmt gbrpf32le
>
> +FATE_EXR += fate-exr-rgb-scanline-zip-half-0x0-0xFFFF
> +fate-exr-rgb-scanline-zip-half-0x0-0xFFFF: CMD = framecrc -i
> $(TARGET_SAMPLES)/exr/rgb_scanline_zip_half_float_0x0_to_0xFFFF.exr
> -pix_fmt gbrpf32le
>
>  FATE_EXR-$(call DEMDEC, IMAGE2, EXR) += $(FATE_EXR)
>
> diff --git a/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
> b/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
> new file mode 100644
> index 0000000000..b6201116fe
> --- /dev/null
> +++ b/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
> @@ -0,0 +1,6 @@
> +#tb 0: 1/25
> +#media_type 0: video
> +#codec_id 0: rawvideo
> +#dimensions 0: 256x256
> +#sar 0: 1/1
> +0,          0,          0,        1,   786432, 0x1445e411
> --
> 2.29.2
>
>
ping
Paul B Mahol Dec. 7, 2020, 11:29 a.m. UTC | #2
On Sun, Dec 6, 2020 at 4:20 AM Mark Reid <mindmark@gmail.com> wrote:

> On Sun, Nov 22, 2020 at 8:32 PM <mindmark@gmail.com> wrote:
>
> > From: Mark Reid <mindmark@gmail.com>
> >
> > Hi,
> > This patch handles NaNs more like the offical implentation handles them,
> > preserving
> > the original bits.
> >
> >
> >
> https://github.com/AcademySoftwareFoundation/openexr/blob/RB-2.5/IlmBase/Half/toFloat.cpp#L111
> >
> > It also adds a fate test that is a 256x256 exr containing all possible
> > 16bit half-float values.
> >
> > Here is a link to download the fate test file, if someone could add it to
> > fate me
> >
> >
> https://www.dropbox.com/s/2q4jg8w489aunsf/rgb_scanline_zip_half_float_0x0_to_0xFFFF.exr
> >
> > ---
> >  libavcodec/exr.c                                    | 3 +--
> >  tests/fate/image.mak                                | 2 ++
> >  tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF | 6 ++++++
> >  3 files changed, 9 insertions(+), 2 deletions(-)
> >  create mode 100644 tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
> >
> > diff --git a/libavcodec/exr.c b/libavcodec/exr.c
> > index d233dd43fb..6e6ce4275c 100644
> > --- a/libavcodec/exr.c
> > +++ b/libavcodec/exr.c
> > @@ -193,8 +193,7 @@ static union av_intfloat32 exr_half2float(uint16_t
> hf)
> >          // half-float NaNs will be converted to a single precision NaN
> >          // half-float Infs will be converted to a single precision Inf
> >          exp = FLOAT_MAX_BIASED_EXP;
> > -        if (mantissa)
> > -            mantissa = (1 << 23) - 1;    // set all bits to indicate a
> NaN
> > +        mantissa <<= 13; // preserve half-float NaN bits if set
> >      } else if (exp == 0x0) {
> >          // convert half-float zero/denorm to single precision value
> >          if (mantissa) {
> > diff --git a/tests/fate/image.mak b/tests/fate/image.mak
> > index 22072a62f1..c453f0f79c 100644
> > --- a/tests/fate/image.mak
> > +++ b/tests/fate/image.mak
> > @@ -317,6 +317,8 @@ fate-exr-rgb-scanline-half-zip-dw-outside: CMD =
> > framecrc -i $(TARGET_SAMPLES)/e
> >  FATE_EXR += fate-exr-rgb-tile-half-zip-dw-outside
> >  fate-exr-rgb-tile-half-zip-dw-outside: CMD = framecrc -i
> > $(TARGET_SAMPLES)/exr/rgb_tile_half_zip_dw_outside.exr -pix_fmt gbrpf32le
> >
> > +FATE_EXR += fate-exr-rgb-scanline-zip-half-0x0-0xFFFF
> > +fate-exr-rgb-scanline-zip-half-0x0-0xFFFF: CMD = framecrc -i
> > $(TARGET_SAMPLES)/exr/rgb_scanline_zip_half_float_0x0_to_0xFFFF.exr
> > -pix_fmt gbrpf32le
> >
> >  FATE_EXR-$(call DEMDEC, IMAGE2, EXR) += $(FATE_EXR)
> >
> > diff --git a/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
> > b/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
> > new file mode 100644
> > index 0000000000..b6201116fe
> > --- /dev/null
> > +++ b/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
> > @@ -0,0 +1,6 @@
> > +#tb 0: 1/25
> > +#media_type 0: video
> > +#codec_id 0: rawvideo
> > +#dimensions 0: 256x256
> > +#sar 0: 1/1
> > +0,          0,          0,        1,   786432, 0x1445e411
> > --
> > 2.29.2
> >
> >
> ping
>

Uploaded sample to server.
Will apply in the next 48h.


> _______________________________________________
> 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/exr.c b/libavcodec/exr.c
index d233dd43fb..6e6ce4275c 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -193,8 +193,7 @@  static union av_intfloat32 exr_half2float(uint16_t hf)
         // half-float NaNs will be converted to a single precision NaN
         // half-float Infs will be converted to a single precision Inf
         exp = FLOAT_MAX_BIASED_EXP;
-        if (mantissa)
-            mantissa = (1 << 23) - 1;    // set all bits to indicate a NaN
+        mantissa <<= 13; // preserve half-float NaN bits if set
     } else if (exp == 0x0) {
         // convert half-float zero/denorm to single precision value
         if (mantissa) {
diff --git a/tests/fate/image.mak b/tests/fate/image.mak
index 22072a62f1..c453f0f79c 100644
--- a/tests/fate/image.mak
+++ b/tests/fate/image.mak
@@ -317,6 +317,8 @@  fate-exr-rgb-scanline-half-zip-dw-outside: CMD = framecrc -i $(TARGET_SAMPLES)/e
 FATE_EXR += fate-exr-rgb-tile-half-zip-dw-outside
 fate-exr-rgb-tile-half-zip-dw-outside: CMD = framecrc -i $(TARGET_SAMPLES)/exr/rgb_tile_half_zip_dw_outside.exr -pix_fmt gbrpf32le
 
+FATE_EXR += fate-exr-rgb-scanline-zip-half-0x0-0xFFFF
+fate-exr-rgb-scanline-zip-half-0x0-0xFFFF: CMD = framecrc -i $(TARGET_SAMPLES)/exr/rgb_scanline_zip_half_float_0x0_to_0xFFFF.exr -pix_fmt gbrpf32le
 
 FATE_EXR-$(call DEMDEC, IMAGE2, EXR) += $(FATE_EXR)
 
diff --git a/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF b/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
new file mode 100644
index 0000000000..b6201116fe
--- /dev/null
+++ b/tests/ref/fate/exr-rgb-scanline-zip-half-0x0-0xFFFF
@@ -0,0 +1,6 @@ 
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 256x256
+#sar 0: 1/1
+0,          0,          0,        1,   786432, 0x1445e411