sekrit-twc / zimg

Scaling, colorspace conversion, and dithering library
Do What The F*ck You Want To Public License
405 stars 77 forks source link

Question about the bilinear filter used in chroma subsampling #178

Closed dreifachstein closed 2 years ago

dreifachstein commented 2 years ago

The 444 to 420 conversion uses a 3-tap (1/4, 1/2, 1/4) horizontal filter and a 4-tap (1/8. 3/8/ 3/8, 1/8) vertical filter for chroma_sample_loc=left. The 4-tap vertical filter is quite unexpected. Is this intentional?

sekrit-twc commented 2 years ago
in:  x0 x1 x2 x3 x4 x5
out:   y0    y1    y2

y1 = w1 * x1 + w2 * x2 + w3 * x3 + w4 * x4
w1 = w4
w2 = w3
w2 = 3 * w1
w1 + w2 + w3 + w4 = 1
==> w1 = 1/8, w2 = 3/8, w3 = 3/8, w4 = 1/8

Where is the issue?

dreifachstein commented 2 years ago

I was expecting the bilinear subsampling step to use 3-tap horizontal and 2-tap vertical with weights derived from pixel coverage.

sekrit-twc commented 2 years ago

As you can see in the diagram, there are four input samples between y0 and y2, thus four weights contribute to the value of y1.