aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 4638a7fef4c384fd33e264cc0e7fd7ae9a1be998 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# 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) → <image>`

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-pixel-read 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-pixel-write! 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]) → <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.

#### `(image-maxval pgm-image) → integer`

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

#### `(image-pixel-read 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`.

#### `(image-pixel-write! 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]) → <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.

#### `(image-maxval ppm-image) → integer`

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

#### `(image-pixel-read 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-pixel-write! 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) → <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 `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`.

### Downloading Code with Git

```bash
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

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