Bitmap/Read a PPM file: Difference between revisions
Content added Content deleted
Line 286: | Line 286: | ||
(defun read-ppm-image (file) |
(defun read-ppm-image (file) |
||
"reads an image from a ppm file and constructs the rgb-pixel-buffer" |
|||
(flet ((image-data-reader (stream start-position width height image-build-function read-function) |
(flet ((image-data-reader (stream start-position width height image-build-function read-function) |
||
(file-position stream start-position) |
(file-position stream start-position) |
||
Line 298: | Line 297: | ||
(max-value (parse-integer (fourth header) :junk-allowed t)) |
(max-value (parse-integer (fourth header) :junk-allowed t)) |
||
(image (make-rgb-pixel-buffer width height))) |
(image (make-rgb-pixel-buffer width height))) |
||
⚫ | |||
⚫ | |||
(cond ((string= "P6" image-type) |
(cond ((string= "P6" image-type) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
file-pos |
|||
⚫ | |||
⚫ | |||
⚫ | |||
height |
|||
#'(lambda (w h val) |
|||
⚫ | |||
(setf (rgb-pixel image w h) val)) |
|||
height |
|||
#'(lambda (stream) |
|||
(make-rgb-pixel (read-byte stream) |
|||
(read-byte stream) |
|||
(read-byte stream)))) |
|||
⚫ | |||
(read-byte stream) |
|||
(read-byte stream)))) |
|||
⚫ | |||
((string= "P3" image-type) |
((string= "P3" image-type) |
||
( |
(with-open-file (stream file :direction :input) |
||
⚫ | |||
(error "unsupported depth - convert to 1byte depth with pamdepth") |
|||
file-pos |
|||
(with-open-file (stream file :direction :input) |
|||
⚫ | |||
⚫ | |||
height |
|||
#'(lambda (w h val) |
|||
⚫ | |||
(setf (rgb-pixel image w h) val)) |
|||
height |
|||
#'(lambda (stream) |
|||
(make-rgb-pixel (read stream) |
|||
(read stream) |
|||
(read stream)))) |
|||
⚫ | |||
(read stream) |
|||
(read stream)))) |
|||
⚫ | |||
(t 'unsupported)) |
(t 'unsupported)) |
||
image)))) |
|||
(export 'read-ppm-image) |
(export 'read-ppm-image) |