sdlgenblit.pl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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-2026 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. #ifdef SDL_HAVE_BLIT_AUTO
  103. /* *INDENT-OFF* */ // clang-format off
  104. __EOF__
  105. }
  106. sub close_file {
  107. my $name = shift;
  108. print FILE <<__EOF__;
  109. /* *INDENT-ON* */ // clang-format on
  110. #endif // SDL_HAVE_BLIT_AUTO
  111. __EOF__
  112. close FILE;
  113. if ( ! -f $name || system("cmp -s $name $name.new") != 0 ) {
  114. rename("$name.new", "$name");
  115. } else {
  116. unlink("$name.new");
  117. }
  118. }
  119. sub output_copydefs
  120. {
  121. print FILE <<__EOF__;
  122. extern SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[];
  123. __EOF__
  124. }
  125. sub output_copyfuncname
  126. {
  127. my $prefix = shift;
  128. my $src = shift;
  129. my $dst = shift;
  130. my $modulate = shift;
  131. my $blend = shift;
  132. my $scale = shift;
  133. my $args = shift;
  134. my $suffix = shift;
  135. print FILE "$prefix SDL_Blit_${src}_${dst}";
  136. if ( $modulate ) {
  137. print FILE "_Modulate";
  138. }
  139. if ( $blend ) {
  140. print FILE "_Blend";
  141. }
  142. if ( $scale ) {
  143. print FILE "_Scale";
  144. }
  145. if ( $args ) {
  146. print FILE "(SDL_BlitInfo *info)";
  147. }
  148. print FILE "$suffix";
  149. }
  150. sub get_rgba
  151. {
  152. my $prefix = shift;
  153. my $format = shift;
  154. my $ignore_alpha = shift;
  155. my $string;
  156. if ($ignore_alpha) {
  157. $string = $get_rgba_string_ignore_alpha{$format};
  158. } else {
  159. $string = $get_rgba_string{$format};
  160. }
  161. $string =~ s/__/$prefix/g;
  162. if ( $prefix eq "" ) {
  163. $string =~ s/_/value/g;
  164. } else {
  165. $string =~ s/_//g;
  166. }
  167. if ( $prefix ne "" ) {
  168. print FILE <<__EOF__;
  169. ${prefix}pixel = *$prefix;
  170. __EOF__
  171. } else {
  172. print FILE <<__EOF__;
  173. pixelvalue = *src;
  174. __EOF__
  175. }
  176. print FILE <<__EOF__;
  177. $string
  178. __EOF__
  179. }
  180. sub set_rgba
  181. {
  182. my $prefix = shift;
  183. my $format = shift;
  184. my $suffix = "";
  185. my $string = $set_rgba_string{$format};
  186. $string =~ s/__/$prefix/g;
  187. if ( $prefix eq "" ) {
  188. $suffix = "value";
  189. $string =~ s/_/value/g;
  190. } else {
  191. $string =~ s/_//g;
  192. }
  193. print FILE <<__EOF__;
  194. $string
  195. *dst = ${prefix}pixel${suffix};
  196. __EOF__
  197. }
  198. sub output_copycore
  199. {
  200. my $src = shift;
  201. my $dst = shift;
  202. my $modulate = shift;
  203. my $blend = shift;
  204. my $is_modulateA_done = shift;
  205. my $A_is_const_FF = shift;
  206. my $s = "";
  207. my $d = "";
  208. my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
  209. my $src_has_alpha = ($src =~ /A/) ? 1 : 0;
  210. my $sa = "";
  211. my $da = "";
  212. if (!$modulate && !$blend) {
  213. # Nice and easy...
  214. if ( $src eq $dst ) {
  215. print FILE <<__EOF__;
  216. *dst = *src;
  217. __EOF__
  218. return;
  219. }
  220. # Matching color-order
  221. $sa = $src;
  222. $sa =~ s/[XA8]//g;
  223. $da = $dst;
  224. $da =~ s/[XA8]//g;
  225. if ($sa eq $da) {
  226. if ($dst_has_alpha && $src_has_alpha) {
  227. $da = substr $dst, 0, 1;
  228. if ($da eq "A") {
  229. # RGBA -> ARGB
  230. print FILE <<__EOF__;
  231. pixelvalue = *src;
  232. pixelvalue = (pixelvalue >> 8) | (pixelvalue << 24);
  233. *dst = pixelvalue;
  234. __EOF__
  235. } else {
  236. # ARGB -> RGBA -- unused
  237. print FILE <<__EOF__;
  238. pixelvalue = *src;
  239. pixelvalue = (pixelvalue << 8) | A;
  240. *dst = pixelvalue;
  241. __EOF__
  242. }
  243. } elsif ($dst_has_alpha) {
  244. $da = substr $dst, 0, 1;
  245. if ($da eq "A") {
  246. # XRGB -> ARGB
  247. print FILE <<__EOF__;
  248. pixelvalue = *src;
  249. pixelvalue |= (A << 24);
  250. *dst = pixelvalue;
  251. __EOF__
  252. } else {
  253. # XRGB -> RGBA -- unused
  254. print FILE <<__EOF__;
  255. pixelvalue = *src;
  256. pixelvalue = (pixelvalue << 8) | A;
  257. *dst = pixelvalue;
  258. __EOF__
  259. }
  260. } else {
  261. $sa = substr $src, 0, 1;
  262. if ($sa eq "A") {
  263. # ARGB -> XRGB
  264. print FILE <<__EOF__;
  265. pixelvalue = *src;
  266. pixelvalue &= 0xFFFFFF;
  267. *dst = pixelvalue;
  268. __EOF__
  269. } else {
  270. # RGBA -> XRGB
  271. print FILE <<__EOF__;
  272. pixelvalue = *src;
  273. pixelvalue >>= 8;
  274. *dst = pixelvalue;
  275. __EOF__
  276. }
  277. }
  278. return;
  279. }
  280. }
  281. my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
  282. if ( $blend ) {
  283. get_rgba("src", $src, $ignore_dst_alpha);
  284. get_rgba("dst", $dst, !$dst_has_alpha);
  285. $s = "src";
  286. $d = "dst";
  287. } else {
  288. get_rgba("", $src, $ignore_dst_alpha);
  289. }
  290. if ( $modulate ) {
  291. print FILE <<__EOF__;
  292. if (flags & SDL_COPY_MODULATE_COLOR) {
  293. MULT_DIV_255(${s}R, modulateR, ${s}R);
  294. MULT_DIV_255(${s}G, modulateG, ${s}G);
  295. MULT_DIV_255(${s}B, modulateB, ${s}B);
  296. }
  297. __EOF__
  298. if (!$ignore_dst_alpha && !$is_modulateA_done) {
  299. print FILE <<__EOF__;
  300. if (flags & SDL_COPY_MODULATE_ALPHA) {
  301. MULT_DIV_255(${s}A, modulateA, ${s}A);
  302. }
  303. __EOF__
  304. }
  305. }
  306. if ( $blend ) {
  307. if (!$A_is_const_FF) {
  308. print FILE <<__EOF__;
  309. if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
  310. if (${s}A < 255) {
  311. MULT_DIV_255(${s}R, ${s}A, ${s}R);
  312. MULT_DIV_255(${s}G, ${s}A, ${s}G);
  313. MULT_DIV_255(${s}B, ${s}A, ${s}B);
  314. }
  315. }
  316. __EOF__
  317. }
  318. print FILE <<__EOF__;
  319. switch (flags & SDL_COPY_BLEND_MASK) {
  320. case SDL_COPY_BLEND:
  321. __EOF__
  322. if ($A_is_const_FF) {
  323. print FILE <<__EOF__;
  324. ${d}R = ${s}R;
  325. ${d}G = ${s}G;
  326. ${d}B = ${s}B;
  327. __EOF__
  328. } else {
  329. print FILE <<__EOF__;
  330. MULT_DIV_255((255 - ${s}A), ${d}R, ${d}R);
  331. ${d}R += ${s}R;
  332. MULT_DIV_255((255 - ${s}A), ${d}G, ${d}G);
  333. ${d}G += ${s}G;
  334. MULT_DIV_255((255 - ${s}A), ${d}B, ${d}B);
  335. ${d}B += ${s}B;
  336. __EOF__
  337. }
  338. if ( $dst_has_alpha ) {
  339. if ($A_is_const_FF) {
  340. print FILE <<__EOF__;
  341. ${d}A = 0xFF;
  342. __EOF__
  343. } else {
  344. print FILE <<__EOF__;
  345. MULT_DIV_255((255 - ${s}A), ${d}A, ${d}A);
  346. ${d}A += ${s}A;
  347. __EOF__
  348. }
  349. }
  350. print FILE <<__EOF__;
  351. break;
  352. case SDL_COPY_BLEND_PREMULTIPLIED:
  353. __EOF__
  354. if ($A_is_const_FF) {
  355. print FILE <<__EOF__;
  356. ${d}R = ${s}R;
  357. ${d}G = ${s}G;
  358. ${d}B = ${s}B;
  359. __EOF__
  360. } else {
  361. print FILE <<__EOF__;
  362. MULT_DIV_255((255 - ${s}A), ${d}R, ${d}R);
  363. ${d}R += ${s}R;
  364. if (${d}R > 255) ${d}R = 255;
  365. MULT_DIV_255((255 - ${s}A), ${d}G, ${d}G);
  366. ${d}G += ${s}G;
  367. if (${d}G > 255) ${d}G = 255;
  368. MULT_DIV_255((255 - ${s}A), ${d}B, ${d}B);
  369. ${d}B += ${s}B;
  370. if (${d}B > 255) ${d}B = 255;
  371. __EOF__
  372. }
  373. if ( $dst_has_alpha ) {
  374. if ($A_is_const_FF) {
  375. print FILE <<__EOF__;
  376. ${d}A = 0xFF;
  377. __EOF__
  378. } else {
  379. print FILE <<__EOF__;
  380. MULT_DIV_255((255 - ${s}A), ${d}A, ${d}A);
  381. ${d}A += ${s}A;
  382. if (${d}A > 255) ${d}A = 255;
  383. __EOF__
  384. }
  385. }
  386. print FILE <<__EOF__;
  387. break;
  388. case SDL_COPY_ADD:
  389. case SDL_COPY_ADD_PREMULTIPLIED:
  390. ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
  391. ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
  392. ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
  393. break;
  394. case SDL_COPY_MOD:
  395. MULT_DIV_255(${s}R, ${d}R, ${d}R);
  396. MULT_DIV_255(${s}G, ${d}G, ${d}G);
  397. MULT_DIV_255(${s}B, ${d}B, ${d}B);
  398. break;
  399. case SDL_COPY_MUL:
  400. __EOF__
  401. if ($A_is_const_FF) {
  402. print FILE <<__EOF__;
  403. MULT_DIV_255(${s}R, ${d}R, ${d}R);
  404. MULT_DIV_255(${s}G, ${d}G, ${d}G);
  405. MULT_DIV_255(${s}B, ${d}B, ${d}B);
  406. __EOF__
  407. } else {
  408. print FILE <<__EOF__;
  409. {
  410. Uint32 tmp1, tmp2;
  411. MULT_DIV_255(${s}R, ${d}R, tmp1);
  412. MULT_DIV_255(${d}R, (255 - ${s}A), tmp2);
  413. ${d}R = tmp1 + tmp2; if (${d}R > 255) ${d}R = 255;
  414. MULT_DIV_255(${s}G, ${d}G, tmp1);
  415. MULT_DIV_255(${d}G, (255 - ${s}A), tmp2);
  416. ${d}G = tmp1 + tmp2; if (${d}G > 255) ${d}G = 255;
  417. MULT_DIV_255(${s}B, ${d}B, tmp1);
  418. MULT_DIV_255(${d}B, (255 - ${s}A), tmp2);
  419. ${d}B = tmp1 + tmp2; if (${d}B > 255) ${d}B = 255;
  420. }
  421. __EOF__
  422. }
  423. print FILE <<__EOF__;
  424. break;
  425. }
  426. __EOF__
  427. }
  428. if ( $blend ) {
  429. set_rgba("dst", $dst);
  430. } else {
  431. set_rgba("", $dst);
  432. }
  433. }
  434. sub output_copyfunc
  435. {
  436. my $src = shift;
  437. my $dst = shift;
  438. my $modulate = shift;
  439. my $blend = shift;
  440. my $scale = shift;
  441. my $dst_has_alpha = ($dst =~ /A/) ? 1 : 0;
  442. my $ignore_dst_alpha = !$dst_has_alpha && !$blend;
  443. my $src_has_alpha = ($src =~ /A/) ? 1 : 0;
  444. my $is_modulateA_done = 0;
  445. my $A_is_const_FF = 0;
  446. my $sa = $src;
  447. my $da = $dst;
  448. my $matching_colors = 0;
  449. $sa =~ s/[XA8]//g;
  450. $da =~ s/[XA8]//g;
  451. $matching_colors = (!$modulate && !$blend && ($sa eq $da)) ? 1 : 0;
  452. output_copyfuncname("static void", $src, $dst, $modulate, $blend, $scale, 1, "\n");
  453. print FILE <<__EOF__;
  454. {
  455. __EOF__
  456. if ( $modulate || $blend ) {
  457. print FILE <<__EOF__;
  458. const int flags = info->flags;
  459. __EOF__
  460. }
  461. if ( $modulate ) {
  462. print FILE <<__EOF__;
  463. const Uint32 modulateR = info->r;
  464. const Uint32 modulateG = info->g;
  465. const Uint32 modulateB = info->b;
  466. __EOF__
  467. if (!$ignore_dst_alpha) {
  468. print FILE <<__EOF__;
  469. const Uint32 modulateA = info->a;
  470. __EOF__
  471. }
  472. }
  473. if ( $blend ) {
  474. print FILE <<__EOF__;
  475. Uint32 srcpixel;
  476. __EOF__
  477. if (!$ignore_dst_alpha && !$src_has_alpha) {
  478. if ($modulate){
  479. $is_modulateA_done = 1;
  480. print FILE <<__EOF__;
  481. const Uint32 srcA = (flags & SDL_COPY_MODULATE_ALPHA) ? modulateA : 0xFF;
  482. __EOF__
  483. } else {
  484. $A_is_const_FF = 1;
  485. }
  486. print FILE <<__EOF__;
  487. Uint32 srcR, srcG, srcB;
  488. __EOF__
  489. } else {
  490. print FILE <<__EOF__;
  491. Uint32 srcR, srcG, srcB, srcA;
  492. __EOF__
  493. }
  494. print FILE <<__EOF__;
  495. Uint32 dstpixel;
  496. __EOF__
  497. if ($dst_has_alpha) {
  498. print FILE <<__EOF__;
  499. Uint32 dstR, dstG, dstB, dstA;
  500. __EOF__
  501. } else {
  502. print FILE <<__EOF__;
  503. Uint32 dstR, dstG, dstB;
  504. __EOF__
  505. }
  506. } elsif ( $modulate || $src ne $dst ) {
  507. print FILE <<__EOF__;
  508. Uint32 pixelvalue;
  509. __EOF__
  510. if ( !$ignore_dst_alpha && !$src_has_alpha ) {
  511. if ( $modulate ) {
  512. $is_modulateA_done = 1;
  513. print FILE <<__EOF__;
  514. const Uint32 A = (flags & SDL_COPY_MODULATE_ALPHA) ? modulateA : 0xFF;
  515. __EOF__
  516. } else {
  517. $A_is_const_FF = 1;
  518. print FILE <<__EOF__;
  519. const Uint32 A = 0xFF;
  520. __EOF__
  521. }
  522. if ( !$matching_colors ) {
  523. print FILE <<__EOF__;
  524. Uint32 R, G, B;
  525. __EOF__
  526. }
  527. } elsif ( !$ignore_dst_alpha ) {
  528. if ( !$matching_colors ) {
  529. print FILE <<__EOF__;
  530. Uint32 R, G, B, A;
  531. __EOF__
  532. }
  533. } elsif ( !$matching_colors ) {
  534. print FILE <<__EOF__;
  535. Uint32 R, G, B;
  536. __EOF__
  537. }
  538. }
  539. if ( $scale ) {
  540. print FILE <<__EOF__;
  541. Uint64 srcy, srcx;
  542. Uint64 posy, posx;
  543. Uint64 incy, incx;
  544. __EOF__
  545. print FILE <<__EOF__;
  546. incy = ((Uint64)info->src_h << 16) / info->dst_h;
  547. incx = ((Uint64)info->src_w << 16) / info->dst_w;
  548. posy = incy / 2;
  549. while (info->dst_h--) {
  550. $format_type{$src} *src = NULL;
  551. $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
  552. int n = info->dst_w;
  553. posx = incx / 2;
  554. srcy = posy >> 16;
  555. while (n--) {
  556. srcx = posx >> 16;
  557. src = ($format_type{$src} *)(info->src + (srcy * info->src_pitch) + (srcx * $format_size{$src}));
  558. __EOF__
  559. print FILE <<__EOF__;
  560. __EOF__
  561. output_copycore($src, $dst, $modulate, $blend, $is_modulateA_done, $A_is_const_FF);
  562. print FILE <<__EOF__;
  563. posx += incx;
  564. ++dst;
  565. }
  566. posy += incy;
  567. info->dst += info->dst_pitch;
  568. }
  569. __EOF__
  570. } else {
  571. print FILE <<__EOF__;
  572. while (info->dst_h--) {
  573. $format_type{$src} *src = ($format_type{$src} *)info->src;
  574. $format_type{$dst} *dst = ($format_type{$dst} *)info->dst;
  575. int n = info->dst_w;
  576. while (n--) {
  577. __EOF__
  578. output_copycore($src, $dst, $modulate, $blend, $is_modulateA_done, $A_is_const_FF);
  579. print FILE <<__EOF__;
  580. ++src;
  581. ++dst;
  582. }
  583. info->src += info->src_pitch;
  584. info->dst += info->dst_pitch;
  585. }
  586. __EOF__
  587. }
  588. print FILE <<__EOF__;
  589. }
  590. __EOF__
  591. }
  592. sub output_copyfunc_h
  593. {
  594. }
  595. sub output_copyinc
  596. {
  597. print FILE <<__EOF__;
  598. #include "SDL_blit.h"
  599. #include "SDL_blit_auto.h"
  600. __EOF__
  601. }
  602. sub output_copyinc_h
  603. {
  604. print FILE <<__EOF__;
  605. #include "SDL_blit.h"
  606. __EOF__
  607. }
  608. sub output_copyfunctable
  609. {
  610. print FILE <<__EOF__;
  611. SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
  612. __EOF__
  613. for (my $i = 0; $i <= $#src_formats; ++$i) {
  614. my $src = $src_formats[$i];
  615. for (my $j = 0; $j <= $#dst_formats; ++$j) {
  616. my $dst = $dst_formats[$j];
  617. for (my $modulate = 0; $modulate <= 1; ++$modulate) {
  618. for (my $blend = 0; $blend <= 1; ++$blend) {
  619. for (my $scale = 0; $scale <= 1; ++$scale) {
  620. if ( $modulate || $blend || $scale ) {
  621. print FILE " { SDL_PIXELFORMAT_$src, SDL_PIXELFORMAT_$dst, ";
  622. my $flags = "";
  623. my $flag = "";
  624. if ( $modulate ) {
  625. $flag = "SDL_COPY_MODULATE_MASK";
  626. if ( $flags eq "" ) {
  627. $flags = $flag;
  628. } else {
  629. $flags = "$flags | $flag";
  630. }
  631. }
  632. if ( $blend ) {
  633. $flag = "SDL_COPY_BLEND_MASK";
  634. if ( $flags eq "" ) {
  635. $flags = $flag;
  636. } else {
  637. $flags = "$flags | $flag";
  638. }
  639. }
  640. if ( $scale ) {
  641. $flag = "SDL_COPY_NEAREST";
  642. if ( $flags eq "" ) {
  643. $flags = $flag;
  644. } else {
  645. $flags = "$flags | $flag";
  646. }
  647. }
  648. if ( $flags eq "" ) {
  649. $flags = "0";
  650. }
  651. print FILE "($flags), SDL_CPU_ANY,";
  652. output_copyfuncname("", $src_formats[$i], $dst_formats[$j], $modulate, $blend, $scale, 0, " },\n");
  653. }
  654. }
  655. }
  656. }
  657. }
  658. }
  659. print FILE <<__EOF__;
  660. { SDL_PIXELFORMAT_UNKNOWN, SDL_PIXELFORMAT_UNKNOWN, 0, 0, NULL }
  661. };
  662. __EOF__
  663. }
  664. sub output_copyfunc_c
  665. {
  666. my $src = shift;
  667. my $dst = shift;
  668. for (my $modulate = 0; $modulate <= 1; ++$modulate) {
  669. for (my $blend = 0; $blend <= 1; ++$blend) {
  670. for (my $scale = 0; $scale <= 1; ++$scale) {
  671. if ( $modulate || $blend || $scale ) {
  672. output_copyfunc($src, $dst, $modulate, $blend, $scale);
  673. }
  674. }
  675. }
  676. }
  677. }
  678. open_file("SDL_blit_auto.h");
  679. output_copyinc_h();
  680. output_copydefs();
  681. for (my $i = 0; $i <= $#src_formats; ++$i) {
  682. for (my $j = 0; $j <= $#dst_formats; ++$j) {
  683. output_copyfunc_h($src_formats[$i], $dst_formats[$j]);
  684. }
  685. }
  686. print FILE "\n";
  687. close_file("SDL_blit_auto.h");
  688. open_file("SDL_blit_auto.c");
  689. output_copyinc();
  690. for (my $i = 0; $i <= $#src_formats; ++$i) {
  691. for (my $j = 0; $j <= $#dst_formats; ++$j) {
  692. output_copyfunc_c($src_formats[$i], $dst_formats[$j]);
  693. }
  694. }
  695. output_copyfunctable();
  696. close_file("SDL_blit_auto.c");