Disable dithering for full range 8 to 16 bit conversions#39
Conversation
Upsampling from full range 8 bit to full range 16 bit is x * 257, which doesn't need dithering.
Co-authored-by: Dave <orangechannel@pm.me>
|
Just realized I tested all three cases on some clips with Expr and all cause information loss so I'm gonna go ahead and change it |
Always enable dithering by default when converting between float and integer samples Enable dithering when downsampling from float 32 to float 16
|
At least with the python logic, depth would dither for int to f32, which I would explicitly disable.
I don't think that's correct for chroma, since |
I hadn't thought of that, I'll have a look at the chroma conversions too
oops |
|
It seems like chroma is safe in this case. This test script sttill returns a green clip Edit: float 16 can handle up to int 10 |
Only dither when upsampling from integer to float when converting to16 bit float AND the current bit depth is higher than 10, as this seems to be the maximum amount of information float 16 can handle in both full and limited range. It does seem to be able to handle 11 bit full range conversions, though, wildly obscure as it may be
|
this conditional should mean that: |
|
Please add a comment explaining why this case is excluded (i.e. summarize what has been discussed here). That might prevent confusion in a few months when someone else looks at the code. |
Dithering isn't used for conversions to float formats so this was the correct behavior. should_dither = (range_in != range # full -> limited OR limited -> full
or clip.format.sample_type == vs.FLOAT # float -> int
or (range_in == Range.FULL and not (curr_depth, bitdepth) == (8, 16)) # full, int -> full, int but specifically not for 8 -> 16
or curr_depth > bitdepth) and sample_type == vs.INTEGER # limited, int -> limited, int if downsampling@Frechdachs @kgrabs does this seem correct?
|
|
float16 only has precision up to about 10-11 bit integer, so converting from 11-16 bit integer to float 16 is downsampling |
|
But does zimg even dither when converting anything to float, even half? VapourSynth docs say no and this seems to also imply that but this is a big codebase that I’m not too interested in learning about. |
|
So it seems. Float output likely never dithers same thing for |
|
Might want to bring this up in zimg’s repo then if you think it should allow dithering to half float, but for now I think the code block I suggested is accurate for when dithering is needed/possible. |
Upsampling from full range 8 bit (0-255) to full range 16 bit (0-65535) is x * 257, which doesn't need dithering.