comparison src/video/SDL_blit.c @ 2263:900c35d8e8fd

More work in progress, still doesn't compile...
author Sam Lantinga <slouken@libsdl.org>
date Fri, 17 Aug 2007 06:40:12 +0000
parents bee005ace1bf
children 265bb136af92
comparison
equal deleted inserted replaced
2262:bee005ace1bf 2263:900c35d8e8fd
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #include "SDL_video.h" 24 #include "SDL_video.h"
25 #include "SDL_sysvideo.h" 25 #include "SDL_sysvideo.h"
26 #include "SDL_blit.h" 26 #include "SDL_blit.h"
27 #include "SDL_blit_auto.h"
27 #include "SDL_blit_copy.h" 28 #include "SDL_blit_copy.h"
28 #include "SDL_RLEaccel_c.h" 29 #include "SDL_RLEaccel_c.h"
29 #include "SDL_pixels_c.h" 30 #include "SDL_pixels_c.h"
30 31
31 /* The general purpose software blit routine */ 32 /* The general purpose software blit routine */
59 } 60 }
60 } 61 }
61 62
62 /* Set up source and destination buffer pointers, and BLIT! */ 63 /* Set up source and destination buffer pointers, and BLIT! */
63 if (okay && srcrect->w && srcrect->h) { 64 if (okay && srcrect->w && srcrect->h) {
65 SDL_BlitFunc RunBlit;
64 SDL_BlitInfo *info = &src->map->info; 66 SDL_BlitInfo *info = &src->map->info;
65 67
66 /* Set up the blit information */ 68 /* Set up the blit information */
67 info->src = (Uint8 *) src->pixels + 69 info->src = (Uint8 *) src->pixels +
68 (Uint16) srcrect->y * src->pitch + 70 (Uint16) srcrect->y * src->pitch +
69 (Uint16) srcrect->x * info->src_fmt->BytesPerPixel; 71 (Uint16) srcrect->x * info->src_fmt->BytesPerPixel;
70 info.src_w = srcrect->w; 72 info->src_w = srcrect->w;
71 info.src_h = srcrect->h; 73 info->src_h = srcrect->h;
72 info.dst = (Uint8 *) dst->pixels + 74 info->dst = (Uint8 *) dst->pixels +
73 (Uint16) dstrect->y * dst->pitch + 75 (Uint16) dstrect->y * dst->pitch +
74 (Uint16) dstrect->x * info->dst_fmt->BytesPerPixel; 76 (Uint16) dstrect->x * info->dst_fmt->BytesPerPixel;
75 info.dst_w = dstrect->w; 77 info->dst_w = dstrect->w;
76 info.dst_h = dstrect->h; 78 info->dst_h = dstrect->h;
77 RunBlit = (SDL_BlitFunc) src->map->data; 79 RunBlit = (SDL_BlitFunc) src->map->data;
78 80
79 /* Run the actual software blit */ 81 /* Run the actual software blit */
80 RunBlit(info); 82 RunBlit(info);
81 } 83 }
115 return SDL_TRUE; 117 return SDL_TRUE;
116 } 118 }
117 #endif /* __MACOSX__ */ 119 #endif /* __MACOSX__ */
118 120
119 static SDL_BlitFunc 121 static SDL_BlitFunc
120 SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, SDL_BlitEntry * entries) 122 SDL_ChooseBlitFunc(Uint32 src_format, Uint32 dst_format, int flags, SDL_BlitFuncEntry * entries)
121 { 123 {
122 int i; 124 int i;
123 static Uint32 features = 0xffffffff; 125 static Uint32 features = 0xffffffff;
124 126
125 /* Get the available CPU features */ 127 /* Get the available CPU features */
152 } 154 }
153 } 155 }
154 } 156 }
155 } 157 }
156 158
157 for (i = 0; entries[i].blit; ++i) { 159 for (i = 0; entries[i].func; ++i) {
158 if (src_format != entries[i].src_format) { 160 if (src_format != entries[i].src_format) {
159 continue; 161 continue;
160 } 162 }
161 if (dst_format != entries[i].dst_format) { 163 if (dst_format != entries[i].dst_format) {
162 continue; 164 continue;
175 /* Figure out which of many blit routines to set up on a surface */ 177 /* Figure out which of many blit routines to set up on a surface */
176 int 178 int
177 SDL_CalculateBlit(SDL_Surface * surface) 179 SDL_CalculateBlit(SDL_Surface * surface)
178 { 180 {
179 SDL_BlitFunc blit = NULL; 181 SDL_BlitFunc blit = NULL;
180 int blit_index; 182 SDL_Surface *dst = surface->map->dst;
183 Uint32 src_format;
184 Uint32 dst_format;
181 185
182 /* Clean everything out to start */ 186 /* Clean everything out to start */
183 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { 187 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
184 SDL_UnRLESurface(surface, 1); 188 SDL_UnRLESurface(surface, 1);
185 } 189 }
186 surface->map->blit = NULL; 190 surface->map->blit = NULL;
187 191 surface->map->info.src_fmt = surface->format;
188 /* Get the blit function index, based on surface mode */ 192 surface->map->info.src_pitch = surface->pitch;
189 /* { 0 = nothing, 1 = colorkey, 2 = alpha, 3 = colorkey+alpha } */ 193 surface->map->info.dst_fmt = dst->format;
190 blit_index = 0; 194 surface->map->info.dst_pitch = dst->pitch;
191 blit_index |= (!!(surface->flags & SDL_SRCCOLORKEY)) << 0; 195
192 if (surface->flags & SDL_SRCALPHA 196 src_format = SDL_MasksToPixelFormatEnum(surface->format->BitsPerPixel, surface->format->Rmask, surface->format->Gmask, surface->format->Bmask, surface->format->Amask);
193 && ((surface->map->cmod >> 24) != SDL_ALPHA_OPAQUE 197 dst_format = SDL_MasksToPixelFormatEnum(dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask);
194 || surface->format->Amask)) {
195 blit_index |= 2;
196 }
197 198
198 /* Check for special "identity" case -- copy blit */ 199 /* Check for special "identity" case -- copy blit */
199 if (surface->map->identity && blit_index == 0) { 200 if (surface->map->identity && !surface->map->info.flags) {
200 /* Handle overlapping blits on the same surface */ 201 /* Handle overlapping blits on the same surface */
201 if (surface == surface->map->dst) { 202 if (surface == dst) {
202 blit = SDL_BlitCopyOverlap; 203 blit = SDL_BlitCopyOverlap;
203 } else { 204 } else {
204 blit = SDL_BlitCopy; 205 blit = SDL_BlitCopy;
205 } 206 }
206 } else { 207 } else {
207 if (surface->format->BitsPerPixel < 8) { 208 if (surface->format->BitsPerPixel < 8) {
208 blit = SDL_CalculateBlit0(surface, blit_index); 209 blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTable0);
209 } else { 210 } else {
210 switch (surface->format->BytesPerPixel) { 211 switch (surface->format->BytesPerPixel) {
211 case 1: 212 case 1:
212 blit = SDL_CalculateBlit1(surface, blit_index); 213 blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTable1);
213 break; 214 break;
214 case 2: 215 case 2:
215 case 3: 216 case 3:
216 case 4: 217 case 4:
217 blit = SDL_CalculateBlitN(surface, blit_index); 218 blit = SDL_ChooseBlitFunc(src_format, dst_format, surface->map->info.flags, SDL_BlitFuncTableN);
218 break; 219 break;
219 } 220 }
220 } 221 }
221 } 222 }
222 if (blit == NULL) { 223 if (blit == NULL) {