Skip to content

Commit 6a2ed00

Browse files
rzumerbarrbrain
authored andcommitted
Fix 4:2:0 assumption in IEF block context selection
1 parent 390d989 commit 6a2ed00

File tree

3 files changed

+35
-44
lines changed

3 files changed

+35
-44
lines changed

src/encoder.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,8 +1140,11 @@ pub fn encode_tx_block<T: Pixel>(
11401140
let ief_params = if mode.is_directional()
11411141
&& fi.sequence.enable_intra_edge_filter
11421142
{
1143-
let above_block_info = ts.above_block_info(tile_partition_bo, p);
1144-
let left_block_info = ts.left_block_info(tile_partition_bo, p);
1143+
let (plane_xdec, plane_ydec) = if p == 0 { (0, 0) } else { (xdec, ydec) };
1144+
let above_block_info =
1145+
ts.above_block_info(tile_partition_bo, plane_xdec, plane_ydec);
1146+
let left_block_info =
1147+
ts.left_block_info(tile_partition_bo, plane_xdec, plane_ydec);
11451148
Some(IntraEdgeFilterParameters::new(p, above_block_info, left_block_info))
11461149
} else {
11471150
None

src/rdo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,8 @@ fn intra_frame_rdo_mode_decision<T: Pixel>(
12291229
};
12301230

12311231
let ief_params = if fi.sequence.enable_intra_edge_filter {
1232-
let above_block_info = ts.above_block_info(tile_bo, 0);
1233-
let left_block_info = ts.left_block_info(tile_bo, 0);
1232+
let above_block_info = ts.above_block_info(tile_bo, 0, 0);
1233+
let left_block_info = ts.left_block_info(tile_bo, 0, 0);
12341234
Some(IntraEdgeFilterParameters::new(
12351235
0,
12361236
above_block_info,

src/tiling/tile_state.rs

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -229,55 +229,43 @@ impl<'a, T: Pixel> TileStateMut<'a, T> {
229229
})
230230
}
231231

232+
/// Returns above block information for context during prediction.
233+
/// If there is no above block, returns `None`.
234+
/// `xdec` and `ydec` are the decimation factors of the targeted plane.
232235
pub fn above_block_info(
233-
&self, bo: TileBlockOffset, plane: usize,
236+
&self, bo: TileBlockOffset, xdec: usize, ydec: usize,
234237
) -> Option<CodedBlockInfo> {
235-
let (bo_x, bo_y) = (bo.0.x, bo.0.y);
236-
if plane == 0 {
237-
if bo_y == 0 {
238-
None
239-
} else {
240-
Some(self.coded_block_info[bo_y - 1][bo_x])
241-
}
238+
let (mut bo_x, mut bo_y) = (bo.0.x, bo.0.y);
239+
if bo_x & 1 == 0 {
240+
bo_x += xdec
241+
};
242+
if bo_y & 1 == 1 {
243+
bo_y -= ydec
244+
};
245+
if bo_y == 0 {
246+
None
242247
} else {
243-
let (mut bo_x_uv, mut bo_y_uv) = (bo_x, bo_y);
244-
if bo_x & 1 == 0 {
245-
bo_x_uv += 1
246-
};
247-
if bo_y & 1 == 1 {
248-
bo_y_uv -= 1
249-
};
250-
if bo_y_uv == 0 {
251-
None
252-
} else {
253-
Some(self.coded_block_info[bo_y_uv - 1][bo_x_uv])
254-
}
248+
Some(self.coded_block_info[bo_y - 1][bo_x])
255249
}
256250
}
257251

252+
/// Returns left block information for context during prediction.
253+
/// If there is no left block, returns `None`.
254+
/// `xdec` and `ydec` are the decimation factors of the targeted plane.
258255
pub fn left_block_info(
259-
&self, bo: TileBlockOffset, plane: usize,
256+
&self, bo: TileBlockOffset, xdec: usize, ydec: usize,
260257
) -> Option<CodedBlockInfo> {
261-
let (bo_x, bo_y) = (bo.0.x, bo.0.y);
262-
if plane == 0 {
263-
if bo_x == 0 {
264-
None
265-
} else {
266-
Some(self.coded_block_info[bo_y][bo_x - 1])
267-
}
258+
let (mut bo_x, mut bo_y) = (bo.0.x, bo.0.y);
259+
if bo_x & 1 == 1 {
260+
bo_x -= xdec
261+
};
262+
if bo_y & 1 == 0 {
263+
bo_y += ydec
264+
};
265+
if bo_x == 0 {
266+
None
268267
} else {
269-
let (mut bo_x_uv, mut bo_y_uv) = (bo_x, bo_y);
270-
if bo_x & 1 == 1 {
271-
bo_x_uv -= 1
272-
};
273-
if bo_y & 1 == 0 {
274-
bo_y_uv += 1
275-
};
276-
if bo_x_uv == 0 {
277-
None
278-
} else {
279-
Some(self.coded_block_info[bo_y_uv][bo_x_uv - 1])
280-
}
268+
Some(self.coded_block_info[bo_y][bo_x - 1])
281269
}
282270
}
283271
}

0 commit comments

Comments
 (0)