github.com/nevalang/neva@v0.23.1-0.20240507185603-7696a9bb8dda/std/image/image.neva (about)

     1  // RGBA represents a color in the RGBA 64-bit color space.
     2  pub type RGBA struct {
     3    r int
     4    g int
     5    b int
     6    a int
     7  }
     8  
     9  // Pixel represents an RGBA color at a given Point.
    10  pub type Pixel struct {
    11    x int
    12    y int
    13    color RGBA
    14  }
    15  
    16  // Image is an RGBA represented as a string of pixels with one byte per color component.
    17  //
    18  // Pixels are arranged in order such that (x, y) starts at pixels[y*width + x*4].
    19  pub type Image struct {
    20    pixels string
    21    width int
    22    height int
    23  }
    24  
    25  // New creates a new RGBA image from the given pixels.
    26  #extern(image_new)
    27  pub component New(pixels stream<Pixel>) (img Image, err error)
    28  
    29  // Encode a PNG image or return an error.
    30  #extern(image_encode)
    31  pub component Encode(img Image) (data string, err error)