aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasaya Tojo <masaya@tojo.tokyo>2024-08-04 22:48:14 +0900
committerMasaya Tojo <masaya@tojo.tokyo>2024-08-04 22:53:19 +0900
commit8ea85b76e5858c2d205301fd02591c2a47cc088d (patch)
tree142187894b859fefb2d976d3fb2634a101fd06c2
parentd71502c7022875b13543d22530c02f0d9a862e30 (diff)
Make `maxval` argument optional
-rw-r--r--pnm/pgm.scm24
-rw-r--r--pnm/ppm.scm26
2 files changed, 29 insertions, 21 deletions
diff --git a/pnm/pgm.scm b/pnm/pgm.scm
index 89f4c35..200720f 100644
--- a/pnm/pgm.scm
+++ b/pnm/pgm.scm
@@ -23,16 +23,20 @@
(scheme case-lambda)
(pnm image))
(begin
- (define (make-pgm-image width height maxval)
- (when (or (< maxval 0)
- (< 65536 maxval))
- (error "(pnm pgm) make-pgm: maxval is out of range"))
- (let* ((byte-count (* width height
- (if (< maxval 256)
- 1
- 2)))
- (data (make-bytevector byte-count 0)))
- (%make-pgm-image width height maxval data)))
+ (define make-pgm-image
+ (case-lambda
+ ((width height)
+ (make-pgm-image width height 255))
+ ((width height maxval)
+ (when (or (< maxval 0)
+ (< 65536 maxval))
+ (error "(pnm pgm) make-pgm: maxval is out of range"))
+ (let* ((byte-count (* width height
+ (if (< maxval 256)
+ 1
+ 2)))
+ (data (make-bytevector byte-count 0)))
+ (%make-pgm-image width height maxval data)))))
(define (%make-pgm-image width height maxval data)
(when (or (< maxval 0)
diff --git a/pnm/ppm.scm b/pnm/ppm.scm
index 496eee1..11331af 100644
--- a/pnm/ppm.scm
+++ b/pnm/ppm.scm
@@ -23,17 +23,21 @@
(scheme case-lambda)
(pnm image))
(begin
- (define (make-ppm-image width height maxval)
- (when (or (< maxval 0)
- (< 65536 maxval))
- (error "(pnm ppm) make-ppm-image: Maxval is out of range"))
- (let ((data (make-bytevector (* width
- height
- (if (< maxval 256)
- 3
- 6))
- 0)))
- (%make-ppm-image width height maxval data)))
+ (define make-ppm-image
+ (case-lambda
+ ((width height)
+ (make-ppm-image width height 255))
+ ((width height maxval)
+ (when (or (< maxval 0)
+ (< 65536 maxval))
+ (error "(pnm ppm) make-ppm-image: Maxval is out of range"))
+ (let ((data (make-bytevector (* width
+ height
+ (if (< maxval 256)
+ 3
+ 6))
+ 0)))
+ (%make-ppm-image width height maxval data)))))
(define (%make-ppm-image width height maxval data)
(when (or (< maxval 0)