r10424: Automated commit for Debian build of cl-photo upstream-version-0.2
[cl-photo.git] / convert.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          convert.lisp
6 ;;;; Purpose:       Conversions functions for cl-photo
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  April 2005
9 ;;;;
10 ;;;; $Id$
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 (defconstant +radian->degrees+ (/ 360d0 pi 2))
23 (defconstant +inches->mm+ 25.4d0)
24
25 (declaim (inline diagonal))
26 (defun diagonal (x y)
27   (sqrt (+ (* x x) (* y y))))
28
29 (declaim (inline radians->degrees))
30 (defun radians->degrees (r)
31   (* +radian->degrees+ r))
32
33 (declaim (inline degrees->radians))
34 (defun degrees->radians (r)
35   (/ r +radian->degrees+))
36
37 (declaim (inline mm->feet))
38 (defun mm->feet (d)
39   (/ d +inches->mm+ 12))
40
41 (declaim (inline feet->mm))
42 (defun feet->mm (d)
43   (* d 12 +inches->mm+))
44
45 (declaim (inline inches->mm))
46 (defun inches->mm (d)
47   (* d +inches->mm+))
48
49 (declaim (inline mm->inches))
50 (defun mm->inches (d)
51   (/ d +inches->mm+))
52
53 (defun length->mm (d units)
54   "Convert a length in units to mm."
55   (ecase units
56     (:mm d)
57     (:inches (inches->mm d))
58     (:feet (* 12 (inches->mm d)))
59     (:yards (* 36 (inches->mm d)))
60     (:meters (* 1000 d))))
61
62 (defun mm->length (d units)
63   "Convert a number of mm to units."
64   (ecase units
65     (:mm d)
66     (:inches (mm->inches d))
67     (:feet (/ (mm->inches d) 12))
68     (:yards (/ (mm->inches d) 36))
69     (:meters (/ d 1000))))
70
71 (defun format-dimensions (format)
72   "Returns format dimensions in mm."
73   (ecase format
74     (:aps-c (cons 22.7 15.1))
75     ((:aps :dx) (cons 24 16))
76     ((:35 :35mm) (cons 36 24))
77     ((:645 :6x4.5cm) (cons 60 45))
78     ((:6x6 :6x6cm) (cons 60 60))
79     ((:6x7 :6x7cm) (cons 60 70))
80     ((:6x9 :6x9cm) (cons 60 90))
81     ((:4x5 :4x5in) (cons (* 4 +inches->mm+) (* 5 +inches->mm+)))
82     ((:5x7 :5x7in) (cons (* 5 +inches->mm+) (* 7 +inches->mm+)))
83     ((:8x10 :8x10in) (cons (* 8 +inches->mm+) (* 10 +inches->mm+))) 
84     (:11x13.75in (cons (* 11 +inches->mm+) (* 13.75 +inches->mm+)))
85     (:11x16.5in (cons (* 11 +inches->mm+) (* 16.5 +inches->mm+)))
86     (:13x19in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
87     (:16x20in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
88     (:16x24in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
89     (:18x22.5in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
90     (:18x24in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
91     (:24x30in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
92     (:24x36in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
93     ))