Skip to content

Commit 527d779

Browse files
committed
const SegmentId::COUNT: Rename from RAV1D_MAX_SEGMENTS.
1 parent c5fd7ed commit 527d779

File tree

7 files changed

+31
-32
lines changed

7 files changed

+31
-32
lines changed

include/dav1d/headers.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::src::enum_map::EnumKey;
2+
use crate::src::levels::SegmentId;
23
use crate::src::relaxed_atomic::RelaxedAtomic;
34
use parking_lot::Mutex;
45
use std::ffi::c_int;
@@ -61,7 +62,7 @@ pub const DAV1D_MAX_CDEF_STRENGTHS: usize = 8;
6162
pub const DAV1D_MAX_OPERATING_POINTS: usize = 32;
6263
pub const DAV1D_MAX_TILE_COLS: usize = 64;
6364
pub const DAV1D_MAX_TILE_ROWS: usize = 64;
64-
pub const DAV1D_MAX_SEGMENTS: u8 = 8;
65+
pub const DAV1D_MAX_SEGMENTS: u8 = SegmentId::COUNT as _;
6566
pub const DAV1D_NUM_REF_FRAMES: usize = 8;
6667
pub const DAV1D_PRIMARY_REF_NONE: u8 = 7;
6768
pub const DAV1D_REFS_PER_FRAME: usize = 7;
@@ -71,7 +72,6 @@ pub(crate) const RAV1D_MAX_CDEF_STRENGTHS: usize = DAV1D_MAX_CDEF_STRENGTHS;
7172
pub(crate) const RAV1D_MAX_OPERATING_POINTS: usize = DAV1D_MAX_OPERATING_POINTS;
7273
pub(crate) const RAV1D_MAX_TILE_COLS: usize = DAV1D_MAX_TILE_COLS;
7374
pub(crate) const RAV1D_MAX_TILE_ROWS: usize = DAV1D_MAX_TILE_ROWS;
74-
pub(crate) const RAV1D_MAX_SEGMENTS: u8 = DAV1D_MAX_SEGMENTS;
7575
pub(crate) const _RAV1D_NUM_REF_FRAMES: usize = DAV1D_NUM_REF_FRAMES;
7676
pub(crate) const RAV1D_PRIMARY_REF_NONE: u8 = DAV1D_PRIMARY_REF_NONE;
7777
pub(crate) const RAV1D_REFS_PER_FRAME: usize = DAV1D_REFS_PER_FRAME;
@@ -1508,7 +1508,7 @@ pub struct Dav1dSegmentationDataSet {
15081508
#[derive(Clone, Default)]
15091509
#[repr(C)]
15101510
pub struct Rav1dSegmentationDataSet {
1511-
pub d: [Rav1dSegmentationData; RAV1D_MAX_SEGMENTS as usize],
1511+
pub d: [Rav1dSegmentationData; SegmentId::COUNT],
15121512
pub preskip: u8,
15131513
pub last_active_segid: i8,
15141514
}
@@ -2096,7 +2096,7 @@ pub struct Dav1dFrameHeader_segmentation {
20962096
pub qidx: [u8; DAV1D_MAX_SEGMENTS as usize],
20972097
}
20982098

2099-
/// Like a `[bool; RAV1D_MAX_SEGMENTS as usize]`,
2099+
/// Like a `[bool; SegmentId::COUNT]`,
21002100
/// but the [`bool`]s are compressed into the bits of the [`u8`].
21012101
#[derive(Clone, Copy, Default)]
21022102
pub struct LossLess {
@@ -2109,16 +2109,16 @@ impl LossLess {
21092109
}
21102110

21112111
pub const fn get(&self, index: usize) -> bool {
2112-
const { assert!(u8::BITS >= RAV1D_MAX_SEGMENTS as _) };
2112+
const { assert!(u8::BITS >= SegmentId::COUNT as _) };
21132113
self.bits & (1 << index) != 0
21142114
}
21152115

21162116
pub const fn all(&self) -> bool {
2117-
self.bits == ((1u64 << RAV1D_MAX_SEGMENTS) - 1) as u8
2117+
self.bits == ((1u64 << SegmentId::COUNT) - 1) as u8
21182118
}
21192119

2120-
pub const fn to_array(&self) -> [bool; RAV1D_MAX_SEGMENTS as usize] {
2121-
let mut a = [false; RAV1D_MAX_SEGMENTS as usize];
2120+
pub const fn to_array(&self) -> [bool; SegmentId::COUNT] {
2121+
let mut a = [false; SegmentId::COUNT];
21222122
let mut i = 0;
21232123
while i < a.len() {
21242124
a[i] = self.get(i);
@@ -2127,7 +2127,7 @@ impl LossLess {
21272127
a
21282128
}
21292129

2130-
pub fn from_array(a: [bool; RAV1D_MAX_SEGMENTS as usize]) -> Self {
2130+
pub fn from_array(a: [bool; SegmentId::COUNT]) -> Self {
21312131
let mut this = Self::empty();
21322132
let mut i = 0;
21332133
while i < a.len() {
@@ -2147,7 +2147,7 @@ pub struct Rav1dFrameHeader_segmentation {
21472147
pub update_data: u8,
21482148
pub seg_data: Rav1dSegmentationDataSet,
21492149
pub lossless: LossLess,
2150-
pub qidx: [u8; RAV1D_MAX_SEGMENTS as usize],
2150+
pub qidx: [u8; SegmentId::COUNT],
21512151
}
21522152

21532153
impl From<Dav1dFrameHeader_segmentation> for Rav1dFrameHeader_segmentation {

lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub mod src {
6363
mod iter;
6464
mod itx;
6565
mod itx_1d;
66-
mod levels;
66+
pub(crate) mod levels;
6767
mod lf_apply;
6868
mod lf_mask;
6969
pub mod lib;

src/cdf.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use crate::include::dav1d::headers::Rav1dFilterMode;
44
use crate::include::dav1d::headers::Rav1dFrameHeader;
5-
use crate::include::dav1d::headers::RAV1D_MAX_SEGMENTS;
65
use crate::src::align::Align16;
76
use crate::src::align::Align32;
87
use crate::src::align::Align4;
@@ -12,6 +11,7 @@ use crate::src::levels::BlockLevel;
1211
use crate::src::levels::BlockPartition;
1312
use crate::src::levels::BlockSize;
1413
use crate::src::levels::MVJoint;
14+
use crate::src::levels::SegmentId;
1515
use crate::src::levels::N_COMP_INTER_PRED_MODES;
1616
use crate::src::levels::N_INTRA_PRED_MODES;
1717
use crate::src::levels::N_TX_SIZES;
@@ -103,7 +103,7 @@ pub struct CdfModeContext {
103103
pub angle_delta: Align16<[[u16; 8]; 8]>,
104104
pub filter_intra: Align16<[u16; 8]>,
105105
pub comp_inter_mode: Align16<[[u16; N_COMP_INTER_PRED_MODES]; 8]>,
106-
pub seg_id: Align16<[[u16; RAV1D_MAX_SEGMENTS as usize]; 3]>,
106+
pub seg_id: Align16<[[u16; SegmentId::COUNT]; 3]>,
107107
pub pal_sz: Align16<[[[u16; 8]; 7]; 2]>,
108108
pub color_map: Align16<[[[[u16; 8]; 5]; 7]; 2]>,
109109
pub filter: Align8<[[[u16; 4]; 8]; 2]>,
@@ -5021,7 +5021,7 @@ pub(crate) fn rav1d_cdf_thread_update(
50215021
update_cdf_4d!(N_TX_SIZES, 2, 41 /*42*/, 3, coef.base_tok);
50225022
update_bit_2d!(2, 3, coef.dc_sign);
50235023
update_cdf_4d!(4, 2, 21, 3, coef.br_tok);
5024-
update_cdf_2d!(3, (RAV1D_MAX_SEGMENTS - 1) as usize, m.seg_id);
5024+
update_cdf_2d!(3, SegmentId::COUNT - 1, m.seg_id);
50255025
update_cdf_1d!(7, m.cfl_sign.0);
50265026
update_cdf_2d!(6, 15, m.cfl_alpha);
50275027
update_bit_0d!(m.restore_wiener);

src/decode.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::include::dav1d::headers::Rav1dTxfmMode;
1616
use crate::include::dav1d::headers::Rav1dWarpedMotionParams;
1717
use crate::include::dav1d::headers::Rav1dWarpedMotionType;
1818
use crate::include::dav1d::headers::SgrIdx;
19-
use crate::include::dav1d::headers::RAV1D_MAX_SEGMENTS;
2019
use crate::include::dav1d::headers::RAV1D_PRIMARY_REF_NONE;
2120
use crate::include::dav1d::picture::Rav1dPicture;
2221
use crate::src::align::Align16;
@@ -187,13 +186,13 @@ fn init_quant_tables(
187186
seq_hdr: &Rav1dSequenceHeader,
188187
frame_hdr: &Rav1dFrameHeader,
189188
qidx: u8,
190-
dq: &[[[RelaxedAtomic<u16>; 2]; 3]; RAV1D_MAX_SEGMENTS as usize],
189+
dq: &[[[RelaxedAtomic<u16>; 2]; 3]; SegmentId::COUNT],
191190
) {
192191
let tbl = &dav1d_dq_tbl[seq_hdr.hbd as usize];
193192

194193
let segmentation_is_enabled = frame_hdr.segmentation.enabled != 0;
195194
let len = if segmentation_is_enabled {
196-
RAV1D_MAX_SEGMENTS as usize
195+
SegmentId::COUNT
197196
} else {
198197
1
199198
};
@@ -1375,7 +1374,7 @@ fn decode_b(
13751374
let diff = rav1d_msac_decode_symbol_adapt8(
13761375
&mut ts_c.msac,
13771376
&mut ts_c.cdf.m.seg_id[seg_ctx as usize],
1378-
RAV1D_MAX_SEGMENTS as usize - 1,
1377+
SegmentId::COUNT - 1,
13791378
);
13801379
let last_active_seg_id_plus1 =
13811380
(frame_hdr.segmentation.seg_data.last_active_segid + 1) as u8;
@@ -1463,7 +1462,7 @@ fn decode_b(
14631462
let diff = rav1d_msac_decode_symbol_adapt8(
14641463
&mut ts_c.msac,
14651464
&mut ts_c.cdf.m.seg_id[seg_ctx as usize],
1466-
RAV1D_MAX_SEGMENTS as usize - 1,
1465+
SegmentId::COUNT - 1,
14671466
);
14681467
let last_active_seg_id_plus1 =
14691468
(frame_hdr.segmentation.seg_data.last_active_segid + 1) as u8;

src/internal.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::include::dav1d::headers::Rav1dITUTT35;
1616
use crate::include::dav1d::headers::Rav1dMasteringDisplay;
1717
use crate::include::dav1d::headers::Rav1dSequenceHeader;
1818
use crate::include::dav1d::headers::Rav1dWarpedMotionParams;
19-
use crate::include::dav1d::headers::RAV1D_MAX_SEGMENTS;
2019
use crate::include::dav1d::picture::Rav1dPicAllocator;
2120
use crate::include::dav1d::picture::Rav1dPicture;
2221
use crate::src::align::Align16;
@@ -827,9 +826,9 @@ pub(crate) struct Rav1dFrameData {
827826
pub sb_shift: c_int,
828827
pub sb_step: c_int,
829828
pub sr_sb128w: c_int,
830-
pub dq: [[[RelaxedAtomic<u16>; 2]; 3]; RAV1D_MAX_SEGMENTS as usize], /* [RAV1D_MAX_SEGMENTS][3 plane][2 dc/ac] */
831-
pub qm: [[Option<&'static [u8]>; 3]; 19], /* [3 plane][19] */
832-
pub a: Vec<BlockContext>, /* len = w*tile_rows */
829+
pub dq: [[[RelaxedAtomic<u16>; 2]; 3]; SegmentId::COUNT], /* [SegmentId::COUNT][3 plane][2 dc/ac] */
830+
pub qm: [[Option<&'static [u8]>; 3]; 19], /* [3 plane][19] */
831+
pub a: Vec<BlockContext>, /* len = w*tile_rows */
833832
pub rf: RefMvsFrame,
834833
pub jnt_weights: [[u8; 7]; 7],
835834
pub bitdepth_max: c_int,
@@ -898,7 +897,7 @@ pub struct Rav1dTileState {
898897
// each entry is one tile-sbrow; middle index is refidx
899898
pub lowest_pixel: usize,
900899

901-
pub dqmem: [[[RelaxedAtomic<u16>; 2]; 3]; RAV1D_MAX_SEGMENTS as usize], /* [RAV1D_MAX_SEGMENTS][3 plane][2 dc/ac] */
900+
pub dqmem: [[[RelaxedAtomic<u16>; 2]; 3]; SegmentId::COUNT], /* [SegmentId::COUNT][3 plane][2 dc/ac] */
902901
pub dq: RelaxedAtomic<TileStateRef>,
903902
pub last_qidx: RelaxedAtomic<u8>,
904903
pub last_delta_lf: RelaxedAtomic<[i8; 4]>,

src/levels.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![deny(unsafe_code)]
22

33
use crate::include::dav1d::headers::Rav1dFilterMode;
4-
use crate::include::dav1d::headers::RAV1D_MAX_SEGMENTS;
54
use crate::src::enum_map::EnumKey;
65
use bitflags::bitflags;
76
use std::fmt;
@@ -500,15 +499,17 @@ impl Default for Av1BlockIntraInter {
500499
}
501500
}
502501

503-
/// Within range `0..`[`RAV1D_MAX_SEGMENTS`].
502+
/// Within range `0..`[`SegmentId::COUNT`].
504503
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
505504
pub struct SegmentId {
506505
id: u8,
507506
}
508507

509508
impl SegmentId {
509+
pub const COUNT: usize = 8;
510+
510511
pub const fn new(id: u8) -> Option<Self> {
511-
if id < RAV1D_MAX_SEGMENTS {
512+
if id < Self::COUNT as _ {
512513
Some(Self { id })
513514
} else {
514515
None
@@ -517,15 +518,15 @@ impl SegmentId {
517518

518519
pub const fn get(&self) -> usize {
519520
// Cheaply make sure it is in bounds in a way the compiler can see at call sites.
520-
(self.id % RAV1D_MAX_SEGMENTS) as usize
521+
self.id as usize % Self::COUNT
521522
}
522523

523524
pub fn min() -> Self {
524525
Self::new(0).unwrap()
525526
}
526527

527528
pub fn max() -> Self {
528-
Self::new(RAV1D_MAX_SEGMENTS - 1).unwrap()
529+
Self::new(Self::COUNT as u8 - 1).unwrap()
529530
}
530531
}
531532

src/lf_mask.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ use crate::include::dav1d::headers::Rav1dFrameHeader;
44
use crate::include::dav1d::headers::Rav1dLoopfilterModeRefDeltas;
55
use crate::include::dav1d::headers::Rav1dPixelLayout;
66
use crate::include::dav1d::headers::Rav1dRestorationType;
7-
use crate::include::dav1d::headers::RAV1D_MAX_SEGMENTS;
87
use crate::src::align::Align16;
98
use crate::src::align::ArrayDefault;
109
use crate::src::ctx::CaseSet;
1110
use crate::src::disjoint_mut::DisjointMut;
1211
use crate::src::internal::Bxy;
1312
use crate::src::levels::BlockSize;
1413
use crate::src::levels::RectTxfmSize;
14+
use crate::src::levels::SegmentId;
1515
use crate::src::levels::TX_4X4;
1616
use crate::src::relaxed_atomic::RelaxedAtomic;
1717
use crate::src::tables::dav1d_block_dimensions;
@@ -671,12 +671,12 @@ fn calc_lf_value_chroma(
671671
}
672672

673673
pub(crate) fn rav1d_calc_lf_values(
674-
lflvl_values: &mut [Align16<[[[u8; 2]; 8]; 4]>; RAV1D_MAX_SEGMENTS as usize],
674+
lflvl_values: &mut [Align16<[[[u8; 2]; 8]; 4]>; SegmentId::COUNT],
675675
hdr: &Rav1dFrameHeader,
676676
lf_delta: &[i8; 4],
677677
) {
678678
let n_seg = if hdr.segmentation.enabled != 0 {
679-
RAV1D_MAX_SEGMENTS as usize
679+
SegmentId::COUNT
680680
} else {
681681
1
682682
};

0 commit comments

Comments
 (0)