Advertisement
Guest User

Untitled

a guest
May 10th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 18.17 KB | None | 0 0
  1. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/d_main.c ./src/d_main.c
  2. 94a95,97
  3. > // NSM
  4. > #include "i_capture.h"
  5. >
  6. 471a475,480
  7. >       // NSM
  8. >       if (capturing_video && !doSkip)
  9. >       {
  10. >         I_CaptureFrame ();
  11. >       }
  12. >
  13. 1655a1665,1673
  14. >   // NSM
  15. >   if ((p = M_CheckParm("-viddump")) && (p < myargc-1))
  16. >   {
  17. >     I_CapturePrep (myargv[p + 1]);
  18. >   }
  19. >
  20. >
  21. >
  22. >
  23. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/g_game.c ./src/g_game.c
  24. 87a88,89
  25. > #include "i_capture.h" // NSM
  26. >
  27. 3480a3483,3490
  28. >       // NSM
  29. >       if (capturing_video)
  30. >       {
  31. >         I_CaptureFinish ();
  32. >         // supress I_Error since it needs to be clicked (in windows anyway),
  33. >         // so causes problems with batch conversion
  34. >         I_SafeExit (0);
  35. >       }
  36. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/i_capture.c ./src/i_capture.c
  37. 0a1,392
  38. > /* Emacs style mode select   -*- C++ -*-
  39. >  *-----------------------------------------------------------------------------
  40. >  *
  41. >  *
  42. >  *  PrBoom: a Doom port merged with LxDoom and LSDLDoom
  43. >  *  based on BOOM, a modified and improved DOOM engine
  44. >  *  Copyright (C) 1999 by
  45. >  *  id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  46. >  *  Copyright (C) 1999-2000 by
  47. >  *  Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  48. >  *  Copyright 2005, 2006 by
  49. >  *  Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  50. >  *  Copyright 2007 by
  51. >  *  Andrey Budko, Roman Marchenko
  52. >  *
  53. >  *  This program is free software; you can redistribute it and/or
  54. >  *  modify it under the terms of the GNU General Public License
  55. >  *  as published by the Free Software Foundation; either version 2
  56. >  *  of the License, or (at your option) any later version.
  57. >  *
  58. >  *  This program is distributed in the hope that it will be useful,
  59. >  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  60. >  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  61. >  *  GNU General Public License for more details.
  62. >  *
  63. >  *  You should have received a copy of the GNU General Public License
  64. >  *  along with this program; if not, write to the Free Software
  65. >  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  66. >  *  02111-1307, USA.
  67. >  *
  68. >  * DESCRIPTION:
  69. >  *
  70. >  *---------------------------------------------------------------------
  71. >  */
  72. >
  73. > #include <stdio.h>
  74. > #include <stdlib.h>
  75. > #include "i_sound.h"
  76. > #include "i_video.h"
  77. > #include "lprintf.h"
  78. >
  79. >
  80. >
  81. >
  82. > static const char *vid_fname;
  83. >
  84. > static FILE *sndfile;
  85. > static void *sndfileinfo;
  86. > static FILE *vidfile;
  87. > static void *vidfileinfo;
  88. >
  89. > // %w video width (px)
  90. > // %h video height (px)
  91. > // %s sound rate (hz)
  92. > // %f filename passed to -viddump
  93. > // %% single percent sign
  94. >
  95. > const char *cap_soundcommand;
  96. > const char *cap_videocommand;
  97. > const char *cap_muxcommand;
  98. > const char *cap_tempfile1;
  99. > const char *cap_tempfile2;
  100. >
  101. > //static const char *sndcommandin = "ffmpeg -f s16le -ar %s -ac 2 -i pipe:0 -acodec libvorbis -f ogg output.ogg";
  102. > //static const char *sndcommandin = "ffmpeg -f s16le -ar %s -ac 2 -i pipe:0 -acodec pcm_s16le output.wav";
  103. > // todo: add aspect ratio information
  104. > //static const char *vidcommandin = "ffmpeg -f rawvideo -pix_fmt rgb24 -s %wx%h -r 35 -i pipe:0 -vcodec libx264 -f mp4 -fpre ./libx264-baseline.ffpreset -crf 22 output.mp4";
  105. > //static const char *vidcommandin = "ffmpeg -f rawvideo -pix_fmt rgb24 -s %wx%h -r 35 -i pipe:0 -f null fubar.out";
  106. > //static const char *fincommandin = "ffmpeg -i output.ogg -i output.mp4 -vcodec copy -acodec copy %f";
  107. > //static const char *fincommandin = "ffmpeg -formats";
  108. >
  109. >
  110. > // parsed versions
  111. > static char sndcommand[MAX_PATH];
  112. > static char vidcommand[MAX_PATH];
  113. > static char muxcommand[MAX_PATH];
  114. >
  115. > // parses a command with simple printf-style replacements.
  116. > static int parsecommand (char *out, const char *in, int len)
  117. > {
  118. >   int i;
  119. >
  120. >   char *buff = malloc (len);
  121. >
  122. >   if (!buff)
  123. >     return 0;
  124. >
  125. >   while (*in && len > 1)
  126. >   {
  127. >     if (*in == '%')
  128. >     {
  129. >       switch (in[1])
  130. >       {
  131. >         case 'w':
  132. >           i = snprintf (out, len, "%u", SCREENWIDTH);
  133. >           break;
  134. >         case 'h':
  135. >           i = snprintf (out, len, "%u", SCREENHEIGHT);
  136. >           break;
  137. >         case 's':
  138. >           i = snprintf (out, len, "%u", snd_samplerate);
  139. >           break;
  140. >         case 'f':
  141. >           i = snprintf (out, len, "%s", vid_fname);
  142. >           break;
  143. >         case '%':
  144. >           i = snprintf (out, len, "%%");
  145. >           break;
  146. >         default:
  147. >           return 0;
  148. >       }
  149. >       out += i;
  150. >       len -= i;
  151. >       in += 2;
  152. >     }
  153. >     else
  154. >     {
  155. >       *out++ = *in++;
  156. >       len--;
  157. >     }
  158. >   }
  159. >   if (*in || len < 1)
  160. >   { // out of space
  161. >     return 0;
  162. >   }
  163. >   *out = 0;
  164. >   return 1;
  165. > }
  166. >
  167. >
  168. > int capturing_video = 0;
  169. >
  170. >
  171. >
  172. >
  173. > // popen replacement for w32
  174. >
  175. > #ifdef _WIN32
  176. > #if 0
  177. > // this works, but it spawns unnessecary cmd.exe menus, and the winapi ref says it's depreciated
  178. > // and unsafe for non-console apps to call
  179. >
  180. > static FILE *my_popen (const char *cmd, void **finfo)
  181. > {
  182. >   return _popen (cmd, "wb");
  183. > }
  184. > static void my_pclose (FILE *f, void *finfo)
  185. > {
  186. >   _pclose (f);
  187. > }
  188. >
  189. > #else // #if 0
  190. > // direct winapi implementation
  191. >
  192. > #define WIN32_LEAN_AND_MEAN
  193. > #include <windows.h>
  194. > #include <io.h>
  195. >
  196. > typedef struct
  197. > {
  198. >   HANDLE pipe[2];
  199. >   HANDLE proc;
  200. >   HANDLE thread;
  201. > } pinfo_t;
  202. >
  203. > // extra pointer is used to hold process id to wait on to close
  204. > static FILE *my_popen (const char *cmd, void **finfo)
  205. > {
  206. >   FILE *f = NULL;
  207. >   pinfo_t *pinfo;
  208. >
  209. >
  210. >   PROCESS_INFORMATION piProcInfo;
  211. >   STARTUPINFO siStartInfo;
  212. >   SECURITY_ATTRIBUTES sa;
  213. >
  214. >   pinfo = malloc (sizeof (pinfo_t));
  215. >   if (!pinfo)
  216. >     return NULL;
  217. >
  218. >
  219. >   // make the pipe
  220. >
  221. >   sa.nLength = sizeof (sa);
  222. >   sa.bInheritHandle = 1;
  223. >   sa.lpSecurityDescriptor = NULL;
  224. >   if (!CreatePipe (pinfo->pipe, pinfo->pipe + 1, &sa, 1 << 22)) // suggest 4MB buffer
  225. >   {
  226. >     free (pinfo);
  227. >     return NULL;
  228. >   }
  229. >
  230. >   // very important
  231. >   if (!SetHandleInformation (pinfo->pipe[1], HANDLE_FLAG_INHERIT, 0))
  232. >   {
  233. >     CloseHandle (pinfo->pipe[0]);
  234. >     CloseHandle (pinfo->pipe[1]);
  235. >     free (pinfo);
  236. >     return NULL;
  237. >   }
  238. >
  239. >
  240. >   // start the child process
  241. >
  242. >   ZeroMemory (&siStartInfo, sizeof (STARTUPINFO));
  243. >   siStartInfo.cb         = sizeof (STARTUPINFO);
  244. >   siStartInfo.hStdInput  = pinfo->pipe[0];
  245. >   siStartInfo.hStdOutput = 0; //GetStdHandle (STD_OUTPUT_HANDLE);
  246. >   siStartInfo.hStdError  = 0; //GetStdHandle (STD_ERROR_HANDLE);
  247. >   siStartInfo.dwFlags    = STARTF_USESTDHANDLES;
  248. >
  249. >   if (!CreateProcess(NULL,// application name
  250. >        (LPTSTR)cmd,       // command line
  251. >        NULL,              // process security attributes
  252. >        NULL,              // primary thread security attributes
  253. >        TRUE,              // handles are inherited
  254. >        DETACHED_PROCESS,  // creation flags
  255. >        NULL,              // use parent's environment
  256. >        NULL,              // use parent's current directory
  257. >        &siStartInfo,      // STARTUPINFO pointer
  258. >        &piProcInfo))      // receives PROCESS_INFORMATION
  259. >   {
  260. >     CloseHandle (pinfo->pipe[0]);
  261. >     CloseHandle (pinfo->pipe[1]);
  262. >     free (pinfo);
  263. >     return NULL;
  264. >   }
  265. >
  266. >   CloseHandle (pinfo->pipe[0]);
  267. >   pinfo->proc = piProcInfo.hProcess;
  268. >   pinfo->thread = piProcInfo.hThread;
  269. >
  270. >
  271. >                                 // what the hell is this cast for
  272. >   f = _fdopen (_open_osfhandle ((int) pinfo->pipe[1], 0), "wb");
  273. >
  274. >   if (!f)
  275. >   {
  276. >     CloseHandle (pinfo->pipe[0]);
  277. >     CloseHandle (pinfo->pipe[1]);
  278. >     CloseHandle (pinfo->proc);
  279. >     CloseHandle (pinfo->thread);
  280. >     free (pinfo);
  281. >     return NULL;
  282. >   }
  283. >
  284. >   *finfo = pinfo;
  285. >   return f;
  286. > }
  287. >
  288. > static void my_pclose (FILE *f, void *finfo)
  289. > {
  290. >   pinfo_t *pinfo = (pinfo_t *) finfo;
  291. >
  292. >   if (!f || !pinfo)
  293. >     return;
  294. >
  295. >   fclose (f);
  296. >
  297. >   WaitForSingleObject (pinfo->proc, INFINITE);
  298. >
  299. >   CloseHandle (pinfo->proc);
  300. >   CloseHandle (pinfo->thread);
  301. >   free (pinfo);
  302. > }
  303. >
  304. > #endif // #if 0
  305. > #else // _WIN32
  306. > // posix implementation
  307. >
  308. > static FILE *my_popen (const char *cmd, void **finfo)
  309. > {
  310. >   return popen (cmd, "wb");
  311. > }
  312. > static void my_pclose (FILE *f, void *finfo)
  313. > {
  314. >   pclose (f);
  315. > }
  316. > #endif // _WIN32
  317. >
  318. >
  319. >
  320. > // init and open sound, video pipes
  321. > // fn is filename passed from command line, typically final output file
  322. > void I_CapturePrep (const char *fn)
  323. > {
  324. >   vid_fname = fn;
  325. >
  326. >   if (!parsecommand (sndcommand, cap_soundcommand, MAX_PATH))
  327. >   {
  328. >     lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_soundcommand);
  329. >     capturing_video = 0;
  330. >     return;
  331. >   }
  332. >   if (!parsecommand (vidcommand, cap_videocommand, MAX_PATH))
  333. >   {
  334. >     lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_videocommand);
  335. >     capturing_video = 0;
  336. >     return;
  337. >   }
  338. >   if (!parsecommand (muxcommand, cap_muxcommand, MAX_PATH))
  339. >   {
  340. >     lprintf (LO_ERROR, "I_CapturePrep: malformed command %s\n", cap_muxcommand);
  341. >     capturing_video = 0;
  342. >     return;
  343. >   }
  344. >
  345. >   lprintf (LO_INFO, "I_CapturePrep: opening pipe \"%s\"\n", sndcommand);
  346. >   sndfile = my_popen (sndcommand, &sndfileinfo);
  347. >   if (!sndfile)
  348. >   {
  349. >     lprintf (LO_ERROR, "I_CapturePrep: sound pipe failed\n");
  350. >     capturing_video = 0;
  351. >     return;
  352. >   }
  353. >   lprintf (LO_INFO, "I_CapturePrep: opening pipe \"%s\"\n", vidcommand);
  354. >   vidfile = my_popen (vidcommand, &vidfileinfo);
  355. >   if (!vidfile)
  356. >   {
  357. >     lprintf (LO_ERROR, "I_CapturePrep: video pipe failed\n");
  358. >     my_pclose (sndfile, sndfileinfo);
  359. >     capturing_video = 0;
  360. >     return;
  361. >   }
  362. >   I_SetSoundCap ();
  363. >   lprintf (LO_INFO, "I_CapturePrep: video capture started\n");
  364. >   capturing_video = 1;
  365. > }
  366. >
  367. >
  368. >
  369. > // capture a single frame of video (and corresponding audio length)
  370. > // and send it to pipes
  371. > void I_CaptureFrame (void)
  372. > {
  373. >   char *snd;
  374. >   char *vid;
  375. >
  376. >   if (!capturing_video)
  377. >     return;
  378. >
  379. >   // NB: sync errors will occur if samplerate % 35 != 0
  380. >   snd = I_GrabSound (snd_samplerate / 35);
  381. >   if (snd)
  382. >   {
  383. >     fwrite (snd, 4, snd_samplerate / 35, sndfile);
  384. >     free (snd);
  385. >   }
  386. >   vid = I_GrabScreen ();
  387. >   if (vid)
  388. >   {
  389. >     fwrite (vid, 1, SCREENWIDTH * SCREENHEIGHT * 3, vidfile);
  390. >     free (vid);
  391. >   }
  392. >
  393. > }
  394. >
  395. >
  396. > // close pipes, call muxcommand, finalize
  397. > void I_CaptureFinish (void)
  398. > {
  399. >   FILE *f;
  400. >   void *finfo;
  401. >
  402. >   const char **s;
  403. >
  404. >   if (!capturing_video)
  405. >     return;
  406. >   capturing_video = 0;
  407. >
  408. >   my_pclose (sndfile, sndfileinfo);
  409. >   sndfile = NULL;
  410. >   my_pclose (vidfile, vidfileinfo);
  411. >   vidfile = NULL;
  412. >
  413. >   // muxing and temp file cleanup
  414. >
  415. >   f = my_popen (muxcommand, &finfo);
  416. >
  417. >   lprintf (LO_INFO, "I_CapturePrep: opening pipe \"%s\"\n", muxcommand);
  418. >   if (!f)
  419. >   {
  420. >     lprintf (LO_ERROR, "I_CaptureFinish: finalize pipe failed\n");
  421. >     return;
  422. >   }
  423. >
  424. >   my_pclose (f, finfo);
  425. >
  426. >   // unlink any files user wants gone
  427. >   remove (cap_tempfile1);
  428. >   remove (cap_tempfile2);
  429. > }
  430. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/i_capture.h ./src/i_capture.h
  431. 0a1,64
  432. > /* Emacs style mode select   -*- C++ -*-
  433. >  *-----------------------------------------------------------------------------
  434. >  *
  435. >  *
  436. >  *  PrBoom: a Doom port merged with LxDoom and LSDLDoom
  437. >  *  based on BOOM, a modified and improved DOOM engine
  438. >  *  Copyright (C) 1999 by
  439. >  *  id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  440. >  *  Copyright (C) 1999-2000 by
  441. >  *  Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  442. >  *  Copyright 2005, 2006 by
  443. >  *  Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  444. >  *  Copyright 2007 by
  445. >  *  Andrey Budko, Roman Marchenko
  446. >  *
  447. >  *  This program is free software; you can redistribute it and/or
  448. >  *  modify it under the terms of the GNU General Public License
  449. >  *  as published by the Free Software Foundation; either version 2
  450. >  *  of the License, or (at your option) any later version.
  451. >  *
  452. >  *  This program is distributed in the hope that it will be useful,
  453. >  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  454. >  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  455. >  *  GNU General Public License for more details.
  456. >  *
  457. >  *  You should have received a copy of the GNU General Public License
  458. >  *  along with this program; if not, write to the Free Software
  459. >  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  460. >  *  02111-1307, USA.
  461. >  *
  462. >  * DESCRIPTION:
  463. >  *
  464. >  *---------------------------------------------------------------------
  465. >  */
  466. >
  467. > #ifndef __I_CAPTURE__
  468. > #define __I_CAPTURE__
  469. >
  470. > // commandlines passed to popen()
  471. > // this one recieves raw PCM sound on stdin
  472. > extern const char *cap_soundcommand;
  473. > // this one recieves raw RGB video on stdin
  474. > extern const char *cap_videocommand;
  475. > // this one recieves nothing on stdin and is called after the other two finish
  476. > extern const char *cap_muxcommand;
  477. > // names of two files to remove after muxcommand finishes
  478. > extern const char *cap_tempfile1;
  479. > extern const char *cap_tempfile2;
  480. >
  481. > // true if we're capturing video
  482. > extern int capturing_video;
  483. >
  484. > // init and open sound, video pipes
  485. > // fn is filename passed from command line, typically final output file
  486. > void I_CapturePrep (const char *fn);
  487. >
  488. > // capture a single frame of video (and corresponding audio length)
  489. > // and send it to pipes
  490. > void I_CaptureFrame (void);
  491. >
  492. > // close pipes, call muxcommand, finalize
  493. > void I_CaptureFinish (void);
  494. >
  495. > #endif
  496. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/i_sound.h ./src/i_sound.h
  497. 82a83,89
  498. > // NSM sound capture routines
  499. > // silences sound output, and instead allows sound capture to work
  500. > // call this before sound startup
  501. > void I_SetSoundCap (void);
  502. > // grabs len samples of audio (16 bit interleaved)
  503. > char *I_GrabSound (int len);
  504. >
  505. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/i_video.h ./src/i_video.h
  506. 64a65,66
  507. > // NSM expose lower level screen data grab for vidcap
  508. > unsigned char *I_GrabScreen (void);
  509. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/m_misc.c ./src/m_misc.c
  510. 85a86,88
  511. > // NSM
  512. > #include "i_capture.h"
  513. >
  514. 893a897,904
  515. >   // NSM
  516. >   {"Video capture encoding settings",{NULL},{0},UL,UL,def_none,ss_none},
  517. >   {"cap_soundcommand",{NULL, &cap_soundcommand},{0,"ffmpeg -f s16le -ar %s -ac 2 -i pipe:0 -acodec libvorbis -f ogg -aq 5 output.ogg"},UL,UL,def_str,ss_none},
  518. >   {"cap_videocommand",{NULL, &cap_videocommand},{0,"ffmpeg -f rawvideo -pix_fmt rgb24 -s %wx%h -r 35 -i pipe:0 -vcodec libx264 -f mp4 -fpre ./libx264-baseline.ffpreset -crf 22 output.mp4"},UL,UL,def_str,ss_none},
  519. >   {"cap_muxcommand",{NULL, &cap_muxcommand},{0,"ffmpeg -i output.ogg -i output.mp4 -vcodec copy -acodec copy %f"},UL,UL,def_str,ss_none},
  520. >   {"cap_tempfile1",{NULL, &cap_tempfile1},{0,"output.ogg"},UL,UL,def_str,ss_none},
  521. >   {"cap_tempfile2",{NULL, &cap_tempfile2},{0,"output.mp4"},UL,UL,def_str,ss_none},
  522. >
  523. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/Makefile.am ./src/Makefile.am
  524. 61c61
  525. <  s_advsound.c   s_advsound.h \
  526. ---
  527. >  s_advsound.c   s_advsound.h       i_capture.c      i_capture.h \
  528. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/SDL/i_sound.c ./src/SDL/i_sound.c
  529. 132a133,135
  530. > // NSM
  531. > static int dumping_sound = 0;
  532. >
  533. 434a438,444
  534. >   // NSM: when dumping sound, ignore the callback calls and only
  535. >   // service dumping calls
  536. >   if (dumping_sound && unused != (void *) 0xdeadbeef)
  537. >     return;
  538. >
  539. >
  540. >
  541. 618a629,652
  542. > // NSM sound capture routines
  543. >
  544. > // silences sound output, and instead allows sound capture to work
  545. > // call this before sound startup
  546. > void I_SetSoundCap (void)
  547. > {
  548. >   dumping_sound = 1;
  549. > }
  550. >
  551. > // grabs len samples of audio (16 bit interleaved)
  552. > char *I_GrabSound (int len)
  553. > {
  554. >   char *buff;
  555. >   if (!dumping_sound)
  556. >     return NULL;
  557. >
  558. >   buff = malloc (len * 4);
  559. >   if (buff)
  560. >   {
  561. >     memset (buff, 0, len * 4);
  562. >     I_UpdateSound ((void *) 0xdeadbeef, buff, len * 4);
  563. >   }
  564. >   return buff;
  565. > }
  566. diff --ignore-file-name-case -EbrNX diffign.txt ../2508/src/SDL/i_sshot.c ./src/SDL/i_sshot.c
  567. 331a332,395
  568. >
  569. > // NSM
  570. > // returns current screern contents as RGB24 (raw)
  571. > // returned pointer should be freed when done
  572. >
  573. > unsigned char *I_GrabScreen (void)
  574. > {
  575. >   unsigned char *pixel_data;
  576. >
  577. >   #ifdef GL_DOOM
  578. >   if (V_GetMode() == VID_MODEGL)
  579. >   {
  580. >     pixel_data = gld_ReadScreen();
  581. >     return pixel_data;
  582. >   }
  583. >   #endif
  584. >
  585. >   pixel_data = malloc(SCREENWIDTH * SCREENHEIGHT * 3);
  586. >
  587. >   if (pixel_data)
  588. >   {
  589. >     SDL_Surface *scr = SDL_GetVideoSurface();
  590. >     SDL_PixelFormat *fmt = scr->format;
  591. >     SDL_Palette *pal = fmt->palette;
  592. >     unsigned char *pixel_src = (unsigned char *) scr->pixels;
  593. >
  594. >     int lock_needed = SDL_MUSTLOCK(scr);
  595. >     int lock_was_successful = 0;
  596. >
  597. >     if (!lock_needed || SDL_LockSurface(scr) >= 0)
  598. >     {
  599. >       // While the screen is locked write it into a buffer
  600. >       unsigned char *s = pixel_data;
  601. >       int i;
  602. >
  603. >       if (pal) // 8bpp
  604. >       {
  605. >         for (i = 0; i < SCREENWIDTH * SCREENHEIGHT; i++)
  606. >         {
  607. >           *s++ = pal->colors[pixel_src[i]].r;
  608. >           *s++ = pal->colors[pixel_src[i]].g;
  609. >           *s++ = pal->colors[pixel_src[i]].b;
  610. >         }
  611. >       }
  612. >       else // high/truecolor
  613. >       {
  614. >         for (i = 0; i < SCREENWIDTH * SCREENHEIGHT; i++)
  615. >         {
  616. >           Uint32 p = *(Uint32 *) (pixel_src + i * fmt->BytesPerPixel);
  617. >           *s++ = (((p & fmt->Rmask)>>fmt->Rshift)<<fmt->Rloss);
  618. >           *s++ = (((p & fmt->Gmask)>>fmt->Gshift)<<fmt->Gloss);
  619. >           *s++ = (((p & fmt->Bmask)>>fmt->Bshift)<<fmt->Bloss);
  620. >         }
  621. >       }
  622. >
  623. >       if (lock_needed)
  624. >         SDL_UnlockSurface(scr);
  625. >     }
  626. >   }
  627. >   return pixel_data;
  628. > }
  629. >
  630. >
  631. >
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement