No description
Find a file
jiro4989 556633d87e ⬆️ bump patch
2021-02-01 03:02:54 +09:00
.github fix: broken runnableExamples #9 (#10) 2021-02-01 03:01:48 +09:00
docs 🔥 remove unused html 2021-01-29 02:04:08 +09:00
examples 💚 変数名の変更漏れを修正 (#3) 2019-07-13 09:01:15 +09:00
src fix: broken runnableExamples #9 (#10) 2021-02-01 03:01:48 +09:00
tests 🧪 Add tests for newPGM and newPPM 2021-01-29 17:05:27 +09:00
.gitignore ♻️ モジュール構造を変更して一つに統合した 2019-04-30 16:55:41 +09:00
pnm.nimble ⬆️ bump patch 2021-02-01 03:02:54 +09:00
README.adoc 📝 update CI badge 2021-01-29 02:12:54 +09:00

:toc: left
:sectnums:

= pnm

https://en.wikipedia.org/wiki/Netpbm_format[PNM (Portable Anymap)] parser/generator library in pure Nim.

image:https://github.com/jiro4989/pnm/workflows/test/badge.svg["Build Status", link="https://github.com/jiro4989/pnm/actions"]

== 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

== Install

[source,bash]
nimble install pnm

== Usage

=== Reading PGM file

[source,nim]
----
import pnm

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

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

=== Writing PGM file

[source,nim]
----
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(pgmFileDescriptorP2, col, row, data)
  writePGMFile("tests/out/p2.pgm", p)

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

=== Other examples

See `examples` directory.
Run example code.

Generating PBM.

[source,bash]
cd write_pbm
nim c -d:release main.nim
./main

image:docs/pbm_example.png["PBM example"]

Generating PGM.

[source,bash]
cd write_pgm
nim c -d:release main.nim
./main

image:docs/pgm_example.png["PGM example"]

Generating PPM.

[source,bash]
cd write_ppm
nim c -d:release main.nim
./main

image:docs/ppm_example1.png["PPM example1"]
image:docs/ppm_example2.png["PPM example2"]

Controling generated PNM files.

[source,bash]
cd read_file
nim c -d:release main.nim
./main

image:docs/ppm_example1.convert.png["Converted PPM example1"]

== Warning

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

== Document

* https://jiro4989.github.io/pnm/pnm.html