Skip to main content

read_webp_dimensions

Function read_webp_dimensions 

Source
fn read_webp_dimensions(data: &[u8]) -> Option<(u32, u32)>
Expand description

手动解析 WebP RIFF header 拿尺寸(前 30 字节即够,不调用 zenwebp 全解码器)。

不用 zenwebp::WebPDecoder::build 的原因:VP8X(扩展格式)的全解码器在 构造时会扫描所有 RIFF chunk(EXIF/ICCP/ALPH…),文件大于传入缓冲区时失败。 get_image_dimensions 只读 64 KiB header 前缀,大 VP8X WebP(> 64 KiB) 因此丢失尺寸 → rebuild 索引时该文件被跳过 → DB 行被误删(issue #30)。

三种子格式的尺寸都在 RIFF 签名之后的前 30 字节内:

  • VP8 (lossy):byte 26-27 width、28-29 height,u16_le & 0x3FFF
  • VP8L(lossless):byte 21-24 为 u32_le header, width=(1+h)&0x3FFFheight=(1+(h>>14))&0x3FFF
  • VP8X(extended):byte 24-26 / 27-29 各为 24-bit LE,+1 得画布尺寸