///|
/// # CUR 扩展 CUR Extended
///
/// CUR 扩展功能 CUR extended features
///|
/// CUR 扩展信息(包含图像数量、热点坐标等)
pub struct CurInfoExtended {
icon_type : Int32
num_images : Int32
widths : Array[Int32]
heights : Array[Int32]
hotspot_xs : Array[Int32]
hotspot_ys : Array[Int32]
width : Int32
height : Int32
num_channels : Int32
has_alpha : Bool
}
///|
/// 检测数据是否为 CUR 格式
///
/// 仅看前 4 字节会把 24/32-bit TGA 误判为 CUR(TGA 头前 4 字节恰好是
/// `00 00 02 00`)。这里同时校验图像条目数 ≥ 1 且目录表装得下。
pub fn is_cur_format(data : Bytes) -> Bool {
let len = data.length()
if len < 6 {
return false
}
let reserved = read_u16_le(data, 0)
let icon_type = read_u16_le(data, 2)
let count = read_u16_le(data, 4)
reserved == 0 && icon_type == 2 && count >= 1 && len >= 6 + count * 16
}
///|
/// 解析 CUR 扩展头部信息
pub fn cur_info_extended(
data : Bytes,
) -> CurInfoExtended raise @types.LoadError {
let len = data.length()
if len < 6 {
raise @types.LoadError::DecodeFailed("CUR 数据过短")
}
let icon_type = read_u16_le(data, 2)
let count = read_u16_le(data, 4)
if icon_type != 2 {
raise @types.LoadError::UnsupportedFormat("Not a CUR file")
}
if count == 0 {
raise @types.LoadError::DecodeFailed("CUR 无图像条目")
}
if len < 6 + count * 16 {
raise @types.LoadError::DecodeFailed("CUR 目录数据不完整")
}
let widths : Array[Int32] = []
let heights : Array[Int32] = []
let hotspot_xs : Array[Int32] = []
let hotspot_ys : Array[Int32] = []
let mut best_w = 0
let mut best_h = 0
let mut best_area = 0
for i in 0.. best_area {
best_area = area
best_w = real_w
best_h = real_h
}
}
CurInfoExtended::{
icon_type,
num_images: count,
widths,
heights,
hotspot_xs,
hotspot_ys,
width: best_w,
height: best_h,
num_channels: 4,
has_alpha: true,
}
}