diff clojure/com/aurellem/run/image.clj @ 488:09b3bc0b71b5

added rgb->gbRGB translation code.
author Robert McIntyre <rlm@mit.edu>
date Mon, 07 May 2012 12:31:16 -0500
parents 3f0156038802
children 641e1c511224 2304906d443b
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/image.clj	Mon May 07 11:15:49 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/image.clj	Mon May 07 12:31:16 2012 -0500
     1.3 @@ -1,4 +1,4 @@
     1.4 -(ns com.aurellem.run.music
     1.5 +(ns com.aurellem.run.image
     1.6    (:use (com.aurellem.gb saves gb-driver util constants
     1.7                           items vbm characters money
     1.8                           rlm-assembly))
     1.9 @@ -8,10 +8,6 @@
    1.10    (:import [com.aurellem.gb.gb_driver SaveState])
    1.11    (:import java.io.File))
    1.12  
    1.13 -
    1.14 -
    1.15 -
    1.16 -
    1.17  ;; want to display an image onto the screen.
    1.18  ;; probably will be the six ponies, possibly with scrolling. 
    1.19  
    1.20 @@ -30,10 +26,86 @@
    1.21  ;; the code snipped itself is by Brett Bibby and is translated here
    1.22  ;; from C into clojure.
    1.23  
    1.24 -;; TODO include original code
    1.25  
    1.26 +;; This section of code is used to convert an RGB (pc) triplet into
    1.27 +;; a RGB (gameboy) triplet. This section of code was kindly donated
    1.28 +;; by Brett Bibby (GameBrains).
    1.29  
    1.30 -(def intensity [
    1.31 +;; BYTE intensity[32] = {
    1.32 +;;   0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
    1.33 +;;   0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
    1.34 +;;   0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
    1.35 +
    1.36 +;; unsigned char influence[3][3] = 
    1.37 +;;   {
    1.38 +;;     {16,4,4},
    1.39 +;;     {8,16,8},
    1.40 +;;     {0,8,16}
    1.41 +;;   };
    1.42 +
    1.43 +;; RGBQUAD translate(BYTE rgb[3])
    1.44 +;; {
    1.45 +;;   RGBQUAD color;
    1.46 +;;   BYTE	tmp[3];
    1.47 +;;   BYTE	m[3][3];
    1.48 +;;   BYTE	i,j;
    1.49 +
    1.50 +;;   for (i=0;i<3;i++)
    1.51 +;;     for (j=0;j<3;j++)
    1.52 +;;       m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;
    1.53 +
    1.54 +;;   for (i=0;i<3;i++)
    1.55 +;;     {
    1.56 +;;       if (m[0][i]>m[1][i])
    1.57 +;; 	{
    1.58 +;; 	  j=m[0][i]; 
    1.59 +;; 	  m[0][i]=m[1][i]; 
    1.60 +;; 	  m[1][i]=j;
    1.61 +;; 	}
    1.62 +
    1.63 +;;       if (m[1][i]>m[2][i])
    1.64 +;; 	{
    1.65 +;; 	  j=m[1][i]; 
    1.66 +;; 	  m[1][i]=m[2][i]; 
    1.67 +;; 	  m[2][i]=j;
    1.68 +;; 	}
    1.69 +
    1.70 +;;       if (m[0][i]>m[1][i])
    1.71 +;; 	{
    1.72 +;; 	  j=m[0][i]; 
    1.73 +;; 	  m[0][i]=m[1][i]; 
    1.74 +;; 	  m[1][i]=j;
    1.75 +;; 	}
    1.76 +
    1.77 +;;       tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
    1.78 +;;     }
    1.79 +
    1.80 +;;   color.rgbRed	= tmp[0];
    1.81 +;;   color.rgbGreen	= tmp[1];
    1.82 +;;   color.rgbBlue	= tmp[2];
    1.83 +
    1.84 +;;   return color;
    1.85 +;; }
    1.86 +
    1.87 +
    1.88 +(def intensity
    1.89 +  [0x00 0x10 0x20 0x30 0x40 0x50 0x5e 0x6c 0x7a 0x88 0x94
    1.90 +   0xa0 0xae 0xb7 0xbf 0xc6 0xce 0xd3 0xd9 0xdf 0xe3 0xe7
    1.91 +   0xeb 0xef 0xf3 0xf6 0xf9 0xfb 0xfd 0xfe 0xff 0xff])
    1.92 +
    1.93 +(def influence
    1.94 +  [[16 4 4]
    1.95 +   [8 16 8]
    1.96 +   [0 8 16]])
    1.97  
    1.98  (defn rgb->gb-rb [[r g b]]
    1.99 -  
   1.100 \ No newline at end of file
   1.101 +  (let [color-matrix
   1.102 +        (map
   1.103 +         (fn [color-row]
   1.104 +           (map
   1.105 +            (fn [color]
   1.106 +              (bit-shift-right
   1.107 +               (* (intensity (bit-shift-right r 3))
   1.108 +                  color) 5)))))]))
   1.109 +                  
   1.110 +        
   1.111 \ No newline at end of file