From 130cfded751571069d16caff42baa709146ee501 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 5 Mar 2008 17:38:12 +0000 Subject: Implement inventory scrolling for HoF. svn-id: r31043 --- engines/kyra/screen_v2.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) (limited to 'engines/kyra/screen_v2.cpp') diff --git a/engines/kyra/screen_v2.cpp b/engines/kyra/screen_v2.cpp index 2bec373266..ab46dce6f3 100644 --- a/engines/kyra/screen_v2.cpp +++ b/engines/kyra/screen_v2.cpp @@ -84,12 +84,81 @@ void Screen_v2::generateGrayOverlay(const uint8 *srcPal, uint8 *grayOverlay, int grayOverlay[i] = findLeastDifferentColor(tmpPal + 3 * i, srcPal, lastColor); } -void Screen_v2::applyGrayOverlay(int x, int y, int w, int h, int pageNum, const uint8 *grayOverlay) { +uint8 *Screen_v2::generateOverlay(const uint8 *palette, uint8 *buffer, int startColor, int fac) { + if (!palette || !buffer) + return buffer; + + fac = MIN(0xFF, fac); + + byte col1, col2, col3; + col1 = palette[startColor * 3 + 0]; + col2 = palette[startColor * 3 + 1]; + col3 = palette[startColor * 3 + 2]; + *buffer = 0; + + uint8 *dst = buffer + 1; + for (int i = 1; i != 255; ++i) { + byte procCol1, procCol2, procCol3; + const uint8 *src = palette + i*3; + const int factor = (fac >> 1) & 0xFF; + byte col; + + col = *src++; + col -= ((((col - col1) * factor) << 1) >> 8) & 0xFF; + procCol1 = col; + + col = *src++; + col -= ((((col - col2) * factor) << 1) >> 8) & 0xFF; + procCol2 = col; + + col = *src++; + col -= ((((col - col3) * factor) << 1) >> 8) & 0xFF; + procCol3 = col; + + uint16 minValue = 0xFFFF; + uint8 colorNumber = startColor; + const uint8 *pal = palette + 3; + for (int count = 0xFF, cur = 1; count > 0; --count, ++cur) { + pal += 3; + if (cur != i) { + uint16 value = 0; + pal -= 3; + col = *pal++ - procCol1; + col *= col; + value += col; + + col = *pal++ - procCol2; + col *= col; + value += col; + + col = *pal++ - procCol3; + col *= col; + value += col; + + if (value == 0) { + colorNumber = i; + break; + } else if (value < minValue) { + minValue = value; + colorNumber = cur; + } + } + } + + *dst++ = colorNumber; + } + + return buffer; +} + +void Screen_v2::applyOverlay(int x, int y, int w, int h, int pageNum, const uint8 *overlay) { uint8 * dst = getPagePtr(pageNum) + y * 320 + x; while (h--) { - for (int wi = 0; wi < 320; wi++) - dst[wi] = grayOverlay[dst[wi]]; - dst += 320; + for (int wi = 0; wi < w; ++wi) { + uint8 index = *dst; + *dst++ = overlay[index]; + } + dst += 320 - w; } } -- cgit v1.2.3