image.core\testgen\vp8.mbt

89.9% · 89 / 99 points · 111 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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