AOMediaCodec / afgs1-spec

Film grain synthesis algorithm and parameters
https://aomediacodec.github.io/afgs1-spec/
Other
8 stars 7 forks source link

Derivation of ArCoeffsYPlus128 etc. doesn't make sense #115

Open haasn opened 7 months ago

haasn commented 7 months ago

You specify:

ArCoeffsYPlus128[ i ] = ar_coeffs_y[ i ] - (1<<(BitsArY - 1))

This suggests a signed interpretation of ArCoeffsYPlus128, with value ranges spanning from [-16,15] to [-127,128] depending on the value of BitsArY. When you then go on to subtract 128 from this value as part of the film grain application process, you get nonsensical value ranges like [-144,-113] or [-255,0].

Contrast this with AV1 film grain spec, in which ar_coeffs_y_plus_128[ i ] is parsed as an unsigned f(8), which is then shifted by subtracting 128 (as the name implies), giving a signed integer in the range [-128,127], as part of the film grain application process.

I strongly suspect the intent here was either one of:

But I don't have enough information (let alone a sample file) to confirm which interpretation is correct.

haasn commented 7 months ago

I suspect that this error was introduced accidentally as part of https://github.com/AOMediaCodec/afgs1-spec/pull/65/commits/635ef34c4f6891b68804fe970bb179ec9225782e, which replaced the previous formula ar_coeffs_y[ i ] = ar_coeffs_y[ i ] - (1<<(BitsArY - 1)) by changing the name of the field.

That would imply the second interpretation is correct.

andrey-norkin commented 6 months ago

The second interpretation is correct. The PR #116 should solve the issue.