X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=dof.lisp;h=e3793b4969f4af6791880ac09902065d7ba165a5;hb=4e83bf8dbe167504969d64842ccf8bfae859ca9b;hp=d9cb7f1f2a2b4f1e15d51216e5a946bbaa700334;hpb=2502270d59bbf71c29d82486997d38a3981b307c;p=cl-photo.git diff --git a/dof.lisp b/dof.lisp index d9cb7f1..e3793b4 100755 --- a/dof.lisp +++ b/dof.lisp @@ -9,8 +9,11 @@ ;;;; ;;;; $Id$ ;;;; -;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin Rosenberg. -;;;; Rights of modification and redistribution are in the LICENSE file. +;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin M. Rosenberg +;;;; +;;;; cl-photo users are granted the rights to distribute and use this software +;;;; as governed by the terms of the GNU General Public License v2 +;;;; (http://www.gnu.org/licenses/gpl.html) ;;;; ;;;; ************************************************************************* @@ -18,9 +21,67 @@ ;; Based on http://www.photostuff.co.uk/dofmstr.htm +(defun coc-format (format &key (lpm 5) (minimum-distance 250) + (viewing-distance 250) + (print-size (format-dimensions :8x10in))) + "Returns circle of confusion in mm and print magnification for a format. +Default resolving power is 5 lpm at 25cm." + + (let* ((format-size (format-dimensions format)) + (format-diagonal (diagonal (car format-size) (cdr format-size))) + (print-diagonal (diagonal (car print-size) (cdr print-size))) + (resolution-factor (/ (* lpm print-diagonal minimum-distance) + (* format-diagonal viewing-distance))) + (coc (/ 1.0d0 resolution-factor)) + (print-magnification (/ print-diagonal format-diagonal))) + (values coc print-magnification))) + +(defun coc-sensor (format nx ny) + "Returns circle of confusion based on pixel size." + (let* ((dim (format-dimensions format)) + (pixel-width (/ (car dim) nx)) + (pixel-height (/ (cdr dim) ny))) + (values (coerce (* 2 pixel-width) 'float) + (coerce (* 2 pixel-height) 'float)))) + +(defun coc-sensor-camera (camera &key (format :aps)) + (let ((dim (sensor-dimensions camera :format format))) + (coc-sensor format (car dim) (cdr dim)))) + +(defun sensor-dimensions-megapixels (format megapixels) + (let* ((dim (format-dimensions format)) + (aspect-ratio (/ (car dim) (cdr dim))) + (width (round (sqrt (* aspect-ratio 1000000 megapixels))))) + (cons width (round (/ width aspect-ratio))))) + +(defun sensor-dimensions (camera &key (format :aps)) + (etypecase camera + (keyword + (ecase camera + ;; nikon + (:d2x (cons 4288 2848)) + (:d2x (cons 2484 1242)) + (: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 camera)))) + +(defun coc-airy-disk (f-stop) + "Return the circle of confusion based on the airy disk." + (let ((airy (/ f-stop 1500))) + (coerce (* 2 airy) 'float))) + (defun dof (focal-length f-stop distance coc) "Returns depth of field as fives values: -near dof, far dof, total dof, near point, far point" +near dof, far dof, total dof, near point, far point. +Circle of confusion can either be a number or keyword designating format." (let* ((aperature (/ focal-length f-stop)) (numerator (* distance coc (- distance focal-length))) (factor-1 (* focal-length aperature)) @@ -42,7 +103,6 @@ near dof, far dof, total dof, near point, far point" (values (* 0.001 near-dof) (* 0.001 far-dof) (* 0.001 total-dof) (* 0.001 near-point) (* 0.001 far-point)))) - (defun hyperfocal (focal-length f-stop coc) (+ focal-length (/ (* focal-length focal-length) (* f-stop coc))))