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
|
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* newsprint plug-in
* Copyright (C) 1997-1998 Austin Donnelly <austin@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* version 0.60
*
* This plug-in puts an image through a screen at a particular angle
* and lines per inch, to arrive at a newspaper-style effect.
*
* Austin Donnelly <austin@greenend.org.uk>
* http://www.cl.cam.ac.uk/~and1000/newsprint/
*
* Richard Mortier <rmm1002@cam.ac.uk> did the spot_round() function
* with correct tonal balance.
*
* Tim Harris <tim.harris@acm.org> provided valuable feedback on
* pre-press issues.
*
*
* 0.52: 10 Jan 1999 <austin@greenend.org.uk>
* gtk_label_set() -> gtk_label_set_text()
* 0.60: 18 Jun 2001 <austin@gimp.org>
* fixed long-standing bug where newsprint() function in GREYA images
* treated them as RGB (bpp rather than colour_bpp) to select
* colourspace to use. Thanks to warner-gnome.bugzilla@lothar.com for
* spotting this and providing the patch. Bug #52981.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
#ifdef RCSID
static char rcsid[] = "$Id: newsprint.c,v 1.69.2.2 2005/06/21 22:11:36 weskaggs Exp $";
#endif
#define VERSION "v0.60"
/* Some useful macros */
#ifdef DEBUG
#define DEBUG_PRINT(x) printf x
#else
#define DEBUG_PRINT(x)
#endif
/*#define TIMINGS*/
#define TILE_CACHE_SIZE 16
#define SCALE_WIDTH 125
#define DEF_OVERSAMPLE 1 /* default for how much to oversample by */
#define SPOT_PREVIEW_SZ 16
#define PREVIEW_SIZE (2 * SPOT_PREVIEW_SZ + 1)
#define PREVIEW_OVERSAMPLE 3
#define ISNEG(x) (((x) < 0)? 1 : 0)
#define DEG2RAD(d) ((d) * G_PI / 180)
#define CLAMPED_ADD(a, b) (((a)+(b) > 0xff)? 0xff : (a) + (b))
/* Bartlett window supersampling weight function. See table 4.1, page
* 123 of Alan Watt and Mark Watt, Advanced Animation and Rendering
* Techniques, theory and practice. Addison-Wesley, 1992. ISBN
* 0-201-54412-1 */
#define BARTLETT(x,y) (((oversample/2)+1-ABS(x)) * ((oversample/2)+1-ABS(y)))
#define WGT(x,y) wgt[((y+oversample/2)*oversample) + x+oversample/2]
/* colourspaces we can separate to: */
#define CS_GREY 0
#define CS_RGB 1
#define CS_CMYK 2
#define CS_INTENSITY 3
#define NUM_CS 4
#define VALID_CS(x) ((x) >= 0 && (x) <= NUM_CS-1)
/* Spot function related types and definitions */
typedef gdouble spotfn_t (gdouble x, gdouble y);
/* forward declaration of the functions themselves */
static spotfn_t spot_round;
static spotfn_t spot_line;
static spotfn_t spot_diamond;
static spotfn_t spot_PSsquare;
static spotfn_t spot_PSdiamond;
typedef struct
{
const gchar *name; /* function's name */
spotfn_t *fn; /* function itself */
guchar *thresh; /* cached threshold matrix */
gdouble prev_lvl[3]; /* intensities to preview */
guchar *prev_thresh; /* preview-sized threshold matrix */
gint balanced; /* TRUE if spot fn is already balanced */
} spot_info_t;
/* This is all the info needed per spot function. Functions are refered to
* by their index into this array. */
static spot_info_t spotfn_list[] =
{
#define SPOTFN_DOT 0
{
N_("Round"),
spot_round,
NULL,
{ .22, .50, .90 },
NULL,
FALSE
},
{
N_("Line"),
spot_line,
NULL,
{ .15, .50, .80 },
NULL,
FALSE
},
{
N_("Diamond"),
spot_diamond,
NULL,
{ .15, .50, .80 },
NULL,
TRUE
},
{ N_("PS Square (Euclidean Dot)"),
spot_PSsquare,
NULL,
{ .15, .50, .90 },
NULL,
FALSE
},
{
N_("PS Diamond"),
spot_PSdiamond,
NULL,
{ .15, .50, .90 },
NULL,
FALSE
},
/* NULL-name terminates */
{ NULL,
NULL,
NULL,
{ 0.0, 0.0, 0.0 },
NULL,
FALSE
}
};
#define NUM_SPOTFN (G_N_ELEMENTS (spotfn_list))
#define VALID_SPOTFN(x) ((x) >= 0 && (x) < NUM_SPOTFN)
#define THRESH(x,y) (thresh[(y)*width + (x)])
#define THRESHn(n,x,y) ((thresh[n])[(y)*width + (x)])
/* Arguments to filter */
/* Some of these are here merely to save them across calls. They are
* marked as "UI use". Everything else is a valid arg. */
typedef struct
{
/* resolution section: */
gint cell_width;
/* screening section: */
gint colourspace; /* 0: RGB, 1: CMYK, 2: Intensity */
gint k_pullout; /* percentage of black to pull out */
/* grey screen (only used if greyscale drawable) */
gdouble gry_ang;
gint gry_spotfn;
/* red / cyan screen */
gdouble red_ang;
gint red_spotfn;
/* green / magenta screen */
gdouble grn_ang;
gint grn_spotfn;
/* blue / yellow screen */
gdouble blu_ang;
gint blu_spotfn;
/* anti-alias section */
gint oversample; /* 1 == no anti-aliasing, else small odd int */
} NewsprintValues;
/* bits of state used by the UI, but not visible from the PDB */
typedef struct
{
gdouble input_spi; /* input samples per inch */
gdouble output_lpi; /* desired output lines per inch */
gboolean lock_channels; /* changes to one channel affect all */
gboolean preview;
} NewsprintUIValues;
/* state for the preview widgets */
typedef struct
{
GtkWidget *widget; /* preview widget itself */
GtkWidget *label; /* the label below it */
} preview_st;
/* state for the channel notebook pages */
typedef struct _channel_st channel_st;
struct _channel_st
{
GtkWidget *vbox; /* vbox of this channel */
gint *spotfn_num; /* which spotfn the menu is controlling */
preview_st prev[3]; /* state for 3 preview widgets */
GtkObject *angle_adj; /* angle adjustment */
GtkWidget *combo; /* popup for spot function */
GtkWidget *menuitem[NUM_SPOTFN]; /* menuitems for each spot function */
GtkWidget *ch_menuitem; /* menuitem for the channel selector */
gint ch_menu_num; /* this channel's position in the selector */
channel_st *next; /* circular list of channels in locked group */
};
/* State associated with the configuration dialog and passed to its
* callback functions */
typedef struct
{
GtkWidget *pull_table;
GtkObject *pull; /* black pullout percentage */
GtkObject *input_spi;
GtkObject *output_lpi;
GtkObject *cellsize;
GtkWidget *vbox; /* container for screen info */
/* Notebook for the channels (one per colorspace) */
GtkWidget *channel_notebook[NUM_CS];
/* room for up to 4 channels per colourspace */
channel_st *chst[NUM_CS][4];
} NewsprintDialog_st;
/***** Local vars *****/
/* defaults */
/* fixed copy so we can reset them */
static const NewsprintValues factory_defaults =
{
/* resolution stuff */
10, /* cell width */
/* screen setup (default is the classic rosette pattern) */
CS_RGB, /* use RGB, not CMYK or Intensity */
100, /* max pullout */
/* grey/black */
45.0,
SPOTFN_DOT,
/* red/cyan */
15.0,
SPOTFN_DOT,
/* green/magenta */
75.0,
SPOTFN_DOT,
/* blue/yellow */
0.0,
SPOTFN_DOT,
/* anti-alias control */
DEF_OVERSAMPLE
};
static const NewsprintUIValues factory_defaults_ui =
{
72, /* input spi */
7.2, /* output lpi */
FALSE, /* lock channels */
TRUE /* preview */
};
/* Mutable copy for normal use. Initialised in run(). */
static NewsprintValues pvals;
static NewsprintUIValues pvals_ui;
/* channel templates */
typedef struct
{
const gchar *name;
/* pointers to the variables this channel updates */
gdouble *angle;
gint *spotfn;
/* factory defaults for the angle and spot function (as pointers so
* the silly compiler can see they're really constants) */
const gdouble *factory_angle;
const gint *factory_spotfn;
} chan_tmpl;
static const chan_tmpl grey_tmpl[] =
{
{
N_("_Grey"),
&pvals.gry_ang,
&pvals.gry_spotfn,
&factory_defaults.gry_ang,
&factory_defaults.gry_spotfn
},
{ NULL, NULL, NULL, NULL, NULL }
};
static const chan_tmpl rgb_tmpl[] =
{
{
N_("R_ed"),
&pvals.red_ang,
&pvals.red_spotfn,
&factory_defaults.red_ang,
&factory_defaults.red_spotfn
},
{
N_("_Green"),
&pvals.grn_ang,
&pvals.grn_spotfn,
&factory_defaults.grn_ang,
&factory_defaults.grn_spotfn
},
{
N_("_Blue"),
&pvals.blu_ang,
&pvals.blu_spotfn,
&factory_defaults.blu_ang,
&factory_defaults.blu_spotfn
},
{ NULL, NULL, NULL, NULL, NULL }
};
static const chan_tmpl cmyk_tmpl[] =
{
{
N_("C_yan"),
&pvals.red_ang,
&pvals.red_spotfn,
&factory_defaults.red_ang,
&factory_defaults.red_spotfn
},
{
N_("Magen_ta"),
&pvals.grn_ang,
&pvals.grn_spotfn,
&factory_defaults.grn_ang,
&factory_defaults.grn_spotfn
},
{
N_("_Yellow"),
&pvals.blu_ang,
&pvals.blu_spotfn,
&factory_defaults.blu_ang,
&factory_defaults.blu_spotfn
},
{
N_("_Black"),
&pvals.gry_ang,
&pvals.gry_spotfn,
&factory_defaults.gry_ang,
&factory_defaults.gry_spotfn
},
{ NULL, NULL, NULL, NULL, NULL }
};
static const chan_tmpl intensity_tmpl[] =
{
{
N_("Intensity"),
&pvals.gry_ang,
&pvals.gry_spotfn,
&factory_defaults.gry_ang,
&factory_defaults.gry_spotfn
},
{ NULL, NULL, NULL, NULL, NULL }
};
/* cspace_chan_tmpl is indexed by colourspace, and gives an array of
* channel templates for that colourspace */
static const chan_tmpl *cspace_chan_tmpl[] =
{
grey_tmpl,
rgb_tmpl,
cmyk_tmpl,
intensity_tmpl
};
#define NCHANS(x) ((sizeof(x) / sizeof(chan_tmpl)) - 1)
/* cspace_nchans gives a quick way of finding the number of channels
* in a colourspace. Alternatively, if you're walking the channel
* template, you can use the NULL entry at the end to stop. */
static const gint cspace_nchans[] =
{
NCHANS (grey_tmpl),
NCHANS (rgb_tmpl),
NCHANS (cmyk_tmpl),
NCHANS (intensity_tmpl)
};
/* Declare local functions. */
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static gboolean newsprint_dialog (GimpDrawable *drawable);
static void newsprint_cspace_update (GtkWidget *widget,
gpointer data);
static void newsprint_menu_callback (GtkWidget *widget,
gpointer data);
static void angle_callback (GtkAdjustment *adjustment,
gpointer data);
static void lpi_callback (GtkAdjustment *adjustment,
gpointer data);
static void spi_callback (GtkAdjustment *adjustment,
gpointer data);
static void cellsize_callback (GtkAdjustment *adjustment,
gpointer data);
static void newsprint_defaults_callback (GtkWidget *widget,
gpointer data);
static void newsprint (GimpDrawable *drawable,
GimpPreview *preview);
static guchar * spot2thresh (gint type,
gint width);
static void preview_update (channel_st *st);
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run /* run_proc */
};
/***** Functions *****/
MAIN ()
static void
query (void)
{
static GimpParamDef args[]=
{
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
{ GIMP_PDB_IMAGE, "image", "Input image (unused)" },
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
{ GIMP_PDB_INT32, "cell_width", "screen cell width, in pixels" },
{ GIMP_PDB_INT32, "colorspace", "separate to 0:RGB, 1:CMYK, 2:Intensity" },
{ GIMP_PDB_INT32, "k_pullout", "Percentage of black to pullout (CMYK only)" },
{ GIMP_PDB_FLOAT, "gry_ang", "Grey/black screen angle (degrees)" },
{ GIMP_PDB_INT32, "gry_spotfn", "Grey/black spot function (0=dots, 1=lines, 2=diamonds, 3=euclidean dot, 4=PS diamond)" },
{ GIMP_PDB_FLOAT, "red_ang", "Red/cyan screen angle (degrees)" },
{ GIMP_PDB_INT32, "red_spotfn", "Red/cyan spot function (values as gry_spotfn)" },
{ GIMP_PDB_FLOAT, "grn_ang", "Green/magenta screen angle (degrees)" },
{ GIMP_PDB_INT32, "grn_spotfn", "Green/magenta spot function (values as gry_spotfn)" },
{ GIMP_PDB_FLOAT, "blu_ang", "Blue/yellow screen angle (degrees)" },
{ GIMP_PDB_INT32, "blu_spotfn", "Blue/yellow spot function (values as gry_spotfn)" },
{ GIMP_PDB_INT32, "oversample", "how many times to oversample spot fn" }
/* 15 args */
};
gimp_install_procedure ("plug_in_newsprint",
"Re-sample the image to give a newspaper-like effect",
"Halftone the image, trading off resolution to "
"represent colors or grey levels using the process "
"described both in the PostScript language "
"definition, and also by Robert Ulichney, \"Digital "
"halftoning\", MIT Press, 1987.",
"Austin Donnelly",
"Austin Donnelly",
"1998 (" VERSION ")",
N_("Newsprin_t..."),
"RGB*, GRAY*",
GIMP_PLUGIN,
G_N_ELEMENTS (args), 0,
args, NULL);
gimp_plugin_menu_register ("plug_in_newsprint", "<Image>/Filters/Distorts");
}
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[1];
GimpDrawable *drawable;
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
run_mode = param[0].data.d_int32;
INIT_I18N ();
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
/* basic defaults */
pvals = factory_defaults;
pvals_ui = factory_defaults_ui;
/* Get the specified drawable */
drawable = gimp_drawable_get (param[2].data.d_drawable);
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
/* Possibly retrieve data */
gimp_get_data ("plug_in_newsprint", &pvals);
gimp_get_data ("plug_in_newsprint_ui", &pvals_ui);
/* First acquire information with a dialog */
if (! newsprint_dialog (drawable))
{
gimp_drawable_detach (drawable);
return;
}
break;
case GIMP_RUN_NONINTERACTIVE:
/* Make sure all the arguments are there! */
if (nparams != 15)
{
status = GIMP_PDB_CALLING_ERROR;
break;
}
pvals.cell_width = param[3].data.d_int32;
pvals.colourspace = param[4].data.d_int32;
pvals.k_pullout = param[5].data.d_int32;
pvals.gry_ang = param[6].data.d_float;
pvals.gry_spotfn = param[7].data.d_int32;
pvals.red_ang = param[8].data.d_float;
pvals.red_spotfn = param[9].data.d_int32;
pvals.grn_ang = param[10].data.d_float;
pvals.grn_spotfn = param[11].data.d_int32;
pvals.blu_ang = param[12].data.d_float;
pvals.blu_spotfn = param[13].data.d_int32;
pvals.oversample = param[14].data.d_int32;
/* check values are within permitted ranges */
if (!VALID_SPOTFN (pvals.gry_spotfn) ||
!VALID_SPOTFN (pvals.red_spotfn) ||
!VALID_SPOTFN (pvals.grn_spotfn) ||
!VALID_SPOTFN (pvals.blu_spotfn) ||
!VALID_CS (pvals.colourspace) ||
pvals.k_pullout < 0 || pvals.k_pullout > 100)
{
status = GIMP_PDB_CALLING_ERROR;
}
break;
case GIMP_RUN_WITH_LAST_VALS:
/* Possibly retrieve data */
gimp_get_data ("plug_in_newsprint", &pvals);
break;
default:
break;
}
if (status == GIMP_PDB_SUCCESS)
{
/* Make sure that the drawable is gray or RGB color */
if (gimp_drawable_is_rgb (drawable->drawable_id) ||
gimp_drawable_is_gray (drawable->drawable_id))
{
gimp_progress_init (_("Newsprint..."));
/* set the tile cache size */
gimp_tile_cache_ntiles (TILE_CACHE_SIZE);
/* run the newsprint effect */
newsprint (drawable, NULL);
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush ();
/* Store data */
if (run_mode == GIMP_RUN_INTERACTIVE)
{
gimp_set_data ("plug_in_newsprint",
&pvals, sizeof (NewsprintValues));
gimp_set_data ("plug_in_newsprint_ui",
&pvals_ui, sizeof (NewsprintUIValues));
}
}
else
{
/*gimp_message ("newsprint: cannot operate on indexed images");*/
status = GIMP_PDB_EXECUTION_ERROR;
}
}
values[0].data.d_status = status;
gimp_drawable_detach (drawable);
}
/* create new menu state, and the preview widgets for it */
static channel_st *
new_preview (gint *sfn)
{
channel_st *st;
GtkWidget *preview;
GtkWidget *label;
gint i;
st = g_new (channel_st, 1);
st->spotfn_num = sfn;
/* make the preview widgets */
for (i = 0; i < 3; i++)
{
preview = gimp_preview_area_new ();
gtk_widget_set_size_request (preview,
PREVIEW_SIZE, PREVIEW_SIZE);
gtk_widget_show (preview);
g_signal_connect_swapped (preview, "size_allocate",
G_CALLBACK (preview_update), st);
label = gtk_label_new ("");
gtk_widget_show (label);
st->prev[i].widget = preview;
st->prev[i].label = label;
/* st->prev[i].value changed by preview_update */
}
return st;
}
/* the popup menu "st" has changed, so the previews associated with it
* need re-calculation */
static void
preview_update (channel_st *st)
{
gint sfn = *(st->spotfn_num);
preview_st *prev;
gint i;
gint x;
gint y;
gint width = SPOT_PREVIEW_SZ * PREVIEW_OVERSAMPLE;
gint oversample = PREVIEW_OVERSAMPLE;
guchar *thresh;
gchar pct[12];
guchar value;
guchar rgb[3 * PREVIEW_SIZE * PREVIEW_SIZE ];
/* If we don't yet have a preview threshold matrix for this spot
* function, generate one now. */
if (!spotfn_list[sfn].prev_thresh)
{
spotfn_list[sfn].prev_thresh =
spot2thresh (sfn, SPOT_PREVIEW_SZ * PREVIEW_OVERSAMPLE);
}
thresh = spotfn_list[sfn].prev_thresh;
for (i = 0; i < 3; i++)
{
prev = &st->prev[i];
value = spotfn_list[sfn].prev_lvl[i] * 0xff;
for (y = 0; y < PREVIEW_SIZE ; y++)
{
for (x = 0; x < PREVIEW_SIZE ; x++)
{
guint32 sum = 0;
gint sx, sy;
gint tx, ty;
gint rx, ry;
rx = x * PREVIEW_OVERSAMPLE;
ry = y * PREVIEW_OVERSAMPLE;
for (sy = -oversample/2; sy <= oversample/2; sy++)
for (sx = -oversample/2; sx <= oversample/2; sx++)
{
tx = rx+sx;
ty = ry+sy;
while (tx < 0) tx += width;
while (ty < 0) ty += width;
while (tx >= width) tx -= width;
while (ty >= width) ty -= width;
if (value > THRESH (tx, ty))
sum += 0xff * BARTLETT (sx, sy);
}
sum /= BARTLETT (0, 0) * BARTLETT (0, 0);
/* blue lines on cell boundaries */
if ((x % SPOT_PREVIEW_SZ) == 0 ||
(y % SPOT_PREVIEW_SZ) == 0)
{
rgb[(y*PREVIEW_SIZE+x)*3+0] = 0;
rgb[(y*PREVIEW_SIZE+x)*3+1] = 0;
rgb[(y*PREVIEW_SIZE+x)*3+2] = 0xff;
}
else
{
rgb[(y*PREVIEW_SIZE+x)*3+0] = sum;
rgb[(y*PREVIEW_SIZE+x)*3+1] = sum;
rgb[(y*PREVIEW_SIZE+x)*3+2] = sum;
}
}
}
/* redraw preview widget */
gimp_preview_area_draw (GIMP_PREVIEW_AREA (prev->widget),
0, 0, PREVIEW_SIZE, PREVIEW_SIZE,
GIMP_RGB_IMAGE,
rgb,
PREVIEW_SIZE * 3);
g_snprintf (pct, sizeof (pct), "%2d%%",
(int) RINT (spotfn_list[sfn].prev_lvl[i] * 100));
gtk_label_set_text (GTK_LABEL(prev->label), pct);
}
}
static void
newsprint_menu_callback (GtkWidget *widget,
gpointer data)
{
channel_st *st = data;
gint value;
static gboolean in_progress = FALSE;
/* We shouldn't need recursion protection, but if lock_channels is
* set, and gimp_int_combo_box_set_active ever generates a "changed"
* signal, then we'll get back here.
*/
if (in_progress)
{
printf ("newsprint_menu_callback: unexpected recursion: can't happen\n");
return;
}
in_progress = TRUE;
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value);
*(st->spotfn_num) = value;
preview_update (st);
/* ripple the change to the other popups if the channels are
* locked together. */
if (pvals_ui.lock_channels)
{
channel_st *c = st->next;
gint old_value;
while (c != st)
{
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (c->combo), value);
old_value = *(c->spotfn_num);
*(c->spotfn_num) = value;
if (old_value != value)
preview_update (c);
c = c->next;
}
}
in_progress = FALSE;
}
static void
angle_callback (GtkAdjustment *adjustment,
gpointer data)
{
channel_st *st = data;
channel_st *c;
gdouble *angle_ptr;
static gint in_progress = FALSE;
angle_ptr = g_object_get_data (G_OBJECT (adjustment), "angle");
gimp_double_adjustment_update (adjustment, angle_ptr);
if (pvals_ui.lock_channels && !in_progress)
{
in_progress = TRUE;
c = st->next;
while (c != st)
{
gtk_adjustment_set_value (GTK_ADJUSTMENT (c->angle_adj), *angle_ptr);
c = c->next;
}
in_progress = FALSE;
}
}
static void
lpi_callback (GtkAdjustment *adjustment,
gpointer data)
{
NewsprintDialog_st *st = data;
gimp_double_adjustment_update (adjustment, &pvals_ui.output_lpi);
g_signal_handlers_block_by_func (st->cellsize,
cellsize_callback,
data);
gtk_adjustment_set_value (GTK_ADJUSTMENT (st->cellsize),
pvals_ui.input_spi / pvals_ui.output_lpi);
g_signal_handlers_unblock_by_func (st->cellsize,
cellsize_callback,
data);
}
static void
spi_callback (GtkAdjustment *adjustment,
gpointer data)
{
NewsprintDialog_st *st = data;
gimp_double_adjustment_update (adjustment, &pvals_ui.input_spi);
g_signal_handlers_block_by_func (st->output_lpi,
lpi_callback,
data);
gtk_adjustment_set_value (GTK_ADJUSTMENT (st->output_lpi),
pvals_ui.input_spi / pvals.cell_width);
g_signal_handlers_unblock_by_func (st->output_lpi,
lpi_callback,
data);
}
static void
cellsize_callback (GtkAdjustment *adjustment,
gpointer data)
{
NewsprintDialog_st *st = data;
gimp_int_adjustment_update (adjustment, &pvals.cell_width);
g_signal_handlers_block_by_func (st->output_lpi,
lpi_callback,
data);
gtk_adjustment_set_value (GTK_ADJUSTMENT (st->output_lpi),
pvals_ui.input_spi / pvals.cell_width);
g_signal_handlers_unblock_by_func (st->output_lpi,
lpi_callback,
data);
}
static void
newsprint_defaults_callback (GtkWidget *widget,
gpointer data)
{
NewsprintDialog_st *st = data;
gint saved_lock;
gint cspace;
channel_st **chst;
const chan_tmpl *ct;
gint spotfn;
gint c;
/* temporarily turn off channel lock */
saved_lock = pvals_ui.lock_channels;
pvals_ui.lock_channels = FALSE;
/* for each colourspace, reset its channel info */
for (cspace = 0; cspace < NUM_CS; cspace++)
{
chst = st->chst[cspace];
ct = cspace_chan_tmpl[cspace];
/* skip this colourspace if we haven't used it yet */
if (!chst[0])
continue;
c = 0;
while (ct->name)
{
gtk_adjustment_set_value (GTK_ADJUSTMENT (chst[c]->angle_adj),
*(ct->factory_angle));
/* change the popup menu and also activate the menuitem in
* question, in order to run the handler that re-computes
* the preview area */
spotfn = *(ct->factory_spotfn);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (chst[c]->combo),
spotfn);
c++;
ct++;
}
}
pvals_ui.lock_channels = saved_lock;
}
/* Create (but don't yet show) a new vbox for a channel 'widget'.
* Return the channel state, so caller can find the vbox and place it
* in the notebook. */
static channel_st *
new_channel (const chan_tmpl *ct, GtkWidget *preview)
{
GtkSizeGroup *group;
GtkWidget *table;
GtkWidget *hbox;
GtkWidget *hbox2;
GtkWidget *abox;
GtkWidget *label;
spot_info_t *sf;
channel_st *chst;
gint i;
/* create the channel state record */
chst = new_preview (ct->spotfn);
chst->vbox = gtk_vbox_new (FALSE, 6);
gtk_container_set_border_width (GTK_CONTAINER (chst->vbox), 12);
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (chst->vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
/* angle slider */
chst->angle_adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
_("_Angle:"), SCALE_WIDTH, 0,
*ct->angle,
-90, 90, 1, 15, 1,
TRUE, 0, 0,
NULL, NULL);
g_object_set_data (G_OBJECT (chst->angle_adj), "angle", ct->angle);
gtk_size_group_add_widget (group, GIMP_SCALE_ENTRY_LABEL (chst->angle_adj));
g_object_unref (group);
g_signal_connect (chst->angle_adj, "value_changed",
G_CALLBACK (angle_callback),
chst);
g_signal_connect_swapped (chst->angle_adj, "value_changed",
G_CALLBACK (gimp_preview_invalidate),
preview);
/* spot function popup */
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (chst->vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
abox = gtk_alignment_new (0.5, 0.0, 0.0, 0.0);
gtk_box_pack_start (GTK_BOX (hbox), abox, FALSE, FALSE, 0);
gtk_widget_show (abox);
hbox2 = gtk_hbox_new (FALSE, 6);
gtk_container_add (GTK_CONTAINER (abox), hbox2);
gtk_widget_show (hbox2);
label = gtk_label_new_with_mnemonic (_("_Spot function:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
gtk_widget_show (label);
gtk_size_group_add_widget (group, label);
chst->combo = gimp_int_combo_box_new (NULL, 0);
for (sf = spotfn_list, i = 0; sf->name; sf++, i++)
gimp_int_combo_box_append (GIMP_INT_COMBO_BOX (chst->combo),
GIMP_INT_STORE_VALUE, i,
GIMP_INT_STORE_LABEL, gettext (sf->name),
-1);
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (chst->combo),
*ct->spotfn);
g_signal_connect (chst->combo, "changed",
G_CALLBACK (newsprint_menu_callback),
chst);
g_signal_connect_swapped (chst->combo, "changed",
G_CALLBACK (gimp_preview_invalidate),
preview);
gtk_box_pack_start (GTK_BOX (hbox2), chst->combo, FALSE, FALSE, 0);
gtk_widget_show (chst->combo);
/* spot function previews */
{
GtkWidget *sub;
sub = gtk_table_new (2, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (sub), 6);
gtk_table_set_row_spacings (GTK_TABLE (sub), 1);
gtk_box_pack_start (GTK_BOX (hbox), sub, FALSE, FALSE, 0);
for (i = 0; i < 3; i++)
{
gtk_table_attach (GTK_TABLE (sub), chst->prev[i].widget,
i, i+1, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
gtk_table_attach (GTK_TABLE (sub), chst->prev[i].label,
i, i+1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
}
gtk_widget_show (sub);
}
/* fire the update once to make sure we start with something
* in the preview windows */
preview_update (chst);
gtk_widget_show (table);
/* create the menuitem used to select this channel for editing */
chst->ch_menuitem = gtk_menu_item_new_with_label (gettext (ct->name));
/* signal attachment and showing left to caller */
/* deliberately don't show the chst->frame, leave that up to
* the caller */
return chst;
}
/* Make all the channels needed for "colourspace", and fill in
* the respective channel state fields in "st". */
static void
gen_channels (NewsprintDialog_st *st,
gint colourspace,
GtkWidget *preview)
{
const chan_tmpl *ct;
channel_st **chst;
channel_st *base = NULL;
gint i;
chst = st->chst[colourspace];
ct = cspace_chan_tmpl[colourspace];
i = 0;
st->channel_notebook[colourspace] = gtk_notebook_new ();
gtk_box_pack_start (GTK_BOX (st->vbox), st->channel_notebook[colourspace],
FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (st->vbox),
st->channel_notebook[colourspace], 3);
gtk_widget_show (st->channel_notebook[colourspace]);
while (ct->name)
{
chst[i] = new_channel (ct, preview);
if (i)
chst[i-1]->next = chst[i];
else
base = chst[i];
gtk_notebook_append_page (GTK_NOTEBOOK (st->channel_notebook[colourspace]),
chst[i]->vbox,
gtk_label_new_with_mnemonic (gettext (ct->name)));
gtk_widget_show (chst[i]->vbox);
i++;
ct++;
}
/* make the list circular */
chst[i-1]->next = base;
}
static gboolean
newsprint_dialog (GimpDrawable *drawable)
{
/* widgets we need from callbacks stored here */
NewsprintDialog_st st;
GtkWidget *dialog;
GtkWidget *paned;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *preview;
GtkWidget *frame;
GtkWidget *table;
GtkObject *adj;
GSList *group = NULL;
gint bpp;
gint i;
gdouble xres, yres;
gboolean run;
gimp_ui_init ("newsprint", TRUE);
/* flag values to say we haven't filled these channel
* states in yet */
for(i=0; i<NUM_CS; i++)
st.chst[i][0] = NULL;
/* need to know the bpp, so we can tell if we're doing
* RGB/CMYK or grey style of dialog box */
bpp = gimp_drawable_bpp (drawable->drawable_id);
if (gimp_drawable_has_alpha (drawable->drawable_id))
bpp--;
/* force greyscale if it's the only thing we can do */
if (bpp == 1)
{
pvals.colourspace = CS_GREY;
}
else
{
if (pvals.colourspace == CS_GREY)
pvals.colourspace = CS_RGB;
}
dialog = gimp_dialog_new (_("Newsprint"), "newsprint",
NULL, 0,
gimp_standard_help_func, "plug-in-newsprint",
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_OK,
NULL);
paned = gtk_hpaned_new ();
gtk_container_set_border_width (GTK_CONTAINER (paned), 12);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), paned);
gtk_widget_show (paned);
hbox = gtk_hbox_new (FALSE, 0);
gtk_paned_pack1 (GTK_PANED (paned), hbox, TRUE, FALSE);
gtk_widget_show (hbox);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_box_pack_end (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
gtk_widget_show (vbox);
preview = gimp_drawable_preview_new (drawable, &pvals_ui.preview);
gtk_box_pack_start_defaults (GTK_BOX (hbox), preview);
gtk_widget_show (preview);
g_signal_connect_swapped (preview, "invalidated",
G_CALLBACK (newsprint),
drawable);
hbox = gtk_hbox_new (FALSE, 0);
gtk_paned_pack2 (GTK_PANED (paned), hbox, FALSE, FALSE);
gtk_widget_show (hbox);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
gtk_widget_show (vbox);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (hbox), vbox);
gtk_widget_show (vbox);
/* resolution settings */
frame = gimp_frame_new (_("Resolution"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
table = gtk_table_new (3, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
gimp_image_get_resolution (gimp_drawable_get_image (drawable->drawable_id),
&xres, &yres);
/* XXX hack: should really note both resolutions, and use
* rectangular cells, not square cells. But I'm being lazy,
* and the majority of the world works with xres == yres */
pvals_ui.input_spi = xres;
st.input_spi =
gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
_("_Input SPI:"), SCALE_WIDTH, 7,
pvals_ui.input_spi,
1.0, 1200.0, 1.0, 10.0, 0,
FALSE, GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION,
NULL, NULL);
g_signal_connect (st.input_spi, "value_changed",
G_CALLBACK (spi_callback),
&st);
g_signal_connect_swapped (st.input_spi, "value_changed",
G_CALLBACK (gimp_preview_invalidate),
preview);
st.output_lpi =
gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
_("O_utput LPI:"), SCALE_WIDTH, 7,
pvals_ui.output_lpi,
1.0, 1200.0, 1.0, 10.0, 1,
FALSE, GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION,
NULL, NULL);
g_signal_connect (st.output_lpi, "value_changed",
G_CALLBACK (lpi_callback),
&st);
g_signal_connect_swapped (st.output_lpi, "value_changed",
G_CALLBACK (gimp_preview_invalidate),
preview);
st.cellsize = gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
_("C_ell size:"), SCALE_WIDTH, 7,
pvals.cell_width,
3.0, 100.0, 1.0, 5.0, 0,
FALSE, 3.0, GIMP_MAX_IMAGE_SIZE,
NULL, NULL);
g_signal_connect (st.cellsize, "value_changed",
G_CALLBACK (cellsize_callback),
&st);
g_signal_connect_swapped (st.cellsize, "value_changed",
G_CALLBACK (gimp_preview_invalidate),
preview);
/* screen settings */
frame = gimp_frame_new (_("Screen"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
st.vbox = gtk_vbox_new (FALSE, 12);
gtk_container_add (GTK_CONTAINER (frame), st.vbox);
/* optional portion begins */
if (bpp != 1)
{
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *button;
GtkWidget *toggle;
st.pull_table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (st.pull_table), 6);
/* black pullout */
st.pull = gimp_scale_entry_new (GTK_TABLE (st.pull_table), 0, 0,
_("B_lack pullout (%):"), SCALE_WIDTH, 0,
pvals.k_pullout,
0, 100, 1, 10, 0,
TRUE, 0, 0,
NULL, NULL);
gtk_widget_set_sensitive (st.pull_table, (pvals.colourspace == CS_CMYK));
gtk_widget_show (st.pull_table);
g_signal_connect (st.pull, "value_changed",
G_CALLBACK (gimp_int_adjustment_update),
&pvals.k_pullout);
g_signal_connect_swapped (st.pull, "value_changed",
G_CALLBACK (gimp_preview_invalidate),
preview);
/* RGB / CMYK / Intensity select */
hbox = gtk_hbox_new (FALSE, 6);
gtk_box_pack_start (GTK_BOX (st.vbox), hbox, FALSE, FALSE, 0);
/* pack the scaleentry table */
gtk_box_pack_start (GTK_BOX (st.vbox), st.pull_table, FALSE, FALSE, 0);
label = gtk_label_new (_("Separate to:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show(label);
toggle = gtk_radio_button_new_with_mnemonic(group, _("_RGB"));
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
(pvals.colourspace == CS_RGB));
gtk_widget_show (toggle);
g_object_set_data (G_OBJECT (toggle), "dialog", &st);
g_object_set_data (G_OBJECT (toggle), "preview", preview);
g_signal_connect (toggle, "toggled",
G_CALLBACK (newsprint_cspace_update),
GINT_TO_POINTER (CS_RGB));
g_signal_connect_swapped (toggle, "toggled",
G_CALLBACK (gimp_preview_invalidate),
preview);
toggle = gtk_radio_button_new_with_mnemonic (group, _("C_MYK"));
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
(pvals.colourspace == CS_CMYK));
gtk_widget_show (toggle);
g_object_set_data (G_OBJECT (toggle), "dialog", &st);
g_object_set_data (G_OBJECT (toggle), "preview", preview);
g_signal_connect (toggle, "toggled",
G_CALLBACK (newsprint_cspace_update),
GINT_TO_POINTER (CS_CMYK));
g_signal_connect_swapped (toggle, "toggled",
G_CALLBACK (gimp_preview_invalidate),
preview);
toggle = gtk_radio_button_new_with_mnemonic (group, _("I_ntensity"));
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (toggle));
gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
(pvals.colourspace == CS_INTENSITY));
gtk_widget_show (toggle);
g_object_set_data (G_OBJECT (toggle), "dialog", &st);
g_object_set_data (G_OBJECT (toggle), "preview", preview);
g_signal_connect (toggle, "toggled",
G_CALLBACK (newsprint_cspace_update),
GINT_TO_POINTER (CS_INTENSITY));
g_signal_connect_swapped (toggle, "toggled",
G_CALLBACK (gimp_preview_invalidate),
preview);
gtk_widget_show (hbox);
/* channel lock & factory defaults button */
hbox = gtk_hbutton_box_new ();
gtk_box_set_spacing (GTK_BOX (hbox), 6);
gtk_box_pack_start (GTK_BOX (st.vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
toggle = gtk_check_button_new_with_mnemonic (_("_Lock channels"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
pvals_ui.lock_channels);
gtk_box_pack_start (GTK_BOX (hbox), toggle, FALSE, FALSE, 0);
gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&pvals_ui.lock_channels);
g_signal_connect_swapped (toggle, "toggled",
G_CALLBACK (gimp_preview_invalidate),
preview);
button = gtk_button_new_with_mnemonic (_("_Factory defaults"));
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
g_signal_connect (button, "clicked",
G_CALLBACK (newsprint_defaults_callback),
&st);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gimp_preview_invalidate),
preview);
}
/* Make the channels appropriate for this colourspace and
* currently selected defaults. They may have already been
* created as a result of callbacks to cspace_update from
* gtk_toggle_button_set_active().
*/
if (!st.chst[pvals.colourspace][0])
{
gen_channels (&st, pvals.colourspace, preview);
}
gtk_widget_show (st.vbox);
gtk_widget_show (frame);
/* anti-alias control */
frame = gimp_frame_new (_("Antialiasing"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_container_add (GTK_CONTAINER (frame), table);
adj = gimp_scale_entry_new (GTK_TABLE (table), 0, 0,
_("O_versample:"), SCALE_WIDTH, 0,
pvals.oversample,
1.0, 15.0, 1.0, 5.0, 0,
TRUE, 0, 0,
NULL, NULL);
g_signal_connect (adj, "value_changed",
G_CALLBACK (gimp_int_adjustment_update),
&pvals.oversample);
g_signal_connect_swapped (adj, "value_changed",
G_CALLBACK (gimp_preview_invalidate),
preview);
gtk_widget_show (table);
gtk_widget_show (frame);
gtk_widget_show (dialog);
preview_update(st.chst[pvals.colourspace][0]);
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
gtk_widget_destroy (dialog);
return run;
}
/* Newsprint interface functions */
static void
newsprint_cspace_update (GtkWidget *widget,
gpointer data)
{
NewsprintDialog_st *st;
gint new_cs = GPOINTER_TO_INT (data);
gint old_cs = pvals.colourspace;
GtkWidget *preview;
st = g_object_get_data (G_OBJECT (widget), "dialog");
preview = g_object_get_data (G_OBJECT (widget), "preview");
if (!st)
printf ("newsprint: cspace_update: no state, can't happen!\n");
if (st)
{
/* the CMYK widget looks after the black pullout widget */
if (new_cs == CS_CMYK)
{
gtk_widget_set_sensitive (st->pull_table,
GTK_TOGGLE_BUTTON (widget)->active);
}
/* if we're not activate, then there's nothing more to do */
if (!GTK_TOGGLE_BUTTON (widget)->active)
return;
pvals.colourspace = new_cs;
/* make sure we have the necessary channels for the new
* colourspace */
if (!st->chst[new_cs][0])
gen_channels (st, new_cs, preview);
/* hide the old channels (if any) */
if (st->channel_notebook[old_cs])
{
gtk_widget_hide (st->channel_notebook[old_cs]);
}
/* show the new channels */
gtk_widget_show (st->channel_notebook[new_cs]);
gtk_notebook_set_current_page (GTK_NOTEBOOK (st->channel_notebook[new_cs]), 0);
preview_update (st->chst[new_cs][0]);
}
}
/*
* Newsprint Effect
*/
/*************************************************************/
/* Spot functions */
/* Spot functions define the order in which pixels should be whitened
* as a cell lightened in colour. They are defined over the entire
* cell, and are called over each pixel in the cell. The cell
* co-ordinate space ranges from -1.0 .. +1.0 inclusive, in both x- and
* y-axes.
*
* This means the spot function f(x, y) must be defined for:
* -1 <= x <= +1, where x is a real number, and
* -1 <= y <= +1, where y is a real number.
*
* The function f's range is -1.0 .. +1.0 inclusive, but it is
* permissible for f to return values outside this range: the nearest
* valid value will be used instead. NOTE: this is in contrast with
* PostScript spot functions, where it is a RangeError for the spot
* function to go outside these limits.
*
* An initially black cell is filled from lowest spot function value
* to highest. The actual values returned do not matter - it is their
* relative orderings that count. This means that spot functions do
* not need to be tonally balanced. A tonally balanced spot function
* is one which for all slices though the function (eg say at z), the
* area of the slice = 4z. In particular, almost all PostScript spot
* functions are _not_ tonally balanced.
*/
/* The classic growing dot spot function. This one isn't tonally
* balanced. It can be made so, but it's _really_ ugly. Thanks to
* Richard Mortier for this one:
*
* #define a(r) \
* ((r<=1)? G_PI * (r*r) : \
* 4 * sqrt(r*r - 1) + G_PI*r*r - 4*r*r*acos(1/r))
*
* radius = sqrt(x*x + y*y);
*
* return a(radius) / 4; */
static gdouble
spot_round (gdouble x,
gdouble y)
{
return 1 - (x * x + y * y);
}
/* Another commonly seen spot function is the v-shaped wedge. Tonally
* balanced. */
static gdouble
spot_line (gdouble x,
gdouble y)
{
return ABS (y);
}
/* Square/Diamond dot that never becomes round. Tonally balanced. */
static gdouble
spot_diamond (gdouble x,
gdouble y)
{
gdouble xy = ABS (x) + ABS (y);
/* spot only valid for 0 <= xy <= 2 */
return ((xy <= 1) ?
2 * xy * xy :
2 * xy * xy - 4 * (xy - 1) * (xy - 1)) / 4;
}
/* The following two functions are implementations of algorithms
* described in "Postscript Screening: Adobe Accurate Screens"
* (Adobe Press, 1992) by Peter Fink.
*/
/* Square (or Euclidean) dot. Also very common. */
static gdouble
spot_PSsquare (gdouble x,
gdouble y)
{
gdouble ax = ABS (x);
gdouble ay = ABS (y);
return ((ax + ay) > 1 ?
((ay - 1) * (ay - 1) + (ax - 1) * (ax - 1)) - 1 :
1 - (ay * ay + ax * ax));
}
/* Diamond spot function */
static gdouble
spot_PSdiamond (gdouble x,
gdouble y)
{
gdouble ax = ABS (x);
gdouble ay = ABS (y);
return ((ax + ay) <= 0.75 ? 1 - (ax * ax + ay * ay) : /* dot */
((ax + ay) <= 1.23 ? 1 - ((ay * 0.76) + ax) : /* to diamond (0.76 distort) */
((ay - 1) * (ay - 1) + (ax - 1) * (ax - 1)) -1)); /* back to dot */
}
/*************************************************************/
/* Spot function to threshold matrix conversion */
/* Each call of the spot function results in one of these */
typedef struct
{
gint index; /* (y * width) + x */
gdouble value; /* return value of the spot function */
} order_t;
/* qsort(3) compare function */
static gint
order_cmp (const void *va,
const void *vb)
{
const order_t *a = va;
const order_t *b = vb;
return (a->value < b->value) ? -1 : ((a->value > b->value)? + 1 : 0);
}
/* Convert spot function "type" to a threshold matrix of size "width"
* times "width". Returns newly allocated threshold matrix. The
* reason for qsort()ing the results rather than just using the spot
* function's value directly as the threshold value is that we want to
* ensure that the threshold matrix is tonally balanced - that is, for
* a threshold value of x%, x% of the values in the matrix are < x%.
*
* Actually, it turns out that qsort()ing a function which is already
* balanced can quite significantly detract from the quality of the
* final result. This is particularly noticable with the line or
* diamond spot functions at 45 degrees. This is because if the spot
* function has multiple locations with the same value, qsort may use
* them in any order. Often, there is quite clearly an optimal order
* however. By marking functions as pre-balanced, this random
* shuffling is avoided. WARNING: a non-balanced spot function marked
* as pre-balanced is bad: you'll end up with dark areas becoming too
* dark or too light, and vice versa for light areas. This is most
* easily checked by halftoning an area, then bluring it back - you
* should get the same colour back again. The only way of getting a
* correctly balanced function is by getting a formula for the spot's
* area as a function of x and y - this can be fairly tough (ie
* possiblly an integral in two dimensions that must be solved
* analytically).
*
* The threshold matrix is used to compare against image values. If
* the image value is greater than the threshold value, then the
* output pixel is illuminated. This means that a threshold matrix
* entry of 0 never causes output pixels to be illuminated. */
static guchar *
spot2thresh (gint type,
gint width)
{
gdouble sx, sy;
gdouble val;
spotfn_t *spotfn;
guchar *thresh;
order_t *order;
gint x, y;
gint i;
gint wid2 = width * width;
gint balanced = spotfn_list[type].balanced;
thresh = g_new (guchar, wid2);
spotfn = spotfn_list[type].fn;
order = g_new (order_t, wid2);
i = 0;
for (y = 0; y < width; y++)
{
for (x = 0; x < width; x++)
{
/* scale x & y to -1 ... +1 inclusive */
sx = (((gdouble)x) / (width-1) - 0.5) * 2;
sy = (((gdouble)y) / (width-1) - 0.5) * 2;
val = spotfn(sx, sy);
val = CLAMP (val, -1, 1); /* interval is inclusive */
order[i].index = i;
order[i].value = val;
i++;
}
}
if (!balanced)
{
/* now sort array of (point, value) pairs in ascending order */
qsort (order, wid2, sizeof (order_t), order_cmp);
}
/* compile threshold matrix in order from darkest to lightest */
for (i = 0; i < wid2; i++)
{
/* thresh[] contains values from 0 .. 254. The reason for not
* including 255 is so that an image value of 255 remains
* unmolested. It would be bad to filter a completely white
* image and end up with black speckles. */
if (balanced)
thresh[order[i].index] = order[i].value * 0xfe;
else
thresh[order[i].index] = i * 0xff / wid2;
}
g_free (order);
/* TODO: this is where the code to apply a transfer or dot gain
* function to the threshold matrix would go. */
return thresh;
}
/**************************************************************/
/* Main loop */
/* This function operates on the image, striding across it in tiles. */
static void
newsprint (GimpDrawable *drawable,
GimpPreview *preview)
{
GimpPixelRgn src_rgn, dest_rgn;
guchar *src_row, *dest_row;
guchar *src, *dest;
guchar *thresh[4] = { NULL, NULL, NULL, NULL };
gdouble r;
gdouble theta;
gdouble rot[4];
gint bpp, colour_bpp;
gint has_alpha;
gint b;
gint tile_width;
gint width;
gint row, col;
gint x, y, x_step, y_step;
gint x1, y1, x2, y2;
gint preview_width, preview_height;
gint rx, ry;
gint progress, max_progress;
gint oversample;
gint colourspace;
gpointer pr;
gint w002;
guchar *preview_buffer = NULL;
#ifdef TIMINGS
GTimer *timer = g_timer_new ();
#endif
width = pvals.cell_width;
if (width < 0)
width = -width;
if (width < 1)
width = 1;
oversample = pvals.oversample;
width *= oversample;
tile_width = gimp_tile_width ();
bpp = gimp_drawable_bpp (drawable->drawable_id);
if (preview)
{
gimp_preview_get_position (preview, &x1, &y1);
gimp_preview_get_size (preview, &preview_width, &preview_height);
x2 = x1 + preview_width;
y2 = y1 + preview_height;
preview_buffer = g_new (guchar, preview_width * preview_height * bpp);
}
else
{
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
}
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
colour_bpp = has_alpha ? bpp-1 : bpp;
colourspace= pvals.colourspace;
if (colour_bpp == 1)
{
colourspace = CS_GREY;
}
else
{
if (colourspace == CS_GREY)
colourspace = CS_RGB;
}
/* Bartlett window matrix optimisation */
w002 = BARTLETT (0, 0) * BARTLETT (0, 0);
#if 0
/* It turns out to be slightly slower to cache a pre-computed
* bartlett matrix! I put it down to d-cache pollution *shrug* */
wgt = g_new (gint, oversample * oversample);
for (y = -oversample / 2; y <= oversample / 2; y++)
for (x = -oversample / 2; x<=oversample / 2; x++)
WGT (x, y) = BARTLETT (x, y);
#endif /* 0 */
#define ASRT(_x) \
do { \
if (!VALID_SPOTFN(_x)) \
{ \
printf("newsprint: %d is not a valid spot type\n", _x); \
_x = SPOTFN_DOT; \
} \
} while(0)
/* calculate the RGB / CMYK rotations and threshold matrices */
if (colour_bpp == 1 || colourspace == CS_INTENSITY)
{
rot[0] = DEG2RAD (pvals.gry_ang);
thresh[0] = spot2thresh (pvals.gry_spotfn, width);
}
else
{
gint rf = pvals.red_spotfn;
gint gf = pvals.grn_spotfn;
gint bf = pvals.blu_spotfn;
rot[0] = DEG2RAD (pvals.red_ang);
rot[1] = DEG2RAD (pvals.grn_ang);
rot[2] = DEG2RAD (pvals.blu_ang);
/* always need at least one threshold matrix */
ASRT (rf);
spotfn_list[rf].thresh = spot2thresh (rf, width);
thresh[0] = spotfn_list[rf].thresh;
ASRT (gf);
spotfn_list[gf].thresh = spot2thresh (gf, width);
thresh[1] = spotfn_list[gf].thresh;
ASRT (bf);
spotfn_list[bf].thresh = spot2thresh (bf, width);
thresh[2] = spotfn_list[bf].thresh;
if (colourspace == CS_CMYK)
{
rot[3] = DEG2RAD (pvals.gry_ang);
gf = pvals.gry_spotfn;
ASRT (gf);
spotfn_list[gf].thresh = spot2thresh (gf, width);
thresh[3] = spotfn_list[gf].thresh;
}
}
/* Initialize progress */
progress = 0;
max_progress = (x2 - x1) * (y2 - y1);
for (y = y1; y < y2; y += tile_width - (y % tile_width))
{
for (x = x1; x < x2; x += tile_width - (x % tile_width))
{
/* snap to tile boundary */
x_step = tile_width - (x % tile_width);
y_step = tile_width - (y % tile_width);
/* don't step off the end of the image */
x_step = MIN (x_step, x2 - x);
y_step = MIN (y_step, y2 - y);
/* set up the source and dest regions */
gimp_pixel_rgn_init (&src_rgn, drawable, x, y, x_step, y_step,
FALSE/*dirty*/, FALSE/*shadow*/);
gimp_pixel_rgn_init (&dest_rgn, drawable, x, y, x_step, y_step,
TRUE/*dirty*/, TRUE/*shadow*/);
/* page in the image, one tile at a time */
for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn);
pr != NULL;
pr = gimp_pixel_rgns_process (pr))
{
src_row = src_rgn.data;
if (preview)
dest_row = preview_buffer +
((src_rgn.y - y1) * preview_width + src_rgn.x - x1) * bpp;
else
dest_row = dest_rgn.data;
for (row = 0; row < src_rgn.h; row++)
{
src = src_row;
dest = dest_row;
for (col = 0; col < src_rgn.w; col++)
{
guchar data[4];
rx = (x + col) * oversample;
ry = (y + row) * oversample;
/* convert rx and ry to polar (r, theta) */
r = sqrt (((double)rx)*rx + ((double)ry)*ry);
theta = atan2 (((gdouble)ry), ((gdouble)rx));
for (b = 0; b < colour_bpp; b++)
data[b] = src[b];
/* do colour space conversion */
switch (colourspace)
{
case CS_CMYK:
{
gint r,g,b,k;
r = data[0];
g = data[1];
b = data[2];
k = pvals.k_pullout;
gimp_rgb_to_cmyk_int (&r, &g, &b, &k);
data[0] = r;
data[1] = g;
data[2] = b;
data[3] = k;
}
break;
case CS_INTENSITY:
data[3] = data[0]; /* save orig for later */
data[0] = GIMP_RGB_INTENSITY (data[0],
data[1],
data[2]) + 0.5;
break;
default:
break;
}
for (b = 0; b < cspace_nchans[colourspace]; b++)
{
rx = RINT (r * cos (theta + rot[b]));
ry = RINT (r * sin (theta + rot[b]));
/* Make sure rx and ry are positive and within
* the range 0 .. width-1 (incl). Can't use %
* operator, since its definition on negative
* numbers is not helpful. Can't use ABS(),
* since that would cause reflection about the
* x- and y-axes. Relies on integer division
* rounding towards zero. */
rx -= ((rx - ISNEG (rx) * (width-1)) / width) * width;
ry -= ((ry - ISNEG (ry) * (width-1)) / width) * width;
{
guint32 sum = 0;
gint sx, sy;
gint tx, ty;
for (sy = -oversample/2; sy <= oversample/2; sy++)
for (sx = -oversample/2; sx <= oversample/2; sx++)
{
tx = rx+sx;
ty = ry+sy;
while (tx < 0) tx += width;
while (ty < 0) ty += width;
while (tx >= width) tx -= width;
while (ty >= width) ty -= width;
if (data[b] > THRESHn(b, tx, ty))
sum += 0xff * BARTLETT(sx, sy);
}
sum /= w002;
data[b] = sum;
}
}
if (has_alpha)
dest[colour_bpp] = src[colour_bpp];
/* re-pack the colours into RGB */
switch (colourspace)
{
case CS_CMYK:
data[0] = CLAMPED_ADD (data[0], data[3]);
data[1] = CLAMPED_ADD (data[1], data[3]);
data[2] = CLAMPED_ADD (data[2], data[3]);
data[0] = 0xff - data[0];
data[1] = 0xff - data[1];
data[2] = 0xff - data[2];
break;
case CS_INTENSITY:
if (has_alpha)
{
dest[colour_bpp] = data[0];
data[0] = 0xff;
}
data[1] = data[1] * data[0] / 0xff;
data[2] = data[2] * data[0] / 0xff;
data[0] = data[3] * data[0] / 0xff;
break;
default:
/* no other special cases */
break;
}
for (b = 0; b < colour_bpp; b++)
dest[b] = data[b];
src += src_rgn.bpp;
dest += dest_rgn.bpp;
}
src_row += src_rgn.rowstride;
if (preview)
dest_row += preview_width * bpp;
else
dest_row += dest_rgn.rowstride;
}
/* Update progress */
progress += src_rgn.w * src_rgn.h;
if (!preview)
gimp_progress_update ((double) progress / (double) max_progress);
}
}
}
#ifdef TIMINGS
g_printerr ("%f seconds\n", g_timer_elapsed (timer));
g_timer_destroy (timer);
#endif
/*
* Note: the tresh array should *NOT* be freed.
* Its values will be reused anyway so this is NOT a memory leak.
* Well it is, but only the first time, so it doesn't matter.
*/
if (preview)
{
gimp_preview_draw_buffer (preview, preview_buffer, preview_width * bpp);
g_free (preview_buffer);
}
else
{
/* update the affected region */
gimp_drawable_flush (drawable);
gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
}
}
|