annotate src/dmblit.c @ 2294:7f6ba3b32f54

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Jul 2019 10:28:43 +0300
parents a3023fe79c43
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Sprite / surface blitting functions
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * (C) Copyright 2011 Tecnic Software productions (TNSP)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 //#define DM_CLIP_DEBUG
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 typedef struct
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 int v0, v1, voffs, vadd;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 DMFixedPoint32 vdelta;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 } DMQValue;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
18 int dmScaledClipCoord(DMQValue *pv, int v0, int v1, int v2, int clipMin, int clipMax)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 DMFixedPoint32 a, b;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 // Basic bounds check
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 if (v1 < 1 || v2 < 1 || v0 + v2 < clipMin || v0 >= clipMax)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 #ifdef DM_CLIPDEBUG
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 printf("out of bounds\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 return -1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 // Calculate delta
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 FP_SETHL(a, v1, 0);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 FP_CONV(b, v2);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 FP_DIV_R(pv->vdelta, a, b);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 // Perform clipping
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 if (v0 + v2 >= clipMax)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 pv->vadd = v0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 pv->v1 = clipMax;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 pv->vadd = clipMax - v2;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 pv->v1 = v0 + v2;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
47
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 if (v0 < clipMin)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 pv->voffs = clipMin - v0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 pv->v0 = clipMin;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 pv->vadd -= v0 + clipMin;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 pv->voffs = 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 pv->v0 = v0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
59
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 #ifdef DM_CLIP_DEBUG
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 printf("dmClipCoord(%d, (%d, %d), [%d, %d]): vdelta=",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 v0, v1, v2, clipMin, clipMax);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 FP_PRINTF(pv->vdelta);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 printf(", v0=%d, v1=%d, voffs=%d, vadd=%d\n",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 pv->v0, pv->v1, pv->voffs, pv->vadd);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 return 0;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
82
265ce3091d88 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
71
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
72 int dmUnscaledClipCoord(DMQValue *pv, int v0, int v1, int clipMin, int clipMax)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
73 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
74 // Basic bounds check
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
75 if (v1 < 1 || v0 + v1 < clipMin || v0 >= clipMax)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
76 return -1;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
77
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
78 // Perform clipping
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
79 if (v0 + v1 >= clipMax)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
80 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
81 pv->vadd = v0;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
82 pv->v1 = clipMax;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
83 }
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
84 else
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
85 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
86 pv->vadd = clipMax - v1;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
87 pv->v1 = v0 + v1;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
88 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
89
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
90 if (v0 < clipMin)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
91 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
92 pv->voffs = clipMin - v0;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
93 pv->v0 = clipMin;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
94 pv->vadd -= v0 + clipMin;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
95 }
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
96 else
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
97 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
98 pv->voffs = 0;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
99 pv->v0 = v0;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
100 }
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
101
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
102 return 0;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
103 }
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
104
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
105
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 #include "dmblitfunc.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
82
265ce3091d88 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
108
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 static const DMScaledBlitFunc dmScaledBlitTable[DMD_NMODES][DMD_NBITDEPTHS][DMD_NBITDEPTHS] =
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 // DMD_NONE
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 { dmScaledBlitSurface8to8 , dmScaledBlitSurface8to32 },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 { NULL , dmScaledBlitSurface32to32 },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 // DMD_TRANSPARENT
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 { dmScaledBlitSurface8to8Transparent , dmScaledBlitSurface8to32Transparent },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 { NULL , dmScaledBlitSurface32to32Transparent },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 // DMD_SATURATE
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 { dmScaledBlitSurface8to8Saturate , dmScaledBlitSurface8to32Saturate },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 { NULL , dmScaledBlitSurface32to32Saturate },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 #if 0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 // DMD_NONE | DMD_ANTIALIAS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 { dmScaledBlitSurface8to8Antialias , dmScaledBlitSurface8to32Antialias },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 { NULL , dmScaledBlitSurface32to32Antialias },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 // DMD_TRANSPARENT | DMD_ANTIALIAS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 { dmScaledBlitSurface8to8AATransp , dmScaledBlitSurface8to32AATransparent },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 { NULL , dmScaledBlitSurface32to32AATransparent },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 // DMD_SATURATE | DMD_ANTIALIAS
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 { dmScaledBlitSurface8to8AASaturate , dmScaledBlitSurface8to32AASaturate },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 { NULL , dmScaledBlitSurface32to32AASaturate },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 },
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 static const int ndmScaledBlitTable = sizeof(dmScaledBlitTable) / sizeof(dmScaledBlitTable[0]);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
147
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 DMScaledBlitFunc dmGetScaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 int isrc, idst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 if (src == NULL || dst == NULL || mode < 0 || mode >= ndmScaledBlitTable)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 return NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 isrc = dmBitsPerPixel2Index(src->BitsPerPixel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 idst = dmBitsPerPixel2Index(dst->BitsPerPixel);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 if (isrc < 0 || idst < 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 return NULL;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
158
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 return dmScaledBlitTable[mode][isrc][idst];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 int dmScaledBlitSurfaceAny(SDL_Surface *src, const int x0, const int y0, const int dwidth, const int dheight, SDL_Surface *dst, int mode)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 DMScaledBlitFunc bfunc = dmGetScaledBlitFunc(src->format, dst->format, mode);
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
166
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 if (bfunc == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 return -15;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 return bfunc(src, x0, y0, dwidth, dheight, dst);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
172
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
173
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
174 static const DMUnscaledBlitFunc dmUnscaledBlitTable[DMD_NMODES][DMD_NBITDEPTHS][DMD_NBITDEPTHS] =
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
175 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
176 // DMD_NONE
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
177 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
178 { dmUnscaledBlitSurface8to8 , dmUnscaledBlitSurface8to32 },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
179 { NULL , dmUnscaledBlitSurface32to32 },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
180 },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
181 // DMD_TRANSPARENT
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
182 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
183 { dmUnscaledBlitSurface8to8Transparent, dmUnscaledBlitSurface8to32Transparent },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
184 { NULL , dmUnscaledBlitSurface32to32Transparent },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
185 },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
186 // DMD_SATURATE
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
187 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
188 { dmUnscaledBlitSurface8to8Saturate , dmUnscaledBlitSurface8to32Saturate },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
189 { NULL , dmUnscaledBlitSurface32to32Saturate },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
190 },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
191 #if 0
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
192 // DMD_NONE | DMD_ANTIALIAS
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
193 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
194 { dmUnscaledBlitSurface8to8Antialias , dmUnscaledBlitSurface8to32Antialias },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
195 { NULL , dmUnscaledBlitSurface32to32Antialias },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
196 },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
197 // DMD_TRANSPARENT | DMD_ANTIALIAS
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
198 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
199 { dmUnscaledBlitSurface8to8AATransp , dmUnscaledBlitSurface8to32AATransparent },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
200 { NULL , dmUnscaledBlitSurface32to32AATransparent },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
201 },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
202 // DMD_SATURATE | DMD_ANTIALIAS
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
203 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
204 { dmUnscaledBlitSurface8to8AASaturate , dmUnscaledBlitSurface8to32AASaturate },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
205 { NULL , dmUnscaledBlitSurface32to32AASaturate },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
206 },
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
207 #endif
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
208 };
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
209
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
210 static const int ndmUnscaledBlitTable = sizeof(dmUnscaledBlitTable) / sizeof(dmUnscaledBlitTable[0]);
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
211
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
212
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
213
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
214 DMUnscaledBlitFunc dmGetUnscaledBlitFunc(SDL_PixelFormat *src, SDL_PixelFormat *dst, int mode)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
215 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
216 int isrc, idst;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
217 if (src == NULL || dst == NULL || mode < 0 || mode >= ndmUnscaledBlitTable)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
218 return NULL;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
219
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
220 isrc = dmBitsPerPixel2Index(src->BitsPerPixel);
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
221 idst = dmBitsPerPixel2Index(dst->BitsPerPixel);
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
222 if (isrc < 0 || idst < 0)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
223 return NULL;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
224
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
225 return dmUnscaledBlitTable[mode][isrc][idst];
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
226 }
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
227
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
228
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
229 int dmUnscaledBlitSurfaceAny(SDL_Surface *src, const int x0, const int y0, SDL_Surface *dst, int mode)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
230 {
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
231 DMUnscaledBlitFunc bfunc = dmGetUnscaledBlitFunc(src->format, dst->format, mode);
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
232
95
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
233 if (bfunc == NULL)
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
234 return -15;
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
235
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
236 return bfunc(src, x0, y0, dst);
0430f484641b Add unscaled blitting functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
237 }
610
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
238
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
239
1601
a3023fe79c43 Change dmConvertScaledSurface() interface by remove flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
240 SDL_Surface *dmConvertScaledSurface(SDL_Surface *src, SDL_PixelFormat *fmt, const int dwidth, const int dheight)
610
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
241 {
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
242 // Create the target surface
1601
a3023fe79c43 Change dmConvertScaledSurface() interface by remove flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
243 SDL_Surface *result = SDL_CreateRGBSurface(
a3023fe79c43 Change dmConvertScaledSurface() interface by remove flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
244 0, dwidth, dheight, fmt->BitsPerPixel,
a3023fe79c43 Change dmConvertScaledSurface() interface by remove flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
245 fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);
a3023fe79c43 Change dmConvertScaledSurface() interface by remove flags.
Matti Hamalainen <ccr@tnsp.org>
parents: 1102
diff changeset
246
610
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
247 if (result == NULL)
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
248 return NULL;
1102
e06abfde6c39 Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
249
610
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
250 // Use scaled blitting to convert the scaled image ..
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
251 dmScaledBlitSurfaceAny(src, 0, 0, dwidth, dheight, result, DMD_NONE);
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
252
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
253 return result;
e74ad60b1e85 Add new scaled surface conversion function.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
254 }