# 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 `(pnm)` library ```scheme (import (pnm)) ``` ### Image #### `(image? x) → boolean` Returns `#t` if `x` is a valid image object; otherwise, it returns `#f`. #### `(image-type image) → 'pbm | 'pgm | 'ppm` Returns the type of the given image. - `pbm`: Portable Bit Map - `pgm`: Portable Gray Map - `ppm`: Portable Pixel Map #### `(image-width image) → integer` Returns the width of `image`. #### `(image-height image) → integer` Returns the height of `image`. ### PBM (Portable Bit Map) #### `(make-pbm-image width height) → ` Returns a new Portable Bit Map (PBM) image with the specified width and height. #### `(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). #### `(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. #### `(image-set! pbm-image x y b)` Sets the pixel at coordinates `(x, y)` in the specified `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]) → ` 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. #### `(image-maxval pgm-image) → integer` Returns the maximum pixel intensity value for the specified PGM image. #### `(image-ref 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`. #### `(image-set! 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]) → ` 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. #### `(image-maxval pgm-image) → integer` Returns the maximum color intensity value for the specified PPM image. #### `(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. ### `(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 #### `(image-read port) → ` 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 `image-read` procedure; otherwise, it returns `#f`. ### Writing ### `(image-write image port)` Writes the specified `image` (PBM, PGM, or PPM) to the given output `port`. ## License This library is released under the LGPLv3+ License. See the COPYING and COPYING.LESSER files for more details. ## Copyright Copyright (c) 2024 Masaya Tojo