r10439: canera database
[cl-photo.git] / cameras.lisp
index 4d5821a2c44b722173da7dfe233261569bd68bef..6e4e74bd8a713d9821ed78cf0ee33b7b7f4eb54a 100644 (file)
@@ -1,4 +1,4 @@
-;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
+;;;; -*-a Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
          (width (round (sqrt (* aspect-ratio 1000000 megapixels)))))
     (cons width (round (/ width aspect-ratio)))))
 
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (defun make-output-format (w h &key (units :inches))
+    (let ((name (format nil "~Dx~Din" w h)))
+      (list :format (kmrcl:ensure-keyword name)
+            :output (cons (inches->mm w) (inches->mm h))
+            :name name
+            :nicks (list (kmrcl:ensure-keyword (format nil "~Dx~D" w h)))))))
 
-(defun sensor-dimensions (sensor-spec &key (format :aps))
-  "Returns the number of pixels for a sensor. 
+(defparameter +format-db+
+  '(
+   (:format :d2x :make :nikon :pixels (4288 . 2848) :imager (23.7 . 15.6) :name "D2X")
+   (:format :d100 :make :nikon :pixels (3037 . 2024) :imager (23.7 . 15.6) :name "D100")
+   (:format :d70 :make :nikon :pixels (3008 . 2000) :imager (23.7 . 15.6) :name "D70")
+   (:format :d70s :make :nikon :pixels (3008 . 2000) :imager (23.7 . 15.6) :name "D70s")
+   (:format :d50 :make :nikon :pixels (3008 . 2000) :imager (23.7 . 15.6) :name "D70")
+   (:format :d1x :make :nikon :pixels (4028 . 1324) :imager (23.7 . 15.6) :name "D1X")
+   (:format :d2h :make :nikon :pixels (2464 . 1632) :imager (23.3 . 15.5) :name "D2H")
+   (:format :d2hs :make :nikon :pixels (2464 . 1632) :imager (23.3 . 15.5) :name "D2Hs")
+   
+   (:format :300d :make :canon :pixels (3072 . 2048) :imager (22.7 . 15.1) :name "300D")
+   (:format :10d :make :canon :pixels (3072 . 2048) :imager (22.7 . 15.1) :name "10D")
+   (:format :d30 :make :canon :pixels (0 . 0) :imager (22.7 . 15.1) :name "D30")
+   (:format :d60 :make :canon :pixels (0 . 0) :imager (22.7 . 15.1) :name "D60")
+   (:format :350d :make :canon :pixels (3456 . 2304) :imager (22.2 . 14.8) :name "350D")
+   (:format :1d :make :canon :pixels (2464 . 1648) :imager (27 . 17.8) :name "1D")
+   (:format :20d :make :canon :pixels (3456 . 2304) :imager (22.5 . 15) :name "20D")
+   (:format :1dmkii :make :canon :pixels (3504 . 2336) :imager (28.7 . 19.1)
+    :name "1D Mark II" :nicks (:1d2 :1dii :1dmkii))
+   (:format :1ds :make :canon :pixels (4064 . 3328) :imager (36 . 24) :name "1Ds")
+   (:format :1dsmkii :make :canon :pixels (4992 . 3328) :imager (36 . 24)
+    :name "1Ds Mark II" :nicks (:1ds2 :1dsii))
+
+   (: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)
+   #.(make-output-format 11 13.75)
+   #.(make-output-format 11 16.5)
+   #.(make-output-format 13 16.25)
+   #.(make-output-format 13 19)
+   #.(make-output-format 16 20)
+   #.(make-output-format 16 24)
+   #.(make-output-format 18 22.5)
+   #.(make-output-format 18 24)
+   #.(make-output-format 24 30)
+   #.(make-output-format 24 36)
+  ))
+
+(defun format-match-p (format-spec format)
+  (when (or (eql format-spec (getf format :format))
+            (member format-spec (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. 
 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))
-
-       ))
+     (getf (find-format sensor-spec) :pixels))
     (number
      (sensor-dimensions-megapixels format sensor-spec))))
 
+(defun imager-dimensions (format-spec)
+  "Returns the imager dimensions in mm of a FORMAT."
+  (getf (find-format format-spec) :imager))
 
-(defun format-dimensions (format)
-  "Returns format dimensions in mm."
-  (ecase format
-    (:aps-c (cons 22.7 15.1))
-    ((:aps :dx :24x16mm) (cons 24 16))
-    ((:35mm :36x24mm) (cons 36 24))
-    (:6x4.5cm (cons 60 45))
-    ((:6x6 :6x6cm) (cons 60 60))
-    ((:6x7 :6x7cm) (cons 60 70))
-    ((:6x9 :6x9cm) (cons 60 90))
-    ((:4x5 :4x5in) (cons (* 4 +inches->mm+) (* 5 +inches->mm+)))
-    ((:5x7 :5x7in) (cons (* 5 +inches->mm+) (* 7 +inches->mm+)))
-    ((:8x10 :8x10in) (cons (* 8 +inches->mm+) (* 10 +inches->mm+))) 
-    (:11x13.75in (cons (* 11 +inches->mm+) (* 13.75 +inches->mm+)))
-    (:11x16.5in (cons (* 11 +inches->mm+) (* 16.5 +inches->mm+)))
-    (:13x19in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
-    (:16x20in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
-    (:16x24in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
-    (:18x22.5in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
-    (:18x24in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
-    (:24x30in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
-    (:24x36in (cons (* 13 +inches->mm+) (* 19 +inches->mm+)))
-    ))
+(defun output-dimensions (format-spec)
+  "Returns the output dimensions in mm of a FORMAT."
+  (getf (find-format format-spec) :output))