From: Kevin M. Rosenberg Date: Fri, 31 Aug 2007 18:04:31 +0000 (+0000) Subject: r11859: Canonicalize whitespace X-Git-Tag: v0.13~5 X-Git-Url: http://git.kpe.io/?p=cl-photo.git;a=commitdiff_plain;h=6290486a001d80c01676dfd9c2ac053cb4bc1871 r11859: Canonicalize whitespace --- diff --git a/cameras.lisp b/cameras.lisp index 118f48a..ee51d71 100644 --- a/cameras.lisp +++ b/cameras.lisp @@ -28,12 +28,12 @@ (eval-when (:compile-toplevel :load-toplevel :execute) (defun make-output-format (w h &key (units :inches)) (let ((name (format nil "~Dx~D~A" w h - (ecase units - (:inches "in") - (:mm "mm") - (:cm "cm") - (:m "m") - (:feet "ft"))))) + (ecase units + (:inches "in") + (:mm "mm") + (:cm "cm") + (:m "m") + (:feet "ft"))))) (list :format (kmrcl:ensure-keyword name) :output (cons (length->mm w units) (length->mm h units)) :name name @@ -64,7 +64,7 @@ :name "N Digital") (:format :s1pro :make "FujiFilm" :pixels (3040 . 2016) :imager (23 . 15.5) - :name "FinePix S1 Pro") + :name "FinePix S1 Pro") (:format :s2pro :make "FujiFilm" :pixels (4256 . 2848) :imager (23 . 15.5) :name "FinePix S2 Pro") (:format :s3pro :make "FujiFilm" :pixels (4256 . 2848) :imager (23 . 15.5) @@ -116,13 +116,13 @@ (:format :1/1.8in :imager (7.18 . 5.32) :name "1/1.8\"") (:format :dx :imager (24 . 16) :name "DX") (:format :35mm :imager (36 . 24) :name "35mm") - + (:format :6x4.5cm :imager (60 . 45) :name "6x4.5cm" :nicks (:\645)) (:format :6x6cm :imager (60 . 60) :name "6x6cm" :nicks (:6x6)) (:format :6x7cm :imager (60 . 70) :name "6x7cm" :nicks (:6x7)) (:format :6x9cm :imager (60 . 90) :name "6x9cm" :nicks (:6x9)) (:format :6x12cm :imager (60 . 120) :name "6x12cm" :nicks (:6x12)) - + #.(make-output-format 4 5) #.(make-output-format 5 7) #.(make-output-format 8 10) @@ -139,47 +139,47 @@ )) (defun sort-formats (formats) - (sort formats - (lambda (a b) - (block nil - (cond - ((and (null (getf a :make)) (getf b :make)) - (return nil)) - ((and (getf a :make) (null (getf b :make))) - (return t)) - ((string-lessp (getf a :make) (getf b :make)) - (return t)) - ((string-greaterp (getf a :make) (getf b :make)) - (return nil))) - (when (and (getf a :name) (getf b :name)) - (cond - ((string-lessp (getf a :name) (getf b :name)) - (return t)) - ((string-greaterp (getf a :name) (getf b :name)) - (return nil)))))))) + (sort formats + (lambda (a b) + (block nil + (cond + ((and (null (getf a :make)) (getf b :make)) + (return nil)) + ((and (getf a :make) (null (getf b :make))) + (return t)) + ((string-lessp (getf a :make) (getf b :make)) + (return t)) + ((string-greaterp (getf a :make) (getf b :make)) + (return nil))) + (when (and (getf a :name) (getf b :name)) + (cond + ((string-lessp (getf a :name) (getf b :name)) + (return t)) + ((string-greaterp (getf a :name) (getf b :name)) + (return nil)))))))) (defvar *digital-cameras* (sort-formats (loop for format in +format-db+ - when (getf format :pixels) - collect format))) + when (getf format :pixels) + collect format))) (defvar *cameras* (sort-formats (loop for format in +format-db+ - when (getf format :imager) - collect format))) - + when (getf format :imager) + collect format))) + (defun format-match-p (format-spec format) (let ((key (ensure-keyword format-spec))) (when (or (eql key (getf format :format)) - (member key (getf format :nicks))) + (member key (getf format :nicks))) t))) (defun find-format (format-spec) (find format-spec +format-db+ :test 'format-match-p)) (defun pixel-dimensions (sensor-spec &key (format :35mm)) - "Returns the number of pixels for a format. + "Returns the number of pixels for a format. 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 @@ -194,13 +194,13 @@ so the proper aspect ratio is used." "Returns the imager dimensions in mm of a FORMAT." (getf (find-format format-spec) :imager)) -(defun pixel-size (format-spec) +(defun pixel-size (format-spec) "Return pixel size in micrometers." (let ((pixel-dim (pixel-dimensions format-spec)) - (imager-dim (imager-dimensions format-spec))) + (imager-dim (imager-dimensions format-spec))) (when (and pixel-dim imager-dim) (values (* 1000 (/ (car imager-dim) (car pixel-dim))) - (* 1000 (/ (cdr imager-dim) (cdr pixel-dim))))))) + (* 1000 (/ (cdr imager-dim) (cdr pixel-dim))))))) (defun output-dimensions (format-spec) "Returns the output dimensions in mm of a FORMAT." diff --git a/dof.lisp b/dof.lisp index 8dfdf14..f1cd7b2 100644 --- a/dof.lisp +++ b/dof.lisp @@ -24,29 +24,29 @@ (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))))) + (/ (cdr print-size) (cdr print-size))))) -(defun coc (imager-size &key (lpm 5) (minimum-distance 250) +(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. + "Returns circle of confusion in mm and print magnification for a format. Default resolving power is 5 lpm at 25cm." (let* ((magnification (print-magnification imager-size print-size)) - (resolution-factor (/ (* magnification lpm minimum-distance) viewing-distance)) - (coc (/ 1.0d0 resolution-factor))) + (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) +(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. + "Returns circle of confusion in mm and print magnification for a format. Default resolving power is 5 lpm at 25cm." (let* ((format-size (imager-dimensions format)) @@ -62,9 +62,9 @@ Default resolving power is 5 lpm at 25cm." "Returns lpm and circle of confusion based on pixel size." (when (and (consp imager) (consp pixels)) (let ((coc-w (float (* 2 (/ (car imager) (car pixels))))) - (coc-h (float (* 2 (/ (cdr imager) (cdr pixels)))))) + (coc-h (float (* 2 (/ (cdr imager) (cdr pixels)))))) (values coc-w coc-h (/ 1. coc-w) (/ 1. coc-h))))) - + (defun coc-pixels-format (format) "Returns circle of confusion based on pixel size." (coc-pixels (imager-dimensions format) (pixel-dimensions format))) @@ -88,7 +88,7 @@ Default resolving power is 5 lpm at 25cm." Six values are returned: 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)) + (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)) @@ -124,10 +124,10 @@ Pupil factor is the ratio of the exit to enterance pupil diameters." (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. +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 + (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) diff --git a/fov.lisp b/fov.lisp index 64bbe80..bad7042 100644 --- a/fov.lisp +++ b/fov.lisp @@ -19,7 +19,7 @@ (in-package #:photo) -(defun aov-one-dim (focal-length frame-size +(defun aov-one-dim (focal-length frame-size &key (projection :rectilinear) (magnification 0)) "Returns the angle of view in one dimension. Default is infinity which @@ -28,21 +28,21 @@ has an magnification of 0." (:rectilinear (radians->degrees (* 2 (atan (/ frame-size 2 focal-length (1+ magnification)))))) - (:equisolid + (:equisolid (radians->degrees (* 4 (asin (/ frame-size 4 focal-length))))) - (:equidistance + (:equidistance (radians->degrees (/ (* 2 frame-size) focal-length))) (:orthogonal (radians->degrees (* 2 (asin (/ frame-size 2 focal-length))))) (:stereographic (radians->degrees (* 4 (atan (/ frame-size 4 focal-length))))) )) - - + + (defun aov (focal-length frame-width frame-height &key (projection :rectilinear) (magnification 0)) - "Returns the angle of field of view for a focal length and frame size. + "Returns the angle of field of view for a focal length and frame size. Default is infinity (magnification 0)" (values (aov-one-dim focal-length frame-width :projection projection :magnification magnification) @@ -79,7 +79,7 @@ Default is infinity (magnification 0)" (defun image-distance-magnification (focal-length magnification) - "Returns the image distance for a focused object at distance using the Gaussian + "Returns the image distance for a focused object at distance using the Gaussian Lens Equation." (* focal-length (1+ magnification))) @@ -109,25 +109,25 @@ and image distance (mm) for a given image (mm) and object distance (mm)." (setq image-distance (gaussian-lens :focal-length focal-length :object-distance object-distance - :units units))) + :units units))) ((and (not object-distance) image-distance (not magnification)) (setq object-distance (gaussian-lens - :focal-length focal-length - :image-distance image-distance - :units units))) + :focal-length focal-length + :image-distance image-distance + :units units))) ((and (not object-distance) (not image-distance) magnification) (setf image-distance (image-distance-magnification focal-length magnification) object-distance (when (numberp image-distance) (mm->length (/ image-distance magnification) units)))) (t - (error "Must set one, and only one, of the parameters: image-distance, object-distance, or magnification."))) + (error "Must set one, and only one, of the parameters: image-distance, object-distance, or magnification."))) (%fov focal-length frame-width frame-height object-distance image-distance units projection)) (defun aov-format (focal-length format &key (projection :rectilinear)) "Returns the angle of field of view for a focal length and frame size at infinity" - (let ((dim (imager-dimensions format))) + (let ((dim (imager-dimensions format))) (aov focal-length (car dim) (cdr dim) :projection projection))) (defun magnification (&key focal-length object-distance image-distance (units :feet)) @@ -166,40 +166,40 @@ Returns: focal-length object-distance image-distance magnification bellows-facto (cond ((and focal-length object-distance (not image-distance) (not magnification)) (setq magnification (magnification :focal-length focal-length - :object-distance object-distance - :units units)) + :object-distance object-distance + :units units)) (setq image-distance (gaussian-lens :focal-length focal-length - :object-distance object-distance - :units units))) + :object-distance object-distance + :units units))) ((and focal-length (not object-distance) image-distance (not magnification)) (setq magnification (magnification :focal-length focal-length - :image-distance image-distance - :units units)) + :image-distance image-distance + :units units)) (setq object-distance (gaussian-lens :focal-length focal-length - :image-distance image-distance - :units units))) + :image-distance image-distance + :units units))) ((and (not focal-length) object-distance image-distance (not magnification)) (setq magnification (magnification :object-distance object-distance - :image-distance image-distance - :units units)) + :image-distance image-distance + :units units)) (setq focal-length (gaussian-lens :object-distance object-distance - :image-distance image-distance - :units units))) + :image-distance image-distance + :units units))) ((and focal-length (not object-distance) (not image-distance) magnification) (setq image-distance (image-distance-magnification focal-length magnification)) (setq object-distance (gaussian-lens :focal-length focal-length - :image-distance image-distance - :units units))) + :image-distance image-distance + :units units))) ((and (not focal-length) object-distance (not image-distance) magnification) (setq image-distance (* magnification (length->mm object-distance units))) (setq focal-length (gaussian-lens :image-distance image-distance - :object-distance object-distance - :units units))) + :object-distance object-distance + :units units))) ((and (not focal-length) (not object-distance) image-distance magnification) (setq object-distance (mm->length (float (/ image-distance magnification)) units)) (setq focal-length (gaussian-lens :image-distance image-distance - :object-distance object-distance - :units units))) + :object-distance object-distance + :units units))) (t (error "Must set two, and only two input parameters: focal-length, image-distance, object-distance, magnifcation."))) (values focal-length object-distance image-distance magnification (1+ magnification))) @@ -212,50 +212,50 @@ Returns: focal-length object-distance image-distance magnification bellows-facto "Returns T when count N of input args are not nil." (= n (count-if-not #'null args))) -(defun extension-tube (focal-length &key original-object-distance - original-image-distance original-magnification - new-object-distance new-image-distance - new-magnification extension-length (units :feet)) +(defun extension-tube (focal-length &key original-object-distance + original-image-distance original-magnification + new-object-distance new-image-distance + new-magnification extension-length (units :feet)) "Computes the parameters for using extension tubes. Requires: 1. original-object-distance, original-image-distance, or original-magnification 2. new-object-distance, new-image-distance, new-magnification, or extension-length Returns: original-object-distance, original-image-distance, original-magnification, original-bellows-factor new-object-distance, new-image-distance, new-magnification, extension-length." - + (when (or (not focal-length) (not units) - (not (n-args-not-nil 1 original-object-distance - original-image-distance - original-magnification)) - (not (n-args-not-nil 1 new-object-distance - new-image-distance - new-magnification - extension-length))) + (not (n-args-not-nil 1 original-object-distance + original-image-distance + original-magnification)) + (not (n-args-not-nil 1 new-object-distance + new-image-distance + new-magnification + extension-length))) (error "Invalid arguments. Must set 1 of the following original-object-distance, original-image-distance, or original-magnification parameters as well as one of the following parameters new-object-distance, new-image-distance, new-magnification, or extension-length.")) (flet ((ret (ood oid om obf nod nid nm nbf e) - (list :focal-length focal-length :original-object-distance ood - :original-image-distance oid :original-magnification om - :original-bellows-factor obf :new-object-distance nod - :new-image-distance nid :new-magnification nm - :new-bellows-factor nbf :extension-length e))) + (list :focal-length focal-length :original-object-distance ood + :original-image-distance oid :original-magnification om + :original-bellows-factor obf :new-object-distance nod + :new-image-distance nid :new-magnification nm + :new-bellows-factor nbf :extension-length e))) (multiple-value-bind (focal-length-original o-od o-id o-m o-bf) (close-up :focal-length focal-length :object-distance original-object-distance - :image-distance original-image-distance :magnification original-magnification :units units) + :image-distance original-image-distance :magnification original-magnification :units units) (declare (ignore focal-length-original)) - + (cond (extension-length (multiple-value-bind (focal-length-new n-od n-id n-m n-bf) - (close-up :focal-length focal-length :image-distance (+ o-id extension-length) :units units) - (declare (ignore focal-length-new)) - (ret o-od o-id o-m o-bf n-od n-id n-m n-bf extension-length))) + (close-up :focal-length focal-length :image-distance (+ o-id extension-length) :units units) + (declare (ignore focal-length-new)) + (ret o-od o-id o-m o-bf n-od n-id n-m n-bf extension-length))) ((not extension-length) (multiple-value-bind (focal-length-new n-od n-id n-m n-bf) - (close-up :focal-length focal-length :object-distance new-object-distance - :image-distance new-image-distance :magnification new-magnification :units units) - (declare (ignore focal-length-new)) - (ret o-od o-id o-m o-bf n-od n-id n-m n-bf (- n-id o-id)))))))) + (close-up :focal-length focal-length :object-distance new-object-distance + :image-distance new-image-distance :magnification new-magnification :units units) + (declare (ignore focal-length-new)) + (ret o-od o-id o-m o-bf n-od n-id n-m n-bf (- n-id o-id)))))))) diff --git a/package.lisp b/package.lisp index 081e3be..0096657 100644 --- a/package.lisp +++ b/package.lisp @@ -41,7 +41,7 @@ #:gaussian-lens #:close-up #:extension-tube - + ;; dof.lisp #:print-magnification #:coc @@ -54,7 +54,7 @@ #:effective-aperture #:rayleigh-limit #:maximum-sharpness-aperture - + ;; tables.lisp #:hyperfocal-table #:aov-table diff --git a/tables.lisp b/tables.lisp index 228a0ed..aad7421 100644 --- a/tables.lisp +++ b/tables.lisp @@ -25,7 +25,7 @@ (defun hyperfocal-table (focal-length coc &key (units :feet) (output *standard-output*)) (loop for f-stop in +f-stops+ - do (format output "~4,1F ~,1F~%" + do (format output "~4,1F ~,1F~%" f-stop (hyperfocal focal-length f-stop coc :units units))) (values)) @@ -37,7 +37,7 @@ (loop for focal-length in +focal-lengths+ do (let ((aov (multiple-value-list (aov focal-length (car imager-dim) (cdr imager-dim) :projection projection)))) - (format output "~5D ~5,1F ~5,1F ~5,1F~%" + (format output "~5D ~5,1F ~5,1F ~5,1F~%" focal-length (nth 0 aov) (nth 1 aov) (nth 2 aov))))) (values)) @@ -54,7 +54,7 @@ (car imager-dim) (cdr imager-dim) distance :projection projection)))) - (format output "~8F: ~6F ~6F ~6F ~6F~%" + (format output "~8F: ~6F ~6F ~6F ~6F~%" (mm->length distance units) (nth 0 fov) (nth 1 fov) (nth 2 fov) (nth 3 fov))))) (values)) @@ -71,7 +71,7 @@ (dolist (distance distances) (multiple-value-bind (near far dof mag blur) (dof focal-length f-stop distance coc :units units) - (declare (ignorable dof mag blur)) + (declare (ignorable dof mag blur)) (when (minusp far) (setq far "Inf ")) (format output "~5F/~5F " near far))) (format output "~%"))) diff --git a/tests.lisp b/tests.lisp index 3f1c57c..403977c 100644 --- a/tests.lisp +++ b/tests.lisp @@ -41,96 +41,96 @@ (def-numeric-test :aov.1 (aov 50 36 24) 39.5977 26.9915 46.7930) - -(def-numeric-test + +(def-numeric-test :fov.1 (fov 50 24 16 :magnification 1 :units :mm) 24 16 28.8444 1 100 100) -(def-numeric-test +(def-numeric-test :fov.2 (fov 50 24 16 :magnification 1 :units :feet) 0.07874 0.052494 0.094634 1 0.328084 100) -(def-numeric-test +(def-numeric-test :fov.3 (fov 50 24 16 :image-distance 100 :units :mm) 24 16 28.8444 1 100 100) -(def-numeric-test +(def-numeric-test :fov.4 (fov 50 24 16 :image-distance 100 :units :feet) 0.07874 0.052494 0.094634 1 0.328084 100) -(def-numeric-test +(def-numeric-test :fov.5 (fov 50 24 16 :object-distance 100 :units :mm) 24 16 28.8444 1 100 100) -(def-numeric-test +(def-numeric-test :fov.6 (fov 50 24 16 :object-distance (cl-photo::mm->feet 100) :units :feet) 0.07874 0.052494 0.094634 1 0.328084 100) -(def-numeric-test +(def-numeric-test :mag.1 (magnification :focal-length 50 :image-distance 100 :units :mm) 1) -(def-numeric-test +(def-numeric-test :mag.2 (magnification :focal-length 50 :image-distance 100 :units :feet) 1) -(def-numeric-test +(def-numeric-test :mag.3 (magnification :focal-length 50 :object-distance 100 :units :mm) 1) -(def-numeric-test +(def-numeric-test :mag.4 (magnification :focal-length 50 :object-distance (cl-photo::mm->feet 100) :units :feet) 1) -(def-numeric-test +(def-numeric-test :mag.5 (magnification :image-distance 100 :object-distance 100 :units :mm) 1) -(def-numeric-test +(def-numeric-test :mag.6 (magnification :image-distance 100 :object-distance (cl-photo::mm->feet 100) :units :feet) 1) -(def-numeric-test +(def-numeric-test :cu.1 (close-up :focal-length 65 :magnification 5 :units :mm) 65 78 390 5 6) -(def-numeric-test - :cu.2 (close-up :focal-length 65 :object-distance 78 :units :mm) +(def-numeric-test + :cu.2 (close-up :focal-length 65 :object-distance 78 :units :mm) 65 78 390 5 6) -(def-numeric-test - :cu.3 (close-up :focal-length 65 :image-distance 390 :units :mm) +(def-numeric-test + :cu.3 (close-up :focal-length 65 :image-distance 390 :units :mm) 65 78 390 5 6) -(def-numeric-test - :cu.4 (close-up :object-distance 78 :image-distance 390 :units :mm) +(def-numeric-test + :cu.4 (close-up :object-distance 78 :image-distance 390 :units :mm) 65 78 390 5 6) -(def-numeric-test - :cu.5 (close-up :object-distance 78 :magnification 5 :units :mm) +(def-numeric-test + :cu.5 (close-up :object-distance 78 :magnification 5 :units :mm) 65 78 390 5 6) -(def-numeric-test +(def-numeric-test :cu.6 (close-up :image-distance 390 :magnification 5 :units :mm) 65 78 390 5 6) -(def-numeric-test +(def-numeric-test :cu.7 (close-up :focal-length 65 :magnification 5 :units :feet) 65 0.2559055 390 5 6) -(def-numeric-test - :cu.8 (close-up :focal-length 65 :object-distance 0.2559055 :units :feet) +(def-numeric-test + :cu.8 (close-up :focal-length 65 :object-distance 0.2559055 :units :feet) 65 0.2559055 390 5 6) -(def-numeric-test - :cu.9 (close-up :focal-length 65 :image-distance 390 :units :feet) +(def-numeric-test + :cu.9 (close-up :focal-length 65 :image-distance 390 :units :feet) 65 0.2559055 390 5 6) -(def-numeric-test - :cu.10 (close-up :object-distance 0.2559055 :image-distance 390 :units :feet) +(def-numeric-test + :cu.10 (close-up :object-distance 0.2559055 :image-distance 390 :units :feet) 65 0.2559055 390 5 6) -(def-numeric-test - :cu.11 (close-up :object-distance 0.2559055 :magnification 5 :units :feet) +(def-numeric-test + :cu.11 (close-up :object-distance 0.2559055 :magnification 5 :units :feet) 65 0.2559055 390 5 6) -(def-numeric-test +(def-numeric-test :cu.12 (close-up :image-distance 390 :magnification 5 :units :feet) 65 0.2559055 390 5 6)