#lang scheme/base #| PBM Portable BitMap B/W PGM Portable GreyMap Grey P5 PPM Portable PixMap RGB P6 PNM Portable aNyMap |# (define (pgm-type->reader type) (case type ((P5) (lambda (w h) (read-bytes (* w h)))) ((P6) (lambda (w h) (read-bytes (/ (* w h) 8)))) (else (error 'not-a-pgm-file "~s" type)))) (define (read-pgm [p (current-input-port)]) (parameterize ((current-input-port p)) (let* ((header (read)) (read-body (pgm-type->reader header)) (_ (read-line)) ;; newline (_ (read-line)) ;; comment line (width (read)) (height (read)) (levels (read)) (_ (read-line))) ;; newline (printf "pgm: ~a ~a ~a\n" width height levels) ;; The rest is binary data (values width height ;(read-body width height) )))) ; pdftoppm -f 22 -l 22 ~/library/link/AITR-595.pdf >/tmp/page.ppm (define (test) (read-pgm (open-input-file "/tmp/page.ppm")))