+(defun coc-airy (f-stop &optional (wavelength 0.000512))
+ "Return the circle of confusion based on the airy disk."
+ (float (/ 1 (rayleigh-limit f-stop wavelength))))
+
+(defun rayleigh-limit (f-stop &optional (wavelength 0.0005))
+ "Returns the rayleigh limit in line pairs per mm (MTF 9%) as well as the MTF50"
+ (let ((rayleigh (float (/ 1 1.22 f-stop wavelength))))
+ (values rayleigh (* 0.46 rayleigh))))
+
+(defun maximum-sharpness-aperture (format &optional (wavelength 0.0005))
+ (multiple-value-bind (coc-w coc-h lpm-w lpm-h) (coc-pixels-format format)
+ (declare (ignore coc-w coc-h))
+ (/ 1. (* 1.22 wavelength (/ (min lpm-w lpm-h) 0.46)))))
+
+(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, magnification, blur size at infinity (mm).
+Circle of confusion can either be a number or keyword designating format.
+Reference: http://www.vanwalree.com/optics/dofderivation.html"
+ (let* ((aperture (/ focal-length f-stop))
+ (pd (* aperture pupil-factor))
+ (numerator (* coc (- distance focal-length) (+ focal-length (* pupil-factor (- distance focal-length)))))
+ (d1 (* pupil-factor coc (- distance focal-length)))
+ (d2 (* pd focal-length))
+ (front-dof (/ numerator (+ d1 d2)))
+ (rear-dof (/ numerator (- d1 d2)))
+ (mag (float (/ focal-length (- distance focal-length))))
+ (infinity-blur-diameter (/ (* mag focal-length) f-stop))
+ (depth (+ front-dof rear-dof)))
+ (values front-dof rear-dof 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).