Module npng

Examples

Types

Color = uint32
An RGBA Color is defined as follows: 0x 12 34 56 78
  • 12: red level: 00 => no red , FF => full red
  • 34: greej level: 00 => no green , FF => full green
  • 56: blue level: 00 => no blue , FF => full blue
  • 78: alpha level: 00 => fully transparent , FF => fully opaque
Examples:
  • solid yellow: 0xFFFF00FF
  • solid blue: 0x0000FFFF
  Source Edit
PNG = object
  w*, h*: int
  pixels*: seq[Color]
A png file. To create one, see initPNG   Source Edit

Consts

Transparent = 0x00000000
Common colors used for testing   Source Edit
Black = 0x000000FF
  Source Edit
Blue = 0x0000FFFF
  Source Edit
Green = 0x00FF00FF
  Source Edit
Red = 0x00000000FF0000FF'i64
  Source Edit
Purple = 0x00000000FF00FFFF'i64
  Source Edit
Yellow = 0x00000000FFFF00FF'i64
  Source Edit
White = 0x00000000FFFFFFFF'i64
  Source Edit
HalfTBlack = 0x00000088
HalfT<Color> colors are <color> at half alpha   Source Edit
HalfTBlue = 0x0000FF88
  Source Edit
HalfTGreen = 0x00FF0088
  Source Edit
HalfTRed = 0x00000000FF000088'i64
  Source Edit
HalftWhite = 0x00000000FFFFFF88'i64
  Source Edit

Procs

proc `[]`(png: PNG; i, j: int): Color {.
raises: [], tags: []
.}
  Source Edit
proc `[]=`(png: var PNG; i, j: int; col: Color) {.
raises: [], tags: []
.}
  Source Edit
proc initPNG(w, h: int): PNG {.
raises: [], tags: []
.}
Create a w by h png. Initially it is filled with black, fully transparent pixels.   Source Edit
proc initPNG(w, h: int; pix: seq[Color]): PNG {.
raises: [], tags: []
.}
Create a w by h png, with initial pixels pix   Source Edit
proc fillWith(png: var PNG; color: Color = White) {.
raises: [], tags: []
.}
Fill a png with color   Source Edit
proc appendImg(png: PNG; toID: string = "body") {.
raises: [Exception], tags: [RootEffect]
.}
Inline a png in a html file. If toId is presents, it tries adding it to that element, otherwise adds it to body.   Source Edit
proc writeToFile(png: PNG; file: string) {.
raises: [Exception], tags: [RootEffect, WriteIOEffect]
.}
Write a png to a file. The file is created if not present and overwritten otherwise.   Source Edit