r10409: updates for cl-photo
[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 Rosenberg.
13 ;;;; Rights of modification and redistribution are in the LICENSE file.
14 ;;;;
15 ;;;; *************************************************************************
16
17 (in-package #:photo)
18
19 (defconstant +radian->degrees+ (/ 360d0 pi 2))
20 (defconstant +inches->mm+ 25.4d0)
21
22 (declaim (inline diagonal))
23 (defun diagonal (x y)
24   (sqrt (+ (* x x) (* y y))))
25
26 (declaim (inline radians->degrees))
27 (defun radians->degrees (r)
28   (* +radian->degrees+ r))
29
30 (declaim (inline degrees->radians))
31 (defun degrees->radians (r)
32   (/ r +radian->degrees+))
33
34 (declaim (inline mm->feet))
35 (defun mm->feet (d)
36   (/ d +inches->mm+ 12))
37
38 (declaim (inline feet->mm))
39 (defun feet->mm (d)
40   (* d 12 +inches->mm+))
41
42 (declaim (inline inches->mm))
43 (defun inches->mm (d)
44   (* d +inches->mm+))
45
46 (defun format-dimensions (format)
47   "Returns format dimensions in mm."
48   (ecase format
49     (:aps-c (cons 22.7 15.1))
50     ((:aps :dx) (cons 24 16))
51     ((:35 :35mm) (cons 36 24))
52     ((:645 :6x4.5cm) (cons 60 45))
53     ((:6x6 :6x6cm) (cons 60 60))
54     ((:6x7 :6x7cm) (cons 60 70))
55     ((:6x9 :6x9cm) (cons 60 90))
56     ((:4x5 :4x5in) (cons (* 4 +inches->mm+) (* 5 +inches->mm+)))
57     ((:5x7 :5x7in) (cons (* 5 +inches->mm+) (* 7 +inches->mm+)))
58     ((:8x10 :8x10in) (cons (* 8 +inches->mm+) (* 10 +inches->mm+))) 
59     (:11x13.75in (cons (* 11 +inches->mm+) (* 13.75 +inches->mm+)))
60     (:11x16.5in (cons (* 11 +inches->mm+) (* 16.5 +inches->mm+)))
61     (:13x19in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
62     (:16x20in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
63     (:16x24in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
64     (:18x22.5in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
65     (:18x24in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
66     (:24x30in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
67     (:24x36in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
68     ))