diff options
Diffstat (limited to 'pnm/pbm.scm')
-rw-r--r-- | pnm/pbm.scm | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/pnm/pbm.scm b/pnm/pbm.scm index 32506e0..7e7bc78 100644 --- a/pnm/pbm.scm +++ b/pnm/pbm.scm @@ -37,7 +37,8 @@ (data (make-bytevector byte-count 0))) (make-pbm-image width height data))) ((width height data) - (let* ((byte-width (ceiling (/ width 8)))) + (let* ((byte-width (ceiling (/ width 8))) + (byte-count (* byte-width height))) (define (xy->byte-idx+bit-idx x y) (let-values (((byte-x bit-x) (floor/ x 8))) (values (+ (* y byte-width) @@ -52,4 +53,6 @@ (let ((byte (bytevector-u8-ref data byte-idx))) (bytevector-u8-set! data byte-idx (copy-bit (- 7 bit-idx) byte b))))) + (unless (= byte-count (bytevector-length data)) + (error (string-append "(pnm pbm) make-pbm-image: Invalid bytevector length" byte-count))) (make-image 'pbm width height 1 data pixel-getter pixel-setter))))))) |