The current logic hard-coded a check for v_sub == 1. We can extend this logic slightly to cover the case of interlaced 4:1:0 (which has v_sub == 2). Here is a diagram explaining this scenario (with center-siting): a a a a a a a a b b b b b b b b X X a a a a a a a a b b b b b b b b a a a a a a a a b b b b b b b b Y Y a a a a a a a a b b b b b b b b a = even luma rows b = odd luma rows X = even chroma sample Y = odd chroma sample In progressive mode, the chroma samples sit at (384, 384) respectively. Relative to the 8x4 grid of even luma samples (a), the X sample sits at: h_chr_pos = 384 v_chr_pos = 192 Relative to the 8x4 grid of odd luma samples (b), the Y sample sits at: h_chr_pos = 384 v_chr_pos = 576 The new code calculates the correct values in all circumstances.
Unified · Split
| @@ -643,9 +643,19 @@ static void calc_chroma_pos(int *h_pos_out, int *v_pos_out, int chroma_loc, · 642 unmodified lines | |||
| 643 | v_pos = v_pos_override; | 643 | v_pos = v_pos_override; |
| 644 | 644 | ||
| 645 | /* Fix vertical chroma position for interlaced frames */ | 645 | /* Fix vertical chroma position for interlaced frames */ |
| 646 | if (v_sub == 1 && index > 0) { | 646 | if (v_sub && index > 0) { |
| 647 | v_pos += 256 * (index == 2); /* offset by one luma row for odd rows */ | 647 | /* When vertically subsampling, chroma samples are effectively only |
| 648 | v_pos >>= 1; /* double luma row distance */ | 648 | * placed next to even rows. To access them from the odd field, we need |
| 649 | * to account for this shift by offsetting the distance of one luma row. | ||
| 650 | * | ||
| 651 | * For 4x vertical subsampling (v_sub == 2), they are only placed | ||
| 652 | * next to every *other* even row, so we need to shift by three luma | ||
| 653 | * rows to get to the chroma sample. */ | ||
| 654 | if (index == 2) | ||
| 655 | v_pos += (256 << v_sub) - 256; | ||
| 656 | |||
| 657 | /* Luma row distance is doubled for fields, so halve offsets */ | ||
| 658 | v_pos >>= 1; | ||
| 649 | } | 659 | } |
| 650 | 660 | ||
| 651 | /* Explicitly strip chroma offsets when not subsampling, because it | 661 | /* Explicitly strip chroma offsets when not subsampling, because it |