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
|
// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2003
//
// Implementation of Image
//
#define MAGICKCORE_IMPLEMENTATION 1
#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
#include "Magick++/Include.h"
#include <cstdlib>
#include <string>
#include <string.h>
#include <errno.h>
#include <math.h>
#if !defined(MAGICKCORE_WINDOWS_SUPPORT)
#include <strings.h>
#endif
using namespace std;
#include "Magick++/Image.h"
#include "Magick++/Functions.h"
#include "Magick++/Pixels.h"
#include "Magick++/Options.h"
#include "Magick++/ImageRef.h"
#define AbsoluteValue(x) ((x) < 0 ? -(x) : (x))
#define MagickPI 3.14159265358979323846264338327950288419716939937510
#define DegreesToRadians(x) (MagickPI*(x)/180.0)
MagickPPExport const char *Magick::borderGeometryDefault = "6x6+0+0";
MagickPPExport const char *Magick::frameGeometryDefault = "25x25+6+6";
MagickPPExport const char *Magick::raiseGeometryDefault = "6x6+0+0";
static bool magick_initialized=false;
//
// Explicit template instantiations
//
//
// Friend functions to compare Image objects
//
MagickPPExport int Magick::operator == ( const Magick::Image& left_,
const Magick::Image& right_ )
{
// If image pixels and signature are the same, then the image is identical
return ( ( left_.rows() == right_.rows() ) &&
( left_.columns() == right_.columns() ) &&
( left_.signature() == right_.signature() )
);
}
MagickPPExport int Magick::operator != ( const Magick::Image& left_,
const Magick::Image& right_ )
{
return ( ! (left_ == right_) );
}
MagickPPExport int Magick::operator > ( const Magick::Image& left_,
const Magick::Image& right_ )
{
return ( !( left_ < right_ ) && ( left_ != right_ ) );
}
MagickPPExport int Magick::operator < ( const Magick::Image& left_,
const Magick::Image& right_ )
{
// If image pixels are less, then image is smaller
return ( ( left_.rows() * left_.columns() ) <
( right_.rows() * right_.columns() )
);
}
MagickPPExport int Magick::operator >= ( const Magick::Image& left_,
const Magick::Image& right_ )
{
return ( ( left_ > right_ ) || ( left_ == right_ ) );
}
MagickPPExport int Magick::operator <= ( const Magick::Image& left_,
const Magick::Image& right_ )
{
return ( ( left_ < right_ ) || ( left_ == right_ ) );
}
//
// Image object implementation
//
// Construct from image file or image specification
Magick::Image::Image( const std::string &imageSpec_ )
: _imgRef(new ImageRef)
{
try
{
// Initialize, Allocate and Read images
read( imageSpec_ );
}
catch ( const Warning & /*warning_*/ )
{
// FIXME: need a way to report warnings in constructor
}
catch ( const Error & /*error_*/ )
{
// Release resources
delete _imgRef;
throw;
}
}
// Construct a blank image canvas of specified size and color
Magick::Image::Image( const Geometry &size_,
const Color &color_ )
: _imgRef(new ImageRef)
{
// xc: prefix specifies an X11 color string
std::string imageSpec("xc:");
imageSpec += color_;
try
{
// Set image size
size( size_ );
// Initialize, Allocate and Read images
read( imageSpec );
}
catch ( const Warning & /*warning_*/ )
{
// FIXME: need a way to report warnings in constructor
}
catch ( const Error & /*error_*/ )
{
// Release resources
delete _imgRef;
throw;
}
}
// Construct Image from in-memory BLOB
Magick::Image::Image ( const Blob &blob_ )
: _imgRef(new ImageRef)
{
try
{
// Initialize, Allocate and Read images
read( blob_ );
}
catch ( const Warning & /*warning_*/ )
{
// FIXME: need a way to report warnings in constructor
}
catch ( const Error & /*error_*/ )
{
// Release resources
delete _imgRef;
throw;
}
}
// Construct Image of specified size from in-memory BLOB
Magick::Image::Image ( const Blob &blob_,
const Geometry &size_ )
: _imgRef(new ImageRef)
{
try
{
// Read from Blob
read( blob_, size_ );
}
catch ( const Warning & /*warning_*/ )
{
// FIXME: need a way to report warnings in constructor
}
catch ( const Error & /*error_*/ )
{
// Release resources
delete _imgRef;
throw;
}
}
// Construct Image of specified size and depth from in-memory BLOB
Magick::Image::Image ( const Blob &blob_,
const Geometry &size_,
const size_t depth_ )
: _imgRef(new ImageRef)
{
try
{
// Read from Blob
read( blob_, size_, depth_ );
}
catch ( const Warning & /*warning_*/ )
{
// FIXME: need a way to report warnings in constructor
}
catch ( const Error & /*error_*/ )
{
// Release resources
delete _imgRef;
throw;
}
}
// Construct Image of specified size, depth, and format from in-memory BLOB
Magick::Image::Image ( const Blob &blob_,
const Geometry &size_,
const size_t depth_,
const std::string &magick_ )
: _imgRef(new ImageRef)
{
try
{
// Read from Blob
read( blob_, size_, depth_, magick_ );
}
catch ( const Warning & /*warning_*/ )
{
// FIXME: need a way to report warnings in constructor
}
catch ( const Error & /*error_*/ )
{
// Release resources
delete _imgRef;
throw;
}
}
// Construct Image of specified size, and format from in-memory BLOB
Magick::Image::Image ( const Blob &blob_,
const Geometry &size_,
const std::string &magick_ )
: _imgRef(new ImageRef)
{
try
{
// Read from Blob
read( blob_, size_, magick_ );
}
catch ( const Warning & /*warning_*/ )
{
// FIXME: need a way to report warnings in constructor
}
catch ( const Error & /*error_*/ )
{
// Release resources
delete _imgRef;
throw;
}
}
// Construct an image based on an array of raw pixels, of specified
// type and mapping, in memory
Magick::Image::Image ( const size_t width_,
const size_t height_,
const std::string &map_,
const StorageType type_,
const void *pixels_ )
: _imgRef(new ImageRef)
{
try
{
read( width_, height_, map_.c_str(), type_, pixels_ );
}
catch ( const Warning & /*warning_*/ )
{
// FIXME: need a way to report warnings in constructor
}
catch ( const Error & /*error_*/ )
{
// Release resources
delete _imgRef;
throw;
}
}
// Default constructor
Magick::Image::Image( void )
: _imgRef(new ImageRef)
{
}
// Destructor
/* virtual */
Magick::Image::~Image()
{
bool doDelete = false;
{
Lock( &_imgRef->_mutexLock );
if ( --_imgRef->_refCount == 0 )
doDelete = true;
}
if ( doDelete )
{
delete _imgRef;
}
_imgRef = 0;
}
// Adaptive-blur image
void Magick::Image::adaptiveBlur( const double radius_, const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
AdaptiveBlurImage( image(), radius_, sigma_, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Local adaptive threshold image
// http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm
// Width x height define the size of the pixel neighborhood
// offset = constant to subtract from pixel neighborhood mean
void Magick::Image::adaptiveThreshold ( const size_t width_,
const size_t height_,
const ssize_t offset_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
AdaptiveThresholdImage( constImage(), width_, height_, offset_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Add noise to image
void Magick::Image::addNoise( const NoiseType noiseType_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
AddNoiseImage ( image(),
noiseType_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::addNoiseChannel( const ChannelType channel_,
const NoiseType noiseType_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
AddNoiseImageChannel ( image(),
channel_,
noiseType_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Affine Transform image
void Magick::Image::affineTransform ( const DrawableAffine &affine_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
AffineMatrix _affine;
_affine.sx = affine_.sx();
_affine.sy = affine_.sy();
_affine.rx = affine_.rx();
_affine.ry = affine_.ry();
_affine.tx = affine_.tx();
_affine.ty = affine_.ty();
MagickCore::Image* newImage =
AffineTransformImage( image(), &_affine, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Annotate using specified text, and placement location
void Magick::Image::annotate ( const std::string &text_,
const Geometry &location_ )
{
annotate ( text_, location_, NorthWestGravity, 0.0 );
}
// Annotate using specified text, bounding area, and placement gravity
void Magick::Image::annotate ( const std::string &text_,
const Geometry &boundingArea_,
const GravityType gravity_ )
{
annotate ( text_, boundingArea_, gravity_, 0.0 );
}
// Annotate with text using specified text, bounding area, placement
// gravity, and rotation.
void Magick::Image::annotate ( const std::string &text_,
const Geometry &boundingArea_,
const GravityType gravity_,
const double degrees_ )
{
modifyImage();
DrawInfo *drawInfo
= options()->drawInfo();
drawInfo->text = const_cast<char *>(text_.c_str());
char boundingArea[MaxTextExtent];
drawInfo->geometry = 0;
if ( boundingArea_.isValid() ){
if ( boundingArea_.width() == 0 || boundingArea_.height() == 0 )
{
FormatLocaleString( boundingArea, MaxTextExtent, "%+.20g%+.20g",
(double) boundingArea_.xOff(), (double) boundingArea_.yOff() );
}
else
{
(void) CopyMagickString( boundingArea, string(boundingArea_).c_str(),
MaxTextExtent);
}
drawInfo->geometry = boundingArea;
}
drawInfo->gravity = gravity_;
AffineMatrix oaffine = drawInfo->affine;
if ( degrees_ != 0.0)
{
AffineMatrix affine;
affine.sx=1.0;
affine.rx=0.0;
affine.ry=0.0;
affine.sy=1.0;
affine.tx=0.0;
affine.ty=0.0;
AffineMatrix current = drawInfo->affine;
affine.sx=cos(DegreesToRadians(fmod(degrees_,360.0)));
affine.rx=sin(DegreesToRadians(fmod(degrees_,360.0)));
affine.ry=(-sin(DegreesToRadians(fmod(degrees_,360.0))));
affine.sy=cos(DegreesToRadians(fmod(degrees_,360.0)));
drawInfo->affine.sx=current.sx*affine.sx+current.ry*affine.rx;
drawInfo->affine.rx=current.rx*affine.sx+current.sy*affine.rx;
drawInfo->affine.ry=current.sx*affine.ry+current.ry*affine.sy;
drawInfo->affine.sy=current.rx*affine.ry+current.sy*affine.sy;
drawInfo->affine.tx=current.sx*affine.tx+current.ry*affine.ty
+current.tx;
}
AnnotateImage( image(), drawInfo );
// Restore original values
drawInfo->affine = oaffine;
drawInfo->text = 0;
drawInfo->geometry = 0;
throwImageException();
}
// Annotate with text (bounding area is entire image) and placement gravity.
void Magick::Image::annotate ( const std::string &text_,
const GravityType gravity_ )
{
modifyImage();
DrawInfo *drawInfo
= options()->drawInfo();
drawInfo->text = const_cast<char *>(text_.c_str());
drawInfo->gravity = gravity_;
AnnotateImage( image(), drawInfo );
drawInfo->gravity = NorthWestGravity;
drawInfo->text = 0;
throwImageException();
}
// Blur image
void Magick::Image::blur( const double radius_, const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
BlurImage( image(), radius_, sigma_, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::blurChannel( const ChannelType channel_,
const double radius_, const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
BlurImageChannel( image(), channel_,radius_, sigma_, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Add border to image
// Only uses width & height
void Magick::Image::border( const Geometry &geometry_ )
{
RectangleInfo borderInfo = geometry_;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
BorderImage( image(), &borderInfo, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Extract channel from image
void Magick::Image::channel ( const ChannelType channel_ )
{
modifyImage();
SeparateImageChannel ( image(), channel_ );
throwImageException();
}
// Set or obtain modulus channel depth
void Magick::Image::channelDepth ( const ChannelType channel_,
const size_t depth_)
{
modifyImage();
SetImageChannelDepth( image(), channel_, depth_);
throwImageException();
}
size_t Magick::Image::channelDepth ( const ChannelType channel_ )
{
size_t channel_depth;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
channel_depth=GetImageChannelDepth( constImage(), channel_,
&exceptionInfo );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return channel_depth;
}
// Charcoal-effect image
void Magick::Image::charcoal( const double radius_, const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
CharcoalImage( image(), radius_, sigma_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Chop image
void Magick::Image::chop( const Geometry &geometry_ )
{
RectangleInfo chopInfo = geometry_;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ChopImage( image(), &chopInfo, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// contains one or more color corrections and applies the correction to the
// image.
void Magick::Image::cdl ( const std::string &cdl_ )
{
modifyImage();
(void) ColorDecisionListImage( image(), cdl_.c_str() );
throwImageException();
}
// Colorize
void Magick::Image::colorize ( const unsigned int opacityRed_,
const unsigned int opacityGreen_,
const unsigned int opacityBlue_,
const Color &penColor_ )
{
if ( !penColor_.isValid() )
{
throwExceptionExplicit( OptionError,
"Pen color argument is invalid");
}
char opacity[MaxTextExtent];
FormatLocaleString(opacity,MaxTextExtent,"%u/%u/%u",opacityRed_,opacityGreen_,opacityBlue_);
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ColorizeImage ( image(), opacity,
penColor_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::colorize ( const unsigned int opacity_,
const Color &penColor_ )
{
colorize( opacity_, opacity_, opacity_, penColor_ );
}
// Apply a color matrix to the image channels. The user supplied
// matrix may be of order 1 to 6 (1x1 through 6x6).
void Magick::Image::colorMatrix (const size_t order_,
const double *color_matrix_)
{
KernelInfo
*kernel_info;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
kernel_info=AcquireKernelInfo("1");
kernel_info->width=order_;
kernel_info->height=order_;
kernel_info->values=(double *) color_matrix_;
MagickCore::Image* newImage =
ColorMatrixImage( image(), kernel_info, &exceptionInfo );
kernel_info->values=(double *) NULL;
kernel_info=DestroyKernelInfo(kernel_info);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Compare current image with another image
// Sets meanErrorPerPixel, normalizedMaxError, and normalizedMeanError
// in the current image. False is returned if the images are identical.
bool Magick::Image::compare ( const Image &reference_ )
{
modifyImage();
Image ref = reference_;
ref.modifyImage();
return static_cast<bool>(IsImagesEqual(image(), ref.image()));
}
// Composite two images
void Magick::Image::composite ( const Image &compositeImage_,
const ssize_t xOffset_,
const ssize_t yOffset_,
const CompositeOperator compose_ )
{
// Image supplied as compositeImage is composited with current image and
// results in updating current image.
modifyImage();
CompositeImage( image(),
compose_,
compositeImage_.constImage(),
xOffset_,
yOffset_ );
throwImageException();
}
void Magick::Image::composite ( const Image &compositeImage_,
const Geometry &offset_,
const CompositeOperator compose_ )
{
modifyImage();
ssize_t x = offset_.xOff();
ssize_t y = offset_.yOff();
size_t width = columns();
size_t height = rows();
ParseMetaGeometry (static_cast<std::string>(offset_).c_str(),
&x, &y,
&width, &height );
CompositeImage( image(),
compose_,
compositeImage_.constImage(),
x, y );
throwImageException();
}
void Magick::Image::composite ( const Image &compositeImage_,
const GravityType gravity_,
const CompositeOperator compose_ )
{
modifyImage();
RectangleInfo geometry;
SetGeometry(compositeImage_.constImage(), &geometry);
GravityAdjustGeometry(columns(), rows(), gravity_, &geometry);
CompositeImage( image(),
compose_,
compositeImage_.constImage(),
geometry.x, geometry.y );
throwImageException();
}
// Contrast image
void Magick::Image::contrast ( const size_t sharpen_ )
{
modifyImage();
ContrastImage ( image(), (MagickBooleanType) sharpen_ );
throwImageException();
}
// Convolve image. Applies a general image convolution kernel to the image.
// order_ represents the number of columns and rows in the filter kernel.
// kernel_ is an array of doubles representing the convolution kernel.
void Magick::Image::convolve ( const size_t order_,
const double *kernel_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ConvolveImage ( image(), order_,
kernel_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Crop image
void Magick::Image::crop ( const Geometry &geometry_ )
{
RectangleInfo cropInfo = geometry_;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
CropImage( image(),
&cropInfo,
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Cycle Color Map
void Magick::Image::cycleColormap ( const ssize_t amount_ )
{
modifyImage();
CycleColormapImage( image(), amount_ );
throwImageException();
}
// Despeckle
void Magick::Image::despeckle ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
DespeckleImage( image(), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Display image
void Magick::Image::display( void )
{
DisplayImages( imageInfo(), image() );
}
// Distort image. distorts an image using various distortion methods, by
// mapping color lookups of the source image to a new destination image
// usally of the same size as the source image, unless 'bestfit' is set to
// true.
void Magick::Image::distort ( const DistortImageMethod method_,
const size_t number_arguments_,
const double *arguments_,
const bool bestfit_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage = DistortImage ( image(), method_,
number_arguments_, arguments_, bestfit_ == true ? MagickTrue : MagickFalse,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Draw on image using single drawable
void Magick::Image::draw ( const Magick::Drawable &drawable_ )
{
modifyImage();
DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
if(wand)
{
drawable_.operator()(wand);
if( constImage()->exception.severity == UndefinedException)
DrawRender(wand);
wand=DestroyDrawingWand(wand);
}
throwImageException();
}
// Draw on image using a drawable list
void Magick::Image::draw ( const std::list<Magick::Drawable> &drawable_ )
{
modifyImage();
DrawingWand *wand = DrawAllocateWand( options()->drawInfo(), image());
if(wand)
{
for( std::list<Magick::Drawable>::const_iterator p = drawable_.begin();
p != drawable_.end(); p++ )
{
p->operator()(wand);
if( constImage()->exception.severity != UndefinedException)
break;
}
if( constImage()->exception.severity == UndefinedException)
DrawRender(wand);
wand=DestroyDrawingWand(wand);
}
throwImageException();
}
// Hilight edges in image
void Magick::Image::edge ( const double radius_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
EdgeImage( image(), radius_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Emboss image (hilight edges)
void Magick::Image::emboss ( const double radius_, const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
EmbossImage( image(), radius_, sigma_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Enhance image (minimize noise)
void Magick::Image::enhance ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
EnhanceImage( image(), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Equalize image (histogram equalization)
void Magick::Image::equalize ( void )
{
modifyImage();
EqualizeImage( image() );
throwImageException();
}
// Erase image to current "background color"
void Magick::Image::erase ( void )
{
modifyImage();
SetImageBackgroundColor( image() );
throwImageException();
}
// Extends image as defined by the geometry.
//
void Magick::Image::extent ( const Geometry &geometry_ )
{
RectangleInfo extentInfo = geometry_;
modifyImage();
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ExtentImage ( image(), &extentInfo, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_ )
{
backgroundColor ( backgroundColor_ );
extent ( geometry_ );
}
void Magick::Image::extent ( const Geometry &geometry_, const GravityType gravity_ )
{
RectangleInfo geometry;
SetGeometry(image(), &geometry);
GravityAdjustGeometry(image()->columns, image()->rows, gravity_, &geometry);
extent ( geometry_ );
}
void Magick::Image::extent ( const Geometry &geometry_, const Color &backgroundColor_, const GravityType gravity_ )
{
image()->gravity = gravity_;
backgroundColor ( backgroundColor_ );
extent ( geometry_ );
}
// Flip image (reflect each scanline in the vertical direction)
void Magick::Image::flip ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
FlipImage( image(), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Flood-fill color across pixels that match the color of the
// target pixel and are neighbors of the target pixel.
// Uses current fuzz setting when determining color match.
void Magick::Image::floodFillColor( const ssize_t x_,
const ssize_t y_,
const Magick::Color &fillColor_ )
{
floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_ ) );
}
void Magick::Image::floodFillColor( const Geometry &point_,
const Magick::Color &fillColor_ )
{
floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_) );
}
// Flood-fill color across pixels starting at target-pixel and
// stopping at pixels matching specified border color.
// Uses current fuzz setting when determining color match.
void Magick::Image::floodFillColor( const ssize_t x_,
const ssize_t y_,
const Magick::Color &fillColor_,
const Magick::Color &borderColor_ )
{
floodFillTexture( x_, y_, Image( Geometry( 1, 1), fillColor_),
borderColor_ );
}
void Magick::Image::floodFillColor( const Geometry &point_,
const Magick::Color &fillColor_,
const Magick::Color &borderColor_ )
{
floodFillTexture( point_, Image( Geometry( 1, 1), fillColor_),
borderColor_ );
}
// Floodfill pixels matching color (within fuzz factor) of target
// pixel(x,y) with replacement opacity value using method.
void Magick::Image::floodFillOpacity( const ssize_t x_,
const ssize_t y_,
const unsigned int opacity_,
const PaintMethod method_ )
{
modifyImage();
MagickPixelPacket target;
GetMagickPixelPacket(image(),&target);
PixelPacket pixel=static_cast<PixelPacket>(pixelColor(x_,y_));
target.red=pixel.red;
target.green=pixel.green;
target.blue=pixel.blue;
target.opacity=opacity_;
FloodfillPaintImage ( image(),
DefaultChannels,
options()->drawInfo(), // const DrawInfo *draw_info
&target,
static_cast<ssize_t>(x_), static_cast<ssize_t>(y_),
method_ == FloodfillMethod ? MagickFalse : MagickTrue);
throwImageException();
}
// Flood-fill texture across pixels that match the color of the
// target pixel and are neighbors of the target pixel.
// Uses current fuzz setting when determining color match.
void Magick::Image::floodFillTexture( const ssize_t x_,
const ssize_t y_,
const Magick::Image &texture_ )
{
modifyImage();
// Set drawing pattern
options()->fillPattern(texture_.constImage());
// Get pixel view
Pixels pixels(*this);
// Fill image
PixelPacket *p = pixels.get(x_, y_, 1, 1 );
MagickPixelPacket target;
GetMagickPixelPacket(constImage(),&target);
target.red=p->red;
target.green=p->green;
target.blue=p->blue;
if (p)
FloodfillPaintImage ( image(), // Image *image
DefaultChannels,
options()->drawInfo(), // const DrawInfo *draw_info
&target, // const MagickPacket target
static_cast<ssize_t>(x_), // const ssize_t x_offset
static_cast<ssize_t>(y_), // const ssize_t y_offset
MagickFalse // const PaintMethod method
);
throwImageException();
}
void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
const Magick::Image &texture_ )
{
floodFillTexture( point_.xOff(), point_.yOff(), texture_ );
}
// Flood-fill texture across pixels starting at target-pixel and
// stopping at pixels matching specified border color.
// Uses current fuzz setting when determining color match.
void Magick::Image::floodFillTexture( const ssize_t x_,
const ssize_t y_,
const Magick::Image &texture_,
const Magick::Color &borderColor_ )
{
modifyImage();
// Set drawing fill pattern
options()->fillPattern(texture_.constImage());
MagickPixelPacket target;
GetMagickPixelPacket(constImage(),&target);
target.red=static_cast<PixelPacket>(borderColor_).red;
target.green=static_cast<PixelPacket>(borderColor_).green;
target.blue=static_cast<PixelPacket>(borderColor_).blue;
FloodfillPaintImage ( image(),
DefaultChannels,
options()->drawInfo(),
&target,
static_cast<ssize_t>(x_),
static_cast<ssize_t>(y_),
MagickTrue);
throwImageException();
}
void Magick::Image::floodFillTexture( const Magick::Geometry &point_,
const Magick::Image &texture_,
const Magick::Color &borderColor_ )
{
floodFillTexture( point_.xOff(), point_.yOff(), texture_, borderColor_ );
}
// Flop image (reflect each scanline in the horizontal direction)
void Magick::Image::flop ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
FlopImage( image(), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Frame image
void Magick::Image::frame ( const Geometry &geometry_ )
{
FrameInfo info;
info.x = static_cast<ssize_t>(geometry_.width());
info.y = static_cast<ssize_t>(geometry_.height());
info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
info.outer_bevel = geometry_.xOff();
info.inner_bevel = geometry_.yOff();
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
FrameImage( image(), &info, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::frame ( const size_t width_,
const size_t height_,
const ssize_t outerBevel_, const ssize_t innerBevel_ )
{
FrameInfo info;
info.x = static_cast<ssize_t>(width_);
info.y = static_cast<ssize_t>(height_);
info.width = columns() + ( static_cast<size_t>(info.x) << 1 );
info.height = rows() + ( static_cast<size_t>(info.y) << 1 );
info.outer_bevel = static_cast<ssize_t>(outerBevel_);
info.inner_bevel = static_cast<ssize_t>(innerBevel_);
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
FrameImage( image(), &info, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Fx image. Applies a mathematical expression to the image.
void Magick::Image::fx ( const std::string expression )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
FxImageChannel ( image(), DefaultChannels, expression.c_str(), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::fx ( const std::string expression,
const Magick::ChannelType channel )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
FxImageChannel ( image(), channel, expression.c_str(), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Gamma correct image
void Magick::Image::gamma ( const double gamma_ )
{
char gamma[MaxTextExtent + 1];
FormatLocaleString( gamma, MaxTextExtent, "%3.6f", gamma_);
modifyImage();
GammaImage ( image(), gamma );
}
void Magick::Image::gamma ( const double gammaRed_,
const double gammaGreen_,
const double gammaBlue_ )
{
char gamma[MaxTextExtent + 1];
FormatLocaleString( gamma, MaxTextExtent, "%3.6f/%3.6f/%3.6f/",
gammaRed_, gammaGreen_, gammaBlue_);
modifyImage();
GammaImage ( image(), gamma );
throwImageException();
}
// Gaussian blur image
// The number of neighbor pixels to be included in the convolution
// mask is specified by 'width_'. The standard deviation of the
// gaussian bell curve is specified by 'sigma_'.
void Magick::Image::gaussianBlur ( const double width_, const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
GaussianBlurImage( image(), width_, sigma_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::gaussianBlurChannel ( const ChannelType channel_,
const double width_,
const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
GaussianBlurImageChannel( image(), channel_, width_, sigma_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Apply a color lookup table (Hald CLUT) to the image.
void Magick::Image::haldClut ( const Image &clutImage_ )
{
modifyImage();
(void) HaldClutImage( image(), clutImage_.constImage() );
throwImageException();
}
// Implode image
void Magick::Image::implode ( const double factor_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ImplodeImage( image(), factor_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// implements the inverse discrete Fourier transform (IFT) of the image either
// as a magnitude / phase or real / imaginary image pair.
void Magick::Image::inverseFourierTransform ( const Image &phase_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage = InverseFourierTransformImage( image(),
phase_.constImage(), MagickTrue, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::inverseFourierTransform ( const Image &phase_,
const bool magnitude_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage = InverseFourierTransformImage( image(),
phase_.constImage(), magnitude_ == true ? MagickTrue : MagickFalse,
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Level image. Adjust the levels of the image by scaling the colors
// falling between specified white and black points to the full
// available quantum range. The parameters provided represent the
// black, mid (gamma), and white points. The black point specifies
// the darkest color in the image. Colors darker than the black point
// are set to zero. Mid point (gamma) specifies a gamma correction to
// apply to the image. White point specifies the lightest color in the
// image. Colors brighter than the white point are set to the maximum
// quantum value. The black and white point have the valid range 0 to
// QuantumRange while gamma has a useful range of 0 to ten.
void Magick::Image::level ( const double black_point,
const double white_point,
const double gamma )
{
modifyImage();
char levels[MaxTextExtent];
FormatLocaleString( levels, MaxTextExtent, "%g,%g,%g",black_point,white_point,gamma);
(void) LevelImage( image(), levels );
throwImageException();
}
// Level image channel. Adjust the levels of the image channel by
// scaling the values falling between specified white and black points
// to the full available quantum range. The parameters provided
// represent the black, mid (gamma), and white points. The black
// point specifies the darkest color in the image. Colors darker than
// the black point are set to zero. Mid point (gamma) specifies a
// gamma correction to apply to the image. White point specifies the
// lightest color in the image. Colors brighter than the white point
// are set to the maximum quantum value. The black and white point
// have the valid range 0 to QuantumRange while gamma has a useful range of
// 0 to ten.
void Magick::Image::levelChannel ( const Magick::ChannelType channel,
const double black_point,
const double white_point,
const double gamma )
{
modifyImage();
(void) LevelImageChannel( image(), channel, black_point, white_point,
gamma );
throwImageException();
}
// Magnify image by integral size
void Magick::Image::magnify ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
MagnifyImage( image(), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Remap image colors with closest color from reference image
void Magick::Image::map ( const Image &mapImage_ , const bool dither_ )
{
modifyImage();
options()->quantizeDither( dither_ );
RemapImage ( options()->quantizeInfo(), image(),
mapImage_.constImage());
throwImageException();
}
// Floodfill designated area with replacement opacity value
void Magick::Image::matteFloodfill ( const Color &target_ ,
const unsigned int opacity_,
const ssize_t x_, const ssize_t y_,
const Magick::PaintMethod method_ )
{
modifyImage();
MagickPixelPacket target;
GetMagickPixelPacket(constImage(),&target);
target.red=static_cast<PixelPacket>(target_).red;
target.green=static_cast<PixelPacket>(target_).green;
target.blue=static_cast<PixelPacket>(target_).blue;
target.opacity=opacity_;
FloodfillPaintImage ( image(), OpacityChannel, options()->drawInfo(), &target,
x_, y_, method_ == FloodfillMethod ? MagickFalse : MagickTrue);
throwImageException();
}
// Filter image by replacing each pixel component with the median
// color in a circular neighborhood
void Magick::Image::medianFilter ( const double radius_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
StatisticImage ( image(), MedianStatistic, (size_t) radius_, (size_t)
radius_,&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Reduce image by integral size
void Magick::Image::minify ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
MinifyImage( image(), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Modulate percent hue, saturation, and brightness of an image
void Magick::Image::modulate ( const double brightness_,
const double saturation_,
const double hue_ )
{
char modulate[MaxTextExtent + 1];
FormatLocaleString( modulate, MaxTextExtent, "%3.6f,%3.6f,%3.6f",
brightness_, saturation_, hue_);
modifyImage();
ModulateImage( image(), modulate );
throwImageException();
}
// Motion blur image with specified blur factor
// The radius_ parameter specifies the radius of the Gaussian, in
// pixels, not counting the center pixel. The sigma_ parameter
// specifies the standard deviation of the Laplacian, in pixels.
// The angle_ parameter specifies the angle the object appears
// to be comming from (zero degrees is from the right).
void Magick::Image::motionBlur ( const double radius_,
const double sigma_,
const double angle_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
MotionBlurImage( image(), radius_, sigma_, angle_, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Negate image. Set grayscale_ to true to effect grayscale values
// only
void Magick::Image::negate ( const bool grayscale_ )
{
modifyImage();
NegateImage ( image(), grayscale_ == true ? MagickTrue : MagickFalse );
throwImageException();
}
// Normalize image
void Magick::Image::normalize ( void )
{
modifyImage();
NormalizeImage ( image() );
throwImageException();
}
// Oilpaint image
void Magick::Image::oilPaint ( const double radius_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
OilPaintImage( image(), radius_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Set or attenuate the opacity channel. If the image pixels are
// opaque then they are set to the specified opacity value, otherwise
// they are blended with the supplied opacity value. The value of
// opacity_ ranges from 0 (completely opaque) to QuantumRange. The defines
// OpaqueOpacity and TransparentOpacity are available to specify
// completely opaque or completely transparent, respectively.
void Magick::Image::opacity ( const unsigned int opacity_ )
{
modifyImage();
SetImageOpacity( image(), opacity_ );
}
// Change the color of an opaque pixel to the pen color.
void Magick::Image::opaque ( const Color &opaqueColor_,
const Color &penColor_ )
{
if ( !opaqueColor_.isValid() )
{
throwExceptionExplicit( OptionError,
"Opaque color argument is invalid" );
}
if ( !penColor_.isValid() )
{
throwExceptionExplicit( OptionError,
"Pen color argument is invalid" );
}
modifyImage();
std::string opaqueColor = opaqueColor_;
std::string penColor = penColor_;
MagickPixelPacket opaque;
MagickPixelPacket pen;
(void) QueryMagickColor(std::string(opaqueColor_).c_str(),&opaque,&image()->exception);
(void) QueryMagickColor(std::string(penColor_).c_str(),&pen,&image()->exception);
OpaquePaintImage ( image(), &opaque, &pen, MagickFalse );
throwImageException();
}
// Ping is similar to read except only enough of the image is read to
// determine the image columns, rows, and filesize. Access the
// columns(), rows(), and fileSize() attributes after invoking ping.
// The image data is not valid after calling ping.
void Magick::Image::ping ( const std::string &imageSpec_ )
{
options()->fileName( imageSpec_ );
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
PingImage( imageInfo(), &exceptionInfo );
replaceImage( image );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Ping is similar to read except only enough of the image is read
// to determine the image columns, rows, and filesize. Access the
// columns(), rows(), and fileSize() attributes after invoking
// ping. The image data is not valid after calling ping.
void Magick::Image::ping ( const Blob& blob_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
PingBlob( imageInfo(), blob_.data(), blob_.length(), &exceptionInfo );
replaceImage( image );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Execute a named process module using an argc/argv syntax similar to
// that accepted by a C 'main' routine. An exception is thrown if the
// requested process module doesn't exist, fails to load, or fails during
// execution.
void Magick::Image::process( std::string name_, const ssize_t argc, const char **argv )
{
modifyImage();
size_t status =
InvokeDynamicImageFilter( name_.c_str(), &image(), argc, argv,
&image()->exception );
if (status == false)
throwException( image()->exception );
}
// Quantize colors in image using current quantization settings
// Set measureError_ to true in order to measure quantization error
void Magick::Image::quantize ( const bool measureError_ )
{
modifyImage();
if (measureError_)
options()->quantizeInfo()->measure_error=MagickTrue;
else
options()->quantizeInfo()->measure_error=MagickFalse;
QuantizeImage( options()->quantizeInfo(), image() );
throwImageException();
}
// Apply an arithmetic or bitwise operator to the image pixel quantums.
void Magick::Image::quantumOperator ( const ChannelType channel_,
const MagickEvaluateOperator operator_,
double rvalue_)
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
EvaluateImageChannel( image(), channel_, operator_, rvalue_, &exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::quantumOperator ( const ssize_t x_,const ssize_t y_,
const size_t columns_,
const size_t rows_,
const ChannelType channel_,
const MagickEvaluateOperator operator_,
const double rvalue_)
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
RectangleInfo geometry;
geometry.width = columns_;
geometry.height = rows_;
geometry.x = x_;
geometry.y = y_;
MagickCore::Image *crop_image = CropImage( image(), &geometry,
&exceptionInfo );
EvaluateImageChannel( crop_image, channel_, operator_, rvalue_,
&exceptionInfo );
(void) CompositeImage( image(), image()->matte != MagickFalse ?
OverCompositeOp : CopyCompositeOp, crop_image, geometry.x, geometry.y );
crop_image = DestroyImageList(crop_image);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Raise image (lighten or darken the edges of an image to give a 3-D
// raised or lowered effect)
void Magick::Image::raise ( const Geometry &geometry_ ,
const bool raisedFlag_ )
{
RectangleInfo raiseInfo = geometry_;
modifyImage();
RaiseImage ( image(), &raiseInfo, raisedFlag_ == true ? MagickTrue : MagickFalse );
throwImageException();
}
// Random threshold image.
//
// Changes the value of individual pixels based on the intensity
// of each pixel compared to a random threshold. The result is a
// low-contrast, two color image. The thresholds_ argument is a
// geometry containing LOWxHIGH thresholds. If the string
// contains 2x2, 3x3, or 4x4, then an ordered dither of order 2,
// 3, or 4 will be performed instead. If a channel_ argument is
// specified then only the specified channel is altered. This is
// a very fast alternative to 'quantize' based dithering.
void Magick::Image::randomThreshold( const Geometry &thresholds_ )
{
randomThresholdChannel(thresholds_,DefaultChannels);
}
void Magick::Image::randomThresholdChannel( const Geometry &thresholds_,
const ChannelType channel_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
modifyImage();
(void) RandomThresholdImageChannel( image(),
channel_,
static_cast<std::string>(thresholds_).c_str(),
&exceptionInfo );
throwImageException();
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Read image into current object
void Magick::Image::read ( const std::string &imageSpec_ )
{
options()->fileName( imageSpec_ );
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
ReadImage( imageInfo(), &exceptionInfo );
// Ensure that multiple image frames were not read.
if ( image && image->next )
{
// Destroy any extra image frames
MagickCore::Image* next = image->next;
image->next = 0;
next->previous = 0;
DestroyImageList( next );
}
if ( image )
{
(void) DestroyExceptionInfo( &exceptionInfo );
throwException( image->exception );
}
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
replaceImage( image );
}
// Read image of specified size into current object
void Magick::Image::read ( const Geometry &size_,
const std::string &imageSpec_ )
{
size( size_ );
read( imageSpec_ );
}
// Read image from in-memory BLOB
void Magick::Image::read ( const Blob &blob_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
BlobToImage( imageInfo(),
static_cast<const void *>(blob_.data()),
blob_.length(), &exceptionInfo );
replaceImage( image );
throwException( exceptionInfo );
if ( image )
throwException( image->exception );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Read image of specified size from in-memory BLOB
void Magick::Image::read ( const Blob &blob_,
const Geometry &size_ )
{
// Set image size
size( size_ );
// Read from Blob
read( blob_ );
}
// Read image of specified size and depth from in-memory BLOB
void Magick::Image::read ( const Blob &blob_,
const Geometry &size_,
const size_t depth_ )
{
// Set image size
size( size_ );
// Set image depth
depth( depth_ );
// Read from Blob
read( blob_ );
}
// Read image of specified size, depth, and format from in-memory BLOB
void Magick::Image::read ( const Blob &blob_,
const Geometry &size_,
const size_t depth_,
const std::string &magick_ )
{
// Set image size
size( size_ );
// Set image depth
depth( depth_ );
// Set image magick
magick( magick_ );
// Set explicit image format
fileName( magick_ + ':');
// Read from Blob
read( blob_ );
}
// Read image of specified size, and format from in-memory BLOB
void Magick::Image::read ( const Blob &blob_,
const Geometry &size_,
const std::string &magick_ )
{
// Set image size
size( size_ );
// Set image magick
magick( magick_ );
// Set explicit image format
fileName( magick_ + ':');
// Read from Blob
read( blob_ );
}
// Read image based on raw pixels in memory (ConstituteImage)
void Magick::Image::read ( const size_t width_,
const size_t height_,
const std::string &map_,
const StorageType type_,
const void *pixels_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
ConstituteImage( width_, height_, map_.c_str(), type_, pixels_,
&exceptionInfo );
replaceImage( image );
throwException( exceptionInfo );
if ( image )
throwException( image->exception );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Reduce noise in image
void Magick::Image::reduceNoise ( const double order_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
StatisticImage( image(), NonpeakStatistic, (size_t) order_, (size_t) order_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Resize image
void Magick::Image::resize( const Geometry &geometry_ )
{
// Calculate new size. This code should be supported using binary arguments
// in the ImageMagick library.
ssize_t x = 0;
ssize_t y = 0;
size_t width = columns();
size_t height = rows();
ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
&x, &y,
&width, &height );
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ResizeImage( image(),
width,
height,
image()->filter,
1.0,
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Roll image
void Magick::Image::roll ( const Geometry &roll_ )
{
ssize_t xOff = roll_.xOff();
if ( roll_.xNegative() )
xOff = 0 - xOff;
ssize_t yOff = roll_.yOff();
if ( roll_.yNegative() )
yOff = 0 - yOff;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
RollImage( image(), xOff, yOff, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::roll ( const size_t columns_,
const size_t rows_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
RollImage( image(),
static_cast<ssize_t>(columns_),
static_cast<ssize_t>(rows_), &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Rotate image
void Magick::Image::rotate ( const double degrees_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
RotateImage( image(), degrees_, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Sample image
void Magick::Image::sample ( const Geometry &geometry_ )
{
ssize_t x = 0;
ssize_t y = 0;
size_t width = columns();
size_t height = rows();
ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
&x, &y,
&width, &height );
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
SampleImage( image(), width, height, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Scale image
void Magick::Image::scale ( const Geometry &geometry_ )
{
ssize_t x = 0;
ssize_t y = 0;
size_t width = columns();
size_t height = rows();
ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
&x, &y,
&width, &height );
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ScaleImage( image(), width, height, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Segment (coalesce similar image components) by analyzing the
// histograms of the color components and identifying units that are
// homogeneous with the fuzzy c-means technique.
void Magick::Image::segment ( const double clusterThreshold_,
const double smoothingThreshold_ )
{
modifyImage();
SegmentImage ( image(),
options()->quantizeColorSpace(),
(MagickBooleanType) options()->verbose(),
clusterThreshold_,
smoothingThreshold_ );
throwImageException();
SyncImage( image() );
throwImageException();
}
// Shade image using distant light source
void Magick::Image::shade ( const double azimuth_,
const double elevation_,
const bool colorShading_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ShadeImage( image(),
colorShading_ == true ? MagickTrue : MagickFalse,
azimuth_,
elevation_,
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Simulate an image shadow
void Magick::Image::shadow( const double percent_opacity_, const double sigma_,
const ssize_t x_, const ssize_t y_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage = ShadowImage( image(), percent_opacity_, sigma_,
x_, y_, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Sharpen pixels in image
void Magick::Image::sharpen ( const double radius_, const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
SharpenImage( image(),
radius_,
sigma_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::sharpenChannel ( const ChannelType channel_,
const double radius_, const double sigma_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
SharpenImageChannel( image(),
channel_,
radius_,
sigma_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Shave pixels from image edges.
void Magick::Image::shave ( const Geometry &geometry_ )
{
RectangleInfo shaveInfo = geometry_;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ShaveImage( image(),
&shaveInfo,
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Shear image
void Magick::Image::shear ( const double xShearAngle_,
const double yShearAngle_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ShearImage( image(),
xShearAngle_,
yShearAngle_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Contrast image
void Magick::Image::sigmoidalContrast ( const size_t sharpen_, const double contrast, const double midpoint )
{
modifyImage();
(void) SigmoidalContrastImageChannel( image(), DefaultChannels, (MagickBooleanType) sharpen_, contrast, midpoint );
throwImageException();
}
// Solarize image (similar to effect seen when exposing a photographic
// film to light during the development process)
void Magick::Image::solarize ( const double factor_ )
{
modifyImage();
SolarizeImage ( image(), factor_ );
throwImageException();
}
// Sparse color image, given a set of coordinates, interpolates the colors
// found at those coordinates, across the whole image, using various methods.
//
void Magick::Image::sparseColor ( const ChannelType channel,
const SparseColorMethod method,
const size_t number_arguments,
const double *arguments )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage = SparseColorImage ( image(), channel, method,
number_arguments, arguments, &exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Spread pixels randomly within image by specified ammount
void Magick::Image::spread ( const size_t amount_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
SpreadImage( image(),
amount_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Add a digital watermark to the image (based on second image)
void Magick::Image::stegano ( const Image &watermark_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
SteganoImage( image(),
watermark_.constImage(),
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Stereo image (left image is current image)
void Magick::Image::stereo ( const Image &rightImage_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
StereoImage( image(),
rightImage_.constImage(),
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Swirl image
void Magick::Image::swirl ( const double degrees_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
SwirlImage( image(), degrees_,
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Texture image
void Magick::Image::texture ( const Image &texture_ )
{
modifyImage();
TextureImage( image(), texture_.constImage() );
throwImageException();
}
// Threshold image
void Magick::Image::threshold ( const double threshold_ )
{
modifyImage();
BilevelImage( image(), threshold_ );
throwImageException();
}
// Transform image based on image geometry only
void Magick::Image::transform ( const Geometry &imageGeometry_ )
{
modifyImage();
TransformImage ( &(image()), 0,
std::string(imageGeometry_).c_str() );
throwImageException();
}
// Transform image based on image and crop geometries
void Magick::Image::transform ( const Geometry &imageGeometry_,
const Geometry &cropGeometry_ )
{
modifyImage();
TransformImage ( &(image()), std::string(cropGeometry_).c_str(),
std::string(imageGeometry_).c_str() );
throwImageException();
}
// Add matte image to image, setting pixels matching color to transparent
void Magick::Image::transparent ( const Color &color_ )
{
if ( !color_.isValid() )
{
throwExceptionExplicit( OptionError,
"Color argument is invalid" );
}
std::string color = color_;
MagickPixelPacket target;
(void) QueryMagickColor(std::string(color_).c_str(),&target,&image()->exception);
modifyImage();
TransparentPaintImage ( image(), &target, TransparentOpacity, MagickFalse );
throwImageException();
}
// Add matte image to image, setting pixels matching color to transparent
void Magick::Image::transparentChroma(const Color &colorLow_,
const Color &colorHigh_)
{
if ( !colorLow_.isValid() || !colorHigh_.isValid() )
{
throwExceptionExplicit( OptionError,
"Color argument is invalid" );
}
std::string colorLow = colorLow_;
std::string colorHigh = colorHigh_;
MagickPixelPacket targetLow;
MagickPixelPacket targetHigh;
(void) QueryMagickColor(std::string(colorLow_).c_str(),&targetLow,
&image()->exception);
(void) QueryMagickColor(std::string(colorHigh_).c_str(),&targetHigh,
&image()->exception);
modifyImage();
TransparentPaintImageChroma ( image(), &targetLow, &targetHigh,
TransparentOpacity, MagickFalse );
throwImageException();
}
// Trim edges that are the background color from the image
void Magick::Image::trim ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
TrimImage( image(), &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Replace image with a sharpened version of the original image
// using the unsharp mask algorithm.
// radius_
// the radius of the Gaussian, in pixels, not counting the
// center pixel.
// sigma_
// the standard deviation of the Gaussian, in pixels.
// amount_
// the percentage of the difference between the original and
// the blur image that is added back into the original.
// threshold_
// the threshold in pixels needed to apply the diffence amount.
void Magick::Image::unsharpmask ( const double radius_,
const double sigma_,
const double amount_,
const double threshold_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
UnsharpMaskImage( image(),
radius_,
sigma_,
amount_,
threshold_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::unsharpmaskChannel ( const ChannelType channel_,
const double radius_,
const double sigma_,
const double amount_,
const double threshold_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
UnsharpMaskImageChannel( image(),
channel_,
radius_,
sigma_,
amount_,
threshold_,
&exceptionInfo );
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Map image pixels to a sine wave
void Magick::Image::wave ( const double amplitude_, const double wavelength_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
WaveImage( image(),
amplitude_,
wavelength_,
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Write image to file
void Magick::Image::write( const std::string &imageSpec_ )
{
modifyImage();
fileName( imageSpec_ );
WriteImage( imageInfo(), image() );
throwImageException();
}
// Write image to in-memory BLOB
void Magick::Image::write ( Blob *blob_ )
{
modifyImage();
size_t length = 2048; // Efficient size for small images
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
void* data = ImageToBlob( imageInfo(),
image(),
&length,
&exceptionInfo);
throwException( exceptionInfo );
blob_->updateNoCopy( data, length, Blob::MallocAllocator );
throwImageException();
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::write ( Blob *blob_,
const std::string &magick_ )
{
modifyImage();
magick(magick_);
size_t length = 2048; // Efficient size for small images
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
void* data = ImageToBlob( imageInfo(),
image(),
&length,
&exceptionInfo);
throwException( exceptionInfo );
blob_->updateNoCopy( data, length, Blob::MallocAllocator );
throwImageException();
(void) DestroyExceptionInfo( &exceptionInfo );
}
void Magick::Image::write ( Blob *blob_,
const std::string &magick_,
const size_t depth_ )
{
modifyImage();
magick(magick_);
depth(depth_);
size_t length = 2048; // Efficient size for small images
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
void* data = ImageToBlob( imageInfo(),
image(),
&length,
&exceptionInfo);
throwException( exceptionInfo );
blob_->updateNoCopy( data, length, Blob::MallocAllocator );
throwImageException();
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Write image to an array of pixels with storage type specified
// by user (ExportImagePixels), e.g.
// image.write( 0, 0, 640, 1, "RGB", 0, pixels );
void Magick::Image::write ( const ssize_t x_,
const ssize_t y_,
const size_t columns_,
const size_t rows_,
const std::string &map_,
const StorageType type_,
void *pixels_ )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
ExportImagePixels( image(), x_, y_, columns_, rows_, map_.c_str(), type_,
pixels_,
&exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Zoom image
void Magick::Image::zoom( const Geometry &geometry_ )
{
// Calculate new size. This code should be supported using binary arguments
// in the ImageMagick library.
ssize_t x = 0;
ssize_t y = 0;
size_t width = columns();
size_t height = rows();
ParseMetaGeometry (static_cast<std::string>(geometry_).c_str(),
&x, &y,
&width, &height );
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
ResizeImage( image(),
width,
height,
image()->filter,
image()->blur,
&exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
/*
* Methods for setting image attributes
*
*/
// Join images into a single multi-image file
void Magick::Image::adjoin ( const bool flag_ )
{
modifyImage();
options()->adjoin( flag_ );
}
bool Magick::Image::adjoin ( void ) const
{
return constOptions()->adjoin();
}
// Remove pixel aliasing
void Magick::Image::antiAlias( const bool flag_ )
{
modifyImage();
options()->antiAlias( static_cast<size_t>(flag_) );
}
bool Magick::Image::antiAlias( void )
{
return static_cast<bool>( options()->antiAlias( ) );
}
// Animation inter-frame delay
void Magick::Image::animationDelay ( const size_t delay_ )
{
modifyImage();
image()->delay = delay_;
}
size_t Magick::Image::animationDelay ( void ) const
{
return constImage()->delay;
}
// Number of iterations to play animation
void Magick::Image::animationIterations ( const size_t iterations_ )
{
modifyImage();
image()->iterations = iterations_;
}
size_t Magick::Image::animationIterations ( void ) const
{
return constImage()->iterations;
}
// Access/Update a named image attribute
void Magick::Image::attribute ( const std::string name_,
const std::string value_ )
{
modifyImage();
SetImageProperty( image(), name_.c_str(), value_.c_str() );
}
std::string Magick::Image::attribute ( const std::string name_ )
{
const char *value = GetImageProperty( constImage(), name_.c_str() );
if ( value )
return std::string( value );
return std::string(); // Intentionally no exception
}
// Background color
void Magick::Image::backgroundColor ( const Color &backgroundColor_ )
{
modifyImage();
if ( backgroundColor_.isValid() )
{
image()->background_color = backgroundColor_;
}
else
{
image()->background_color = Color();
}
options()->backgroundColor( backgroundColor_ );
}
Magick::Color Magick::Image::backgroundColor ( void ) const
{
return constOptions()->backgroundColor( );
}
// Background fill texture
void Magick::Image::backgroundTexture ( const std::string &backgroundTexture_ )
{
modifyImage();
options()->backgroundTexture( backgroundTexture_ );
}
std::string Magick::Image::backgroundTexture ( void ) const
{
return constOptions()->backgroundTexture( );
}
// Original image columns
size_t Magick::Image::baseColumns ( void ) const
{
return constImage()->magick_columns;
}
// Original image name
std::string Magick::Image::baseFilename ( void ) const
{
return std::string(constImage()->magick_filename);
}
// Original image rows
size_t Magick::Image::baseRows ( void ) const
{
return constImage()->magick_rows;
}
// Border color
void Magick::Image::borderColor ( const Color &borderColor_ )
{
modifyImage();
if ( borderColor_.isValid() )
{
image()->border_color = borderColor_;
}
else
{
image()->border_color = Color();
}
options()->borderColor( borderColor_ );
}
Magick::Color Magick::Image::borderColor ( void ) const
{
return constOptions()->borderColor( );
}
// Return smallest bounding box enclosing non-border pixels. The
// current fuzz value is used when discriminating between pixels.
// This is the crop bounding box used by crop(Geometry(0,0));
Magick::Geometry Magick::Image::boundingBox ( void ) const
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
RectangleInfo bbox = GetImageBoundingBox( constImage(), &exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return Geometry( bbox );
}
// Text bounding-box base color
void Magick::Image::boxColor ( const Color &boxColor_ )
{
modifyImage();
options()->boxColor( boxColor_ );
}
Magick::Color Magick::Image::boxColor ( void ) const
{
return constOptions()->boxColor( );
}
// Pixel cache threshold. Once this threshold is exceeded, all
// subsequent pixels cache operations are to/from disk.
// This setting is shared by all Image objects.
/* static */
void Magick::Image::cacheThreshold ( const size_t threshold_ )
{
SetMagickResourceLimit( MemoryResource, threshold_ );
}
void Magick::Image::chromaBluePrimary ( const double x_, const double y_ )
{
modifyImage();
image()->chromaticity.blue_primary.x = x_;
image()->chromaticity.blue_primary.y = y_;
}
void Magick::Image::chromaBluePrimary ( double *x_, double *y_ ) const
{
*x_ = constImage()->chromaticity.blue_primary.x;
*y_ = constImage()->chromaticity.blue_primary.y;
}
void Magick::Image::chromaGreenPrimary ( const double x_, const double y_ )
{
modifyImage();
image()->chromaticity.green_primary.x = x_;
image()->chromaticity.green_primary.y = y_;
}
void Magick::Image::chromaGreenPrimary ( double *x_, double *y_ ) const
{
*x_ = constImage()->chromaticity.green_primary.x;
*y_ = constImage()->chromaticity.green_primary.y;
}
void Magick::Image::chromaRedPrimary ( const double x_, const double y_ )
{
modifyImage();
image()->chromaticity.red_primary.x = x_;
image()->chromaticity.red_primary.y = y_;
}
void Magick::Image::chromaRedPrimary ( double *x_, double *y_ ) const
{
*x_ = constImage()->chromaticity.red_primary.x;
*y_ = constImage()->chromaticity.red_primary.y;
}
void Magick::Image::chromaWhitePoint ( const double x_, const double y_ )
{
modifyImage();
image()->chromaticity.white_point.x = x_;
image()->chromaticity.white_point.y = y_;
}
void Magick::Image::chromaWhitePoint ( double *x_, double *y_ ) const
{
*x_ = constImage()->chromaticity.white_point.x;
*y_ = constImage()->chromaticity.white_point.y;
}
// Set image storage class
void Magick::Image::classType ( const ClassType class_ )
{
if ( classType() == PseudoClass && class_ == DirectClass )
{
// Use SyncImage to synchronize the DirectClass pixels with the
// color map and then set to DirectClass type.
modifyImage();
SyncImage( image() );
image()->colormap = (PixelPacket *)
RelinquishMagickMemory( image()->colormap );
image()->storage_class = static_cast<MagickCore::ClassType>(DirectClass);
return;
}
if ( classType() == DirectClass && class_ == PseudoClass )
{
// Quantize to create PseudoClass color map
modifyImage();
quantizeColors(MaxColormapSize);
quantize();
image()->storage_class = static_cast<MagickCore::ClassType>(PseudoClass);
}
}
// Associate a clip mask with the image. The clip mask must be the
// same dimensions as the image. Pass an invalid image to unset an
// existing clip mask.
void Magick::Image::clipMask ( const Magick::Image & clipMask_ )
{
modifyImage();
if( clipMask_.isValid() )
{
// Set clip mask
SetImageClipMask( image(), clipMask_.constImage() );
}
else
{
// Unset existing clip mask
SetImageClipMask( image(), 0 );
}
}
Magick::Image Magick::Image::clipMask ( void ) const
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
GetImageClipMask( constImage(), &exceptionInfo );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return Magick::Image( image );
}
void Magick::Image::colorFuzz ( const double fuzz_ )
{
modifyImage();
image()->fuzz = fuzz_;
options()->colorFuzz( fuzz_ );
}
double Magick::Image::colorFuzz ( void ) const
{
return constOptions()->colorFuzz( );
}
// Set color in colormap at index
void Magick::Image::colorMap ( const size_t index_,
const Color &color_ )
{
MagickCore::Image* imageptr = image();
if (index_ > (MaxColormapSize-1) )
throwExceptionExplicit( OptionError,
"Colormap index must be less than MaxColormapSize" );
if ( !color_.isValid() )
throwExceptionExplicit( OptionError,
"Color argument is invalid");
modifyImage();
// Ensure that colormap size is large enough
if ( colorMapSize() < (index_+1) )
colorMapSize( index_ + 1 );
// Set color at index in colormap
(imageptr->colormap)[index_] = color_;
}
// Return color in colormap at index
Magick::Color Magick::Image::colorMap ( const size_t index_ ) const
{
const MagickCore::Image* imageptr = constImage();
if ( !imageptr->colormap )
throwExceptionExplicit( OptionError,
"Image does not contain a colormap");
if ( index_ > imageptr->colors-1 )
throwExceptionExplicit( OptionError,
"Index out of range");
return Magick::Color( (imageptr->colormap)[index_] );
}
// Colormap size (number of colormap entries)
void Magick::Image::colorMapSize ( const size_t entries_ )
{
if (entries_ >MaxColormapSize )
throwExceptionExplicit( OptionError,
"Colormap entries must not exceed MaxColormapSize" );
modifyImage();
MagickCore::Image* imageptr = image();
if( !imageptr->colormap )
{
// Allocate colormap
imageptr->colormap =
static_cast<PixelPacket*>(AcquireMagickMemory(entries_*sizeof(PixelPacket)));
imageptr->colors = 0;
}
else if ( entries_ > imageptr->colors )
{
// Re-allocate colormap
imageptr->colormap=(PixelPacket *)
ResizeMagickMemory(imageptr->colormap,(entries_)*sizeof(PixelPacket));
}
// Initialize any new colormap entries as all black
Color black(0,0,0);
for( size_t i=imageptr->colors; i<(entries_-1); i++ )
(imageptr->colormap)[i] = black;
imageptr->colors = entries_;
}
size_t Magick::Image::colorMapSize ( void )
{
const MagickCore::Image* imageptr = constImage();
if ( !imageptr->colormap )
throwExceptionExplicit( OptionError,
"Image does not contain a colormap");
return imageptr->colors;
}
// Image colorspace
void Magick::Image::colorSpace( const ColorspaceType colorSpace_ )
{
// Nothing to do?
if ( image()->colorspace == colorSpace_ )
return;
modifyImage();
TransformRGBImage( image(), colorSpace_ );
throwImageException();
}
Magick::ColorspaceType Magick::Image::colorSpace ( void ) const
{
return constImage()->colorspace;
}
// Set image colorspace type.
void Magick::Image::colorspaceType( const ColorspaceType colorSpace_ )
{
modifyImage();
options()->colorspaceType( colorSpace_ );
}
Magick::ColorspaceType Magick::Image::colorspaceType ( void ) const
{
return constOptions()->colorspaceType();
}
// Comment string
void Magick::Image::comment ( const std::string &comment_ )
{
modifyImage();
SetImageProperty( image(), "Comment", NULL );
if ( comment_.length() > 0 )
SetImageProperty( image(), "Comment", comment_.c_str() );
throwImageException();
}
std::string Magick::Image::comment ( void ) const
{
const char *value = GetImageProperty( constImage(), "Comment" );
if ( value )
return std::string( value );
return std::string(); // Intentionally no exception
}
// Composition operator to be used when composition is implicitly used
// (such as for image flattening).
void Magick::Image::compose (const CompositeOperator compose_)
{
image()->compose=compose_;
}
Magick::CompositeOperator Magick::Image::compose ( void ) const
{
return constImage()->compose;
}
// Compression algorithm
void Magick::Image::compressType ( const CompressionType compressType_ )
{
modifyImage();
image()->compression = compressType_;
options()->compressType( compressType_ );
}
Magick::CompressionType Magick::Image::compressType ( void ) const
{
return constImage()->compression;
}
// Enable printing of debug messages from ImageMagick
void Magick::Image::debug ( const bool flag_ )
{
modifyImage();
options()->debug( flag_ );
}
bool Magick::Image::debug ( void ) const
{
return constOptions()->debug();
}
// Tagged image format define (set/access coder-specific option) The
// magick_ option specifies the coder the define applies to. The key_
// option provides the key specific to that coder. The value_ option
// provides the value to set (if any). See the defineSet() method if the
// key must be removed entirely.
void Magick::Image::defineValue ( const std::string &magick_,
const std::string &key_,
const std::string &value_ )
{
modifyImage();
std::string format = magick_ + ":" + key_;
std::string option = value_;
(void) SetImageOption ( imageInfo(), format.c_str(), option.c_str() );
}
std::string Magick::Image::defineValue ( const std::string &magick_,
const std::string &key_ ) const
{
std::string definition = magick_ + ":" + key_;
const char *option =
GetImageOption ( constImageInfo(), definition.c_str() );
if (option)
return std::string( option );
return std::string( );
}
// Tagged image format define. Similar to the defineValue() method
// except that passing the flag_ value 'true' creates a value-less
// define with that format and key. Passing the flag_ value 'false'
// removes any existing matching definition. The method returns 'true'
// if a matching key exists, and 'false' if no matching key exists.
void Magick::Image::defineSet ( const std::string &magick_,
const std::string &key_,
bool flag_ )
{
modifyImage();
std::string definition = magick_ + ":" + key_;
if (flag_)
{
(void) SetImageOption ( imageInfo(), definition.c_str(), "" );
}
else
{
DeleteImageOption( imageInfo(), definition.c_str() );
}
}
bool Magick::Image::defineSet ( const std::string &magick_,
const std::string &key_ ) const
{
std::string key = magick_ + ":" + key_;
const char *option =
GetImageOption ( constImageInfo(), key.c_str() );
if (option)
return true;
return false;
}
// Pixel resolution
void Magick::Image::density ( const Geometry &density_ )
{
modifyImage();
options()->density( density_ );
if ( density_.isValid() )
{
image()->x_resolution = density_.width();
if ( density_.height() != 0 )
{
image()->y_resolution = density_.height();
}
else
{
image()->y_resolution = density_.width();
}
}
else
{
// Reset to default
image()->x_resolution = 0;
image()->y_resolution = 0;
}
}
Magick::Geometry Magick::Image::density ( void ) const
{
if (isValid())
{
ssize_t x_resolution=72;
ssize_t y_resolution=72;
if (constImage()->x_resolution > 0.0)
x_resolution=static_cast<ssize_t>(constImage()->x_resolution + 0.5);
if (constImage()->y_resolution > 0.0)
y_resolution=static_cast<ssize_t>(constImage()->y_resolution + 0.5);
return Geometry(x_resolution,y_resolution);
}
return constOptions()->density( );
}
// Image depth (bits allocated to red/green/blue components)
void Magick::Image::depth ( const size_t depth_ )
{
size_t depth = depth_;
if (depth > MAGICKCORE_QUANTUM_DEPTH)
depth=MAGICKCORE_QUANTUM_DEPTH;
modifyImage();
image()->depth=depth;
options()->depth( depth );
}
size_t Magick::Image::depth ( void ) const
{
return constImage()->depth;
}
std::string Magick::Image::directory ( void ) const
{
if ( constImage()->directory )
return std::string( constImage()->directory );
throwExceptionExplicit( CorruptImageWarning,
"Image does not contain a directory");
return std::string();
}
// Endianness (little like Intel or big like SPARC) for image
// formats which support endian-specific options.
void Magick::Image::endian ( const Magick::EndianType endian_ )
{
modifyImage();
options()->endian( endian_ );
image()->endian = endian_;
}
Magick::EndianType Magick::Image::endian ( void ) const
{
return constImage()->endian;
}
// EXIF profile (BLOB)
void Magick::Image::exifProfile( const Magick::Blob &exifProfile_ )
{
modifyImage();
if ( exifProfile_.data() != 0 )
{
StringInfo * exif_profile = AcquireStringInfo( exifProfile_.length() );
SetStringInfoDatum(exif_profile ,(unsigned char *) exifProfile_.data());
(void) SetImageProfile( image(), "exif", exif_profile);
exif_profile =DestroyStringInfo( exif_profile );
}
}
Magick::Blob Magick::Image::exifProfile( void ) const
{
const StringInfo * exif_profile = GetImageProfile( constImage(), "exif" );
if ( exif_profile == (StringInfo *) NULL)
return Blob( 0, 0 );
return Blob(GetStringInfoDatum(exif_profile),GetStringInfoLength(exif_profile));
}
// Image file name
void Magick::Image::fileName ( const std::string &fileName_ )
{
modifyImage();
fileName_.copy( image()->filename,
sizeof(image()->filename) - 1 );
image()->filename[ fileName_.length() ] = 0; // Null terminate
options()->fileName( fileName_ );
}
std::string Magick::Image::fileName ( void ) const
{
return constOptions()->fileName( );
}
// Image file size
off_t Magick::Image::fileSize ( void ) const
{
return (off_t) GetBlobSize( constImage() );
}
// Color to use when drawing inside an object
void Magick::Image::fillColor ( const Magick::Color &fillColor_ )
{
modifyImage();
options()->fillColor(fillColor_);
}
Magick::Color Magick::Image::fillColor ( void ) const
{
return constOptions()->fillColor();
}
// Rule to use when filling drawn objects
void Magick::Image::fillRule ( const Magick::FillRule &fillRule_ )
{
modifyImage();
options()->fillRule(fillRule_);
}
Magick::FillRule Magick::Image::fillRule ( void ) const
{
return constOptions()->fillRule();
}
// Pattern to use while filling drawn objects.
void Magick::Image::fillPattern ( const Image &fillPattern_ )
{
modifyImage();
if(fillPattern_.isValid())
options()->fillPattern( fillPattern_.constImage() );
else
options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
}
Magick::Image Magick::Image::fillPattern ( void ) const
{
// FIXME: This is inordinately innefficient
Image texture;
const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
if ( tmpTexture )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
CloneImage( tmpTexture,
0, // columns
0, // rows
MagickTrue, // orphan
&exceptionInfo);
texture.replaceImage( image );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
return texture;
}
// Filter used by zoom
void Magick::Image::filterType ( const Magick::FilterTypes filterType_ )
{
modifyImage();
image()->filter = filterType_;
}
Magick::FilterTypes Magick::Image::filterType ( void ) const
{
return constImage()->filter;
}
// Font name
void Magick::Image::font ( const std::string &font_ )
{
modifyImage();
options()->font( font_ );
}
std::string Magick::Image::font ( void ) const
{
return constOptions()->font( );
}
// Font point size
void Magick::Image::fontPointsize ( const double pointSize_ )
{
modifyImage();
options()->fontPointsize( pointSize_ );
}
double Magick::Image::fontPointsize ( void ) const
{
return constOptions()->fontPointsize( );
}
// Font type metrics
void Magick::Image::fontTypeMetrics( const std::string &text_,
TypeMetric *metrics )
{
DrawInfo *drawInfo = options()->drawInfo();
drawInfo->text = const_cast<char *>(text_.c_str());
GetTypeMetrics( image(), drawInfo, &(metrics->_typeMetric) );
drawInfo->text = 0;
}
// Image format string
std::string Magick::Image::format ( void ) const
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
const MagickInfo * magick_info
= GetMagickInfo( constImage()->magick, &exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
if (( magick_info != 0 ) &&
( *magick_info->description != '\0' ))
return std::string(magick_info->description);
throwExceptionExplicit( CorruptImageWarning,
"Unrecognized image magick type" );
return std::string();
}
// Gamma adjustment
double Magick::Image::gamma ( void ) const
{
return constImage()->gamma;
}
Magick::Geometry Magick::Image::geometry ( void ) const
{
if ( constImage()->geometry )
{
return Geometry(constImage()->geometry);
}
throwExceptionExplicit( OptionWarning,
"Image does not contain a geometry");
return Geometry();
}
void Magick::Image::gifDisposeMethod ( const size_t disposeMethod_ )
{
modifyImage();
image()->dispose = (DisposeType) disposeMethod_;
}
size_t Magick::Image::gifDisposeMethod ( void ) const
{
// FIXME: It would be better to return an enumeration
return constImage()->dispose;
}
// ICC ICM color profile (BLOB)
void Magick::Image::iccColorProfile( const Magick::Blob &colorProfile_ )
{
profile("icm",colorProfile_);
}
Magick::Blob Magick::Image::iccColorProfile( void ) const
{
const StringInfo * color_profile = GetImageProfile( constImage(), "icc" );
if ( color_profile == (StringInfo *) NULL)
return Blob( 0, 0 );
return Blob( GetStringInfoDatum(color_profile), GetStringInfoLength(color_profile) );
}
void Magick::Image::interlaceType ( const Magick::InterlaceType interlace_ )
{
modifyImage();
image()->interlace = interlace_;
options()->interlaceType ( interlace_ );
}
Magick::InterlaceType Magick::Image::interlaceType ( void ) const
{
return constImage()->interlace;
}
// IPTC profile (BLOB)
void Magick::Image::iptcProfile( const Magick::Blob &iptcProfile_ )
{
modifyImage();
if ( iptcProfile_.data() != 0 )
{
StringInfo * iptc_profile = AcquireStringInfo( iptcProfile_.length() );
SetStringInfoDatum(iptc_profile ,(unsigned char *) iptcProfile_.data());
(void) SetImageProfile( image(), "iptc", iptc_profile);
iptc_profile =DestroyStringInfo( iptc_profile );
}
}
Magick::Blob Magick::Image::iptcProfile( void ) const
{
const StringInfo * iptc_profile = GetImageProfile( constImage(), "iptc" );
if ( iptc_profile == (StringInfo *) NULL)
return Blob( 0, 0 );
return Blob( GetStringInfoDatum(iptc_profile), GetStringInfoLength(iptc_profile));
}
// Does object contain valid image?
void Magick::Image::isValid ( const bool isValid_ )
{
if ( !isValid_ )
{
delete _imgRef;
_imgRef = new ImageRef;
}
else if ( !isValid() )
{
// Construct with single-pixel black image to make
// image valid. This is an obvious hack.
size( Geometry(1,1) );
read( "xc:#000000" );
}
}
bool Magick::Image::isValid ( void ) const
{
if ( rows() && columns() )
return true;
return false;
}
// Label image
void Magick::Image::label ( const std::string &label_ )
{
modifyImage();
SetImageProperty ( image(), "Label", NULL );
if ( label_.length() > 0 )
SetImageProperty ( image(), "Label", label_.c_str() );
throwImageException();
}
std::string Magick::Image::label ( void ) const
{
const char *value = GetImageProperty( constImage(), "Label" );
if ( value )
return std::string( value );
return std::string();
}
void Magick::Image::magick ( const std::string &magick_ )
{
modifyImage();
magick_.copy( image()->magick,
sizeof(image()->magick) - 1 );
image()->magick[ magick_.length() ] = 0;
options()->magick( magick_ );
}
std::string Magick::Image::magick ( void ) const
{
if ( *(constImage()->magick) != '\0' )
return std::string(constImage()->magick);
return constOptions()->magick( );
}
void Magick::Image::matte ( const bool matteFlag_ )
{
modifyImage();
// If matte channel is requested, but image doesn't already have a
// matte channel, then create an opaque matte channel. Likewise, if
// the image already has a matte channel but a matte channel is not
// desired, then set the matte channel to opaque.
if ((matteFlag_ && !constImage()->matte) ||
(constImage()->matte && !matteFlag_))
SetImageOpacity(image(),OpaqueOpacity);
image()->matte = (MagickBooleanType) matteFlag_;
}
bool Magick::Image::matte ( void ) const
{
if ( constImage()->matte )
return true;
else
return false;
}
void Magick::Image::matteColor ( const Color &matteColor_ )
{
modifyImage();
if ( matteColor_.isValid() )
{
image()->matte_color = matteColor_;
options()->matteColor( matteColor_ );
}
else
{
// Set to default matte color
Color tmpColor( "#BDBDBD" );
image()->matte_color = tmpColor;
options()->matteColor( tmpColor );
}
}
Magick::Color Magick::Image::matteColor ( void ) const
{
return Color( constImage()->matte_color.red,
constImage()->matte_color.green,
constImage()->matte_color.blue );
}
double Magick::Image::meanErrorPerPixel ( void ) const
{
return(constImage()->error.mean_error_per_pixel);
}
// Image modulus depth (minimum number of bits required to support
// red/green/blue components without loss of accuracy)
void Magick::Image::modulusDepth ( const size_t depth_ )
{
modifyImage();
SetImageDepth( image(), depth_ );
options()->depth( depth_ );
}
size_t Magick::Image::modulusDepth ( void ) const
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
size_t depth=GetImageDepth( constImage(), &exceptionInfo );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return depth;
}
void Magick::Image::monochrome ( const bool monochromeFlag_ )
{
modifyImage();
options()->monochrome( monochromeFlag_ );
}
bool Magick::Image::monochrome ( void ) const
{
return constOptions()->monochrome( );
}
Magick::Geometry Magick::Image::montageGeometry ( void ) const
{
if ( constImage()->montage )
return Magick::Geometry(constImage()->montage);
throwExceptionExplicit( CorruptImageWarning,
"Image does not contain a montage" );
return Magick::Geometry();
}
double Magick::Image::normalizedMaxError ( void ) const
{
return(constImage()->error.normalized_maximum_error);
}
double Magick::Image::normalizedMeanError ( void ) const
{
return constImage()->error.normalized_mean_error;
}
// Image orientation
void Magick::Image::orientation ( const Magick::OrientationType orientation_ )
{
modifyImage();
image()->orientation = orientation_;
}
Magick::OrientationType Magick::Image::orientation ( void ) const
{
return constImage()->orientation;
}
void Magick::Image::penColor ( const Color &penColor_ )
{
modifyImage();
options()->fillColor(penColor_);
options()->strokeColor(penColor_);
}
Magick::Color Magick::Image::penColor ( void ) const
{
return constOptions()->fillColor();
}
void Magick::Image::penTexture ( const Image &penTexture_ )
{
modifyImage();
if(penTexture_.isValid())
options()->fillPattern( penTexture_.constImage() );
else
options()->fillPattern( static_cast<MagickCore::Image*>(NULL) );
}
Magick::Image Magick::Image::penTexture ( void ) const
{
// FIXME: This is inordinately innefficient
Image texture;
const MagickCore::Image* tmpTexture = constOptions()->fillPattern( );
if ( tmpTexture )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
CloneImage( tmpTexture,
0, // columns
0, // rows
MagickTrue, // orphan
&exceptionInfo);
texture.replaceImage( image );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
return texture;
}
// Set the color of a pixel.
void Magick::Image::pixelColor ( const ssize_t x_, const ssize_t y_,
const Color &color_ )
{
// Test arguments to ensure they are within the image.
if ( y_ > (ssize_t) rows() || x_ > (ssize_t) columns() )
throwExceptionExplicit( OptionError,
"Access outside of image boundary" );
modifyImage();
// Set image to DirectClass
classType( DirectClass );
// Get pixel view
Pixels pixels(*this);
// Set pixel value
*(pixels.get(x_, y_, 1, 1 )) = color_;
// Tell ImageMagick that pixels have been updated
pixels.sync();
return;
}
// Get the color of a pixel
Magick::Color Magick::Image::pixelColor ( const ssize_t x_,
const ssize_t y_ ) const
{
ClassType storage_class;
storage_class = classType();
// DirectClass
const PixelPacket* pixel = getConstPixels( x_, y_, 1, 1 );
if ( storage_class == DirectClass )
{
if ( pixel )
return Color( *pixel );
}
// PseudoClass
if ( storage_class == PseudoClass )
{
const IndexPacket* indexes = getConstIndexes();
if ( indexes )
return colorMap( (size_t) *indexes );
}
return Color(); // invalid
}
// Preferred size and location of an image canvas.
void Magick::Image::page ( const Magick::Geometry &pageSize_ )
{
modifyImage();
options()->page( pageSize_ );
image()->page = pageSize_;
}
Magick::Geometry Magick::Image::page ( void ) const
{
return Geometry( constImage()->page.width,
constImage()->page.height,
AbsoluteValue(constImage()->page.x),
AbsoluteValue(constImage()->page.y),
constImage()->page.x < 0 ? true : false,
constImage()->page.y < 0 ? true : false);
}
// Add a named profile to an image or remove a named profile by
// passing an empty Blob (use default Blob constructor).
// Valid names are:
// "*", "8BIM", "ICM", "IPTC", or a generic profile name.
void Magick::Image::profile( const std::string name_,
const Magick::Blob &profile_ )
{
modifyImage();
ssize_t result = ProfileImage( image(), name_.c_str(),
(unsigned char *)profile_.data(),
profile_.length(), MagickTrue);
if( !result )
throwImageException();
}
// Retrieve a named profile from the image.
// Valid names are:
// "8BIM", "8BIMTEXT", "APP1", "APP1JPEG", "ICC", "ICM", & "IPTC" or
// an existing generic profile name.
Magick::Blob Magick::Image::profile( const std::string name_ ) const
{
const MagickCore::Image* image = constImage();
const StringInfo * profile = GetImageProfile( image, name_.c_str() );
if ( profile != (StringInfo *) NULL)
return Blob( (void*) GetStringInfoDatum(profile), GetStringInfoLength(profile));
Blob blob;
Image temp_image = *this;
temp_image.write( &blob, name_ );
return blob;
}
void Magick::Image::quality ( const size_t quality_ )
{
modifyImage();
image()->quality = quality_;
options()->quality( quality_ );
}
size_t Magick::Image::quality ( void ) const
{
return constImage()->quality;
}
void Magick::Image::quantizeColors ( const size_t colors_ )
{
modifyImage();
options()->quantizeColors( colors_ );
}
size_t Magick::Image::quantizeColors ( void ) const
{
return constOptions()->quantizeColors( );
}
void Magick::Image::quantizeColorSpace
( const Magick::ColorspaceType colorSpace_ )
{
modifyImage();
options()->quantizeColorSpace( colorSpace_ );
}
Magick::ColorspaceType Magick::Image::quantizeColorSpace ( void ) const
{
return constOptions()->quantizeColorSpace( );
}
void Magick::Image::quantizeDither ( const bool ditherFlag_ )
{
modifyImage();
options()->quantizeDither( ditherFlag_ );
}
bool Magick::Image::quantizeDither ( void ) const
{
return constOptions()->quantizeDither( );
}
void Magick::Image::quantizeTreeDepth ( const size_t treeDepth_ )
{
modifyImage();
options()->quantizeTreeDepth( treeDepth_ );
}
size_t Magick::Image::quantizeTreeDepth ( void ) const
{
return constOptions()->quantizeTreeDepth( );
}
void Magick::Image::renderingIntent
( const Magick::RenderingIntent renderingIntent_ )
{
modifyImage();
image()->rendering_intent = renderingIntent_;
}
Magick::RenderingIntent Magick::Image::renderingIntent ( void ) const
{
return static_cast<Magick::RenderingIntent>(constImage()->rendering_intent);
}
void Magick::Image::resolutionUnits
( const Magick::ResolutionType resolutionUnits_ )
{
modifyImage();
image()->units = resolutionUnits_;
options()->resolutionUnits( resolutionUnits_ );
}
Magick::ResolutionType Magick::Image::resolutionUnits ( void ) const
{
return constOptions()->resolutionUnits( );
}
void Magick::Image::scene ( const size_t scene_ )
{
modifyImage();
image()->scene = scene_;
}
size_t Magick::Image::scene ( void ) const
{
return constImage()->scene;
}
std::string Magick::Image::signature ( const bool force_ ) const
{
Lock( &_imgRef->_mutexLock );
// Re-calculate image signature if necessary
if ( force_ ||
!GetImageProperty(constImage(), "Signature") ||
constImage()->taint )
{
SignatureImage( const_cast<MagickCore::Image *>(constImage()) );
}
const char *property = GetImageProperty(constImage(), "Signature");
return std::string( property );
}
void Magick::Image::size ( const Geometry &geometry_ )
{
modifyImage();
options()->size( geometry_ );
image()->rows = geometry_.height();
image()->columns = geometry_.width();
}
Magick::Geometry Magick::Image::size ( void ) const
{
return Magick::Geometry( constImage()->columns, constImage()->rows );
}
// Splice image
void Magick::Image::splice( const Geometry &geometry_ )
{
RectangleInfo spliceInfo = geometry_;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* newImage =
SpliceImage( image(), &spliceInfo, &exceptionInfo);
replaceImage( newImage );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Obtain image statistics. Statistics are normalized to the range of
// 0.0 to 1.0 and are output to the specified ImageStatistics
// structure.
void Magick::Image::statistics ( ImageStatistics *statistics ) const
{
double
maximum,
minimum;
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
(void) GetImageChannelRange(constImage(),RedChannel,&minimum,&maximum,
&exceptionInfo);
statistics->red.minimum=minimum;
statistics->red.maximum=maximum;
(void) GetImageChannelMean(constImage(),RedChannel,
&statistics->red.mean,&statistics->red.standard_deviation,&exceptionInfo);
(void) GetImageChannelKurtosis(constImage(),RedChannel,
&statistics->red.kurtosis,&statistics->red.skewness,&exceptionInfo);
(void) GetImageChannelRange(constImage(),GreenChannel,&minimum,&maximum,
&exceptionInfo);
statistics->green.minimum=minimum;
statistics->green.maximum=maximum;
(void) GetImageChannelMean(constImage(),GreenChannel,
&statistics->green.mean,&statistics->green.standard_deviation,
&exceptionInfo);
(void) GetImageChannelKurtosis(constImage(),GreenChannel,
&statistics->green.kurtosis,&statistics->green.skewness,&exceptionInfo);
(void) GetImageChannelRange(constImage(),BlueChannel,&minimum,&maximum,
&exceptionInfo);
statistics->blue.minimum=minimum;
statistics->blue.maximum=maximum;
(void) GetImageChannelMean(constImage(),BlueChannel,
&statistics->blue.mean,&statistics->blue.standard_deviation,&exceptionInfo);
(void) GetImageChannelKurtosis(constImage(),BlueChannel,
&statistics->blue.kurtosis,&statistics->blue.skewness,&exceptionInfo);
(void) GetImageChannelRange(constImage(),OpacityChannel,&minimum,&maximum,
&exceptionInfo);
statistics->opacity.minimum=minimum;
statistics->opacity.maximum=maximum;
(void) GetImageChannelMean(constImage(),OpacityChannel,
&statistics->opacity.mean,&statistics->opacity.standard_deviation,
&exceptionInfo);
(void) GetImageChannelKurtosis(constImage(),OpacityChannel,
&statistics->opacity.kurtosis,&statistics->opacity.skewness,&exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Strip strips an image of all profiles and comments.
void Magick::Image::strip ( void )
{
modifyImage();
StripImage( image() );
throwImageException();
}
// enabled/disable stroke anti-aliasing
void Magick::Image::strokeAntiAlias ( const bool flag_ )
{
modifyImage();
options()->strokeAntiAlias(flag_);
}
bool Magick::Image::strokeAntiAlias ( void ) const
{
return constOptions()->strokeAntiAlias();
}
// Color to use when drawing object outlines
void Magick::Image::strokeColor ( const Magick::Color &strokeColor_ )
{
modifyImage();
options()->strokeColor(strokeColor_);
}
Magick::Color Magick::Image::strokeColor ( void ) const
{
return constOptions()->strokeColor();
}
// dash pattern for drawing vector objects (default one)
void Magick::Image::strokeDashArray ( const double* strokeDashArray_ )
{
modifyImage();
options()->strokeDashArray( strokeDashArray_ );
}
const double* Magick::Image::strokeDashArray ( void ) const
{
return constOptions()->strokeDashArray( );
}
// dash offset for drawing vector objects (default one)
void Magick::Image::strokeDashOffset ( const double strokeDashOffset_ )
{
modifyImage();
options()->strokeDashOffset( strokeDashOffset_ );
}
double Magick::Image::strokeDashOffset ( void ) const
{
return constOptions()->strokeDashOffset( );
}
// Specify the shape to be used at the end of open subpaths when they
// are stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap,
// and SquareCap.
void Magick::Image::strokeLineCap ( const Magick::LineCap lineCap_ )
{
modifyImage();
options()->strokeLineCap( lineCap_ );
}
Magick::LineCap Magick::Image::strokeLineCap ( void ) const
{
return constOptions()->strokeLineCap( );
}
// Specify the shape to be used at the corners of paths (or other
// vector shapes) when they are stroked. Values of LineJoin are
// UndefinedJoin, MiterJoin, RoundJoin, and BevelJoin.
void Magick::Image::strokeLineJoin ( const Magick::LineJoin lineJoin_ )
{
modifyImage();
options()->strokeLineJoin( lineJoin_ );
}
Magick::LineJoin Magick::Image::strokeLineJoin ( void ) const
{
return constOptions()->strokeLineJoin( );
}
// Specify miter limit. When two line segments meet at a sharp angle
// and miter joins have been specified for 'lineJoin', it is possible
// for the miter to extend far beyond the thickness of the line
// stroking the path. The miterLimit' imposes a limit on the ratio of
// the miter length to the 'lineWidth'. The default value of this
// parameter is 4.
void Magick::Image::strokeMiterLimit ( const size_t strokeMiterLimit_ )
{
modifyImage();
options()->strokeMiterLimit( strokeMiterLimit_ );
}
size_t Magick::Image::strokeMiterLimit ( void ) const
{
return constOptions()->strokeMiterLimit( );
}
// Pattern to use while stroking drawn objects.
void Magick::Image::strokePattern ( const Image &strokePattern_ )
{
modifyImage();
if(strokePattern_.isValid())
options()->strokePattern( strokePattern_.constImage() );
else
options()->strokePattern( static_cast<MagickCore::Image*>(NULL) );
}
Magick::Image Magick::Image::strokePattern ( void ) const
{
// FIXME: This is inordinately innefficient
Image texture;
const MagickCore::Image* tmpTexture = constOptions()->strokePattern( );
if ( tmpTexture )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
MagickCore::Image* image =
CloneImage( tmpTexture,
0, // columns
0, // rows
MagickTrue, // orphan
&exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
texture.replaceImage( image );
}
return texture;
}
// Stroke width for drawing lines, circles, ellipses, etc.
void Magick::Image::strokeWidth ( const double strokeWidth_ )
{
modifyImage();
options()->strokeWidth( strokeWidth_ );
}
double Magick::Image::strokeWidth ( void ) const
{
return constOptions()->strokeWidth( );
}
void Magick::Image::subImage ( const size_t subImage_ )
{
modifyImage();
options()->subImage( subImage_ );
}
size_t Magick::Image::subImage ( void ) const
{
return constOptions()->subImage( );
}
void Magick::Image::subRange ( const size_t subRange_ )
{
modifyImage();
options()->subRange( subRange_ );
}
size_t Magick::Image::subRange ( void ) const
{
return constOptions()->subRange( );
}
// Annotation text encoding (e.g. "UTF-16")
void Magick::Image::textEncoding ( const std::string &encoding_ )
{
modifyImage();
options()->textEncoding( encoding_ );
}
std::string Magick::Image::textEncoding ( void ) const
{
return constOptions()->textEncoding( );
}
void Magick::Image::tileName ( const std::string &tileName_ )
{
modifyImage();
options()->tileName( tileName_ );
}
std::string Magick::Image::tileName ( void ) const
{
return constOptions()->tileName( );
}
size_t Magick::Image::totalColors ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
size_t colors = GetNumberColors( image(), 0, &exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return colors;
}
// Origin of coordinate system to use when annotating with text or drawing
void Magick::Image::transformOrigin ( const double x_, const double y_ )
{
modifyImage();
options()->transformOrigin( x_, y_ );
}
// Rotation to use when annotating with text or drawing
void Magick::Image::transformRotation ( const double angle_ )
{
modifyImage();
options()->transformRotation( angle_ );
}
// Reset transformation parameters to default
void Magick::Image::transformReset ( void )
{
modifyImage();
options()->transformReset();
}
// Scale to use when annotating with text or drawing
void Magick::Image::transformScale ( const double sx_, const double sy_ )
{
modifyImage();
options()->transformScale( sx_, sy_ );
}
// Skew to use in X axis when annotating with text or drawing
void Magick::Image::transformSkewX ( const double skewx_ )
{
modifyImage();
options()->transformSkewX( skewx_ );
}
// Skew to use in Y axis when annotating with text or drawing
void Magick::Image::transformSkewY ( const double skewy_ )
{
modifyImage();
options()->transformSkewY( skewy_ );
}
// Image representation type
Magick::ImageType Magick::Image::type ( void ) const
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
ImageType image_type = constOptions()->type();
if ( image_type == UndefinedType )
image_type= GetImageType( constImage(), &exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return image_type;
}
void Magick::Image::type ( const Magick::ImageType type_)
{
modifyImage();
options()->type( type_ );
SetImageType( image(), type_ );
}
void Magick::Image::verbose ( const bool verboseFlag_ )
{
modifyImage();
options()->verbose( verboseFlag_ );
}
bool Magick::Image::verbose ( void ) const
{
return constOptions()->verbose( );
}
void Magick::Image::view ( const std::string &view_ )
{
modifyImage();
options()->view( view_ );
}
std::string Magick::Image::view ( void ) const
{
return constOptions()->view( );
}
// Virtual pixel method
void Magick::Image::virtualPixelMethod ( const VirtualPixelMethod virtual_pixel_method_ )
{
modifyImage();
SetImageVirtualPixelMethod( image(), virtual_pixel_method_ );
options()->virtualPixelMethod( virtual_pixel_method_ );
}
Magick::VirtualPixelMethod Magick::Image::virtualPixelMethod ( void ) const
{
return GetImageVirtualPixelMethod( constImage() );
}
void Magick::Image::x11Display ( const std::string &display_ )
{
modifyImage();
options()->x11Display( display_ );
}
std::string Magick::Image::x11Display ( void ) const
{
return constOptions()->x11Display( );
}
double Magick::Image::xResolution ( void ) const
{
return constImage()->x_resolution;
}
double Magick::Image::yResolution ( void ) const
{
return constImage()->y_resolution;
}
// Copy Constructor
Magick::Image::Image( const Image & image_ )
: _imgRef(image_._imgRef)
{
Lock( &_imgRef->_mutexLock );
// Increase reference count
++_imgRef->_refCount;
}
// Assignment operator
Magick::Image& Magick::Image::operator=( const Magick::Image &image_ )
{
if( this != &image_ )
{
{
Lock( &image_._imgRef->_mutexLock );
++image_._imgRef->_refCount;
}
bool doDelete = false;
{
Lock( &_imgRef->_mutexLock );
if ( --_imgRef->_refCount == 0 )
doDelete = true;
}
if ( doDelete )
{
// Delete old image reference with associated image and options.
delete _imgRef;
_imgRef = 0;
}
// Use new image reference
_imgRef = image_._imgRef;
}
return *this;
}
//////////////////////////////////////////////////////////////////////
//
// Low-level Pixel Access Routines
//
// Also see the Pixels class, which provides support for multiple
// cache views. The low-level pixel access routines in the Image
// class are provided in order to support backward compatability.
//
//////////////////////////////////////////////////////////////////////
// Transfers read-only pixels from the image to the pixel cache as
// defined by the specified region
const Magick::PixelPacket* Magick::Image::getConstPixels
( const ssize_t x_, const ssize_t y_,
const size_t columns_,
const size_t rows_ ) const
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
const PixelPacket* p = (*GetVirtualPixels)( constImage(),
x_, y_,
columns_, rows_,
&exceptionInfo );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return p;
}
// Obtain read-only pixel indexes (valid for PseudoClass images)
const Magick::IndexPacket* Magick::Image::getConstIndexes ( void ) const
{
const Magick::IndexPacket* result = GetVirtualIndexQueue( constImage() );
if( !result )
throwImageException();
return result;
}
// Obtain image pixel indexes (valid for PseudoClass images)
Magick::IndexPacket* Magick::Image::getIndexes ( void )
{
Magick::IndexPacket* result = GetAuthenticIndexQueue( image() );
if( !result )
throwImageException();
return ( result );
}
// Transfers pixels from the image to the pixel cache as defined
// by the specified region. Modified pixels may be subsequently
// transferred back to the image via syncPixels.
Magick::PixelPacket* Magick::Image::getPixels ( const ssize_t x_, const ssize_t y_,
const size_t columns_,
const size_t rows_ )
{
modifyImage();
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
PixelPacket* result = (*GetAuthenticPixels)( image(),
x_, y_,
columns_, rows_, &exceptionInfo );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return result;
}
// Allocates a pixel cache region to store image pixels as defined
// by the region rectangle. This area is subsequently transferred
// from the pixel cache to the image via syncPixels.
Magick::PixelPacket* Magick::Image::setPixels ( const ssize_t x_, const ssize_t y_,
const size_t columns_,
const size_t rows_ )
{
modifyImage();
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
PixelPacket* result = (*QueueAuthenticPixels)( image(),
x_, y_,
columns_, rows_, &exceptionInfo );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return result;
}
// Transfers the image cache pixels to the image.
void Magick::Image::syncPixels ( void )
{
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
(*SyncAuthenticPixels)( image(), &exceptionInfo );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
// Transfers one or more pixel components from a buffer or file
// into the image pixel cache of an image.
// Used to support image decoders.
void Magick::Image::readPixels ( const Magick::QuantumType quantum_,
const unsigned char *source_ )
{
QuantumInfo
*quantum_info;
quantum_info=AcquireQuantumInfo(imageInfo(),image());
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
ImportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
quantum_,source_, &exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
quantum_info=DestroyQuantumInfo(quantum_info);
}
// Transfers one or more pixel components from the image pixel
// cache to a buffer or file.
// Used to support image encoders.
void Magick::Image::writePixels ( const Magick::QuantumType quantum_,
unsigned char *destination_ )
{
QuantumInfo
*quantum_info;
quantum_info=AcquireQuantumInfo(imageInfo(),image());
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
ExportQuantumPixels(image(),(MagickCore::CacheView *) NULL,quantum_info,
quantum_,destination_, &exceptionInfo);
quantum_info=DestroyQuantumInfo(quantum_info);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
/////////////////////////////////////////////////////////////////////
//
// No end-user methods beyond this point
//
/////////////////////////////////////////////////////////////////////
//
// Construct using existing image and default options
//
Magick::Image::Image ( MagickCore::Image* image_ )
: _imgRef(new ImageRef( image_))
{
}
// Get Magick::Options*
Magick::Options* Magick::Image::options( void )
{
return _imgRef->options();
}
const Magick::Options* Magick::Image::constOptions( void ) const
{
return _imgRef->options();
}
// Get MagickCore::Image*
MagickCore::Image*& Magick::Image::image( void )
{
return _imgRef->image();
}
const MagickCore::Image* Magick::Image::constImage( void ) const
{
return _imgRef->image();
}
// Get ImageInfo *
MagickCore::ImageInfo* Magick::Image::imageInfo( void )
{
return _imgRef->options()->imageInfo();
}
const MagickCore::ImageInfo * Magick::Image::constImageInfo( void ) const
{
return _imgRef->options()->imageInfo();
}
// Get QuantizeInfo *
MagickCore::QuantizeInfo* Magick::Image::quantizeInfo( void )
{
return _imgRef->options()->quantizeInfo();
}
const MagickCore::QuantizeInfo * Magick::Image::constQuantizeInfo( void ) const
{
return _imgRef->options()->quantizeInfo();
}
//
// Replace current image
//
MagickCore::Image * Magick::Image::replaceImage
( MagickCore::Image* replacement_ )
{
MagickCore::Image* image;
if( replacement_ )
image = replacement_;
else
image = AcquireImage(constImageInfo());
{
Lock( &_imgRef->_mutexLock );
if ( _imgRef->_refCount == 1 )
{
// We own the image, just replace it, and de-register
_imgRef->id( -1 );
_imgRef->image(image);
}
else
{
// We don't own the image, dereference and replace with copy
--_imgRef->_refCount;
_imgRef = new ImageRef( image, constOptions() );
}
}
return _imgRef->_image;
}
//
// Prepare to modify image or image options
// Replace current image and options with copy if reference count > 1
//
void Magick::Image::modifyImage( void )
{
{
Lock( &_imgRef->_mutexLock );
if ( _imgRef->_refCount == 1 )
{
// De-register image and return
_imgRef->id( -1 );
return;
}
}
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
replaceImage( CloneImage( image(),
0, // columns
0, // rows
MagickTrue, // orphan
&exceptionInfo) );
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
return;
}
//
// Test for an ImageMagick reported error and throw exception if one
// has been reported. Secretly resets image->exception back to default
// state even though this method is const.
//
void Magick::Image::throwImageException( void ) const
{
// Throw C++ exception while resetting Image exception to default state
throwException( const_cast<MagickCore::Image*>(constImage())->exception );
}
// Register image with image registry or obtain registration id
ssize_t Magick::Image::registerId( void )
{
Lock( &_imgRef->_mutexLock );
if( _imgRef->id() < 0 )
{
char id[MaxTextExtent];
ExceptionInfo exceptionInfo;
GetExceptionInfo( &exceptionInfo );
_imgRef->id(_imgRef->id()+1);
sprintf(id,"%.20g\n",(double) _imgRef->id());
SetImageRegistry(ImageRegistryType, id, image(), &exceptionInfo);
throwException( exceptionInfo );
(void) DestroyExceptionInfo( &exceptionInfo );
}
return _imgRef->id();
}
// Unregister image from image registry
void Magick::Image::unregisterId( void )
{
modifyImage();
_imgRef->id( -1 );
}
//
// Create a local wrapper around MagickCoreTerminus
//
namespace Magick
{
extern "C" {
void MagickPlusPlusDestroyMagick(void);
}
}
void Magick::MagickPlusPlusDestroyMagick(void)
{
if (magick_initialized)
{
magick_initialized=false;
MagickCore::MagickCoreTerminus();
}
}
// C library initialization routine
void MagickPPExport Magick::InitializeMagick(const char *path_)
{
MagickCore::MagickCoreGenesis(path_,MagickFalse);
if (!magick_initialized)
magick_initialized=true;
}
//
// Cleanup class to ensure that ImageMagick singletons are destroyed
// so as to avoid any resemblence to a memory leak (which seems to
// confuse users)
//
namespace Magick
{
class MagickCleanUp
{
public:
MagickCleanUp( void );
~MagickCleanUp( void );
};
// The destructor for this object is invoked when the destructors for
// static objects in this translation unit are invoked.
static MagickCleanUp magickCleanUpGuard;
}
Magick::MagickCleanUp::MagickCleanUp ( void )
{
// Don't even think about invoking InitializeMagick here!
}
Magick::MagickCleanUp::~MagickCleanUp ( void )
{
MagickPlusPlusDestroyMagick();
}
|