From: Kostya Shishkov Date: Sat, 13 Jun 2020 12:33:55 +0000 (+0200) Subject: mov: support default palette and grayscale mode X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=2736c15a4e47e346a6a05e12c988b230ec80d2d1;p=nihav.git mov: support default palette and grayscale mode --- diff --git a/nihav-commonfmt/src/demuxers/mov.rs b/nihav-commonfmt/src/demuxers/mov.rs index 5d66174..0c23b02 100644 --- a/nihav-commonfmt/src/demuxers/mov.rs +++ b/nihav-commonfmt/src/demuxers/mov.rs @@ -421,12 +421,48 @@ fn read_stsd(track: &mut Track, br: &mut ByteReader, size: u64) -> DemuxerResult br.read_skip(31)?; // actual compressor name let depth = br.read_u16be()?; let ctable_id = br.read_u16be()?; - validate!((depth <= 8) || (ctable_id == 0xFFFF)); + validate!(((depth & 0x1F) <= 8) || (ctable_id == 0xFFFF)); if ctable_id == 0 { let max_pal_size = start_pos + size - br.tell(); let mut pal = [0; 1024]; read_palette(br, max_pal_size, &mut pal)?; track.pal = Some(Arc::new(pal)); + } else if (depth & 0x20) == 0 && (depth & 0x1F) <= 8 { + match depth & 0x1F { + 2 => { + let mut pal = [0; 1024]; + (&mut pal[..4 * 4]).copy_from_slice(&MOV_DEFAULT_PAL_2BIT); + track.pal = Some(Arc::new(pal)); + }, + 4 => { + let mut pal = [0; 1024]; + (&mut pal[..16 * 4]).copy_from_slice(&MOV_DEFAULT_PAL_4BIT); + track.pal = Some(Arc::new(pal)); + }, + 8 => { + track.pal = Some(Arc::new(MOV_DEFAULT_PAL_8BIT)); + }, + _ => {}, + }; + } else if (depth & 0x1F) <= 8 { + let mut pal = [0; 1024]; + let cdepth = depth & 0x1F; + let size = 1 << cdepth; + for i in 0..size { + let mut clr = (size - 1 - i) as u8; + let mut off = 8 - cdepth; + while off >= cdepth { + clr |= clr >> (8 - off); + off -= cdepth; + } + if off > 0 { + clr |= clr >> (8 - off); + } + pal[i * 4] = clr; + pal[i * 4 + 1] = clr; + pal[i * 4 + 2] = clr; + } + track.pal = Some(Arc::new(pal)); } // todo other atoms, put as extradata let cname = if let Some(name) = find_codec_from_mov_video_fourcc(&fcc) { @@ -885,6 +921,289 @@ impl DemuxerCreator for MOVDemuxerCreator { fn get_name(&self) -> &'static str { "mov" } } +const MOV_DEFAULT_PAL_2BIT: [u8; 4 * 4] = [ + 0x93, 0x65, 0x5E, 0x00, + 0xFF, 0xFF, 0xFF, 0x00, + 0xDF, 0xD0, 0xAB, 0x00, + 0x00, 0x00, 0x00, 0x00 +]; +const MOV_DEFAULT_PAL_4BIT: [u8; 16 * 4] = [ + 0xFF, 0xFB, 0xFF, 0x00, + 0xEF, 0xD9, 0xBB, 0x00, + 0xE8, 0xC9, 0xB1, 0x00, + 0x93, 0x65, 0x5E, 0x00, + 0xFC, 0xDE, 0xE8, 0x00, + 0x9D, 0x88, 0x91, 0x00, + 0xFF, 0xFF, 0xFF, 0x00, + 0xFF, 0xFF, 0xFF, 0x00, + 0xFF, 0xFF, 0xFF, 0x00, + 0x47, 0x48, 0x37, 0x00, + 0x7A, 0x5E, 0x55, 0x00, + 0xDF, 0xD0, 0xAB, 0x00, + 0xFF, 0xFB, 0xF9, 0x00, + 0xE8, 0xCA, 0xC5, 0x00, + 0x8A, 0x7C, 0x77, 0x00, + 0x00, 0x00, 0x00, 0x00 +]; +const MOV_DEFAULT_PAL_8BIT: [u8; 256 * 4] = [ + 0xFF, 0xFF, 0xFF, 0x00, + 0xFF, 0xFF, 0xCC, 0x00, + 0xFF, 0xFF, 0x99, 0x00, + 0xFF, 0xFF, 0x66, 0x00, + 0xFF, 0xFF, 0x33, 0x00, + 0xFF, 0xFF, 0x00, 0x00, + 0xFF, 0xCC, 0xFF, 0x00, + 0xFF, 0xCC, 0xCC, 0x00, + 0xFF, 0xCC, 0x99, 0x00, + 0xFF, 0xCC, 0x66, 0x00, + 0xFF, 0xCC, 0x33, 0x00, + 0xFF, 0xCC, 0x00, 0x00, + 0xFF, 0x99, 0xFF, 0x00, + 0xFF, 0x99, 0xCC, 0x00, + 0xFF, 0x99, 0x99, 0x00, + 0xFF, 0x99, 0x66, 0x00, + 0xFF, 0x99, 0x33, 0x00, + 0xFF, 0x99, 0x00, 0x00, + 0xFF, 0x66, 0xFF, 0x00, + 0xFF, 0x66, 0xCC, 0x00, + 0xFF, 0x66, 0x99, 0x00, + 0xFF, 0x66, 0x66, 0x00, + 0xFF, 0x66, 0x33, 0x00, + 0xFF, 0x66, 0x00, 0x00, + 0xFF, 0x33, 0xFF, 0x00, + 0xFF, 0x33, 0xCC, 0x00, + 0xFF, 0x33, 0x99, 0x00, + 0xFF, 0x33, 0x66, 0x00, + 0xFF, 0x33, 0x33, 0x00, + 0xFF, 0x33, 0x00, 0x00, + 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xCC, 0x00, + 0xFF, 0x00, 0x99, 0x00, + 0xFF, 0x00, 0x66, 0x00, + 0xFF, 0x00, 0x33, 0x00, + 0xFF, 0x00, 0x00, 0x00, + 0xCC, 0xFF, 0xFF, 0x00, + 0xCC, 0xFF, 0xCC, 0x00, + 0xCC, 0xFF, 0x99, 0x00, + 0xCC, 0xFF, 0x66, 0x00, + 0xCC, 0xFF, 0x33, 0x00, + 0xCC, 0xFF, 0x00, 0x00, + 0xCC, 0xCC, 0xFF, 0x00, + 0xCC, 0xCC, 0xCC, 0x00, + 0xCC, 0xCC, 0x99, 0x00, + 0xCC, 0xCC, 0x66, 0x00, + 0xCC, 0xCC, 0x33, 0x00, + 0xCC, 0xCC, 0x00, 0x00, + 0xCC, 0x99, 0xFF, 0x00, + 0xCC, 0x99, 0xCC, 0x00, + 0xCC, 0x99, 0x99, 0x00, + 0xCC, 0x99, 0x66, 0x00, + 0xCC, 0x99, 0x33, 0x00, + 0xCC, 0x99, 0x00, 0x00, + 0xCC, 0x66, 0xFF, 0x00, + 0xCC, 0x66, 0xCC, 0x00, + 0xCC, 0x66, 0x99, 0x00, + 0xCC, 0x66, 0x66, 0x00, + 0xCC, 0x66, 0x33, 0x00, + 0xCC, 0x66, 0x00, 0x00, + 0xCC, 0x33, 0xFF, 0x00, + 0xCC, 0x33, 0xCC, 0x00, + 0xCC, 0x33, 0x99, 0x00, + 0xCC, 0x33, 0x66, 0x00, + 0xCC, 0x33, 0x33, 0x00, + 0xCC, 0x33, 0x00, 0x00, + 0xCC, 0x00, 0xFF, 0x00, + 0xCC, 0x00, 0xCC, 0x00, + 0xCC, 0x00, 0x99, 0x00, + 0xCC, 0x00, 0x66, 0x00, + 0xCC, 0x00, 0x33, 0x00, + 0xCC, 0x00, 0x00, 0x00, + 0x99, 0xFF, 0xFF, 0x00, + 0x99, 0xFF, 0xCC, 0x00, + 0x99, 0xFF, 0x99, 0x00, + 0x99, 0xFF, 0x66, 0x00, + 0x99, 0xFF, 0x33, 0x00, + 0x99, 0xFF, 0x00, 0x00, + 0x99, 0xCC, 0xFF, 0x00, + 0x99, 0xCC, 0xCC, 0x00, + 0x99, 0xCC, 0x99, 0x00, + 0x99, 0xCC, 0x66, 0x00, + 0x99, 0xCC, 0x33, 0x00, + 0x99, 0xCC, 0x00, 0x00, + 0x99, 0x99, 0xFF, 0x00, + 0x99, 0x99, 0xCC, 0x00, + 0x99, 0x99, 0x99, 0x00, + 0x99, 0x99, 0x66, 0x00, + 0x99, 0x99, 0x33, 0x00, + 0x99, 0x99, 0x00, 0x00, + 0x99, 0x66, 0xFF, 0x00, + 0x99, 0x66, 0xCC, 0x00, + 0x99, 0x66, 0x99, 0x00, + 0x99, 0x66, 0x66, 0x00, + 0x99, 0x66, 0x33, 0x00, + 0x99, 0x66, 0x00, 0x00, + 0x99, 0x33, 0xFF, 0x00, + 0x99, 0x33, 0xCC, 0x00, + 0x99, 0x33, 0x99, 0x00, + 0x99, 0x33, 0x66, 0x00, + 0x99, 0x33, 0x33, 0x00, + 0x99, 0x33, 0x00, 0x00, + 0x99, 0x00, 0xFF, 0x00, + 0x99, 0x00, 0xCC, 0x00, + 0x99, 0x00, 0x99, 0x00, + 0x99, 0x00, 0x66, 0x00, + 0x99, 0x00, 0x33, 0x00, + 0x99, 0x00, 0x00, 0x00, + 0x66, 0xFF, 0xFF, 0x00, + 0x66, 0xFF, 0xCC, 0x00, + 0x66, 0xFF, 0x99, 0x00, + 0x66, 0xFF, 0x66, 0x00, + 0x66, 0xFF, 0x33, 0x00, + 0x66, 0xFF, 0x00, 0x00, + 0x66, 0xCC, 0xFF, 0x00, + 0x66, 0xCC, 0xCC, 0x00, + 0x66, 0xCC, 0x99, 0x00, + 0x66, 0xCC, 0x66, 0x00, + 0x66, 0xCC, 0x33, 0x00, + 0x66, 0xCC, 0x00, 0x00, + 0x66, 0x99, 0xFF, 0x00, + 0x66, 0x99, 0xCC, 0x00, + 0x66, 0x99, 0x99, 0x00, + 0x66, 0x99, 0x66, 0x00, + 0x66, 0x99, 0x33, 0x00, + 0x66, 0x99, 0x00, 0x00, + 0x66, 0x66, 0xFF, 0x00, + 0x66, 0x66, 0xCC, 0x00, + 0x66, 0x66, 0x99, 0x00, + 0x66, 0x66, 0x66, 0x00, + 0x66, 0x66, 0x33, 0x00, + 0x66, 0x66, 0x00, 0x00, + 0x66, 0x33, 0xFF, 0x00, + 0x66, 0x33, 0xCC, 0x00, + 0x66, 0x33, 0x99, 0x00, + 0x66, 0x33, 0x66, 0x00, + 0x66, 0x33, 0x33, 0x00, + 0x66, 0x33, 0x00, 0x00, + 0x66, 0x00, 0xFF, 0x00, + 0x66, 0x00, 0xCC, 0x00, + 0x66, 0x00, 0x99, 0x00, + 0x66, 0x00, 0x66, 0x00, + 0x66, 0x00, 0x33, 0x00, + 0x66, 0x00, 0x00, 0x00, + 0x33, 0xFF, 0xFF, 0x00, + 0x33, 0xFF, 0xCC, 0x00, + 0x33, 0xFF, 0x99, 0x00, + 0x33, 0xFF, 0x66, 0x00, + 0x33, 0xFF, 0x33, 0x00, + 0x33, 0xFF, 0x00, 0x00, + 0x33, 0xCC, 0xFF, 0x00, + 0x33, 0xCC, 0xCC, 0x00, + 0x33, 0xCC, 0x99, 0x00, + 0x33, 0xCC, 0x66, 0x00, + 0x33, 0xCC, 0x33, 0x00, + 0x33, 0xCC, 0x00, 0x00, + 0x33, 0x99, 0xFF, 0x00, + 0x33, 0x99, 0xCC, 0x00, + 0x33, 0x99, 0x99, 0x00, + 0x33, 0x99, 0x66, 0x00, + 0x33, 0x99, 0x33, 0x00, + 0x33, 0x99, 0x00, 0x00, + 0x33, 0x66, 0xFF, 0x00, + 0x33, 0x66, 0xCC, 0x00, + 0x33, 0x66, 0x99, 0x00, + 0x33, 0x66, 0x66, 0x00, + 0x33, 0x66, 0x33, 0x00, + 0x33, 0x66, 0x00, 0x00, + 0x33, 0x33, 0xFF, 0x00, + 0x33, 0x33, 0xCC, 0x00, + 0x33, 0x33, 0x99, 0x00, + 0x33, 0x33, 0x66, 0x00, + 0x33, 0x33, 0x33, 0x00, + 0x33, 0x33, 0x00, 0x00, + 0x33, 0x00, 0xFF, 0x00, + 0x33, 0x00, 0xCC, 0x00, + 0x33, 0x00, 0x99, 0x00, + 0x33, 0x00, 0x66, 0x00, + 0x33, 0x00, 0x33, 0x00, + 0x33, 0x00, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0x00, + 0x00, 0xFF, 0xCC, 0x00, + 0x00, 0xFF, 0x99, 0x00, + 0x00, 0xFF, 0x66, 0x00, + 0x00, 0xFF, 0x33, 0x00, + 0x00, 0xFF, 0x00, 0x00, + 0x00, 0xCC, 0xFF, 0x00, + 0x00, 0xCC, 0xCC, 0x00, + 0x00, 0xCC, 0x99, 0x00, + 0x00, 0xCC, 0x66, 0x00, + 0x00, 0xCC, 0x33, 0x00, + 0x00, 0xCC, 0x00, 0x00, + 0x00, 0x99, 0xFF, 0x00, + 0x00, 0x99, 0xCC, 0x00, + 0x00, 0x99, 0x99, 0x00, + 0x00, 0x99, 0x66, 0x00, + 0x00, 0x99, 0x33, 0x00, + 0x00, 0x99, 0x00, 0x00, + 0x00, 0x66, 0xFF, 0x00, + 0x00, 0x66, 0xCC, 0x00, + 0x00, 0x66, 0x99, 0x00, + 0x00, 0x66, 0x66, 0x00, + 0x00, 0x66, 0x33, 0x00, + 0x00, 0x66, 0x00, 0x00, + 0x00, 0x33, 0xFF, 0x00, + 0x00, 0x33, 0xCC, 0x00, + 0x00, 0x33, 0x99, 0x00, + 0x00, 0x33, 0x66, 0x00, + 0x00, 0x33, 0x33, 0x00, + 0x00, 0x33, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0xCC, 0x00, + 0x00, 0x00, 0x99, 0x00, + 0x00, 0x00, 0x66, 0x00, + 0x00, 0x00, 0x33, 0x00, + 0xEE, 0x00, 0x00, 0x00, + 0xDD, 0x00, 0x00, 0x00, + 0xBB, 0x00, 0x00, 0x00, + 0xAA, 0x00, 0x00, 0x00, + 0x88, 0x00, 0x00, 0x00, + 0x77, 0x00, 0x00, 0x00, + 0x55, 0x00, 0x00, 0x00, + 0x44, 0x00, 0x00, 0x00, + 0x22, 0x00, 0x00, 0x00, + 0x11, 0x00, 0x00, 0x00, + 0x00, 0xEE, 0x00, 0x00, + 0x00, 0xDD, 0x00, 0x00, + 0x00, 0xBB, 0x00, 0x00, + 0x00, 0xAA, 0x00, 0x00, + 0x00, 0x88, 0x00, 0x00, + 0x00, 0x77, 0x00, 0x00, + 0x00, 0x55, 0x00, 0x00, + 0x00, 0x44, 0x00, 0x00, + 0x00, 0x22, 0x00, 0x00, + 0x00, 0x11, 0x00, 0x00, + 0x00, 0x00, 0xEE, 0x00, + 0x00, 0x00, 0xDD, 0x00, + 0x00, 0x00, 0xBB, 0x00, + 0x00, 0x00, 0xAA, 0x00, + 0x00, 0x00, 0x88, 0x00, + 0x00, 0x00, 0x77, 0x00, + 0x00, 0x00, 0x55, 0x00, + 0x00, 0x00, 0x44, 0x00, + 0x00, 0x00, 0x22, 0x00, + 0x00, 0x00, 0x11, 0x00, + 0xEE, 0xEE, 0xEE, 0x00, + 0xDD, 0xDD, 0xDD, 0x00, + 0xBB, 0xBB, 0xBB, 0x00, + 0xAA, 0xAA, 0xAA, 0x00, + 0x88, 0x88, 0x88, 0x00, + 0x77, 0x77, 0x77, 0x00, + 0x55, 0x55, 0x55, 0x00, + 0x44, 0x44, 0x44, 0x00, + 0x22, 0x22, 0x22, 0x00, + 0x11, 0x11, 0x11, 0x00, + 0x00, 0x00, 0x00, 0x00 +]; + #[cfg(test)] mod test { use super::*;