Git Product home page Git Product logo

pnm's Introduction

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(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)

3.3. Other examples

See examples directory. Run example code.

Generating PBM.

cd write_pbm
nim c -d:release main.nim
./main

PBM example

Generating PGM.

cd write_pgm
nim c -d:release main.nim
./main

PGM example

Generating PPM.

cd write_ppm
nim c -d:release main.nim
./main

PPM example1 PPM example2

Controling generated PNM files.

cd read_file
nim c -d:release main.nim
./main

Converted PPM example1

4. Warning

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

pnm's People

Contributors

jiro4989 avatar metasyn avatar momeemt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

momeemt

pnm's Issues

documentの生成に失敗してる

newPBMのrunnableExampleで最大輝度の255を渡すように修正された結果ドキュメント生成が失敗してるっぽい。

PBMは0,1の2値しか受け取らないので上限が指定できないけれど、PGM, PNMで上限を指定できるようになったときに、同様の修正をPBMのrunnableExamplesに当てた結果ドキュメント生成がコケるようになった。

runnableExampleのテストも必要だな

バイナリ形式のPPM画像が読み込めない

概要

readPPMプロシージャを用いてバイナリ形式(P6)のPPM画像を読み込むと、次のようなエラーが発生する。

/Volumes/momeeSSD/Developer/pien/src/pien.nim(32) pien
/Volumes/momeeSSD/Developer/pien/src/pien.nim(26) rsv
/Users/momiyama/.nimble/pkgs/pnm-2.1.1/pnm.nim(853) readPPMFile
/Users/momiyama/.nimble/pkgs/pnm-2.1.1/pnm.nim(810) readPPM
/Users/momiyama/.nimble/pkgs/pnm-2.1.1/pnm.nim(603) parsePPM
/Users/momiyama/.choosenim/toolchains/nim-1.4.0/lib/pure/strutils.nim(1129) parseInt
Error: unhandled exception: invalid integer: # [ValueError]

原因

バイナリを正しく読み取ることができていないのではないかと思います。
調べたところ、wavファイルのバイナリを読み取りたいという質問に対して、streamを用いると良いと回答されていました。現在、これを使って正しく読み取ることができないか確かめています。

私はNimでファイルを扱うことに慣れていないので、もし何か思い当たる解決策がありましたら教えていただけると助かります。

読み取ろうとした画像(一部)

P6
# Created by IrfanView
1024 768
255
59R6:S04M15N8:S>@Y8:S46O46O,.G02K8:SBB\88R??W9;R;@VCI_PRiHJa6;O6;O;@V=BV7<P8=P:@P:@P;=L79H76H87I@?Q@?Q=8N:7L1.C97L31G:8NIJ_ABWA=T<:P<:RAAY@>VGE]GE]:8P<<V::T8:Q>@W=BX>CY?AX46M79P8:Q79NCEZ@EY?DX:?R49L<AW38N48Q:>W>D\7=U7=S7?T8@W*5K-8N8CY:@Z39S59R15N13LCE^JLeDF_CG`@E[;@V5:N55M<<TPNfJH`CC[??W:8P64LB@XEC[CC[@@X<<VAA[<<TBBZLIdHE`;;UGGaMJiEEa44P/1J=?X79R9;R>@W>>X44N$"::8P<8O73J51H=9P95L<8OF@ZJD^D@YA=VGE[KI_IG_LJbMNc>?TFD\IIaKLaBDY:<Q?AVABW=>S?@UIJ_DF[=?TDF[GI^DI]MRfUWlQShKNa?BU<=Q78L?=UKIaKIaLJbDBZNLdTRhPNdSSmPPj@BY13J9;

(長すぎるので省略)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.