Anonymous user
Bitmap/Read a PPM file: Difference between revisions
→{{header|Common Lisp}}
Line 286:
(defun read-ppm-image (file)
(flet ((image-data-reader (stream start-position width height image-build-function read-function)
(file-position stream start-position)
Line 298 ⟶ 297:
(max-value (parse-integer (fourth header) :junk-allowed t))
(image (make-rgb-pixel-buffer width height)))
(cond ((string= "P6" image-type)
▲ (if (> max-value 255)
▲ (error "unsupported depth - convert to 1byte depth with pamdepth")
file-pos
▲ (with-open-file (stream file :direction :input :element-type '(unsigned-byte 8))
▲ (image-data-reader stream
#'(lambda (w h val)
▲ width
(setf (rgb-pixel image w h) val))
▲ image)))
((string= "P3" image-type)
(
file-pos
▲ (image-data-reader stream
#'(lambda (w h val)
▲ width
(setf (rgb-pixel image w h) val))
▲ image)))
(t 'unsupported))
(export 'read-ppm-image)
|