home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume12 / postscript / part01 / source / trapezoid.c < prev   
Encoding:
C/C++ Source or Header  |  1987-10-27  |  1.9 KB  |  58 lines

  1. /*
  2.  * Copyright (C) Rutherford Appleton Laboratory 1987
  3.  * 
  4.  * This source may be copied, distributed, altered or used, but not sold for profit
  5.  * or incorporated into a product except under licence from the author.
  6.  * It is not in the public domain.
  7.  * This notice should remain in the source unaltered, and any changes to the source
  8.  * made by persons other than the author should be marked as such.
  9.  * 
  10.  *    Crispin Goswell @ Rutherford Appleton Laboratory caag@uk.ac.rl.vd
  11.  */
  12. #include "main.h"
  13. #include "graphics.h"
  14. #include "canon.h"
  15.  
  16. static int Xvalue (ax, ay, bx, by, cy) int ax, ay, bx, by, cy;
  17.  {
  18.      return bx + (cy - by) * (ax - bx) / (float) (ay - by);
  19.  }
  20.  
  21. void BitBltTrapezoid (to, lefttop, leftbottom, righttop, rightbottom, top, bottom, rop)
  22.     struct hardware *to;
  23.     DevicePoint lefttop, leftbottom, righttop, rightbottom;
  24.     int top, bottom, rop;
  25.  {
  26.      int i, j, temp;
  27.      static int left [1024], right [1024];
  28.      
  29.      int     ltx = Xvalue (lefttop.dx,     lefttop.dy,     leftbottom.dx,     leftbottom.dy,     top),
  30.          rtx = Xvalue (righttop.dx,     righttop.dy,     rightbottom.dx, rightbottom.dy, top),
  31.          lbx = Xvalue (lefttop.dx,     lefttop.dy,     leftbottom.dx,     leftbottom.dy,     bottom),
  32.          rbx = Xvalue (righttop.dx,     righttop.dy,     rightbottom.dx, rightbottom.dy, bottom);
  33.      
  34.      if (ltx == lbx && rtx == rbx)
  35.       {
  36.           if (rtx < ltx)
  37.               temp = rtx, rtx = ltx, ltx = temp;
  38.           
  39.          BitBlt ((struct hardware *) NULL, to,
  40.              NewDevicePoint (0, 0), NewDevicePoint (ltx, top),
  41.              NewDevicePoint (rtx - ltx + 1, bottom - top + 1), rop);
  42.          
  43.          return;
  44.       }
  45.      
  46.      for (i = top, j = 0; i <= bottom; i++, j++)
  47.       {
  48.           int     lx = Xvalue (lefttop.dx,     lefttop.dy,     leftbottom.dx, leftbottom.dy,  i),
  49.              rx = Xvalue (righttop.dx,     righttop.dy,     rightbottom.dx,rightbottom.dy, i);
  50.          
  51.          if (rx < lx)
  52.              temp = rx, rx = lx, lx = temp;
  53.          
  54.          left [j] = lx; right [j] = rx;
  55.       }
  56.      BitBltBlob (to, top, bottom - top, left, right, single_rop [rop]);
  57.  }
  58.