changeset 489:641e1c511224

cleanup.
author Robert McIntyre <rlm@mit.edu>
date Mon, 07 May 2012 12:37:04 -0500
parents 09b3bc0b71b5
children 151c96d60921
files clojure/com/aurellem/gb/gb_driver.clj clojure/com/aurellem/run/image.clj
diffstat 2 files changed, 5 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/gb_driver.clj	Mon May 07 12:31:16 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/gb_driver.clj	Mon May 07 12:37:04 2012 -0500
     1.3 @@ -271,6 +271,11 @@
     1.4  
     1.5  (def original-rom (rom (root)))
     1.6  
     1.7 +
     1.8 +;; RGB colors in an image are not the same as those in a GameBoy, so I
     1.9 +;; need to convert them.  Fortunately, this code is already written
    1.10 +;; for me in this C-code from the public domain hi-color converter by
    1.11 +;; Glen Cook, Jeff Frohwein, and Rob Jones.
    1.12  (defn rgb->gb-rb [[r g b :as color]]
    1.13    (let [store (int-array 3)]
    1.14      (Gb/translateRGB (int-array color) store)
     2.1 --- a/clojure/com/aurellem/run/image.clj	Mon May 07 12:31:16 2012 -0500
     2.2 +++ b/clojure/com/aurellem/run/image.clj	Mon May 07 12:37:04 2012 -0500
     2.3 @@ -18,94 +18,3 @@
     2.4  ;; sprites, and can still be scrolled, so why not? 
     2.5  
     2.6  
     2.7 -;; First of all, RGB colors in an image are not the same as those in a
     2.8 -;; GameBoy, so I need to convert them.  Fortunately, this code is
     2.9 -;; already written for me in this C-code from the public domain
    2.10 -;; hi-color converter by Glen Cook, Jeff Frohwein, and Rob Jones.
    2.11 -
    2.12 -;; the code snipped itself is by Brett Bibby and is translated here
    2.13 -;; from C into clojure.
    2.14 -
    2.15 -
    2.16 -;; This section of code is used to convert an RGB (pc) triplet into
    2.17 -;; a RGB (gameboy) triplet. This section of code was kindly donated
    2.18 -;; by Brett Bibby (GameBrains).
    2.19 -
    2.20 -;; BYTE intensity[32] = {
    2.21 -;;   0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
    2.22 -;;   0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
    2.23 -;;   0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
    2.24 -
    2.25 -;; unsigned char influence[3][3] = 
    2.26 -;;   {
    2.27 -;;     {16,4,4},
    2.28 -;;     {8,16,8},
    2.29 -;;     {0,8,16}
    2.30 -;;   };
    2.31 -
    2.32 -;; RGBQUAD translate(BYTE rgb[3])
    2.33 -;; {
    2.34 -;;   RGBQUAD color;
    2.35 -;;   BYTE	tmp[3];
    2.36 -;;   BYTE	m[3][3];
    2.37 -;;   BYTE	i,j;
    2.38 -
    2.39 -;;   for (i=0;i<3;i++)
    2.40 -;;     for (j=0;j<3;j++)
    2.41 -;;       m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;
    2.42 -
    2.43 -;;   for (i=0;i<3;i++)
    2.44 -;;     {
    2.45 -;;       if (m[0][i]>m[1][i])
    2.46 -;; 	{
    2.47 -;; 	  j=m[0][i]; 
    2.48 -;; 	  m[0][i]=m[1][i]; 
    2.49 -;; 	  m[1][i]=j;
    2.50 -;; 	}
    2.51 -
    2.52 -;;       if (m[1][i]>m[2][i])
    2.53 -;; 	{
    2.54 -;; 	  j=m[1][i]; 
    2.55 -;; 	  m[1][i]=m[2][i]; 
    2.56 -;; 	  m[2][i]=j;
    2.57 -;; 	}
    2.58 -
    2.59 -;;       if (m[0][i]>m[1][i])
    2.60 -;; 	{
    2.61 -;; 	  j=m[0][i]; 
    2.62 -;; 	  m[0][i]=m[1][i]; 
    2.63 -;; 	  m[1][i]=j;
    2.64 -;; 	}
    2.65 -
    2.66 -;;       tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
    2.67 -;;     }
    2.68 -
    2.69 -;;   color.rgbRed	= tmp[0];
    2.70 -;;   color.rgbGreen	= tmp[1];
    2.71 -;;   color.rgbBlue	= tmp[2];
    2.72 -
    2.73 -;;   return color;
    2.74 -;; }
    2.75 -
    2.76 -
    2.77 -(def intensity
    2.78 -  [0x00 0x10 0x20 0x30 0x40 0x50 0x5e 0x6c 0x7a 0x88 0x94
    2.79 -   0xa0 0xae 0xb7 0xbf 0xc6 0xce 0xd3 0xd9 0xdf 0xe3 0xe7
    2.80 -   0xeb 0xef 0xf3 0xf6 0xf9 0xfb 0xfd 0xfe 0xff 0xff])
    2.81 -
    2.82 -(def influence
    2.83 -  [[16 4 4]
    2.84 -   [8 16 8]
    2.85 -   [0 8 16]])
    2.86 -
    2.87 -(defn rgb->gb-rb [[r g b]]
    2.88 -  (let [color-matrix
    2.89 -        (map
    2.90 -         (fn [color-row]
    2.91 -           (map
    2.92 -            (fn [color]
    2.93 -              (bit-shift-right
    2.94 -               (* (intensity (bit-shift-right r 3))
    2.95 -                  color) 5)))))]))
    2.96 -                  
    2.97 -        
    2.98 \ No newline at end of file