Mercurial > sdl-ios-xcode
annotate src/video/SDL_stretch.c @ 753:b14fdadd8311
Date: Thu, 4 Dec 2003 07:48:40 +0200
From: "Mike Gorchak"
Subject: SDL/QNX6 new patch
Here in attachment my patch for the SDL/QNX6 again :) It contain non-crtitical/cosmetic fixes:
1. Fixed window centering at other than the first consoles.
2. Fixed window centering algorithm in case when window height or width are greater than the desktop resolution.
3. Fixed window positioning on other than the first consoles.
4. Fixed occasional input focus lost when switching to fullscreen.
5. Removed the Photon's default chroma color for the overlays, added RGB(12, 6, 12) color instead (very dark pink).
6. Added more checks to the YUV overlay code (fixed crashes during resolution mode switches).
7. Added support for Enter/Backspace keys in unicode mode (used by Maelstrom and by other games).
8. Fixed window restore/maximize function. It works, finally.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 10 Dec 2003 12:35:56 +0000 |
parents | 8b9ac38381d0 |
children | b8d311d90021 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
288
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
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 | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
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 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* This a stretch blit implementation based on ideas given to me by | |
29 Tomasz Cejner - thanks! :) | |
30 | |
31 April 27, 2000 - Sam Lantinga | |
32 */ | |
33 | |
34 #include "SDL_error.h" | |
35 #include "SDL_video.h" | |
36 #include "SDL_blit.h" | |
37 | |
38 /* This isn't ready for general consumption yet - it should be folded | |
39 into the general blitting mechanism. | |
40 */ | |
41 | |
288
2f5a6062db86
Updated for Watcom C++ and LCC compilers
Sam Lantinga <slouken@libsdl.org>
parents:
274
diff
changeset
|
42 #if (defined(WIN32) && !defined(_M_ALPHA) && !defined(_WIN32_WCE) && \ |
2f5a6062db86
Updated for Watcom C++ and LCC compilers
Sam Lantinga <slouken@libsdl.org>
parents:
274
diff
changeset
|
43 !defined(__WATCOMC__) && !defined(__LCC__) && !defined(__FREEBCC__)) || \ |
2f5a6062db86
Updated for Watcom C++ and LCC compilers
Sam Lantinga <slouken@libsdl.org>
parents:
274
diff
changeset
|
44 (defined(i386) && defined(__GNUC__) && defined(USE_ASMBLIT)) |
0 | 45 #define USE_ASM_STRETCH |
46 #endif | |
47 | |
48 #ifdef USE_ASM_STRETCH | |
49 | |
50 #if defined(WIN32) || defined(i386) | |
51 #define PREFIX16 0x66 | |
52 #define STORE_BYTE 0xAA | |
53 #define STORE_WORD 0xAB | |
54 #define LOAD_BYTE 0xAC | |
55 #define LOAD_WORD 0xAD | |
56 #define RETURN 0xC3 | |
57 #else | |
58 #error Need assembly opcodes for this architecture | |
59 #endif | |
60 | |
61 #if defined(__ELF__) && defined(__GNUC__) | |
62 extern unsigned char _copy_row[4096] __attribute__ ((alias ("copy_row"))); | |
63 #endif | |
64 static unsigned char copy_row[4096]; | |
65 | |
66 static int generate_rowbytes(int src_w, int dst_w, int bpp) | |
67 { | |
68 static struct { | |
69 int bpp; | |
70 int src_w; | |
71 int dst_w; | |
72 } last; | |
73 | |
74 int i; | |
75 int pos, inc; | |
76 unsigned char *eip; | |
77 unsigned char load, store; | |
78 | |
79 /* See if we need to regenerate the copy buffer */ | |
80 if ( (src_w == last.src_w) && | |
81 (dst_w == last.src_w) && (bpp == last.bpp) ) { | |
82 return(0); | |
83 } | |
84 last.bpp = bpp; | |
85 last.src_w = src_w; | |
86 last.dst_w = dst_w; | |
87 | |
88 switch (bpp) { | |
89 case 1: | |
90 load = LOAD_BYTE; | |
91 store = STORE_BYTE; | |
92 break; | |
93 case 2: | |
94 case 4: | |
95 load = LOAD_WORD; | |
96 store = STORE_WORD; | |
97 break; | |
98 default: | |
99 SDL_SetError("ASM stretch of %d bytes isn't supported\n", bpp); | |
100 return(-1); | |
101 } | |
102 pos = 0x10000; | |
103 inc = (src_w << 16) / dst_w; | |
104 eip = copy_row; | |
105 for ( i=0; i<dst_w; ++i ) { | |
106 while ( pos >= 0x10000L ) { | |
107 if ( bpp == 2 ) { | |
108 *eip++ = PREFIX16; | |
109 } | |
110 *eip++ = load; | |
111 pos -= 0x10000L; | |
112 } | |
113 if ( bpp == 2 ) { | |
114 *eip++ = PREFIX16; | |
115 } | |
116 *eip++ = store; | |
117 pos += inc; | |
118 } | |
119 *eip++ = RETURN; | |
120 | |
121 /* Verify that we didn't overflow (too late) */ | |
122 if ( eip > (copy_row+sizeof(copy_row)) ) { | |
123 SDL_SetError("Copy buffer overflow"); | |
124 return(-1); | |
125 } | |
126 return(0); | |
127 } | |
128 | |
129 #else | |
130 | |
131 #define DEFINE_COPY_ROW(name, type) \ | |
132 void name(type *src, int src_w, type *dst, int dst_w) \ | |
133 { \ | |
134 int i; \ | |
135 int pos, inc; \ | |
136 type pixel = 0; \ | |
137 \ | |
138 pos = 0x10000; \ | |
139 inc = (src_w << 16) / dst_w; \ | |
140 for ( i=dst_w; i>0; --i ) { \ | |
141 while ( pos >= 0x10000L ) { \ | |
142 pixel = *src++; \ | |
143 pos -= 0x10000L; \ | |
144 } \ | |
145 *dst++ = pixel; \ | |
146 pos += inc; \ | |
147 } \ | |
148 } | |
149 DEFINE_COPY_ROW(copy_row1, Uint8) | |
150 DEFINE_COPY_ROW(copy_row2, Uint16) | |
151 DEFINE_COPY_ROW(copy_row4, Uint32) | |
152 | |
153 #endif /* USE_ASM_STRETCH */ | |
154 | |
155 /* The ASM code doesn't handle 24-bpp stretch blits */ | |
156 void copy_row3(Uint8 *src, int src_w, Uint8 *dst, int dst_w) | |
157 { | |
158 int i; | |
159 int pos, inc; | |
160 Uint8 pixel[3]; | |
161 | |
162 pos = 0x10000; | |
163 inc = (src_w << 16) / dst_w; | |
164 for ( i=dst_w; i>0; --i ) { | |
165 while ( pos >= 0x10000L ) { | |
166 pixel[0] = *src++; | |
167 pixel[1] = *src++; | |
168 pixel[2] = *src++; | |
169 pos -= 0x10000L; | |
170 } | |
171 *dst++ = pixel[0]; | |
172 *dst++ = pixel[1]; | |
173 *dst++ = pixel[2]; | |
174 pos += inc; | |
175 } | |
176 } | |
177 | |
178 /* Perform a stretch blit between two surfaces of the same format. | |
179 NOTE: This function is not safe to call from multiple threads! | |
180 */ | |
181 int SDL_SoftStretch(SDL_Surface *src, SDL_Rect *srcrect, | |
182 SDL_Surface *dst, SDL_Rect *dstrect) | |
183 { | |
184 int pos, inc; | |
185 int dst_width; | |
186 int dst_maxrow; | |
187 int src_row, dst_row; | |
188 Uint8 *srcp = NULL; | |
189 Uint8 *dstp; | |
190 SDL_Rect full_src; | |
191 SDL_Rect full_dst; | |
192 #if defined(USE_ASM_STRETCH) && defined(__GNUC__) | |
193 int u1, u2; | |
194 #endif | |
195 const int bpp = dst->format->BytesPerPixel; | |
196 | |
197 if ( src->format->BitsPerPixel != dst->format->BitsPerPixel ) { | |
198 SDL_SetError("Only works with same format surfaces"); | |
199 return(-1); | |
200 } | |
201 | |
202 /* Verify the blit rectangles */ | |
203 if ( srcrect ) { | |
204 if ( (srcrect->x < 0) || (srcrect->y < 0) || | |
205 ((srcrect->x+srcrect->w) > src->w) || | |
206 ((srcrect->y+srcrect->h) > src->h) ) { | |
207 SDL_SetError("Invalid source blit rectangle"); | |
208 return(-1); | |
209 } | |
210 } else { | |
211 full_src.x = 0; | |
212 full_src.y = 0; | |
213 full_src.w = src->w; | |
214 full_src.h = src->h; | |
215 srcrect = &full_src; | |
216 } | |
217 if ( dstrect ) { | |
218 if ( (dstrect->x < 0) || (dstrect->y < 0) || | |
219 ((dstrect->x+dstrect->w) > dst->w) || | |
220 ((dstrect->y+dstrect->h) > dst->h) ) { | |
221 SDL_SetError("Invalid destination blit rectangle"); | |
222 return(-1); | |
223 } | |
224 } else { | |
225 full_dst.x = 0; | |
226 full_dst.y = 0; | |
227 full_dst.w = dst->w; | |
228 full_dst.h = dst->h; | |
229 dstrect = &full_dst; | |
230 } | |
231 | |
232 /* Set up the data... */ | |
233 pos = 0x10000; | |
234 inc = (srcrect->h << 16) / dstrect->h; | |
235 src_row = srcrect->y; | |
236 dst_row = dstrect->y; | |
237 dst_width = dstrect->w*bpp; | |
238 | |
239 #ifdef USE_ASM_STRETCH | |
240 /* Write the opcodes for this stretch */ | |
241 if ( (bpp != 3) && | |
242 (generate_rowbytes(srcrect->w, dstrect->w, bpp) < 0) ) { | |
243 return(-1); | |
244 } | |
245 #endif | |
246 | |
247 /* Perform the stretch blit */ | |
248 for ( dst_maxrow = dst_row+dstrect->h; dst_row<dst_maxrow; ++dst_row ) { | |
249 dstp = (Uint8 *)dst->pixels + (dst_row*dst->pitch) | |
250 + (dstrect->x*bpp); | |
251 while ( pos >= 0x10000L ) { | |
252 srcp = (Uint8 *)src->pixels + (src_row*src->pitch) | |
253 + (srcrect->x*bpp); | |
254 ++src_row; | |
255 pos -= 0x10000L; | |
256 } | |
257 #ifdef USE_ASM_STRETCH | |
258 switch (bpp) { | |
259 case 3: | |
260 copy_row3(srcp, srcrect->w, dstp, dstrect->w); | |
261 break; | |
262 default: | |
263 #ifdef __GNUC__ | |
627
8b9ac38381d0
Fixed compile problem in SDL_stretch.c with gcc 3.3
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
264 __asm__ __volatile__ ( |
8b9ac38381d0
Fixed compile problem in SDL_stretch.c with gcc 3.3
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
265 "call _copy_row" |
0 | 266 : "=&D" (u1), "=&S" (u2) |
267 : "0" (dstp), "1" (srcp) | |
268 : "memory" ); | |
269 #else | |
270 #ifdef WIN32 | |
271 { void *code = ©_row; | |
272 __asm { | |
273 push edi | |
274 push esi | |
275 | |
276 mov edi, dstp | |
277 mov esi, srcp | |
278 call dword ptr code | |
279 | |
280 pop esi | |
281 pop edi | |
282 } | |
283 } | |
284 #else | |
285 #error Need inline assembly for this compiler | |
286 #endif | |
287 #endif /* __GNUC__ */ | |
288 break; | |
289 } | |
290 #else | |
291 switch (bpp) { | |
292 case 1: | |
293 copy_row1(srcp, srcrect->w, dstp, dstrect->w); | |
294 break; | |
295 case 2: | |
296 copy_row2((Uint16 *)srcp, srcrect->w, | |
297 (Uint16 *)dstp, dstrect->w); | |
298 break; | |
299 case 3: | |
300 copy_row3(srcp, srcrect->w, dstp, dstrect->w); | |
301 break; | |
302 case 4: | |
303 copy_row4((Uint32 *)srcp, srcrect->w, | |
304 (Uint32 *)dstp, dstrect->w); | |
305 break; | |
306 } | |
307 #endif | |
308 pos += inc; | |
309 } | |
310 return(0); | |
311 } | |
312 |