home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fonts 1 / freshfonts1.bin / programs / amiga / pastex / src / specialhost / flextr.c < prev    next >
Text File  |  1991-01-29  |  4KB  |  112 lines

  1. /****************************************************************/
  2. /* The function "extract_one()" of this module if from the    */
  3. /* file flextr.c of the FBM Library 0.9.            */
  4. /*                                */
  5. /* Some changes are made, to work with one bit per pixel    */
  6. /* instead of 1 byte.                        */
  7. /*                                */
  8. /* The warning "out of bounds" is deleted, because I didn't    */
  9. /* understand it.                        */
  10. /*                                */
  11. /* 27-07-90  Georg Hessmann (hes)                */
  12. /* 14-11-90  Michael Illgner, speed improvement            */
  13. /****************************************************************/
  14.  
  15. /*****************************************************************
  16.  * flextr.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  17.  *
  18.  * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  19.  * use this file in whole or in part provided that you do not sell it
  20.  * for profit and that this copyright notice is retained unchanged.
  21.  *
  22.  * flextr.c: Extract a rectangle and/or resize it.
  23.  *
  24.  * CONTENTS
  25.  *    extract_fbm (input, output, xo, yo, w, h, ow, oh, title, credits)
  26.  *
  27.  * EDITLOG
  28.  *    LastEditDate = Tue Mar  7 19:56:56 1989 - Michael Mauldin
  29.  *    LastFileName = /usr2/mlm/src/misc/fbm/flextr.c
  30.  *
  31.  * HISTORY
  32.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  33.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  34.  *
  35.  * 12-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  36.  *    Created.
  37.  *****************************************************************/
  38.  
  39. void extract_one(UBYTE *BMin,  UBYTE *BMout,
  40.                  USHORT inlen, USHORT outlen,    /* line length in bytes        */
  41.          USHORT w,     USHORT h,    /* size input plane in pixel    */
  42.          USHORT ow,    USHORT oh)    /* size output plane in pixel    */
  43. {
  44.   USHORT xf, yf, xi, yi, byte, row, col;
  45.   USHORT InByte1, InByte2, InBit1, InBit2, OutByte, OutBit;
  46.   UBYTE  *InRow1, *InRow2, *OutRow, BitMask;
  47.   ULONG  dc;
  48.  
  49.   const UBYTE  Bit[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  50.   const ULONG  wh2    = ((ULONG)ow * (ULONG)oh) / 2;
  51.   const USHORT xm     = w % ow;
  52.   const USHORT xd     = w / ow;
  53.   const USHORT ym     = h % oh;
  54.   const USHORT yd     = h / oh;
  55.   const ULONG  InSkip = yd * inlen;
  56.  
  57.  
  58.   if (w == ow && h == oh)
  59.   {
  60.    InRow1 = BMin; OutRow = BMout;
  61.    for(row=0; row<h; row++) for(byte=0; byte<inlen; byte++) *OutRow++ = *InRow1++;
  62.   }
  63.   else
  64.   {
  65.    yf = 0; yi = 0;
  66.    OutRow = BMout; InRow1 = BMin; InRow2 = BMin + inlen;
  67.    for(row=0; row<oh; row++)
  68.    {
  69.     if (!(row % 100)) pline("   work on line %d (from %d lines)", row, oh);
  70.     xf = 0; xi = 0;
  71.     for(col=0; col<ow; col++)
  72.     {
  73.      OutByte = col >> 3;    OutBit = col & 0x07;
  74.      InByte1 = xi >> 3;     InBit1 = xi & 0x07;
  75.      InByte2 = (xi+1) >> 3; InBit2 = (xi+1) & 0x07;
  76.      BitMask = Bit[OutBit];
  77.      if (xi > w-2 || yi > h-2)
  78.      {
  79.       if ((xi == w-1 && yi <= h-1) || (yi == h-1 && xi <= w-1))
  80.       {
  81.        if (InRow1[InByte1] & Bit[InBit1]) OutRow[OutByte] |= BitMask;
  82.       }
  83.       else OutRow[OutByte] |= BitMask;
  84.      }
  85.      else
  86.      {
  87.       dc = 0;
  88.       if (InRow1[InByte1] & Bit[InBit1]) dc += (ow-xf)*(oh-yf);
  89.       if (InRow2[InByte1] & Bit[InBit1]) dc += (ow-xf)*yf;
  90.       if (InRow1[InByte2] & Bit[InBit2]) dc += xf*(oh-yf);
  91.       if (InRow2[InByte2] & Bit[InBit2]) dc += xf*yf;
  92.       if (dc > wh2) OutRow[OutByte] |= BitMask;
  93.      }
  94.      xf += xm; xi += xd;
  95.      if (xf >= ow)
  96.      {
  97.       xf -= ow;
  98.       xi ++;
  99.      }
  100.     }
  101.     OutRow += outlen;
  102.     yf += ym; InRow1 += InSkip; yi += yd;
  103.     if (yf >= oh)
  104.     {
  105.      yf -= oh;
  106.      InRow1 += inlen; yi++;
  107.     }
  108.     InRow2 = InRow1 + inlen;
  109.    }
  110.   }
  111. }
  112.