+(defun sensor-dimensions (sensor-spec &key (format :aps))
+ "Returns the number of pixels for a sensor.
+CAMERA-SPEC is either a keyword designating the camera or
+the number of megapixels of the sensor.
+FORMAT should be defined if the CAMERA-SPEC is the number of megapixels
+so the proper aspect ratio is used."
+ (etypecase sensor-spec
+ (keyword
+ (ecase sensor-spec
+ ;; nikon
+ (:d2x (cons 4288 2848))
+ (:d100 (cons 3037 2024))
+ (:d2h (cons 2464 1632))
+ (:d70 (cons 3008 2000))
+
+ ;; canon
+ (:1d (cons 2464 1648))
+ (:1d2 (cons 3504 2336))
+ (:1ds (cons 4064 2704))
+ (:1ds2 (cons 4992 3328))
+
+ ))
+ (number
+ (sensor-dimensions-megapixels format sensor-spec))))
+
+(defun coc-airy (f-stop)
+ "Return the circle of confusion based on the airy disk."
+ (let ((airy (/ f-stop 1500)))
+ (float (* 2 airy))))
+
+(defun dof-mm (focal-length f-stop distance coc &key (pupil-factor 1))
+ "Returns depth of field based on focal-length, f-stop, distance, and coc.
+Six values are returned:
+near dof, far dof, total dof, near point, far point, magnification,
+blur size at infinity (mm).
+Circle of confusion can either be a number or keyword designating format."
+ (let* ((aperture (/ focal-length f-stop))
+ (numerator-1 (* (- pupil-factor 1) (- distance focal-length)
+ coc focal-length))
+ (numerator-2 (* pupil-factor aperture focal-length distance))
+ (denominator-1 (* pupil-factor coc (- distance focal-length)))
+ (denominator-2 (* pupil-factor aperture focal-length))
+ (near (/ (+ numerator-1 numerator-2)
+ (+ denominator-1 denominator-2)))
+ (far (/ (- numerator-1 numerator-2)
+ (- denominator-1 denominator-2)))
+ (mag (float (/ focal-length (- distance focal-length))))
+ (infinity-blur-diameter (/ (* mag focal-length) f-stop))
+ (depth (- far near)))
+ (values near far depth mag infinity-blur-diameter)))
+
+;; Simplified calculation for symmetric lens
+(defun dof-symmetric-mm (focal-length f-stop distance coc)
+ "Returns depth of field based on focal-length, f-stop, distance, and coc.
+Six values are returned:
+near dof, far dof, total dof, near point, far point, magnification,
+blur size at infinity (mm).
+Circle of confusion can either be a number or keyword designating format.
+Pupil factor is the ratio of the exit to enterance pupil diameters."
+ (let* ((aperture (/ focal-length f-stop))
+ (numerator (* distance coc (- distance focal-length)))
+ (factor-1 (* focal-length aperture))
+ (factor-2 (* coc (- distance focal-length)))
+ (near (- distance (/ numerator (+ factor-1 factor-2))))
+ (far (+ distance (/ numerator (- factor-1 factor-2))))
+ (mag (magnification focal-length distance))
+ (infinity-blur-diameter (/ (* mag focal-length) f-stop))
+ (depth (- far near)))
+ (values near far depth mag infinity-blur-diameter)))