aboutsummaryrefslogtreecommitdiff

R7RS-PNM

R7RS-PNM is a R7RS library for handling PNM (Portable Any Map) files, providing functionality for reading and writing PNM files,as well as accessing and modifying pixel data.

Usage

Import (image-format pnm) library

(import (image-format pnm))

Image

(pnm-image? x) → boolean

Returns #t if x is a valid pnm-image object; otherwise, it returns #f.

(pnm-image-type pnm-image) → 'pbm | 'pgm | 'ppm

Returns the type of the given pnm-image.

  • pbm: Portable Bit Map
  • pgm: Portable Gray Map
  • ppm: Portable Pixel Map

(pnm-image-width pnm-image) → integer

Returns the width of pnm-image.

(pnm-image-height pnm-image) → integer

Returns the height of pnm-image.

PBM (Portable Bit Map)

(make-pbm-image width height) → <pnm-image>

Returns a new Portable Bit Map (PBM) image with the specified width and height.

(pnm-image-maxval pbm-image) → #t

Returns the maximum value for pixel intensity in a PBM image, which is

always #t for PBM images, indicating binary values (black and white).

(pnm-image-ref pbm-image x y) → boolean

Returns the value of the pixel at coordinates (x, y) in the specified image. The return value is #t for a white pixel and #f for a black pixel.

(pnm-image-set! pbm-image x y b)

Sets the pixel at coordinates (x, y) in the specified pnm-image to the boolean value b. If b is #t, the pixel is set to white; if #f, it is set to black.

PGM (Portable PGM Map)

(make-pgm-image width height [maxval]) → <pnm-image>

Creates a new Portable Gray Map (PGM) image with the specified width and height. The optional maxval parameter defines the maximum pixel intensity, defaulting to 255 if not provided.

(pnm-image-maxval pgm-image) → integer

Returns the maximum pixel intensity value for the specified PGM image.

(pnm-image-ref pgm-image x y) → integer

Returns the gray value of the pixel at coordinates (x, y) in the specified PGM image. The value is an integer between 0 and maxval.

(pnm-image-set! pgm-image x y v)

Sets the pixel at coordinates (x, y) in the specified PGM image to the given integer value v, which must be between 0 and maxval.

PPM (Portable PPM Map)

(make-ppm-image width height [maxval]) → <pnm-image>

Creates a new Portable Pixel Map (PPM) image with the specified width and height. The optional maxval parameter defines the maximum color intensity, defaulting to 255 if not provided.

(pnm-image-maxval ppm-image) → integer

Returns the maximum color intensity value for the specified PPM image.

(pnm-image-ref ppm-image x y) → (values integer integer integer)

Returns the RGB values of the pixel at coordinates (x, y) in the specified PPM image as three integers, representing the red, green, and blue components, respectively.

(pnm-image-set! ppm-image x y r g b)

Sets the pixel at coordinates (x, y) in the specified PPM image to the given RGB values r, g, and b, which must be integers between 0 and maxval.

Reading

(pnm-image-read port) → <pnm-image>

Reads a PNM image from the specified input port and returns the corresponding image object (PBM, PGM, or PPM).

(pnm-parse-error? exn) → boolean

Returns #t if the exception exn is a parse error that occurred during the execution of the pnm-image-read procedure; otherwise, it returns #f.

Writing

(pnm-image-write pnm-image port)

Writes the specified pnm-image (PBM, PGM, or PPM) to the given output port.

Downloading Code with Git

git clone https://git.tojo.tokyo/r7rs-pnm.git

License

This library is released under the LGPLv3+ License. See the COPYING and COPYING.LESSER files for more details.

Copyright (c) 2024 Masaya Tojo masaya@tojo.tokyo