1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810
|
/* gap_story_render_processor.c
*
*
* GAP storyboard rendering processor.
*
* GAP video encoder tool procedures for STORYBOARD file based video encoding
* This module is the Storyboard processor that reads instructions from the storyboard
* file, fetches input frames, and renders composite video frames
* according to the instructions in the storyboard file.
*
* The storyboard processor is typically used to:
* - check storyboard syntax and deliver information (number of total frames)
* for the master encoder dialog.
* - render the composite video frame at specified master frame number
* (is called as frame fetching utility by all encoders)
*
* The storyboard processor provides fuctionality to mix audiodata,
* this is usually done in the master encoder dialog (before starting the selected encoder)
*
* Copyright (C) 2006 Wolfgang Hofer <hof@gimp.org>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* 2006.06.25 hof - created (moved stuff from the former gap_gve_story modules to this new module)
* - new features:
* use shadow tracks, (implicite) generated by the new overlap attribute
* normal track numbers are 1, 3, 5, 7
* corresponding shadow tracks are 0, 2, 4, 6 (shadow = normal -1)
* - support video frame flipping (hor/vertical)
*
*/
#include <config.h>
/* SYTEM (UNIX) includes */
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>
#include <errno.h>
#include <dirent.h>
#include <glib/gstdio.h>
/* GIMP includes */
#include "gtk/gtk.h"
#include "gap-intl.h"
#include "libgimp/gimp.h"
#include "gap_libgapbase.h"
#include "gap_libgimpgap.h"
#include "gap_lib_common_defs.h"
#include "gap_audio_util.h"
#include "gap_audio_wav.h"
#include "gap_story_file.h"
#include "gap_layer_copy.h"
#include "gap_story_render_audio.h"
#include "gap_story_render_processor.h"
#include "gap_fmac_name.h"
#include "gap_frame_fetcher.h"
/* data for the storyboard proceesor frame fetching
*/
typedef struct GapStbFetchData { /* nick: gfd */
gint32 comp_image_id;
gint32 tmp_image_id;
gint32 layer_id;
gchar *framename;
gdouble opacity;
gdouble scale_x;
gdouble scale_y;
gdouble move_x;
gdouble move_y;
GapStoryRenderFrameRangeElem *frn_elem;
gint32 localframe_index;
gint32 local_stepcount;
gdouble localframe_tween_rest;
gboolean keep_proportions;
gboolean fit_width;
gboolean fit_height;
GapStoryRenderFrameType frn_type;
char *trak_filtermacro_file;
} GapStbFetchData;
/*************************************************************
* STORYBOARD FUNCTIONS *
*************************************************************
*/
#define MAX_IMG_CACHE_ELEMENTS 6
extern int gap_debug; /* 1 == print debug infos , 0 dont print debug infos */
static gint32 global_monitor_image_id = -1;
static gint32 global_monitor_display_id = -1;
static void p_debug_print_render_section_names(GapStoryRenderVidHandle *vidhand);
static void p_frame_backup_save( char *key
, gint32 image_id
, gint32 layer_id
, gint32 master_frame_nr
, gboolean multilayer
);
static void p_debug_dup_image(gint32 image_id);
static void p_encoding_monitor( char *key
, gint32 image_id
, gint32 layer_id
, gint32 master_frame_nr
);
static GapStoryRenderErrors * p_new_stb_error(void);
static void p_init_stb_error(GapStoryRenderErrors *sterr);
static void p_free_stb_error(GapStoryRenderErrors *sterr);
static void p_set_stb_error(GapStoryRenderErrors *sterr, char *errtext);
static void p_find_min_max_vid_tracknumbers(GapStoryRenderFrameRangeElem *frn_list
, gint32 *lowest_tracknr
, gint32 *highest_tracknr
);
static void p_step_attribute(gint32 frames_handled
,gdouble *from_val
,gdouble *to_val
,gint32 *dur
);
static gdouble p_step_attribute_read(gint32 frame_step
,gdouble from_val
,gdouble to_val
,gint32 dur
);
static gdouble p_step_attribute_read(gint32 frame_step
,gdouble from_val
,gdouble to_val
,gint32 dur
);
static void p_select_section_by_name(GapStoryRenderVidHandle *vidhand
, const char *section_name);
static char * p_fetch_framename (GapStoryRenderFrameRangeElem *frn_list
, gint32 master_frame_nr /* starts at 1 */
, gint32 track
, GapStoryRenderFrameType *frn_type
, char **filtermacro_file
, gint32 *localframe_index /* used only for ANIMIMAGE and videoclip, -1 for all other types */
, gint32 *local_stepcount /* nth frame within this clip, starts with 0 */
, gdouble *localframe_tween_rest /* non-integer part of the position. value < 1.0 for tween fetching */
, gboolean *keep_proportions
, gboolean *fit_width
, gboolean *fit_height
, gdouble *red_f
, gdouble *green_f
, gdouble *blue_f
, gdouble *alpha_f
, gdouble *opacity /* output opacity 0.0 upto 1.0 */
, gdouble *scale_x /* output 0.0 upto 10.0 where 1.0 is 1:1 */
, gdouble *scale_y /* output 0.0 upto 10.0 where 1.0 is 1:1 */
, gdouble *move_x /* output -1.0 upto 1.0 where 0.0 is centered */
, gdouble *move_y /* output -1.0 upto 1.0 where 0.0 is centered */
, GapStoryRenderFrameRangeElem **frn_elem_ptr /* OUT pointer to the relevant framerange element */
);
static void p_calculate_frames_to_handle(GapStoryRenderFrameRangeElem *frn_elem);
static GapStoryRenderFrameRangeElem * p_new_framerange_element(
GapStoryRenderFrameType frn_type
,gint32 track
,const char *basename /* basename or full imagename for frn_type GAP_FRN_IMAGE */
,const char *ext /* NULL for frn_type GAP_FRN_IMAGE */
,gint32 frame_from /* IN: range start */
,gint32 frame_to /* IN: range end */
,const char *storyboard_file /* IN: NULL if no storyboard file is used */
,const char *preferred_decoder /* IN: NULL if no preferred_decoder is specified */
,const char *filtermacro_file /* IN: NULL, or name of the macro file */
,GapStoryRenderFrameRangeElem *frn_list /* NULL or list of already known ranges */
,GapStoryRenderErrors *sterr /* element to store Error/Warning report */
,gint32 seltrack /* IN: select videotrack number 1 upto 99 for GAP_FRN_MOVIE */
,gint32 exact_seek /* IN: 0 fast seek, 1 exact seek (only for GVA Videoreads) */
,gdouble delace /* IN: 0.0 no deinterlace, 1.0-1.99 odd 2.0-2.99 even rows (only for GVA Videoreads) */
,gdouble step_density /* IN: 1==normal stepsize 1:1 0.5 == each frame twice, 2.0 only every 2nd frame */
,gint32 flip_request /* 0 NONE, 1 flip horizontal, 2 flip vertical, 3 rotate 180degree */
,const char *mask_name /* reference to layer mask definition */
,gdouble mask_stepsize /* stepsize for the layer mask */
,GapStoryMaskAnchormode mask_anchor /* how to apply the layer mask */
,gboolean mask_disable
,gint32 fmac_total_steps
);
static void p_add_frn_list(GapStoryRenderVidHandle *vidhand, GapStoryRenderFrameRangeElem *frn_elem);
static void p_step_all_vtrack_attributes(gint32 track, gint32 frames_to_handle
,GapStoryRenderVTrackArray *vtarr
);
static void p_set_vtrack_attributes(GapStoryRenderFrameRangeElem *frn_elem
,GapStoryRenderVTrackArray *vtarr
);
static void p_vidclip_add_as_is(GapStoryRenderFrameRangeElem *frn_elem
,GapStoryRenderVidHandle *vidhand
,GapStoryRenderVTrackArray *vtarr
);
static void p_vidclip_shadow_add_silence(gint32 shadow_track
,gint32 fill_shadow_frames
,GapStoryRenderVidHandle *vidhand
,GapStoryRenderVTrackArray *vtarr
,const char *storyboard_file
);
static void p_recalculate_range_part(GapStoryRenderFrameRangeElem *frn_elem
, gint32 lost_frames
, gint32 rest_frames
);
static void p_copy_vattr_values(gint32 src_track
, gint32 dst_track
, GapStoryRenderVTrackArray *vtarr
);
static void p_vidclip_split_and_add_frn_list(GapStoryRenderFrameRangeElem *frn_elem,
GapStoryRenderVidHandle *vidhand,
GapStoryRenderVTrackArray *vtarr,
const char *storyboard_file
);
static void p_vidclip_add(GapStoryRenderFrameRangeElem *frn_elem
,GapStoryRenderVidHandle *vidhand
,GapStoryRenderVTrackArray *vtarr
,const char *storyboard_file
,gboolean first_of_group
);
static void p_clear_vattr_array(GapStoryRenderVTrackArray *vtarr);
static gboolean p_fmt_string_has_framenumber_format(const char *fmt_string);
static gboolean p_fmt_string_has_videobasename_format(const char *fmt_string);
static void p_storyboard_analyze(GapStoryBoard *stb
, gint32 *mainsection_frame_count
, GapStoryRenderVidHandle *vidhand
);
static GapStoryRenderFrameRangeElem * p_framerange_list_from_storyboard(
const char *storyboard_file
,gint32 *frame_count
,GapStoryRenderVidHandle *vidhand
,GapStoryBoard *stb_mem_ptr
);
static void p_free_framerange_list(GapStoryRenderFrameRangeElem * frn_list);
static GapStoryRenderSection * p_new_render_section(const char *section_name);
static void p_append_render_section_to_vidhand(GapStoryRenderVidHandle *vidhand
, GapStoryRenderSection *new_render_section);
static void p_open_mask_vidhand(GapStoryElem *stb_elem
, GapStoryRenderMaskDefElem *maskdef_elem);
static void p_copy_mask_definitions_to_vidhand(GapStoryBoard *stb_ptr
, GapStoryRenderVidHandle *vidhand);
static void p_free_mask_definitions(GapStoryRenderVidHandle *vidhand);
static GapStoryRenderMaskDefElem * p_find_maskdef_by_name(GapStoryRenderVidHandle *vidhand, const char *mask_name);
static gint32 p_mask_fetcher(GapStoryRenderVidHandle *vidhand
, const char *mask_name
, gint32 master_frame_nr
, gint32 mask_width
, gint32 mask_height
, gint32 *layer_id /* OUT: Id of the only layer in the composite image */
, gboolean *was_last_maskframe /* OUT: true if this was the last maskframe */
);
static void p_fetch_and_add_layermask(GapStoryRenderVidHandle *vidhand
, GapStoryRenderFrameRangeElem *frn_elem
, gint32 local_stepcount
, gint32 image_id
, gint32 layer_id
);
static GapStoryRenderVidHandle * p_open_video_handle_private( gboolean ignore_audio
, gboolean ignore_video
, gboolean create_audio_tmp_files
, gdouble *progress_ptr
, char *status_msg
, gint32 status_msg_len
, const char *storyboard_file
, const char *basename
, const char *ext
, gint32 frame_from
, gint32 frame_to
, gint32 *frame_count /* output total frame_count , or 0 on failure */
, gboolean do_gimp_progress
, GapLibTypeInputRange input_mode
, const char *imagename
, const char *preferred_decoder
, gint32 seltrack
, gint32 exact_seek
, gdouble delace
, gboolean compensate_framerange
, GapStoryBoard *stb_mem_ptr
);
static gint32 p_exec_filtermacro(gint32 image_id
, gint32 layer_id
, const char *filtermacro_file
, const char *filtermacro_file_to
, gdouble current_step
, gint32 total_steps
);
static gint32 p_transform_and_add_layer( gint32 comp_image_id
, gint32 tmp_image_id
, gint32 layer_id
, gboolean keep_proportions
, gboolean fit_width
, gboolean fit_height
, gdouble opacity /* 0.0 upto 1.0 */
, gdouble scale_x /* 0.0 upto 10.0 where 1.0 = 1:1 */
, gdouble scale_y /* 0.0 upto 10.0 where 1.0 = 1:1 */
, gdouble move_x /* -1.0 upto +1.0 where 0 = no move, -1 is left outside */
, gdouble move_y /* -1.0 upto +1.0 where 0 = no move, -1 is top outside */
, char *filtermacro_file
, gint32 flip_request
, GapStoryRenderFrameRangeElem *frn_elem
, GapStoryRenderVidHandle *vidhand
, gint32 local_stepcount
);
static gint32 p_create_unicolor_image(gint32 *layer_id, gint32 width , gint32 height
, gdouble r_f, gdouble g_f, gdouble b_f, gdouble a_f);
static gint32 p_prepare_RGB_image(gint32 image_id);
static void p_limit_open_videohandles(GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, gint32 currently_open_videohandles
);
static t_GVA_Handle * p_try_to_steal_gvahand(GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, char *basename /* the videofile name */
, gint32 exact_seek
);
static void p_split_delace_value(gdouble delace
, gdouble localframe_tween_rest
, gint32 *deinterlace_ptr
, gdouble *threshold_ptr);
static void p_conditional_delace_drawable(GapStbFetchData *gfd, gint32 drawable_id);
static void p_stb_render_image_or_animimage(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr);
static void p_stb_render_movie(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, gint32 vid_width, gint32 vid_height);
static void p_stb_render_section(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, gint32 vid_width, gint32 vid_height
, const char *section_name);
static void p_stb_render_frame_images(GapStbFetchData *gfd, gint32 master_frame_nr);
static void p_stb_render_composite_image_postprocessing(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, gint32 vid_width, gint32 vid_height
, char *filtermacro_file
, const char *section_name
);
static void p_stb_render_result_monitoring(GapStbFetchData *gfd, gint32 master_frame_nr);
static void p_paste_logo_pattern(gint32 drawable_id
, gint32 logo_pattern_id
, gint32 offsetX
, gint32 offsetY
);
static void p_do_insert_area_processing(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand);
static gint32 p_story_render_fetch_composite_image_private(GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr /* starts at 1 */
, gint32 vid_width /* desired Video Width in pixels */
, gint32 vid_height /* desired Video Height in pixels */
, char *filtermacro_file /* NULL if no filtermacro is used */
, gint32 *layer_id /* output: Id of the only layer in the composite image */
, const char *section_name /* NULL for main section */
);
/* ----------------------------------------------------
* gap_story_render_debug_print_maskdef_elem
* ----------------------------------------------------
* print all List elements for the given track
* (negative track number will print all elements)
*/
void
gap_story_render_debug_print_maskdef_elem(GapStoryRenderMaskDefElem *maskdef_elem, gint l_idx)
{
if(maskdef_elem)
{
printf("\n ===== maskdef_elem start ============ \n" );
printf(" [%d] record_type : %d\n", (int)l_idx, (int)maskdef_elem->record_type );
printf(" [%d] mask_name : ", (int)l_idx); if(maskdef_elem->mask_name) { printf("%s\n", maskdef_elem->mask_name );} else { printf ("(null)\n"); }
printf(" [%d] mask_vidhand : %d\n", (int)l_idx, (int)maskdef_elem->mask_vidhand );
printf(" [%d] frame_count : %d\n", (int)l_idx, (int)maskdef_elem->frame_count );
printf(" [%d] flip_request : %d\n", (int)l_idx, (int)maskdef_elem->flip_request );
if(maskdef_elem->mask_vidhand)
{
printf("Storyboard list for this maskdef_elem:\n" );
gap_story_render_debug_print_framerange_list(maskdef_elem->mask_vidhand->frn_list, -1);
}
printf("\n ===== maskdef_elem end ============ \n" );
}
} /* end gap_story_render_debug_print_maskdef_elem */
/* ----------------------------------------------------
* p_frn_record_type_to_string
* ----------------------------------------------------
*/
static const char *
p_frn_record_type_to_string(GapStoryRenderFrameType frn_type)
{
switch(frn_type)
{
case GAP_FRN_SILENCE: return("GAP_FRN_SILENCE"); break;
case GAP_FRN_COLOR: return("GAP_FRN_COLOR"); break;
case GAP_FRN_IMAGE: return("GAP_FRN_IMAGE"); break;
case GAP_FRN_ANIMIMAGE: return("GAP_FRN_ANIMIMAGE"); break;
case GAP_FRN_FRAMES: return("GAP_FRN_FRAMES"); break;
case GAP_FRN_MOVIE: return("GAP_FRN_MOVIE"); break;
case GAP_FRN_SECTION: return("GAP_FRN_SECTION"); break;
}
return("** UNDEFINED RECORD TYPE **");
} /* end p_frn_record_type_to_string */
/* ----------------------------------------------------
* gap_story_render_debug_print_frame_elem
* ----------------------------------------------------
* print all List elements for the given track
* (negative track number will print all elements)
*/
void
gap_story_render_debug_print_frame_elem(GapStoryRenderFrameRangeElem *frn_elem, gint l_idx)
{
static const char *normal_track = " (normal)";
static const char *shadow_track = " (shadow)";
if(frn_elem)
{
const char *track_type;
track_type = normal_track;
if((frn_elem->track & 1) == 0)
{
track_type = shadow_track;
}
printf("\n [%d] frn_type : %d %s\n", (int)l_idx, (int)frn_elem->frn_type
,p_frn_record_type_to_string(frn_elem->frn_type));
printf(" [%d] itrack (internal) : %d %s\n", (int)l_idx, (int)frn_elem->track, track_type );
printf(" [%d] track (file) : %d\n", (int)l_idx, (int)(1+(frn_elem->track / 2)) );
printf(" [%d] basename : ", (int)l_idx); if(frn_elem->basename) { printf("%s\n", frn_elem->basename );} else { printf ("(null)\n"); }
printf(" [%d] ext : ", (int)l_idx); if(frn_elem->ext) { printf("%s\n", frn_elem->ext );} else { printf ("(null)\n"); }
printf(" [%d] gvahand : %d\n", (int)l_idx, (int)frn_elem->gvahand );
printf(" [%d] seltrack : %d\n", (int)l_idx, (int)frn_elem->seltrack );
printf(" [%d] exact_seek : %d\n", (int)l_idx, (int)frn_elem->exact_seek );
printf(" [%d] delace : %.2f\n", (int)l_idx, (float)frn_elem->delace );
printf(" [%d] filtermacro_file : ", (int)l_idx); if(frn_elem->filtermacro_file) { printf("%s\n", frn_elem->filtermacro_file );} else { printf ("(null)\n"); }
printf(" [%d] f.macro_file_to : ", (int)l_idx); if(frn_elem->filtermacro_file_to) { printf("%s\n", frn_elem->filtermacro_file_to );} else { printf ("(null)\n"); }
printf(" [%d] fmac_total_steps : %d\n", (int)l_idx, (int)frn_elem->fmac_total_steps );
printf(" [%d] frame_from : %.4f\n", (int)l_idx, (float)frn_elem->frame_from );
printf(" [%d] frame_to : %.4f\n", (int)l_idx, (float)frn_elem->frame_to );
printf(" [%d] frames_to_handle : %d\n", (int)l_idx, (int)frn_elem->frames_to_handle);
printf(" [%d] delta : %d\n", (int)l_idx, (int)frn_elem->delta );
printf(" [%d] step_density : %.4f\n", (int)l_idx, (float)frn_elem->step_density );
if(frn_elem->keep_proportions)
{printf(" [%d] keep_proportions : TRUE\n", (int)l_idx );}
else
{printf(" [%d] keep_proportions : FALSE\n", (int)l_idx );}
if(frn_elem->fit_width)
{printf(" [%d] fit_width : TRUE\n", (int)l_idx );}
else
{printf(" [%d] fit_width : FALSE\n", (int)l_idx );}
if(frn_elem->fit_height)
{printf(" [%d] fit_height : TRUE\n", (int)l_idx );}
else
{printf(" [%d] fit_height : FALSE\n", (int)l_idx );}
printf(" [%d] flip_request : %d\n", (int)l_idx, (int)frn_elem->flip_request );
if(frn_elem->mask_name)
{
printf(" [%d] mask_name : %s\n", (int)l_idx, frn_elem->mask_name);
printf(" [%d] mask_anchor : %d\n", (int)l_idx, (int)frn_elem->mask_anchor );
printf(" [%d] mask_stepsize : %.4f\n", (int)l_idx, (float)frn_elem->mask_stepsize );
printf(" [%d] mask_framecount : %.4f\n", (int)l_idx, (float)frn_elem->mask_framecount );
}
else
{
printf(" [%d] mask_name : (null)\n", (int)l_idx );
}
printf(" [%d] wait_untiltime_sec : %f\n", (int)l_idx, (float)frn_elem->wait_untiltime_sec );
printf(" [%d] wait_untilframes : %d\n", (int)l_idx, (int)frn_elem->wait_untilframes );
printf(" [%d] opacity_from : %f\n", (int)l_idx, (float)frn_elem->opacity_from );
printf(" [%d] opacity_to : %f\n", (int)l_idx, (float)frn_elem->opacity_to );
printf(" [%d] opacity_dur : %d\n", (int)l_idx, (int)frn_elem->opacity_dur );
printf(" [%d] scale_x_from : %f\n", (int)l_idx, (float)frn_elem->scale_x_from );
printf(" [%d] scale_x_to : %f\n", (int)l_idx, (float)frn_elem->scale_x_to );
printf(" [%d] scale_x_dur : %d\n", (int)l_idx, frn_elem->scale_x_dur );
printf(" [%d] scale_y_from : %f\n", (int)l_idx, (float)frn_elem->scale_y_from );
printf(" [%d] scale_y_to : %f\n", (int)l_idx, (float)frn_elem->scale_y_to );
printf(" [%d] scale_y_dur : %d\n", (int)l_idx, (int)frn_elem->scale_y_dur );
printf(" [%d] move_x_from : %f\n", (int)l_idx, (float)frn_elem->move_x_from );
printf(" [%d] move_x_to : %f\n", (int)l_idx, (float)frn_elem->move_x_to );
printf(" [%d] move_x_dur : %d\n", (int)l_idx, (int)frn_elem->move_x_dur );
printf(" [%d] move_y_from : %f\n", (int)l_idx, (float)frn_elem->move_y_from );
printf(" [%d] move_y_to : %f\n", (int)l_idx, (float)frn_elem->move_y_to );
printf(" [%d] move_y_dur : %d\n", (int)l_idx, (int)frn_elem->move_y_dur );
}
} /* end gap_story_render_debug_print_frame_elem */
/* ----------------------------------------------------
* p_debug_print_render_section_names
* ----------------------------------------------------
* print section_name and pointers as debug information to stdout,
*/
static void
p_debug_print_render_section_names(GapStoryRenderVidHandle *vidhand)
{
GapStoryRenderSection *section;
printf("\nDEBUG p_debug_print_render_section_names START\n");
for(section = vidhand->section_list; section != NULL; section = section->next)
{
printf("DEBUG render_section: adr vidhand:%d section:%d section->frn_list:%d)"
, (int)vidhand
, (int)section
, (int)section->frn_list
);
if (section->section_name == NULL)
{
printf("section_name: (null) e.g. MAIN\n");
}
else
{
printf("section->section_name: %s\n", section->section_name);
}
}
printf("DEBUG p_debug_print_render_section_names END\n");
fflush(stdout);
} /* end p_debug_print_render_section_names */
/* ----------------------------------------------------
* gap_story_render_debug_print_framerange_list
* ----------------------------------------------------
* print all List elements for the given track
* (negative track number will print all elements)
*/
void
gap_story_render_debug_print_framerange_list(GapStoryRenderFrameRangeElem *frn_list
, gint32 track /* -1 show all tracks */
)
{
GapStoryRenderFrameRangeElem *frn_elem;
gint l_idx;
printf("\ngap_story_render_debug_print_framerange_list: START\n");
l_idx = 0;
for(frn_elem = frn_list; frn_elem != NULL; frn_elem = (GapStoryRenderFrameRangeElem *)frn_elem->next)
{
if((frn_elem->track == track) || (track < 0))
{
gap_story_render_debug_print_frame_elem(frn_elem, l_idx);
}
l_idx++;
}
printf("gap_story_render_debug_print_framerange_list: END\n");
fflush(stdout);
} /* end gap_story_render_debug_print_framerange_list */
/* ----------------------------------------------------
* gap_story_render_debug_print_audiorange_list
* ----------------------------------------------------
* print all List elements for the given track
* (negative track number will print all elements)
*/
void
gap_story_render_debug_print_audiorange_list(GapStoryRenderAudioRangeElem *aud_list
, gint32 track /* -1 show all tracks */
)
{
GapStoryRenderAudioRangeElem *aud_elem;
gint l_idx;
printf("\ngap_story_render_debug_print_audiorange_list: START\n");
l_idx = 0;
for(aud_elem = aud_list; aud_elem != NULL; aud_elem = (GapStoryRenderAudioRangeElem *)aud_elem->next)
{
if((aud_elem->track == track) || (track < 0))
{
printf("\n [%d] aud_type : %d\n", (int)l_idx, (int)aud_elem->aud_type );
printf(" [%d] track : %d\n", (int)l_idx, (int)aud_elem->track );
printf(" [%d] audiofile : ", (int)l_idx); if(aud_elem->audiofile) { printf("%s\n", aud_elem->audiofile );} else { printf ("(null)\n"); }
printf(" [%d] tmp_audiofile : ", (int)l_idx); if(aud_elem->tmp_audiofile) { printf("%s\n", aud_elem->tmp_audiofile );} else { printf ("(null)\n"); }
printf(" [%d] gvahand : %d\n", (int)l_idx, (int)aud_elem->gvahand );
printf(" [%d] seltrack : %d\n", (int)l_idx, (int)aud_elem->seltrack );
printf(" [%d] samplerate : %d\n", (int)l_idx, (int)aud_elem->samplerate );
printf(" [%d] channels : %d\n", (int)l_idx, (int)aud_elem->channels );
printf(" [%d] bytes_per_sample : %d\n", (int)l_idx, (int)aud_elem->bytes_per_sample );
printf(" [%d] samples : %d\n", (int)l_idx, (int)aud_elem->samples );
printf(" [%d] audio_id : %d\n", (int)l_idx, (int)aud_elem->audio_id);
printf(" [%d] aud_data : %d\n", (int)l_idx, (int)aud_elem->aud_data);
printf(" [%d] aud_bytelength : %d\n", (int)l_idx, (int)aud_elem->aud_bytelength);
printf(" [%d] range_samples : %d\n", (int)l_idx, (int)aud_elem->range_samples );
printf(" [%d] fade_in_samples : %d\n", (int)l_idx, (int)aud_elem->fade_in_samples );
printf(" [%d] fade_out_samples : %d\n", (int)l_idx, (int)aud_elem->fade_out_samples );
printf(" [%d] offset_rangestart : %d\n", (int)l_idx, (int)aud_elem->byteoffset_rangestart );
printf(" [%d] byteoffset_data : %d\n", (int)l_idx, (int)aud_elem->byteoffset_data );
printf(" [%d] wait_untiltime_sec: %f\n", (int)l_idx, (float)aud_elem->wait_untiltime_sec );
printf(" [%d] wait_until_samples: %d\n", (int)l_idx, (int)aud_elem->wait_until_samples );
printf(" [%d] max_playtime_sec : %f\n", (int)l_idx, (float)aud_elem->max_playtime_sec );
printf(" [%d] range_playtime_sec: %f\n", (int)l_idx, (float)aud_elem->range_playtime_sec );
printf(" [%d] play_from_sec : %f\n", (int)l_idx, (float)aud_elem->play_from_sec );
printf(" [%d] play_to_sec : %f\n", (int)l_idx, (float)aud_elem->play_to_sec );
printf(" [%d] volume_start : %f\n", (int)l_idx, (float)aud_elem->volume_start );
printf(" [%d] volume : %f\n", (int)l_idx, (float)aud_elem->volume );
printf(" [%d] volume_end : %f\n", (int)l_idx, (float)aud_elem->volume_end );
printf(" [%d] fade_in_sec : %f\n", (int)l_idx, (float)aud_elem->fade_in_sec );
printf(" [%d] fade_out_sec : %f\n", (int)l_idx, (float)aud_elem->fade_out_sec );
}
l_idx++;
}
printf("gap_story_render_debug_print_audiorange_list: END\n");
fflush(stdout);
} /* end gap_story_render_debug_print_audiorange_list */
/* ----------------------------------------------------
* p_frame_backup_save
* ----------------------------------------------------
*/
static void
p_frame_backup_save( char *key
, gint32 image_id
, gint32 layer_id
, gint32 master_frame_nr
, gboolean multilayer
)
{
gint32 l_len;
char *l_framename;
char *l_basename;
l_len = gimp_get_data_size(key);
if(l_len <= 0)
{
return;
}
l_basename = g_malloc0(l_len);
gimp_get_data(key, l_basename);
if(*l_basename != '\0')
{
if(multilayer)
{
l_framename = gap_lib_alloc_fname(l_basename, master_frame_nr, ".xcf");
}
else
{
l_framename = gap_lib_alloc_fname(l_basename, master_frame_nr, ".png");
}
if(gap_debug) printf("Debug: Saving frame to file: %s\n", l_framename);
gimp_file_save(GIMP_RUN_WITH_LAST_VALS, image_id, layer_id, l_framename, l_framename);
g_free(l_framename);
}
g_free(l_basename);
} /* end p_frame_backup_save */
/* ----------------------------------------------------
* p_debug_dup_image
* ----------------------------------------------------
* Duplicate image, and open a display for the duplicate
* (Procedure is used for debug only
*/
static void
p_debug_dup_image(gint32 image_id)
{
gint32 l_dup_image_id;
l_dup_image_id = gimp_image_duplicate(image_id);
gimp_display_new(l_dup_image_id);
} /* end p_debug_dup_image */
/* ----------------------------------------------------
* p_encoding_monitor
* ----------------------------------------------------
* monitor the image before passed to the encoder.
* - at 1.st call open global_monitor_image_id
* and add a display.
* - on all further calls copy the composite layer
* to the global_monitor_image_id
*/
static void
p_encoding_monitor( char *key
, gint32 image_id
, gint32 layer_id
, gint32 master_frame_nr
)
{
gint32 l_len;
char *l_true_or_false;
l_len = gimp_get_data_size(key);
if(l_len <= 0)
{
return;
}
l_true_or_false = g_malloc0(l_len);
gimp_get_data(key, l_true_or_false);
if(*l_true_or_false == 'T')
{
char *l_imagename;
printf("Monitoring image_id: %d, layer_id:%d master_frame:%d\n", (int)image_id, (int)layer_id ,(int)master_frame_nr );
l_imagename = g_strdup_printf(_("encoding_video_frame_%06d"), (int)master_frame_nr);
if(global_monitor_image_id < 0)
{
global_monitor_image_id = gimp_image_duplicate(image_id);
global_monitor_display_id = gimp_display_new(global_monitor_image_id);
gimp_image_set_filename(global_monitor_image_id, l_imagename);
}
else
{
gint l_nlayers;
gint32 *l_layers_list;
gint32 l_fsel_layer_id;
l_layers_list = gimp_image_get_layers(global_monitor_image_id, &l_nlayers);
if(l_layers_list != NULL)
{
gimp_selection_none(image_id); /* if there is no selection, copy the complete layer */
gimp_selection_none(global_monitor_image_id); /* if there is no selection, copy the complete layer */
gimp_edit_copy(layer_id);
l_fsel_layer_id = gimp_edit_paste(l_layers_list[0], FALSE); /* FALSE paste clear selection */
gimp_floating_sel_anchor(l_fsel_layer_id);
g_free (l_layers_list);
gimp_image_set_filename(global_monitor_image_id, l_imagename);
gimp_displays_flush();
}
else
{
printf("no more MONITORING, (user has closed monitor image)\n");
}
}
g_free(l_imagename);
}
g_free(l_true_or_false);
} /* end p_encoding_monitor */
/* --------------------------------
* p_init_stb_error
* --------------------------------
*/
static void
p_init_stb_error(GapStoryRenderErrors *sterr)
{
if(sterr->errtext) { g_free(sterr->errtext); }
if(sterr->errline) { g_free(sterr->errline); }
if(sterr->warntext) { g_free(sterr->warntext); }
if(sterr->warnline) { g_free(sterr->warnline); }
sterr->errtext = NULL;
sterr->errline = NULL;
sterr->warntext = NULL;
sterr->warnline = NULL;
sterr->currline = NULL;
sterr->errline_nr = 0;
sterr->warnline_nr = 0;
sterr->curr_nr = 0;
} /* end p_init_stb_error */
/* --------------------------------
* p_new_stb_error
* --------------------------------
*/
static GapStoryRenderErrors *
p_new_stb_error(void)
{
GapStoryRenderErrors *sterr;
sterr = g_malloc0(sizeof(GapStoryRenderErrors));
p_init_stb_error(sterr);
return(sterr);
} /* end p_new_stb_error */
/* --------------------------------
* p_free_stb_error
* --------------------------------
*/
static void
p_free_stb_error(GapStoryRenderErrors *sterr)
{
p_init_stb_error(sterr);
g_free(sterr);
} /* end p_free_stb_error */
/* --------------------------------
* p_set_stb_error
* --------------------------------
*/
static void
p_set_stb_error(GapStoryRenderErrors *sterr, char *errtext)
{
printf("** error: %s\n [at line:%d] %s\n"
, errtext
, (int)sterr->curr_nr
, sterr->currline
);
if(sterr->errtext == NULL)
{
sterr->errtext = g_strdup(errtext);
sterr->errline_nr = sterr->curr_nr;
sterr->errline = g_strdup(sterr->currline);
}
} /* end p_set_stb_error */
/* --------------------------------
* gap_story_render_set_stb_error
* --------------------------------
*/
void
gap_story_render_set_stb_error(GapStoryRenderErrors *sterr, char *errtext)
{
p_set_stb_error(sterr, errtext);
} /* end gap_story_render_set_stb_error */
/* --------------------------------
* gap_story_render_set_stb_warning
* --------------------------------
*/
void
gap_story_render_set_stb_warning(GapStoryRenderErrors *sterr, char *warntext)
{
printf("** warning: %s\n [at line:%d] %s\n"
, warntext
, (int)sterr->curr_nr
, sterr->currline
);
if(sterr->warntext == NULL)
{
sterr->warntext = g_strdup(warntext);
sterr->warnline_nr = sterr->curr_nr;
sterr->warnline = g_strdup(sterr->currline);
}
} /* end gap_story_render_set_stb_warning */
/* ----------------------------------------------------
* p_find_min_max_vid_tracknumbers
* ----------------------------------------------------
* findout the lowest and highest track number used
* in the framerange list
*/
static void
p_find_min_max_vid_tracknumbers(GapStoryRenderFrameRangeElem *frn_list
, gint32 *lowest_tracknr
, gint32 *highest_tracknr
)
{
GapStoryRenderFrameRangeElem *frn_elem;
*lowest_tracknr = GAP_STB_MAX_VID_INTERNAL_TRACKS;
*highest_tracknr = -1;
for(frn_elem = frn_list; frn_elem != NULL; frn_elem = (GapStoryRenderFrameRangeElem *)frn_elem->next)
{
if (frn_elem->track > *highest_tracknr)
{
*highest_tracknr = frn_elem->track;
}
if (frn_elem->track < *lowest_tracknr)
{
*lowest_tracknr = frn_elem->track;
}
}
if(gap_debug) printf("p_find_min_max_vid_tracknumbers: min:%d max:%d\n", (int)*lowest_tracknr, (int)*highest_tracknr);
} /* end p_find_min_max_vid_tracknumbers */
/* ---------------------------------------
* p_step_attribute
* ---------------------------------------
* calculate remaining attribute value after N frames_handled
* and change *from_val and *dur accordingly
*/
static void
p_step_attribute(gint32 frames_handled
,gdouble *from_val
,gdouble *to_val
,gint32 *dur
)
{
gint32 l_rest_steps;
gdouble step_delta_val;
l_rest_steps = *dur - frames_handled;
if((l_rest_steps <= 0) || (*dur <= 0))
{
*from_val = *to_val;
*dur = 0;
}
else
{
step_delta_val = (*to_val - *from_val) / (gdouble)(*dur);
*from_val = *to_val - (step_delta_val * l_rest_steps) ;
*dur = l_rest_steps;
}
} /* end p_step_attribute */
/* --------------------------------
* p_step_attribute_read
* --------------------------------
* return attribute value after N frame steps
*/
static gdouble
p_step_attribute_read(gint32 frame_step
,gdouble from_val
,gdouble to_val
,gint32 dur
)
{
gdouble l_from_val;
gdouble l_to_val;
gint32 l_dur;
l_from_val = from_val;
l_to_val = to_val;
l_dur = dur;
p_step_attribute( frame_step
, &l_from_val
, &l_to_val
, &l_dur
);
return(l_from_val);
} /* end p_step_attribute */
/* ----------------------------------------------------
* p_select_section_by_name
* ----------------------------------------------------
* switch to specified section by
* setting frn_list and aud_list pointers of the specified video handle vidhand
* to the sub list of to the specified section_name.
* section_name NULL refers to the main section.
* at unknown section_name's set both pointers to NULL.
*/
static void
p_select_section_by_name(GapStoryRenderVidHandle *vidhand, const char *section_name)
{
GapStoryRenderSection *section;
for(section = vidhand->section_list; section != NULL; section = section->next)
{
if (section_name == NULL)
{
if (section->section_name == NULL)
{
if(gap_debug)
{
printf("p_select_section_by_name: null (switch to MAIN section)\n");
fflush(stdout);
}
break;
}
}
else
{
if (section->section_name != NULL)
{
if (strcmp(section->section_name, section_name) == 0)
{
if(gap_debug)
{
printf("p_select_section_by_name: (switch to SUB-SECTION: %s)\n", section_name);
fflush(stdout);
}
break;
}
}
}
}
if (section != NULL)
{
vidhand->frn_list = section->frn_list;
vidhand->aud_list = section->aud_list;
}
else
{
vidhand->frn_list = NULL;
vidhand->aud_list = NULL;
}
if(gap_debug)
{
printf("p_select_section_by_name: addr of section: %d Resulting addr of frn_list: %d)\n"
, (int)section
, (int)vidhand->frn_list
);
fflush(stdout);
}
} /* end p_select_section_by_name */
/* ----------------------------------------------------
* p_fetch_framename
* ----------------------------------------------------
* fetch framename for a given master_frame_nr in the given video track
* within a storyboard framerange list.
* (simple animations without a storyboard file
* are represented by a short storyboard framerange list that has
* just one element entry at track 1).
*
* output gduoble attribute values (opacity, scale, move) for the frame
* at track and master_frame_nr position.
*
* return the name of the frame (that is to be displayed at position master_frame_nr).
* return NULL if there is no frame at desired track and master_frame_nr
*/
static char *
p_fetch_framename(GapStoryRenderFrameRangeElem *frn_list
, gint32 master_frame_nr /* starts at 1 */
, gint32 track
, GapStoryRenderFrameType *frn_type
, char **filtermacro_file
, gint32 *localframe_index /* starts at 1, used for ANIMIMAGE and VIDEOFILES, -1 for all other types */
, gint32 *local_stepcount /* nth frame within this clip, starts with 0 */
, gdouble *localframe_tween_rest /* non-integer part of the position. value < 1.0 for tween fetching */
, gboolean *keep_proportions
, gboolean *fit_width
, gboolean *fit_height
, gdouble *red_f
, gdouble *green_f
, gdouble *blue_f
, gdouble *alpha_f
, gdouble *opacity /* output opacity 0.0 upto 1.0 */
, gdouble *scale_x /* output 0.0 upto 10.0 where 1.0 is 1:1 */
, gdouble *scale_y /* output 0.0 upto 10.0 where 1.0 is 1:1 */
, gdouble *move_x /* output -1.0 upto 1.0 where 0.0 is centered */
, gdouble *move_y /* output -1.0 upto 1.0 where 0.0 is centered */
, GapStoryRenderFrameRangeElem **frn_elem_ptr /* OUT pointer to the relevant framerange element */
)
{
GapStoryRenderFrameRangeElem *frn_elem;
char *l_framename;
gint32 l_frame_group_count;
gint32 l_fnr;
gint32 l_step;
gint32 l_found_at_idx;
gint32 l_frames_to_handle;
l_frame_group_count = 0;
l_framename = NULL;
/* default attributes (used if storyboard does not define settings) */
*opacity = 1.0;
*scale_x = 1.0;
*scale_y = 1.0;
*move_x = 0.0;
*move_y = 0.0;
*localframe_index = -1;
*local_stepcount = 0;
*localframe_tween_rest = 0.0;
*frn_type = GAP_FRN_SILENCE;
*keep_proportions = FALSE;
*fit_width = TRUE;
*fit_height = TRUE;
*red_f = 0.0;
*green_f = 0.0;
*blue_f = 0.0;
*alpha_f = 1.0;
*filtermacro_file = NULL;
*frn_elem_ptr = NULL;
l_found_at_idx=0;
for (frn_elem = frn_list; frn_elem != NULL; frn_elem = (GapStoryRenderFrameRangeElem *)frn_elem->next)
{
if(frn_elem->track == track)
{
l_frames_to_handle = frn_elem->frames_to_handle;
if (frn_elem->wait_untiltime_sec > 0)
{
l_frames_to_handle += MAX(0, frn_elem->wait_untilframes - l_frame_group_count);
}
if (master_frame_nr <= l_frame_group_count + l_frames_to_handle)
{
gdouble fnr;
/* calculate positive or negative offset from_frame to desired frame */
fnr = (gdouble)(frn_elem->delta * (master_frame_nr - (l_frame_group_count +1 )))
* frn_elem->step_density;
/* calculate framenumber local to the clip */
l_fnr = (gint32)(frn_elem->frame_from + fnr);
{
gint32 fnrInt;
fnrInt = fnr; /* truncate to integer */
*localframe_tween_rest = fnr - fnrInt;
if(gap_debug)
{
printf("fnr:%.4f, fnrInt:%d localframe_tween_rest:%.4f\n"
,(float)fnr
,(int)fnrInt
,(float)*localframe_tween_rest
);
}
}
*local_stepcount = master_frame_nr - l_frame_group_count;
*local_stepcount -= 1;
switch(frn_elem->frn_type)
{
case GAP_FRN_SILENCE:
case GAP_FRN_COLOR:
l_framename = NULL; /* there is no filename for video silence or unicolor */
break;
case GAP_FRN_IMAGE:
l_framename = g_strdup(frn_elem->basename); /* use 1:1 basename for single images */
break;
case GAP_FRN_ANIMIMAGE:
l_framename = g_strdup(frn_elem->basename); /* use 1:1 basename for ainimated single images */
*localframe_index = l_fnr; /* local frame number is index in the layerstack */
break;
case GAP_FRN_MOVIE:
/* video file frame numners start at 1 */
l_framename = g_strdup(frn_elem->basename); /* use 1:1 basename for videofiles */
*localframe_index = l_fnr; /* local frame number is the wanted video frame number */
break;
case GAP_FRN_FRAMES:
l_framename = gap_lib_alloc_fname(frn_elem->basename
,l_fnr
,frn_elem->ext
);
break;
case GAP_FRN_SECTION:
/* frame numners in storyboard sections start at 1 */
l_framename = g_strdup(frn_elem->basename); /* section_name 1:1 for STB sections */
*localframe_index = l_fnr; /* local frame number is the wanted video frame number */
break;
}
/* return values for current fixed attribute settings
*/
*frn_type = frn_elem->frn_type;
*keep_proportions = frn_elem->keep_proportions;
*fit_width = frn_elem->fit_width;
*fit_height = frn_elem->fit_height;
*red_f = frn_elem->red_f;
*green_f = frn_elem->green_f;
*blue_f = frn_elem->blue_f;
*alpha_f = frn_elem->alpha_f;
*filtermacro_file = frn_elem->filtermacro_file;
frn_elem->last_master_frame_access = master_frame_nr;
*frn_elem_ptr = frn_elem; /* deliver pointer to the current frn_elem */
/* calculate effect attributes for the current step
* where l_step = 0 at the 1.st frame of the local range
*/
l_step = (master_frame_nr - 1) - l_frame_group_count;
*opacity = p_step_attribute_read(l_step
, frn_elem->opacity_from
, frn_elem->opacity_to
, frn_elem->opacity_dur
);
*scale_x = p_step_attribute_read(l_step
, frn_elem->scale_x_from
, frn_elem->scale_x_to
, frn_elem->scale_x_dur
);
*scale_y = p_step_attribute_read(l_step
, frn_elem->scale_y_from
, frn_elem->scale_y_to
, frn_elem->scale_y_dur
);
*move_x = p_step_attribute_read(l_step
, frn_elem->move_x_from
, frn_elem->move_x_to
, frn_elem->move_x_dur
);
*move_y = p_step_attribute_read(l_step
, frn_elem->move_y_from
, frn_elem->move_y_to
, frn_elem->move_y_dur
);
break;
}
l_frame_group_count += l_frames_to_handle;
}
l_found_at_idx++;
}
if(gap_debug)
{
printf("p_fetch_framename: track:%d master_frame_nr:%d framename:%s: found_at_idx:%d opa:%f scale:%f %f move:%f %f layerstack_idx:%d\n"
,(int)track
,(int)master_frame_nr
, l_framename
,(int)l_found_at_idx
, (float)*opacity
, (float)*scale_x
, (float)*scale_y
, (float)*move_x
, (float)*move_y
, (int)*localframe_index
);
}
return l_framename;
} /* end p_fetch_framename */
/* ---------------------------------
* p_calculate_frames_to_handle
* ---------------------------------
*/
static void
p_calculate_frames_to_handle(GapStoryRenderFrameRangeElem *frn_elem)
{
gdouble fnr;
if(frn_elem->step_density <= 0)
{
/* force legal value */
frn_elem->step_density = 1.0;
}
fnr = (gdouble)(ABS(frn_elem->frame_from - frn_elem->frame_to) +1);
fnr = fnr / frn_elem->step_density;
frn_elem->frames_to_handle = MAX((gint32)(fnr + 0.5), 1);
} /* end p_calculate_frames_to_handle */
/* ----------------------------------------------------
* p_new_framerange_element
* ----------------------------------------------------
* allocate a new GapStoryRenderFrameRangeElem for storyboard processing
* - read directory to check for first and last available frame Number
* for the given filename and extension.
* - findout processing order (1 ascending, -1 descending)
* - findout frames_to_handle in the given range.
*
* Single images are added with frn_type == GAP_FRN_IMAGE
* and frame_from = 1
* and frame_to = N (10 if image is to display for duration of 10 frames)
*
* return GapStoryRenderFrameRangeElem with allocated copies of basename and ext strings.
*/
static GapStoryRenderFrameRangeElem *
p_new_framerange_element(GapStoryRenderFrameType frn_type
,gint32 track
,const char *basename /* basename or full imagename for frn_type GAP_FRN_IMAGE */
,const char *ext /* NULL for frn_type GAP_FRN_IMAGE and GAP_FRN_MOVIE */
,gint32 frame_from /* IN: range start */
,gint32 frame_to /* IN: range end */
,const char *storyboard_file /* IN: NULL if no storyboard file is used */
,const char *preferred_decoder /* IN: NULL if no preferred_decoder is specified */
,const char *filtermacro_file /* IN: NULL, or name of the macro file */
,GapStoryRenderFrameRangeElem *frn_list /* NULL or list of already known ranges */
,GapStoryRenderErrors *sterr /* element to store Error/Warning report */
,gint32 seltrack /* IN: select videotrack number 1 upto 99 for GAP_FRN_MOVIE */
,gint32 exact_seek /* IN: 0 fast seek, 1 exact seek (only for GVA Videoreads) */
,gdouble delace /* IN: 0.0 no deinterlace, 1.0-1.99 odd 2.0-2.99 even rows (only for GVA Videoreads) */
,gdouble step_density /* IN: 1==normal stepsize 1:1 0.5 == each frame twice, 2.0 only every 2nd frame */
,gint32 flip_request /* 0 NONE, 1 flip horizontal, 2 flip vertical, 3 rotate 180degree */
,const char *mask_name /* reference to layer mask definition */
,gdouble mask_stepsize /* stepsize for the layer mask */
,GapStoryMaskAnchormode mask_anchor /* how to apply the layer mask */
,gboolean mask_disable
,gint32 fmac_total_steps
)
{
GapStoryRenderFrameRangeElem *frn_elem;
if(gap_debug)
{
printf("\np_new_framerange_element: START frn_type:%d\n", (int)frn_type);
printf(" track:%d:\n", (int)track);
printf(" frame_from:%d:\n", (int)frame_from);
printf(" frame_to:%d:\n", (int)frame_to);
printf(" step_density:%f:\n", (float)step_density);
if(basename) printf(" basename:%s:\n", basename);
if(ext) printf(" ext:%s:\n", ext);
if(storyboard_file) printf(" storyboard_file:%s:\n", storyboard_file);
if(preferred_decoder) printf(" preferred_decoder:%s:\n", preferred_decoder);
}
frn_elem = g_malloc0(sizeof(GapStoryRenderFrameRangeElem));
frn_elem->frn_type = frn_type;
frn_elem->track = track;
frn_elem->frame_from = frame_from;
frn_elem->frame_to = frame_to;
frn_elem->frames_to_handle = 0;
frn_elem->delta = 1;
frn_elem->step_density = step_density;
frn_elem->last_master_frame_access = -1; /* -1 indicate that there was no access */
frn_elem->flip_request = flip_request;
frn_elem->mask_framecount = 0;
frn_elem->mask_stepsize = mask_stepsize;
frn_elem->mask_anchor = mask_anchor;
/* disabled masks are ignored for storyboard processing
* by using a mask_name == NULL
*/
frn_elem->mask_name = NULL;
if(!mask_disable)
{
if(mask_name)
{
frn_elem->mask_name = g_strdup(mask_name);
}
}
/* default attributes (used if storyboard does not define settings) */
frn_elem->red_f = 0.0;
frn_elem->green_f = 0.0;
frn_elem->blue_f = 0.0;
frn_elem->alpha_f = 1.0;
frn_elem->keep_proportions = FALSE;
frn_elem->fit_width = TRUE;
frn_elem->fit_height = TRUE;
frn_elem->wait_untiltime_sec = 0.0;
frn_elem->wait_untilframes = 0;
frn_elem->opacity_from = 1.0;
frn_elem->opacity_to = 1.0;
frn_elem->opacity_dur = 0;
frn_elem->scale_x_from = 1.0;
frn_elem->scale_x_to = 1.0;
frn_elem->scale_x_dur = 0;
frn_elem->scale_y_from = 1.0;
frn_elem->scale_y_to = 1.0;
frn_elem->scale_y_dur = 0;
frn_elem->move_x_from = 0.0;
frn_elem->move_x_to = 0.0;
frn_elem->move_x_dur = 0;
frn_elem->move_y_from = 0.0;
frn_elem->move_y_to = 0.0;
frn_elem->move_y_dur = 0;
frn_elem->filtermacro_file = NULL;
frn_elem->filtermacro_file_to = NULL;
frn_elem->fmac_total_steps = 1;
frn_elem->gvahand = NULL;
frn_elem->seltrack = seltrack;
frn_elem->exact_seek = exact_seek;
frn_elem->delace = delace;
frn_elem->next = NULL;
if(ext)
{
if(*ext == '.')
{
frn_elem->ext = g_strdup(ext);
}
else
{
frn_elem->ext = g_strdup_printf(".%s", ext);
}
}
/* check basename for absolute pathname.
* Except for frn_type GAP_FRN_SECTION, where basename
* refers to a section_name and not to a filename(part).
*/
if(basename)
{
if (frn_type == GAP_FRN_SECTION)
{
frn_elem->basename = g_strdup(basename);
}
else
{
frn_elem->basename = gap_file_make_abspath_filename(basename, storyboard_file);
}
} /* end check for absolute pathname */
/* check filtermacro_file for absolute pathname */
frn_elem->fmac_total_steps = fmac_total_steps;
frn_elem->filtermacro_file = NULL;
if(filtermacro_file)
{
if(*filtermacro_file != '\0')
{
frn_elem->filtermacro_file = gap_file_make_abspath_filename(filtermacro_file, storyboard_file);
if(!g_file_test(frn_elem->filtermacro_file, G_FILE_TEST_EXISTS))
{
char *l_errtxt;
l_errtxt = g_strdup_printf("filtermacro_file not found: %s", frn_elem->filtermacro_file);
p_set_stb_error(sterr, l_errtxt);
g_free(l_errtxt);
g_free(frn_elem->filtermacro_file);
frn_elem->filtermacro_file = NULL;
}
else
{
frn_elem->filtermacro_file_to = gap_fmac_get_alternate_name(filtermacro_file);
if(frn_elem->filtermacro_file_to)
{
if(!gap_fmac_chk_filtermacro_file(frn_elem->filtermacro_file_to))
{
g_free(frn_elem->filtermacro_file_to);
frn_elem->filtermacro_file_to = NULL;
}
}
}
}
}
/* check processing order delta */
if (frn_elem->frame_from > frn_elem->frame_to)
{
frn_elem->delta = -1; /* -1 is inverse (descending) order */
}
else
{
frn_elem->delta = 1; /* +1 is normal (ascending) order */
}
/* calculate frames_to_handle respecting step_density */
p_calculate_frames_to_handle(frn_elem);
if(gap_debug)
{
if(frn_elem->basename) printf("\np_new_framerange_element: frn_elem->basename:%s:\n", frn_elem->basename);
if(frn_elem->ext) printf("p_new_framerange_element: frn_elem->ext:%s:\n",frn_elem->ext);
printf("p_new_framerange_element: frn_elem->frame_from:%d:\n", (int)frn_elem->frame_from);
printf("p_new_framerange_element: frn_elem->frame_to:%d:\n", (int)frn_elem->frame_to);
printf("p_new_framerange_element: frn_elem->frames_to_handle:%d:\n", (int)frn_elem->frames_to_handle);
printf("\np_new_framerange_element: END\n");
}
return(frn_elem);
} /* end p_new_framerange_element */
/* --------------------------------
* p_add_frn_list
* --------------------------------
*/
static void
p_add_frn_list(GapStoryRenderVidHandle *vidhand, GapStoryRenderFrameRangeElem *frn_elem)
{
GapStoryRenderFrameRangeElem *frn_listend;
if((vidhand) && (frn_elem))
{
if(vidhand->parsing_section == NULL)
{
printf("** INTERNAL ERROR parsing_section is NULL\n");
return;
}
frn_listend = vidhand->parsing_section->frn_list;
if (vidhand->parsing_section->frn_list == NULL)
{
/* 1. element (or returned list) starts frn_list */
vidhand->parsing_section->frn_list = frn_elem;
}
else
{
/* link frn_elem (that can be a single ement or list) to the end of frn_list */
frn_listend = vidhand->parsing_section->frn_list;
while(frn_listend->next != NULL)
{
frn_listend = (GapStoryRenderFrameRangeElem *)frn_listend->next;
}
frn_listend->next = (GapStoryRenderFrameRangeElem *)frn_elem;
}
}
} /* end p_add_frn_list */
/* ----------------------------------------------------
* p_step_all_vtrack_attributes
* ----------------------------------------------------
*/
static void
p_step_all_vtrack_attributes(gint32 track
, gint32 frames_to_handle
, GapStoryRenderVTrackArray *vtarr
)
{
p_step_attribute( frames_to_handle
, &vtarr->attr[track].opacity_from
, &vtarr->attr[track].opacity_to
, &vtarr->attr[track].opacity_dur
);
p_step_attribute( frames_to_handle
, &vtarr->attr[track].scale_x_from
, &vtarr->attr[track].scale_x_to
, &vtarr->attr[track].scale_x_dur
);
p_step_attribute( frames_to_handle
, &vtarr->attr[track].scale_y_from
, &vtarr->attr[track].scale_y_to
, &vtarr->attr[track].scale_y_dur
);
p_step_attribute( frames_to_handle
, &vtarr->attr[track].move_x_from
, &vtarr->attr[track].move_x_to
, &vtarr->attr[track].move_x_dur
);
p_step_attribute( frames_to_handle
, &vtarr->attr[track].move_y_from
, &vtarr->attr[track].move_y_to
, &vtarr->attr[track].move_y_dur
);
} /* end p_step_all_vtrack_attributes */
/* ----------------------------------------------------
* p_set_vtrack_attributes
* ----------------------------------------------------
* set current video track attributes for the
* Framerange_Element. from the current attribute array.
*
* attribute array is changed to the state after
* the playback of the Framerange_element.
*
* Example for fade_in Attribute settings:
* IN: opacity_from: 0.0 opacity_to: 1.0 opacity_dur: 50 frames
* if the range has 50 or more frames
* the fade_in can be handled fully within the range,
* the result will be:
* OUT: opacity_from: 1.0 opacity_to: 1.0 opacity_dur: 0 frames
*
* if the range is for example 25 frames (smaller than the duration 50)
* the result will be:
* OUT: opacity_from: 0.5 opacity_to: 1.0 opacity_dur: 25 frames
* because there are 25 rest frames to complete the fade in action
* in the next range (if there will be any)
*
*/
static void
p_set_vtrack_attributes(GapStoryRenderFrameRangeElem *frn_elem
,GapStoryRenderVTrackArray *vtarr
)
{
gint32 track;
track = frn_elem->track;
frn_elem->keep_proportions = vtarr->attr[track].keep_proportions;
frn_elem->fit_width = vtarr->attr[track].fit_width;
frn_elem->fit_height = vtarr->attr[track].fit_height;
frn_elem->mask_framecount = vtarr->attr[track].mask_framecount;
frn_elem->opacity_from = vtarr->attr[track].opacity_from;
frn_elem->opacity_to = vtarr->attr[track].opacity_to;
frn_elem->opacity_dur = vtarr->attr[track].opacity_dur;
frn_elem->scale_x_from = vtarr->attr[track].scale_x_from;
frn_elem->scale_x_to = vtarr->attr[track].scale_x_to;
frn_elem->scale_x_dur = vtarr->attr[track].scale_x_dur;
frn_elem->scale_y_from = vtarr->attr[track].scale_y_from;
frn_elem->scale_y_to = vtarr->attr[track].scale_y_to;
frn_elem->scale_y_dur = vtarr->attr[track].scale_y_dur;
frn_elem->move_x_from = vtarr->attr[track].move_x_from;
frn_elem->move_x_to = vtarr->attr[track].move_x_to;
frn_elem->move_x_dur = vtarr->attr[track].move_x_dur;
frn_elem->move_y_from = vtarr->attr[track].move_y_from;
frn_elem->move_y_to = vtarr->attr[track].move_y_to;
frn_elem->move_y_dur = vtarr->attr[track].move_y_dur;
/* advance mask_framecount */
vtarr->attr[track].mask_framecount += frn_elem->frames_to_handle;
p_step_all_vtrack_attributes(track, frn_elem->frames_to_handle, vtarr);
} /* end p_set_vtrack_attributes */
/* ---------------------------------
* p_vidclip_add_as_is
* ---------------------------------
* set vtrack attribtes and add the frn_elem to the
* list of videoclips (frn_list).
* NOTE: the mask_framecount is set from current vattr context.
*/
static void
p_vidclip_add_as_is(GapStoryRenderFrameRangeElem *frn_elem
,GapStoryRenderVidHandle *vidhand
,GapStoryRenderVTrackArray *vtarr
)
{
if(frn_elem)
{
vtarr->attr[frn_elem->track].frame_count += frn_elem->frames_to_handle;
p_set_vtrack_attributes(frn_elem, vtarr);
p_add_frn_list(vidhand, frn_elem);
if(gap_debug)
{
printf("#------------------ \n");
gap_story_render_debug_print_frame_elem(frn_elem, -4);
printf("\n#------------------ \n");
}
}
} /* end p_vidclip_add_as_is */
/* ---------------------------------
* p_vidclip_shadow_add_silence
* ---------------------------------
*/
static void
p_vidclip_shadow_add_silence(gint32 shadow_track
,gint32 fill_shadow_frames
,GapStoryRenderVidHandle *vidhand
,GapStoryRenderVTrackArray *vtarr
,const char *storyboard_file)
{
GapStoryRenderFrameRangeElem *frn_elem;
frn_elem = p_new_framerange_element(GAP_FRN_SILENCE
, shadow_track
, NULL /* basename */
, NULL /* extension */
, 1 /* frame_from */
, fill_shadow_frames /* frame_to */
, storyboard_file
, NULL /* preferred_decoder */
, NULL /* filtermacro_file */
, vidhand->frn_list
, vidhand->sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
if(frn_elem)
{
vtarr->attr[frn_elem->track].frame_count += frn_elem->frames_to_handle;
p_set_vtrack_attributes(frn_elem, vtarr);
/* do NOT step vtrack attributes
* because ths fill operation with empty frames in the shadow track
* creates frames before the current position and needs no current vtrack attributes
* and MUST NOT change the current vattr settings.
*/
p_add_frn_list(vidhand, frn_elem);
}
} /* end p_vidclip_shadow_add_silence */
/* ---------------------------------
* p_recalculate_range_part
* ---------------------------------
* calculate a new from_frames and to_frames values
* to reduce the clip length to the specified rest_frames.
* lost_frames is an offest from the start.
*
*
* #########################################################
* | | | |
* |<-- lost_frames -->|<----- rest_frames --->| |
* | | |
* | |
* |<--- frames_to_handle (before recalculate) ----------->|
*/
static void
p_recalculate_range_part(GapStoryRenderFrameRangeElem *frn_elem
, gint32 lost_frames
, gint32 rest_frames)
{
gdouble l_offs_lost;
gdouble l_offs_rest;
gdouble l_orig_from;
gdouble l_orig_to;
gint32 l_orig_frames_to_handle;
l_orig_from = frn_elem->frame_from;
l_orig_to = frn_elem->frame_to;
p_calculate_frames_to_handle(frn_elem);
l_orig_frames_to_handle = frn_elem->frames_to_handle;
if ((lost_frames + rest_frames) > l_orig_frames_to_handle)
{
printf("p_recalculate_range_part: ** ERROR cant split %d frames into parts of %d + %d\n"
, (int)frn_elem->frames_to_handle
, (int)lost_frames
, (int)rest_frames
);
if(lost_frames > frn_elem->frames_to_handle)
{
return;
}
rest_frames = frn_elem->frames_to_handle - lost_frames;
}
l_offs_lost = (gdouble)lost_frames * frn_elem->step_density;
l_offs_rest = (gdouble)(MAX(0,rest_frames -1)) * frn_elem->step_density;
if(frn_elem->frame_to >= frn_elem->frame_from)
{
frn_elem->frame_from += l_offs_lost;
frn_elem->frame_to = frn_elem->frame_from + l_offs_rest;
}
else
{
frn_elem->frame_from -= l_offs_lost;
frn_elem->frame_to = frn_elem->frame_from - l_offs_rest;
frn_elem->frame_from += 0.5;
frn_elem->frame_to += 0.5;
}
p_calculate_frames_to_handle(frn_elem);
if(gap_debug)
{
printf("\nRANGE PART (in): orig from:%.3f to:%.3f to_handle:%d lost_frames:%d rest_frames:%d\n"
, (float)l_orig_from
, (float)l_orig_to
, (int)l_orig_frames_to_handle
, (int)lost_frames
, (int)rest_frames
);
printf("RANGE PART (out): from:%f to:%f offs_lost:%f offs_rest:%f frames_to_handle: %d\n\n"
, (float)frn_elem->frame_from
, (float)frn_elem->frame_to
, (float)l_offs_lost
, (float)l_offs_rest
, (int)frn_elem->frames_to_handle
);
}
if(frn_elem->frames_to_handle != rest_frames)
{
if(gap_debug)
{
/* result may differ due to rounding
* in case step_density != 1.0 is used
*/
printf("\n\nRANGE PART (dif) frames_to_handle != rest_frames due to rounding differences\n");
printf(" ==> FORCE frames_to_handle: from caluclated value: %d forced value: %d\n\n"
,(int)frn_elem->frames_to_handle
,(int)rest_frames
);
}
frn_elem->frames_to_handle = rest_frames;
}
} /* end p_recalculate_range_part */
/* ---------------------------------
* p_copy_vattr_values
* ---------------------------------
* copy video attribute values from specified src track
* to specified dest track.
* NOTE:
* the current frame_count and overlap_count are NOT copied!
* (typical use of this procedure is to transfer the settings
* from a normal track to a shadow track, where the counters
* must not be affected by the copy)
*/
static void
p_copy_vattr_values(gint32 src_track
, gint32 dst_track
, GapStoryRenderVTrackArray *vtarr
)
{
vtarr->attr[dst_track].keep_proportions = vtarr->attr[src_track].keep_proportions;
vtarr->attr[dst_track].fit_width = vtarr->attr[src_track].fit_width;
vtarr->attr[dst_track].fit_height = vtarr->attr[src_track].fit_height;
vtarr->attr[dst_track].opacity_from = vtarr->attr[src_track].opacity_from;
vtarr->attr[dst_track].opacity_to = vtarr->attr[src_track].opacity_to;
vtarr->attr[dst_track].opacity_dur = vtarr->attr[src_track].opacity_dur;
vtarr->attr[dst_track].scale_x_from = vtarr->attr[src_track].scale_x_from;
vtarr->attr[dst_track].scale_x_to = vtarr->attr[src_track].scale_x_to;
vtarr->attr[dst_track].scale_x_dur = vtarr->attr[src_track].scale_x_dur;
vtarr->attr[dst_track].scale_y_from = vtarr->attr[src_track].scale_y_from;
vtarr->attr[dst_track].scale_y_to = vtarr->attr[src_track].scale_y_to;
vtarr->attr[dst_track].scale_y_dur = vtarr->attr[src_track].scale_y_dur;
vtarr->attr[dst_track].move_x_from = vtarr->attr[src_track].move_x_from;
vtarr->attr[dst_track].move_x_to = vtarr->attr[src_track].move_x_to;
vtarr->attr[dst_track].move_x_dur = vtarr->attr[src_track].move_x_dur;
vtarr->attr[dst_track].move_y_from = vtarr->attr[src_track].move_y_from;
vtarr->attr[dst_track].move_y_to = vtarr->attr[src_track].move_y_to;
vtarr->attr[dst_track].move_y_dur = vtarr->attr[src_track].move_y_dur;
} /* end p_copy_vattr_values */
/* ---------------------------------
* p_vidclip_split_and_add_frn_list
* ---------------------------------
* split the current clip into parts used for overlap in the shadow track
* and remaining part in the normal track.
* if the required amount of overlaping frames is not available in this
* currently handled clip, the splitting will continue in the following
* clips later on. In this case there will be no remaning part.
* In some rare cases the current clip is completely thrown away
* because the needed amount for overlapping will be fetched from
* one of the following handled clips.
*/
static void
p_vidclip_split_and_add_frn_list(GapStoryRenderFrameRangeElem *frn_elem
,GapStoryRenderVidHandle *vidhand
,GapStoryRenderVTrackArray *vtarr
,const char *storyboard_file)
{
gint32 l_track;
gint32 l_shadow_track;
gint32 l_shadow_frames_free;
gint32 l_cut_frames; /* frames cut off from start of this video clip */
gint32 l_overlap_frames; /* overlapping frames handled by this video clip */
gint32 l_fill_shadow_frames; /* requred empty frames to fill up shadow track */
gint32 l_lost_frames; /* frames in this clip thrown away because no space in shadow track */
gint32 l_remain_frames; /* frames reamaining to be placed in normal track */
gint32 l_dead_frames; /* frames in this clip and further clips thrown away because no space in shadow track */
gint32 l_need_frames; /* required number of frames to overlap */
l_track = frn_elem->track;
l_shadow_track = l_track - 1;
l_shadow_frames_free = MAX(0, (vtarr->attr[l_track].frame_count
- vtarr->attr[l_shadow_track].frame_count));
l_cut_frames = MIN(vtarr->attr[l_track].overlap_count, frn_elem->frames_to_handle);
l_fill_shadow_frames =
MAX(0,
((vtarr->attr[l_track].frame_count
- vtarr->attr[l_track].overlap_count)
- vtarr->attr[l_shadow_track].frame_count)
);
l_need_frames = MAX(0, (l_shadow_frames_free - l_fill_shadow_frames));
l_dead_frames = vtarr->attr[l_track].overlap_count - l_need_frames;
l_overlap_frames = MAX(0, (l_cut_frames - l_dead_frames));
l_lost_frames = l_cut_frames - l_overlap_frames;
l_remain_frames = frn_elem->frames_to_handle - l_cut_frames;
if(gap_debug)
{
printf("SPLIT: free_shadow:%d fill_shadow:%d need:%d dead:%d cut: %d, overlap:%d, lost:%d remain:%d\n"
, (int)l_shadow_frames_free
, (int)l_fill_shadow_frames
, (int)l_need_frames
, (int)l_dead_frames
, (int)l_cut_frames
, (int)l_overlap_frames
, (int)l_lost_frames
, (int)l_remain_frames
);
}
if(l_fill_shadow_frames > 0)
{
p_vidclip_shadow_add_silence(l_shadow_track
, l_fill_shadow_frames
, vidhand
, vtarr
, storyboard_file
);
/* reset mask_framecount in shadow track to 0 */
vtarr->attr[l_shadow_track].mask_framecount = 0;
}
if(l_overlap_frames > 0)
{
GapStoryRenderFrameRangeElem *frn_elem_dup;
/* shadow track shall continue with current vatt settings
* of the corresponding normal track
*/
p_copy_vattr_values(l_track /* source */
,l_shadow_track /* destination */
,vtarr
);
/* create a copy for the shadow track */
frn_elem_dup = p_new_framerange_element(frn_elem->frn_type
,l_shadow_track
,frn_elem->basename
,frn_elem->ext
,frn_elem->frame_from
,frn_elem->frame_to
,storyboard_file
,vidhand->preferred_decoder
,frn_elem->filtermacro_file
,vidhand->frn_list
,vidhand->sterr
,frn_elem->seltrack
,frn_elem->exact_seek
,frn_elem->delace
,frn_elem->step_density
,frn_elem->flip_request
,frn_elem->mask_name
,frn_elem->mask_stepsize
,frn_elem->mask_anchor
,FALSE /* keep mask enabled if the element has one */
,frn_elem->fmac_total_steps
);
p_recalculate_range_part(frn_elem_dup
,l_lost_frames
,l_overlap_frames
);
p_vidclip_add_as_is(frn_elem_dup, vidhand, vtarr);
/* copy vattr settings back from shadow track to normal track
* (after the overlapping frames were processed in the
* shadow track), the normal track will continue with settings
* changed by shadow track processing
*/
p_copy_vattr_values(l_shadow_track /* source */
,l_track /* destination */
,vtarr
);
/* continue mask_framecount in normal track (that has started in the shadow track) */
vtarr->attr[l_track].mask_framecount = vtarr->attr[l_shadow_track].mask_framecount;
/* decrement overlap_count by */
vtarr->attr[l_track].overlap_count -= l_cut_frames;
}
if(l_remain_frames > 0)
{
p_recalculate_range_part(frn_elem
,l_cut_frames
,l_remain_frames
);
p_vidclip_add_as_is(frn_elem, vidhand, vtarr);
}
} /* end p_vidclip_split_and_add_frn_list */
/* ---------------------------------
* p_vidclip_add
* ---------------------------------
* set vtrack attribtes and add the frn_elem to the
* list of videoclips (frn_list)
* Overlapping is handled by splitting th video clip
* into appropriate parts, where the overlapping frames
* are placed into the shadow track.
*/
static void
p_vidclip_add(GapStoryRenderFrameRangeElem *frn_elem
,GapStoryRenderVidHandle *vidhand
,GapStoryRenderVTrackArray *vtarr
,const char *storyboard_file
,gboolean first_of_group
)
{
if(frn_elem == NULL)
{
return;
}
if(vtarr->attr[frn_elem->track].overlap_count > 0)
{
if(first_of_group)
{
/* reset mask frame progress to 0 in the shadow track */
vtarr->attr[frn_elem->track -1].mask_framecount = 0; /* shadow track */
}
/* an overlap transition is pending
* have to split off the overlapping frame part
* to the shadow track, the rest will be added to
* the normal track
*/
p_vidclip_split_and_add_frn_list(frn_elem, vidhand, vtarr, storyboard_file);
}
else
{
if(first_of_group)
{
/* reset mask frame progress to 0 before processing each parsed clip.
* the mask_framecount handles clip internal start value for fetching layer mask frames
* in case were the scanned clip is splitted internally
* (due to repetitions, pingpong mode, or overlapping)
* the splitted parts 2 up to N will have mask_framecount > 0
*/
vtarr->attr[frn_elem->track].mask_framecount = 0;
}
/* normal scenario without shadow track overlapping
* simply add the video clip 1:1 to the list
*/
p_vidclip_add_as_is(frn_elem, vidhand, vtarr);
}
} /* end p_vidclip_add */
/* ----------------------------------------------------
* p_clear_vattr_array
* ----------------------------------------------------
*/
static void
p_clear_vattr_array(GapStoryRenderVTrackArray *vtarr)
{
gint l_idx;
vtarr->max_tracknum = GAP_STB_MAX_VID_INTERNAL_TRACKS -1;
/* clear video track attribute settings for all tracks */
for(l_idx=0; l_idx <= vtarr->max_tracknum; l_idx++)
{
vtarr->attr[l_idx].frame_count = 0;
vtarr->attr[l_idx].overlap_count = 0;
vtarr->attr[l_idx].mask_framecount = 0;
vtarr->attr[l_idx].keep_proportions = FALSE;
vtarr->attr[l_idx].fit_width = TRUE;
vtarr->attr[l_idx].fit_height = TRUE;
vtarr->attr[l_idx].opacity_from = 1.0;
vtarr->attr[l_idx].opacity_to = 1.0;
vtarr->attr[l_idx].opacity_dur = 0;
vtarr->attr[l_idx].scale_x_from = 1.0;
vtarr->attr[l_idx].scale_x_to = 1.0;
vtarr->attr[l_idx].scale_x_dur = 0;
vtarr->attr[l_idx].scale_y_from = 1.0;
vtarr->attr[l_idx].scale_y_to = 1.0;
vtarr->attr[l_idx].scale_y_dur = 0;
vtarr->attr[l_idx].move_x_from = 0.0;
vtarr->attr[l_idx].move_x_to = 0.0;
vtarr->attr[l_idx].move_x_dur = 0;
vtarr->attr[l_idx].move_y_from = 0.0;
vtarr->attr[l_idx].move_y_to = 0.0;
vtarr->attr[l_idx].move_y_dur = 0;
}
} /* end p_clear_vattr_array */
/* -------------------------------------
* p_fmt_string_has_framenumber_format
* -------------------------------------
* return true if the specified format string contains "%06d" (or "%02d" up to "%09d")
* false if the format has no such numeric part for the framenumber.
*
*/
static gboolean
p_fmt_string_has_framenumber_format(const char *fmt_string)
{
const char *ptr;
gboolean l_found;
l_found = FALSE;
ptr = fmt_string;
while(ptr)
{
if(ptr[0] == '\0')
{
break;
}
if (ptr[0] == '%')
{
if(ptr[1] != '\0')
{
if(ptr[2] != '\0')
{
if(ptr[3] != '\0')
{
if((ptr[1] == '0') && (ptr[3] == 'd'))
{
if((ptr[2] >= '2') && (ptr[2] <= '9'))
{
l_found = TRUE;
break;
}
}
}
}
}
}
ptr++;
}
return (l_found);
} /* end p_fmt_string_has_framenumber_format */
/* -------------------------------------
* p_fmt_string_has_videobasename_format
* -------------------------------------
* return true if the specified format string contains "%s"
* false if the format has no such videobasename placeholder part.
*
*/
static gboolean
p_fmt_string_has_videobasename_format(const char *fmt_string)
{
const char *ptr;
gboolean l_found;
l_found = FALSE;
ptr = fmt_string;
while(ptr)
{
if(ptr[0] == '\0')
{
break;
}
if ((ptr[0] == '%') && (ptr[1] == 's'))
{
l_found = TRUE;
break;
}
ptr++;
}
return (l_found);
} /* end p_fmt_string_has_videobasename_format */
/* ----------------------------------------------------
* p_storyboard_analyze
* ----------------------------------------------------
* this procedure checks the specified storyboard (GapStoryBoard *stb) in memory
* and converts all elements to the
* corresponding rangelist structures (audio or frames or attr tables)
* OUT: mainsection_frame_count is set to the number of frames in the main section
* (if the main section has more than one track, the longest track
* is used to set the mainsection_frame_count).
*/
static void
p_storyboard_analyze(GapStoryBoard *stb
, gint32 *mainsection_frame_count
, GapStoryRenderVidHandle *vidhand
)
{
GapStoryRenderVTrackArray vtarray;
GapStoryRenderVTrackArray *vtarr;
GapStorySection *stb_section;
GapStoryElem *stb_elem;
char *storyboard_file;
GapStoryRenderAudioRangeElem *aud_elem;
GapStoryRenderFrameRangeElem *frn_elem;
GapStoryRenderFrameRangeElem *frn_list;
GapStoryRenderFrameRangeElem *frn_pinglist;
GapStoryRenderErrors *sterr;
GapStoryRenderFrameRangeElem *frn_known_list;
gint32 l_track;
gint l_idx;
gint32 l_max_elems;
gint32 l_cnt_elems;
gint32 highest_vtrack;
sterr=vidhand->sterr;
frn_list = NULL;
vtarr = &vtarray;
storyboard_file = stb->storyboardfile;
/* copy Master informations: */
if(stb->master_width > 0)
{
vidhand->master_width = stb->master_width;
vidhand->master_height = stb->master_height;
}
if(stb->master_framerate > 0)
{
vidhand->master_framerate = stb->master_framerate;
}
vidhand->preferred_decoder = NULL;
if(stb->preferred_decoder)
{
vidhand->preferred_decoder = g_strdup(stb->preferred_decoder);
}
vidhand->master_insert_area_format = NULL;
if(stb->master_insert_area_format)
{
vidhand->master_insert_area_format = g_strdup(stb->master_insert_area_format);
vidhand->master_insert_area_format_has_framenumber =
p_fmt_string_has_framenumber_format(vidhand->master_insert_area_format);
vidhand->master_insert_area_format_has_videobasename =
p_fmt_string_has_videobasename_format(vidhand->master_insert_area_format);
}
if(stb->master_volume >= 0)
{
vidhand->master_volume = stb->master_volume;
}
if(stb->master_samplerate > 0)
{
vidhand->master_samplerate = stb->master_samplerate;
}
vidhand->section_list = NULL;
for(stb_section = stb->stb_section; stb_section != NULL; stb_section = stb_section->next)
{
if (stb_section == stb->mask_section)
{
/* ignore mask definitions (e.g. all elements in mask_section) here,
* because mask definitions are handled separately.
* (for the rendering mask_definitions are not handled like sub sections,
* mask_definitions have global scope in the whole storyboard
* see procedure p_copy_mask_definitions_to_vidhand)
*/
continue;
}
vidhand->parsing_section = p_new_render_section(stb_section->section_name);
p_append_render_section_to_vidhand(vidhand, vidhand->parsing_section);
/* clear video track attribute settings for all tracks.
* video attribute array holds current transition values (opacity, move and scale)
* of all tracks and is updated at parsing of the the current clip.
* each processed clip gets its start values from the array, and modifies the values
* according to the amount of framesteps of a transition that can be handled
* by processing the clip.
* processing of a transition attribute element explicite sets the specified
* number of framesteps, and from_ and to values for the next transition.
*
* The video attribute array must be cleared at start of each section.
*/
p_clear_vattr_array(vtarr);
/* count Elements in the current STB section and check highest video track number */
highest_vtrack = 0;
l_max_elems = 0;
for(stb_elem = stb_section->stb_elem; stb_elem != NULL; stb_elem = stb_elem->next)
{
l_max_elems++;
if(stb_elem->track > highest_vtrack)
{
highest_vtrack = stb_elem->track;
}
}
/* Loop foreach Element in the current STB section */
l_cnt_elems = 0;
for(stb_elem = stb_section->stb_elem; stb_elem != NULL; stb_elem = stb_elem->next)
{
if(stb_elem->track == GAP_STB_MASK_TRACK_NUMBER)
{
/* ignore mask definitions, in the reserved GAP_STB_MASK_TRACK_NUMBER track
* in this loop,
* mask definitions are handled separately.
* (GAP_STB_MASK_TRACK_NUMBER shall not occure in main and sub sections
* in new versions of storyboard processing)
*/
continue;
}
/* convert video tracknumbers from file to internal representation
* note that internal tracknumbers 0, 2, 4 ... are reserved for shadow tracks
* that are generated only for internal usage if a videotrack uses overlapping
* frames.
* the lowest internal tracknumber always appears in foreground
* (e.g. is placed on top of layerstack at rendering of the composite frame)
*/
if (stb->master_vtrack1_is_toplayer)
{
/* default order track 1 is the top layer
* 1 ==> 1
* 2 ==> 3
* 3 ==> 5
*/
l_track = 1 + (2 * MAX((stb_elem->track -1), 0));
}
else
{
/* inverse order track 1 is the background layer
* 1 ==> 5
* 2 ==> 3
* 3 ==> 1
*/
l_track = 1 + (2 * MAX((highest_vtrack - stb_elem->track), 0));
}
frn_known_list = vidhand->frn_list;
if (stb_section->section_name != NULL)
{
if (stb_elem->record_type == GAP_STBREC_VID_SECTION)
{
/* section playback is only supported in the main section
* in other section use black frames when they contain
* GAP_STBREC_VID_SECTION (this case should not happen regulary)
*/
stb_elem->record_type = GAP_STBREC_VID_BLACKSECTION;
}
}
/* reset mask frame progress to 1 before processing each parsed clip.
* the mask_framecount handles clip internal start value for fetching layer mask frames
* in case were the scanned clip is splitted internally
* (due to repetitions, pingpong mode, or overlapping)
* the splitted parts 2 up to N will have mask_framecount > 0
*/
vtarr->attr[l_track].mask_framecount = 0;
switch(stb_elem->record_type)
{
case GAP_STBREC_ATT_TRANSITION:
{
gint ii;
vtarr->attr[l_track].overlap_count += MAX(stb_elem->att_overlap, 0);
vtarr->attr[l_track].fit_width = stb_elem->att_fit_width;
vtarr->attr[l_track].fit_height = stb_elem->att_fit_height;
vtarr->attr[l_track].keep_proportions = stb_elem->att_keep_proportions;
for(ii=0; ii < GAP_STB_ATT_TYPES_ARRAY_MAX; ii++)
{
if(stb_elem->att_arr_enable[ii])
{
switch(ii)
{
case GAP_STB_ATT_TYPE_OPACITY:
vtarr->attr[l_track].opacity_from = stb_elem->att_arr_value_from[ii];
vtarr->attr[l_track].opacity_to = stb_elem->att_arr_value_to[ii];
vtarr->attr[l_track].opacity_dur = stb_elem->att_arr_value_dur[ii];
break;
case GAP_STB_ATT_TYPE_MOVE_X:
vtarr->attr[l_track].move_x_from = stb_elem->att_arr_value_from[ii];
vtarr->attr[l_track].move_x_to = stb_elem->att_arr_value_to[ii];
vtarr->attr[l_track].move_x_dur = stb_elem->att_arr_value_dur[ii];
break;
case GAP_STB_ATT_TYPE_MOVE_Y:
vtarr->attr[l_track].move_y_from = stb_elem->att_arr_value_from[ii];
vtarr->attr[l_track].move_y_to = stb_elem->att_arr_value_to[ii];
vtarr->attr[l_track].move_y_dur = stb_elem->att_arr_value_dur[ii];
break;
case GAP_STB_ATT_TYPE_ZOOM_X:
vtarr->attr[l_track].scale_x_from = stb_elem->att_arr_value_from[ii];
vtarr->attr[l_track].scale_x_to = stb_elem->att_arr_value_to[ii];
vtarr->attr[l_track].scale_x_dur = stb_elem->att_arr_value_dur[ii];
break;
case GAP_STB_ATT_TYPE_ZOOM_Y:
vtarr->attr[l_track].scale_y_from = stb_elem->att_arr_value_from[ii];
vtarr->attr[l_track].scale_y_to = stb_elem->att_arr_value_to[ii];
vtarr->attr[l_track].scale_y_dur = stb_elem->att_arr_value_dur[ii];
break;
}
}
}
}
break;
case GAP_STBREC_VID_SILENCE:
if(!vidhand->ignore_video)
{
/* add framerange element for the current storyboard_file line */
frn_elem = p_new_framerange_element(GAP_FRN_SILENCE
, l_track
, NULL /* basename */
, NULL /* extension */
, 1 /* frame_from */
, stb_elem->nloop /* frame_to */
, storyboard_file
, NULL /* preferred_decoder */
, NULL /* filtermacro_file */
, frn_known_list
, sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
if(frn_elem)
{
frn_elem->wait_untiltime_sec = stb_elem->vid_wait_untiltime_sec;
frn_elem->wait_untilframes = stb_elem->vid_wait_untiltime_sec * vidhand->master_framerate;
p_vidclip_add(frn_elem, vidhand, vtarr, storyboard_file, TRUE);
}
}
break;
case GAP_STBREC_VID_BLACKSECTION:
if(!vidhand->ignore_video)
{
/* add framerange element for the current storyboard_file line */
frn_elem = p_new_framerange_element(GAP_FRN_SILENCE
, l_track
, NULL /* basename */
, NULL /* extension */
, 1 /* frame_from */
, 1 + abs(stb_elem->to_frame - stb_elem->from_frame)
, storyboard_file
, NULL /* preferred_decoder */
, NULL /* filtermacro_file */
, frn_known_list
, sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
if(frn_elem)
{
p_vidclip_add(frn_elem, vidhand, vtarr, storyboard_file, TRUE);
}
}
break;
case GAP_STBREC_VID_COLOR:
if(!vidhand->ignore_video)
{
/* add framerange element for the current storyboard_file line */
frn_elem = p_new_framerange_element(GAP_FRN_COLOR
, l_track
, NULL
, NULL /* extension */
, 1 /* frame_from */
, stb_elem->nloop /* frame_to */
, storyboard_file
, NULL /* referred_decoder */
, NULL /* filtermacro_file */
, frn_known_list
, sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, stb_elem->flip_request
, stb_elem->mask_name
, stb_elem->mask_stepsize
, stb_elem->mask_anchor
, stb_elem->mask_disable
, stb_elem->fmac_total_steps
);
if(frn_elem)
{
frn_elem->red_f = CLAMP(stb_elem->color_red, 0.0, 1.0);
frn_elem->green_f = CLAMP(stb_elem->color_green, 0.0, 1.0);
frn_elem->blue_f = CLAMP(stb_elem->color_blue, 0.0, 1.0);
frn_elem->alpha_f = CLAMP(stb_elem->color_alpha, 0.0, 1.0);
p_vidclip_add(frn_elem, vidhand, vtarr, storyboard_file, TRUE);
}
}
break;
case GAP_STBREC_VID_IMAGE:
if(!vidhand->ignore_video)
{
/* add framerange element for the current storyboard_file line */
frn_elem = p_new_framerange_element(GAP_FRN_IMAGE
, l_track
, stb_elem->orig_filename
, NULL /* extension */
, 1 /* frame_from */
, stb_elem->nloop /* frame_to */
, storyboard_file
, vidhand->preferred_decoder
, stb_elem->filtermacro_file
, frn_known_list
, sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, stb_elem->flip_request
, stb_elem->mask_name
, stb_elem->mask_stepsize
, stb_elem->mask_anchor
, stb_elem->mask_disable
, stb_elem->fmac_total_steps
);
if(frn_elem)
{
p_vidclip_add(frn_elem, vidhand, vtarr, storyboard_file, TRUE);
}
}
break;
case GAP_STBREC_VID_ANIMIMAGE:
case GAP_STBREC_VID_FRAMES:
case GAP_STBREC_VID_MOVIE:
case GAP_STBREC_VID_SECTION:
if(!vidhand->ignore_video)
{
GapStoryRenderFrameType l_frn_type;
gint32 l_repcnt;
gint32 l_sub_from;
gint32 l_sub_to;
gint l_pingpong;
char *l_file_or_basename;
char *l_ext_ptr;
gboolean first_of_group;
l_ext_ptr = NULL;
l_file_or_basename = stb_elem->orig_filename;
l_pingpong = 1;
if(stb_elem->playmode == GAP_STB_PM_PINGPONG)
{
l_pingpong = 2;
}
l_frn_type = GAP_FRN_ANIMIMAGE;
switch(stb_elem->record_type)
{
case GAP_STBREC_VID_ANIMIMAGE:
l_frn_type = GAP_FRN_ANIMIMAGE;
l_file_or_basename = stb_elem->orig_filename;
break;
case GAP_STBREC_VID_FRAMES:
l_frn_type = GAP_FRN_FRAMES;
l_ext_ptr = stb_elem->ext;
l_file_or_basename = stb_elem->basename;
break;
case GAP_STBREC_VID_MOVIE:
l_frn_type = GAP_FRN_MOVIE;
l_file_or_basename = stb_elem->orig_filename;
break;
case GAP_STBREC_VID_SECTION:
l_frn_type = GAP_FRN_SECTION;
l_file_or_basename = stb_elem->orig_filename;
break;
default:
break; /* should never be reached */
}
frn_pinglist = frn_known_list;
first_of_group = TRUE;
/* expand element according to pingpong and nloop settings */
for(l_repcnt=0; l_repcnt < stb_elem->nloop; l_repcnt++)
{
l_sub_from = stb_elem->from_frame;
l_sub_to = stb_elem->to_frame;
for(l_idx=0; l_idx < l_pingpong; l_idx++)
{
/* add framerange element for the current storyboard_file line */
frn_elem = p_new_framerange_element( l_frn_type
, l_track
, l_file_or_basename
, l_ext_ptr
, l_sub_from
, l_sub_to
, storyboard_file
, gap_story_get_preferred_decoder(stb, stb_elem)
, stb_elem->filtermacro_file
, frn_pinglist
, sterr
, stb_elem->seltrack
, stb_elem->exact_seek
, stb_elem->delace
, stb_elem->step_density
, stb_elem->flip_request
, stb_elem->mask_name
, stb_elem->mask_stepsize
, stb_elem->mask_anchor
, stb_elem->mask_disable
, stb_elem->fmac_total_steps
);
if(frn_elem)
{
/* prepare for pingpong mode with inverted range,
* omitting the start/end frames
*/
l_sub_from = frn_elem->frame_to - frn_elem->delta;
l_sub_to = frn_elem->frame_from + frn_elem->delta;
p_vidclip_add(frn_elem, vidhand, vtarr, storyboard_file, first_of_group);
first_of_group = FALSE;
frn_pinglist = frn_list;
}
}
}
}
break;
case GAP_STBREC_AUD_SILENCE:
if(!vidhand->ignore_audio)
{
/* add audiorange element for the current storyboard_file line */
aud_elem = gap_story_render_audio_new_audiorange_element(GAP_AUT_SILENCE
, l_track
, NULL
, vidhand->master_samplerate
, 0 /* from_sec */
, stb_elem->aud_play_to_sec /* to_sec */
, 0.0 /* vol_start */
, 0.0 /* volume */
, 0.0 /* vol_end */
, 0.0 /* fade_in_sec */
, 0.0 /* fade_out_sec */
, vidhand->util_sox
, vidhand->util_sox_options
, storyboard_file
, vidhand->preferred_decoder
, vidhand->aud_list /* known audio range elements */
, sterr
, 1 /* seltrack */
, vidhand->create_audio_tmp_files
, 0.0 /* min_play_sec */
, 0.0 /* max_play_sec */
, vidhand
);
if(aud_elem)
{
aud_elem->wait_untiltime_sec = stb_elem->aud_wait_untiltime_sec;
aud_elem->wait_until_samples = stb_elem->aud_wait_untiltime_sec * aud_elem->samplerate;
gap_story_render_audio_add_aud_list(vidhand, aud_elem);
}
}
break;
case GAP_STBREC_AUD_SOUND:
case GAP_STBREC_AUD_MOVIE:
if(!vidhand->ignore_audio)
{
GapStoryRenderAudioType l_aud_type;
gint l_rix;
if(stb_elem->record_type == GAP_STBREC_AUD_SOUND)
{
l_aud_type = GAP_AUT_AUDIOFILE;
}
else
{
l_aud_type = GAP_AUT_MOVIE;
}
for(l_rix=0; l_rix < stb_elem->nloop; l_rix++)
{
/* add audiorange element for the current storyboard_file line */
aud_elem = gap_story_render_audio_new_audiorange_element(l_aud_type /* GAP_AUT_MOVIE or GAP_AUT_AUDIOFILE */
, l_track
, stb_elem->aud_filename
, vidhand->master_samplerate
, stb_elem->aud_play_from_sec
, stb_elem->aud_play_to_sec
, stb_elem->aud_volume_start
, stb_elem->aud_volume
, stb_elem->aud_volume_end
, stb_elem->aud_fade_in_sec
, stb_elem->aud_fade_out_sec
, vidhand->util_sox
, vidhand->util_sox_options
, storyboard_file
, gap_story_get_preferred_decoder(stb, stb_elem)
, vidhand->aud_list /* known audio range elements */
, sterr
, stb_elem->aud_seltrack
, vidhand->create_audio_tmp_files
, stb_elem->aud_min_play_sec
, stb_elem->aud_max_play_sec
, vidhand
);
if(aud_elem)
{
gap_story_render_audio_add_aud_list(vidhand, aud_elem);
}
}
}
break;
default:
break;
}
/* progress handling */
l_cnt_elems++;
*vidhand->progress = (gdouble)l_cnt_elems / (gdouble)l_max_elems;
if(vidhand->status_msg)
{
g_snprintf(vidhand->status_msg, vidhand->status_msg_len
, _("analyze line %d (out of %d)")
, (int)l_cnt_elems
, (int)l_max_elems
);
}
} /* END Loop foreach Element in the current STB section */
if (stb_section->section_name == NULL)
{
gint vii;
/* section_name NULL is the MAIN section
*/
vidhand->frn_list = vidhand->parsing_section->frn_list;
vidhand->aud_list = vidhand->parsing_section->aud_list;
/* findout total frame_count of the main section
* (is the max frame_count of all tracks
* within the MAIN section)
*/
for(vii=0; vii <= vtarr->max_tracknum; vii++)
{
if (*mainsection_frame_count < vtarr->attr[vii].frame_count)
{
*mainsection_frame_count = vtarr->attr[vii].frame_count;
}
}
}
} /* END loop for all sections of the storyboard */
} /* end p_storyboard_analyze */
/* ----------------------------------------------------
* p_framerange_list_from_storyboard
* ----------------------------------------------------
* this procedure builds up a framerange list
* from the given storyboard structure in MEMORY
* or by parsing the specified storyboard_file.
*
* return the framerange_list (scanned from storyboard or storyboard_file)
*/
static GapStoryRenderFrameRangeElem *
p_framerange_list_from_storyboard(const char *storyboard_file
,gint32 *frame_count
,GapStoryRenderVidHandle *vidhand
,GapStoryBoard *stb_mem_ptr
)
{
GapStoryRenderErrors *sterr;
sterr=vidhand->sterr;
*frame_count = 0;
if(gap_debug)
{
printf("p_framerange_list_from_storyboard: START vidhand:%d stb_mem_ptr;%d"
, (int)vidhand
, (int)stb_mem_ptr
);
if (storyboard_file == NULL)
{
printf(" storyboard_file: (null)");
}
else
{
printf(" storyboard_file:%s"
, storyboard_file
);
}
printf("\n");
}
/* convert from GapStoryBoard to render representation
* of the storyboard.
*/
{
GapStoryBoard *stb;
stb = NULL;
if(stb_mem_ptr)
{
/* we have a storyboard already available in MEMORY
* make a full copy for further processing.
*/
stb = gap_story_duplicate_full(stb_mem_ptr);
}
if(stb == NULL)
{
/* load and parse the storyboard structure from file */
stb = gap_story_parse(storyboard_file);
}
if(stb)
{
if(stb->errtext != NULL)
{
/* report the 1.st error */
sterr->curr_nr = stb->errline_nr;
sterr->currline = stb->errline;
p_set_stb_error(sterr, stb->errtext);
}
else
{
/* findout min and max playtime for audio clip references
* that are to extract from videofiles
*/
gap_story_set_aud_movie_min_max(stb);
/* analyze the stb list and transform this list
* to vidhand->section_list->frn_list and vidhand->section_list->aud_list
*/
p_storyboard_analyze(stb
,frame_count
,vidhand
);
/* mask definitions */
p_copy_mask_definitions_to_vidhand(stb, vidhand);
}
gap_story_free_storyboard(&stb);
}
}
/* select MAIN section (has section_name NULL) per default
* (Note: this sets vidhand->frn_list to the frn_list of the MAIN section)
*/
p_select_section_by_name(vidhand, NULL);
if((vidhand->frn_list == 0) || (*frame_count == 0))
{
*frame_count = 0;
sterr->currline = "(eof)";
p_set_stb_error(sterr, _("No Frames or Images found ...."));
/* note: this can occure if there are non empty sub sections
* but the MAIN section is empty.
* (in such a case nothing will be rendered).
*/
}
if(gap_debug)
{
printf("p_framerange_list_from_storyboard: END vidhand:%d\n"
, (int)vidhand
);
}
return (vidhand->frn_list);
} /* end p_framerange_list_from_storyboard */
/* ----------------------------------------------------
* p_free_framerange_list
* ----------------------------------------------------
*/
static void
p_free_framerange_list(GapStoryRenderFrameRangeElem * frn_list)
{
GapStoryRenderFrameRangeElem *frn_elem;
GapStoryRenderFrameRangeElem *frn_next;
for(frn_elem = frn_list; frn_elem != NULL; frn_elem = frn_next)
{
if(frn_elem->basename) { g_free(frn_elem->basename);}
if(frn_elem->ext) { g_free(frn_elem->ext);}
if(frn_elem->filtermacro_file) { g_free(frn_elem->filtermacro_file);}
#ifdef GAP_ENABLE_VIDEOAPI_SUPPORT
if(frn_elem->gvahand) { GVA_close(frn_elem->gvahand);}
#endif
frn_next = (GapStoryRenderFrameRangeElem *)frn_elem->next;
g_free(frn_elem);
}
} /* end p_free_framerange_list */
/* ----------------------------------------------------
* p_new_render_section
* ----------------------------------------------------
*/
static GapStoryRenderSection *
p_new_render_section(const char *section_name)
{
GapStoryRenderSection *new_render_section;
new_render_section = g_new(GapStoryRenderSection, 1);
new_render_section->frn_list = NULL;
new_render_section->aud_list = NULL;
new_render_section->section_name = NULL;
if (section_name != NULL)
{
new_render_section->section_name = g_strdup(section_name);
}
new_render_section->next = NULL;
return (new_render_section);
} /* end p_new_render_section */
/* ----------------------------------------------------
* p_append_render_section_to_vidhand
* ----------------------------------------------------
* append the specified new_render_section at end of the section_list
* of the specified video handle.
*/
static void
p_append_render_section_to_vidhand(GapStoryRenderVidHandle *vidhand
, GapStoryRenderSection *new_render_section)
{
GapStoryRenderSection *render_section;
for(render_section = vidhand->section_list; render_section != NULL; render_section = render_section->next)
{
if(render_section->next == NULL)
{
break;
}
}
if (render_section != NULL)
{
render_section->next = new_render_section;
}
else
{
vidhand->section_list = new_render_section;
}
} /* end p_append_render_section_to_vidhand */
/* ----------------------------------------------------
* p_open_mask_vidhand
* ----------------------------------------------------
*/
static void
p_open_mask_vidhand(GapStoryElem *stb_elem, GapStoryRenderMaskDefElem *maskdef_elem)
{
GapLibTypeInputRange input_mode;
input_mode = GAP_RNGTYPE_IMAGE;
switch(stb_elem->record_type)
{
case GAP_STBREC_VID_IMAGE:
input_mode = GAP_RNGTYPE_IMAGE;
break;
case GAP_STBREC_VID_ANIMIMAGE:
input_mode = GAP_RNGTYPE_LAYER;
break;
case GAP_STBREC_VID_FRAMES:
input_mode = GAP_RNGTYPE_FRAMES;
break;
case GAP_STBREC_VID_MOVIE:
input_mode = GAP_RNGTYPE_MOVIE;
break;
default:
break;
}
if(gap_debug)
{
printf("p_open_mask_vidhand: MASK_ELEM\n");
gap_story_debug_print_elem(stb_elem);
}
maskdef_elem->mask_vidhand = p_open_video_handle_private( TRUE /* ignore_audio */
, FALSE /* dont ignore_video */
, FALSE /* create_audio_tmp_files */
, NULL /* progress_ptr */
, NULL /* status_msg */
, 0 /* status_msg_len */
, NULL /* storyboard_file */
,stb_elem->basename
,stb_elem->ext
,stb_elem->from_frame
,stb_elem->to_frame
,&maskdef_elem->frame_count
,FALSE /* do_gimp_progress */
,input_mode
,stb_elem->orig_filename /* imagename */
,stb_elem->preferred_decoder
,stb_elem->seltrack
,stb_elem->exact_seek
,stb_elem->delace
,FALSE /* compensate_framerange */
,NULL /* stb_mem_ptr */
);
if(maskdef_elem->mask_vidhand)
{
maskdef_elem->mask_vidhand->is_mask_handle = TRUE;
}
} /* end p_open_mask_vidhand */
/* ----------------------------------------------------
* p_copy_mask_definitions
* ----------------------------------------------------
* copy mask definitions and open a sub GapStoryRenderVidHandle
* for each mask definition.
* those handles are used to fetch masks from any type of clips.
*/
static void
p_copy_mask_definitions_to_vidhand(GapStoryBoard *stb_ptr, GapStoryRenderVidHandle *vidhand)
{
GapStoryElem *stb_elem;
vidhand->maskdef_elem = NULL; /* start with empty mask definition list */
if (stb_ptr->mask_section == NULL)
{
return;
}
for(stb_elem = stb_ptr->mask_section->stb_elem; stb_elem != NULL; stb_elem = stb_elem->next)
{
if(stb_elem->track != GAP_STB_MASK_TRACK_NUMBER)
{
/* mask definitions are restricted to internal track number 0,
* ignore other tracks for maskdefinition (shall not occure)
*/
continue;
}
if ((stb_elem->record_type == GAP_STBREC_VID_SECTION)
|| (stb_elem->record_type == GAP_STBREC_VID_BLACKSECTION))
{
/* section playback is NOT supported for mask definitions.
* ignore such elements (that shall not occure in regular case)
*/
continue;
}
if(stb_elem->mask_name)
{
GapStoryRenderMaskDefElem *maskdef_elem;
GapStoryElem *stb_elem_ref;
/* check if there are references (in any section) to this mask definition */
stb_elem_ref = gap_story_find_mask_reference_by_name(stb_ptr, stb_elem->mask_name);
if(stb_elem_ref == NULL)
{
/* this mask definition is not refered,
* no processing is necessary
*/
continue;
}
if(gap_debug)
{
printf("p_copy_mask_definitions_to_vidhand: \n");
gap_story_debug_print_elem(stb_elem);
}
maskdef_elem = g_new(GapStoryRenderMaskDefElem, 1);
if(maskdef_elem)
{
maskdef_elem->mask_name = g_strdup(stb_elem->mask_name);
maskdef_elem->record_type = (gint32)stb_elem->record_type;
maskdef_elem->frame_count = 0;
maskdef_elem->flip_request = stb_elem->flip_request;
maskdef_elem->mask_vidhand = NULL;
maskdef_elem->next = vidhand->maskdef_elem;
p_open_mask_vidhand(stb_elem, maskdef_elem);
/* link mask definition element as 1st element to the list */
vidhand->maskdef_elem = maskdef_elem;
}
}
}
} /* end p_copy_mask_definitions */
/* ----------------------------------------------------
* p_free_mask_definitions
* ----------------------------------------------------
* free all mask definitions and close sub GapStoryRenderVidHandle
* for all mask definitions.
*/
static void
p_free_mask_definitions(GapStoryRenderVidHandle *vidhand)
{
GapStoryRenderMaskDefElem *maskdef_elem;
GapStoryRenderMaskDefElem *maskdef_next;
for(maskdef_elem = vidhand->maskdef_elem; maskdef_elem != NULL; maskdef_elem = maskdef_next)
{
if(maskdef_elem->mask_vidhand)
{
gap_story_render_close_vid_handle(maskdef_elem->mask_vidhand);
}
if(maskdef_elem->mask_name)
{
g_free(maskdef_elem->mask_name);
}
maskdef_next = maskdef_elem->next;
g_free(maskdef_elem);
}
} /* end p_free_mask_definitions */
/* ----------------------------------------------------
* gap_story_render_close_vid_handle
* ----------------------------------------------------
* close video handle (free framelist and errors)
*/
void
gap_story_render_close_vid_handle(GapStoryRenderVidHandle *vidhand)
{
GapStoryRenderSection *render_section;
render_section = vidhand->section_list;
while(render_section != NULL)
{
GapStoryRenderSection *next_render_section;
next_render_section = render_section->next;
p_free_framerange_list(render_section->frn_list);
if (render_section->section_name != NULL)
{
g_free(render_section->section_name);
}
g_free(render_section);
render_section = next_render_section;
}
p_free_stb_error(vidhand->sterr);
p_free_mask_definitions(vidhand);
/* unregister frame fetcher resource usage (e.g. the image cache) */
gap_frame_fetch_unregister_user(vidhand->ffetch_user_id);
vidhand->section_list = NULL;
vidhand->frn_list = NULL;
vidhand->sterr = NULL;
} /* end gap_story_render_close_vid_handle */
/* ----------------------------------------------------
* gap_story_render_set_audio_resampling_program
* ----------------------------------------------------
*/
void
gap_story_render_set_audio_resampling_program(GapStoryRenderVidHandle *vidhand
, char *util_sox
, char *util_sox_options
)
{
if(vidhand)
{
if(vidhand->util_sox)
{
g_free(vidhand->util_sox);
vidhand->util_sox = NULL;
}
if(vidhand->util_sox_options)
{
g_free(vidhand->util_sox_options);
vidhand->util_sox_options = NULL;
}
if(util_sox)
{
vidhand->util_sox = g_strdup(util_sox);
}
if(util_sox_options)
{
vidhand->util_sox_options = g_strdup(util_sox_options);
}
}
} /* end gap_story_render_set_audio_resampling_program */
/* ----------------------------------------------------
* p_find_maskdef_by_name
* ----------------------------------------------------
*/
static GapStoryRenderMaskDefElem *
p_find_maskdef_by_name(GapStoryRenderVidHandle *vidhand, const char *mask_name)
{
GapStoryRenderMaskDefElem *maskdef_elem;
for(maskdef_elem = vidhand->maskdef_elem; maskdef_elem != NULL; maskdef_elem = maskdef_elem->next)
{
if(strcmp(maskdef_elem->mask_name, mask_name) == 0)
{
return(maskdef_elem);
}
}
return (NULL);
} /* end p_find_maskdef_by_name */
/* ----------------------------------------------------
* p_mask_image_fetcher
* ----------------------------------------------------
* fetch specified mask frame as gray image with only one composite layer.
* if the mask definition is not found,
* then deliver -1.
* if the mask definition has less frames than master_frame_nr, then deliver the
* last available frame as mask.
* return the image id.
*/
static gint32
p_mask_fetcher(GapStoryRenderVidHandle *vidhand
, const char *mask_name
, gint32 master_frame_nr
, gint32 mask_width
, gint32 mask_height
, gint32 *layer_id_ptr /* OUT: Id of the only layer in the composite image */
, gboolean *was_last_maskframe /* OUT: true if this was the last maskframe */
)
{
GapStoryRenderMaskDefElem *maskdef_elem;
gint32 image_id;
*was_last_maskframe = FALSE;
image_id = -1;
maskdef_elem = p_find_maskdef_by_name(vidhand, mask_name);
if(maskdef_elem == NULL)
{
printf("\n** Error MASK fetch could not find maskdef_elem (== NULL) MASK: %s IGNORED\n"
, mask_name);
}
else
{
gint32 l_framenr;
/* limit access to last available frame */
l_framenr = MIN(master_frame_nr, maskdef_elem->frame_count);
if(gap_debug)
{
printf("\n############# MASK start FETCH ##########\n");
printf("MASK relevant framenr:%d\n"
, (int)l_framenr
);
gap_story_render_debug_print_maskdef_elem(maskdef_elem, -7);
}
/* the composite image fecther already converts to gray when called
* with a mask videohandle (marked with is_mask_handle flag)
*/
image_id = p_story_render_fetch_composite_image_private(maskdef_elem->mask_vidhand
, l_framenr /* starts at 1 */
, mask_width /* desired Width in pixels */
, mask_height /* desired Height in pixels */
, NULL /* NULL if no filtermacro is used */
, layer_id_ptr /* OUT: Id of the only layer in the composite image */
, NULL /* each mask has its own mask_vidhand where
* the elements are in main section (section_name = NULL)
*/
);
if(gap_debug)
{
printf("\n.........#### MASK end FETCH ####......\n");
}
*layer_id_ptr = gap_layer_flip(*layer_id_ptr, maskdef_elem->flip_request);
if(gimp_drawable_has_alpha(*layer_id_ptr))
{
*layer_id_ptr = gimp_image_flatten(image_id);
}
if(gap_debug)
{
printf("p_mask_fetcher: flip_request:%d\n"
,(int)maskdef_elem->flip_request
);
}
if (l_framenr == maskdef_elem->frame_count)
{
*was_last_maskframe = TRUE;
}
}
return(image_id);
} /* end p_mask_fetcher */
/* ----------------------------------------------------
* p_fetch_and_add_layermask
* ----------------------------------------------------
*/
static void
p_fetch_and_add_layermask(GapStoryRenderVidHandle *vidhand
, GapStoryRenderFrameRangeElem *frn_elem
, gint32 local_stepcount
, gint32 image_id
, gint32 layer_id
)
{
gint32 l_tmp_mask_image_id;
gint32 l_tmp_mask_layer_id;
gint32 l_master_framenr;
gdouble l_framenr;
gboolean l_found_in_cache;
gboolean l_was_last_maskframe;
/* both local_stepcount and mask_framecount start with 0 for the 1st element */
l_framenr = frn_elem->mask_stepsize * (gdouble)(frn_elem->mask_framecount + local_stepcount);
l_master_framenr = 1 + (gint32)(l_framenr);
if(gap_debug)
{
printf("\n============--------------====\n");
printf("p_fetch_and_add_layermask: local_stepcount: %d master_framenr:%d\n"
,(int)local_stepcount
,(int)l_master_framenr
);
gap_story_render_debug_print_frame_elem(frn_elem, -5);
}
l_found_in_cache = FALSE;
// l_tmp_mask_image_id = TODO lookup in the cache ################
if(l_found_in_cache)
{
if(gap_debug)
{
printf("FOUND MASK in cache: mask_name:%s master_framenr:%d\n"
,frn_elem->mask_name
,(int)l_master_framenr
);
}
}
else
{
l_tmp_mask_image_id = p_mask_fetcher(vidhand
, frn_elem->mask_name
, l_master_framenr
, gimp_drawable_width(layer_id)
, gimp_drawable_height(layer_id)
,&l_tmp_mask_layer_id
,&l_was_last_maskframe
);
}
if(gap_debug)
{
printf("MASK image_id: %d l_tmp_mask_layer_id:%d\n"
,(int)l_tmp_mask_image_id
,(int)l_tmp_mask_layer_id
);
}
if(l_tmp_mask_image_id >= 0)
{
gint32 l_new_layer_mask_id;
if(1==0)
{
p_debug_dup_image(l_tmp_mask_image_id);
}
/* add aplha channel if necessary
* (this is required to allow adding the layermask
*/
if(!gimp_drawable_has_alpha(layer_id))
{
gimp_layer_add_alpha(layer_id);
}
l_new_layer_mask_id = gimp_layer_create_mask(layer_id, GIMP_ADD_WHITE_MASK);
gimp_layer_add_mask(layer_id, l_new_layer_mask_id);
/* overwrite the white layer mask with the fetched mask */
gap_layer_copy_content(l_new_layer_mask_id /* dst_drawable_id */
,l_tmp_mask_layer_id /* src_drawable_id */
);
if(!l_found_in_cache)
{
// TODO: decide if l_tmp_mask_image_id should be stored in cache or to delete immediate.
// store if:
// - there are more than one references
// - if mask stepsize < 1.0
// - the last frame of the mask sequence (l_framenr == maskdef_elem->frame_count)
// (that has to be repeated for all remaining frame in the clip)
// if((frn_elem->mask_stepsize < 1.0)
// || (l_was_last_maskframe)
// )
gap_image_delete_immediate(l_tmp_mask_image_id);
}
}
} /* end p_fetch_and_add_layermask */
/* ----------------------------------------------------
* p_open_video_handle_private
* ----------------------------------------------------
* this procedure builds a framerange list from
* the given storyboard file.
* if NULL is passed as storyboard_file
* the list is built with just one entry.
* from basename and ext parameters.
*
* return framerange list
*/
static GapStoryRenderVidHandle *
p_open_video_handle_private( gboolean ignore_audio
, gboolean ignore_video
, gboolean create_audio_tmp_files
, gdouble *progress_ptr
, char *status_msg
, gint32 status_msg_len
, const char *storyboard_file
, const char *basename
, const char *ext
, gint32 frame_from
, gint32 frame_to
, gint32 *frame_count /* output total frame_count , or 0 on failure */
, gboolean do_gimp_progress
, GapLibTypeInputRange input_mode
, const char *imagename
, const char *preferred_decoder
, gint32 seltrack
, gint32 exact_seek
, gdouble delace
, gboolean compensate_framerange
, GapStoryBoard *stb_mem_ptr
)
{
GapStoryRenderVidHandle *vidhand;
GapStoryRenderSection *render_section;
GapStoryRenderFrameRangeElem *frn_elem;
vidhand = g_malloc0(sizeof(GapStoryRenderVidHandle));
render_section = NULL;
if(gap_debug)
{
printf("p_open_video_handle_private: new vidhand:%d\n", (int)vidhand);
}
if(progress_ptr) { vidhand->progress = progress_ptr; }
else { vidhand->progress = &vidhand->dummy_progress; }
if(status_msg)
{
vidhand->status_msg = status_msg;
vidhand->status_msg_len = status_msg_len;
}
else
{
vidhand->status_msg = NULL;
vidhand->status_msg_len = 0;
}
/* registrate as user of the frame fetcher resources (e.g. the image cache) */
vidhand->ffetch_user_id = gap_frame_fetch_register_user("gap_story_render_processor.p_open_video_handle_private");
vidhand->frn_list = NULL;
vidhand->preferred_decoder = NULL;
vidhand->master_insert_area_format = NULL;
vidhand->master_insert_area_format_has_videobasename = FALSE;
vidhand->master_insert_area_format_has_framenumber = FALSE;
vidhand->do_gimp_progress = do_gimp_progress;
*vidhand->progress = 0.0;
vidhand->sterr = p_new_stb_error();
vidhand->master_framerate = 25.0;
vidhand->master_width = 0;
vidhand->master_height = 0;
vidhand->master_samplerate = 44100; /* 44.1 kHZ CD standard Quality */
vidhand->master_volume = 1.0;
vidhand->util_sox = NULL; /* use DEFAULT resample program (sox), where needed */
vidhand->util_sox_options = NULL; /* use DEFAULT options */
vidhand->ignore_audio = ignore_audio;
vidhand->ignore_video = ignore_video;
vidhand->create_audio_tmp_files = create_audio_tmp_files;
vidhand->maskdef_elem = NULL;
vidhand->is_mask_handle = FALSE;
vidhand->parsing_section = NULL;
vidhand->section_list = NULL;
global_monitor_image_id = -1;
*frame_count = 0;
if((storyboard_file) && (input_mode == GAP_RNGTYPE_STORYBOARD))
{
if(*storyboard_file != '\0')
{
vidhand->frn_list = p_framerange_list_from_storyboard(storyboard_file
, frame_count
, vidhand
, stb_mem_ptr);
}
render_section = vidhand->section_list;
}
if (vidhand->section_list == NULL)
{
/* make sure that the video handle always has a main section
* with section Name NULL.
* (this can occure if not directly created from a storyboard
* or when creating sub video handle for mask processing)
*/
vidhand->section_list = p_new_render_section(NULL);
vidhand->parsing_section = vidhand->section_list;
render_section = vidhand->section_list;
if(gap_debug)
{
printf("p_open_video_handle_private: added default MAIN render_section\n");
}
}
if(gap_debug)
{
printf("p_open_video_handle_private: OPENING vidhand:%d\n"
, (int)vidhand
);
p_debug_print_render_section_names(vidhand);
}
if((render_section->frn_list == NULL)
&& (input_mode == GAP_RNGTYPE_LAYER)
&& (imagename))
{
gint32 l_from;
gint32 l_to;
l_from = frame_from;
l_to = frame_to;
if(compensate_framerange)
{
/* layerindex starts with 0, but master_index should start with 1
* increment by 1 to compensate. (only needed for single multilayer image encoding)
*/
l_from = 1;
l_to = 1+ MAX(frame_to, frame_from);
}
/* add element for animimage (one multilayer image) */
frn_elem = p_new_framerange_element(GAP_FRN_ANIMIMAGE
, 1 /* track */
, imagename
, NULL
, l_from
, l_to
, NULL /* storyboard_file */
, NULL /* preferred_decoder */
, NULL /* filtermacro_file */
, NULL /* frn_list */
, vidhand->sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
if(frn_elem)
{
*frame_count = frn_elem->frames_to_handle;
}
if(compensate_framerange)
{
/* add a layer 0 (as separate 1.st listelement)
* to compensate framenumbers if the range does not start with 1
*/
render_section->frn_list = p_new_framerange_element(GAP_FRN_ANIMIMAGE
, 1 /* track */
, imagename
, NULL
, 1 /* from */
, 1 /* to */
, NULL /* storyboard_file */
, NULL /* preferred_decoder */
, NULL /* filtermacro_file */
, NULL /* frn_list */
, vidhand->sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
render_section->frn_list->frames_to_handle = l_from -1;
render_section->frn_list->next = frn_elem;
if(gap_debug)
{
printf("***************************\n");
printf("COMPENSATE LAYERS (ANIMIMAGE):\n");
gap_story_render_debug_print_framerange_list(render_section->frn_list , -1);
printf("***************************\n");
}
}
else
{
render_section->frn_list = frn_elem;
}
}
if((render_section->frn_list == NULL)
&& (basename)
&& (ext))
{
gint32 l_from;
gint32 l_to;
l_from = frame_from;
l_to = frame_to;
if(compensate_framerange)
{
/* layerindex starts with 0, but master_index should start with 1
* increment by 1 to compensate. (only needed for single multilayer image encoding)
*/
l_from = MIN(frame_from, frame_to);
l_to = MAX(frame_to, frame_from);
}
if(input_mode == GAP_RNGTYPE_FRAMES)
{
/* element for framerange */
frn_elem = p_new_framerange_element(GAP_FRN_FRAMES
, 1 /* track */
, basename
, ext
, l_from
, l_to
, NULL /* storyboard_file */
, NULL /* preferred_decoder */
, NULL /* filtermacro_file */
, NULL /* frn_list */
, vidhand->sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
if(frn_elem) *frame_count = frn_elem->frames_to_handle;
if(compensate_framerange)
{
/* add a SILENCE dummy (as 1.st listelement)
* to compensate framenumbers if the range does not start with 1
*/
render_section->frn_list = p_new_framerange_element(GAP_FRN_SILENCE
, 1 /* track */
, NULL
, NULL
, 0 /* frame_from */
, l_from -1 /* frame_to */
, NULL /* storyboard_file */
, NULL /* preferred_decoder */
, NULL /* filtermacro_file */
, NULL /* frn_list */
, vidhand->sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
render_section->frn_list->frames_to_handle = l_from -1;
render_section->frn_list->next = frn_elem;
if(gap_debug)
{
printf("***************************\n");
printf("COMPENSATE FRAMES:\n");
gap_story_render_debug_print_framerange_list(render_section->frn_list , -1);
printf("***************************\n");
}
}
else
{
render_section->frn_list = frn_elem;
}
}
}
if((render_section->frn_list == NULL)
&& (input_mode == GAP_RNGTYPE_IMAGE)
&& (imagename))
{
/* add element for single image
* (typical used only for mask definitions)
*/
frn_elem = p_new_framerange_element(GAP_FRN_IMAGE
, 1 /* track */
, imagename
, NULL
, 1 /* frame_from */
, 1 /* frame_to */
, NULL /* storyboard_file */
, NULL /* preferred_decoder */
, NULL /* filtermacro_file */
, NULL /* frn_list */
, vidhand->sterr
, 1 /* seltrack */
, 0 /* exact_seek*/
, 0.0 /* delace */
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
if(frn_elem)
{
*frame_count = frn_elem->frames_to_handle;
}
render_section->frn_list = frn_elem;
}
if((render_section->frn_list == NULL)
&& (input_mode == GAP_RNGTYPE_MOVIE)
&& (imagename))
{
/* add element for single movie input
* (typical used only for mask definitions)
*/
frn_elem = p_new_framerange_element(GAP_FRN_MOVIE
, 1 /* track */
, imagename
, NULL
, frame_from
, frame_to
, NULL /* storyboard_file */
, preferred_decoder
, NULL /* filtermacro_file */
, NULL /* frn_list */
, vidhand->sterr
, seltrack
, exact_seek
, delace
, 1.0 /* step_density */
, GAP_STB_FLIP_NONE /* flip_request */
, NULL /* mask_name */
, 1.0 /* mask_stepsize */
, GAP_MSK_ANCHOR_CLIP /* mask_anchor */
, TRUE /* mask_disable */
, 1 /* fmac_total_steps */
);
if(frn_elem)
{
*frame_count = frn_elem->frames_to_handle;
}
render_section->frn_list = frn_elem;
}
/* select MAIN section (has section_name NULL) per default */
p_select_section_by_name(vidhand, NULL);
/* p_free_stb_error(vidhand->sterr); */
if(gap_debug)
{
printf("\n\np_open_video_handle_private: END vidhand:%d\n\n", (int)vidhand);
gap_story_render_debug_print_framerange_list(vidhand->frn_list, -1);
}
return(vidhand);
} /* end p_open_video_handle_private */
/* ----------------------------------------------------
* gap_story_render_open_extended_video_handle
* ----------------------------------------------------
* this procedure builds a framerange list from
* the given storyboard file.
* if NULL is passed as storyboard_file
* the list is built with just one entry.
* from basename and ext parameters.
*
* return framerange list
*/
GapStoryRenderVidHandle *
gap_story_render_open_extended_video_handle( gboolean ignore_audio
, gboolean ignore_video
, gboolean create_audio_tmp_files
, gdouble *progress_ptr
, char *status_msg
, gint32 status_msg_len
, GapLibTypeInputRange input_mode
, const char *imagename
, const char *storyboard_file
, const char *basename
, const char *ext
, gint32 frame_from
, gint32 frame_to
, gint32 *frame_count /* output total frame_count , or 0 on failure */
)
{
return(p_open_video_handle_private( ignore_audio /* ignore_audio */
, ignore_video /* dont ignore_video */
, create_audio_tmp_files
, progress_ptr /* progress_ptr */
, status_msg /* status_msg */
, status_msg_len /* status_msg_len */
,storyboard_file
,basename
,ext
,frame_from
,frame_to
,frame_count
,FALSE /* DONT do_gimp_progress */
,input_mode
,imagename
,NULL /* preferred_decoder */
,1 /* seltrack */
,0 /* exact_seek */
,0.0 /* delace */
,TRUE /* compensate_framerange */
,NULL /* stb_mem_ptr */
)
);
} /* end gap_story_render_open_extended_video_handle */
/* ----------------------------------------------------
* gap_story_render_open_vid_handle_from_stb
* ----------------------------------------------------
* this procedure builds a framerange list from
* the given storyboard in MEMORY.
*
* this wrapper to p_open_video_handle
* ignores AUDIO informations in the storyboard file
* (Typically the Player uses this variant
* for playback of composite storyboard video)
*
* return the video handle
*/
GapStoryRenderVidHandle *
gap_story_render_open_vid_handle_from_stb(GapStoryBoard *stb_mem_ptr
,gint32 *frame_count /* output total frame_count , or 0 on failure */
)
{
GapStoryRenderVidHandle *l_vidhand;
l_vidhand = NULL;
if(stb_mem_ptr)
{
l_vidhand = p_open_video_handle_private( TRUE /* ignore_audio */
, FALSE /* dont ignore_video */
, FALSE /* create_audio_tmp_files */
, NULL /* progress_ptr */
, NULL /* status_msg */
, 0 /* status_msg_len */
,stb_mem_ptr->storyboardfile
, NULL /* basename */
, NULL /* ext */
,1 /* frame_from (not relevant) */
,1 /* frame_to (not relevant) */
,frame_count
,FALSE /* do_gimp_progress */
,GAP_RNGTYPE_STORYBOARD /* input_mode */
,NULL /* imagename */
,NULL /* preferred_decoder */
,1 /* seltrack */
,0 /* exact_seek */
,0.0 /* delace */
,TRUE /* compensate_framerange */
,stb_mem_ptr /* stb_mem_ptr */
);
}
return(l_vidhand);
} /* end gap_story_render_open_vid_handle_from_stb */
/* ----------------------------------------------------
* gap_story_render_open_vid_handle
* ----------------------------------------------------
* this procedure builds a framerange list from
* the given storyboard file.
* if NULL is passed as storyboard_file
* the list is built with just one entry
* from basename and ext parameters.
*
* this wrapper to p_open_video_handle
* ignores AUDIO informations in the storyboard file
* (The encoders use this variant
* because the common GUI usually creates
* the composite audio track, and passes
* the resulting WAV file ready to use)
*
* return the video handle
*/
GapStoryRenderVidHandle *
gap_story_render_open_vid_handle(GapLibTypeInputRange input_mode
, gint32 image_id
, const char *storyboard_file
, const char *basename
, const char *ext
, gint32 frame_from
, gint32 frame_to
, gint32 *frame_count /* output total frame_count , or 0 on failure */
)
{
GapStoryRenderVidHandle *l_vidhand;
char *imagename;
imagename = NULL;
if(image_id >= 0)
{
imagename = gimp_image_get_filename(image_id);
}
l_vidhand = p_open_video_handle_private( TRUE /* ignore_audio */
, FALSE /* dont ignore_video */
, FALSE /* create_audio_tmp_files */
, NULL /* progress_ptr */
, NULL /* status_msg */
, 0 /* status_msg_len */
,storyboard_file
,basename
,ext
,frame_from
,frame_to
,frame_count
,TRUE /* do_gimp_progress */
,input_mode
,imagename
,NULL /* preferred_decoder */
,1 /* seltrack */
,0 /* exact_seek */
,0.0 /* delace */
,TRUE /* compensate_framerange */
,NULL /* stb_mem_ptr */
);
if(imagename)
{
g_free(imagename);
}
return(l_vidhand);
}
/* ----------------------------------------------------
* p_exec_filtermacro
* ----------------------------------------------------
* - execute the (optional) filtermacro_file if not NULL
* (filtermacro_file is a set of one or more gimp_filter procedures
* with predefined parameter values)
*/
static gint32
p_exec_filtermacro(gint32 image_id, gint32 layer_id, const char *filtermacro_file
, const char *filtermacro_file_to
, gdouble current_step
, gint32 total_steps
)
{
GimpParam* l_params;
gint l_retvals;
gint32 l_rc_layer_id;
gint l_nlayers;
gint32 *l_layers_list;
l_rc_layer_id = layer_id;
if (filtermacro_file)
{
if(*filtermacro_file != '\0')
{
if(gap_debug)
{
printf("DEBUG: before execute filtermacro_file:%s image_id:%d layer_id:%d current:%f total:%d\n"
, filtermacro_file
, (int)image_id
, (int)layer_id
, (float)current_step
, (int)total_steps
);
}
if(! gimp_drawable_has_alpha (layer_id))
{
/* some filtermacros do not work with layer that do not have an alpha channel
* and cause gimp to fail on attempt to call gimp_pixel_rgn_init
* with both dirty and shadow flag set to TRUE
* in this situation GIMP displays the error message
* "expected tile ack and received: 5"
* and causes the called plug-in to exit immediate without success
* Therfore always add an alpha channel before calling a filtermacro.
*/
gimp_layer_add_alpha(layer_id);
}
if((filtermacro_file_to == NULL)
|| (total_steps <= 1))
{
/* execute simple GAP Filtermacro_file */
l_params = gimp_run_procedure (GAP_FMACNAME_PLUG_IN_NAME_FMAC,
&l_retvals,
GIMP_PDB_INT32, GIMP_RUN_NONINTERACTIVE,
GIMP_PDB_IMAGE, image_id,
GIMP_PDB_DRAWABLE, layer_id,
GIMP_PDB_STRING, filtermacro_file,
GIMP_PDB_END);
}
else
{
if(current_step > total_steps)
{
current_step = total_steps;
}
if(current_step < 0.0)
{
current_step = 0.0;
}
/* execute varying value mix of 2 GAP Filtermacro_files */
l_params = gimp_run_procedure (GAP_FMACNAME_PLUG_IN_NAME_FMAC_VARYING,
&l_retvals,
GIMP_PDB_INT32, GIMP_RUN_NONINTERACTIVE,
GIMP_PDB_IMAGE, image_id,
GIMP_PDB_DRAWABLE, layer_id,
GIMP_PDB_STRING, filtermacro_file,
GIMP_PDB_STRING, filtermacro_file_to,
GIMP_PDB_FLOAT, current_step, /* 0.0 upto 1.0 */
GIMP_PDB_INT32, total_steps,
GIMP_PDB_END);
}
if(l_params[0].data.d_status != GIMP_PDB_SUCCESS)
{
printf("ERROR: filtermacro_file:%s failed\n", filtermacro_file);
l_rc_layer_id = -1;
}
g_free(l_params);
l_layers_list = gimp_image_get_layers(image_id, &l_nlayers);
if(l_layers_list != NULL)
{
g_free (l_layers_list);
}
if(l_nlayers > 1 )
{
/* merge visible layers (reduce to single layer) */
l_rc_layer_id = gap_image_merge_visible_layers(image_id, GIMP_CLIP_TO_IMAGE);
}
}
}
return(l_rc_layer_id);
} /* end p_exec_filtermacro */
/* ----------------------------------------------------
* p_transform_and_add_layer
* ----------------------------------------------------
* - copy the layer (layer_id) to the composite image
* using copy/paste
* - the source Layer (layer_id) must be part of tmp_image_id
* - set opacity, scale and move layer_id according to video attributes
*
* return the new created layer id in the comp_image_id
* (that is already added to the composte image on top of layerstack)
*/
static gint32
p_transform_and_add_layer( gint32 comp_image_id
, gint32 tmp_image_id
, gint32 layer_id
, gboolean keep_proportions
, gboolean fit_width
, gboolean fit_height
, gdouble opacity /* 0.0 upto 1.0 */
, gdouble scale_x /* 0.0 upto 10.0 where 1.0 = 1:1 */
, gdouble scale_y /* 0.0 upto 10.0 where 1.0 = 1:1 */
, gdouble move_x /* -1.0 upto +1.0 where 0 = no move, -1 is left outside */
, gdouble move_y /* -1.0 upto +1.0 where 0 = no move, -1 is top outside */
, char *filtermacro_file
, gint32 flip_request
, GapStoryRenderFrameRangeElem *frn_elem
, GapStoryRenderVidHandle *vidhand
, gint32 local_stepcount
)
{
gint32 vid_width;
gint32 vid_height;
gint32 l_new_layer_id;
gint32 l_fsel_layer_id;
GapStoryCalcAttr calculate_attributes;
GapStoryCalcAttr *calculated;
if(gap_debug)
{
printf("p_transform_and_add_layer: called at layer_id: %d, tmp_image_id:%d\n"
, (int)layer_id
,(int)tmp_image_id );
gap_story_render_debug_print_frame_elem(frn_elem, -77);
}
/* execute input track specific filtermacro (optional if supplied)
* local_stepcount (usually delivered by procedure p_fetch_framename)
* is used to define fmac_current_step
* (starts at 0)
*/
p_exec_filtermacro(tmp_image_id
, layer_id
, filtermacro_file
, frn_elem->filtermacro_file_to
, (gdouble)(local_stepcount) /* fmac_current_step */
, frn_elem->fmac_total_steps
);
if(gap_debug)
{
printf("p_transform_and_add_layer: FILTERMACRO DONE at layer_id: %d, tmp_image_id:%d\n"
, (int)layer_id
,(int)tmp_image_id );
}
layer_id = gap_layer_flip(layer_id, flip_request);
/* expand layer to tmp image size (before applying any scaling) */
gimp_layer_resize_to_image_size(layer_id);
vid_width = gimp_image_width(comp_image_id);
vid_height = gimp_image_height(comp_image_id);
/* calculate scaling, offsets and opacity according to current attributes */
gap_story_file_calculate_render_attributes(&calculate_attributes
, vid_width
, vid_height
, vid_width
, vid_height
, gimp_image_width(tmp_image_id)
, gimp_image_height(tmp_image_id)
, keep_proportions
, fit_width
, fit_height
, opacity
, scale_x
, scale_y
, move_x
, move_y
);
calculated = &calculate_attributes;
/* check size and scale source layer_id to calculated size
*/
if ((gimp_image_width(tmp_image_id) != calculated->width)
|| (gimp_image_height(tmp_image_id) != calculated->height) )
{
if(gap_debug)
{
printf("DEBUG: p_transform_and_add_layer scaling layer from %dx%d to %dx%d\n"
, (int)gimp_image_width(tmp_image_id)
, (int)gimp_image_height(tmp_image_id)
, (int)calculated->width
, (int)calculated->height
);
}
gimp_layer_scale(layer_id, calculated->width, calculated->height
, FALSE /* FALSE: centered at image TRUE: centered local on layer */
);
}
/* add a new layer to composite image */
l_new_layer_id = gimp_layer_new(comp_image_id
, "pasted_track"
, vid_width
, vid_height
, GIMP_RGBA_IMAGE
, 0.0 /* Opacity full transparent */
,GIMP_NORMAL_MODE);
gimp_image_add_layer(comp_image_id, l_new_layer_id, 0);
gap_layer_clear_to_color(l_new_layer_id, 0.0, 0.0, 0.0, 0.0);
if((frn_elem->mask_name != NULL)
&& (frn_elem->mask_anchor == GAP_MSK_ANCHOR_CLIP))
{
p_fetch_and_add_layermask(vidhand
, frn_elem
, local_stepcount
, tmp_image_id
, layer_id
);
/* apply the mask (necessary because the following copy with this layer
* as source would ignore the layer mask)
*/
gimp_layer_remove_mask(layer_id, GIMP_MASK_APPLY);
}
/* copy from tmp_image and paste to composite_image
* force copying of the complete layer by clearing the selection
*/
gimp_selection_none(tmp_image_id);
gimp_edit_copy(layer_id);
l_fsel_layer_id = gimp_edit_paste(l_new_layer_id, FALSE); /* FALSE paste clear selection */
gimp_layer_set_offsets(l_fsel_layer_id
, calculated->x_offs
, calculated->y_offs
);
gimp_floating_sel_anchor(l_fsel_layer_id);
if((frn_elem->mask_name != NULL)
&& (frn_elem->mask_anchor == GAP_MSK_ANCHOR_MASTER))
{
p_fetch_and_add_layermask(vidhand
, frn_elem
, local_stepcount
, comp_image_id
, l_new_layer_id
);
}
gimp_layer_set_opacity(l_new_layer_id, calculated->opacity);
return(l_new_layer_id);
} /* end p_transform_and_add_layer */
/* ----------------------------------------------------
* p_create_unicolor_image
* ----------------------------------------------------
* - create a new image with one black filled layer
* (both have the requested size)
*
* return the new created image_id
* and the layer_id of the black_layer
*/
static gint32
p_create_unicolor_image(gint32 *layer_id, gint32 width , gint32 height
, gdouble r_f, gdouble g_f, gdouble b_f, gdouble a_f)
{
gint32 l_empty_layer_id;
gint32 l_image_id;
*layer_id = -1;
l_image_id = gimp_image_new(width, height, GIMP_RGB);
if(l_image_id >= 0)
{
l_empty_layer_id = gimp_layer_new(l_image_id, "black_background",
width, height,
GIMP_RGBA_IMAGE,
100.0, /* Opacity full opaque */
GIMP_NORMAL_MODE);
gimp_image_add_layer(l_image_id, l_empty_layer_id, 0);
/* clear layer to unique color */
gap_layer_clear_to_color(l_empty_layer_id, r_f, g_f, b_f, a_f);
*layer_id = l_empty_layer_id;
}
return(l_image_id);
} /* end p_create_unicolor_image */
/* ----------------------------------------------------
* p_prepare_RGB_image
* ----------------------------------------------------
* prepare image for encoding
* - clear undo stack
* - convert to RGB
* - merge all visible layer to one layer that
* fits the image size.
*
* return the resulting layer_id.
*/
static gint32
p_prepare_RGB_image(gint32 image_id)
{
gint l_nlayers;
gint32 *l_layers_list;
gint32 l_layer_id;
l_layer_id = -1;
/* dont waste time and memory for undo in noninteracive processing
* of the frames
*/
/* gimp_image_undo_enable(image_id); */ /* clear undo stack */
/* no more gimp_image_undo_enable, because this results in Warnings since gimp-2.1.6
* Gimp-Core-CRITICAL **: file gimpimage.c: line 1708 (gimp_image_undo_thaw): assertion `gimage->undo_freeze_count > 0' failed
*/
gimp_image_undo_disable(image_id); /* NO Undo */
l_layers_list = gimp_image_get_layers(image_id, &l_nlayers);
if(l_layers_list != NULL)
{
l_layer_id = l_layers_list[0];
g_free (l_layers_list);
}
if((l_nlayers > 1 ) || (gimp_layer_get_mask (l_layer_id) >= 0))
{
if(gap_debug) printf("DEBUG: p_prepare_image merge layers tmp image\n");
/* merge visible layers (reduce to single layer) */
l_layer_id = gap_image_merge_visible_layers(image_id, GIMP_CLIP_TO_IMAGE);
}
/* convert TO RGB if needed */
if(gimp_image_base_type(image_id) != GIMP_RGB)
{
gimp_image_convert_rgb(image_id);
}
if(l_layer_id >= 0)
{
gimp_layer_resize_to_image_size(l_layer_id);
}
return(l_layer_id);
} /* end p_prepare_RGB_image */
/* ----------------------------------------------------
* p_limit_open_videohandles
* ----------------------------------------------------
* if the number of currently_open_videohandles exceeds a limit,
* then try to close the handle(s) until the number is below the limit.
* (but do not close handles that are involved in fetching the current master_frame_nr)
*
* This kind of garbage collection is useful for storyboards that are using many
* different videofile references and would run into memory and other resource problems
* when all handles are kept open until the end of rendering process.
* (note that each video handle has its own frame cache)
*/
static void
p_limit_open_videohandles(GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, gint32 currently_open_videohandles
)
{
#ifdef GAP_ENABLE_VIDEOAPI_SUPPORT
#define GAP_STB_DEFAULT_MAX_OPEN_VIDEOFILES 12
GapStoryRenderFrameRangeElem *frn_elem;
gint32 l_count_open_videohandles;
gint32 l_max_open_videohandles;
l_max_open_videohandles = gap_base_get_gimprc_int_value("video-storyboard-max-open-videofiles"
, GAP_STB_DEFAULT_MAX_OPEN_VIDEOFILES
, 2
, 100
);
l_count_open_videohandles = currently_open_videohandles;
if (l_count_open_videohandles <= l_max_open_videohandles)
{
/* we are below the limit, nothing left to do in that case */
return;
}
for (frn_elem = vidhand->frn_list; frn_elem != NULL; frn_elem = (GapStoryRenderFrameRangeElem *)frn_elem->next)
{
if((frn_elem->last_master_frame_access < master_frame_nr)
&& (frn_elem->gvahand != NULL))
{
if(gap_debug)
{
printf("too many open videofiles %d detected (limit:%d) at master_frame_nr:%d\n"
" CLOSING GVA handle for video read access %s\n"
, (int)l_count_open_videohandles
, (int)l_max_open_videohandles
, (int)master_frame_nr
, frn_elem->basename
);
}
GVA_close(frn_elem->gvahand);
frn_elem->gvahand = NULL;
l_count_open_videohandles--;
if (l_count_open_videohandles <= l_max_open_videohandles)
{
return;
}
}
}
#endif
return;
} /* end p_limit_open_videohandles */
/* ----------------------------------------------------
* p_try_to_steal_gvahand
* ----------------------------------------------------
* try to steal an alread open GVA handle for video read from another
* element.
* conditions: must use same videofile, and exact_seek mode
* but steal only handles that are not in current access
* (where the last accessed master_frame_nr is lower
* than the current one)
*/
static t_GVA_Handle *
p_try_to_steal_gvahand(GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, char *basename /* the videofile name */
, gint32 exact_seek
)
{
#ifdef GAP_ENABLE_VIDEOAPI_SUPPORT
GapStoryRenderFrameRangeElem *frn_elem;
gint32 l_count_open_videohandles;
l_count_open_videohandles = 0;
for (frn_elem = vidhand->frn_list; frn_elem != NULL; frn_elem = (GapStoryRenderFrameRangeElem *)frn_elem->next)
{
if (frn_elem->gvahand != NULL)
{
l_count_open_videohandles++;
}
if((frn_elem->exact_seek == exact_seek)
&& (frn_elem->last_master_frame_access < master_frame_nr)
&& (frn_elem->gvahand != NULL))
{
if(strcmp(frn_elem->basename, basename) == 0)
{
t_GVA_Handle *gvahand;
if(gap_debug)
{
printf("(RE)using an already open GVA handle for video read access %s\n"
, frn_elem->basename
);
}
gvahand = frn_elem->gvahand;
frn_elem->gvahand = NULL; /* steal from this element */
return(gvahand);
}
}
}
p_limit_open_videohandles(vidhand, master_frame_nr, l_count_open_videohandles);
#endif
return(NULL); /* nothing found to steal from, return NULL */
} /* end p_try_to_steal_gvahand */
/* ------------------------------------
* gap_story_render_calc_audio_playtime
* ------------------------------------
* - check all audio tracks for audio playtime
* set *aud_total_sec to the playtime of the
* logest audio track playtime.
*/
void
gap_story_render_calc_audio_playtime(GapStoryRenderVidHandle *vidhand, gdouble *aud_total_sec)
{
gap_story_render_audio_calculate_playtime(vidhand, aud_total_sec);
} /* gap_story_render_calc_audio_playtime */
/* -------------------------------------------
* gap_story_render_create_composite_audiofile
* -------------------------------------------
*/
gboolean
gap_story_render_create_composite_audiofile(GapStoryRenderVidHandle *vidhand
, char *comp_audiofile
)
{
return (gap_story_render_audio_create_composite_audiofile(vidhand, comp_audiofile));
} /* end gap_story_render_create_composite_audiofile */
/* --------------------------------------------
* gap_story_convert_layer_to_RGB_thdata
* --------------------------------------------
* convert the specified gimp drawable to thdata Buffer
* (Bytesequence RGB 8)
* if the drawable is a gray image it is converted
* to RGB (red, green and blue are set to the same value).
*/
guchar *
gap_story_convert_layer_to_RGB_thdata(gint32 layer_id, gint32 *RAW_size
, gint32 *th_bpp
, gint32 *th_width
, gint32 *th_height
)
{
GimpDrawable *drawable;
GimpPixelRgn pixel_rgn;
GimpImageType drawable_type;
guchar *RAW_data;
guchar *RAW_ptr;
guchar *pixelrow_data;
guint l_row;
gint32 l_idx;
gint32 l_blue;
gint32 l_green;
gint32 l_red;
gint32 l_rowstride;
drawable = gimp_drawable_get (layer_id);
drawable_type = gimp_drawable_type (drawable->drawable_id);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, drawable->width, drawable->height, FALSE, FALSE);
l_rowstride = drawable->width * drawable->bpp;
pixelrow_data = (guchar *)g_malloc0(l_rowstride);
*RAW_size = drawable->width * drawable->height * 3;
*th_bpp = 3;
*th_width = drawable->width;
*th_height = drawable->height;
RAW_data = (guchar *)g_malloc0((drawable->width * drawable->height * 3));
RAW_ptr = RAW_data;
l_red = 0;
l_green = 1;
l_blue = 2;
if((drawable_type == GIMP_GRAY_IMAGE)
|| (drawable_type == GIMP_GRAYA_IMAGE))
{
l_green = 0;
l_blue = 0;
}
for(l_row = 0; l_row < drawable->height; l_row++)
{
gint32 l_src_row;
l_src_row = l_row;
gimp_pixel_rgn_get_rect (&pixel_rgn, pixelrow_data
, 0
, l_src_row
, drawable->width
, 1);
for(l_idx=0;l_idx < l_rowstride; l_idx += drawable->bpp)
{
*(RAW_ptr++) = pixelrow_data[l_idx + l_red];
*(RAW_ptr++) = pixelrow_data[l_idx + l_green];
*(RAW_ptr++) = pixelrow_data[l_idx + l_blue];
}
}
g_free(pixelrow_data);
return(RAW_data);
} /* end gap_story_convert_layer_to_RGB_thdata */
/* ---------------------------------------
* gap_story_render_fetch_composite_vthumb
* ---------------------------------------
* render composite image and convert
* to (RGB 8) thumbdata.
*/
guchar *
gap_story_render_fetch_composite_vthumb(GapStoryRenderVidHandle *stb_comp_vidhand
, gint32 framenumber
, gint32 width, gint32 height
)
{
gint32 composite_image_id;
gint32 l_layer_id;
guchar *th_data;
if(gap_debug)
{
printf("\n###\n###\nSTART VTHUMB rendering at master_frame_nr %d"
" with this list of elements:\n"
,(int)framenumber
);
gap_story_render_debug_print_framerange_list(stb_comp_vidhand->frn_list, -1);
}
th_data = NULL;
composite_image_id = gap_story_render_fetch_composite_image(
stb_comp_vidhand
, framenumber
, width
, height
, NULL /* filtermacro_file */
, &l_layer_id
);
if(composite_image_id >= 0)
{
gint32 RAW_size;
gint32 th_bpp;
gint32 th_width;
gint32 th_height;
th_data = gap_story_convert_layer_to_RGB_thdata(l_layer_id
, &RAW_size
, &th_bpp
, &th_width
, &th_height
);
if ((th_width != width) || (th_height != height))
{
printf("ERROR: gap_story_render_fetch_composite_vthumb width/height"
" expected:(%d/%d) actual:(%d/%d)\n"
,(int)width
,(int)height
,(int)th_width
,(int)th_height
);
}
gimp_image_delete(composite_image_id);
}
return (th_data);
} /* end gap_story_render_fetch_composite_vthumb */
/* ----------------------------------------------------
* gap_story_render_fetch_composite_image
* ----------------------------------------------------
* fetch composite VIDEO Image at a given master_frame_nr
* within a storyboard framerange list.
*
* the returned image is flattend RGB and scaled to
* desired video framesize.
*
* it is a merged result of all video tracks,
*
* frames at master_frame_nr were loaded
* for all video tracks and added to the composite image
* (track 0 on top, track N on bottom
* of the layerstack)
* opacity, scaling and move (decenter) attributes
* were set to according to current Video Attributes.
*
* an (optional) filtermacro_file is performed on the
* composite image.
*
* (simple animations without a storyboard file
* are represented by a short storyboard framerange list that has
* just one element entry at track 1).
*
* return image_id of resulting image and the flattened resulting layer_id
*/
gint32
gap_story_render_fetch_composite_image(GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr /* starts at 1 */
, gint32 vid_width /* desired Video Width in pixels */
, gint32 vid_height /* desired Video Height in pixels */
, char *filtermacro_file /* NULL if no filtermacro is used */
, gint32 *layer_id /* output: Id of the only layer in the composite image */
)
{
return (
p_story_render_fetch_composite_image_private(vidhand
,master_frame_nr
,vid_width
,vid_height
,filtermacro_file
,layer_id
,NULL));
} /* end gap_story_render_fetch_composite_image */
/* ------------------------------------------------
* p_split_delace_value
* ------------------------------------------------
* split the specified delace value:
* integer part is deinterlace mode,
* (0 NO,
* 1 Odd,
* 2 Even,
* 3 Odd First,
* 4 Even first)
* rest is the threshold value.
* The localframe_tween_rest is a positive value < 1.0.
* This is only relevant in case delace mode is 3 Odd First or 4 Even first.
* For clips with standard stepsize 1 localframe_tween_rest is always 0.
* In Clips with non-integer stepsize localframe_tween_rest referes
* between 2 framenumbers, where the value 0.5 is the middle.
* An Interlaced frame contains 2 half-frames where one half-frame is represented by
* the even, the other half-frame by the odd lines.
*
* therfore localframe_tween_rest values >= 0.5 selects the other half-frame,
* in case the enable_interlace_tween_pick option is enabled.
*
* OUT: *deinterlace_ptr
* 0 NO,
* 1 Odd,
* 2 Even,
* OUT: *threshold_ptr The threshold < 1.0 for smooth mix of 2 pixel rows.
*/
static void
p_split_delace_value(gdouble delace, gdouble localframe_tween_rest, gint32 *deinterlace_ptr, gdouble *threshold_ptr)
{
gint32 delace_int;
delace_int = delace;
*threshold_ptr = delace - (gdouble)delace_int;
switch (delace_int)
{
case 4:
*deinterlace_ptr = 2;
if (localframe_tween_rest >= 0.5)
{
*deinterlace_ptr = 1;
}
break;
case 3:
*deinterlace_ptr = 1;
if (localframe_tween_rest >= 0.5)
{
*deinterlace_ptr = 2;
}
break;
case 2:
*deinterlace_ptr = 2;
break;
case 1:
*deinterlace_ptr = 1;
break;
default:
*deinterlace_ptr = 0;
break;
}
} /* end p_split_delace_value */
/* -------------------------------------------------------------------
* p_conditional_delace_drawable
* -------------------------------------------------------------------
* general deinterlace handling for frames, images an animimages
* (except cliptype movie)
*/
static void
p_conditional_delace_drawable(GapStbFetchData *gfd, gint32 drawable_id)
{
gint32 l_deinterlace;
gdouble l_threshold;
if(gfd->frn_type == GAP_FRN_MOVIE)
{
/* deinterlace for cliptype movie is already handled by the API at fetching.
*/
return;
}
/* split delace value: integer part is deinterlace mode, rest is threshold */
p_split_delace_value(gfd->frn_elem->delace
, gfd->localframe_tween_rest
, &l_deinterlace
, &l_threshold
);
#ifdef GAP_ENABLE_VIDEOAPI_SUPPORT
if (l_deinterlace != 0)
{
GVA_delace_drawable(drawable_id, l_deinterlace, l_threshold);
}
#endif
} /* end p_conditional_delace_drawable */
/* -------------------------------------------------------------------
* p_stb_render_image_or_animimage (GAP_FRN_ANIMIMAGE or GAP_FRN_IMAGE
* -------------------------------------------------------------------
* fetch a single image or animimage
*/
static void
p_stb_render_image_or_animimage(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr)
{
gint32 l_orig_image_id;
gint l_nlayers;
gint32 *l_layers_list;
l_orig_image_id = gap_frame_fetch_orig_image(vidhand->ffetch_user_id
, gfd->framename /* full filename of the image */
, TRUE /* enable caching */
);
gimp_selection_none(l_orig_image_id);
if(gfd->frn_type == GAP_FRN_IMAGE)
{
gfd->layer_id = p_prepare_RGB_image(l_orig_image_id);
gfd->tmp_image_id = gimp_image_duplicate(l_orig_image_id);
}
else
{
/* GAP_FRN_ANIMIMAGE */
if(gap_debug)
{
printf("ANIM fetch gfd->localframe_index: %d master:%d from: %d to: %d\n"
,(int)gfd->localframe_index
,(int)master_frame_nr
,(int)gfd->frn_elem->frame_from
,(int)gfd->frn_elem->frame_to
);
}
gfd->tmp_image_id = p_create_unicolor_image(&gfd->layer_id
, gimp_image_width(l_orig_image_id)
, gimp_image_height(l_orig_image_id)
, 0.0, 0.0, 0.0, 0.0);
gimp_layer_add_alpha(gfd->layer_id);
l_layers_list = gimp_image_get_layers(l_orig_image_id, &l_nlayers);
if(l_layers_list != NULL)
{
if((gfd->localframe_index < l_nlayers)
&& (gfd->localframe_index >= 0))
{
gint32 l_fsel_layer_id;
if(gap_debug)
{
printf("ANIM-IMG: layer_id: %d gimp_layer_get_apply_mask:%d\n"
,(int)l_layers_list[gfd->localframe_index]
,(int)gimp_layer_get_apply_mask(l_layers_list[gfd->localframe_index])
);
}
gimp_drawable_set_visible(l_layers_list[gfd->localframe_index], TRUE);
if (0 != gimp_layer_get_apply_mask(l_layers_list[gfd->localframe_index]))
{
/* the layer has an active mask, apply the mask now
* because copying from the layer ignores the mask
*/
gimp_layer_remove_mask(l_layers_list[gfd->localframe_index], GIMP_MASK_APPLY);
}
gimp_layer_resize_to_image_size(l_layers_list[gfd->localframe_index]);
gimp_edit_copy(l_layers_list[gfd->localframe_index]);
l_fsel_layer_id = gimp_edit_paste(gfd->layer_id, FALSE); /* FALSE paste clear selection */
gimp_floating_sel_anchor(l_fsel_layer_id);
}
g_free (l_layers_list);
}
}
} /* end p_stb_render_image_or_animimage */
/* -------------------------------------------
* p_stb_render_movie (GAP_FRN_MOVIE)
* -------------------------------------------
* fetch frame from a videofile (gfd->framename contains the videofile name)
*/
static void
p_stb_render_movie(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, gint32 vid_width, gint32 vid_height)
{
gfd->tmp_image_id = -1;
#ifdef GAP_ENABLE_VIDEOAPI_SUPPORT
if(gfd->frn_elem->gvahand == NULL)
{
/* before we open a new GVA videohandle, lets check
* if another element has already opened this videofile,
* and reuse the already open gvahand handle if possible
*/
gfd->frn_elem->gvahand = p_try_to_steal_gvahand(vidhand
, master_frame_nr
, gfd->frn_elem->basename
, gfd->frn_elem->exact_seek
);
if(gfd->frn_elem->gvahand == NULL)
{
if(vidhand->preferred_decoder)
{
gfd->frn_elem->gvahand = GVA_open_read_pref(gfd->framename
, gfd->frn_elem->seltrack
, 1 /* aud_track */
, vidhand->preferred_decoder
, FALSE /* use MMX if available (disable_mmx == FALSE) */
);
}
else
{
gfd->frn_elem->gvahand = GVA_open_read(gfd->framename
,gfd->frn_elem->seltrack
,1 /* aud_track */
);
}
if(gfd->frn_elem->gvahand)
{
GVA_set_fcache_size(gfd->frn_elem->gvahand, GAP_STB_RENDER_GVA_FRAMES_TO_KEEP_CACHED);
gfd->frn_elem->gvahand->do_gimp_progress = vidhand->do_gimp_progress;
if(gfd->frn_elem->exact_seek == 1)
{
/* configure the GVA Procedures for exact (but slow) seek emulaion */
gfd->frn_elem->gvahand->emulate_seek = TRUE;
}
}
}
}
if(gfd->frn_elem->gvahand)
{
gint32 l_deinterlace;
gdouble l_threshold;
t_GVA_RetCode l_fcr;
/* split delace value: integer part is deinterlace mode, rest is threshold */
p_split_delace_value(gfd->frn_elem->delace
, gfd->localframe_tween_rest
, &l_deinterlace
, &l_threshold
);
/* set image and layer in the gvahand structure invalid,
* to force creation of a new image in the following call of GVA_frame_to_gimp_layer
*/
gfd->frn_elem->gvahand->image_id = -1;
gfd->frn_elem->gvahand->layer_id = -1;
/* attempt to read frame from the GVA API internal framecache */
/* printf("\nST: before GVA_debug_print_fcache (2) #:%d\n", (int)gfd->localframe_index );
* GVA_debug_print_fcache(gfd->frn_elem->gvahand);
* printf("ST: before GVA_frame_to_gimp_layer (2) attempt cache read #:%d\n", (int)gfd->localframe_index );
*/
l_fcr = GVA_frame_to_gimp_layer(gfd->frn_elem->gvahand
, TRUE /* delete_mode */
, gfd->localframe_index /* framenumber */
, l_deinterlace
, l_threshold
);
if (l_fcr != GVA_RET_OK)
{
/* if no success, we try explicite read that frame */
if(gfd->frn_elem->gvahand->current_seek_nr != gfd->localframe_index)
{
if(((gfd->frn_elem->gvahand->current_seek_nr + GAP_STB_RENDER_GVA_FRAMES_TO_KEEP_CACHED) > gfd->localframe_index)
&& (gfd->frn_elem->gvahand->current_seek_nr < gfd->localframe_index ) )
{
/* near forward seek is performed by dummyreads to fill up the framecache
*/
while(gfd->frn_elem->gvahand->current_seek_nr < gfd->localframe_index)
{
GVA_get_next_frame(gfd->frn_elem->gvahand);
}
}
else
{
if(vidhand->do_gimp_progress)
{
gimp_progress_init(_("Seek Inputvideoframe..."));
}
GVA_seek_frame(gfd->frn_elem->gvahand, (gdouble)gfd->localframe_index, GVA_UPOS_FRAMES);
if(vidhand->do_gimp_progress)
{
gimp_progress_init(_("Continue Encoding..."));
}
}
}
if(GVA_get_next_frame(gfd->frn_elem->gvahand) == GVA_RET_OK)
{
GVA_frame_to_gimp_layer(gfd->frn_elem->gvahand
, TRUE /* delete_mode */
, gfd->localframe_index /* framenumber */
, l_deinterlace
, l_threshold
);
}
}
/* take the newly created image from gvahand stucture */
gfd->tmp_image_id = gfd->frn_elem->gvahand->image_id;
gfd->frn_elem->gvahand->image_id = -1;
gfd->frn_elem->gvahand->layer_id = -1;
}
#endif
} /* end p_stb_render_movie */
/* -------------------------------------------
* p_stb_render_section (GAP_FRN_SECTION)
* -------------------------------------------
* handle section rendering (via recursive call)
*/
static void
p_stb_render_section(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, gint32 vid_width, gint32 vid_height
, const char *section_name)
{
gint32 sub_layer_id;
gint32 sub_master_frame_nr;
const char *sub_section_name;
gboolean orig_do_progress;
gdouble orig_progress;
if(gap_debug)
{
printf("SUB-SECTION: before RECURSIVE call\n");
}
orig_do_progress = vidhand->do_gimp_progress;
orig_progress = *vidhand->progress;
vidhand->do_gimp_progress = FALSE;
sub_section_name = gfd->framename;
sub_master_frame_nr = gfd->localframe_index;
gfd->tmp_image_id =
p_story_render_fetch_composite_image_private(vidhand
, sub_master_frame_nr
, vid_width
, vid_height
, NULL /* filtrmacro_file */
, &sub_layer_id
, sub_section_name
);
if(gap_debug)
{
printf("SUB-SECTION: after RECURSIVE call\n");
}
/* The recursive call of p_story_render_fetch_composite_image_private
* has set frn_list and aud_list to a sub_section.
* therefore switch back to current section after the call.
* furthermore restore progress settings.
*/
p_select_section_by_name(vidhand, section_name);
vidhand->do_gimp_progress = orig_do_progress;
*vidhand->progress = orig_progress;
} /* end p_stb_render_section */
/* -------------------------------------------
* p_stb_render_frame_images (GAP_FRN_FRAMES)
* -------------------------------------------
* gfd->framename is one single imagefile out of a series of numbered imagefiles.
* (note that the gfd->framename is already full qualified
* and includes path name, numberpart and extension)
*/
static void
p_stb_render_frame_images(GapStbFetchData *gfd, gint32 master_frame_nr)
{
if(gap_debug)
{
printf("FRAME fetch gfd->framename: %s\n ===> master:%d from: %d to: %d\n"
,gfd->framename
,(int)master_frame_nr
,(int)gfd->frn_elem->frame_from
,(int)gfd->frn_elem->frame_to
);
}
gfd->tmp_image_id = gap_lib_load_image(gfd->framename);
} /* end p_stb_render_frame_images */
/* -------------------------------------------
* p_stb_render_composite_image_postprocessing
* -------------------------------------------
* perform postprocessing on the composite frame image.
* this includes
* - convert to gray (only when fetching masks)
* - optional applying the global filtermacro
* - check size and scale (if filtermacro has changed size of the composite image)
* - check layers and flatten in case there is more than one layer
* The result is a single layer ( gfd->layer_id ) in the composite image.
*/
static void
p_stb_render_composite_image_postprocessing(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr
, gint32 vid_width, gint32 vid_height
, char *filtermacro_file
, const char *section_name
)
{
gint l_nlayers;
gint32 *l_layers_list;
if(gfd->comp_image_id < 0)
{
/* none of the tracks had a frame image on this master_frame_nr position
* create a blank image (VID_SILENNCE)
*/
gfd->comp_image_id = p_create_unicolor_image(&gfd->layer_id
, vid_width
, vid_height
, 0.0
, 0.0
, 0.0
, 1.0
);
}
if(vidhand->is_mask_handle == TRUE)
{
/* we are running as mask fetcher,
* therefore convert to GRAY image
*/
if(gimp_image_base_type(gfd->comp_image_id) != GIMP_GRAY)
{
gimp_image_convert_grayscale(gfd->comp_image_id);
}
}
/* debug: disabled code to display a copy of the image */
if(1==0)
{
p_debug_dup_image(gfd->comp_image_id);
}
/* check the layerstack
*/
l_layers_list = gimp_image_get_layers(gfd->comp_image_id, &l_nlayers);
if(l_layers_list != NULL)
{
gfd->layer_id = l_layers_list[0];
g_free (l_layers_list);
}
if((vidhand->is_mask_handle != TRUE)
&& (section_name == NULL))
{
/* debug feature: save the multilayer composite frame
* before it is passed to the filtermacro
* (always off for mask fetching)
*/
p_frame_backup_save( GAP_VID_ENC_SAVE_MULTILAYER
, gfd->comp_image_id
, gfd->layer_id
, master_frame_nr
, TRUE /* can be multilayer */
);
}
if((l_nlayers > 1 )
|| (gimp_drawable_has_alpha(gfd->layer_id)))
{
if(gap_debug)
{
printf("DEBUG: p_stb_render_composite_image_postprocessing flatten Composite image\n");
}
/* flatten current frame image (reduce to single layer) */
gfd->layer_id = gimp_image_flatten (gfd->comp_image_id);
}
/* execute filtermacro (optional if supplied) */
p_exec_filtermacro(gfd->comp_image_id
, gfd->layer_id
, filtermacro_file
, NULL /* have no 2nd filtermacro_file_to for varying parametersets */
, 0.0 /* current_step */
, 1 /* total_steps */
);
/* check again size and scale image to desired Videosize if needed */
if ((gimp_image_width(gfd->comp_image_id) != vid_width)
|| (gimp_image_height(gfd->comp_image_id) != vid_height) )
{
if(gap_debug) printf("DEBUG: p_story_render_fetch_composite_image_private: scaling tmp image\n");
gimp_image_scale(gfd->comp_image_id, vid_width, vid_height);
}
/* check again for layerstack (macro could have add more layers)
* or there might be an alpha channel
*/
l_layers_list = gimp_image_get_layers(gfd->comp_image_id, &l_nlayers);
if(l_layers_list != NULL)
{
gfd->layer_id = l_layers_list[0];
g_free (l_layers_list);
}
if((l_nlayers > 1 )
|| (gimp_drawable_has_alpha(gfd->layer_id)))
{
if(gap_debug) printf("DEBUG: p_story_render_fetch_composite_image_private FINAL flatten Composite image\n");
/* flatten current frame image (reduce to single layer) */
gfd->layer_id = gimp_image_flatten (gfd->comp_image_id);
}
} /* end p_stb_render_composite_image_postprocessing */
/* -------------------------------------------
* p_stb_render_result_monitoring
* -------------------------------------------
*
*/
static void
p_stb_render_result_monitoring(GapStbFetchData *gfd, gint32 master_frame_nr)
{
/* debug feature: save the flattened composite as jpg frame before it is passed to the encoder */
p_frame_backup_save( GAP_VID_ENC_SAVE_FLAT
, gfd->comp_image_id
, gfd->layer_id
, master_frame_nr
, FALSE /* is no multilayer, use jpeg */
);
/* debug feature: monitor composite image while encoding */
p_encoding_monitor(GAP_VID_ENC_MONITOR
, gfd->comp_image_id
, gfd->layer_id
, master_frame_nr
);
} /* end p_stb_render_result_monitoring */
/* ------------------------
* p_paste_logo_pattern
* ------------------------
* replace logo area with the specified logo pattern
*/
static void
p_paste_logo_pattern(gint32 drawable_id
, gint32 logo_pattern_id
, gint32 offsetX
, gint32 offsetY
)
{
gint32 l_fsel_layer_id;
gint l_src_offset_x;
gint l_src_offset_y;
gint32 image_id;
image_id = gimp_drawable_get_image(drawable_id);
gimp_selection_all(gimp_drawable_get_image(logo_pattern_id));
/* findout the offsets of the replacement_pattern layer within the source Image */
gimp_drawable_offsets(logo_pattern_id, &l_src_offset_x, &l_src_offset_y );
gimp_edit_copy(logo_pattern_id);
l_fsel_layer_id = gimp_edit_paste(drawable_id, TRUE); /* FALSE paste clear selection */
gimp_selection_none(gimp_drawable_get_image(logo_pattern_id));
if(gap_debug)
{
gint l_fsel_offset_x;
gint l_fsel_offset_y;
gimp_drawable_offsets(l_fsel_layer_id, &l_fsel_offset_x, &l_fsel_offset_y );
printf("p_paste_logo_pattern: l_src_offsets: (%d %d) fsel:(%d %d) final offsets: (%d %d) rep_id:%d\n"
,(int)l_src_offset_x
,(int)l_src_offset_y
,(int)l_fsel_offset_x
,(int)l_fsel_offset_y
,(int)(offsetX + l_src_offset_x)
,(int)(offsetY + l_src_offset_y)
,(int)logo_pattern_id
);
}
gimp_layer_set_offsets(l_fsel_layer_id
, offsetX + l_src_offset_x
, offsetY + l_src_offset_y);
gimp_floating_sel_anchor(l_fsel_layer_id);
} /* end p_copy_and_paste_replacement_pattern */
/* -------------------------------------
* p_do_insert_area_processing
* -------------------------------------
*/
static void
p_do_insert_area_processing(GapStbFetchData *gfd
, GapStoryRenderVidHandle *vidhand)
{
char *logo_imagename;
char *videofilename_without_path;
videofilename_without_path = gap_story_build_basename(gfd->framename);
if (vidhand->master_insert_area_format_has_framenumber)
{
if (vidhand->master_insert_area_format_has_videobasename)
{
logo_imagename =
g_strdup_printf(vidhand->master_insert_area_format
, videofilename_without_path
, gfd->localframe_index /* videoFrameNr */
);
}
else
{
logo_imagename =
g_strdup_printf(vidhand->master_insert_area_format
, gfd->localframe_index /* videoFrameNr */
);
}
}
else
{
if (vidhand->master_insert_area_format_has_videobasename)
{
logo_imagename =
g_strdup_printf(vidhand->master_insert_area_format
, videofilename_without_path
);
}
else
{
logo_imagename = g_strdup(vidhand->master_insert_area_format);
}
}
if(gap_debug)
{
printf("p_do_insert_area_processing: format:%s\n video:%s\n logo_imagename:%s\n"
, vidhand->master_insert_area_format
, videofilename_without_path
, logo_imagename
);
}
if(g_file_test(logo_imagename, G_FILE_TEST_EXISTS))
{
gint32 logo_image_id;
gint32 logo_layer_id;
if (vidhand->master_insert_area_format_has_framenumber)
{
logo_image_id = gap_lib_load_image(logo_imagename);
}
else
{
/* use framefetcher cache in case all frames shall get the same logo */
logo_image_id = gap_frame_fetch_orig_image(vidhand->ffetch_user_id
, logo_imagename
, TRUE /* enable caching */
);
}
if(logo_image_id < 0)
{
printf("p_do_insert_area_processing: ERROR could not load logo_imagename:%s\n", logo_imagename);
return;
}
gimp_selection_none(logo_image_id);
logo_layer_id = p_prepare_RGB_image(logo_image_id);
p_paste_logo_pattern(gfd->layer_id
, logo_layer_id
, 0, 0 /* offest_X, offset_Y */
);
if (vidhand->master_insert_area_format_has_framenumber)
{
/* do not keep individual per frame logo images cached
*/
gap_image_delete_immediate(logo_image_id);
}
}
} /* end p_do_insert_area_processing */
/* --------------------------------------------
* p_story_render_fetch_composite_image_private
* --------------------------------------------
* this procedure builds the composite image for the fram number specified by master_frame_nr.
* Therefore all videotracks of the storyboard (specified via an already opened handle vidhand)
* are fetched as layers. The track number is the layerstack index.
* optional filtermacro processing is done for the separate layers (clip specific filtermacre)
* and for the composite image (global filtermacro)
*/
static gint32
p_story_render_fetch_composite_image_private(GapStoryRenderVidHandle *vidhand
, gint32 master_frame_nr /* starts at 1 */
, gint32 vid_width /* desired Video Width in pixels */
, gint32 vid_height /* desired Video Height in pixels */
, char *filtermacro_file /* NULL if no filtermacro is used */
, gint32 *layer_id /* output: Id of the only layer in the composite image */
, const char *section_name /* NULL for main section */
)
{
GapStbFetchData gapStbFetchData;
GapStbFetchData *gfd;
gint l_track;
gint32 l_track_min;
gint32 l_track_max;
gdouble l_red_f;
gdouble l_green_f;
gdouble l_blue_f;
gdouble l_alpha_f;
gfd = &gapStbFetchData;
gfd->localframe_tween_rest = 0.0;
gfd->comp_image_id = -1;
gfd->tmp_image_id = -1;
gfd->layer_id = -1;
*layer_id = -1;
if(gap_debug)
{
printf("p_story_render_fetch_composite_image_private START master_frame_nr:%d %dx%d vidhand:%d\n"
, (int)master_frame_nr
, (int)vid_width
, (int)vid_height
, (int)vidhand
);
if (section_name == NULL)
{
printf(" section_name: (null)\n");
}
else
{
printf(" section_name: %s\n", section_name);
}
}
p_select_section_by_name(vidhand, section_name);
if(gap_debug)
{
if((vidhand->is_mask_handle == FALSE)
&& (master_frame_nr == 1)
// && (section_name == NULL)
)
{
printf("\n###\n###\nSTART rendering at master_frame_nr 1 with this list of elements:\n");
gap_story_render_debug_print_framerange_list(vidhand->frn_list, -1);
}
}
p_find_min_max_vid_tracknumbers(vidhand->frn_list, &l_track_min, &l_track_max);
/* reverse order, has the effect, that track 0 is processed as last track
* and will be put on top of the layerstack
*/
for(l_track = MIN(GAP_STB_MAX_VID_INTERNAL_TRACKS, l_track_max); l_track >= MAX(0, l_track_min); l_track--)
{
gfd->framename = p_fetch_framename(vidhand->frn_list
, master_frame_nr /* starts at 1 */
, l_track
, &gfd->frn_type
, &gfd->trak_filtermacro_file
, &gfd->localframe_index /* used only for ANIMIMAGE, SECTION and Videoframe Number, -1 for all other types */
, &gfd->local_stepcount /* nth frame within this clip */
, &gfd->localframe_tween_rest /* non integer part of local position (in case stepsize != 1) */
, &gfd->keep_proportions
, &gfd->fit_width
, &gfd->fit_height
, &l_red_f
, &l_green_f
, &l_blue_f
, &l_alpha_f
, &gfd->opacity /* output opacity 0.0 upto 1.0 */
, &gfd->scale_x /* output 0.0 upto 10.0 where 1.0 is 1:1 */
, &gfd->scale_y /* output 0.0 upto 10.0 where 1.0 is 1:1 */
, &gfd->move_x /* output -1.0 upto 1.0 where 0.0 is centered */
, &gfd->move_y /* output -1.0 upto 1.0 where 0.0 is centered */
, &gfd->frn_elem /* output selected to the relevant framerange element */
);
if((gfd->framename) || (gfd->frn_type == GAP_FRN_COLOR))
{
if(gfd->frn_type == GAP_FRN_COLOR)
{
gfd->tmp_image_id = p_create_unicolor_image(&gfd->layer_id
, vid_width
, vid_height
, l_red_f
, l_green_f
, l_blue_f
, l_alpha_f
);
}
else
{
if(gfd->framename)
{
if((gfd->frn_type == GAP_FRN_ANIMIMAGE)
|| (gfd->frn_type == GAP_FRN_IMAGE))
{
p_stb_render_image_or_animimage(gfd, vidhand, master_frame_nr);
}
else
{
if(gfd->frn_type == GAP_FRN_MOVIE)
{
p_stb_render_movie(gfd, vidhand, master_frame_nr, vid_width, vid_height);
}
else
{
if(gfd->frn_type == GAP_FRN_SECTION)
{
p_stb_render_section(gfd, vidhand, master_frame_nr, vid_width, vid_height, section_name);
}
else
{
/* GAP_FRN_FRAMES */
p_stb_render_frame_images(gfd, master_frame_nr);
}
}
}
if(gfd->tmp_image_id < 0)
{
printf("\n** ERROR fetching master_frame_nr:%d, from framename:%s Current CLIP was:\n"
, (int)master_frame_nr
, (int)gfd->framename
);
gap_story_render_debug_print_frame_elem(gfd->frn_elem, -1);
printf("\n** storyboard render processing failed\n");
g_free(gfd->framename);
return -1;
}
gfd->layer_id = p_prepare_RGB_image(gfd->tmp_image_id);
if((gfd->frn_type == GAP_FRN_MOVIE) && (vidhand->master_insert_area_format))
{
p_do_insert_area_processing(gfd, vidhand);
}
p_conditional_delace_drawable(gfd, gfd->layer_id);
g_free(gfd->framename);
}
}
if(gap_debug)
{
printf("p_prepare_RGB_image returned layer_id: %d, tmp_image_id:%d\n"
, (int)gfd->layer_id
, (int)gfd->tmp_image_id
);
}
if(gfd->comp_image_id < 0)
{
if((gfd->opacity == 1.0)
&& (gfd->scale_x == 1.0)
&& (gfd->scale_y == 1.0)
&& (gfd->move_x == 0.0)
&& (gfd->move_y == 0.0)
&& (gfd->fit_width)
&& (gfd->fit_height)
&& (!gfd->keep_proportions)
&& (gfd->frn_elem->flip_request == GAP_STB_FLIP_NONE)
&& (gfd->frn_elem->mask_name == NULL)
&& (gfd->trak_filtermacro_file == NULL)
&& (gfd->frn_type != GAP_FRN_ANIMIMAGE)
)
{
/* because there are no transformations in the first handled track,
* we can save time and directly use the loaded tmp image as base for the composite image
*/
gfd->comp_image_id = gfd->tmp_image_id;
/* scale image to desired Videosize */
if ((gimp_image_width(gfd->comp_image_id) != vid_width)
|| (gimp_image_height(gfd->comp_image_id) != vid_height) )
{
if(gap_debug) printf("DEBUG: p_story_render_fetch_composite_image_private scaling composite image\n");
gimp_image_scale(gfd->comp_image_id, vid_width, vid_height);
}
}
else
{
/* create empty backgound */
gint32 l_empty_layer_id;
gfd->comp_image_id = p_create_unicolor_image(&l_empty_layer_id
, vid_width
, vid_height
, 0.0
, 0.0
, 0.0
, 1.0
);
}
}
if(gfd->tmp_image_id != gfd->comp_image_id)
{
p_transform_and_add_layer(gfd->comp_image_id, gfd->tmp_image_id, gfd->layer_id
,gfd->keep_proportions
,gfd->fit_width
,gfd->fit_height
,gfd->opacity
,gfd->scale_x
,gfd->scale_y
,gfd->move_x
,gfd->move_y
,gfd->trak_filtermacro_file
,gfd->frn_elem->flip_request
,gfd->frn_elem
,vidhand
,gfd->local_stepcount
);
gap_image_delete_immediate(gfd->tmp_image_id);
}
}
} /* end for loop over all video tracks */
p_stb_render_composite_image_postprocessing(gfd
, vidhand, master_frame_nr
, vid_width, vid_height
, filtermacro_file
, section_name
);
*layer_id = gfd->layer_id;
if((vidhand->is_mask_handle != TRUE)
&& (section_name == NULL))
{
p_stb_render_result_monitoring(gfd, master_frame_nr);
}
if(gap_debug)
{
printf("p_story_render_fetch_composite_image_private END master_frame_nr:%d image_id:%d layer_id:%d\n"
, (int)master_frame_nr
, (int)gfd->comp_image_id
, (int)*layer_id );
}
return(gfd->comp_image_id);
} /* end p_story_render_fetch_composite_image_private */
/* -------------------------------------------------------------------
* gap_story_render_fetch_composite_image_or_chunk (see included file)
* -------------------------------------------------------------------
*
*/
#include "gap_story_render_lossless.c"
|