pnm/util

    Dark Mode
Search:
Group by:

util is internal utilities for pnm module.

You don't need to use directly this module for pnm module.

Procs

proc toBinSeq(b: uint8): seq[uint8] {...}{.raises: [], tags: [].}
Return binary sequence from each bits of uint8.

Example:

from sequtils import repeat
doAssert 0'u8.toBinSeq == 0'u8.repeat(8)
doAssert 0b1010_1010.toBinSeq == @[1'u8, 0, 1, 0, 1, 0, 1, 0]
proc toBinString(data: openArray[uint8]; col: int): string {...}{.raises: [],
    tags: [].}
Return binary string from each bits of uint8.

Example:

doAssert @[0b0000_1111'u8, 0b1010_1010].toBinString(8) == "0000111110101010"
doAssert @[0b1000_0000'u8, 0b0000_0000].toBinString(1) == "10"
proc toMatrixString(data: openArray[uint8]; col: int): string {...}{.raises: [],
    tags: [].}
Return matrix string from decimal sequence. Matrix string is joined by whitespace. And matrix string add new line when counter of column is reached col.

Example:

doAssert @[0'u8, 1, 8, 9].toMatrixString(2) == "0 1\n8 9"
doAssert @[0'u8, 1, 10, 99].toMatrixString(2) == "0 1\n10 99"
proc toMatrixString(s: string; col: int): string {...}{.raises: [], tags: [].}
Return matrix string from decimal sequence. Matrix string is joined by whitespace. And matrix string add new line when counter of column is reached col.

Example:

doAssert "1111111100000000".toMatrixString(8) == "1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0"
proc toBin(arr: openArray[uint8]; col: int = 8): seq[uint8] {...}{.raises: [],
    tags: [].}
Returns sequences that binary sequence is converted to uint8 every 8 bits.

Example:

doAssert @[1'u8, 1, 1, 1, 0, 0, 0, 0].toBin == @[0b1111_0000'u8]
doAssert @[1'u8, 1, 1, 1, 1, 1].toBin == @[0b1111_1100'u8]
var s: seq[uint8]
doAssert s.toBin == s
proc removeCommentLine(s: openArray[uint8]): seq[uint8] {...}{.raises: [], tags: [].}
Return sequence that removed comment line. Range of comment is from '#' to first 'n'.

Example:

doAssert @['a'.uint8, '#'.uint8, ' '.uint8, '\n'.uint8, 'b'.uint8].removeCommentLine == @['a'.uint8, 'b'.uint8]
doAssert @['a'.uint8, '#'.uint8, ' '.uint8, '\n'.uint8].removeCommentLine == @['a'.uint8]
var s: seq[uint8]
doAssert @['#'.uint8, ' '.uint8, '\n'.uint8].removeCommentLine == s
proc replaceWhiteSpace(s: string): string {...}{.raises: [], tags: [].}
Replace continued whitespace to simgle whitespace.