sdlgenblit.pl 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. #!/usr/bin/perl -w
  2. #
  3. # A script to generate optimized C blitters for Simple DirectMedia Layer
  4. # http://www.libsdl.org/
  5. use warnings;
  6. use strict;
  7. my %file;
  8. # The formats potentially supported by this script:
  9. # SDL_PIXELFORMAT_RGB332
  10. # SDL_PIXELFORMAT_XRGB4444
  11. # SDL_PIXELFORMAT_XRGB1555
  12. # SDL_PIXELFORMAT_ARGB4444
  13. # SDL_PIXELFORMAT_ARGB1555
  14. # SDL_PIXELFORMAT_RGB565
  15. # SDL_PIXELFORMAT_RGB24
  16. # SDL_PIXELFORMAT_BGR24
  17. # SDL_PIXELFORMAT_XRGB8888
  18. # SDL_PIXELFORMAT_XBGR8888
  19. # SDL_PIXELFORMAT_ARGB8888
  20. # SDL_PIXELFORMAT_RGBA8888
  21. # SDL_PIXELFORMAT_ABGR8888
  22. # SDL_PIXELFORMAT_BGRA8888
  23. # SDL_PIXELFORMAT_ARGB2101010
  24. # The formats we're actually creating blitters for:
  25. my @src_formats = (
  26. "XRGB8888",
  27. "XBGR8888",
  28. "ARGB8888",
  29. "RGBA8888",
  30. "ABGR8888",
  31. "BGRA8888",
  32. );
  33. my @dst_formats = (
  34. "XRGB8888",
  35. "XBGR8888",
  36. "ARGB8888",
  37. "ABGR8888",
  38. );
  39. my %format_size = (
  40. "XRGB8888" => 4,
  41. "XBGR8888" => 4,
  42. "ARGB8888" => 4,
  43. "RGBA8888" => 4,
  44. "ABGR8888" => 4,
  45. "BGRA8888" => 4,
  46. );
  47. my %format_type = (
  48. "XRGB8888" => "Uint32",
  49. "XBGR8888" => "Uint32",
  50. "ARGB8888" => "Uint32",
  51. "RGBA8888" => "Uint32",
  52. "ABGR8888" => "Uint32",
  53. "BGRA8888" => "Uint32",
  54. );
  55. my %get_rgba_string_ignore_alpha = (
  56. "XRGB8888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
  57. "XBGR8888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
  58. "ARGB8888" => "_R = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _B = (Uint8)_pixel;",
  59. "RGBA8888" => "_R = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _B = (Uint8)(_pixel >> 8);",
  60. "ABGR8888" => "_B = (Uint8)(_pixel >> 16); _G = (Uint8)(_pixel >> 8); _R = (Uint8)_pixel;",
  61. "BGRA8888" => "_B = (Uint8)(_pixel >> 24); _G = (Uint8)(_pixel >> 16); _R = (Uint8)(_pixel >> 8);",
  62. );
  63. my %get_rgba_string = (
  64. "XRGB8888" => $get_rgba_string_ignore_alpha{"XRGB8888"},
  65. "XBGR8888" => $get_rgba_string_ignore_alpha{"XBGR8888"},
  66. "ARGB8888" => $get_rgba_string_ignore_alpha{"ARGB8888"} . " _A = (Uint8)(_pixel >> 24);",
  67. "RGBA8888" => $get_rgba_string_ignore_alpha{"RGBA8888"} . " _A = (Uint8)_pixel;",
  68. "ABGR8888" => $get_rgba_string_ignore_alpha{"ABGR8888"} . " _A = (Uint8)(_pixel >> 24);",
  69. "BGRA8888" => $get_rgba_string_ignore_alpha{"BGRA8888"} . " _A = (Uint8)_pixel;",
  70. );
  71. my %set_rgba_string = (
  72. "XRGB8888" => "_pixel = (_R << 16) | (_G << 8) | _B;",
  73. "XBGR8888" => "_pixel = (_B << 16) | (_G << 8) | _R;",
  74. "ARGB8888" => "_pixel = (_A << 24) | (_R << 16) | (_G << 8) | _B;",
  75. "RGBA8888" => "_pixel = (_R << 24) | (_G << 16) | (_B << 8) | _A;",
  76. "ABGR8888" => "_pixel = (_A << 24) | (_B << 16) | (_G << 8) | _R;",
  77. "BGRA8888" => "_pixel = (_B << 24) | (_G << 16) | (_R << 8) | _A;",
  78. );
  79. sub open_file {
  80. my $name = shift;
  81. open(FILE, ">$name.new") || die "Can't open $name.new: $!";
  82. print FILE <<__EOF__;
  83. // DO NOT EDIT! This file is generated by sdlgenblit.pl
  84. /*
  85. Simple DirectMedia Layer
  86. Copyright (C) 1997-2025 Sam Lantinga <slouken\@libsdl.org>
  87. This software is provided 'as-is', without any express or implied
  88. warranty. In no event will the authors be held liable for any damages
  89. arising from the use of this software.
  90. Permission is granted to anyone to use this software for any purpose,
  91. including commercial applications, and to alter it and redistribute it
  92. freely, subject to the following restrictions:
  93. 1. The origin of this software must not be misrepresented; you must not
  94. claim that you wrote the original software. If you use this software
  95. in a product, an acknowledgment in the product documentation would be
  96. appreciated but is not required.
  97. 2. Altered source versions must be plainly marked as such, and must not be
  98. misrepresented as being the original software.
  99. 3. This notice may not be removed or altered from any source distribution.
  100. */
  101. #include "SDL_internal.h"
  102. #include "SDL_surface_c.h"
  103. #ifdef SDL_HAVE_BLIT_AUTO
  104. /* *INDENT-OFF* */ // clang-format off
  105. __EOF__
  106. }
  107. sub close_file {
  108. my $name = shift;
  109. print FILE <<__EOF__;
  110. /* *INDENT-ON* */ // clang-format on
  111. #endif // SDL_HAVE_BLIT_AUTO
  112. __EOF__
  113. close FILE;
  114. if ( ! -f $name || system("cmp -s $name $name.new") != 0 ) {
  115. rename("$name.new", "$name");
  116. } else {
  117. unlink("$name.new");
  118. }
  119. }
  120. sub output_copydefs
  121. {
  122. print FILE <<__EOF__;
  123. extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[];
  124. __EOF__
  125. }
  126. sub output_copyfuncname
  127. {
  128. my $prefix = shift;
  129. my $src = shift;
  130. my $dst = shift;
  131. my $modulate = shift;
  132. my $blend = shift;
  133. my $scale = shift;
  134. my $args = shift;
  135. my $suffix = shift;
  136. print FILE "$prefix SDL_Blit_${src}_${dst}";
  137. if ( $modulate ) {
  138. print FILE "_Modulate";
  139. }
  140. if ( $blend ) {
  141. print FILE "_Blend";
  142. }
  143. if ( $scale ) {
  144. print FILE "_Scale";
  145. }
  146. if ( $args ) {
  147. print FILE "(SDL_BlitInfo *info)";
  148. }
  149. print FILE "$suffix";
  150. }
  151. sub get_rgba
  152. {
  153. my $prefix = shift;
  154. my $format = shift;
  155. my $ignore_alpha = shift;
  156. my $string;
  157. if ($ignore_alpha) {
  158. $string = $get_rgba_string_ignore_alpha{$format};
  159. } else {
  160. $string = $get_rgba_string{$format};
  161. }
  162. $string =~ s/_/$prefix/g;
  163. if ( $prefix ne "" ) {
  164. print FILE <<__EOF__;
  165. ${prefix}pixel = *$prefix;
  166. __EOF__
  167. } else {
  168. print FILE <<__EOF__;
  169. pixel = *src;
  170. __EOF__
  171. }
  172. print FILE <<__EOF__;
  173. $string
  174. __EOF__
  175. }
  176. sub set_rgba
  177. {
  178. my $prefix = shift;
  179. my $format = shift;
  180. my $string = $set_rgba_string{$format};
  181. $string =~ s/_/$prefix/g;
  182. print FILE <<__EOF__;
  183. $string
  184. *dst = ${prefix}pixel;
  185. __EOF__
  186. }
  187. sub output_copycore
  188. {
  189. my $src = shift;
  190. my $dst = shift;
  191. my $modulate = shift;
  192. my $blend = shift;
  193. my $is_modulateA_done = shift;
  194. my $A_is_const_FF = shift;
  195. my $s = "";
  196. my $d = "";
  197. my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
  198. my $src_has_alpha = ($src =~ /A/) ? 1 : 0;
  199. my $sa = "";
  200. my $da = "";
  201. if (!$modulate && !$blend) {
  202. # Nice and easy...
  203. if ( $src eq $dst ) {
  204. print FILE <<__EOF__;
  205. *dst = *src;
  206. __EOF__
  207. return;
  208. }
  209. # Matching color-order
  210. $sa = $src;
  211. $sa =~ s/[XA8]//g;
  212. $da = $dst;
  213. $da =~ s/[XA8]//g;
  214. if ($sa eq $da) {
  215. if ($dst_has_alpha && $src_has_alpha) {
  216. $da = substr $dst, 0, 1;
  217. if ($da eq "A") {
  218. # RGBA -> ARGB
  219. print FILE <<__EOF__;
  220. pixel = *src;
  221. pixel = (pixel >> 8) | (pixel << 24);
  222. *dst = pixel;
  223. __EOF__
  224. } else {
  225. # ARGB -> RGBA -- unused
  226. print FILE <<__EOF__;
  227. pixel = *src;
  228. pixel = (pixel << 8) | A;
  229. *dst = pixel;
  230. __EOF__
  231. }
  232. } elsif ($dst_has_alpha) {
  233. $da = substr $dst, 0, 1;
  234. if ($da eq "A") {
  235. # XRGB -> ARGB
  236. print FILE <<__EOF__;
  237. pixel = *src;
  238. pixel |= (A << 24);
  239. *dst = pixel;
  240. __EOF__
  241. } else {
  242. # XRGB -> RGBA -- unused
  243. print FILE <<__EOF__;
  244. pixel = *src;
  245. pixel = (pixel << 8) | A;
  246. *dst = pixel;
  247. __EOF__
  248. }
  249. } else {
  250. $sa = substr $src, 0, 1;
  251. if ($sa eq "A") {
  252. # ARGB -> XRGB
  253. print FILE <<__EOF__;
  254. pixel = *src;
  255. pixel &= 0xFFFFFF;
  256. *dst = pixel;
  257. __EOF__
  258. } else {
  259. # RGBA -> XRGB
  260. print FILE <<__EOF__;
  261. pixel = *src;
  262. pixel >>= 8;
  263. *dst = pixel;
  264. __EOF__
  265. }
  266. }
  267. return;
  268. }
  269. }
  270. my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
  271. if ( $blend ) {
  272. get_rgba("src", $src, $ignore_dst_alpha);
  273. get_rgba("dst", $dst, !$dst_has_alpha);
  274. $s = "src";
  275. $d = "dst";
  276. } else {
  277. get_rgba("", $src, $ignore_dst_alpha);
  278. }
  279. if ( $modulate ) {
  280. print FILE <<__EOF__;
  281. if (flags & SDL_COPY_MODULATE_COLOR) {
  282. MULT_DIV_255(${s}R, modulateR, ${s}R);
  283. MULT_DIV_255(${s}G, modulateG, ${s}G);
  284. MULT_DIV_255(${s}B, modulateB, ${s}B);
  285. }
  286. __EOF__
  287. if (!$ignore_dst_alpha && !$is_modulateA_done) {
  288. print FILE <<__EOF__;
  289. if (flags & SDL_COPY_MODULATE_ALPHA) {
  290. MULT_DIV_255(${s}A, modulateA, ${s}A);
  291. }
  292. __EOF__
  293. }
  294. }
  295. if ( $blend ) {
  296. if (!$A_is_const_FF) {
  297. print FILE <<__EOF__;
  298. if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
  299. if (${s}A < 255) {
  300. MULT_DIV_255(${s}R, ${s}A, ${s}R);
  301. MULT_DIV_255(${s}G, ${s}A, ${s}G);
  302. MULT_DIV_255(${s}B, ${s}A, ${s}B);
  303. }
  304. }
  305. __EOF__
  306. }
  307. print FILE <<__EOF__;
  308. switch (flags & SDL_COPY_BLEND_MASK) {
  309. case SDL_COPY_BLEND:
  310. __EOF__
  311. if ($A_is_const_FF) {
  312. print FILE <<__EOF__;
  313. ${d}R = ${s}R;
  314. ${d}G = ${s}G;
  315. ${d}B = ${s}B;
  316. __EOF__
  317. } else {
  318. print FILE <<__EOF__;
  319. MULT_DIV_255((255 - ${s}A), ${d}R, ${d}R);
  320. ${d}R += ${s}R;
  321. MULT_DIV_255((255 - ${s}A), ${d}G, ${d}G);
  322. ${d}G += ${s}G;
  323. MULT_DIV_255((255 - ${s}A), ${d}B, ${d}B);
  324. ${d}B += ${s}B;
  325. __EOF__
  326. }
  327. if ( $dst_has_alpha ) {
  328. if ($A_is_const_FF) {
  329. print FILE <<__EOF__;
  330. ${d}A = 0xFF;
  331. __EOF__
  332. } else {
  333. print FILE <<__EOF__;
  334. MULT_DIV_255((255 - ${s}A), ${d}A, ${d}A);
  335. ${d}A += ${s}A;
  336. __EOF__
  337. }
  338. }
  339. print FILE <<__EOF__;
  340. break;
  341. case SDL_COPY_BLEND_PREMULTIPLIED:
  342. __EOF__
  343. if ($A_is_const_FF) {
  344. print FILE <<__EOF__;
  345. ${d}R = ${s}R;
  346. ${d}G = ${s}G;
  347. ${d}B = ${s}B;
  348. __EOF__
  349. } else {
  350. print FILE <<__EOF__;
  351. MULT_DIV_255((255 - ${s}A), ${d}R, ${d}R);
  352. ${d}R += ${s}R;
  353. if (${d}R > 255) ${d}R = 255;
  354. MULT_DIV_255((255 - ${s}A), ${d}G, ${d}G);
  355. ${d}G += ${s}G;
  356. if (${d}G > 255) ${d}G = 255;
  357. MULT_DIV_255((255 - ${s}A), ${d}B, ${d}B);
  358. ${d}B += ${s}B;
  359. if (${d}B > 255) ${d}B = 255;
  360. __EOF__
  361. }
  362. if ( $dst_has_alpha ) {
  363. if ($A_is_const_FF) {
  364. print FILE <<__EOF__;
  365. ${d}A = 0xFF;
  366. __EOF__
  367. } else {
  368. print FILE <<__EOF__;
  369. MULT_DIV_255((255 - ${s}A), ${d}A, ${d}A);
  370. ${d}A += ${s}A;
  371. if (${d}A > 255) ${d}A = 255;
  372. __EOF__
  373. }
  374. }
  375. print FILE <<__EOF__;
  376. break;
  377. case SDL_COPY_ADD:
  378. case SDL_COPY_ADD_PREMULTIPLIED:
  379. ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
  380. ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
  381. ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
  382. break;
  383. case SDL_COPY_MOD:
  384. MULT_DIV_255(${s}R, ${d}R, ${d}R);
  385. MULT_DIV_255(${s}G, ${d}G, ${d}G);
  386. MULT_DIV_255(${s}B, ${d}B, ${d}B);
  387. break;
  388. case SDL_COPY_MUL:
  389. __EOF__
  390. if ($A_is_const_FF) {
  391. print FILE <<__EOF__;
  392. MULT_DIV_255(${s}R, ${d}R, ${d}R);
  393. MULT_DIV_255(${s}G, ${d}G, ${d}G);
  394. MULT_DIV_255(${s}B, ${d}B, ${d}B);
  395. __EOF__
  396. } else {
  397. print FILE <<__EOF__;
  398. {
  399. Uint32 tmp1, tmp2;
  400. MULT_DIV_255(${s}R, ${d}R, tmp1);
  401. MULT_DIV_255(${d}R, (255 - ${s}A), tmp2);
  402. ${d}R = tmp1 + tmp2; if (${d}R > 255) ${d}R = 255;
  403. MULT_DIV_255(${s}G, ${d}G, tmp1);
  404. MULT_DIV_255(${d}G, (255 - ${s}A), tmp2);
  405. ${d}G = tmp1 + tmp2; if (${d}G > 255) ${d}G = 255;
  406. MULT_DIV_255(${s}B, ${d}B, tmp1);
  407. MULT_DIV_255(${d}B, (255 - ${s}A), tmp2);
  408. ${d}B = tmp1 + tmp2; if (${d}B > 255) ${d}B = 255;
  409. }
  410. __EOF__
  411. }
  412. print FILE <<__EOF__;
  413. break;
  414. }
  415. __EOF__
  416. }
  417. if ( $blend ) {
  418. set_rgba("dst", $dst);
  419. } else {
  420. set_rgba("", $dst);
  421. }
  422. }
  423. sub output_copyfunc
  424. {
  425. my $src = shift;
  426. my $dst = shift;
  427. my $modulate = shift;
  428. my $blend = shift;
  429. my $scale = shift;
  430. my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
  431. my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
  432. my $src_has_alpha = ($src =~ /A/) ? 1 : 0;
  433. my $is_modulateA_done = 0;
  434. my $A_is_const_FF = 0;
  435. my $sa = $src;
  436. my $da = $dst;
  437. my $matching_colors = 0;
  438. $sa =~ s/[XA8]//g;
  439. $da =~ s/[XA8]//g;
  440. $matching_colors = (!$modulate && !$blend && ($sa eq $da)) ? 1 : 0;
  441. output_copyfuncname("static void", $src, $dst, $modulate, $blend, $scale, 1, "\n");
  442. print FILE <<__EOF__;
  443. {
  444. __EOF__
  445. if ( $modulate || $blend ) {
  446. print FILE <<__EOF__;
  447. const int flags = info->flags;
  448. __EOF__
  449. }
  450. if ( $modulate ) {
  451. print FILE <<__EOF__;
  452. const Uint32 modulateR = info->r;
  453. const Uint32 modulateG = info->g;
  454. const Uint32 modulateB = info->b;
  455. __EOF__
  456. if (!$ignore_dst_alpha) {
  457. print FILE <<__EOF__;
  458. const Uint32 modulateA = info->a;
  459. __EOF__
  460. }
  461. }
  462. if ( $blend ) {
  463. print FILE <<__EOF__;
  464. Uint32 srcpixel;
  465. __EOF__
  466. if (!$ignore_dst_alpha && !$src_has_alpha) {
  467. if ($modulate){
  468. $is_modulateA_done = 1;
  469. print FILE <<__EOF__;
  470. const Uint32 srcA = (flags & SDL_COPY_MODULATE_ALPHA) ? modulateA : 0xFF;
  471. __EOF__
  472. } else {
  473. $A_is_const_FF = 1;
  474. }
  475. print FILE <<__EOF__;
  476. Uint32 srcR, srcG, srcB;
  477. __EOF__
  478. } else {
  479. print FILE <<__EOF__;
  480. Uint32 srcR, srcG, srcB, srcA;
  481. __EOF__
  482. }
  483. print FILE <<__EOF__;
  484. Uint32 dstpixel;
  485. __EOF__
  486. if ($dst_has_alpha) {
  487. print FILE <<__EOF__;
  488. Uint32 dstR, dstG, dstB, dstA;
  489. __EOF__
  490. } else {
  491. print FILE <<__EOF__;
  492. Uint32 dstR, dstG, dstB;
  493. __EOF__
  494. }
  495. } elsif ( $modulate || $src ne $dst ) {
  496. print FILE <<__EOF__;
  497. Uint32 pixel;
  498. __EOF__
  499. if ( !$ignore_dst_alpha && !$src_has_alpha ) {
  500. if ( $modulate ) {
  501. $is_modulateA_done = 1;
  502. print FILE <<__EOF__;
  503. const Uint32 A = (flags & SDL_COPY_MODULATE_ALPHA) ? modulateA : 0xFF;
  504. __EOF__
  505. } else {
  506. $A_is_const_FF = 1;
  507. print FILE <<__EOF__;
  508. const Uint32 A = 0xFF;
  509. __EOF__
  510. }
  511. if ( !$matching_colors ) {
  512. print FILE <<__EOF__;
  513. Uint32 R, G, B;
  514. __EOF__
  515. }
  516. } elsif ( !$ignore_dst_alpha ) {
  517. if ( !$matching_colors ) {
  518. print FILE <<__EOF__;
  519. Uint32 R, G, B, A;
  520. __EOF__
  521. }
  522. } elsif ( !$matching_colors ) {
  523. print FILE <<__EOF__;
  524. Uint32 R, G, B;
  525. __EOF__
  526. }
  527. }
  528. if ( $scale ) {
  529. print FILE <<__EOF__;
  530. Uint64 srcy, srcx;
  531. Uint64 posy, posx;
  532. Uint64 incy, incx;
  533. __EOF__
  534. print FILE <<__EOF__;
  535. incy = ((Uint64)info->src_h << 16) / info->dst_h;
  536. incx = ((Uint64)info->src_w << 16) / info->dst_w;
  537. posy = incy / 2;
  538. while (info->dst_h--) {
  539. $format_type{$src} *src = 0;
  540. $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
  541. int n = info->dst_w;
  542. posx = incx / 2;
  543. srcy = posy >> 16;
  544. while (n--) {
  545. srcx = posx >> 16;
  546. src = ($format_type{$src} *)(info->src + (srcy * info->src_pitch) + (srcx * $format_size{$src}));
  547. __EOF__
  548. print FILE <<__EOF__;
  549. __EOF__
  550. output_copycore($src, $dst, $modulate, $blend, $is_modulateA_done, $A_is_const_FF);
  551. print FILE <<__EOF__;
  552. posx += incx;
  553. ++dst;
  554. }
  555. posy += incy;
  556. info->dst += info->dst_pitch;
  557. }
  558. __EOF__
  559. } else {
  560. print FILE <<__EOF__;
  561. while (info->dst_h--) {
  562. $format_type{$src} *src = ($format_type{$src} *)info->src;
  563. $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
  564. int n = info->dst_w;
  565. while (n--) {
  566. __EOF__
  567. output_copycore($src, $dst, $modulate, $blend, $is_modulateA_done, $A_is_const_FF);
  568. print FILE <<__EOF__;
  569. ++src;
  570. ++dst;
  571. }
  572. info->src += info->src_pitch;
  573. info->dst += info->dst_pitch;
  574. }
  575. __EOF__
  576. }
  577. print FILE <<__EOF__;
  578. }
  579. __EOF__
  580. }
  581. sub output_copyfunc_h
  582. {
  583. }
  584. sub output_copyinc
  585. {
  586. print FILE <<__EOF__;
  587. #include "SDL_blit.h"
  588. #include "SDL_blit_auto.h"
  589. __EOF__
  590. }
  591. sub output_copyfunctable
  592. {
  593. print FILE <<__EOF__;
  594. SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
  595. __EOF__
  596. for (my $i = 0; $i <= $#src_formats; ++$i) {
  597. my $src = $src_formats[$i];
  598. for (my $j = 0; $j <= $#dst_formats; ++$j) {
  599. my $dst = $dst_formats[$j];
  600. for (my $modulate = 0; $modulate <= 1; ++$modulate) {
  601. for (my $blend = 0; $blend <= 1; ++$blend) {
  602. for (my $scale = 0; $scale <= 1; ++$scale) {
  603. if ( $modulate || $blend || $scale ) {
  604. print FILE " { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
  605. my $flags = "";
  606. my $flag = "";
  607. if ( $modulate ) {
  608. $flag = "SDL_COPY_MODULATE_MASK";
  609. if ( $flags eq "" ) {
  610. $flags = $flag;
  611. } else {
  612. $flags = "$flags | $flag";
  613. }
  614. }
  615. if ( $blend ) {
  616. $flag = "SDL_COPY_BLEND_MASK";
  617. if ( $flags eq "" ) {
  618. $flags = $flag;
  619. } else {
  620. $flags = "$flags | $flag";
  621. }
  622. }
  623. if ( $scale ) {
  624. $flag = "SDL_COPY_NEAREST";
  625. if ( $flags eq "" ) {
  626. $flags = $flag;
  627. } else {
  628. $flags = "$flags | $flag";
  629. }
  630. }
  631. if ( $flags eq "" ) {
  632. $flags = "0";
  633. }
  634. print FILE "($flags), SDL_CPU_ANY,";
  635. output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642. print FILE <<__EOF__;
  643. { 0, 0, 0, 0, NULL }
  644. };
  645. __EOF__
  646. }
  647. sub output_copyfunc_c
  648. {
  649. my $src = shift;
  650. my $dst = shift;
  651. for (my $modulate = 0; $modulate <= 1; ++$modulate) {
  652. for (my $blend = 0; $blend <= 1; ++$blend) {
  653. for (my $scale = 0; $scale <= 1; ++$scale) {
  654. if ( $modulate || $blend || $scale ) {
  655. output_copyfunc($src, $dst, $modulate, $blend, $scale);
  656. }
  657. }
  658. }
  659. }
  660. }
  661. open_file("SDL_blit_auto.h");
  662. output_copydefs();
  663. for (my $i = 0; $i <= $#src_formats; ++$i) {
  664. for (my $j = 0; $j <= $#dst_formats; ++$j) {
  665. output_copyfunc_h($src_formats[$i], $dst_formats[$j]);
  666. }
  667. }
  668. print FILE "\n";
  669. close_file("SDL_blit_auto.h");
  670. open_file("SDL_blit_auto.c");
  671. output_copyinc();
  672. for (my $i = 0; $i <= $#src_formats; ++$i) {
  673. for (my $j = 0; $j <= $#dst_formats; ++$j) {
  674. output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
  675. }
  676. }
  677. output_copyfunctable();
  678. close_file("SDL_blit_auto.c");