home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / fbm / src / flthre.c < prev    next >
C/C++ Source or Header  |  1990-06-24  |  3KB  |  90 lines

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