Perform a fast, low quality, stretch blit between two surfaces of the same pixel format.
205{
206 int src_locked;
207 int dst_locked;
208 int pos, inc;
209 int dst_maxrow;
210 int src_row, dst_row;
215#ifdef USE_ASM_STRETCH
217#ifdef __GNUC__
219#endif
220#endif
221 const int bpp =
dst->format->BytesPerPixel;
222
223 if (
src->format->format !=
dst->format->format) {
224 return SDL_SetError(
"Only works with same format surfaces");
225 }
226
227
228 if (srcrect) {
229 if ((srcrect->
x < 0) || (srcrect->
y < 0) ||
230 ((srcrect->
x + srcrect->
w) >
src->w) ||
231 ((srcrect->
y + srcrect->
h) >
src->h)) {
233 }
234 } else {
239 srcrect = &full_src;
240 }
241 if (dstrect) {
242 if ((dstrect->
x < 0) || (dstrect->
y < 0) ||
243 ((dstrect->
x + dstrect->
w) >
dst->w) ||
244 ((dstrect->
y + dstrect->
h) >
dst->h)) {
245 return SDL_SetError(
"Invalid destination blit rectangle");
246 }
247 } else {
252 dstrect = &full_dst;
253 }
254
255
256 dst_locked = 0;
259 return SDL_SetError(
"Unable to lock destination surface");
260 }
261 dst_locked = 1;
262 }
263
264 src_locked = 0;
267 if (dst_locked) {
269 }
271 }
272 src_locked = 1;
273 }
274
275
276 pos = 0x10000;
277 inc = (srcrect->
h << 16) / dstrect->
h;
278 src_row = srcrect->
y;
279 dst_row = dstrect->
y;
280
281#ifdef USE_ASM_STRETCH
282
283 if ((bpp == 3) || (generate_rowbytes(srcrect->
w, dstrect->
w, bpp) < 0)) {
285 }
286#endif
287
288
289 for (dst_maxrow = dst_row + dstrect->
h; dst_row < dst_maxrow; ++dst_row) {
290 dstp = (
Uint8 *)
dst->pixels + (dst_row *
dst->pitch)
291 + (dstrect->
x * bpp);
292 while (pos >= 0x10000L) {
293 srcp = (
Uint8 *)
src->pixels + (src_row *
src->pitch)
294 + (srcrect->
x * bpp);
295 ++src_row;
296 pos -= 0x10000L;
297 }
298#ifdef USE_ASM_STRETCH
299 if (use_asm) {
300#ifdef __GNUC__
301 __asm__ __volatile__(
"call *%4":
"=&D"(
u1),
"=&S"(
u2)
302 :"0"(dstp), "1"(srcp), "r"(copy_row)
303 :"memory");
304#elif defined(_MSC_VER) || defined(__WATCOMC__)
305
306 {
307 void *code = copy_row;
308 __asm {
309 push edi
310 push esi
311 mov edi, dstp
312 mov esi, srcp
313 call dword ptr code
316 }
317 }
318
319#else
320#error Need inline assembly for this compiler
321#endif
322 } else
323#endif
324 switch (bpp) {
325 case 1:
326 copy_row1(srcp, srcrect->
w, dstp, dstrect->
w);
327 break;
328 case 2:
329 copy_row2((
Uint16 *) srcp, srcrect->
w,
331 break;
332 case 3:
334 break;
335 case 4:
336 copy_row4((
Uint32 *) srcp, srcrect->
w,
338 break;
339 }
340 pos += inc;
341 }
342
343
344 if (dst_locked) {
346 }
347 if (src_locked) {
349 }
350 return (0);
351}
#define SDL_UnlockSurface
static void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w)
A rectangle, with the origin at the upper left (integer).