163 LandPixels[y div 2, x div 2]:= c |
163 LandPixels[y div 2, x div 2]:= c |
164 end; |
164 end; |
165 end |
165 end |
166 end; |
166 end; |
167 |
167 |
|
168 procedure ColorizeLandFast(Surface: PSDL_Surface); |
|
169 var ltsurf: PSDL_Surface; |
|
170 x, y, ltw, lth, c, modc, lastfull: LongInt; |
|
171 srcp, dstp: Pointer; |
|
172 begin |
|
173 ltsurf:= LoadDataImage(ptCurrTheme, 'LandTex', ifCritical or ifIgnoreCaps); |
|
174 ltw:= ltsurf^.w; |
|
175 lth:= ltsurf^.h; |
|
176 |
|
177 // pointer to ltturf pixels. will be moved from line to line |
|
178 srcp:= ltsurf^.pixels; |
|
179 // pointer to Surface pixels. will be moved forward with every move() |
|
180 dstp:= Surface^.pixels; |
|
181 |
|
182 // amount of pixels to write per move() |
|
183 c:= ltsurf^.pitch; |
|
184 // amount of pixels to write for line's remainer move() |
|
185 modc:= Surface^.pitch mod c; |
|
186 |
|
187 SDL_LockSurface(Surface); |
|
188 SDL_LockSurface(ltsurf); |
|
189 |
|
190 y:= 0; |
|
191 // last x where a full line from src may be written to |
|
192 lastfull:= Surface^.w - ltw; |
|
193 // only copy in one row of landtex. do copies within Surface after |
|
194 while (y < lth) and (y < Surface^.h) do |
|
195 begin |
|
196 x:= 0; |
|
197 // fill dst line with src lines |
|
198 while x <= lastfull do |
|
199 begin |
|
200 move(srcp^, dstp^, c); |
|
201 inc(dstp, c); |
|
202 inc(x, ltw); |
|
203 end; |
|
204 |
|
205 // if it didn't fit perfectly, copy remainder |
|
206 if modc > 0 then |
|
207 begin |
|
208 move(srcp^, dstp^, modc); |
|
209 inc(dstp, modc); |
|
210 end; |
|
211 |
|
212 // move to next line in src surface |
|
213 inc(srcp, ltsurf^.pitch); |
|
214 inc(y); |
|
215 end; |
|
216 |
|
217 // we don't need ltsurf anymore -> cleanup |
|
218 srcp:= nil; |
|
219 SDL_UnlockSurface(ltsurf); |
|
220 SDL_FreeSurface(ltsurf); |
|
221 |
|
222 // from now on only copy pixels within Surface |
|
223 |
|
224 // start reading from position 0, but continue writing at dstp |
|
225 srcp:= Surface^.pixels; |
|
226 // copy all the already written lines at once for that get number of written bytes so far |
|
227 c:= dstp - srcp; // effectively same as c:= lth * Surface^.pitch; |
|
228 // also figure out the remainder again |
|
229 modc:= (Surface^.h mod lth) * Surface^.pitch; // effectivle same as modc:= (Surface^.pitch * Surface^.h) mod c; |
|
230 |
|
231 // last y where a full copy may be written to |
|
232 lastfull:= Surface^.h - lth; |
|
233 |
|
234 // copy filled area down |
|
235 while y <= lastfull do |
|
236 begin |
|
237 move(srcp^, dstp^, c); |
|
238 inc(srcp, c); |
|
239 inc(dstp, c); |
|
240 inc(y, lth); |
|
241 end; |
|
242 |
|
243 // if it didn't fit perfectly, copy remainder |
|
244 if modc > 0 then |
|
245 begin |
|
246 move(srcp^, dstp^, modc); |
|
247 end; |
|
248 |
|
249 SDL_UnlockSurface(Surface); |
|
250 |
|
251 // freed in freeModule() below |
|
252 LandBackSurface:= LoadDataImage(ptCurrTheme, 'LandBackTex', ifIgnoreCaps or ifTransparent); |
|
253 if (LandBackSurface <> nil) and GrayScale then Surface2GrayScale(LandBackSurface); |
|
254 end; |
|
255 |
168 procedure ColorizeLand(Surface: PSDL_Surface); |
256 procedure ColorizeLand(Surface: PSDL_Surface); |
169 var tmpsurf: PSDL_Surface; |
257 var tmpsurf: PSDL_Surface; |
170 r: TSDL_Rect; |
258 r: TSDL_Rect; |
171 y: LongInt; // stupid SDL 1.2 uses stupid SmallInt for y which limits us to 32767. But is even worse if LandTex is large, can overflow on 32767 map. |
259 y: LongInt; // stupid SDL 1.2 uses stupid SmallInt for y which limits us to 32767. But is even worse if LandTex is large, can overflow on 32767 map. |
172 begin |
260 begin |
275 AddProgress(); |
363 AddProgress(); |
276 |
364 |
277 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, AMask); |
365 tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, LAND_WIDTH, LAND_HEIGHT, 32, RMask, GMask, BMask, AMask); |
278 |
366 |
279 if checkFails(tmpsurf <> nil, 'Error creating pre-land surface', true) then exit; |
367 if checkFails(tmpsurf <> nil, 'Error creating pre-land surface', true) then exit; |
280 ColorizeLand(tmpsurf); |
368 ColorizeLandFast(tmpsurf); |
281 if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf); |
369 if gameFlags and gfShoppaBorder = 0 then DrawBorderFromImage(tmpsurf); |
282 AddOnLandObjects(tmpsurf); |
370 AddOnLandObjects(tmpsurf); |
283 |
371 |
284 LandSurface2LandPixels(tmpsurf); |
372 LandSurface2LandPixels(tmpsurf); |
285 SDL_FreeSurface(tmpsurf); |
373 SDL_FreeSurface(tmpsurf); |