pnm

pnm is library for PNM (Portable AnyMap).


Keywords
pnm, image, library, lib, nim
License
MIT
Install
nimble install pnm

Documentation

pnm

PNM (Portable Anymap) parser/generator library in pure Nim.

Build Status

1. Development

nim -v

Nim Compiler Version 0.19.4 [Linux: amd64]
Compiled at 2019-02-01
Copyright (c) 2006-2018 by Andreas Rumpf
git hash: b6d96cafc8bcad1f3d32f2910b25cd11a93f7751
active boot switches: -d:release

nimble -v

nimble v0.9.0 compiled at 2018-10-27 18:10:03
git hash: couldn't determine git hash

2. Install

nimble install pnm

3. Usage

3.1. Reading PGM file

import pnm

block:
  # P2
  let p = readPGMFile("tests/out/p2.pgm")
  echo p

block:
  # P5
  let p = readPGMFile("tests/out/p5.pgm")
  echo p

3.2. Writing PGM file

import pnm

let col = 6
let row = 12
let data = @[
  0'u8, 0, 0, 0, 0, 0,
  0'u8, 0, 0, 0, 0, 0,
  0'u8, 0, 0, 0, 0, 0,
  0'u8, 0, 0, 0, 0, 0,
  1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1,
  1, 1, 1, 1, 1, 1,
  2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2,
  2, 2, 2, 2, 2, 2,
]

block:
  # P2
  let p = newPGM(pgmFileDiscriptorP2, col, row, data)
  writePGMFile("tests/out/p2.pgm", p)

block:
  # P5
  let p = newPGM(pgmFileDiscriptorP5, col, row, data)
  writePGMFile("tests/out/p5.pgm", p)

3.3. Other examples

See examples directory. Run example code.

Generating PBM.

nim c -d:release examples/pbm_example.nim
./examples/pbm_example

PBM example

Generating PGM.

nim c -d:release examples/pgm_example.nim
./examples/pgm_example

PGM example

Generating PPM.

nim c -d:release examples/ppm_example.nim
./examples/ppm_example

PPM example1 PPM example2

Controling generated PNM files.

nim c -d:release examples/convert.nim
./examples/convert

Converted PPM example1

4. Warning

Available color byte of PGM and PPM is 1 byte (0~255).