-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale2x.h
83 lines (64 loc) · 2.45 KB
/
scale2x.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
This file should be included in a C source, and it will create the following functions:
Outside interface:
static void scale2x(SDL_Surface* srcsurface, SDL_Surface* destsurface, int x, int y);
Internal functions:
static void scale2x_row_8bit(Uint8* dest0, Uint8* dest1, Uint8* src0, Uint8* src1, Uint8* src2, int srcw);
static void scale2x_row_16bit(Uint16* dest0, Uint16* dest1, Uint16* src0, Uint16* src1, Uint16* src2, int srcw);
static void scale2x_row_24bit(Uint8* dest0, Uint8* dest1, Uint8* src0, Uint8* src1, Uint8* src2, int srcw);
static void scale2x_row_32bit(Uint32* dest0, Uint32* dest1, Uint32* src0, Uint32* src1, Uint32* src2, int srcw);
static void scale2x_8bit(SDL_Surface* src, SDL_Surface* dest, int x, int y);
static void scale2x_16bit(SDL_Surface* src, SDL_Surface* dest, int x, int y);
static void scale2x_24bit(SDL_Surface* src, SDL_Surface* dest, int x, int y);
static void scale2x_32bit(SDL_Surface* src, SDL_Surface* dest, int x, int y);
File dependencies:
scale2xrowfunc.h
scale2xrowfunc_24bit.h
scale2xrows.h
*/
#define PIXEL Uint8
#define SCALE2XROWFUNC scale2x_row_8bit
#define SCALE2XFUNC scale2x_8bit
#include "scale2xrowfunc.h"
#undef PIXEL
#undef SCALE2XROWFUNC
#undef SCALE2XFUNC
#define PIXEL Uint16
#define SCALE2XROWFUNC scale2x_row_16bit
#define SCALE2XFUNC scale2x_16bit
#include "scale2xrowfunc.h"
#undef PIXEL
#undef SCALE2XROWFUNC
#undef SCALE2XFUNC
#define PIXEL Uint32
#define SCALE2XROWFUNC scale2x_row_32bit
#define SCALE2XFUNC scale2x_32bit
#include "scale2xrowfunc.h"
#undef PIXEL
#undef SCALE2XROWFUNC
#undef SCALE2XFUNC
#include "scale2xrowfunc_24bit.h"
static void scale2x(SDL_Surface* srcsurface, SDL_Surface* destsurface, int x, int y)
{
/* lock surfaces to ensure access to pixels */
SDL_LockSurface(srcsurface);
SDL_LockSurface(destsurface);
/* choose the right function for this depth */
switch (srcsurface->format->BytesPerPixel) {
case 1:
scale2x_8bit(srcsurface, destsurface, x, y);
break;
case 2:
scale2x_16bit(srcsurface, destsurface, x, y);
break;
case 3:
/* We need to pass 3*x because the pointer type is Uint8*. */
scale2x_24bit(srcsurface, destsurface, 3*x, y);
break;
case 4:
scale2x_32bit(srcsurface, destsurface, x, y);
break;
}
SDL_UnlockSurface(srcsurface);
SDL_UnlockSurface(destsurface);
}