Mercurial > sdl-ios-xcode
comparison src/video/SDL_stretch.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
54 #endif | 54 #endif |
55 | 55 |
56 static unsigned char copy_row[4096]; | 56 static unsigned char copy_row[4096]; |
57 | 57 |
58 static int | 58 static int |
59 generate_rowbytes (int src_w, int dst_w, int bpp) | 59 generate_rowbytes(int src_w, int dst_w, int bpp) |
60 { | 60 { |
61 static struct | 61 static struct |
62 { | 62 { |
63 int bpp; | 63 int bpp; |
64 int src_w; | 64 int src_w; |
87 case 4: | 87 case 4: |
88 load = LOAD_WORD; | 88 load = LOAD_WORD; |
89 store = STORE_WORD; | 89 store = STORE_WORD; |
90 break; | 90 break; |
91 default: | 91 default: |
92 SDL_SetError ("ASM stretch of %d bytes isn't supported\n", bpp); | 92 SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); |
93 return (-1); | 93 return (-1); |
94 } | 94 } |
95 pos = 0x10000; | 95 pos = 0x10000; |
96 inc = (src_w << 16) / dst_w; | 96 inc = (src_w << 16) / dst_w; |
97 eip = copy_row; | 97 eip = copy_row; |
110 pos += inc; | 110 pos += inc; |
111 } | 111 } |
112 *eip++ = RETURN; | 112 *eip++ = RETURN; |
113 | 113 |
114 /* Verify that we didn't overflow (too late) */ | 114 /* Verify that we didn't overflow (too late) */ |
115 if (eip > (copy_row + sizeof (copy_row))) { | 115 if (eip > (copy_row + sizeof(copy_row))) { |
116 SDL_SetError ("Copy buffer overflow"); | 116 SDL_SetError("Copy buffer overflow"); |
117 return (-1); | 117 return (-1); |
118 } | 118 } |
119 return (0); | 119 return (0); |
120 } | 120 } |
121 | 121 |
137 } \ | 137 } \ |
138 *dst++ = pixel; \ | 138 *dst++ = pixel; \ |
139 pos += inc; \ | 139 pos += inc; \ |
140 } \ | 140 } \ |
141 } | 141 } |
142 DEFINE_COPY_ROW (copy_row1, Uint8) | 142 DEFINE_COPY_ROW(copy_row1, Uint8) |
143 DEFINE_COPY_ROW (copy_row2, Uint16) DEFINE_COPY_ROW (copy_row4, Uint32) | 143 DEFINE_COPY_ROW(copy_row2, Uint16) DEFINE_COPY_ROW(copy_row4, Uint32) |
144 #endif /* USE_ASM_STRETCH */ | 144 #endif /* USE_ASM_STRETCH */ |
145 /* The ASM code doesn't handle 24-bpp stretch blits */ | 145 /* The ASM code doesn't handle 24-bpp stretch blits */ |
146 void | 146 void |
147 copy_row3 (Uint8 * src, int src_w, Uint8 * dst, int dst_w) | 147 copy_row3(Uint8 * src, int src_w, Uint8 * dst, int dst_w) |
148 { | 148 { |
149 int i; | 149 int i; |
150 int pos, inc; | 150 int pos, inc; |
151 Uint8 pixel[3]; | 151 Uint8 pixel[3]; |
152 | 152 |
168 | 168 |
169 /* Perform a stretch blit between two surfaces of the same format. | 169 /* Perform a stretch blit between two surfaces of the same format. |
170 NOTE: This function is not safe to call from multiple threads! | 170 NOTE: This function is not safe to call from multiple threads! |
171 */ | 171 */ |
172 int | 172 int |
173 SDL_SoftStretch (SDL_Surface * src, SDL_Rect * srcrect, | 173 SDL_SoftStretch(SDL_Surface * src, SDL_Rect * srcrect, |
174 SDL_Surface * dst, SDL_Rect * dstrect) | 174 SDL_Surface * dst, SDL_Rect * dstrect) |
175 { | 175 { |
176 int src_locked; | 176 int src_locked; |
177 int dst_locked; | 177 int dst_locked; |
178 int pos, inc; | 178 int pos, inc; |
179 int dst_width; | 179 int dst_width; |
187 int u1, u2; | 187 int u1, u2; |
188 #endif | 188 #endif |
189 const int bpp = dst->format->BytesPerPixel; | 189 const int bpp = dst->format->BytesPerPixel; |
190 | 190 |
191 if (src->format->BitsPerPixel != dst->format->BitsPerPixel) { | 191 if (src->format->BitsPerPixel != dst->format->BitsPerPixel) { |
192 SDL_SetError ("Only works with same format surfaces"); | 192 SDL_SetError("Only works with same format surfaces"); |
193 return (-1); | 193 return (-1); |
194 } | 194 } |
195 | 195 |
196 /* Verify the blit rectangles */ | 196 /* Verify the blit rectangles */ |
197 if (srcrect) { | 197 if (srcrect) { |
198 if ((srcrect->x < 0) || (srcrect->y < 0) || | 198 if ((srcrect->x < 0) || (srcrect->y < 0) || |
199 ((srcrect->x + srcrect->w) > src->w) || | 199 ((srcrect->x + srcrect->w) > src->w) || |
200 ((srcrect->y + srcrect->h) > src->h)) { | 200 ((srcrect->y + srcrect->h) > src->h)) { |
201 SDL_SetError ("Invalid source blit rectangle"); | 201 SDL_SetError("Invalid source blit rectangle"); |
202 return (-1); | 202 return (-1); |
203 } | 203 } |
204 } else { | 204 } else { |
205 full_src.x = 0; | 205 full_src.x = 0; |
206 full_src.y = 0; | 206 full_src.y = 0; |
210 } | 210 } |
211 if (dstrect) { | 211 if (dstrect) { |
212 if ((dstrect->x < 0) || (dstrect->y < 0) || | 212 if ((dstrect->x < 0) || (dstrect->y < 0) || |
213 ((dstrect->x + dstrect->w) > dst->w) || | 213 ((dstrect->x + dstrect->w) > dst->w) || |
214 ((dstrect->y + dstrect->h) > dst->h)) { | 214 ((dstrect->y + dstrect->h) > dst->h)) { |
215 SDL_SetError ("Invalid destination blit rectangle"); | 215 SDL_SetError("Invalid destination blit rectangle"); |
216 return (-1); | 216 return (-1); |
217 } | 217 } |
218 } else { | 218 } else { |
219 full_dst.x = 0; | 219 full_dst.x = 0; |
220 full_dst.y = 0; | 220 full_dst.y = 0; |
223 dstrect = &full_dst; | 223 dstrect = &full_dst; |
224 } | 224 } |
225 | 225 |
226 /* Lock the destination if it's in hardware */ | 226 /* Lock the destination if it's in hardware */ |
227 dst_locked = 0; | 227 dst_locked = 0; |
228 if (SDL_MUSTLOCK (dst)) { | 228 if (SDL_MUSTLOCK(dst)) { |
229 if (SDL_LockSurface (dst) < 0) { | 229 if (SDL_LockSurface(dst) < 0) { |
230 SDL_SetError ("Unable to lock destination surface"); | 230 SDL_SetError("Unable to lock destination surface"); |
231 return (-1); | 231 return (-1); |
232 } | 232 } |
233 dst_locked = 1; | 233 dst_locked = 1; |
234 } | 234 } |
235 /* Lock the source if it's in hardware */ | 235 /* Lock the source if it's in hardware */ |
236 src_locked = 0; | 236 src_locked = 0; |
237 if (SDL_MUSTLOCK (src)) { | 237 if (SDL_MUSTLOCK(src)) { |
238 if (SDL_LockSurface (src) < 0) { | 238 if (SDL_LockSurface(src) < 0) { |
239 if (dst_locked) { | 239 if (dst_locked) { |
240 SDL_UnlockSurface (dst); | 240 SDL_UnlockSurface(dst); |
241 } | 241 } |
242 SDL_SetError ("Unable to lock source surface"); | 242 SDL_SetError("Unable to lock source surface"); |
243 return (-1); | 243 return (-1); |
244 } | 244 } |
245 src_locked = 1; | 245 src_locked = 1; |
246 } | 246 } |
247 | 247 |
252 dst_row = dstrect->y; | 252 dst_row = dstrect->y; |
253 dst_width = dstrect->w * bpp; | 253 dst_width = dstrect->w * bpp; |
254 | 254 |
255 #ifdef USE_ASM_STRETCH | 255 #ifdef USE_ASM_STRETCH |
256 /* Write the opcodes for this stretch */ | 256 /* Write the opcodes for this stretch */ |
257 if ((bpp != 3) && (generate_rowbytes (srcrect->w, dstrect->w, bpp) < 0)) { | 257 if ((bpp != 3) && (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0)) { |
258 return (-1); | 258 return (-1); |
259 } | 259 } |
260 #endif | 260 #endif |
261 | 261 |
262 /* Perform the stretch blit */ | 262 /* Perform the stretch blit */ |
270 pos -= 0x10000L; | 270 pos -= 0x10000L; |
271 } | 271 } |
272 #ifdef USE_ASM_STRETCH | 272 #ifdef USE_ASM_STRETCH |
273 switch (bpp) { | 273 switch (bpp) { |
274 case 3: | 274 case 3: |
275 copy_row3 (srcp, srcrect->w, dstp, dstrect->w); | 275 copy_row3(srcp, srcrect->w, dstp, dstrect->w); |
276 break; | 276 break; |
277 default: | 277 default: |
278 #ifdef __GNUC__ | 278 #ifdef __GNUC__ |
279 __asm__ __volatile__ ("call *%4": "=&D" (u1), "=&S" (u2): "0" (dstp), "1" (srcp), "r" (copy_row):"memory"); | 279 __asm__ __volatile__("call *%4": "=&D"(u1), "=&S"(u2): "0"(dstp), "1"(srcp), "r"(copy_row):"memory"); |
280 #elif defined(_MSC_VER) || defined(__WATCOMC__) | 280 #elif defined(_MSC_VER) || defined(__WATCOMC__) |
281 { | 281 { |
282 void *code = copy_row; | 282 void *code = copy_row; |
283 __asm { | 283 __asm { |
284 push edi | 284 push edi |
292 break; | 292 break; |
293 } | 293 } |
294 #else | 294 #else |
295 switch (bpp) { | 295 switch (bpp) { |
296 case 1: | 296 case 1: |
297 copy_row1 (srcp, srcrect->w, dstp, dstrect->w); | 297 copy_row1(srcp, srcrect->w, dstp, dstrect->w); |
298 break; | 298 break; |
299 case 2: | 299 case 2: |
300 copy_row2 ((Uint16 *) srcp, srcrect->w, | 300 copy_row2((Uint16 *) srcp, srcrect->w, |
301 (Uint16 *) dstp, dstrect->w); | 301 (Uint16 *) dstp, dstrect->w); |
302 break; | 302 break; |
303 case 3: | 303 case 3: |
304 copy_row3 (srcp, srcrect->w, dstp, dstrect->w); | 304 copy_row3(srcp, srcrect->w, dstp, dstrect->w); |
305 break; | 305 break; |
306 case 4: | 306 case 4: |
307 copy_row4 ((Uint32 *) srcp, srcrect->w, | 307 copy_row4((Uint32 *) srcp, srcrect->w, |
308 (Uint32 *) dstp, dstrect->w); | 308 (Uint32 *) dstp, dstrect->w); |
309 break; | 309 break; |
310 } | 310 } |
311 #endif | 311 #endif |
312 pos += inc; | 312 pos += inc; |
313 } | 313 } |
314 | 314 |
315 /* We need to unlock the surfaces if they're locked */ | 315 /* We need to unlock the surfaces if they're locked */ |
316 if (dst_locked) { | 316 if (dst_locked) { |
317 SDL_UnlockSurface (dst); | 317 SDL_UnlockSurface(dst); |
318 } | 318 } |
319 if (src_locked) { | 319 if (src_locked) { |
320 SDL_UnlockSurface (src); | 320 SDL_UnlockSurface(src); |
321 } | 321 } |
322 return (0); | 322 return (0); |
323 } | 323 } |
324 | 324 |
325 /* vi: set ts=4 sw=4 expandtab: */ | 325 /* vi: set ts=4 sw=4 expandtab: */ |