Skip to content

Commit fb7ed9e

Browse files
alastor0325kinetiknz
authored andcommitted
Address review feedback on mdcv/clli parsing
Fix hex literal formatting in BoxType constants to use '_' separators, and fix read_mdcv to correctly remap wire order G, B, R to struct indices R[0], G[1], B[2] per ISO 14496-12.
1 parent 9b97a6d commit fb7ed9e

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

mp4parse/src/boxes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ box_database!(
123123
ItemPropertyContainerBox 0x6970_636f, // "ipco"
124124
ItemPropertyAssociationBox 0x6970_6d61, // "ipma"
125125
ColourInformationBox 0x636f_6c72, // "colr"
126-
MasteringDisplayColourVolumeBox 0x6d646376, // "mdcv"
127-
ContentLightLevelBox 0x636c6c69, // "clli"
126+
MasteringDisplayColourVolumeBox 0x6d64_6376, // "mdcv"
127+
ContentLightLevelBox 0x636c_6c69, // "clli"
128128
ImageSpatialExtentsProperty 0x6973_7065, // "ispe"
129129
PixelAspectRatioBox 0x7061_7370, // "pasp"
130130
PixelInformationBox 0x7069_7869, // "pixi"

mp4parse/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,8 @@ pub enum VideoCodecSpecific {
11711171
}
11721172

11731173
/// Mastering display colour volume from an `mdcv` box (ISO 14496-12).
1174-
/// Primary indices are R\[0\], G\[1\], B\[2\]. Raw fixed-point values: divide chromaticity
1175-
/// values by 50000 and luminance values by 10000 to obtain physical units.
1174+
/// Primary indices are R\[0\], G\[1\], B\[2\]. Divide chromaticity values by 50000
1175+
/// and luminance values by 10000 to obtain physical units.
11761176
#[derive(Debug, Clone)]
11771177
pub struct MasteringDisplayColourVolume {
11781178
pub display_primaries_x: [u16; 3],
@@ -3731,8 +3731,12 @@ fn read_pasp<T: Read>(src: &mut BMFFBox<T>) -> Result<PixelAspectRatio> {
37313731

37323732
/// Parse mastering display colour volume box (ISO 14496-12).
37333733
fn read_mdcv<T: Read>(src: &mut BMFFBox<T>) -> Result<MasteringDisplayColourVolume> {
3734-
let display_primaries_x = [be_u16(src)?, be_u16(src)?, be_u16(src)?];
3735-
let display_primaries_y = [be_u16(src)?, be_u16(src)?, be_u16(src)?];
3734+
// Wire order is G, B, R (per ISO 14496-12); remap to R[0], G[1], B[2].
3735+
let (gx, gy) = (be_u16(src)?, be_u16(src)?);
3736+
let (bx, by) = (be_u16(src)?, be_u16(src)?);
3737+
let (rx, ry) = (be_u16(src)?, be_u16(src)?);
3738+
let display_primaries_x = [rx, gx, bx];
3739+
let display_primaries_y = [ry, gy, by];
37363740
let white_point_x = be_u16(src)?;
37373741
let white_point_y = be_u16(src)?;
37383742
let max_display_mastering_luminance = be_u32(src)?;

mp4parse/src/tests.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,17 +1392,16 @@ fn read_to_end_oom() {
13921392

13931393
#[test]
13941394
fn read_mdcv() {
1395-
// Synthetic mdcv box: 3 primaries (R, G, B) x/y as u16, white point x/y,
1396-
// max/min luminance as u32. Values chosen to be distinct and easy to verify.
1395+
// Synthetic mdcv box. Wire order is G, B, R (x then y for each primary),
1396+
// remapped by read_mdcv to struct indices R[0], G[1], B[2].
13971397
let mut stream = make_box(BoxSize::Auto, b"mdcv", |s| {
1398-
s // display_primaries_x[0..2] (R, G, B)
1399-
.B16(35400)
1400-
.B16(14600)
1401-
.B16(7500)
1402-
// display_primaries_y[0..2] (R, G, B)
1403-
.B16(14600)
1404-
.B16(59210)
1405-
.B16(3000)
1398+
s // Gx, Gy, Bx, By, Rx, Ry (wire order)
1399+
.B16(14600) // Gx
1400+
.B16(59210) // Gy
1401+
.B16(7500) // Bx
1402+
.B16(3000) // By
1403+
.B16(35400) // Rx
1404+
.B16(14600) // Ry
14061405
// white_point_x, white_point_y
14071406
.B16(15635)
14081407
.B16(16450)

0 commit comments

Comments
 (0)