Sign in

    image

    MoonBit image: simple image representation.

    image
    color
    moonbit
    Download zip
    Author
    Version
    0.17.18
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    8K

    Dependencies

    #gmlewis/image

    check

    This is a simple image representation based on Go's implementation: https://cs.opensource.google/go/go/+/refs/tags/go1.23.3:src/image/image.go which has the copyright notice:

    // Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.

    #Status

    The code has been updated to support compiler:

    $ moon version --all moon 0.1.20261016 (1af328f 2026-10-16) ~/.moon/bin/moon moonc v0.10.16+b1a0e846e (2026-10-16) ~/.moon/bin/moonc moonrun 0.1.20261016 (1af328f 2026-10-16) ~/.moon/bin/moonrun

    Image

    pub(open) trait Image {
    fn color_model(Self) -> &
    Model

    fn bounds(Self) -> Rectangle
    fn at(Self, Int, Int) -> &
    Color

    fn opaque_(Self) -> Bool
    fn set(Self, Int, Int, &
    Color
    ) -> Unit
    fn sub_image(Self, Rectangle) -> &Image
    fn as_ycbcr(Self) -> YCbCr?
    fn raw_data(Self) ->
    Slice
    [Byte]
    fn get_bytes_per_pixel(Self) -> Int
    fn get_stride(Self) -> Int
    fn pix_offset(Self, Int, Int) -> Int
    fn color_index_at(Self, Int, Int) -> Byte
    }

    Image is a finite rectangular grid of [color.Color] values taken from a color model.

    RGBA64Image

    pub(open) trait RGBA64Image {
    fn rgba64_at(Self, Int, Int) ->
    RGBA64

    fn color_model(Self) -> &
    Model

    fn bounds(Self) -> Rectangle
    fn at(Self, Int, Int) -> &
    Color

    }

    RGBA64Image is an [Image] whose pixels can be converted directly to a color.RGBA64.

    SizeError

    type SizeError derive(Eq)

    impl Show for SizeError

    SizeError::equal

    fn SizeError::equal(SizeError, SizeError) -> Bool

    SizeError::to_string

    fn SizeError::to_string(self : SizeError) -> String

    Alpha

    pub(all) struct Alpha {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    Alpha is an in-memory image whose At method returns [color.Alpha] values.
    impl Image for Alpha

    Alpha::alpha_at

    fn Alpha::alpha_at(self : Alpha, x : Int, y : Int) ->
    Alpha

    Alpha::as_ycbcr

    fn Alpha::as_ycbcr(_self : Alpha) -> YCbCr?

    Alpha::at

    fn Alpha::at(self : Alpha, x : Int, y : Int) -> &
    Color

    Alpha::bounds

    fn Alpha::bounds(self : Alpha) -> Rectangle

    Alpha::color_index_at

    fn Alpha::color_index_at(_self : Alpha, _x : Int, _y : Int) -> Byte

    Alpha::color_model

    fn Alpha::color_model(_self : Alpha) -> &
    Model

    Alpha::get

    #alias("_[_]")
    fn Alpha::get(self : Alpha, p : Point) -> &
    Color

    Alpha::get_bytes_per_pixel

    fn Alpha::get_bytes_per_pixel(_self : Alpha) -> Int

    Alpha::get_stride

    fn Alpha::get_stride(self : Alpha) -> Int

    Alpha::new

    fn Alpha::new(r : Rectangle) -> Alpha raise SizeError

    Alpha::new returns a new [Alpha] image with the given bounds.

    Alpha::new_empty

    fn Alpha::new_empty() -> Alpha

    Alpha::opaque_

    fn Alpha::opaque_(self : Alpha) -> Bool

    Alpha::pix_offset

    fn Alpha::pix_offset(self : Alpha, x : Int, y : Int) -> Int

    Alpha::raw_data

    fn Alpha::raw_data(self : Alpha) ->
    Slice
    [Byte]

    Alpha::rgba64_at

    fn Alpha::rgba64_at(self : Alpha, x : Int, y : Int) ->
    RGBA64

    Alpha::set

    fn Alpha::set(self : Alpha, x : Int, y : Int, c : &
    Color
    ) -> Unit

    Alpha::set_alpha

    fn Alpha::set_alpha(self : Alpha, x : Int, y : Int, c :
    Alpha
    ) -> Unit

    Alpha::set_point

    #alias("_[_]=_")
    fn Alpha::set_point(self : Alpha, p : Point, c : &
    Color
    ) -> Unit

    Alpha::set_rgba64

    fn Alpha::set_rgba64(self : Alpha, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    Alpha::sub_image

    fn Alpha::sub_image(self : Alpha, r : Rectangle) -> &Image

    Alpha16

    pub(all) struct Alpha16 {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    Alpha16 is an in-memory image whose At method returns [color.Alpha16] values.
    impl Image for Alpha16

    Alpha16::alpha16_at

    fn Alpha16::alpha16_at(self : Alpha16, x : Int, y : Int) ->
    Alpha16

    Alpha16::as_ycbcr

    fn Alpha16::as_ycbcr(_self : Alpha16) -> YCbCr?

    Alpha16::at

    fn Alpha16::at(self : Alpha16, x : Int, y : Int) -> &
    Color

    Alpha16::bounds

    fn Alpha16::bounds(self : Alpha16) -> Rectangle

    Alpha16::color_index_at

    fn Alpha16::color_index_at(_self : Alpha16, _x : Int, _y : Int) -> Byte

    Alpha16::color_model

    fn Alpha16::color_model(_self : Alpha16) -> &
    Model

    Alpha16::get

    #alias("_[_]")
    fn Alpha16::get(self : Alpha16, p : Point) -> &
    Color

    Alpha16::get_bytes_per_pixel

    fn Alpha16::get_bytes_per_pixel(_self : Alpha16) -> Int

    Alpha16::get_stride

    fn Alpha16::get_stride(self : Alpha16) -> Int

    Alpha16::new

    fn Alpha16::new(r : Rectangle) -> Alpha16 raise SizeError

    Alpha16::new returns a new [Alpha16] image with the given bounds.

    Alpha16::new_empty

    fn Alpha16::new_empty() -> Alpha16

    Alpha16::opaque_

    fn Alpha16::opaque_(self : Alpha16) -> Bool

    Alpha16::pix_offset

    fn Alpha16::pix_offset(self : Alpha16, x : Int, y : Int) -> Int

    Alpha16::raw_data

    fn Alpha16::raw_data(self : Alpha16) ->
    Slice
    [Byte]

    Alpha16::rgba64_at

    fn Alpha16::rgba64_at(self : Alpha16, x : Int, y : Int) ->
    RGBA64

    Alpha16::set

    fn Alpha16::set(self : Alpha16, x : Int, y : Int, c : &
    Color
    ) -> Unit

    Alpha16::set_alpha16

    fn Alpha16::set_alpha16(self : Alpha16, x : Int, y : Int, c :
    Alpha16
    ) -> Unit

    Alpha16::set_point

    #alias("_[_]=_")
    fn Alpha16::set_point(self : Alpha16, p : Point, c : &
    Color
    ) -> Unit

    Alpha16::set_rgba64

    fn Alpha16::set_rgba64(self : Alpha16, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    Alpha16::sub_image

    fn Alpha16::sub_image(self : Alpha16, r : Rectangle) -> &Image

    CMYK

    pub(all) struct CMYK {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    CMYK is an in-memory image whose At method returns [color.CMYK] values.
    impl Image for CMYK

    CMYK::as_ycbcr

    fn CMYK::as_ycbcr(_self : CMYK) -> YCbCr?

    CMYK::at

    fn CMYK::at(self : CMYK, x : Int, y : Int) -> &
    Color

    CMYK::bounds

    fn CMYK::bounds(self : CMYK) -> Rectangle

    CMYK::cmyk_at

    fn CMYK::cmyk_at(self : CMYK, x : Int, y : Int) ->
    CMYK

    CMYK::color_index_at

    fn CMYK::color_index_at(_self : CMYK, _x : Int, _y : Int) -> Byte

    CMYK::color_model

    fn CMYK::color_model(_self : CMYK) -> &
    Model

    CMYK::get

    #alias("_[_]")
    fn CMYK::get(self : CMYK, p : Point) -> &
    Color

    CMYK::get_bytes_per_pixel

    fn CMYK::get_bytes_per_pixel(_self : CMYK) -> Int

    CMYK::get_stride

    fn CMYK::get_stride(self : CMYK) -> Int

    CMYK::new

    fn CMYK::new(r : Rectangle) -> CMYK raise SizeError

    CMYK::new returns a new CMYK image with the given bounds.

    CMYK::new_empty

    fn CMYK::new_empty() -> CMYK

    CMYK::opaque_

    fn CMYK::opaque_(_self : CMYK) -> Bool

    CMYK::pix_offset

    fn CMYK::pix_offset(self : CMYK, x : Int, y : Int) -> Int

    CMYK::raw_data

    fn CMYK::raw_data(self : CMYK) ->
    Slice
    [Byte]

    CMYK::rgba64_at

    fn CMYK::rgba64_at(self : CMYK, x : Int, y : Int) ->
    RGBA64

    CMYK::set

    fn CMYK::set(self : CMYK, x : Int, y : Int, c : &
    Color
    ) -> Unit

    CMYK::set_cmyk

    fn CMYK::set_cmyk(self : CMYK, x : Int, y : Int, c :
    CMYK
    ) -> Unit

    CMYK::set_rgba64

    fn CMYK::set_rgba64(self : CMYK, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    CMYK::sub_image

    fn CMYK::sub_image(self : CMYK, r : Rectangle) -> &Image

    Config

    pub(all) struct Config {
    color_model : &
    Model

    width : Int
    height : Int
    }

    Config holds an image's color model and dimensions.

    Config::new_empty

    fn Config::new_empty() -> Config

    Gray

    pub(all) struct Gray {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    Gray is an in-memory image whose At method returns [color.Gray] values.
    impl Image for Gray

    Gray::as_ycbcr

    fn Gray::as_ycbcr(_self : Gray) -> YCbCr?

    Gray::at

    fn Gray::at(self : Gray, x : Int, y : Int) -> &
    Color

    Gray::bounds

    fn Gray::bounds(self : Gray) -> Rectangle

    Gray::color_index_at

    fn Gray::color_index_at(_self : Gray, _x : Int, _y : Int) -> Byte

    Gray::color_model

    fn Gray::color_model(_self : Gray) -> &
    Model

    Gray::get

    #alias("_[_]")
    fn Gray::get(self : Gray, p : Point) -> &
    Color

    Gray::get_bytes_per_pixel

    fn Gray::get_bytes_per_pixel(_self : Gray) -> Int

    Gray::get_stride

    fn Gray::get_stride(self : Gray) -> Int

    Gray::gray_at

    fn Gray::gray_at(self : Gray, x : Int, y : Int) ->
    Gray

    Gray::new

    fn Gray::new(r : Rectangle) -> Gray raise SizeError

    Gray::new returns a new [Gray] image with the given bounds.

    Gray::new_empty

    fn Gray::new_empty() -> Gray

    Gray::opaque_

    fn Gray::opaque_(_self : Gray) -> Bool

    Gray::pix_offset

    fn Gray::pix_offset(self : Gray, x : Int, y : Int) -> Int

    Gray::raw_data

    fn Gray::raw_data(self : Gray) ->
    Slice
    [Byte]

    Gray::rgba64_at

    fn Gray::rgba64_at(self : Gray, x : Int, y : Int) ->
    RGBA64

    Gray::set

    fn Gray::set(self : Gray, x : Int, y : Int, c : &
    Color
    ) -> Unit

    Gray::set_gray

    fn Gray::set_gray(self : Gray, x : Int, y : Int, c :
    Gray
    ) -> Unit

    Gray::set_point

    #alias("_[_]=_")
    fn Gray::set_point(self : Gray, p : Point, c : &
    Color
    ) -> Unit

    Gray::set_rgba64

    fn Gray::set_rgba64(self : Gray, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    Gray::sub_image

    fn Gray::sub_image(self : Gray, r : Rectangle) -> &Image

    Gray16

    pub(all) struct Gray16 {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    Gray16 is an in-memory image whose At method returns [color.Gray16] values.
    impl Image for Gray16

    Gray16::as_ycbcr

    fn Gray16::as_ycbcr(_self : Gray16) -> YCbCr?

    Gray16::at

    fn Gray16::at(self : Gray16, x : Int, y : Int) -> &
    Color

    Gray16::bounds

    fn Gray16::bounds(self : Gray16) -> Rectangle

    Gray16::color_index_at

    fn Gray16::color_index_at(_self : Gray16, _x : Int, _y : Int) -> Byte

    Gray16::color_model

    fn Gray16::color_model(_self : Gray16) -> &
    Model

    Gray16::get

    #alias("_[_]")
    fn Gray16::get(self : Gray16, p : Point) -> &
    Color

    Gray16::get_bytes_per_pixel

    fn Gray16::get_bytes_per_pixel(_self : Gray16) -> Int

    Gray16::get_stride

    fn Gray16::get_stride(self : Gray16) -> Int

    Gray16::gray16_at

    fn Gray16::gray16_at(self : Gray16, x : Int, y : Int) ->
    Gray16

    Gray16::new

    fn Gray16::new(r : Rectangle) -> Gray16 raise SizeError

    Gray16::new returns a new [Gray16] image with the given bounds.

    Gray16::new_empty

    fn Gray16::new_empty() -> Gray16

    Gray16::opaque_

    fn Gray16::opaque_(_self : Gray16) -> Bool

    Gray16::pix_offset

    fn Gray16::pix_offset(self : Gray16, x : Int, y : Int) -> Int

    Gray16::raw_data

    fn Gray16::raw_data(self : Gray16) ->
    Slice
    [Byte]

    Gray16::rgba64_at

    fn Gray16::rgba64_at(self : Gray16, x : Int, y : Int) ->
    RGBA64

    Gray16::set

    fn Gray16::set(self : Gray16, x : Int, y : Int, c : &
    Color
    ) -> Unit

    Gray16::set_gray16

    fn Gray16::set_gray16(self : Gray16, x : Int, y : Int, c :
    Gray16
    ) -> Unit

    Gray16::set_point

    #alias("_[_]=_")
    fn Gray16::set_point(self : Gray16, p : Point, c : &
    Color
    ) -> Unit

    Gray16::set_rgba64

    fn Gray16::set_rgba64(self : Gray16, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    Gray16::sub_image

    fn Gray16::sub_image(self : Gray16, r : Rectangle) -> &Image

    NRGBA

    pub(all) struct NRGBA {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    NRGBA is an in-memory image whose At method returns [color.NRGBA] values.
    impl Image for NRGBA

    NRGBA::as_ycbcr

    fn NRGBA::as_ycbcr(_self : NRGBA) -> YCbCr?

    NRGBA::at

    fn NRGBA::at(self : NRGBA, x : Int, y : Int) -> &
    Color

    NRGBA::bounds

    fn NRGBA::bounds(self : NRGBA) -> Rectangle

    NRGBA::color_index_at

    fn NRGBA::color_index_at(_self : NRGBA, _x : Int, _y : Int) -> Byte

    NRGBA::color_model

    fn NRGBA::color_model(_self : NRGBA) -> &
    Model

    NRGBA::get

    #alias("_[_]")
    fn NRGBA::get(self : NRGBA, p : Point) -> &
    Color

    NRGBA::get_bytes_per_pixel

    fn NRGBA::get_bytes_per_pixel(_self : NRGBA) -> Int

    NRGBA::get_stride

    fn NRGBA::get_stride(self : NRGBA) -> Int

    NRGBA::new

    fn NRGBA::new(r : Rectangle) -> NRGBA raise SizeError

    NRGBA::new returns a new [NRGBA] image with the given bounds.

    NRGBA::new_empty

    fn NRGBA::new_empty() -> NRGBA

    NRGBA::nrgba_at

    fn NRGBA::nrgba_at(self : NRGBA, x : Int, y : Int) ->
    NRGBA

    NRGBA::opaque_

    fn NRGBA::opaque_(self : NRGBA) -> Bool

    NRGBA::pix_offset

    fn NRGBA::pix_offset(self : NRGBA, x : Int, y : Int) -> Int

    NRGBA::raw_data

    fn NRGBA::raw_data(self : NRGBA) ->
    Slice
    [Byte]

    NRGBA::rgba64_at

    fn NRGBA::rgba64_at(self : NRGBA, x : Int, y : Int) ->
    RGBA64

    NRGBA::set

    fn NRGBA::set(self : NRGBA, x : Int, y : Int, c : &
    Color
    ) -> Unit

    NRGBA::set_nrgba

    fn NRGBA::set_nrgba(self : NRGBA, x : Int, y : Int, c :
    NRGBA
    ) -> Unit

    NRGBA::set_point

    #alias("_[_]=_")
    fn NRGBA::set_point(self : NRGBA, p : Point, c : &
    Color
    ) -> Unit

    NRGBA::set_rgba64

    fn NRGBA::set_rgba64(self : NRGBA, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    NRGBA::sub_image

    fn NRGBA::sub_image(self : NRGBA, r : Rectangle) -> &Image

    NRGBA64

    pub(all) struct NRGBA64 {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    NRGBA64 is an in-memory image whose At method returns [color.NRGBA64] values.
    impl Image for NRGBA64

    NRGBA64::as_ycbcr

    fn NRGBA64::as_ycbcr(_self : NRGBA64) -> YCbCr?

    NRGBA64::at

    fn NRGBA64::at(self : NRGBA64, x : Int, y : Int) -> &
    Color

    NRGBA64::bounds

    fn NRGBA64::bounds(self : NRGBA64) -> Rectangle

    NRGBA64::color_index_at

    fn NRGBA64::color_index_at(_self : NRGBA64, _x : Int, _y : Int) -> Byte

    NRGBA64::color_model

    fn NRGBA64::color_model(_self : NRGBA64) -> &
    Model

    NRGBA64::get

    #alias("_[_]")
    fn NRGBA64::get(self : NRGBA64, p : Point) -> &
    Color

    NRGBA64::get_bytes_per_pixel

    fn NRGBA64::get_bytes_per_pixel(_self : NRGBA64) -> Int

    NRGBA64::get_stride

    fn NRGBA64::get_stride(self : NRGBA64) -> Int

    NRGBA64::new

    fn NRGBA64::new(r : Rectangle) -> NRGBA64 raise SizeError

    NRGBA64::new returns a new [NRGBA64] image with the given bounds.

    NRGBA64::new_empty

    fn NRGBA64::new_empty() -> NRGBA64

    NRGBA64::nrgba64_at

    fn NRGBA64::nrgba64_at(self : NRGBA64, x : Int, y : Int) ->
    NRGBA64

    NRGBA64::opaque_

    fn NRGBA64::opaque_(self : NRGBA64) -> Bool

    NRGBA64::pix_offset

    fn NRGBA64::pix_offset(self : NRGBA64, x : Int, y : Int) -> Int

    NRGBA64::raw_data

    fn NRGBA64::raw_data(self : NRGBA64) ->
    Slice
    [Byte]

    NRGBA64::rgba64_at

    fn NRGBA64::rgba64_at(self : NRGBA64, x : Int, y : Int) ->
    RGBA64

    NRGBA64::set

    fn NRGBA64::set(self : NRGBA64, x : Int, y : Int, c : &
    Color
    ) -> Unit

    NRGBA64::set_nrgba64

    fn NRGBA64::set_nrgba64(self : NRGBA64, x : Int, y : Int, c :
    NRGBA64
    ) -> Unit

    NRGBA64::set_point

    #alias("_[_]=_")
    fn NRGBA64::set_point(self : NRGBA64, p : Point, c : &
    Color
    ) -> Unit

    NRGBA64::set_rgba64

    fn NRGBA64::set_rgba64(self : NRGBA64, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    NRGBA64::sub_image

    fn NRGBA64::sub_image(self : NRGBA64, r : Rectangle) -> &Image

    Paletted

    pub(all) struct Paletted {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    palette :
    Palette

    }

    Paletted is an in-memory image of Byte indices into a given palette.
    impl Image for Paletted

    Paletted::as_ycbcr

    fn Paletted::as_ycbcr(_self : Paletted) -> YCbCr?

    Paletted::at

    fn Paletted::at(self : Paletted, x : Int, y : Int) -> &
    Color

    Paletted::bounds

    fn Paletted::bounds(self : Paletted) -> Rectangle

    Paletted::color_index_at

    fn Paletted::color_index_at(self : Paletted, x : Int, y : Int) -> Byte

    Paletted::color_model

    Paletted::get

    #alias("_[_]")
    fn Paletted::get(self : Paletted, p : Point) -> &
    Color

    Paletted::get_bytes_per_pixel

    fn Paletted::get_bytes_per_pixel(_self : Paletted) -> Int

    Paletted::get_stride

    fn Paletted::get_stride(self : Paletted) -> Int

    Paletted::new

    Paletted::new returns a new [Paletted] image with the given width, height and palette.

    Paletted::new_empty

    fn Paletted::new_empty() -> Paletted

    Paletted::opaque_

    fn Paletted::opaque_(self : Paletted) -> Bool

    Paletted::pix_offset

    fn Paletted::pix_offset(self : Paletted, x : Int, y : Int) -> Int

    Paletted::raw_data

    fn Paletted::raw_data(self : Paletted) ->
    Slice
    [Byte]

    Paletted::rgba64_at

    fn Paletted::rgba64_at(self : Paletted, x : Int, y : Int) ->
    RGBA64

    Paletted::set

    fn Paletted::set(self : Paletted, x : Int, y : Int, c : &
    Color
    ) -> Unit

    Paletted::set_color_index

    fn Paletted::set_color_index(self : Paletted, x : Int, y : Int, index : Byte) -> Unit

    Paletted::set_point

    #alias("_[_]=_")
    fn Paletted::set_point(self : Paletted, p : Point, c : &
    Color
    ) -> Unit

    Paletted::set_rgba64

    fn Paletted::set_rgba64(self : Paletted, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    Paletted::sub_image

    fn Paletted::sub_image(self : Paletted, r : Rectangle) -> &Image

    Point

    pub(all) struct Point {
    x : Int
    y : Int
    } derive(Eq)

    A Point is an X, Y coordinate pair. The axes increase right and down.
    impl Add for Point
    impl Show for Point
    impl Sub for Point

    Point::add

    fn Point::add(self : Point, q : Point) -> Point

    Point::div

    fn Point::div(self : Point, k : Int) -> Point

    div returns the vector p/k.

    Point::equal

    fn Point::equal(Point, Point) -> Bool

    Point::is_in

    fn Point::is_in(self : Point, r : Rectangle) -> Bool

    is_in reports whether p is in r.

    Point::mod

    fn Point::mod(self : Point, r : Rectangle) -> Point

    mod returns the point q in r such that p.X-q.X is a multiple of r's width and p.Y-q.Y is a multiple of r's height.

    Point::mul

    fn Point::mul(self : Point, k : Int) -> Point

    mul returns the vector p*k.

    Point::sub

    fn Point::sub(self : Point, q : Point) -> Point

    Point::to_string

    fn Point::to_string(self : Point) -> String

    to_string returns a string representation of p like "(3,4)".

    RGBA

    pub(all) struct RGBA {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    RGBA is an in-memory image whose At method returns [color.RGBA] values.
    impl Image for RGBA

    RGBA::as_ycbcr

    fn RGBA::as_ycbcr(_self : RGBA) -> YCbCr?

    RGBA::at

    fn RGBA::at(self : RGBA, x : Int, y : Int) -> &
    Color

    RGBA::bounds

    fn RGBA::bounds(self : RGBA) -> Rectangle

    RGBA::color_index_at

    fn RGBA::color_index_at(_self : RGBA, _x : Int, _y : Int) -> Byte

    RGBA::color_model

    fn RGBA::color_model(_self : RGBA) -> &
    Model

    RGBA::get

    #alias("_[_]")
    fn RGBA::get(self : RGBA, p : Point) -> &
    Color

    RGBA::get_bytes_per_pixel

    fn RGBA::get_bytes_per_pixel(_self : RGBA) -> Int

    RGBA::get_stride

    fn RGBA::get_stride(self : RGBA) -> Int

    RGBA::new

    fn RGBA::new(r : Rectangle) -> RGBA raise SizeError

    RGBA::new returns a new [RGBA] image with the given bounds.

    RGBA::new_empty

    fn RGBA::new_empty() -> RGBA

    RGBA::opaque_

    fn RGBA::opaque_(self : RGBA) -> Bool

    RGBA::pix_offset

    fn RGBA::pix_offset(self : RGBA, x : Int, y : Int) -> Int

    RGBA::raw_data

    fn RGBA::raw_data(self : RGBA) ->
    Slice
    [Byte]

    RGBA::rgba64_at

    fn RGBA::rgba64_at(self : RGBA, x : Int, y : Int) ->
    RGBA64

    RGBA::rgba_at

    fn RGBA::rgba_at(self : RGBA, x : Int, y : Int) ->
    RGBA

    RGBA::set

    fn RGBA::set(self : RGBA, x : Int, y : Int, c : &
    Color
    ) -> Unit

    RGBA::set_point

    #alias("_[_]=_")
    fn RGBA::set_point(self : RGBA, p : Point, c : &
    Color
    ) -> Unit

    RGBA::set_rgba

    fn RGBA::set_rgba(self : RGBA, x : Int, y : Int, c :
    RGBA
    ) -> Unit

    RGBA::set_rgba64

    fn RGBA::set_rgba64(self : RGBA, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    RGBA::sub_image

    fn RGBA::sub_image(self : RGBA, r : Rectangle) -> &Image

    RGBA64

    pub(all) struct RGBA64 {
    pix :
    Slice
    [Byte]
    stride : Int
    rect : Rectangle
    }

    RGBA64 is an in-memory image whose At method returns [color.RGBA64] values.
    impl Image for RGBA64

    RGBA64::as_ycbcr

    fn RGBA64::as_ycbcr(_self : RGBA64) -> YCbCr?

    RGBA64::at

    fn RGBA64::at(self : RGBA64, x : Int, y : Int) -> &
    Color

    RGBA64::bounds

    fn RGBA64::bounds(self : RGBA64) -> Rectangle

    RGBA64::color_index_at

    fn RGBA64::color_index_at(_self : RGBA64, _x : Int, _y : Int) -> Byte

    RGBA64::color_model

    fn RGBA64::color_model(_self : RGBA64) -> &
    Model

    RGBA64::get

    #alias("_[_]")
    fn RGBA64::get(self : RGBA64, p : Point) -> &
    Color

    RGBA64::get_bytes_per_pixel

    fn RGBA64::get_bytes_per_pixel(_self : RGBA64) -> Int

    RGBA64::get_stride

    fn RGBA64::get_stride(self : RGBA64) -> Int

    RGBA64::new

    fn RGBA64::new(r : Rectangle) -> RGBA64 raise SizeError

    RGBA64::new returns a new [RGBA64] image with the given bounds.

    RGBA64::new_empty

    fn RGBA64::new_empty() -> RGBA64

    RGBA64::opaque_

    fn RGBA64::opaque_(self : RGBA64) -> Bool

    RGBA64::pix_offset

    fn RGBA64::pix_offset(self : RGBA64, x : Int, y : Int) -> Int

    RGBA64::raw_data

    fn RGBA64::raw_data(self : RGBA64) ->
    Slice
    [Byte]

    RGBA64::rgba64_at

    fn RGBA64::rgba64_at(self : RGBA64, x : Int, y : Int) ->
    RGBA64

    RGBA64::set

    fn RGBA64::set(self : RGBA64, x : Int, y : Int, c : &
    Color
    ) -> Unit

    RGBA64::set_point

    #alias("_[_]=_")
    fn RGBA64::set_point(self : RGBA64, p : Point, c : &
    Color
    ) -> Unit

    RGBA64::set_rgba64

    fn RGBA64::set_rgba64(self : RGBA64, x : Int, y : Int, c :
    RGBA64
    ) -> Unit

    RGBA64::sub_image

    fn RGBA64::sub_image(self : RGBA64, r : Rectangle) -> &Image

    Rectangle

    pub(all) struct Rectangle {
    min : Point
    max : Point
    }

    A Rectangle contains the points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y. It is well-formed if Min.X <= Max.X and likewise for Y. Points are always well-formed. A rectangle's methods always return well-formed outputs for well-formed inputs.

    A Rectangle is also an [Image] whose bounds are the rectangle itself. At returns color.Opaque for points in the rectangle and color.Transparent otherwise.
    impl Image for Rectangle
    impl Eq for Rectangle
    impl Show for Rectangle

    Rectangle::add

    fn Rectangle::add(self : Rectangle, p : Point) -> Rectangle

    add returns the rectangle r translated by p.

    Rectangle::as_ycbcr

    fn Rectangle::as_ycbcr(_self : Rectangle) -> YCbCr?

    Rectangle::at

    fn Rectangle::at(self : Rectangle, x : Int, y : Int) -> &
    Color

    Rectangle::bounds

    fn Rectangle::bounds(self : Rectangle) -> Rectangle

    Rectangle::canon

    fn Rectangle::canon(self : Rectangle) -> Rectangle

    canon returns the canonical version of r. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.

    Rectangle::color_index_at

    fn Rectangle::color_index_at(_self : Rectangle, _x : Int, _y : Int) -> Byte

    Rectangle::color_model

    Rectangle::copy

    fn Rectangle::copy(self : Rectangle) -> Rectangle

    copy makes a copy of the provided rectangle without changing it.

    Rectangle::dx

    fn Rectangle::dx(self : Rectangle) -> Int

    dx returns r's width.

    Rectangle::dy

    fn Rectangle::dy(self : Rectangle) -> Int

    dy returns r's height.

    Rectangle::empty

    fn Rectangle::empty(self : Rectangle) -> Bool

    empty reports whether the rectangle contains no points.

    Rectangle::equal

    fn Rectangle::equal(self : Rectangle, s : Rectangle) -> Bool

    Rectangle::get_bytes_per_pixel

    fn Rectangle::get_bytes_per_pixel(_self : Rectangle) -> Int

    Rectangle::get_stride

    fn Rectangle::get_stride(_self : Rectangle) -> Int

    Rectangle::inset

    fn Rectangle::inset(self : Rectangle, n : Int) -> Rectangle

    inset returns the rectangle r inset by n, which may be negative. If either of r's dimensions is less than 2*n then an empty rectangle near the center of r will be returned.

    Rectangle::intersect

    fn Rectangle::intersect(self : Rectangle, s : Rectangle) -> Rectangle

    intersect returns the largest rectangle contained by both r and s. If the two rectangles do not overlap then the zero rectangle will be returned.

    Rectangle::is_in

    fn Rectangle::is_in(self : Rectangle, s : Rectangle) -> Bool

    is_in reports whether every point in r is in s.

    Rectangle::new

    fn Rectangle::new() -> Rectangle

    Rectangle::new returns an empty (all zeros) rectangle.

    Rectangle::opaque_

    fn Rectangle::opaque_(_self : Rectangle) -> Bool

    Rectangle::overlaps

    fn Rectangle::overlaps(self : Rectangle, s : Rectangle) -> Bool

    overlaps reports whether r and s have a non-empty intersection.

    Rectangle::pix_offset

    fn Rectangle::pix_offset(_self : Rectangle, _x : Int, _y : Int) -> Int

    Rectangle::raw_data

    fn Rectangle::raw_data(_self : Rectangle) ->
    Slice
    [Byte]

    Rectangle::rgba64_at

    fn Rectangle::rgba64_at(self : Rectangle, x : Int, y : Int) ->
    RGBA64

    rgba64_at implements the [RGBA64Image] trait.

    Rectangle::set

    fn Rectangle::set(_self : Rectangle, _x : Int, _y : Int, _c : &
    Color
    ) -> Unit

    Rectangle::size

    fn Rectangle::size(self : Rectangle) -> Point

    size returns r's width and height.

    Rectangle::sub

    fn Rectangle::sub(self : Rectangle, p : Point) -> Rectangle

    sub returns the rectangle r translated by -p.

    Rectangle::sub_image

    fn Rectangle::sub_image(self : Rectangle, _o : Rectangle) -> &Image

    Rectangle::to_string

    fn Rectangle::to_string(self : Rectangle) -> String

    to_string returns a string representation of r like "(3,4)-(6,5)".

    Rectangle::union

    fn Rectangle::union(self : Rectangle, s : Rectangle) -> Rectangle

    union returns the smallest rectangle that contains both r and s.

    YCbCr

    pub(all) struct YCbCr {
    y :
    Slice
    [Byte]
    cb :
    Slice
    [Byte]
    cr :
    Slice
    [Byte]
    y_stride : Int
    c_stride : Int
    subsampling : YCbCrSubsampling
    rect : Rectangle
    }

    YCbCr is an in-memory image of Y'CbCr colors.
    impl Image for YCbCr

    YCbCr::as_ycbcr

    fn YCbCr::as_ycbcr(self : YCbCr) -> YCbCr?

    YCbCr::at

    fn YCbCr::at(self : YCbCr, x : Int, y : Int) -> &
    Color

    YCbCr::bounds

    fn YCbCr::bounds(self : YCbCr) -> Rectangle

    YCbCr::color_index_at

    fn YCbCr::color_index_at(_self : YCbCr, _x : Int, _y : Int) -> Byte

    YCbCr::color_model

    fn YCbCr::color_model(_self : YCbCr) -> &
    Model

    YCbCr::get_bytes_per_pixel

    fn YCbCr::get_bytes_per_pixel(_self : YCbCr) -> Int

    YCbCr::get_stride

    fn YCbCr::get_stride(self : YCbCr) -> Int

    YCbCr::new

    fn YCbCr::new(r : Rectangle, subsampling : YCbCrSubsampling) -> YCbCr raise SizeError

    YCbCr::opaque_

    fn YCbCr::opaque_(_self : YCbCr) -> Bool

    YCbCr::pix_offset

    fn YCbCr::pix_offset(self : YCbCr, x : Int, y : Int) -> Int

    YCbCr::raw_data

    fn YCbCr::raw_data(self : YCbCr) ->
    Slice
    [Byte]

    YCbCr::set

    fn YCbCr::set(self : YCbCr, x : Int, y : Int, c : &
    Color
    ) -> Unit

    YCbCr::sub_image

    fn YCbCr::sub_image(self : YCbCr, r : Rectangle) -> &Image

    YCbCrSubsampling

    pub(all) enum YCbCrSubsampling {
    YCbCrSubsampling444
    YCbCrSubsampling422
    YCbCrSubsampling420
    YCbCrSubsampling440
    YCbCrSubsampling411
    YCbCrSubsampling410
    } derive(Eq)

    YCbCrSubsampling represents the chroma subsampling ratio.

    YCbCrSubsampling::equal

    add2_non_neg

    fn add2_non_neg(x : Int, y : Int) -> Int

    add2_non_neg returns (x + y), unless at least one argument is negative or if the computation overflows the int type, in which case it returns -1.

    mul3_non_neg

    fn mul3_non_neg(x : Int, y : Int, z : Int) -> Int

    mul3_non_neg returns (x * y * z), unless at least one argument is negative or if the computation overflows the int type, in which case it returns -1.
    fn pt(x : Int, y : Int) -> Point

    pt is shorthand for [Point]{X, Y}.

    rect

    fn rect(x0 : Int, y0 : Int, x1 : Int, y1 : Int) -> Rectangle

    rect is shorthand for [Rectangle]{Pt(x0, y0), [Pt](x1, y1)}. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.