image.core\testgen\vp8.mbt
89.9% · 89 / 99 points · 111 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// 构造最小 VP8 **inter(非关键帧)**:3 字节小端 tag(bit0=1、show_frame=1、 - 3
/// first_part_size 写入 bit5-23),随后为全零首分区。inter 帧头不携带分辨率, - 4
/// 解码器应使用参考帧尺寸(见 decode_vp8_inter_frame)。 - 5
pub fn build_vp8_inter_frame(first_part_size~ : Int32 = 32) -> Bytes { - 6◐
let size = if first_part_size < 0 { 0 } else { first_part_size } - 7
let tag = (1 << 0) | (0 << 1) | (1 << 4) | ((size & 0x7FFFF) << 5) - 8
let out : Array[Byte] = [] - 9●
out.push((tag & 0xFF).to_byte()) - 10●
out.push(((tag >> 8) & 0xFF).to_byte()) - 11●
out.push(((tag >> 16) & 0xFF).to_byte()) - 12
for _ in 0..<size { - 13●
out.push(b'\x00') - 14
} - 15●
Bytes::from_array(out) - 16
} - 17
- 18
///| - 19
/// 构造最小 VP8 **key frame**:小端 tag + start code(9D 01 2A)+ 小端分辨率 - 20
/// + 全零首分区。可用于 decode_vp8_frame(零 token 会解码为平坦图像)。 - 21
pub fn build_vp8_key_frame( - 22
width : Int32, - 23
height : Int32, - 24
first_part_size~ : Int32 = 32, - 25
) -> Bytes { - 26◐
let w = if width < 0 { 0 } else { width } - 27◐
let h = if height < 0 { 0 } else { height } - 28◐
let size = if first_part_size < 0 { 0 } else { first_part_size } - 29
let tag = (0 << 0) | (0 << 1) | (1 << 4) | ((size & 0x7FFFF) << 5) - 30
let out : Array[Byte] = [] - 31●
out.push((tag & 0xFF).to_byte()) - 32●
out.push(((tag >> 8) & 0xFF).to_byte()) - 33●
out.push(((tag >> 16) & 0xFF).to_byte()) - 34●
out.push(b'\x9D') - 35●
out.push(b'\x01') - 36●
out.push(b'\x2A') - 37●
out.push((w & 0xFF).to_byte()) - 38●
out.push(((w >> 8) & 0x3F).to_byte()) - 39●
out.push((h & 0xFF).to_byte()) - 40●
out.push(((h >> 8) & 0x3F).to_byte()) - 41
for _ in 0..<size { - 42●
out.push(b'\x00') - 43
} - 44●
Bytes::from_array(out) - 45
} - 46
- 47
///| - 48
/// 构造走帧内预测分支的最小 VP8 关键帧:首分区前两字节为 0xFF,使 - 49
/// Vp8BoolDecoder 的首个 read_bool(180) 判为 1(is_intra),其后以 0 填充。 - 50
pub fn build_vp8_intra_frame( - 51
width : Int32, - 52
height : Int32, - 53
ones~ : Int32 = 2, - 54
) -> Bytes { - 55◐
let w = if width < 0 { 0 } else { width } - 56◐
let h = if height < 0 { 0 } else { height } - 57◐
let n = if ones < 2 { 2 } else { ones } - 58
let stream : Array[Byte] = [] - 59
for _ in 0..<n { - 60●
stream.push(b'\xFF') - 61
} - 62
for _ in 0..<30 { - 63●
stream.push(b'\x00') - 64
} - 65●
let size = stream.length() - 66
let out : Array[Byte] = [] - 67
let tag = (0 << 0) | (0 << 1) | (1 << 4) | ((size & 0x7FFFF) << 5) - 68●
out.push((tag & 0xFF).to_byte()) - 69●
out.push(((tag >> 8) & 0xFF).to_byte()) - 70●
out.push(((tag >> 16) & 0xFF).to_byte()) - 71●
out.push(b'\x9D') - 72●
out.push(b'\x01') - 73●
out.push(b'\x2A') - 74●
out.push((w & 0xFF).to_byte()) - 75●
out.push(((w >> 8) & 0x3F).to_byte()) - 76●
out.push((h & 0xFF).to_byte()) - 77●
out.push(((h >> 8) & 0x3F).to_byte()) - 78
for b in stream { - 79●
out.push(b) - 80
} - 81●
Bytes::from_array(out) - 82
} - 83
- 84
///| - 85
/// 构造首分区为指定重复字节的最小 VP8 关键帧(用于探索不同解码分支)。 - 86
pub fn build_vp8_pattern_frame( - 87
width : Int32, - 88
height : Int32, - 89
byte_val~ : Int32 = 170, - 90
size~ : Int32 = 32, - 91
) -> Bytes { - 92◐
let w = if width < 0 { 0 } else { width } - 93◐
let h = if height < 0 { 0 } else { height } - 94◐
let n = if size < 2 { 2 } else { size } - 95
let out : Array[Byte] = [] - 96
let tag = (0 << 0) | (0 << 1) | (1 << 4) | ((n & 0x7FFFF) << 5) - 97●
out.push((tag & 0xFF).to_byte()) - 98●
out.push(((tag >> 8) & 0xFF).to_byte()) - 99●
out.push(((tag >> 16) & 0xFF).to_byte()) - 100●
out.push(157) - 101●
out.push(1) - 102●
out.push(42) - 103●
out.push((w & 0xFF).to_byte()) - 104●
out.push(((w >> 8) & 0x3F).to_byte()) - 105●
out.push((h & 0xFF).to_byte()) - 106●
out.push(((h >> 8) & 0x3F).to_byte()) - 107
for _ in 0..<n { - 108●
out.push((byte_val & 0xFF).to_byte()) - 109
} - 110●
Bytes::from_array(out) - 111
}