changeset 495:1d81ddd4fa41

merged changes from trip to wichita.
author Robert McIntyre <rlm@mit.edu>
date Mon, 11 Jun 2012 00:55:51 -0500
parents 151c96d60921 (diff) 79606f173658 (current diff)
children a6d060a64246
files clojure/com/aurellem/run/image.clj
diffstat 2 files changed, 15 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/gb_driver.clj	Thu Jun 07 23:11:18 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/gb_driver.clj	Mon Jun 11 00:55:51 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	Thu Jun 07 23:11:18 2012 -0500
     2.2 +++ b/clojure/com/aurellem/run/image.clj	Mon Jun 11 00:55:51 2012 -0500
     2.3 @@ -17,82 +17,34 @@
     2.4  ;; use background tiles?  they provide greater color depth than
     2.5  ;; sprites, and can still be scrolled, so why not? 
     2.6  
     2.7 +;; could also use sprites to get 3 more colors per tile for a total of
     2.8 +;; 7 colors per tile, although not for all tiles...
     2.9  
    2.10 -;; First of all, RGB colors in an image are not the same as those in a
    2.11 -;; GameBoy, so I need to convert them.  Fortunately, this code is
    2.12 -;; already written for me in this C-code from the public domain
    2.13 -;; hi-color converter by Glen Cook, Jeff Frohwein, and Rob Jones.
    2.14  
    2.15 -;; the code snipped itself is by Brett Bibby and is translated here
    2.16 -;; from C into clojure.
    2.17  
    2.18 +;; want a function to
    2.19  
    2.20 -;; This section of code is used to convert an RGB (pc) triplet into
    2.21 -;; a RGB (gameboy) triplet. This section of code was kindly donated
    2.22 -;; by Brett Bibby (GameBrains).
    2.23 +;; 1. read an image
    2.24 +;; 2. split into a grid of 8x8 pixels
    2.25 +;; 3. convert all RGB colors to gb-RGB colors
    2.26 +;; 4. determine efficient color palletes for the image
    2.27 +;; 5. output efficient assembly code to draw the image to the gb
    2.28 +;; screen.
    2.29  
    2.30 -;; BYTE intensity[32] = {
    2.31 -;;   0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x5e, 0x6c, 0x7a, 0x88, 0x94,
    2.32 -;;   0xa0, 0xae, 0xb7, 0xbf, 0xc6, 0xce, 0xd3, 0xd9, 0xdf, 0xe3, 0xe7,
    2.33 -;;   0xeb, 0xef, 0xf3, 0xf6, 0xf9, 0xfb, 0xfd, 0xfe, 0xff, 0xff };
    2.34  
    2.35 -;; unsigned char influence[3][3] = 
    2.36 -;;   {
    2.37 -;;     {16,4,4},
    2.38 -;;     {8,16,8},
    2.39 -;;     {0,8,16}
    2.40 -;;   };
    2.41  
    2.42 -;; RGBQUAD translate(BYTE rgb[3])
    2.43 -;; {
    2.44 -;;   RGBQUAD color;
    2.45 -;;   BYTE	tmp[3];
    2.46 -;;   BYTE	m[3][3];
    2.47 -;;   BYTE	i,j;
    2.48  
    2.49 -;;   for (i=0;i<3;i++)
    2.50 -;;     for (j=0;j<3;j++)
    2.51 -;;       m[i][j] = (intensity[rgb[i]>>3]*influence[i][j]) >> 5;
    2.52  
    2.53 -;;   for (i=0;i<3;i++)
    2.54 -;;     {
    2.55 -;;       if (m[0][i]>m[1][i])
    2.56 -;; 	{
    2.57 -;; 	  j=m[0][i]; 
    2.58 -;; 	  m[0][i]=m[1][i]; 
    2.59 -;; 	  m[1][i]=j;
    2.60 -;; 	}
    2.61  
    2.62 -;;       if (m[1][i]>m[2][i])
    2.63 -;; 	{
    2.64 -;; 	  j=m[1][i]; 
    2.65 -;; 	  m[1][i]=m[2][i]; 
    2.66 -;; 	  m[2][i]=j;
    2.67 -;; 	}
    2.68  
    2.69 -;;       if (m[0][i]>m[1][i])
    2.70 -;; 	{
    2.71 -;; 	  j=m[0][i]; 
    2.72 -;; 	  m[0][i]=m[1][i]; 
    2.73 -;; 	  m[1][i]=j;
    2.74 -;; 	}
    2.75  
    2.76 -;;       tmp[i]=(((m[0][i]+m[1][i]*2+m[2][i]*4)*5) >> 4)+32;
    2.77 -;;     }
    2.78  
    2.79 -;;   color.rgbRed	= tmp[0];
    2.80 -;;   color.rgbGreen	= tmp[1];
    2.81 -;;   color.rgbBlue	= tmp[2];
    2.82  
    2.83 -;;   return color;
    2.84 -;; }
    2.85  
    2.86  
    2.87 -                  
    2.88  
    2.89  (def image-program-target 0xB000)
    2.90  
    2.91 -
    2.92  (def display-width 160)
    2.93  (def display-height 144)
    2.94  
    2.95 @@ -199,3 +151,4 @@
    2.96  
    2.97      ))
    2.98  
    2.99 +