sdlgenblit.pl 19 KB

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