r10454: fix exports
[cl-photo.git] / dof.lisp
old mode 100755 (executable)
new mode 100644 (file)
index 9cb2486..a98b90a
--- a/dof.lisp
+++ b/dof.lisp
 
 (in-package #:photo)
 
+(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)))
 
 (defun coc-format (format &key (lpm 5) (minimum-distance 250) 
                           (viewing-distance 250)
-                          (print-size (format-dimensions :8x10in)))
+                          (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* ((format-size (format-dimensions format))
+  (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)
@@ -35,49 +48,15 @@ Default resolving power is 5 lpm at 25cm."
          (print-magnification (/ print-diagonal format-diagonal)))
     (values coc print-magnification)))
 
-(defun coc-sensor (format nx ny)
+(defun coc-pixels (imager pixels)
   "Returns circle of confusion based on pixel size."
-  (let* ((dim (format-dimensions format))
-         (pixel-width (/ (car dim) nx))
-         (pixel-height (/ (cdr dim) ny))) 
-    (values (float (* 2 pixel-width))
-            (float (* 2 pixel-height)))))
-
-(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 (sensor-spec &key (format :aps))
-  "Returns the number of pixels for a sensor. 
-CAMERA-SPEC is either a keyword designating the camera or
-the number of megapixels of the sensor.
-FORMAT should be defined if the CAMERA-SPEC is the number of megapixels
-so the proper aspect ratio is used."
-  (etypecase sensor-spec
-    (keyword
-     (ecase sensor-spec
-       ;; nikon
-       (:d2x (cons 4288 2848))
-       (:d100 (cons 3037 2024))
-       (:d2h (cons 2464 1632))
-       (: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 sensor-spec))))
+  (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."
@@ -87,8 +66,7 @@ so the proper aspect ratio is used."
 (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).
+near point, far point, total dof, 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)
@@ -125,6 +103,9 @@ Pupil factor is the ratio of the exit to enterance pupil diameters."
     (values near far depth mag infinity-blur-diameter)))
 
 (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)
@@ -134,15 +115,7 @@ Pupil factor is the ratio of the exit to enterance pupil diameters."
             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 magnification (focal-length distance)
-  (float (/ focal-length (- distance focal-length))))
-
-(defun bellows-factor (focal-length distance)
-  (1+ (magnification focal-length distance)))
+  (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)))
\ No newline at end of file
+  (* aperture (bellows-factor focal-length distance)))