src/video/SDL_blit_0.c
changeset 1895 c121d94672cb
parent 1402 d910939febfa
child 2257 340942cfda48
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
    24 #include "SDL_video.h"
    24 #include "SDL_video.h"
    25 #include "SDL_blit.h"
    25 #include "SDL_blit.h"
    26 
    26 
    27 /* Functions to blit from bitmaps to other surfaces */
    27 /* Functions to blit from bitmaps to other surfaces */
    28 
    28 
    29 static void BlitBto1(SDL_BlitInfo *info)
    29 static void
    30 {
    30 BlitBto1(SDL_BlitInfo * info)
    31 	int c;
    31 {
    32 	int width, height;
    32     int c;
    33 	Uint8 *src, *map, *dst;
    33     int width, height;
    34 	int srcskip, dstskip;
    34     Uint8 *src, *map, *dst;
    35 
    35     int srcskip, dstskip;
    36 	/* Set up some basic variables */
    36 
    37 	width = info->d_width;
    37     /* Set up some basic variables */
    38 	height = info->d_height;
    38     width = info->d_width;
    39 	src = info->s_pixels;
    39     height = info->d_height;
    40 	srcskip = info->s_skip;
    40     src = info->s_pixels;
    41 	dst = info->d_pixels;
    41     srcskip = info->s_skip;
    42 	dstskip = info->d_skip;
    42     dst = info->d_pixels;
    43 	map = info->table;
    43     dstskip = info->d_skip;
    44 	srcskip += width-(width+7)/8;
    44     map = info->table;
    45 
    45     srcskip += width - (width + 7) / 8;
    46 	if ( map ) {
    46 
    47 		while ( height-- ) {
    47     if (map) {
    48 		        Uint8 byte = 0, bit;
    48         while (height--) {
    49 	    		for ( c=0; c<width; ++c ) {
    49             Uint8 byte = 0, bit;
    50 				if ( (c&7) == 0 ) {
    50             for (c = 0; c < width; ++c) {
    51 					byte = *src++;
    51                 if ((c & 7) == 0) {
    52 				}
    52                     byte = *src++;
    53 				bit = (byte&0x80)>>7;
    53                 }
    54 				if ( 1 ) {
    54                 bit = (byte & 0x80) >> 7;
    55 				  *dst = map[bit];
    55                 if (1) {
    56 				}
    56                     *dst = map[bit];
    57 				dst++;
    57                 }
    58 				byte <<= 1;
    58                 dst++;
    59 			}
    59                 byte <<= 1;
    60 			src += srcskip;
    60             }
    61 			dst += dstskip;
    61             src += srcskip;
    62 		}
    62             dst += dstskip;
    63 	} else {
    63         }
    64 		while ( height-- ) {
    64     } else {
    65 		        Uint8 byte = 0, bit;
    65         while (height--) {
    66 	    		for ( c=0; c<width; ++c ) {
    66             Uint8 byte = 0, bit;
    67 				if ( (c&7) == 0 ) {
    67             for (c = 0; c < width; ++c) {
    68 					byte = *src++;
    68                 if ((c & 7) == 0) {
    69 				}
    69                     byte = *src++;
    70 				bit = (byte&0x80)>>7;
    70                 }
    71 				if ( 1 ) {
    71                 bit = (byte & 0x80) >> 7;
    72 				  *dst = bit;
    72                 if (1) {
    73 				}
    73                     *dst = bit;
    74 				dst++;
    74                 }
    75 				byte <<= 1;
    75                 dst++;
    76 			}
    76                 byte <<= 1;
    77 			src += srcskip;
    77             }
    78 			dst += dstskip;
    78             src += srcskip;
    79 		}
    79             dst += dstskip;
    80 	}
    80         }
    81 }
    81     }
    82 static void BlitBto2(SDL_BlitInfo *info)
    82 }
    83 {
    83 static void
    84 	int c;
    84 BlitBto2(SDL_BlitInfo * info)
    85 	int width, height;
    85 {
    86 	Uint8 *src;
    86     int c;
    87 	Uint16 *map, *dst;
    87     int width, height;
    88 	int srcskip, dstskip;
    88     Uint8 *src;
    89 
    89     Uint16 *map, *dst;
    90 	/* Set up some basic variables */
    90     int srcskip, dstskip;
    91 	width = info->d_width;
    91 
    92 	height = info->d_height;
    92     /* Set up some basic variables */
    93 	src = info->s_pixels;
    93     width = info->d_width;
    94 	srcskip = info->s_skip;
    94     height = info->d_height;
    95 	dst = (Uint16 *)info->d_pixels;
    95     src = info->s_pixels;
    96 	dstskip = info->d_skip/2;
    96     srcskip = info->s_skip;
    97 	map = (Uint16 *)info->table;
    97     dst = (Uint16 *) info->d_pixels;
    98 	srcskip += width-(width+7)/8;
    98     dstskip = info->d_skip / 2;
    99 
    99     map = (Uint16 *) info->table;
   100 	while ( height-- ) {
   100     srcskip += width - (width + 7) / 8;
   101 	        Uint8 byte = 0, bit;
   101 
   102 	    	for ( c=0; c<width; ++c ) {
   102     while (height--) {
   103 			if ( (c&7) == 0 ) {
   103         Uint8 byte = 0, bit;
   104 				byte = *src++;
   104         for (c = 0; c < width; ++c) {
   105 			}
   105             if ((c & 7) == 0) {
   106 			bit = (byte&0x80)>>7;
   106                 byte = *src++;
   107 			if ( 1 ) {
   107             }
   108 				*dst = map[bit];
   108             bit = (byte & 0x80) >> 7;
   109 			}
   109             if (1) {
   110 			byte <<= 1;
   110                 *dst = map[bit];
   111 			dst++;
   111             }
   112 		}
   112             byte <<= 1;
   113 		src += srcskip;
   113             dst++;
   114 		dst += dstskip;
   114         }
   115 	}
   115         src += srcskip;
   116 }
   116         dst += dstskip;
   117 static void BlitBto3(SDL_BlitInfo *info)
   117     }
   118 {
   118 }
   119 	int c, o;
   119 static void
   120 	int width, height;
   120 BlitBto3(SDL_BlitInfo * info)
   121 	Uint8 *src, *map, *dst;
   121 {
   122 	int srcskip, dstskip;
   122     int c, o;
   123 
   123     int width, height;
   124 	/* Set up some basic variables */
   124     Uint8 *src, *map, *dst;
   125 	width = info->d_width;
   125     int srcskip, dstskip;
   126 	height = info->d_height;
   126 
   127 	src = info->s_pixels;
   127     /* Set up some basic variables */
   128 	srcskip = info->s_skip;
   128     width = info->d_width;
   129 	dst = info->d_pixels;
   129     height = info->d_height;
   130 	dstskip = info->d_skip;
   130     src = info->s_pixels;
   131 	map = info->table;
   131     srcskip = info->s_skip;
   132 	srcskip += width-(width+7)/8;
   132     dst = info->d_pixels;
   133 
   133     dstskip = info->d_skip;
   134 	while ( height-- ) {
   134     map = info->table;
   135 	        Uint8 byte = 0, bit;
   135     srcskip += width - (width + 7) / 8;
   136 	    	for ( c=0; c<width; ++c ) {
   136 
   137 			if ( (c&7) == 0 ) {
   137     while (height--) {
   138 				byte = *src++;
   138         Uint8 byte = 0, bit;
   139 			}
   139         for (c = 0; c < width; ++c) {
   140 			bit = (byte&0x80)>>7;
   140             if ((c & 7) == 0) {
   141 			if ( 1 ) {
   141                 byte = *src++;
   142 				o = bit * 4;
   142             }
   143 				dst[0] = map[o++];
   143             bit = (byte & 0x80) >> 7;
   144 				dst[1] = map[o++];
   144             if (1) {
   145 				dst[2] = map[o++];
   145                 o = bit * 4;
   146 			}
   146                 dst[0] = map[o++];
   147 			byte <<= 1;
   147                 dst[1] = map[o++];
   148 			dst += 3;
   148                 dst[2] = map[o++];
   149 		}
   149             }
   150 		src += srcskip;
   150             byte <<= 1;
   151 		dst += dstskip;
   151             dst += 3;
   152 	}
   152         }
   153 }
   153         src += srcskip;
   154 static void BlitBto4(SDL_BlitInfo *info)
   154         dst += dstskip;
   155 {
   155     }
   156 	int width, height;
   156 }
   157 	Uint8 *src;
   157 static void
   158 	Uint32 *map, *dst;
   158 BlitBto4(SDL_BlitInfo * info)
   159 	int srcskip, dstskip;
   159 {
   160 	int c;
   160     int width, height;
   161 
   161     Uint8 *src;
   162 	/* Set up some basic variables */
   162     Uint32 *map, *dst;
   163 	width = info->d_width;
   163     int srcskip, dstskip;
   164 	height = info->d_height;
   164     int c;
   165 	src = info->s_pixels;
   165 
   166 	srcskip = info->s_skip;
   166     /* Set up some basic variables */
   167 	dst = (Uint32 *)info->d_pixels;
   167     width = info->d_width;
   168 	dstskip = info->d_skip/4;
   168     height = info->d_height;
   169 	map = (Uint32 *)info->table;
   169     src = info->s_pixels;
   170 	srcskip += width-(width+7)/8;
   170     srcskip = info->s_skip;
   171 
   171     dst = (Uint32 *) info->d_pixels;
   172 	while ( height-- ) {
   172     dstskip = info->d_skip / 4;
   173 	        Uint8 byte = 0, bit;
   173     map = (Uint32 *) info->table;
   174 	    	for ( c=0; c<width; ++c ) {
   174     srcskip += width - (width + 7) / 8;
   175 			if ( (c&7) == 0 ) {
   175 
   176 				byte = *src++;
   176     while (height--) {
   177 			}
   177         Uint8 byte = 0, bit;
   178 			bit = (byte&0x80)>>7;
   178         for (c = 0; c < width; ++c) {
   179 			if ( 1 ) {
   179             if ((c & 7) == 0) {
   180 				*dst = map[bit];
   180                 byte = *src++;
   181 			}
   181             }
   182 			byte <<= 1;
   182             bit = (byte & 0x80) >> 7;
   183 			dst++;
   183             if (1) {
   184 		}
   184                 *dst = map[bit];
   185 		src += srcskip;
   185             }
   186 		dst += dstskip;
   186             byte <<= 1;
   187 	}
   187             dst++;
   188 }
   188         }
   189 
   189         src += srcskip;
   190 static void BlitBto1Key(SDL_BlitInfo *info)
   190         dst += dstskip;
   191 {
   191     }
   192         int width = info->d_width;
   192 }
   193 	int height = info->d_height;
   193 
   194 	Uint8 *src = info->s_pixels;
   194 static void
   195 	Uint8 *dst = info->d_pixels;
   195 BlitBto1Key(SDL_BlitInfo * info)
   196 	int srcskip = info->s_skip;
   196 {
   197 	int dstskip = info->d_skip;
   197     int width = info->d_width;
   198 	Uint32 ckey = info->src->colorkey;
   198     int height = info->d_height;
   199 	Uint8 *palmap = info->table;
   199     Uint8 *src = info->s_pixels;
   200 	int c;
   200     Uint8 *dst = info->d_pixels;
   201 
   201     int srcskip = info->s_skip;
   202 	/* Set up some basic variables */
   202     int dstskip = info->d_skip;
   203 	srcskip += width-(width+7)/8;
   203     Uint32 ckey = info->src->colorkey;
   204 
   204     Uint8 *palmap = info->table;
   205 	if ( palmap ) {
   205     int c;
   206 		while ( height-- ) {
   206 
   207 		        Uint8  byte = 0, bit;
   207     /* Set up some basic variables */
   208 	    		for ( c=0; c<width; ++c ) {
   208     srcskip += width - (width + 7) / 8;
   209 				if ( (c&7) == 0 ) {
   209 
   210 					byte = *src++;
   210     if (palmap) {
   211 				}
   211         while (height--) {
   212 				bit = (byte&0x80)>>7;
   212             Uint8 byte = 0, bit;
   213 				if ( bit != ckey ) {
   213             for (c = 0; c < width; ++c) {
   214 				  *dst = palmap[bit];
   214                 if ((c & 7) == 0) {
   215 				}
   215                     byte = *src++;
   216 				dst++;
   216                 }
   217 				byte <<= 1;
   217                 bit = (byte & 0x80) >> 7;
   218 			}
   218                 if (bit != ckey) {
   219 			src += srcskip;
   219                     *dst = palmap[bit];
   220 			dst += dstskip;
   220                 }
   221 		}
   221                 dst++;
   222 	} else {
   222                 byte <<= 1;
   223 		while ( height-- ) {
   223             }
   224 		        Uint8  byte = 0, bit;
   224             src += srcskip;
   225 	    		for ( c=0; c<width; ++c ) {
   225             dst += dstskip;
   226 				if ( (c&7) == 0 ) {
   226         }
   227 					byte = *src++;
   227     } else {
   228 				}
   228         while (height--) {
   229 				bit = (byte&0x80)>>7;
   229             Uint8 byte = 0, bit;
   230 				if ( bit != ckey ) {
   230             for (c = 0; c < width; ++c) {
   231 				  *dst = bit;
   231                 if ((c & 7) == 0) {
   232 				}
   232                     byte = *src++;
   233 				dst++;
   233                 }
   234 				byte <<= 1;
   234                 bit = (byte & 0x80) >> 7;
   235 			}
   235                 if (bit != ckey) {
   236 			src += srcskip;
   236                     *dst = bit;
   237 			dst += dstskip;
   237                 }
   238 		}
   238                 dst++;
   239 	}
   239                 byte <<= 1;
   240 }
   240             }
   241 
   241             src += srcskip;
   242 static void BlitBto2Key(SDL_BlitInfo *info)
   242             dst += dstskip;
   243 {
   243         }
   244         int width = info->d_width;
   244     }
   245 	int height = info->d_height;
   245 }
   246 	Uint8 *src = info->s_pixels;
   246 
   247 	Uint16 *dstp = (Uint16 *)info->d_pixels;
   247 static void
   248 	int srcskip = info->s_skip;
   248 BlitBto2Key(SDL_BlitInfo * info)
   249 	int dstskip = info->d_skip;
   249 {
   250 	Uint32 ckey = info->src->colorkey;
   250     int width = info->d_width;
   251 	Uint8 *palmap = info->table;
   251     int height = info->d_height;
   252 	int c;
   252     Uint8 *src = info->s_pixels;
   253 
   253     Uint16 *dstp = (Uint16 *) info->d_pixels;
   254 	/* Set up some basic variables */
   254     int srcskip = info->s_skip;
   255 	srcskip += width-(width+7)/8;
   255     int dstskip = info->d_skip;
   256 	dstskip /= 2;
   256     Uint32 ckey = info->src->colorkey;
   257 
   257     Uint8 *palmap = info->table;
   258 	while ( height-- ) {
   258     int c;
   259 	        Uint8 byte = 0, bit;
   259 
   260 	    	for ( c=0; c<width; ++c ) {
   260     /* Set up some basic variables */
   261 			if ( (c&7) == 0 ) {
   261     srcskip += width - (width + 7) / 8;
   262 				byte = *src++;
   262     dstskip /= 2;
   263 			}
   263 
   264 			bit = (byte&0x80)>>7;
   264     while (height--) {
   265 			if ( bit != ckey ) {
   265         Uint8 byte = 0, bit;
   266 				*dstp=((Uint16 *)palmap)[bit];
   266         for (c = 0; c < width; ++c) {
   267 			}
   267             if ((c & 7) == 0) {
   268 			byte <<= 1;
   268                 byte = *src++;
   269 			dstp++;
   269             }
   270 		}
   270             bit = (byte & 0x80) >> 7;
   271 		src += srcskip;
   271             if (bit != ckey) {
   272 		dstp += dstskip;
   272                 *dstp = ((Uint16 *) palmap)[bit];
   273 	}
   273             }
   274 }
   274             byte <<= 1;
   275 
   275             dstp++;
   276 static void BlitBto3Key(SDL_BlitInfo *info)
   276         }
   277 {
   277         src += srcskip;
   278         int width = info->d_width;
   278         dstp += dstskip;
   279 	int height = info->d_height;
   279     }
   280 	Uint8 *src = info->s_pixels;
   280 }
   281 	Uint8 *dst = info->d_pixels;
   281 
   282 	int srcskip = info->s_skip;
   282 static void
   283 	int dstskip = info->d_skip;
   283 BlitBto3Key(SDL_BlitInfo * info)
   284 	Uint32 ckey = info->src->colorkey;
   284 {
   285 	Uint8 *palmap = info->table;
   285     int width = info->d_width;
   286 	int c;
   286     int height = info->d_height;
   287 
   287     Uint8 *src = info->s_pixels;
   288 	/* Set up some basic variables */
   288     Uint8 *dst = info->d_pixels;
   289 	srcskip += width-(width+7)/8;
   289     int srcskip = info->s_skip;
   290 
   290     int dstskip = info->d_skip;
   291 	while ( height-- ) {
   291     Uint32 ckey = info->src->colorkey;
   292 	        Uint8  byte = 0, bit;
   292     Uint8 *palmap = info->table;
   293 	    	for ( c=0; c<width; ++c ) {
   293     int c;
   294 			if ( (c&7) == 0 ) {
   294 
   295 				byte = *src++;
   295     /* Set up some basic variables */
   296 			}
   296     srcskip += width - (width + 7) / 8;
   297 			bit = (byte&0x80)>>7;
   297 
   298 			if ( bit != ckey ) {
   298     while (height--) {
   299 				SDL_memcpy(dst, &palmap[bit*4], 3);
   299         Uint8 byte = 0, bit;
   300 			}
   300         for (c = 0; c < width; ++c) {
   301 			byte <<= 1;
   301             if ((c & 7) == 0) {
   302 			dst += 3;
   302                 byte = *src++;
   303 		}
   303             }
   304 		src += srcskip;
   304             bit = (byte & 0x80) >> 7;
   305 		dst += dstskip;
   305             if (bit != ckey) {
   306 	}
   306                 SDL_memcpy(dst, &palmap[bit * 4], 3);
   307 }
   307             }
   308 
   308             byte <<= 1;
   309 static void BlitBto4Key(SDL_BlitInfo *info)
   309             dst += 3;
   310 {
   310         }
   311         int width = info->d_width;
   311         src += srcskip;
   312 	int height = info->d_height;
   312         dst += dstskip;
   313 	Uint8 *src = info->s_pixels;
   313     }
   314 	Uint32 *dstp = (Uint32 *)info->d_pixels;
   314 }
   315 	int srcskip = info->s_skip;
   315 
   316 	int dstskip = info->d_skip;
   316 static void
   317 	Uint32 ckey = info->src->colorkey;
   317 BlitBto4Key(SDL_BlitInfo * info)
   318 	Uint8 *palmap = info->table;
   318 {
   319 	int c;
   319     int width = info->d_width;
   320 
   320     int height = info->d_height;
   321 	/* Set up some basic variables */
   321     Uint8 *src = info->s_pixels;
   322 	srcskip += width-(width+7)/8;
   322     Uint32 *dstp = (Uint32 *) info->d_pixels;
   323 	dstskip /= 4;
   323     int srcskip = info->s_skip;
   324 
   324     int dstskip = info->d_skip;
   325 	while ( height-- ) {
   325     Uint32 ckey = info->src->colorkey;
   326 	        Uint8 byte = 0, bit;
   326     Uint8 *palmap = info->table;
   327 	    	for ( c=0; c<width; ++c ) {
   327     int c;
   328 			if ( (c&7) == 0 ) {
   328 
   329 				byte = *src++;
   329     /* Set up some basic variables */
   330 			}
   330     srcskip += width - (width + 7) / 8;
   331 			bit = (byte&0x80)>>7;
   331     dstskip /= 4;
   332 			if ( bit != ckey ) {
   332 
   333 				*dstp=((Uint32 *)palmap)[bit];
   333     while (height--) {
   334 			}
   334         Uint8 byte = 0, bit;
   335 			byte <<= 1;
   335         for (c = 0; c < width; ++c) {
   336 			dstp++;
   336             if ((c & 7) == 0) {
   337 		}
   337                 byte = *src++;
   338 		src += srcskip;
   338             }
   339 		dstp += dstskip;
   339             bit = (byte & 0x80) >> 7;
   340 	}
   340             if (bit != ckey) {
   341 }
   341                 *dstp = ((Uint32 *) palmap)[bit];
   342 
   342             }
   343 static void BlitBtoNAlpha(SDL_BlitInfo *info)
   343             byte <<= 1;
   344 {
   344             dstp++;
   345         int width = info->d_width;
   345         }
   346 	int height = info->d_height;
   346         src += srcskip;
   347 	Uint8 *src = info->s_pixels;
   347         dstp += dstskip;
   348 	Uint8 *dst = info->d_pixels;
   348     }
   349 	int srcskip = info->s_skip;
   349 }
   350 	int dstskip = info->d_skip;
   350 
   351 	const SDL_Color *srcpal	= info->src->palette->colors;
   351 static void
   352 	SDL_PixelFormat *dstfmt = info->dst;
   352 BlitBtoNAlpha(SDL_BlitInfo * info)
   353 	int  dstbpp;
   353 {
   354 	int c;
   354     int width = info->d_width;
   355 	const int A = info->src->alpha;
   355     int height = info->d_height;
   356 
   356     Uint8 *src = info->s_pixels;
   357 	/* Set up some basic variables */
   357     Uint8 *dst = info->d_pixels;
   358 	dstbpp = dstfmt->BytesPerPixel;
   358     int srcskip = info->s_skip;
   359 	srcskip += width-(width+7)/8;
   359     int dstskip = info->d_skip;
   360 
   360     const SDL_Color *srcpal = info->src->palette->colors;
   361 	while ( height-- ) {
   361     SDL_PixelFormat *dstfmt = info->dst;
   362 	        Uint8 byte = 0, bit;
   362     int dstbpp;
   363 	    	for ( c=0; c<width; ++c ) {
   363     int c;
   364 			if ( (c&7) == 0 ) {
   364     const int A = info->src->alpha;
   365 				byte = *src++;
   365 
   366 			}
   366     /* Set up some basic variables */
   367 			bit = (byte&0x80)>>7;
   367     dstbpp = dstfmt->BytesPerPixel;
   368 			if ( 1 ) {
   368     srcskip += width - (width + 7) / 8;
   369 			        Uint32 pixel;
   369 
   370 			        unsigned sR, sG, sB;
   370     while (height--) {
   371 				unsigned dR, dG, dB;
   371         Uint8 byte = 0, bit;
   372 				sR = srcpal[bit].r;
   372         for (c = 0; c < width; ++c) {
   373 				sG = srcpal[bit].g;
   373             if ((c & 7) == 0) {
   374 				sB = srcpal[bit].b;
   374                 byte = *src++;
   375 				DISEMBLE_RGB(dst, dstbpp, dstfmt,
   375             }
   376 							pixel, dR, dG, dB);
   376             bit = (byte & 0x80) >> 7;
   377 				ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
   377             if (1) {
   378 			  	ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
   378                 Uint32 pixel;
   379 			}
   379                 unsigned sR, sG, sB;
   380 			byte <<= 1;
   380                 unsigned dR, dG, dB;
   381 			dst += dstbpp;
   381                 sR = srcpal[bit].r;
   382 		}
   382                 sG = srcpal[bit].g;
   383 		src += srcskip;
   383                 sB = srcpal[bit].b;
   384 		dst += dstskip;
   384                 DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
   385 	}
   385                 ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
   386 }
   386                 ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
   387 
   387             }
   388 static void BlitBtoNAlphaKey(SDL_BlitInfo *info)
   388             byte <<= 1;
   389 {
   389             dst += dstbpp;
   390         int width = info->d_width;
   390         }
   391 	int height = info->d_height;
   391         src += srcskip;
   392 	Uint8 *src = info->s_pixels;
   392         dst += dstskip;
   393 	Uint8 *dst = info->d_pixels;
   393     }
   394 	int srcskip = info->s_skip;
   394 }
   395 	int dstskip = info->d_skip;
   395 
   396 	SDL_PixelFormat *srcfmt = info->src;
   396 static void
   397 	SDL_PixelFormat *dstfmt = info->dst;
   397 BlitBtoNAlphaKey(SDL_BlitInfo * info)
   398 	const SDL_Color *srcpal	= srcfmt->palette->colors;
   398 {
   399 	int dstbpp;
   399     int width = info->d_width;
   400 	int c;
   400     int height = info->d_height;
   401 	const int A = srcfmt->alpha;
   401     Uint8 *src = info->s_pixels;
   402 	Uint32 ckey = srcfmt->colorkey;
   402     Uint8 *dst = info->d_pixels;
   403 
   403     int srcskip = info->s_skip;
   404 	/* Set up some basic variables */
   404     int dstskip = info->d_skip;
   405 	dstbpp = dstfmt->BytesPerPixel;
   405     SDL_PixelFormat *srcfmt = info->src;
   406 	srcskip += width-(width+7)/8;
   406     SDL_PixelFormat *dstfmt = info->dst;
   407 
   407     const SDL_Color *srcpal = srcfmt->palette->colors;
   408 	while ( height-- ) {
   408     int dstbpp;
   409 	        Uint8  byte = 0, bit;
   409     int c;
   410 	    	for ( c=0; c<width; ++c ) {
   410     const int A = srcfmt->alpha;
   411 			if ( (c&7) == 0 ) {
   411     Uint32 ckey = srcfmt->colorkey;
   412 				byte = *src++;
   412 
   413 			}
   413     /* Set up some basic variables */
   414 			bit = (byte&0x80)>>7;
   414     dstbpp = dstfmt->BytesPerPixel;
   415 			if ( bit != ckey ) {
   415     srcskip += width - (width + 7) / 8;
   416 			        int sR, sG, sB;
   416 
   417 				int dR, dG, dB;
   417     while (height--) {
   418 				Uint32 pixel;
   418         Uint8 byte = 0, bit;
   419 				sR = srcpal[bit].r;
   419         for (c = 0; c < width; ++c) {
   420 				sG = srcpal[bit].g;
   420             if ((c & 7) == 0) {
   421 				sB = srcpal[bit].b;
   421                 byte = *src++;
   422 				DISEMBLE_RGB(dst, dstbpp, dstfmt,
   422             }
   423 							pixel, dR, dG, dB);
   423             bit = (byte & 0x80) >> 7;
   424 				ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
   424             if (bit != ckey) {
   425 			  	ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
   425                 int sR, sG, sB;
   426 			}
   426                 int dR, dG, dB;
   427 			byte <<= 1;
   427                 Uint32 pixel;
   428 			dst += dstbpp;
   428                 sR = srcpal[bit].r;
   429 		}
   429                 sG = srcpal[bit].g;
   430 		src += srcskip;
   430                 sB = srcpal[bit].b;
   431 		dst += dstskip;
   431                 DISEMBLE_RGB(dst, dstbpp, dstfmt, pixel, dR, dG, dB);
   432 	}
   432                 ALPHA_BLEND(sR, sG, sB, A, dR, dG, dB);
       
   433                 ASSEMBLE_RGB(dst, dstbpp, dstfmt, dR, dG, dB);
       
   434             }
       
   435             byte <<= 1;
       
   436             dst += dstbpp;
       
   437         }
       
   438         src += srcskip;
       
   439         dst += dstskip;
       
   440     }
   433 }
   441 }
   434 
   442 
   435 static SDL_loblit bitmap_blit[] = {
   443 static SDL_loblit bitmap_blit[] = {
   436 	NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
   444     NULL, BlitBto1, BlitBto2, BlitBto3, BlitBto4
   437 };
   445 };
   438 
   446 
   439 static SDL_loblit colorkey_blit[] = {
   447 static SDL_loblit colorkey_blit[] = {
   440     NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
   448     NULL, BlitBto1Key, BlitBto2Key, BlitBto3Key, BlitBto4Key
   441 };
   449 };
   442 
   450 
   443 SDL_loblit SDL_CalculateBlit0(SDL_Surface *surface, int blit_index)
   451 SDL_loblit
   444 {
   452 SDL_CalculateBlit0(SDL_Surface * surface, int blit_index)
   445 	int which;
   453 {
   446 
   454     int which;
   447 	if ( surface->format->BitsPerPixel != 1 ) {
   455 
   448 		/* We don't support sub 8-bit packed pixel modes */
   456     if (surface->format->BitsPerPixel != 1) {
   449 		return NULL;
   457         /* We don't support sub 8-bit packed pixel modes */
   450 	}
   458         return NULL;
   451 	if ( surface->map->dst->format->BitsPerPixel < 8 ) {
   459     }
   452 		which = 0;
   460     if (surface->map->dst->format->BitsPerPixel < 8) {
   453 	} else {
   461         which = 0;
   454 		which = surface->map->dst->format->BytesPerPixel;
   462     } else {
   455 	}
   463         which = surface->map->dst->format->BytesPerPixel;
   456 	switch(blit_index) {
   464     }
   457 	case 0:			/* copy */
   465     switch (blit_index) {
   458 	    return bitmap_blit[which];
   466     case 0:                    /* copy */
   459 
   467         return bitmap_blit[which];
   460 	case 1:			/* colorkey */
   468 
   461 	    return colorkey_blit[which];
   469     case 1:                    /* colorkey */
   462 
   470         return colorkey_blit[which];
   463 	case 2:			/* alpha */
   471 
   464 	    return which >= 2 ? BlitBtoNAlpha : NULL;
   472     case 2:                    /* alpha */
   465 
   473         return which >= 2 ? BlitBtoNAlpha : NULL;
   466 	case 4:			/* alpha + colorkey */
   474 
   467 	    return which >= 2 ? BlitBtoNAlphaKey : NULL;
   475     case 4:                    /* alpha + colorkey */
   468 	}
   476         return which >= 2 ? BlitBtoNAlphaKey : NULL;
   469 	return NULL;
   477     }
   470 }
   478     return NULL;
   471 
   479 }
       
   480 
       
   481 /* vi: set ts=4 sw=4 expandtab: */