diff clojure/com/aurellem/run/image.clj @ 489:641e1c511224

cleanup.
author Robert McIntyre <rlm@mit.edu>
date Mon, 07 May 2012 12:37:04 -0500
parents 09b3bc0b71b5
children 151c96d60921
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/image.clj	Mon May 07 12:31:16 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/image.clj	Mon May 07 12:37:04 2012 -0500
     1.3 @@ -18,94 +18,3 @@
     1.4  ;; sprites, and can still be scrolled, so why not? 
     1.5  
     1.6  
     1.7 -;; First of all, RGB colors in an image are not the same as those in a
     1.8 -;; GameBoy, so I need to convert them.  Fortunately, this code is
     1.9 -;; already written for me in this C-code from the public domain
    1.10 -;; hi-color converter by Glen Cook, Jeff Frohwein, and Rob Jones.
    1.11 -
    1.12 -;; the code snipped itself is by Brett Bibby and is translated here
    1.13 -;; from C into clojure.
    1.14 -
    1.15 -
    1.16 -;; This section of code is used to convert an RGB (pc) triplet into
    1.17 -;; a RGB (gameboy) triplet. This section of code was kindly donated
    1.18 -;; by Brett Bibby (GameBrains).
    1.19 -
    1.20 -;; BYTE intensity[32] = {
    1.21 -;;   0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
    1.22 -;;   0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
    1.23 -;;   0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
    1.24 -
    1.25 -;; unsigned char influence[3][3] = 
    1.26 -;;   {
    1.27 -;;     {16,4,4},
    1.28 -;;     {8,16,8},
    1.29 -;;     {0,8,16}
    1.30 -;;   };
    1.31 -
    1.32 -;; RGBQUAD translate(BYTE rgb[3])
    1.33 -;; {
    1.34 -;;   RGBQUAD color;
    1.35 -;;   BYTE	tmp[3];
    1.36 -;;   BYTE	m[3][3];
    1.37 -;;   BYTE	i,j;
    1.38 -
    1.39 -;;   for (i=0;i<3;i++)
    1.40 -;;     for (j=0;j<3;j++)
    1.41 -;;       m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;
    1.42 -
    1.43 -;;   for (i=0;i<3;i++)
    1.44 -;;     {
    1.45 -;;       if (m[0][i]>m[1][i])
    1.46 -;; 	{
    1.47 -;; 	  j=m[0][i]; 
    1.48 -;; 	  m[0][i]=m[1][i]; 
    1.49 -;; 	  m[1][i]=j;
    1.50 -;; 	}
    1.51 -
    1.52 -;;       if (m[1][i]>m[2][i])
    1.53 -;; 	{
    1.54 -;; 	  j=m[1][i]; 
    1.55 -;; 	  m[1][i]=m[2][i]; 
    1.56 -;; 	  m[2][i]=j;
    1.57 -;; 	}
    1.58 -
    1.59 -;;       if (m[0][i]>m[1][i])
    1.60 -;; 	{
    1.61 -;; 	  j=m[0][i]; 
    1.62 -;; 	  m[0][i]=m[1][i]; 
    1.63 -;; 	  m[1][i]=j;
    1.64 -;; 	}
    1.65 -
    1.66 -;;       tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
    1.67 -;;     }
    1.68 -
    1.69 -;;   color.rgbRed	= tmp[0];
    1.70 -;;   color.rgbGreen	= tmp[1];
    1.71 -;;   color.rgbBlue	= tmp[2];
    1.72 -
    1.73 -;;   return color;
    1.74 -;; }
    1.75 -
    1.76 -
    1.77 -(def intensity
    1.78 -  [0x00 0x10 0x20 0x30 0x40 0x50 0x5e 0x6c 0x7a 0x88 0x94
    1.79 -   0xa0 0xae 0xb7 0xbf 0xc6 0xce 0xd3 0xd9 0xdf 0xe3 0xe7
    1.80 -   0xeb 0xef 0xf3 0xf6 0xf9 0xfb 0xfd 0xfe 0xff 0xff])
    1.81 -
    1.82 -(def influence
    1.83 -  [[16 4 4]
    1.84 -   [8 16 8]
    1.85 -   [0 8 16]])
    1.86 -
    1.87 -(defn rgb->gb-rb [[r g b]]
    1.88 -  (let [color-matrix
    1.89 -        (map
    1.90 -         (fn [color-row]
    1.91 -           (map
    1.92 -            (fn [color]
    1.93 -              (bit-shift-right
    1.94 -               (* (intensity (bit-shift-right r 3))
    1.95 -                  color) 5)))))]))
    1.96 -                  
    1.97 -        
    1.98 \ No newline at end of file