home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume4 / 8to1 / 8to1.c next >
C/C++ Source or Header  |  1989-02-03  |  17KB  |  585 lines

  1. /**************************************************************************
  2.  Copyright (c) 1988 by Hong Min
  3.  
  4.    compile : cc -O -o 8to1 8to1.c -lpixrect 
  5.  
  6.    The program 8to1 converts a 8-bit depth sun raster file (both color, 
  7.    i.e. rgb are different, and grey, i.e. rgb are the same, and both 
  8.    standard format and byte-encoded format) to a 1-bit depth mono sun
  9.    raster file. If your color image has no colormap, this program would
  10.    provide a default grey scale color map. It implements several halftone
  11.    algorithms from Digital Halftones by Dot Diffusion in acm Transactions 
  12.    on Graphics, such as error diffusion, ordered dither and dot diffusion
  13.    with and without edge enhancement.  Just type 8to1, it will give you
  14.    the usage.
  15.  
  16.    This program was written by :
  17.  
  18.     Hong Min 
  19.     Computer Science Department
  20.        SUNY at Stony Brook 
  21.     e-mail address : 
  22.         UUCP: {allegra, philabs, pyramid, research}!sbcs!rainbow
  23.         ARPA-Internet: rainbow@sbcs.sunysb.edu
  24.         CSnet: rainbow@suny-sb
  25.  
  26.    Everyone is welcome to write to me if you like the program or not.
  27.    And welcome to optimize the code, as I haven't fooled with it to
  28.    make it efficient yet.
  29.  
  30.         Enjoy!                            
  31.  
  32. ****************************************************************************/
  33.  
  34.  
  35.  
  36. #include <stdio.h>
  37. #include <sys/types.h>
  38. #include <pixrect/pixrect.h>
  39. #include <pixrect/memvar.h>
  40. #include <pixrect/pr_util.h>
  41. #include <pixrect/pr_io.h>
  42. #include <rasterfile.h>
  43.  
  44. #define ORDER   16      /* dither matrix order */
  45. #define WHITE   0       /* background color */
  46. #define BLACK   ~0      /* foreground color */
  47. #define FALSE    0
  48. #define TRUE    1
  49. #define ALPHA    7
  50. #define BETA    3
  51. #define GAMMA    5
  52. #define DELTA    1
  53.  
  54. short    **A, **B;
  55. int    ordered_dither[8][8] = { 0, 32,  8, 40,  2, 34, 10, 42,
  56.                 48, 16, 56, 24, 50, 18, 58, 26,
  57.                 12, 44,  4, 36, 14, 46,  6, 38,
  58.                 60, 28, 52, 20, 62, 30, 54, 22,
  59.                  3, 35, 11, 43,  1, 33,  9, 41,
  60.                 51, 19, 59, 27, 49, 17, 57, 25,
  61.                 15, 47,  7, 39, 13, 45,  5, 37,
  62.                 63, 31, 55, 23, 61, 29, 53, 21 };
  63. int    dot_diffusion[8][8] = {    34, 48, 40, 32, 29, 15, 23, 31,
  64.                 42, 58, 56, 53, 21,  5,  7, 10,
  65.                 50, 62, 61, 45, 13,  1,  2, 18,
  66.                 38, 46, 54, 37, 25, 17,  9, 26,
  67.                 28, 14, 22, 30, 35, 49, 41, 33,
  68.                 20,  4,  6, 11, 43, 59, 57, 52,
  69.                 12,  0,  3, 19, 51, 63, 60, 44,
  70.                 24, 16,  8, 27, 39, 47, 55, 36 };
  71. int    reverse_matrix[64] = {    49, 21, 22, 50, 41, 13, 42, 14,
  72.                 58, 30, 15, 43, 48, 20, 33,  5, 
  73.                 57, 29, 23, 51, 40, 12, 34,  6,
  74.                 56, 28, 31, 59, 32,  4, 35,  7,
  75.                  3, 39,  0, 36, 63, 27, 24, 60,
  76.                  2, 38,  8, 44, 55, 19, 25, 61,
  77.                  1, 37, 16, 52, 47, 11, 26, 62,
  78.                 10, 46,  9, 45, 54, 18, 17, 53 };
  79.  
  80.  
  81. main(argc, argv)
  82. int    argc;
  83. char    *argv[];
  84. {
  85. register colormap_t         colormap;
  86. register unsigned char        *map;
  87. register struct rasterfile    rh;
  88. register Pixrect         *pr = 0;
  89. register int            i, default_map = FALSE;
  90. int                option;
  91.  
  92.     if ((argc > 4) || (argc < 2)) {
  93.        fprintf(stderr, "Usage: %s option [infile [outfile]]\n", argv[0]);
  94.        fprintf(stderr, "option : 0 -- error diffusion for grey scale\n");
  95.        fprintf(stderr, "         1 -- ordered dither for grey scale\n");
  96.        fprintf(stderr, "         2 -- dot diffusion for grey scale\n");
  97.        fprintf(stderr, "         3 -- error diffusion for grey scale with edge enhancement\n");
  98.        fprintf(stderr, "         4 -- ordered dither for grey scale with edge enhancement\n");
  99.        fprintf(stderr, "         5 -- dot diffusion for grey scale with edge enhancement\n");
  100.        fprintf(stderr, "         6 -- error diffusion for color\n");
  101.        fprintf(stderr, "         7 -- ordered dither for color\n");
  102.        fprintf(stderr, "         8 -- dot diffusion for color\n");
  103.        fprintf(stderr, "         9 -- error diffusion for color with edge enhancement\n");
  104.        fprintf(stderr, "        10 -- ordered dither for color with edge enhancement\n");
  105.        fprintf(stderr, "        11 -- dot diffusion for color with edge enhancement\n");
  106.        exit(1);
  107.     }
  108.  
  109.     sscanf(argv[1], "%d", &option);
  110.  
  111.     /* open the input file if specified */
  112.     if ((argc > 2) && (freopen(argv[2], "r", stdin) == NULL)) {
  113.        fprintf(stderr, "can't open infile %s for read!\n", argv[2]);
  114.        exit(1);
  115.     }
  116.  
  117.     /* open the output file if specified */
  118.     if ((argc > 3) && (freopen(argv[3], "w", stdout) == NULL)) {
  119.        fprintf(stderr, "can't open outfile %s for write!\n", argv[3]);
  120.        exit(1);
  121.     }
  122.  
  123.     /* Load the input rasterfile header */
  124.     if (pr_load_header(stdin, &rh)) {
  125.        fprintf(stderr, "read rasterfile header error\n");
  126.        exit(1);
  127.     }
  128.        
  129.     if (rh.ras_depth != 8) {
  130.        fprintf(stderr, "input file is not a 8 bits deep\n");
  131.        exit(1);
  132.     }
  133.  
  134.     /* Load the colormap */
  135.     colormap.type = RMT_NONE;
  136.     if (pr_load_colormap(stdin, &rh, &colormap)) {
  137.        fprintf(stderr, "read rasterfile header error\n");
  138.        exit(1);
  139.     }
  140.  
  141.     if (colormap.type != RMT_NONE &&
  142.     (colormap.type != RMT_EQUAL_RGB || colormap.length < 256)) {
  143.        fprintf(stderr,"input has unsupported colormap type or length\n");
  144.        exit(1);
  145.     }
  146.  
  147.     if ((colormap.type == RMT_NONE) && (colormap.length == 0)) {
  148.        default_map = TRUE;
  149.        map = (unsigned char *) malloc(256);
  150.        for (i=0; i<256; i++)
  151.         map[i] = i;
  152.     }
  153.        
  154.     if (rh.ras_type != RT_OLD && rh.ras_type != RT_STANDARD &&
  155.     !(pr = pr_load_image(stdin, &rh, &colormap))) {
  156.        fprintf(stderr, "error reading rasterfile\n");
  157.        exit(1);
  158.     }
  159.  
  160.     /* Write new header */
  161.     rh.ras_type = RT_STANDARD;
  162.     rh.ras_depth = 1;
  163.     rh.ras_length = mpr_linebytes(rh.ras_width, 1) * rh.ras_height;
  164.     rh.ras_maptype = RMT_NONE;
  165.     rh.ras_maplength = 0;
  166.  
  167.     if (pr_dump_header(stdout, &rh, (colormap_t *) 0) == PIX_ERR) {
  168.        fprintf(stderr, "error saving raster file header!\n");
  169.        exit(1);
  170.     }
  171.  
  172.     if (rh.ras_width <= 0 || rh.ras_height <= 0)
  173.        exit(1);
  174.     else {
  175.         A = (short **) malloc((rh.ras_width+3)*sizeof(short *));
  176.         B = (short **) malloc((rh.ras_width+3)*sizeof(short *));
  177.         for(i=0; i<rh.ras_width+3; i++) {
  178.            A[i] = (short *)malloc((rh.ras_height+3)*sizeof(short));
  179.            B[i] = (short *)malloc((rh.ras_height+3)*sizeof(short));
  180.         }
  181.     }
  182.  
  183.     if (!default_map)
  184.        map = colormap.map[0];
  185.  
  186.     if (pr)
  187.        switch (option) {
  188.           case 6  : map = (unsigned char *) malloc(256);
  189.             color_map_3_to_1(colormap, map); 
  190.           case 0  :    error_diffusion_image(rh.ras_width, rh.ras_height,
  191.             map, (u_char *) mpr_d(pr)->md_image, stdout, 
  192.             0, mpr_d(pr)->md_linebytes - rh.ras_width);
  193.             break;
  194.           case 7  : map = (unsigned char *) malloc(256);
  195.             color_map_3_to_1(colormap, map);
  196.           case 1  : ordered_dither_image(rh.ras_width, rh.ras_height,
  197.             map, (u_char *) mpr_d(pr)->md_image, stdout,
  198.             0, mpr_d(pr)->md_linebytes - rh.ras_width);
  199.             break;
  200.           case 8  : map = (unsigned char *) malloc(256);
  201.             color_map_3_to_1(colormap, map);
  202.           case 2  : dot_diffusion_image(rh.ras_width, rh.ras_height,
  203.             map, (u_char *) mpr_d(pr)->md_image, stdout, 
  204.             0, mpr_d(pr)->md_linebytes - rh.ras_width);
  205.             break;
  206.           case 9  : map = (unsigned char *) malloc(256);
  207.             color_map_3_to_1(colormap, map);
  208.           case 3  :    error_diffusion_image(rh.ras_width, rh.ras_height,
  209.             map, (u_char *) mpr_d(pr)->md_image, stdout, 
  210.             1, mpr_d(pr)->md_linebytes - rh.ras_width);
  211.             break;
  212.           case 10 : map = (unsigned char *) malloc(256);
  213.             color_map_3_to_1(colormap, map);
  214.           case 4  : ordered_dither_image(rh.ras_width, rh.ras_height,
  215.             map, (u_char *) mpr_d(pr)->md_image, stdout, 
  216.             1, mpr_d(pr)->md_linebytes - rh.ras_width);
  217.             break;
  218.           case 11 : map = (unsigned char *) malloc(256);
  219.             color_map_3_to_1(colormap, map);
  220.           case 5  : dot_diffusion_image(rh.ras_width, rh.ras_height,
  221.             map, (u_char *) mpr_d(pr)->md_image, stdout, 
  222.             1, mpr_d(pr)->md_linebytes - rh.ras_width);
  223.             break;
  224.        }
  225.     else
  226.        switch (option) {
  227.           case 6  : map = (unsigned char *) malloc(256);
  228.             color_map_3_to_1(colormap, map);
  229.           case 0  : error_diffusion_file(rh.ras_width, rh.ras_height,
  230.             map, stdin, stdout, 0,
  231.             mpr_linebytes(rh.ras_width, 8) - rh.ras_width);
  232.             break;
  233.           case 7  : map = (unsigned char *) malloc(256);
  234.             color_map_3_to_1(colormap, map);
  235.           case 1  : ordered_dither_file(rh.ras_width, rh.ras_height,
  236.             map, stdin, stdout, 0,
  237.             mpr_linebytes(rh.ras_width, 8) - rh.ras_width);
  238.             break;
  239.           case 8  : map = (unsigned char *) malloc(256);
  240.             color_map_3_to_1(colormap, map);
  241.           case 2  : dot_diffusion_file(rh.ras_width, rh.ras_height,
  242.             map, stdin, stdout, 0, 
  243.             mpr_linebytes(rh.ras_width, 8) - rh.ras_width);
  244.             break;
  245.           case 9  : map = (unsigned char *) malloc(256);
  246.             color_map_3_to_1(colormap, map);
  247.           case 3  : error_diffusion_file(rh.ras_width, rh.ras_height,
  248.             map, stdin, stdout, 1,
  249.             mpr_linebytes(rh.ras_width, 8) - rh.ras_width);
  250.             break;
  251.           case 10 : map = (unsigned char *) malloc(256);
  252.             color_map_3_to_1(colormap, map);
  253.           case 4  : ordered_dither_file(rh.ras_width, rh.ras_height,
  254.             map, stdin, stdout, 1,
  255.             mpr_linebytes(rh.ras_width, 8) - rh.ras_width);
  256.             break;
  257.           case 11 : map = (unsigned char *) malloc(256);
  258.             color_map_3_to_1(colormap, map);
  259.           case 5  : dot_diffusion_file(rh.ras_width, rh.ras_height,
  260.             map, stdin, stdout, 1,
  261.             mpr_linebytes(rh.ras_width, 8) - rh.ras_width);
  262.             break;
  263.        }
  264. }
  265.  
  266. color_map_3_to_1(colormap, map)
  267. register colormap_t    colormap;
  268. register unsigned char    *map;
  269. {
  270. register unsigned long    tmp, i;
  271.  
  272.     for (i=0; i<256; i++) {
  273.        tmp = colormap.map[0][i]*77 + colormap.map[1][i]*151 + colormap.map[2][i]*28;
  274.        map[i] = tmp >> 8;
  275.     }
  276. }
  277.  
  278.  
  279. edge_enhancement(width, height, off)
  280. register int    width, height, off;
  281. {
  282. register int    i, j, x, y;
  283.  
  284.     B[off][off] = A[off][off]*6 - A[off][off+1] - A[off+1][off] - A[off+1][off+1];
  285.     B[off][off+height-1] = A[off][off+height-1]*6 - A[off][off+height-2] - A[off+1][off+height-1] - A[off+1][off+height-2];
  286.     B[off+width-1][off] = A[off+width-1][off]*6 - A[off+width-1][off+1] - A[off+width-2][off] - A[off+width-2][off+1];
  287.     B[off+width-1][off+height-1] = A[off+width-1][off+height-1]*6 - A[off+width-1][off+height-2] - A[off+width-2][off+height-1] - A[off+width-2][off+height-2];
  288.  
  289.     for (i=1; i<width-1; i++)
  290.        B[off+i][off+0] = A[off+i][off+0]*6 - A[off+i-1][off+0] - A[off+i+1][off+0] - A[off+i-1][off+1] - A[off+i][off+1] - A[off+i+1][off+1];
  291.     for (i=1; i<width-1; i++)
  292.        B[off+i][off+height-1] = A[off+i][off+height-1]*6 - A[off+i-1][off+height-1] - A[off+i+1][off+height-2] - A[off+i-1][off+height-2] - A[off+i][off+1] - A[off+i+1][off+height-2];
  293.     for (i=1; i<height-1; i++)
  294.        B[off+0][off+i] = A[off+0][off+i]*6 - A[off+0][off+i-1] - A[off+0][off+i+1] - A[off+1][off+i-1] - A[off+1][off+i] - A[off+1][off+i+1];
  295.     for (i=1; i<height-1; i++)
  296.        B[off+width-1][off+i] = A[off+width-1][off+i]*6 - A[off+width-1][off+i-1] - A[off+width-1][off+i+1] - A[off+width-2][off+i-1] - A[off+width-2][off+i] - A[off+width-2][off+i+1];
  297.  
  298.     for(i=1; i<width-1; i++)
  299.        for(j=1; j<height-1; j++) {
  300.         B[off+i][off+j] = A[off+i][off+j]*10;
  301.         for(x=i-1; x<=i+1; x++)
  302.            for(y=j-1; y<=j+1; y++)
  303.             B[off+i][off+j] -= A[off+x][off+y];
  304.        }
  305.  
  306.     for(i=0; i<width; i++)
  307.        for(j=0; j<height; j++)
  308.         A[off+i][off+j] = B[off+i][off+j];
  309. }
  310.  
  311.  
  312. int index(x, y, w, pad)
  313. register int    x, y, w, pad;
  314. {
  315.     return(x+y*(w+pad));
  316. }
  317.  
  318. error_diffusion(width, height, out, edge)
  319. register int    width, height;
  320. register FILE    *out;
  321. register int    edge;
  322. {
  323. register int        err, mono_pad;
  324. register u_short    dtmp;
  325. register u_long        i, j;
  326.  
  327.     mono_pad = mpr_linebytes(width, 1)*8 - width;
  328.        
  329.     if (edge)
  330.        edge_enhancement(width, height, 1);
  331.  
  332.     for(j=1; j<height+1; j++) {
  333.        for(i=1; i<width+1; i++) {
  334.         dtmp <<= 1;
  335.         if (A[i][j] > 128)
  336.            err = A[i][j] - 256;
  337.         else {
  338.            err = A[i][j];
  339.            dtmp |= 1;
  340.         }
  341.         A[i+1][j] += (err*ALPHA) >> 4;
  342.           A[i-1][j+1] += (err*BETA) >> 4;
  343.         A[i][j+1] += (err*GAMMA) >> 4;
  344.         A[i+1][j+1] += (err*DELTA) >> 4;
  345.         if (((i-1) % 16) == 15) {
  346.            putc(dtmp >> 8, out);
  347.            putc(dtmp, out);
  348.         }
  349.        }
  350.        for(i=width+1; i<=width+mono_pad; i++) {
  351.         dtmp <<= 1;
  352.         if (((i-1) % 16) == 15) {
  353.            putc(dtmp >> 8, out);
  354.            putc(dtmp, out);
  355.         }
  356.        }
  357.     }
  358. }
  359.  
  360. /* Compute pixel values using error diffusion */
  361. error_diffusion_image(width, height, map, in, out, edge_enhance, pad)
  362. register int         width, height;
  363. register unsigned char     *map;
  364. register u_char     *in;
  365. register FILE         *out;
  366. register int         edge_enhance, pad;
  367. {
  368. register int    i, j;
  369.  
  370.     for(j=1; j<height+1; j++)
  371.        for(i=1; i<width+1; i++)
  372.           A[i][j] = map[*(in+index(i-1, j-1, width, pad))];
  373.  
  374.     error_diffusion(width, height, out, edge_enhance);
  375. }
  376.  
  377.  
  378. /* Compute pixel values using error diffusion */
  379. error_diffusion_file(width, height, map, in, out, edge_enhance, pad)
  380. register int         width, height;
  381. register unsigned char     *map;
  382. register FILE         *in, *out;
  383. register int         edge_enhance, pad;
  384. {
  385. register int        i, j, c; 
  386.  
  387.     for(j=1; j<height+1; j++) {
  388.        for(i=1; i<width+1; i++) {
  389.         if ((c = getc(in)) == EOF) {
  390.            fprintf(stderr, "error reading raster data!\n");
  391.            exit(1);
  392.         }
  393.         A[i][j] = map[c];
  394.        }
  395.        for(i=width; i<width+pad; i++)
  396.         if ((c = getc(in)) == EOF)
  397.            fprintf(stderr, "error reading raster data!\n");
  398.     }
  399.  
  400.     error_diffusion(width, height, out, edge_enhance);
  401. }
  402.  
  403. ordered(width, height, out, edge)
  404. register int    width, height;
  405. register FILE    *out;
  406. register int    edge;
  407. {
  408. register int        mono_pad;
  409. register u_short    dtmp;
  410. register u_long        i, j;
  411.  
  412.     mono_pad = mpr_linebytes(width, 1)*8 - width;
  413.  
  414.     if (edge)
  415.        edge_enhancement(width, height, 0);
  416.  
  417.     for(j=0; j<8; j++)
  418.        for(i=0; i<8; i++)
  419.         ordered_dither[i][j] = ordered_dither[i][j]*4 + 2;
  420.  
  421.     for(j=0; j<height; j++) {
  422.        for(i=0; i<width; i++) {
  423.         dtmp <<= 1;
  424.         if (A[i][j] >= ordered_dither[i%8][j%8])
  425.            dtmp |= 1;
  426.         if ((i % 16) == 15) {
  427.            putc(dtmp >> 8, out);
  428.            putc(dtmp, out);
  429.         }
  430.        }
  431.        for(i=width; i<width+mono_pad; i++) {
  432.         dtmp <<= 1;
  433.         if ((i % 16) == 15) {
  434.            putc(dtmp >> 8, out);
  435.            putc(dtmp, out);
  436.         }
  437.        }
  438.     }
  439. }                    
  440.                     
  441. ordered_dither_image(width, height, map, in, out, edge_enhance, pad)
  442. register int         width, height;
  443. register unsigned char     *map;
  444. register u_char     *in;
  445. register FILE         *out;
  446. register int         edge_enhance, pad;
  447. {
  448. register int        i, j;
  449.  
  450.     for(j=0; j<height; j++)
  451.        for(i=0; i<width; i++)
  452.           A[i][j] = 256 - map[*(in+index(i, j, width, pad))];
  453.  
  454.     ordered(width, height, out, edge_enhance);
  455. }
  456.  
  457.  
  458. ordered_dither_file(width, height, map, in, out, edge_enhance, pad)
  459. register int         width, height;
  460. register unsigned char     *map;
  461. register FILE         *in, *out;
  462. register int         edge_enhance, pad;
  463. {
  464. register int        i, j, c;
  465.  
  466.     for(j=0; j<height; j++) {
  467.        for(i=0; i<width; i++) {
  468.           if ((c = getc(in)) == EOF) {
  469.          fprintf(stderr, "error reading raster data!\n");
  470.          exit(1);
  471.           }
  472.           A[i][j] = 256 - map[c];
  473.        }
  474.        for(i=width; i<width+pad; i++)
  475.         if ((c = getc(in)) == EOF)
  476.            fprintf(stderr, "error reading raster data!\n");
  477.     }
  478.  
  479.     ordered(width, height, out, edge_enhance);
  480. }
  481.  
  482. int weight(x, y)
  483. register int    x,y;
  484. {
  485.     return(3 - x*x - y*y);
  486. }
  487.  
  488. dot(width, height, out, edge)
  489. register int    width, height;
  490. register FILE    *out;
  491. register int    edge;
  492. {
  493. register int        k, u, v, err, w, mono_pad;
  494. register u_short    dtmp;
  495. register u_long        i, j;
  496.  
  497.     mono_pad = mpr_linebytes(width, 1)*8 - width;
  498.  
  499.     if (edge)
  500.        edge_enhancement(width, height, 0);
  501.  
  502.     for(k=0; k<64; k++) {
  503.        for(i=reverse_matrix[k]/8; i<width; i+=8)
  504.           for(j=reverse_matrix[k]%8; j<height; j+=8) {
  505.          if (A[i][j] > 128)
  506.             B[i][j] = 0;
  507.          else
  508.             B[i][j] = 1;
  509.          err = A[i][j] - (1 - B[i][j])*256;
  510.          w = 0;
  511.          for(u=i-1; u<=i+1; u++)
  512.             for(v=j-1; v<=j+1; v++)
  513.                if ((u>=0) && (v>=0) && (dot_diffusion[u%8][v%8] > k))
  514.               w += weight(u-i, v-j);
  515.          if (w > 0) {
  516.             for(u=i-1; u<=i+1; u++)
  517.                for(v=j-1; v<=j+1; v++)
  518.               if ((u>=0)&&(v>=0)&&(dot_diffusion[u%8][v%8]>k))
  519.                  A[u][v] += err * weight(u-i, v-j) / w;
  520.          }
  521.           }
  522.     }
  523.  
  524.     for(j=0; j<height; j++) {
  525.        for(i=0; i<width; i++) {
  526.         dtmp <<= 1;
  527.         if (B[i][j])
  528.            dtmp |= 1;
  529.            if ((i % 16) == 15) {
  530.            putc(dtmp >> 8, out);
  531.            putc(dtmp, out);
  532.         }
  533.        }
  534.        for(i=width; i<width+mono_pad; i++) {
  535.         dtmp <<= 1;
  536.         if ((i % 16) == 15) {
  537.            putc(dtmp >> 8, out);
  538.            putc(dtmp, out);
  539.         }
  540.        }
  541.     }
  542. }
  543.  
  544.  
  545. dot_diffusion_image(width, height, map, in, out, edge_enhance, pad)
  546. register int         width, height;
  547. register unsigned char     *map;
  548. register u_char     *in;
  549. register FILE         *out;
  550. register int         edge_enhance, pad;
  551. {
  552. register int        i, j;
  553.  
  554.     for(j=0; j<height; j++)
  555.        for(i=0; i<width; i++)
  556.           A[i][j] = map[*(in+index(i, j, width, pad))];
  557.  
  558.     dot(width, height, out, edge_enhance);
  559. }
  560.  
  561. dot_diffusion_file(width, height, map, in, out, edge_enhance, pad)
  562. register int         width, height;
  563. register unsigned char     *map;
  564. register FILE         *in, *out;
  565. register int         edge_enhance, pad;
  566. {
  567. register int        i, j, c;
  568.  
  569.     for(j=0; j<height; j++) {
  570.        for(i=0; i<width; i++) {
  571.           if ((c = getc(in)) == EOF) {
  572.          fprintf(stderr, "error reading raster data!\n");
  573.          exit(1);
  574.           }
  575.           A[i][j] = map[c];
  576.        }
  577.        for(i=width; i<width+pad; i++)
  578.         if ((c = getc(in)) == EOF)
  579.            fprintf(stderr, "error reading raster data!\n");
  580.     }
  581.  
  582.     dot(width, height, out, edge_enhance);
  583. }
  584.  
  585.