image.codec\codec\unified_info.mbt
77.2% · 71 / 92 points · 159 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 统一信息 Unified Info - 3
/// - 4
/// 统一图像信息提取 - 5
/// 统一图像信息提取 Unified image information extraction - 6
- 7
///| - 8
/// 统一图像扩展信息(自动格式检测后的联合类型) - 9
/// - 10
/// 通过 `get_image_info_extended` 自动检测格式并返回对应类型的扩展信息 - 11
/// `#non_exhaustive` 表示未来可能添加新构造器 - 12
#non_exhaustive - 13
pub enum ImageInfoExtended { - 14
Avif(AvifInfoExtended) - 15
Heif(HeifInfoExtended) - 16
JpegXl(JpegXlInfoExtended) - 17
Webp(WebpInfoExtended) - 18
Tiff(TiffInfoExtended) - 19
Psd(PsdInfoExtended) - 20
Bmp(BmpInfoExtended) - 21
Gif(GifInfoExtended) - 22
Png(PngInfoExtended) - 23
Jpeg(JpegInfoExtended) - 24
Qoi(QoiInfoExtended) - 25
Tga(TgaInfoExtended) - 26
Hdr(HdrInfoExtended) - 27
Pnm(PnmInfoExtended) - 28
Ico(IcoInfoExtended) - 29
Cur(CurInfoExtended) - 30
Icns(IcnsInfoExtended) - 31
Apng(ApngInfoExtended) - 32
} - 33
- 34
///| - 35
/// 检测图像格式并返回对应的扩展信息 - 36
/// - 37
/// 按 magic number 顺序检测 18 种格式,返回对应类型的 ImageInfoExtended - 38
/// TGA 无明确 magic,放在最后通过头部字段有效性判断 - 39
pub fn get_image_info_extended( - 40
data : Bytes, - 41
) -> ImageInfoExtended raise @types.LoadError { - 42●
if is_apng_format(data) { - 43●
return ImageInfoExtended::Apng(apng_info_extended(data)) - 44
} - 45●
if is_png_format(data) { - 46●
return ImageInfoExtended::Png(png_info_extended(data)) - 47
} - 48●
if is_jpeg_format(data) { - 49●
return ImageInfoExtended::Jpeg(jpeg_info_extended(data)) - 50
} - 51●
if is_bmp_format(data) { - 52●
return ImageInfoExtended::Bmp(bmp_info_extended(data)) - 53
} - 54●
if is_gif_format(data) { - 55●
return ImageInfoExtended::Gif(gif_info_extended(data)) - 56
} - 57●
if is_qoi_format(data) { - 58●
return ImageInfoExtended::Qoi(qoi_info_extended(data)) - 59
} - 60●
if is_hdr_format(data) { - 61●
return ImageInfoExtended::Hdr(hdr_info_extended(data)) - 62
} - 63●
if is_pnm_format(data) { - 64●
return ImageInfoExtended::Pnm(pnm_info_extended(data)) - 65
} - 66●
if is_icns_format(data) { - 67●
return ImageInfoExtended::Icns(icns_info_extended(data)) - 68
} - 69●
if is_webp_format(data) { - 70●
return ImageInfoExtended::Webp(webp_info_extended(data)) - 71
} - 72●
if is_tiff_format(data) { - 73●
return ImageInfoExtended::Tiff(tiff_info_extended(data)) - 74
} - 75●
if is_psd_format(data) { - 76○
return ImageInfoExtended::Psd(psd_info_extended(data)) - 77
} - 78●
if is_avif_format(data) { - 79○
return ImageInfoExtended::Avif(avif_info_extended(data)) - 80
} - 81●
if is_heif_format(data) { - 82○
return ImageInfoExtended::Heif(heif_info_extended(data)) - 83
} - 84●
if is_jpegxl_format(data) { - 85○
return ImageInfoExtended::JpegXl(jpegxl_info_extended(data)) - 86
} - 87●
if is_ico_format(data) { - 88●
return ImageInfoExtended::Ico(ico_info_extended(data)) - 89
} - 90●
if is_cur_format(data) { - 91●
return ImageInfoExtended::Cur(cur_info_extended(data)) - 92
} - 93●
if is_tga_format(data) { - 94●
return ImageInfoExtended::Tga(tga_info_extended(data)) - 95
} - 96
raise @types.LoadError::UnsupportedFormat("Unknown image format") - 97
} - 98
- 99
///| - 100
/// 检测图像格式名称 - 101
/// - 102
/// 检测 18 种格式,返回格式名称字符串 - 103
pub fn detect_image_format(data : Bytes) -> String { - 104●
if is_apng_format(data) { - 105○
return "APNG" - 106
} - 107●
if is_png_format(data) { - 108●
return "PNG" - 109
} - 110●
if is_jpeg_format(data) { - 111●
return "JPEG" - 112
} - 113●
if is_bmp_format(data) { - 114●
return "BMP" - 115
} - 116●
if is_gif_format(data) { - 117●
return "GIF" - 118
} - 119●
if is_qoi_format(data) { - 120●
return "QOI" - 121
} - 122●
if is_hdr_format(data) { - 123○
return "HDR" - 124
} - 125●
if is_pnm_format(data) { - 126○
return "PNM" - 127
} - 128●
if is_icns_format(data) { - 129○
return "ICNS" - 130
} - 131●
if is_webp_format(data) { - 132○
return "WebP" - 133
} - 134●
if is_tiff_format(data) { - 135○
return "TIFF" - 136
} - 137●
if is_psd_format(data) { - 138○
return "PSD" - 139
} - 140●
if is_avif_format(data) { - 141○
return "AVIF" - 142
} - 143●
if is_heif_format(data) { - 144○
return "HEIF" - 145
} - 146●
if is_jpegxl_format(data) { - 147○
return "JPEG-XL" - 148
} - 149●
if is_ico_format(data) { - 150○
return "ICO" - 151
} - 152●
if is_cur_format(data) { - 153○
return "CUR" - 154
} - 155●
if is_tga_format(data) { - 156○
return "TGA" - 157
} - 158
"unknown" - 159
}