2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 #include "SDL_video.h"
27 /* Functions to blit from bitmaps to other surfaces */
29 static void BlitBto1(SDL_BlitInfo *info)
33 Uint8 *src, *map, *dst;
36 /* Set up some basic variables */
37 width = info->d_width;
38 height = info->d_height;
40 srcskip = info->s_skip;
42 dstskip = info->d_skip;
44 srcskip += width-(width+7)/8;
49 for ( c=0; c<width; ++c ) {
66 for ( c=0; c<width; ++c ) {
82 static void BlitBto2(SDL_BlitInfo *info)
90 /* Set up some basic variables */
91 width = info->d_width;
92 height = info->d_height;
94 srcskip = info->s_skip;
95 dst = (Uint16 *)info->d_pixels;
96 dstskip = info->d_skip/2;
97 map = (Uint16 *)info->table;
98 srcskip += width-(width+7)/8;
102 for ( c=0; c<width; ++c ) {
106 bit = (byte&0x80)>>7;
117 static void BlitBto3(SDL_BlitInfo *info)
121 Uint8 *src, *map, *dst;
122 int srcskip, dstskip;
124 /* Set up some basic variables */
125 width = info->d_width;
126 height = info->d_height;
127 src = info->s_pixels;
128 srcskip = info->s_skip;
129 dst = info->d_pixels;
130 dstskip = info->d_skip;
132 srcskip += width-(width+7)/8;
136 for ( c=0; c<width; ++c ) {
140 bit = (byte&0x80)>>7;
154 static void BlitBto4(SDL_BlitInfo *info)
159 int srcskip, dstskip;
162 /* Set up some basic variables */
163 width = info->d_width;
164 height = info->d_height;
165 src = info->s_pixels;
166 srcskip = info->s_skip;
167 dst = (Uint32 *)info->d_pixels;
168 dstskip = info->d_skip/4;
169 map = (Uint32 *)info->table;
170 srcskip += width-(width+7)/8;
174 for ( c=0; c<width; ++c ) {
178 bit = (byte&0x80)>>7;
190 static void BlitBto1Key(SDL_BlitInfo *info)
192 int width = info->d_width;
193 int height = info->d_height;
194 Uint8 *src = info->s_pixels;
195 Uint8 *dst = info->d_pixels;
196 int srcskip = info->s_skip;
197 int dstskip = info->d_skip;
198 Uint32 ckey = info->src->colorkey;
199 Uint8 *palmap = info->table;
202 /* Set up some basic variables */
203 srcskip += width-(width+7)/8;
208 for ( c=0; c<width; ++c ) {
212 bit = (byte&0x80)>>7;
225 for ( c=0; c<width; ++c ) {
229 bit = (byte&0x80)>>7;
242 static void BlitBto2Key(SDL_BlitInfo *info)
244 int width = info->d_width;
245 int height = info->d_height;
246 Uint8 *src = info->s_pixels;
247 Uint16 *dstp = (Uint16 *)info->d_pixels;
248 int srcskip = info->s_skip;
249 int dstskip = info->d_skip;
250 Uint32 ckey = info->src->colorkey;
251 Uint8 *palmap = info->table;
254 /* Set up some basic variables */
255 srcskip += width-(width+7)/8;
260 for ( c=0; c<width; ++c ) {
264 bit = (byte&0x80)>>7;
266 *dstp=((Uint16 *)palmap)[bit];
276 static void BlitBto3Key(SDL_BlitInfo *info)
278 int width = info->d_width;
279 int height = info->d_height;
280 Uint8 *src = info->s_pixels;
281 Uint8 *dst = info->d_pixels;
282 int srcskip = info->s_skip;
283 int dstskip = info->d_skip;
284 Uint32 ckey = info->src->colorkey;
285 Uint8 *palmap = info->table;
288 /* Set up some basic variables */
289 srcskip += width-(width+7)/8;
293 for ( c=0; c<width; ++c ) {
297 bit = (byte&0x80)>>7;
299 SDL_memcpy(dst, &palmap[bit*4], 3);
309 static void BlitBto4Key(SDL_BlitInfo *info)
311 int width = info->d_width;
312 int height = info->d_height;
313 Uint8 *src = info->s_pixels;
314 Uint32 *dstp = (Uint32 *)info->d_pixels;
315 int srcskip = info->s_skip;
316 int dstskip = info->d_skip;
317 Uint32 ckey = info->src->colorkey;
318 Uint8 *palmap = info->table;
321 /* Set up some basic variables */
322 srcskip += width-(width+7)/8;
327 for ( c=0; c<width; ++c ) {
331 bit = (byte&0x80)>>7;
333 *dstp=((Uint32 *)palmap)[bit];
343 static void BlitBtoNAlpha(SDL_BlitInfo *info)
345 int width = info->d_width;
346 int height = info->d_height;
347 Uint8 *src = info->s_pixels;
348 Uint8 *dst = info->d_pixels;
349 int srcskip = info->s_skip;
350 int dstskip = info->d_skip;
351 const SDL_Color *srcpal = info->src->palette->colors;
352 SDL_PixelFormat *dstfmt = info->dst;
355 const int A = info->src->alpha;
357 /* Set up some basic variables */
358 dstbpp = dstfmt->BytesPerPixel;
359 srcskip += width-(width+7)/8;
363 for ( c=0; c<width; ++c ) {
367 bit = (byte&0x80)>>7;
375 DISEMBLE_RGB(dst, dstbpp, dstfmt,
377 ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
378 ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
388 static void BlitBtoNAlphaKey(SDL_BlitInfo *info)
390 int width = info->d_width;
391 int height = info->d_height;
392 Uint8 *src = info->s_pixels;
393 Uint8 *dst = info->d_pixels;
394 int srcskip = info->s_skip;
395 int dstskip = info->d_skip;
396 SDL_PixelFormat *srcfmt = info->src;
397 SDL_PixelFormat *dstfmt = info->dst;
398 const SDL_Color *srcpal = srcfmt->palette->colors;
401 const int A = srcfmt->alpha;
402 Uint32 ckey = srcfmt->colorkey;
404 /* Set up some basic variables */
405 dstbpp = dstfmt->BytesPerPixel;
406 srcskip += width-(width+7)/8;
410 for ( c=0; c<width; ++c ) {
414 bit = (byte&0x80)>>7;
422 DISEMBLE_RGB(dst, dstbpp, dstfmt,
424 ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
425 ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
435 static SDL_loblit bitmap_blit[] = {
436 NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
439 static SDL_loblit colorkey_blit[] = {
440 NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
443 SDL_loblit SDL_CalculateBlit0(SDL_Surface *surface, int blit_index)
447 if ( surface->format->BitsPerPixel != 1 ) {
448 /* We don't support sub 8-bit packed pixel modes */
451 if ( surface->map->dst->format->BitsPerPixel < 8 ) {
454 which = surface->map->dst->format->BytesPerPixel;
458 return bitmap_blit[which];
460 case 1: /* colorkey */
461 return colorkey_blit[which];
464 return which >= 2 ? BlitBtoNAlpha : NULL;
466 case 4: /* alpha + colorkey */
467 return which >= 2 ? BlitBtoNAlphaKey : NULL;