Mercurial > sdl-ios-xcode
annotate src/video/SDL_stretch.c @ 3405:d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 18 Oct 2009 17:49:40 +0000 |
parents | 99210400e8b9 |
children | 8ae607392409 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
2859 | 3 Copyright (C) 1997-2009 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1234
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1234
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1234
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1234
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1234
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1234
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* This a stretch blit implementation based on ideas given to me by | |
25 Tomasz Cejner - thanks! :) | |
26 | |
27 April 27, 2000 - Sam Lantinga | |
28 */ | |
29 | |
30 #include "SDL_video.h" | |
31 #include "SDL_blit.h" | |
32 | |
33 /* This isn't ready for general consumption yet - it should be folded | |
34 into the general blitting mechanism. | |
35 */ | |
36 | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
37 #if ((defined(_MFC_VER) && defined(_M_IX86)/* && !defined(_WIN32_WCE) still needed? */) || \ |
1442
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
38 defined(__WATCOMC__) || \ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
39 (defined(__GNUC__) && defined(__i386__))) && SDL_ASSEMBLY_ROUTINES |
0 | 40 #define USE_ASM_STRETCH |
41 #endif | |
42 | |
43 #ifdef USE_ASM_STRETCH | |
44 | |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
45 #ifdef HAVE_MPROTECT |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
46 #include <sys/types.h> |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
47 #include <sys/mman.h> |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
48 #endif |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
49 #ifdef __GNUC__ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
50 #define PAGE_ALIGNED __attribute__((__aligned__(4096))) |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
51 #else |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
52 #define PAGE_ALIGNED |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
53 #endif |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
54 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
55 #if defined(_M_IX86) || defined(i386) |
0 | 56 #define PREFIX16 0x66 |
57 #define STORE_BYTE 0xAA | |
58 #define STORE_WORD 0xAB | |
59 #define LOAD_BYTE 0xAC | |
60 #define LOAD_WORD 0xAD | |
61 #define RETURN 0xC3 | |
62 #else | |
63 #error Need assembly opcodes for this architecture | |
64 #endif | |
65 | |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
66 static unsigned char copy_row[4096] PAGE_ALIGNED; |
0 | 67 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
68 static int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
69 generate_rowbytes(int src_w, int dst_w, int bpp) |
0 | 70 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
71 static struct |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
72 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
73 int bpp; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
74 int src_w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
75 int dst_w; |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
76 int status; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
77 } last; |
0 | 78 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
79 int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
80 int pos, inc; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
81 unsigned char *eip; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
82 unsigned char load, store; |
0 | 83 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
84 /* See if we need to regenerate the copy buffer */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
85 if ((src_w == last.src_w) && (dst_w == last.dst_w) && (bpp == last.bpp)) { |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
86 return (last.status); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
87 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
88 last.bpp = bpp; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
89 last.src_w = src_w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
90 last.dst_w = dst_w; |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
91 last.status = -1; |
0 | 92 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
93 switch (bpp) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
94 case 1: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
95 load = LOAD_BYTE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
96 store = STORE_BYTE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
97 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
98 case 2: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
99 case 4: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
100 load = LOAD_WORD; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
101 store = STORE_WORD; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
102 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
103 default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
104 SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
105 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
106 } |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
107 #ifdef HAVE_MPROTECT |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
108 /* Make the code writeable */ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
109 if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_WRITE) < 0) { |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
110 SDL_SetError("Couldn't make copy buffer writeable"); |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
111 return (-1); |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
112 } |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
113 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
114 pos = 0x10000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
115 inc = (src_w << 16) / dst_w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
116 eip = copy_row; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
117 for (i = 0; i < dst_w; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
118 while (pos >= 0x10000L) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
119 if (bpp == 2) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
120 *eip++ = PREFIX16; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
121 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
122 *eip++ = load; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
123 pos -= 0x10000L; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
124 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
125 if (bpp == 2) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
126 *eip++ = PREFIX16; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
127 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
128 *eip++ = store; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
129 pos += inc; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
130 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
131 *eip++ = RETURN; |
0 | 132 |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
133 /* Verify that we didn't overflow (too late!!!) */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
134 if (eip > (copy_row + sizeof(copy_row))) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
135 SDL_SetError("Copy buffer overflow"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
136 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
137 } |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
138 #ifdef HAVE_MPROTECT |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
139 /* Make the code executable but not writeable */ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
140 if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) { |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
141 SDL_SetError("Couldn't make copy buffer executable"); |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
142 return (-1); |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
143 } |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
144 #endif |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
145 last.status = 0; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
146 return (0); |
0 | 147 } |
148 | |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
149 #endif /* USE_ASM_STRETCH */ |
0 | 150 |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
151 #define DEFINE_COPY_ROW(name, type) \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
152 void name(type *src, int src_w, type *dst, int dst_w) \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
153 { \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
154 int i; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
155 int pos, inc; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
156 type pixel = 0; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
157 \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
158 pos = 0x10000; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
159 inc = (src_w << 16) / dst_w; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
160 for ( i=dst_w; i>0; --i ) { \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
161 while ( pos >= 0x10000L ) { \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
162 pixel = *src++; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
163 pos -= 0x10000L; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
164 } \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
165 *dst++ = pixel; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
166 pos += inc; \ |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
167 } \ |
0 | 168 } |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
169 /* *INDENT-OFF* */ |
0 | 170 DEFINE_COPY_ROW(copy_row1, Uint8) |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
171 DEFINE_COPY_ROW(copy_row2, Uint16) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
172 DEFINE_COPY_ROW(copy_row4, Uint32) |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
173 /* *INDENT-ON* */ |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
174 |
0 | 175 /* The ASM code doesn't handle 24-bpp stretch blits */ |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
176 void |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
177 copy_row3(Uint8 * src, int src_w, Uint8 * dst, int dst_w) |
0 | 178 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
179 int i; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
180 int pos, inc; |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
181 Uint8 pixel[3] = { 0, 0, 0 }; |
0 | 182 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
183 pos = 0x10000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
184 inc = (src_w << 16) / dst_w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
185 for (i = dst_w; i > 0; --i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
186 while (pos >= 0x10000L) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
187 pixel[0] = *src++; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
188 pixel[1] = *src++; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
189 pixel[2] = *src++; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
190 pos -= 0x10000L; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
191 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
192 *dst++ = pixel[0]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
193 *dst++ = pixel[1]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
194 *dst++ = pixel[2]; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
195 pos += inc; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
196 } |
0 | 197 } |
198 | |
199 /* Perform a stretch blit between two surfaces of the same format. | |
200 NOTE: This function is not safe to call from multiple threads! | |
201 */ | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
202 int |
2828
7e5ff6cd05bf
Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents:
1985
diff
changeset
|
203 SDL_SoftStretch(SDL_Surface * src, const SDL_Rect * srcrect, |
7e5ff6cd05bf
Added very slow software scaling to the X11 renderer
Sam Lantinga <slouken@libsdl.org>
parents:
1985
diff
changeset
|
204 SDL_Surface * dst, const SDL_Rect * dstrect) |
0 | 205 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
206 int src_locked; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
207 int dst_locked; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
208 int pos, inc; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
209 int dst_width; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
210 int dst_maxrow; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
211 int src_row, dst_row; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
212 Uint8 *srcp = NULL; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
213 Uint8 *dstp; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
214 SDL_Rect full_src; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
215 SDL_Rect full_dst; |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
216 #ifdef USE_ASM_STRETCH |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
217 SDL_bool use_asm = SDL_TRUE; |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
218 #ifdef __GNUC__ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
219 int u1, u2; |
0 | 220 #endif |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
221 #endif /* USE_ASM_STRETCH */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
222 const int bpp = dst->format->BytesPerPixel; |
0 | 223 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
224 if (src->format->BitsPerPixel != dst->format->BitsPerPixel) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
225 SDL_SetError("Only works with same format surfaces"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
226 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
227 } |
0 | 228 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
229 /* Verify the blit rectangles */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
230 if (srcrect) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
231 if ((srcrect->x < 0) || (srcrect->y < 0) || |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
232 ((srcrect->x + srcrect->w) > src->w) || |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
233 ((srcrect->y + srcrect->h) > src->h)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
234 SDL_SetError("Invalid source blit rectangle"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
235 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
236 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
237 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
238 full_src.x = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
239 full_src.y = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
240 full_src.w = src->w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
241 full_src.h = src->h; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
242 srcrect = &full_src; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
243 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
244 if (dstrect) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
245 if ((dstrect->x < 0) || (dstrect->y < 0) || |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
246 ((dstrect->x + dstrect->w) > dst->w) || |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
247 ((dstrect->y + dstrect->h) > dst->h)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
248 SDL_SetError("Invalid destination blit rectangle"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
249 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
250 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
251 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
252 full_dst.x = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
253 full_dst.y = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
254 full_dst.w = dst->w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
255 full_dst.h = dst->h; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
256 dstrect = &full_dst; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
257 } |
0 | 258 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
259 /* Lock the destination if it's in hardware */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
260 dst_locked = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
261 if (SDL_MUSTLOCK(dst)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
262 if (SDL_LockSurface(dst) < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
263 SDL_SetError("Unable to lock destination surface"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
264 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
265 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
266 dst_locked = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
267 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
268 /* Lock the source if it's in hardware */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
269 src_locked = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
270 if (SDL_MUSTLOCK(src)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
271 if (SDL_LockSurface(src) < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
272 if (dst_locked) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
273 SDL_UnlockSurface(dst); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
274 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
275 SDL_SetError("Unable to lock source surface"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
276 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
277 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
278 src_locked = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
279 } |
894
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
280 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
281 /* Set up the data... */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
282 pos = 0x10000; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
283 inc = (srcrect->h << 16) / dstrect->h; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
284 src_row = srcrect->y; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
285 dst_row = dstrect->y; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
286 dst_width = dstrect->w * bpp; |
0 | 287 |
288 #ifdef USE_ASM_STRETCH | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
289 /* Write the opcodes for this stretch */ |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
290 if ((bpp == 3) || (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0)) { |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
291 use_asm = SDL_FALSE; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
292 } |
0 | 293 #endif |
294 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
295 /* Perform the stretch blit */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
296 for (dst_maxrow = dst_row + dstrect->h; dst_row < dst_maxrow; ++dst_row) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
297 dstp = (Uint8 *) dst->pixels + (dst_row * dst->pitch) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
298 + (dstrect->x * bpp); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
299 while (pos >= 0x10000L) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
300 srcp = (Uint8 *) src->pixels + (src_row * src->pitch) |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
301 + (srcrect->x * bpp); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
302 ++src_row; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
303 pos -= 0x10000L; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
304 } |
0 | 305 #ifdef USE_ASM_STRETCH |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
306 if (use_asm) { |
0 | 307 #ifdef __GNUC__ |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
308 __asm__ __volatile__("call *%4":"=&D"(u1), "=&S"(u2) |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
309 :"0"(dstp), "1"(srcp), "r"(copy_row) |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
310 :"memory"); |
1442
e3242177fe4a
Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
311 #elif defined(_MSC_VER) || defined(__WATCOMC__) |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
312 /* *INDENT-OFF* */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
313 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
314 void *code = copy_row; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
315 __asm { |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
316 push edi |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
317 push esi |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
318 mov edi, dstp |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
319 mov esi, srcp |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
320 call dword ptr code |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
321 pop esi |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
322 pop edi |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
323 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
324 } |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
325 /* *INDENT-ON* */ |
0 | 326 #else |
327 #error Need inline assembly for this compiler | |
328 #endif | |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
329 } else |
0 | 330 #endif |
3405
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
331 switch (bpp) { |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
332 case 1: |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
333 copy_row1(srcp, srcrect->w, dstp, dstrect->w); |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
334 break; |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
335 case 2: |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
336 copy_row2((Uint16 *) srcp, srcrect->w, |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
337 (Uint16 *) dstp, dstrect->w); |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
338 break; |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
339 case 3: |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
340 copy_row3(srcp, srcrect->w, dstp, dstrect->w); |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
341 break; |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
342 case 4: |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
343 copy_row4((Uint32 *) srcp, srcrect->w, |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
344 (Uint32 *) dstp, dstrect->w); |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
345 break; |
d5f2dd33f4eb
Merged improvements to SDL_SoftStretch() from SDL 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
2859
diff
changeset
|
346 } |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
347 pos += inc; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
348 } |
894
1d1a823904d8
Don't crash if the stretch routines are used on hardware surfaces
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
349 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
350 /* We need to unlock the surfaces if they're locked */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
351 if (dst_locked) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
352 SDL_UnlockSurface(dst); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
353 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
354 if (src_locked) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
355 SDL_UnlockSurface(src); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
356 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
357 return (0); |
0 | 358 } |
359 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1849
diff
changeset
|
360 /* vi: set ts=4 sw=4 expandtab: */ |