]> git.sur5r.net Git - cc65/commitdiff
Optimize low color packed sprites
authorkarri <karri@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 17 Dec 2012 17:48:56 +0000 (17:48 +0000)
committerkarri <karri@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 17 Dec 2012 17:48:56 +0000 (17:48 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5951 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/sp65/lynxsprite.c

index adce53fcac5183b5004947bf6f8e840694996605..99d7a1bc1ecaf9a85153e892f4060ece4aa931b7 100644 (file)
@@ -189,7 +189,7 @@ static void AssembleByte(unsigned bits, char val)
     } while (--bits);
 }
 
-static unsigned char ChoosePackagingMode(signed len, signed index, char LineBuffer[512])
+static unsigned char ChoosePackagingMode(signed len, signed index, char ColorBits, char LineBuffer[512])
 {
     --len;
     if (!len) {
@@ -198,6 +198,18 @@ static unsigned char ChoosePackagingMode(signed len, signed index, char LineBuff
     if (LineBuffer[index] != LineBuffer[index + 1]) {
         return 0;
     }
+    if (ColorBits > 2) {
+        return 1;
+    }
+    if (LineBuffer[index] != LineBuffer[index + 2]) {
+        return 0;
+    }
+    if (ColorBits > 1) {
+        return 1;
+    }
+    if (LineBuffer[index] != LineBuffer[index + 3]) {
+        return 0;
+    }
     return 1;
 }
 
@@ -260,7 +272,7 @@ static void encodeSprite(StrBuf *D, enum Mode M, char ColorBits, char ColorMask,
     case smPacked:
         i = 0;
         while (len) {
-            if (ChoosePackagingMode(len, i, LineBuffer)) {
+            if (ChoosePackagingMode(len, i, ColorBits, LineBuffer)) {
                 /* Make runlength packet */
                 V = LineBuffer[i];
                 ++i;
@@ -282,7 +294,7 @@ static void encodeSprite(StrBuf *D, enum Mode M, char ColorBits, char ColorMask,
                 *d_ptr++ = V;
                 --len;
                 count = 0;
-                while (ChoosePackagingMode(len, i, LineBuffer) == 0 && len && count != 15) {
+                while (ChoosePackagingMode(len, i, ColorBits, LineBuffer) == 0 && len && count != 15) {
                     V = LineBuffer[i++];
                     *d_ptr++ = V;
                     ++count;
@@ -309,7 +321,7 @@ static void encodeSprite(StrBuf *D, enum Mode M, char ColorBits, char ColorMask,
             }
             i = 0;
             while (len) {
-                if (ChoosePackagingMode(len, i, LineBuffer)) {
+                if (ChoosePackagingMode(len, i, ColorBits, LineBuffer)) {
                     /* Make runlength packet */
                     V = LineBuffer[i];
                     ++i;
@@ -331,7 +343,7 @@ static void encodeSprite(StrBuf *D, enum Mode M, char ColorBits, char ColorMask,
                     *d_ptr++ = V;
                     --len;
                     count = 0;
-                    while (ChoosePackagingMode(len, i, LineBuffer) == 0 && len && count != 15) {
+                    while (ChoosePackagingMode(len, i, ColorBits, LineBuffer) == 0 && len && count != 15) {
                         V = LineBuffer[i++];
                         *d_ptr++ = V;
                         ++count;