home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume19 / fbm / part02 / flthre.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-08  |  2.3 KB  |  84 lines

  1. 1/*****************************************************************
  2.  * flthre.c: FBM Library 0.94 (Beta test) 20-May-89  Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  5.  * use this file in whole or in part provided that you do not sell it
  6.  * for profit and that this copyright notice is retained unchanged.
  7.  *
  8.  * flthre.c: 
  9.  *
  10.  * CONTENTS:
  11.  *    thesh_fbm (input, output, thresh)
  12.  *
  13.  * EDITLOG
  14.  *    LastEditDate = Sat May 20 19:06:37 1989 - Michael Mauldin
  15.  *    LastFileName = /usr2/mlm/src/misc/fbm/flthre.c
  16.  *
  17.  * HISTORY
  18.  * 20-May-89  Michael Mauldin (mlm) at Carnegie Mellon University
  19.  *    Bug fix from Dave Cohrs <dave@cs.wisc.edu>
  20.  *
  21.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  22.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  23.  *
  24.  * 10-Dec-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  25.  *    Created.
  26.  *****************************************************************/
  27.  
  28.  
  29. # include <stdio.h>
  30. # include <math.h>
  31. # include <ctype.h>
  32. # include "fbm.h"
  33.  
  34. /*****************************************************************
  35.  * thesh_fbm: Threshhold halftoning
  36.  *****************************************************************/
  37.  
  38. # define RAND(RN) (((seed = 1103515245 * seed + 12345) >> 12) % (RN))
  39.  
  40. #ifndef lint
  41. static char *fbmid =
  42.     "$FBM flthre.c <0.94> 20-May-89  (C) 1989 by Michael Mauldin$";
  43. #endif
  44.  
  45. thesh_fbm (input, output, thresh)
  46. FBM *input, *output;
  47. register int thresh;
  48. { register unsigned char *bmp, *obm;
  49.   register int i, j, rowlen, w, h, outrow;
  50.  
  51.   if (input->hdr.planes != 1)
  52.   { fprintf (stderr, "thesh_fbm: can't halftone color images\n");
  53.     return (0);
  54.   }
  55.  
  56.   fprintf (stderr, "Threshhold halftoning, thesh %d\n", thresh);
  57.  
  58.   /* Allocate output */
  59.   free_fbm (output);
  60.   output->hdr = input->hdr;
  61.   output->hdr.bits = 1;
  62.   output->hdr.physbits = 8;
  63.   outrow = 16 * ((input->hdr.cols + 15) / 16); /* Pad to even byte boundary */
  64.   output->hdr.rowlen = outrow;
  65.   output->hdr.plnlen = outrow*output->hdr.rows;
  66.   alloc_fbm (output);
  67.  
  68.   w = input->hdr.cols;
  69.   h = input->hdr.rows;
  70.   rowlen = input->hdr.rowlen;
  71.   
  72.   /* Now do threshholding */
  73.   for (j=0; j<h; j++)
  74.   { /* scan left to right */
  75.     bmp = &input->bm[j*rowlen];
  76.     obm = &output->bm[j*outrow];
  77.  
  78.     for (i=1; i<w; i++)
  79.     { obm[i] = bmp[i] > thresh ? WHITE : BLACK; }
  80.   }
  81.   
  82.   return (1);
  83. }
  84.