Code for the first scaler:
#define SX 256
#define SY 224
#define DX 320
#define DY 240
#define P(X) (palettetranslate[X])
#define COLORMIX16(A,B,C,D) (((P(A) >> 2) & 0x39E7) + ((P(B) >> 2) & 0x39E7) + ((P(C) >> 2) & 0x39E7) + ((P(D) >> 2) & 0x39E7))
void upscale_320x240(uint32 *dst, uint8 *src)
{
uint16 *buffer = (uint16 *) alloca(sizeof(uint16) * SX * SY * 2 * 2), *buf;
uint16 *dest = (uint16 *) dst;
uint8 *src_old;
int mix = 0;
int x,y;
int dx, dy;
int sx, sy;
uint16 color, a, b, c, d;
// Scale2x 256x224 -> 512x448
buf = buffer;
for (x = 0; x < SX; x++) {
color = P(*src++);
buf[0] = color;
buf[1] = color;
buf[SX*2] = color;
buf[SX*2+1] = color;
buf+=2;
}
for (y = 1; y < SY - 1; y++) {
color = P(*src++);
buf[0] = color;
buf[1] = color;
buf[SX*2] = color;
buf[SX*2+1] = color;
buf+=2;
for (x = 1; x < SX - 1; x++) {
a = P(src[-SX]); b = P(src[1]); c = P(src[-1]); d = P(src[SX]);
color = P(*src++);
buf[0] = (c == a && c != d && a != b) ? a : color;
buf[1] = (a == b && a != c && b != d) ? b : color;
buf[SX*2] = (d == c && d != b && c != a) ? c : color;
buf[SX*2+1] = (b == d && b != a && d != c) ? d : color;
buf+=2;
}
color = P(*src++);
buf[0] = color;
buf[1] = color;
buf[SX*2] = color;
buf[SX*2+1] = color;
buf+=(2+SX*2);
}
for (x = 0; x < SX; x++) {
color = P(*src++);
buf[0] = color;
buf[1] = color;
buf[SX*2] = color;
buf[SX*2+1] = color;
buf+=2;
}
//Downscale to 320x240
dy = 0;
for(y = 0; y < DY; y++) {
dx = 0;
dy += (SY*2-1);
buf = buffer;
for(x = 0; x < DX; x++) {
color = COLORMIX16(buffer[0], buffer[1], buffer[SX*2], buffer[SX*2+1]);
*dest++ = color | ((color>>3) & 0x1803) | ((color>>4) & 0x60);
dx += (SX*2-1);
while (dx >= DX) {
dx -= DX;
buffer++;
}
}
buffer = buf;
while (dy >= DY) {
dy -= DY;
buffer += (SX*2);
}
}
}
Second scaler:
#define SX 256
#define SY 224
#define DX 320
#define DY 240
#define P(X) (palettetranslate[X])
void upscale_320x240(uint32 *dst, uint8 *src)
{
uint16 *dest = (uint16 *) dst, a, b, c;
uint8 *src_old;
int x,y;
int dy;
dy = 0;
src -= 8*SX;
for(y = 0; y < DY; y++) {
dy += SY;
src_old = src;
src += 8;
for(x = 0; x < (SX-16)/3; x++) {
a = P(*src++); b = P(*src++); c = P(*src++);
*dest++ = a;
*dest++ = (a & 0xf800) | (b & 0x07ff);
*dest++ = (b & 0xffe0) | (c & 0x001f);
*dest++ = c;
}
src += 8;
}
}