r10530: fix argument list
[cl-photo.git] / dof.lisp
index 5dfc5dd06e0dac523d29400f0bc58dd9f2152444..8dfdf1478ac32981d9472a92fc1bb7d1d6e70e33 100644 (file)
--- a/dof.lisp
+++ b/dof.lisp
 
 (in-package #:photo)
 
+(defun sort-size (size)
+  "Returns a cons pair with the smaller size first."
+  (if (>= (car size) (cdr size))
+      (cons (cdr size) (car size))
+      (cons (car size) (cdr size))))
+  
+(defun print-magnification (imager-size print-size)
+  "Returns the magnification required between an imager and print sizes
+while taking crop into consideration."
+  (setf imager-size (sort-size imager-size))
+  (setf print-size (sort-size print-size))
+  (float (max (/ (car print-size) (car imager-size))
+             (/ (cdr print-size) (cdr print-size)))))
+
 (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."
-
-  (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)))
+  (let* ((magnification (print-magnification imager-size print-size))
+        (resolution-factor (/ (* magnification lpm minimum-distance) viewing-distance))
+        (coc (/ 1.0d0 resolution-factor)))
+    (values coc magnification)))
 
 (defun coc-format (format &key (lpm 5) (minimum-distance 250) 
                           (viewing-distance 250)
@@ -70,6 +80,7 @@ Default resolving power is 5 lpm at 25cm."
 
 (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))
@@ -128,3 +139,7 @@ Output: NEAR-POINT, FAR-POINT, TOTAL-DOF, MAGNIFICATION, BLUR-SIZE-OF-INFINITY-P
 
 (defun effective-aperture (focal-length distance aperture)
   (* aperture (bellows-factor focal-length distance)))
+
+(defun mtf-scanner (freq dscan-freq &optional (order 3))
+  (abs (expt (kmrcl:sinc (* pi (/ freq dscan-freq))) order)))
+