Opened 11 months ago

Last modified 11 months ago

#10431 new defect

Bug in lut3d.c

Reported by: Michael Koch Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

A *.cube file can contain a line like
LUT_1D_INPUT_RANGE 0.1 0.5
but this doesn't work.

The min and max values are scanned in lut3d.c lines 1747 and 1748.

The bug is in lines 1763 to 1765. Here the inverse of (max-min) is calculated and clipped to the [0..1] range. That's wrong because the inverse is larger than 1. Please allow [0..100] range.
This can be used for strong contrast enhancement. Just specify a narrow range with the min and max parameters, and use a simple LUT with only two entries:

LUT_1D_SIZE 2
LUT_1D_INPUT_RANGE 0.1 0.5
0 0 0
1 1 1

The *.cube file can also contain a similar line for 3D LUTs:
LUT_3D_INPUT_RANGE 0.1 0.5
This is still missing in lut3d.c

Attachments (2)

simple_test_1.cube (55 bytes ) - added by Michael Koch 11 months ago.
1D LUT with LUT_1D_INPUT_RANGE
simple_test_2.cube (75 bytes ) - added by Michael Koch 11 months ago.
1D LUT with DOMAIN_MIN and DOMAIN_MAX

Download all attachments as: .zip

Change History (14)

comment:1 by Elon Musk, 11 months ago

Please cite specifications to make this valid ticket.

in reply to:  1 comment:2 by Michael Koch, 11 months ago

Replying to Elon Musk:

Please cite specifications to make this valid ticket.

I had a link to the specification, but it's dead now.
Here are a few examples where the min and max values are set to 0 and 1, which are the default values: https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=40284

By the way, in the above link is also described that 1D- and 3D-LUTs can be specified in the same *.cube file, and in this case the 1D LUT is applied before the 3D LUT. Is this feature implemented in FFmpeg?

It seems logical to me that min and max can also be set to other values than 0 and 1. Otherwise the LUT_1D_INPUT_RANGE option is useless.

comment:3 by Balling, 11 months ago

had a link to the specification, but it's dead now.

So you did not download the link? Or is it an article? Then it should be on web.archive.

Usually the 1D LUT is a transfer function and 3D LUT is primaries manipulation.

in reply to:  3 comment:4 by Michael Koch, 11 months ago

Replying to Balling:

had a link to the specification, but it's dead now.

So you did not download the link? Or is it an article? Then it should be on web.archive.

The link was
https://wwwimages2.adobe.com/content/dam/acom/en/products/speedgrade/cc/pdfs/cube-lut-specification-1.0.pdf

I have found the document on paper.
The keywords LUT_1D_INPUT_RANGE and LUT_3D_INPUT_RANGE do not exist in this specification. Instead there are keywords
DOMAIN_MIN rl gl bl
and
DOMAIN_MAX rh gh bh

The range of the numbers is not specified.

comment:5 by Michael Koch, 11 months ago

comment:7 by Elon Musk, 11 months ago

Please cite specification to make this valid link. Not going to research whole specification from link for you, have not much that free time.

in reply to:  7 comment:8 by Michael Koch, 11 months ago

Replying to Elon Musk:

Please cite specification to make this valid link. Not going to research whole specification from link for you, have not much that free time.

It seems there exist two different syntax specifications:

LUT_1D_INPUT_RANGE min max
LUT_3D_INPUT_RANGE min max
The first one is already implemented in lut3d.c, but clipped to wrong range in lines 1763 to 1765. For examples see https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=40284
I didn't find a specification for these keywords. Maybe the author of lut3d.c knows where he has found it.

2.
DOMAIN_MIN rl gl bl
DOMAIN_MAX rh gh bh
For specification see chapter 5.6 in
https://web.archive.org/web/20201027210201/https://wwwimages2.adobe.com/content/dam/acom/en/products/speedgrade/cc/pdfs/cube-lut-specification-1.0.pdf
See also this implementation, beginning in line 142:
https://github.com/JakubOchnik/Cube-LUT-Loader/blob/main/src/DataLoader/CubeLUT.cpp

I'm not sure which of these two syntax versions is newer or older.
Seems best if FFmpeg accepts both of them for compatibility.

Last edited 11 months ago by Michael Koch (previous) (diff)

comment:9 by Elon Musk, 11 months ago

Please provide lut files that allow to reproduce this, and what another tool does not clip it to [0,1]

by Michael Koch, 11 months ago

Attachment: simple_test_1.cube added

1D LUT with LUT_1D_INPUT_RANGE

by Michael Koch, 11 months ago

Attachment: simple_test_2.cube added

1D LUT with DOMAIN_MIN and DOMAIN_MAX

comment:10 by Michael Koch, 11 months ago

Two simple LUTs for strong contrast enhancement attached.
The version with LUT_1D_INPUT_RANGE does work in DaVinci Resolve.
The version with DOMAIN_MIN and DOMAIN_MAX does not work in DaVinci Resolve.

in reply to:  10 comment:11 by Michael Koch, 11 months ago

Replying to Michael Koch:

Two simple LUTs for strong contrast enhancement attached.
The version with LUT_1D_INPUT_RANGE does work in DaVinci Resolve.
The version with DOMAIN_MIN and DOMAIN_MAX does not work in DaVinci Resolve.

DaVinci Resolve does correctly read the second LUT, but it just ignores the DOMAIN_MIN and DOMAIN_MAX keywords. This can be shown if a third line is inserted for a nonlinear transfer function:
LUT_1D_SIZE 3
DOMAIN_MIN 0.1 0.1 0.1
DOMAIN_MAX 0.3 0.3 0.3
0 0 0
0.3 0.3 0.3
1 1 1

comment:12 by Balling, 11 months ago

Related: https://github.com/cameramanben/LUTCalc/issues/7

And also https://github.com/cameramanben/LUTCalc/issues/3

If it was having trouble with the input values, then it might be worth trying the Adobe/Lumetri/Speedgrade approch which would contain 'DOMAIN_MIN' and 'DOMAIN_MAX' rather than 'LUT_1D_INPUT_RANGE'.

That is exactly correct. OCIOFileTransform in Nuke requires 1D cube LUTs with input range specified to be in the Iridas/Adobe format, not the Resolve one.

By the way, Ben, there is a Non-Commercial version of Nuke which is free. I think that since you would be using it only for testing purposes with LUTCalc, which is essentially non-profit, you would qualify for a non-commercial license.

Last edited 11 months ago by Balling (previous) (diff)
Note: See TracTickets for help on using tickets.