From 2f860697b8d97369128e749b665673594d97e324 Mon Sep 17 00:00:00 2001 From: karri Date: Mon, 17 Dec 2012 17:48:56 +0000 Subject: [PATCH] Optimize low color packed sprites git-svn-id: svn://svn.cc65.org/cc65/trunk@5951 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/sp65/lynxsprite.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) 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; -- 2.39.5