image.codec\lib\region.mbt

100% · 6 / 6 points · 21 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/// # 区域解码入口 Region decode entry
  3. 3///
  4. 4/// 按魔数自动识别 PNG / BMP / QOI,只解码请求矩形。
  5. 5pub fn decode_region(
  6. 6 data : Bytes,
  7. 7 x : Int32,
  8. 8 y : Int32,
  9. 9 w : Int32,
  10. 10 h : Int32,
  11. 11) -> @types.Image raise @types.LoadError {
  12. 12● match detect_format(data) {
  13. 13● @types.ImageFormat::Png => @codec.decode_png_region(data, x, y, w, h)
  14. 14● @types.ImageFormat::Bmp => @codec.decode_bmp_region(data, x, y, w, h)
  15. 15● @types.ImageFormat::Qoi => @codec.decode_qoi_region(data, x, y, w, h)
  16. 16 _ =>
  17. 17● raise @types.LoadError::DecodeFailed(
  18. 18 "decode_region 暂只支持 PNG / BMP / QOI",
  19. 19 )
  20. 20 }
  21. 21}