1 /*
2 * OpenBOR - http://www.chronocrash.com
3 * -----------------------------------------------------------------------
4 * All rights reserved, see LICENSE in OpenBOR root for details.
5 *
6 * Copyright (c) 2004 - 2012 OpenBOR Team
7 */
8
9 /**
10 * Scales images by 2x while emulating scanlines. The "Scanlines" function
11 * is nearest neighbor filtering with every other line blacked out. The
12 * "ScanlinesTV" function more closely emulates the scanlines on an actual
13 * interlaced TV. Replaces the old "Scanline 2x" and "Scanline TV 2x" filters
14 * licensed under the GPL that were used in OpenBOR before October 2012.
15 */
16
17 #include <string.h>
18 #include "gfx.h"
19 #include "types.h"
20
Scanlines(u8 * srcPtr,u32 srcPitch,u8 * deltaPtr,u8 * dstPtr,u32 dstPitch,int width,int height)21 void Scanlines(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, int width, int height)
22 {
23 u16 *src;
24 u16 *dst;
25 int x, y;
26
27 for (y = 0; y < height; y++)
28 {
29 src = (u16 *)srcPtr;
30 dst = (u16 *)dstPtr;
31 for(x = 0; x < width; x++)
32 {
33 *dst++ = *src;
34 *dst++ = *src++;
35 }
36 srcPtr += srcPitch;
37 dstPtr += dstPitch;
38 memset(dstPtr, 0, dstPitch);
39 dstPtr += dstPitch;
40 }
41 }
42
Scanlines32(u8 * srcPtr,u32 srcPitch,u8 * deltaPtr,u8 * dstPtr,u32 dstPitch,int width,int height)43 void Scanlines32(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, int width, int height)
44 {
45 u32 *src;
46 u32 *dst;
47 int x, y;
48
49 for (y = 0; y < height; y++)
50 {
51 src = (u32 *)srcPtr;
52 dst = (u32 *)dstPtr;
53 for(x = 0; x < width; x++)
54 {
55 *dst++ = *src;
56 *dst++ = *src++;
57 }
58 srcPtr += srcPitch;
59 dstPtr += dstPitch;
60 memset(dstPtr, 0, dstPitch);
61 dstPtr += dstPitch;
62 }
63 }
64
ScanlinesTV(u8 * srcPtr,u32 srcPitch,u8 * deltaPtr,u8 * dstPtr,u32 dstPitch,int width,int height)65 void ScanlinesTV(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, u8 *dstPtr, u32 dstPitch, int width, int height)
66 {
67 u16 *src;
68 u32 *dstTop, *dstBottom;
69 int x, y;
70
71 for (y = 0; y < height; y++)
72 {
73 src = (u16 *)srcPtr;
74 dstTop = (u32 *)dstPtr;
75 dstBottom = (u32 *)(dstPtr + dstPitch);
76 for(x = 0; x < width; x++)
77 {
78 // look at the source pixel and the one to its right
79 u16 a = *src, b = *(++src);
80 u16 bhalf = (b & GfxColorMask) >> 1;
81 u32 result;
82 *dstTop++ = result = a | (((a & GfxColorMask) >> 1) + bhalf) << 16;
83 *dstBottom++ = ((result & GfxQColorMask) >> 2) * 3;
84 }
85 dstPtr += dstPitch << 1;
86 srcPtr += srcPitch;
87 }
88 }
89
90