26 procedure initModule; |
26 procedure initModule; |
27 procedure freeModule; |
27 procedure freeModule; |
28 |
28 |
29 procedure movecursor(dx, dy: LongInt); |
29 procedure movecursor(dx, dy: LongInt); |
30 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
30 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
31 function MakeScreenshot(filename: shortstring): boolean; |
31 function MakeScreenshot(filename: shortstring; k: LongInt): boolean; |
32 function GetTeamStatString(p: PTeam): shortstring; |
32 function GetTeamStatString(p: PTeam): shortstring; |
33 {$IFDEF SDL13} |
33 {$IFDEF SDL13} |
34 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline; |
34 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline; |
35 {$ELSE} |
35 {$ELSE} |
36 function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline; |
36 function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline; |
184 SaveScreenshot:= 0; |
184 SaveScreenshot:= 0; |
185 end; |
185 end; |
186 |
186 |
187 {$ENDIF} // no PNG_SCREENSHOTS |
187 {$ENDIF} // no PNG_SCREENSHOTS |
188 |
188 |
|
189 {$IFDEF USE_VIDEO_RECORDING} |
|
190 // make image k times smaller (useful for saving thumbnails) |
|
191 procedure ReduceImage(img: PByte; width, height, k: LongInt); |
|
192 var i, j, i0, j0, w, h, r, g, b: LongInt; |
|
193 begin |
|
194 w:= width div k; |
|
195 h:= height div k; |
|
196 |
|
197 // rescale inplace |
|
198 if k <> 1 then |
|
199 begin |
|
200 for i:= 0 to h-1 do |
|
201 for j:= 0 to w-1 do |
|
202 begin |
|
203 r:= 0; |
|
204 g:= 0; |
|
205 b:= 0; |
|
206 for i0:= 0 to k-1 do |
|
207 for j0:= 0 to k-1 do |
|
208 begin |
|
209 r+= img[4*(width*(i*k+i0) + j*k+j0)+0]; |
|
210 g+= img[4*(width*(i*k+i0) + j*k+j0)+1]; |
|
211 b+= img[4*(width*(i*k+i0) + j*k+j0)+2]; |
|
212 end; |
|
213 img[4*(w*i + j)+0]:= r div (k*k); |
|
214 img[4*(w*i + j)+1]:= g div (k*k); |
|
215 img[4*(w*i + j)+2]:= b div (k*k); |
|
216 img[4*(w*i + j)+3]:= 0; |
|
217 end; |
|
218 end; |
|
219 end; |
|
220 {$ENDIF} |
|
221 |
189 // captures and saves the screen. returns true on success. |
222 // captures and saves the screen. returns true on success. |
190 function MakeScreenshot(filename: shortstring): Boolean; |
223 // saved image will be k times smaller than original (useful for saving thumbnails). |
|
224 function MakeScreenshot(filename: shortstring; k: LongInt): Boolean; |
191 var p: Pointer; |
225 var p: Pointer; |
192 size: QWord; |
226 size: QWord; |
193 image: PScreenshot; |
227 image: PScreenshot; |
194 format: GLenum; |
228 format: GLenum; |
195 ext: string[4]; |
229 ext: string[4]; |
196 begin |
230 begin |
197 // flash |
|
198 ScreenFade:= sfFromWhite; |
|
199 ScreenFadeValue:= sfMax; |
|
200 ScreenFadeSpeed:= 5; |
|
201 |
|
202 {$IFDEF PNG_SCREENSHOTS} |
231 {$IFDEF PNG_SCREENSHOTS} |
203 format:= GL_RGBA; |
232 format:= GL_RGBA; |
204 ext:= '.png'; |
233 ext:= '.png'; |
205 {$ELSE} |
234 {$ELSE} |
206 format:= GL_BGRA; |
235 format:= GL_BGRA; |
216 AddFileLog('Error: Could not allocate memory for screenshot.'); |
245 AddFileLog('Error: Could not allocate memory for screenshot.'); |
217 MakeScreenshot:= false; |
246 MakeScreenshot:= false; |
218 exit; |
247 exit; |
219 end; |
248 end; |
220 |
249 |
221 // read pixel from the front buffer |
250 // read pixels from the front buffer |
222 glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p); |
251 glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p); |
|
252 |
|
253 {$IFDEF USE_VIDEO_RECORDING} |
|
254 ReduceImage(p, cScreenWidth, cScreenHeight, k); |
|
255 {$ENDIF} |
223 |
256 |
224 // allocate and fill structure that will be passed to new thread |
257 // allocate and fill structure that will be passed to new thread |
225 New(image); // will be disposed in SaveScreenshot() |
258 New(image); // will be disposed in SaveScreenshot() |
226 image^.filename:= UserPathPrefix + '/Screenshots/' + filename + ext; |
259 image^.filename:= UserPathPrefix + filename + ext; |
227 image^.width:= cScreenWidth; |
260 image^.width:= cScreenWidth div k; |
228 image^.height:= cScreenHeight; |
261 image^.height:= cScreenHeight div k; |
229 image^.size:= size; |
262 image^.size:= size; |
230 image^.buffer:= p; |
263 image^.buffer:= p; |
231 |
264 |
232 {$IFDEF USE_SDLTHREADS} |
265 {$IFDEF USE_SDLTHREADS} |
233 SDL_CreateThread(@SaveScreenshot{$IFDEF SDL13}, nil{$ENDIF}, image); |
266 SDL_CreateThread(@SaveScreenshot{$IFDEF SDL13}, nil{$ENDIF}, image); |