Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
483 lines (440 loc) · 12 KB

SDL_blit_0.c

File metadata and controls

483 lines (440 loc) · 12 KB
 
Apr 26, 2001
Apr 26, 2001
1
/*
Apr 8, 2011
Apr 8, 2011
2
3
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
Apr 26, 2001
Apr 26, 2001
4
Apr 8, 2011
Apr 8, 2011
5
6
7
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Apr 26, 2001
Apr 26, 2001
8
Apr 8, 2011
Apr 8, 2011
9
10
11
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
Apr 26, 2001
Apr 26, 2001
12
Apr 8, 2011
Apr 8, 2011
13
14
15
16
17
18
19
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Apr 26, 2001
Apr 26, 2001
20
*/
Feb 21, 2006
Feb 21, 2006
21
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
22
23
24
25
26
27
#include "SDL_video.h"
#include "SDL_blit.h"
/* Functions to blit from bitmaps to other surfaces */
Jul 10, 2006
Jul 10, 2006
28
29
static void
BlitBto1(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
30
{
Jul 10, 2006
Jul 10, 2006
31
32
33
34
35
36
int c;
int width, height;
Uint8 *src, *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
Aug 17, 2007
Aug 17, 2007
37
38
39
width = info->dst_w;
height = info->dst_h;
src = info->src;
Aug 18, 2007
Aug 18, 2007
40
srcskip = info->src_skip;
Aug 17, 2007
Aug 17, 2007
41
dst = info->dst;
Aug 18, 2007
Aug 18, 2007
42
dstskip = info->dst_skip;
Jul 10, 2006
Jul 10, 2006
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
map = info->table;
srcskip += width - (width + 7) / 8;
if (map) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = bit;
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
}
Apr 26, 2001
Apr 26, 2001
81
}
Aug 27, 2008
Aug 27, 2008
82
Jul 10, 2006
Jul 10, 2006
83
84
static void
BlitBto2(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
85
{
Jul 10, 2006
Jul 10, 2006
86
87
88
89
90
91
92
int c;
int width, height;
Uint8 *src;
Uint16 *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
Aug 17, 2007
Aug 17, 2007
93
94
95
width = info->dst_w;
height = info->dst_h;
src = info->src;
Aug 18, 2007
Aug 18, 2007
96
srcskip = info->src_skip;
Aug 17, 2007
Aug 17, 2007
97
dst = (Uint16 *) info->dst;
Aug 18, 2007
Aug 18, 2007
98
dstskip = info->dst_skip / 2;
Jul 10, 2006
Jul 10, 2006
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
map = (Uint16 *) info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
}
src += srcskip;
dst += dstskip;
}
Apr 26, 2001
Apr 26, 2001
118
}
Aug 27, 2008
Aug 27, 2008
119
Jul 10, 2006
Jul 10, 2006
120
121
static void
BlitBto3(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
122
{
Jul 10, 2006
Jul 10, 2006
123
124
125
126
127
128
int c, o;
int width, height;
Uint8 *src, *map, *dst;
int srcskip, dstskip;
/* Set up some basic variables */
Aug 17, 2007
Aug 17, 2007
129
130
131
width = info->dst_w;
height = info->dst_h;
src = info->src;
Aug 18, 2007
Aug 18, 2007
132
srcskip = info->src_skip;
Aug 17, 2007
Aug 17, 2007
133
dst = info->dst;
Aug 18, 2007
Aug 18, 2007
134
dstskip = info->dst_skip;
Jul 10, 2006
Jul 10, 2006
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
map = info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
o = bit * 4;
dst[0] = map[o++];
dst[1] = map[o++];
dst[2] = map[o++];
}
byte <<= 1;
dst += 3;
}
src += srcskip;
dst += dstskip;
}
Apr 26, 2001
Apr 26, 2001
157
}
Aug 27, 2008
Aug 27, 2008
158
Jul 10, 2006
Jul 10, 2006
159
160
static void
BlitBto4(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
161
{
Jul 10, 2006
Jul 10, 2006
162
163
164
165
166
167
168
int width, height;
Uint8 *src;
Uint32 *map, *dst;
int srcskip, dstskip;
int c;
/* Set up some basic variables */
Aug 17, 2007
Aug 17, 2007
169
170
171
width = info->dst_w;
height = info->dst_h;
src = info->src;
Aug 18, 2007
Aug 18, 2007
172
srcskip = info->src_skip;
Aug 17, 2007
Aug 17, 2007
173
dst = (Uint32 *) info->dst;
Aug 18, 2007
Aug 18, 2007
174
dstskip = info->dst_skip / 4;
Jul 10, 2006
Jul 10, 2006
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
map = (Uint32 *) info->table;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
*dst = map[bit];
}
byte <<= 1;
dst++;
}
src += srcskip;
dst += dstskip;
}
Apr 26, 2001
Apr 26, 2001
194
195
}
Jul 10, 2006
Jul 10, 2006
196
197
static void
BlitBto1Key(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
198
{
Aug 17, 2007
Aug 17, 2007
199
200
201
202
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
Aug 18, 2007
Aug 18, 2007
203
204
205
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Jul 10, 2006
Jul 10, 2006
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
Uint8 *palmap = info->table;
int c;
/* Set up some basic variables */
srcskip += width - (width + 7) / 8;
if (palmap) {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = palmap[bit];
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
} else {
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dst = bit;
}
dst++;
byte <<= 1;
}
src += srcskip;
dst += dstskip;
}
}
Apr 26, 2001
Apr 26, 2001
247
248
}
Jul 10, 2006
Jul 10, 2006
249
250
static void
BlitBto2Key(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
251
{
Aug 17, 2007
Aug 17, 2007
252
253
254
255
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint16 *dstp = (Uint16 *) info->dst;
Aug 18, 2007
Aug 18, 2007
256
257
258
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Jul 10, 2006
Jul 10, 2006
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
Uint8 *palmap = info->table;
int c;
/* Set up some basic variables */
srcskip += width - (width + 7) / 8;
dstskip /= 2;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint16 *) palmap)[bit];
}
byte <<= 1;
dstp++;
}
src += srcskip;
dstp += dstskip;
}
Apr 26, 2001
Apr 26, 2001
282
283
}
Jul 10, 2006
Jul 10, 2006
284
285
static void
BlitBto3Key(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
286
{
Aug 17, 2007
Aug 17, 2007
287
288
289
290
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
Aug 18, 2007
Aug 18, 2007
291
292
293
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Jul 10, 2006
Jul 10, 2006
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
Uint8 *palmap = info->table;
int c;
/* Set up some basic variables */
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
SDL_memcpy(dst, &palmap[bit * 4], 3);
}
byte <<= 1;
dst += 3;
}
src += srcskip;
dst += dstskip;
}
Apr 26, 2001
Apr 26, 2001
316
317
}
Jul 10, 2006
Jul 10, 2006
318
319
static void
BlitBto4Key(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
320
{
Aug 17, 2007
Aug 17, 2007
321
322
323
324
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint32 *dstp = (Uint32 *) info->dst;
Aug 18, 2007
Aug 18, 2007
325
326
327
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
Uint32 ckey = info->colorkey;
Jul 10, 2006
Jul 10, 2006
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
Uint8 *palmap = info->table;
int c;
/* Set up some basic variables */
srcskip += width - (width + 7) / 8;
dstskip /= 4;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
*dstp = ((Uint32 *) palmap)[bit];
}
byte <<= 1;
dstp++;
}
src += srcskip;
dstp += dstskip;
}
Apr 26, 2001
Apr 26, 2001
351
352
}
Jul 10, 2006
Jul 10, 2006
353
354
static void
BlitBtoNAlpha(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
355
{
Aug 17, 2007
Aug 17, 2007
356
357
358
359
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
Aug 18, 2007
Aug 18, 2007
360
361
362
363
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
const SDL_Color *srcpal = info->src_fmt->palette->colors;
SDL_PixelFormat *dstfmt = info->dst_fmt;
Jul 10, 2006
Jul 10, 2006
364
365
int dstbpp;
int c;
Aug 18, 2007
Aug 18, 2007
366
const int A = info->a;
Jul 10, 2006
Jul 10, 2006
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/* Set up some basic variables */
dstbpp = dstfmt->BytesPerPixel;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (1) {
Uint32 pixel;
unsigned sR, sG, sB;
unsigned dR, dG, dB;
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
}
byte <<= 1;
dst += dstbpp;
}
src += srcskip;
dst += dstskip;
}
Apr 26, 2001
Apr 26, 2001
396
397
}
Jul 10, 2006
Jul 10, 2006
398
399
static void
BlitBtoNAlphaKey(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
400
{
Aug 17, 2007
Aug 17, 2007
401
402
403
404
int width = info->dst_w;
int height = info->dst_h;
Uint8 *src = info->src;
Uint8 *dst = info->dst;
Aug 18, 2007
Aug 18, 2007
405
406
407
408
int srcskip = info->src_skip;
int dstskip = info->dst_skip;
SDL_PixelFormat *srcfmt = info->src_fmt;
SDL_PixelFormat *dstfmt = info->dst_fmt;
Jul 10, 2006
Jul 10, 2006
409
410
411
const SDL_Color *srcpal = srcfmt->palette->colors;
int dstbpp;
int c;
Aug 18, 2007
Aug 18, 2007
412
413
const int A = info->a;
Uint32 ckey = info->colorkey;
Jul 10, 2006
Jul 10, 2006
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/* Set up some basic variables */
dstbpp = dstfmt->BytesPerPixel;
srcskip += width - (width + 7) / 8;
while (height--) {
Uint8 byte = 0, bit;
for (c = 0; c < width; ++c) {
if ((c & 7) == 0) {
byte = *src++;
}
bit = (byte & 0x80) >> 7;
if (bit != ckey) {
int sR, sG, sB;
int dR, dG, dB;
Uint32 pixel;
sR = srcpal[bit].r;
sG = srcpal[bit].g;
sB = srcpal[bit].b;
DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
}
byte <<= 1;
dst += dstbpp;
}
src += srcskip;
dst += dstskip;
}
Apr 26, 2001
Apr 26, 2001
443
444
}
Jun 3, 2009
Jun 3, 2009
445
static const SDL_BlitFunc bitmap_blit[] = {
Jul 10, 2006
Jul 10, 2006
446
NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
Apr 26, 2001
Apr 26, 2001
447
448
};
Jun 3, 2009
Jun 3, 2009
449
static const SDL_BlitFunc colorkey_blit[] = {
Apr 26, 2001
Apr 26, 2001
450
451
452
NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
};
Aug 18, 2007
Aug 18, 2007
453
454
SDL_BlitFunc
SDL_CalculateBlit0(SDL_Surface * surface)
Apr 26, 2001
Apr 26, 2001
455
{
Jul 10, 2006
Jul 10, 2006
456
457
458
459
460
461
462
463
464
465
466
int which;
if (surface->format->BitsPerPixel != 1) {
/* We don't support sub 8-bit packed pixel modes */
return NULL;
}
if (surface->map->dst->format->BitsPerPixel < 8) {
which = 0;
} else {
which = surface->map->dst->format->BytesPerPixel;
}
Dec 7, 2008
Dec 7, 2008
467
switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
Aug 18, 2007
Aug 18, 2007
468
case 0:
Jul 10, 2006
Jul 10, 2006
469
470
return bitmap_blit[which];
Aug 18, 2007
Aug 18, 2007
471
case SDL_COPY_COLORKEY:
Jul 10, 2006
Jul 10, 2006
472
473
return colorkey_blit[which];
Aug 18, 2007
Aug 18, 2007
474
case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
Jul 10, 2006
Jul 10, 2006
475
476
return which >= 2 ? BlitBtoNAlpha : NULL;
Aug 18, 2007
Aug 18, 2007
477
case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
Jul 10, 2006
Jul 10, 2006
478
479
480
return which >= 2 ? BlitBtoNAlphaKey : NULL;
}
return NULL;
Apr 26, 2001
Apr 26, 2001
481
482
}
Jul 10, 2006
Jul 10, 2006
483
/* vi: set ts=4 sw=4 expandtab: */