c0df801e1f25201bd6577876f5039390e9f2f18a
[cl-photo.git] / tables.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          tables.lisp
6 ;;;; Purpose:       Returns tables of values
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  April 2005
9 ;;;;
10 ;;;; $Id: dof.lisp 10436 2005-04-21 15:36:01Z kevin $
11 ;;;;
12 ;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; cl-photo users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the GNU General Public License v2
16 ;;;; (http://www.gnu.org/licenses/gpl.html)
17 ;;;;
18 ;;;; *************************************************************************
19
20 (in-package #:photo)
21
22 (defparameter +f-stops+ '(1.4 2.0 2.8 4.0 5.6 8 11 16 22 32))
23 (defparameter +focal-lengths+ '(12 24 35 50 70 85 105 135 200 300 400 500 600))
24 (defparameter +distances-feet+ '(0.5 1 3 8 15 25 50 100 200))
25
26 (defun hyperfocal-list (focal-length coc &key (units :feet))
27   (loop for f-stop in +f-stops+
28         collect (hyperfocal focal-length f-stop coc :units units)))
29
30 (defun hyperfocal-table (focal-length coc &key (units :feet) (output *standard-output*))
31   (loop for f-stop in +f-stops+
32         do (format output "~4,1F ~,1F~%" 
33                    f-stop (hyperfocal focal-length f-stop coc :units units)))
34   (values))
35
36 (defun aov-table (imager &key (output *standard-output*) (projection :rectilinear))
37   (let ((imager-dim (etypecase imager
38                       (cons imager)
39                       (symbol (imager-dimensions imager)))))
40     (loop for focal-length in +focal-lengths+
41           do (let ((aov (multiple-value-list (aov focal-length (car imager-dim) (cdr imager-dim)
42                                                   :projection projection))))
43                (format output "~4D ~5,1F ~5,1F ~5,1F~%" 
44                        focal-length (nth 0 aov) (nth 1 aov) (nth 2 aov)))))
45   (values))
46
47 (defun dof-table (focal-length coc &key (output *standard-output*) (units :feet))
48   (let ((distances (mapcar (lambda (mm) (mm->length mm units))
49                            (mapcar 'feet->mm +distances-feet+))))
50     (format output "~&~5A" "")
51     (dolist (distance distances)
52       (format output " ~10F" distance))
53     (format output "~%")
54     (dolist (f-stop +f-stops+)
55       (format output "~5,1F " f-stop)
56       (dolist (distance distances)
57         (multiple-value-bind (near far dof mag blur) (dof focal-length f-stop distance coc
58                                                           :units units)
59           (when (minusp far) (setq far "Inf"))
60           (format output "~4,1F/~4,1F " near far)))
61       (format output "~%")))
62   (values))