Tycho Image — typed RGBA/HDR image IO (PNG/JPEG/PPM/BMP decode, PNG encode) for the Tycho stack
Part of the Tycho graphics stack — mounted there as the image/ submodule.
let img = @image.load_rgba("assets/logo.png")
let tex = dev.create_texture_format(img.width, img.height, @tycho.TextureFormat::RGBA8, img.data)pub suberror ImageError {
DecodeFailed(String)
IoFailed(String)
EncodeFailed(String)
}pub(all) struct HdrImage {
width : Int
height : Int
pixels : FixedArray[Float]
}fn Image::encode(self : Image, format : EncodeFormat, options? : StbiwOptions) -> Bytes raise ImageErrorpub(all) struct StbiGif {
width : Int
height : Int
frames : Int
channels_in_file : Int
channels : Int
delays : FixedArray[Int]
data : Bytes
}pub(all) struct StbiImage16 {
width : Int
height : Int
channels_in_file : Int
channels : Int
data : FixedArray[UInt16]
}pub(all) struct StbiImage8 {
width : Int
height : Int
channels_in_file : Int
channels : Int
data : Bytes
}pub(all) struct StbiImageF {
width : Int
height : Int
channels_in_file : Int
channels : Int
data : FixedArray[Float]
}pub(all) struct StbiInfo {
width : Int
height : Int
channels : Int
image_type : StbiImageType
is_16_bit : Bool
is_hdr : Bool
is_iphone_png : Bool
} derive(Eq, Debug)pub(all) struct StbiOptions {
flip_vertically : Bool
unpremultiply_iphone_png : Bool
convert_iphone_png_to_rgb : Bool
ldr_to_hdr_gamma : Float
ldr_to_hdr_scale : Float
hdr_to_ldr_gamma : Float
hdr_to_ldr_scale : Float
}pub(all) struct StbiwOptions {
flip_vertically : Bool
tga_with_rle : Bool
png_compression_level : Int
force_png_filter : Int
jpg_quality : Int
}fn read_file_bytes(path : String) -> Bytesfn save_hdr_image(path : String, image : HdrImage, options? : StbiwOptions) -> Unit raise ImageErrorfn save_image(path : String, image : Image, format : EncodeFormat, options? : StbiwOptions) -> Unit raise ImageErrorfn save_png_rgba(path : String, width : Int, height : Int, data : Bytes, bgra? : Bool) -> Unit raise ImageErrorfn stbi_is_16_bit_from_memory(buffer : Bytes) -> Boolfn stbi_is_hdr_from_memory(buffer : Bytes) -> Boolfn stbi_load_16_from_memory(buffer : Bytes, desired_channels? : Int, options? : StbiOptions) -> StbiImage16?fn stbi_load_from_memory(buffer : Bytes, desired_channels? : Int, options? : StbiOptions) -> StbiImage8?fn stbi_load_gif_from_memory(buffer : Bytes, desired_channels? : Int, options? : StbiOptions) -> StbiGif?fn stbi_loadf_from_memory(buffer : Bytes, desired_channels? : Int, options? : StbiOptions) -> StbiImageF?fn stbi_write_bmp_to_memory(width : Int, height : Int, comp : Int, data : Bytes, stride_in_bytes? : Int, options? : StbiwOptions) -> Bytes?fn stbi_write_hdr_to_memory(width : Int, height : Int, comp : Int, data : FixedArray[Float], stride_in_floats? : Int, options? : StbiwOptions) -> Bytes?fn stbi_write_jpg_to_memory(width : Int, height : Int, comp : Int, data : Bytes, quality? : Int, stride_in_bytes? : Int, options? : StbiwOptions) -> Bytes?fn stbi_write_png_to_memory(width : Int, height : Int, comp : Int, data : Bytes, stride_in_bytes? : Int, options? : StbiwOptions) -> Bytes?fn stbi_write_tga_to_memory(width : Int, height : Int, comp : Int, data : Bytes, stride_in_bytes? : Int, options? : StbiwOptions) -> Bytes?fn stbi_zlib_compress(data : Bytes, quality? : Int) -> Bytes?fn stbi_zlib_decode(data : Bytes) -> Bytes?fn stbi_zlib_decode_noheader(data : Bytes) -> Bytes?Install
Download zipTycho Image — typed RGBA/HDR image IO (PNG/JPEG/PPM/BMP decode, PNG encode) for the Tycho stack