void Screen::scaleImageGood(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backBuf, int16 bbXPos, int16 bbYPos) { for (int y = 0; y < dstHeight; y++) { for (int x = 0; x < dstWidth; x++) { uint8 c1, c2, c3, c4; uint32 xPos = (x * srcWidth) / dstWidth; uint32 yPos = (y * srcHeight) / dstHeight; uint32 xFrac = dstWidth - (x * srcWidth) % dstWidth; uint32 yFrac = dstHeight - (y * srcHeight) % dstHeight; byte *srcPtr = src + yPos * srcPitch + xPos; bool transparent = true; if (*srcPtr) { c1 = *srcPtr; transparent = false; } else { if (bbXPos + x >= 0 && bbXPos + x < RENDERWIDE && bbYPos + y >= MENUDEEP && bbYPos + y < MENUDEEP + RENDERDEEP) { c1 = *(backBuf + _screenWide * (bbYPos + y) + bbXPos + x); } else { c1 = 0; } } if (x < dstWidth - 1) { if (*(srcPtr + 1)) { c2 = *(srcPtr + 1); transparent = false; } else { if (bbXPos + x + 1 >= 0 && bbXPos + x + 1 < RENDERWIDE && bbYPos + y >= MENUDEEP && bbYPos + y + 1 < MENUDEEP + RENDERDEEP) { c2 = *(backBuf + _screenWide * (bbYPos + y) + bbXPos + x + 1); } else { c2 = c1; } } } else { c2 = c1; } if (y < dstHeight - 1) { if (*(srcPtr + srcPitch)) { c3 = *(srcPtr + srcPitch); transparent = false; } else { if (bbXPos + x >= 0 && bbXPos + x < RENDERWIDE && bbYPos + y + 1 >= MENUDEEP && bbYPos + y + 1 < MENUDEEP + RENDERDEEP) { c3 = *(backBuf + _screenWide * (bbYPos + y + 1) + bbXPos); } else { c3 = c1; } } } else { c3 = c1; } if (x < dstWidth - 1 && y < dstHeight - 1) { if (*(srcPtr + srcPitch + 1)) { c4 = *(srcPtr + srcPitch + 1); transparent = false; } else { if (bbXPos + x + 1 >= 0 && bbXPos + x + 1 < RENDERWIDE && bbYPos + y + 1 >= MENUDEEP && bbYPos + y + 1 < MENUDEEP + RENDERDEEP) { c4 = *(backBuf + _screenWide * (bbYPos + y + 1) + bbXPos + x + 1); } else { c4 = c3; } } } else { c4 = c3; } if (!transparent) { uint32 r1 = _palette[c1 * 3 + 0]; uint32 g1 = _palette[c1 * 3 + 1]; uint32 b1 = _palette[c1 * 3 + 2]; uint32 r2 = _palette[c2 * 3 + 0]; uint32 g2 = _palette[c2 * 3 + 1]; uint32 b2 = _palette[c2 * 3 + 2]; uint32 r3 = _palette[c3 * 3 + 0]; uint32 g3 = _palette[c3 * 3 + 1]; uint32 b3 = _palette[c3 * 3 + 2]; uint32 r4 = _palette[c4 * 3 + 0]; uint32 g4 = _palette[c4 * 3 + 1]; uint32 b4 = _palette[c4 * 3 + 2]; uint32 r5 = (r1 * xFrac + r2 * (dstWidth - xFrac)) / dstWidth; uint32 g5 = (g1 * xFrac + g2 * (dstWidth - xFrac)) / dstWidth; uint32 b5 = (b1 * xFrac + b2 * (dstWidth - xFrac)) / dstWidth; uint32 r6 = (r3 * xFrac + r4 * (dstWidth - xFrac)) / dstWidth; uint32 g6 = (g3 * xFrac + g4 * (dstWidth - xFrac)) / dstWidth; uint32 b6 = (b3 * xFrac + b4 * (dstWidth - xFrac)) / dstWidth; uint32 r = (r5 * yFrac + r6 * (dstHeight - yFrac)) / dstHeight; uint32 g = (g5 * yFrac + g6 * (dstHeight - yFrac)) / dstHeight; uint32 b = (b5 * yFrac + b6 * (dstHeight - yFrac)) / dstHeight; dst[y * dstWidth + x] = quickMatch(r, g, b); } else dst[y * dstWidth + x] = 0; } } }
void Screen::scaleImageGood(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 dstHeight, byte *src, uint16 srcPitch, uint16 srcWidth, uint16 srcHeight, byte *backbuf) { for (int y = 0; y < dstHeight; y++) { for (int x = 0; x < dstWidth; x++) { uint8 c1, c2, c3, c4; uint32 xPos = (x * srcWidth) / dstWidth; uint32 yPos = (y * srcHeight) / dstHeight; uint32 xFrac = dstWidth - (x * srcWidth) % dstWidth; uint32 yFrac = dstHeight - (y * srcHeight) % dstHeight; byte *srcPtr = src + yPos * srcPitch + xPos; byte *backPtr = backbuf + y * _screenWide + x; bool transparent = true; if (*srcPtr) { c1 = *srcPtr; transparent = false; } else c1 = *backPtr; if (x < dstWidth - 1) { if (*(srcPtr + 1)) { c2 = *(srcPtr + 1); transparent = false; } else c2 = *(backPtr + 1); } else c2 = c1; if (y < dstHeight - 1) { if (*(srcPtr + srcPitch)) { c3 = *(srcPtr + srcPitch); transparent = false; } else c3 = *(backPtr + _screenWide); } else c3 = c1; if (x < dstWidth - 1 && y < dstHeight - 1) { if (*(srcPtr + srcPitch + 1)) { c4 = *(srcPtr + srcPitch + 1); transparent = false; } else c4 = *(backPtr + _screenWide + 1); } else c4 = c3; if (!transparent) { uint32 r1 = _palette[c1 * 4 + 0]; uint32 g1 = _palette[c1 * 4 + 1]; uint32 b1 = _palette[c1 * 4 + 2]; uint32 r2 = _palette[c2 * 4 + 0]; uint32 g2 = _palette[c2 * 4 + 1]; uint32 b2 = _palette[c2 * 4 + 2]; uint32 r3 = _palette[c3 * 4 + 0]; uint32 g3 = _palette[c3 * 4 + 1]; uint32 b3 = _palette[c3 * 4 + 2]; uint32 r4 = _palette[c4 * 4 + 0]; uint32 g4 = _palette[c4 * 4 + 1]; uint32 b4 = _palette[c4 * 4 + 2]; uint32 r5 = (r1 * xFrac + r2 * (dstWidth - xFrac)) / dstWidth; uint32 g5 = (g1 * xFrac + g2 * (dstWidth - xFrac)) / dstWidth; uint32 b5 = (b1 * xFrac + b2 * (dstWidth - xFrac)) / dstWidth; uint32 r6 = (r3 * xFrac + r4 * (dstWidth - xFrac)) / dstWidth; uint32 g6 = (g3 * xFrac + g4 * (dstWidth - xFrac)) / dstWidth; uint32 b6 = (b3 * xFrac + b4 * (dstWidth - xFrac)) / dstWidth; uint32 r = (r5 * yFrac + r6 * (dstHeight - yFrac)) / dstHeight; uint32 g = (g5 * yFrac + g6 * (dstHeight - yFrac)) / dstHeight; uint32 b = (b5 * yFrac + b6 * (dstHeight - yFrac)) / dstHeight; dst[y * dstWidth + x] = quickMatch(r, g, b); } else dst[y * dstWidth + x] = 0; } } }