Skip to main content

Module image

Module image 

Source
Expand description

图片基础设施(阶段 6:图片渲染)

架构:

  • core 只持有 解码后的 RGBA 数据(ImageData)与 texture_id (全局原子分配,0 保留给 glyph atlas)。文件 IO 与 PNG/JPEG/WebP 解码在 mgui-components::image_loader(image-decode feature)完成, core 不碰文件系统与图像解码器。
  • paint 输出复用 B2 的 PaintCommand::TexturedRect(uv 全图 [0,0,1,1], texture_id = 图片纹理)。runtime 端按 texture_id 分段 set bind group。
  • BoxFit::Fill 拉伸铺满 widget;BoxFit::Contain 等比缩放居中 (letterbox,绘制矩形在 layout 时算好存 dst_rect)。

ImageWidget 已迁移到 mgui-components crate。

Structs§

ImageData
解码后的位图(直排 RGBA8,每像素 4 字节)。
ImageRenderObject
图片 RO:paint 输出一条 TexturedRect(uv 全图,texture_id 非 0)

Enums§

BoxFit
图片填充模式
TextureUpdate
一张图片纹理在“同一个 texture_id 又来了一次 register“时该怎么处理。

Functions§

image_identity
Rc<ImageData> 的身份。存进缓存的同时必须把 Rc 本身留住, 否则释放后地址被复用,会把“另一张图“误判成“同一帧“。
next_image_id
分配一个全局唯一的图片 texture id
plan_texture_update
该不该更新纹理。无 GPU、无分配,纯函数,所以两端与单测看的是同一条规则。