Module nimage

Types

NColor* = distinct uint32

A color in RGBA format, 8 bits per sample. For example, 50% red, 100% green, 0% blue, 100% alpha would be NColor(0x80FF00FF).

ImageObj* = object of RootObj
    width*: int
    height*: int
    data*: seq[NColor] # Data is stored in row-major format
Image* = ref ImageObj
ColorType* = enum
  gray = 0
  rgb = 2
  palette = 3
  graya = 4
  rgba = 6
PngEncoderOpts* = object
        colorType: ColorType

Procs

proc `[]`*(img: Image; row, col: int): NColor
proc `[]=`*(img: Image; row, col: int; val: NColor)
proc create_image*(width, height: int): Image
proc `$`*(color: NColor): string
proc `==`*(c1, c2: NColor): bool
proc default_opts*(): PngEncoderOpts
proc new_opts*(colorType: ColorType): PngEncoderOpts

Create an encoder options struct for a given color type. Note that for grayscale color types, the value in the red channel is taken as the gray value; green and blue channels are ignored, and the alpha channel is ignored for gray (but not graya).

proc save_png*(img: Image, buf: Stream, opts: PngEncoderOpts)
proc save_png*(img: Image, buf: Stream)
proc load_png*(buf: Stream): Image