From: karri Date: Mon, 17 Dec 2012 17:48:56 +0000 (+0000) Subject: Optimize low color packed sprites X-Git-Tag: V2.14~123 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2f860697b8d97369128e749b665673594d97e324;p=cc65 Optimize low color packed sprites git-svn-id: svn://svn.cc65.org/cc65/trunk@5951 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/sp65/lynxsprite.c b/src/sp65/lynxsprite.c index adce53fca..99d7a1bc1 100644 --- a/src/sp65/lynxsprite.c +++ b/src/sp65/lynxsprite.c @@ -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;