From 8e621e12d665c431695ca08ee015325f2ed47130 Mon Sep 17 00:00:00 2001 From: Kevin Rosenberg Date: Sun, 9 Sep 2007 16:30:22 -0600 Subject: [PATCH] Set near-point correctly when at or above hyperfocal. Avoid divide by 0 errors at hyperfocal. --- debian/changelog | 6 ++++++ dof.lisp | 30 +++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/debian/changelog b/debian/changelog index 9cfcf33..38c2136 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cl-photo (0.14-1) unstable; urgency=low + + * Set near-point correctly when at or above hyperfocal + + -- Kevin M. Rosenberg Sun, 9 Sep 2007 16:28:58 -0600 + cl-photo (0.13-1) unstable; urgency=low * Check if object distance is beyond hyperfocal distance and report infinity for dof (closes:438197) diff --git a/dof.lisp b/dof.lisp index 55b7b2a..d8677d3 100644 --- a/dof.lisp +++ b/dof.lisp @@ -90,6 +90,7 @@ near point, far point, 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)) + (hyperfocal (hyperfocal focal-length f-stop coc)) (numerator-1 (* (- pupil-factor 1) (- distance focal-length) coc focal-length)) (numerator-2 (* pupil-factor aperture focal-length distance)) @@ -97,14 +98,17 @@ Reference: http://www.vanwalree.com/optics/dofderivation.html" (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))) + (far (when (/= denominator-1 denominator-2) + (/ (- 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))) - (when (and (< far 0) (> distance focal-length)) - (setq far most-positive-short-float) - (setq depth most-positive-short-float)) + (depth (when far (- far near)))) + (when (or (>= distance hyperfocal) + (and (null far) (>= distance (* hyperfocal 0.99)))) + (setq near (/ hyperfocal 2) + far most-positive-short-float + depth most-positive-short-float)) (values near far depth mag infinity-blur-diameter))) ;; Simplified calculation for symmetric lens @@ -115,17 +119,21 @@ near point, far point, 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)) + (hyperfocal (hyperfocal focal-length f-stop coc)) (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)))) + (far (when (/= factor-1 factor-2) + (+ distance (/ numerator (- factor-1 factor-2))))) (mag (magnification :focal-length focal-length :object-distance distance :units :mm)) (infinity-blur-diameter (/ (* mag focal-length) f-stop)) - (depth (- far near))) - (when (and (< far 0) (> distance focal-length)) - (setq far most-positive-short-float) - (setq depth most-positive-short-float)) + (depth (when far (- far near)))) + (when (or (>= distance hyperfocal) + (and (null far) (>= distance (* hyperfocal 0.99)))) + (setq near (/ hyperfocal 2) + far most-positive-short-float + depth most-positive-short-float)) (values near far depth mag infinity-blur-diameter))) (defun dof (focal-length f-stop distance coc &key (units :mm) (pupil-factor 1)) -- 2.34.1