;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: April 2005
;;;;
-;;;; $Id: package.lisp 8596 2004-02-03 18:32:50Z kevin $
+;;;; $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)
;;;;
;;;; *************************************************************************
(in-package #:photo)
-;; Based on http://www.photostuff.co.uk/dofmstr.htm
+(defun coc (imager-size &key (lpm 5) (minimum-distance 250)
+ (viewing-distance 250)
+ (print-size (output-dimensions :8x10in)))
+ "Returns circle of confusion in mm and print magnification for a format.
+Default resolving power is 5 lpm at 25cm."
-(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"
- (let* ((aperature (/ focal-length f-stop))
- (numerator (* distance coc (- distance focal-length)))
- (factor-1 (* focal-length aperature))
- (factor-2 (* coc (- distance focal-length)))
- (near (/ numerator (+ factor-1 factor-2)))
- (far (/ numerator (- factor-1 factor-2)))
- (depth (+ far near)))
- (values near far depth (- distance near) (+ distance far))))
+ (let* ((imager-diagonal (diagonal (car imager-size) (cdr imager-size)))
+ (print-diagonal (diagonal (car print-size) (cdr print-size)))
+ (resolution-factor (/ (* lpm print-diagonal minimum-distance)
+ (* imager-diagonal viewing-distance)))
+ (coc (/ 1.0d0 resolution-factor))
+ (print-magnification (/ print-diagonal imager-diagonal)))
+ (values coc print-magnification)))
+
+(defun coc-format (format &key (lpm 5) (minimum-distance 250)
+ (viewing-distance 250)
+ (print-size (output-dimensions :8x10in)))
+ "Returns circle of confusion in mm and print magnification for a format.
+Default resolving power is 5 lpm at 25cm."
-(defun dof-feet (focal-length f-stop distance coc)
- (multiple-value-bind (near-dof far-dof total-dof near-point far-point)
- (dof focal-length f-stop (feet->mm distance) coc)
- (values (mm->feet near-dof) (mm->feet far-dof) (mm->feet total-dof)
- (mm->feet near-point) (mm->feet far-point))))
+ (let* ((format-size (imager-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 dof-meters (focal-length f-stop distance coc)
- (multiple-value-bind (near-dof far-dof total-dof near-point far-point)
- (dof focal-length f-stop (* 1000 distance) coc)
- (values (* 0.001 near-dof) (* 0.001 far-dof) (* 0.001 total-dof)
- (* 0.001 near-point) (* 0.001 far-point))))
+(defun coc-pixels (imager pixels)
+ "Returns circle of confusion based on pixel size."
+ (when (and (consp imager) (consp pixels))
+ (values (float (* 2 (/ (car imager) (car pixels))))
+ (float (* 2 (/ (cdr imager) (cdr pixels)))))))
+
+(defun coc-pixels-format (format)
+ "Returns circle of confusion based on pixel size."
+ (coc-pixels (imager-dimensions format) (pixel-dimensions format)))
+(defun coc-airy (f-stop)
+ "Return the circle of confusion based on the airy disk."
+ (let ((airy (/ f-stop 1500)))
+ (float (* 2 airy))))
-(defun hyperfocal (focal-length f-stop coc)
- (+ focal-length (/ (* focal-length focal-length) (* f-stop coc))))
+(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)))
-(defun hyperfocal-feet (focal-length f-stop coc)
- (mm->feet (hyperfocal focal-length f-stop coc)))
+(defun dof (focal-length f-stop distance coc &key (units :mm) (pupil-factor 1))
+ "Returns the Depth of Field.
+Input: FOCAL-LENGTH, F-STOP, DISTANCE, CIRCLE-OF-CONFUSION.
+Output: NEAR-POINT, FAR-POINT, TOTAL-DOF, MAGNIFICATION, BLUR-SIZE-OF-INFINITY-POINT-IN-MM."
+ (multiple-value-bind (near-point far-point total-dof mag blur)
+ (dof-mm focal-length f-stop (length->mm distance units) coc
+ :pupil-factor pupil-factor)
+ (values (mm->length near-point units)
+ (mm->length far-point units)
+ (mm->length total-dof units)
+ mag blur)))
+(defun hyperfocal (focal-length f-stop coc &key (units :mm))
+ (mm->length (+ focal-length (/ (* focal-length focal-length) f-stop coc)) units))
+(defun effective-aperture (focal-length distance aperture)
+ (* aperture (bellows-factor focal-length distance)))