Browse Source

L2 support added. Fixes #1

James Bowman 2 years ago
parent
commit
f24afdb690
6 changed files with 27 additions and 8 deletions
  1. 17 4
      gameduino2/convert.py
  2. 6 1
      gameduino2/prep.py
  3. 1 0
      gameduino2/registers.py
  4. 1 1
      scripts/gd2asset
  5. 1 1
      scripts/gd3asset
  6. 1 1
      winsetup.py

+ 17 - 4
gameduino2/convert.py

@@ -10,6 +10,7 @@ def convert(im, dither = False, fmt = ARGB1555):
     im = im.convert({
         ARGB1555 : "RGBA",
         L1 : "L",
+        L2 : "L",
         L4 : "L",
         L8 : "L",
         RGB332 : "RGB",
@@ -51,10 +52,8 @@ def convert(im, dither = False, fmt = ARGB1555):
         palstr = lut.convert("RGBA").tobytes()
         rgba = zip(*(array.array('B', palstr[i::4]) for i in range(4)))
         data = imbytes(im)
-        totalsz = 8
     elif fmt == L8:
         data = imbytes(im)
-        totalsz = 8
     elif fmt == L4:
         b0 = imbytes(im)[::2]
         b1 = imbytes(im)[1::2]
@@ -66,12 +65,26 @@ def convert(im, dither = False, fmt = ARGB1555):
             return int((15. * dc / 255))
                 
         data = array.array('B', [(16 * to15(l) + to15(r)) for (l,r) in zip(b0, b1)])
-        totalsz = 4
+    elif fmt == L2:
+        b0 = imbytes(im)[::4]
+        b1 = imbytes(im)[1::4]
+        b2 = imbytes(im)[2::4]
+        b3 = imbytes(im)[3::4]
+        def to3(c):
+            if dither:
+                dc = min(255, c + rnd.randrange(64))
+            else:
+                dc = c
+            return int((3. * dc / 255))
+                
+        data = array.array('B', [(64 * to3(a) + 16 * to3(b) + 4 * to3(c) + to3(d)) for (a,b,c,d) in zip(b0, b1, b2, b3)])
+        print data[128*64:129*64]
     elif fmt == L1:
         if dither:
             im = im.convert("1", dither=Image.FLOYDSTEINBERG)
         else:
             im = im.convert("1", dither=Image.NONE)
         data = imbytes(im)
-        totalsz = 1
+    else:
+        assert 0, "Bad format %r" % fmt
     return (im.size, data)

+ 6 - 1
gameduino2/prep.py

@@ -217,17 +217,20 @@ class AssetBin(gameduino2.base.GD2):
         self.inits.append("static const shape_t %s_SHAPE = {%d, %d, %d, %d};" % (name, self.handle, w, h, vsz))
 
         # aw is aligned width
+        # For L1, L2, L4 formats the width must be a whole number of bytes
         if fmt == gd2.L1:
             aw = (w + 7) & ~7
+        elif fmt == gd2.L2:
+            aw = (w + 3) & ~3
         elif fmt == gd2.L4:
             aw = (w + 1) & ~1
         else:
             aw = w
 
-        # print self.name, name, (filter, gd2.BORDER, gd2.BORDER, vw, vh)
         bpl = {
             gd2.ARGB1555 : 2 * aw,
             gd2.L1       : aw / 8,
+            gd2.L2       : aw / 4,
             gd2.L4       : aw / 2,
             gd2.L8       : aw,
             gd2.RGB332   : aw,
@@ -235,6 +238,8 @@ class AssetBin(gameduino2.base.GD2):
             gd2.ARGB4    : 2 * aw,
             gd2.RGB565   : 2 * aw,
             gd2.PALETTED : aw}[fmt]
+        if fmt == gd2.L2:
+            print w, aw, bpl
         self.BitmapLayout(fmt, bpl, h);
 
         for i,im in enumerate(images):

+ 1 - 0
gameduino2/registers.py

@@ -27,6 +27,7 @@ PALETTED             = 8
 TEXT8X8              = 9
 TEXTVGA              = 10
 BARGRAPH             = 11
+L2                   = 17   # FT810
 
 NEAREST              = 0
 BILINEAR             = 1

+ 1 - 1
scripts/gd2asset

@@ -37,7 +37,7 @@ class GD2Assets(gd2.prep.AssetBin):
         }
 
     def parse_format(self, format):
-        formats = ('ARGB1555', 'L1', 'L4', 'L8', 'RGB332', 'ARGB2', 'ARGB4', 'RGB565')
+        formats = ('ARGB1555', 'L1', 'L2', 'L4', 'L8', 'RGB332', 'ARGB2', 'ARGB4', 'RGB565')
         if format not in formats:
             print 'ERROR: unknown format "%s"' % format
             print

+ 1 - 1
scripts/gd3asset

@@ -37,7 +37,7 @@ class GD2Assets(gd2.prep.AssetBin):
         }
 
     def parse_format(self, format):
-        formats = ('ARGB1555', 'L1', 'L4', 'L8', 'RGB332', 'ARGB2', 'ARGB4', 'RGB565')
+        formats = ('ARGB1555', 'L1', 'L2', 'L4', 'L8', 'RGB332', 'ARGB2', 'ARGB4', 'RGB565')
         if format not in formats:
             print 'ERROR: unknown format "%s"' % format
             print

+ 1 - 1
winsetup.py

@@ -1,4 +1,4 @@
 from distutils.core import setup
 import py2exe
 
-setup(console=['scripts/gd2asset'])
+setup(console=['scripts/gd2asset', 'scripts/gd3asset'])