mitrap.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. *
  3. * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and its
  6. * documentation for any purpose is hereby granted without fee, provided that
  7. * the above copyright notice appear in all copies and that both that
  8. * copyright notice and this permission notice appear in supporting
  9. * documentation, and that the name of Keith Packard not be used in
  10. * advertising or publicity pertaining to distribution of the software without
  11. * specific, written prior permission. Keith Packard makes no
  12. * representations about the suitability of this software for any purpose. It
  13. * is provided "as is" without express or implied warranty.
  14. *
  15. * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  16. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  17. * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  18. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  19. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  20. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. * PERFORMANCE OF THIS SOFTWARE.
  22. */
  23. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include "scrnintstr.h"
  27. #include "gcstruct.h"
  28. #include "pixmapstr.h"
  29. #include "windowstr.h"
  30. #include "servermd.h"
  31. #include "mi.h"
  32. #include "picturestr.h"
  33. #include "mipict.h"
  34. static xFixed
  35. miLineFixedX(xLineFixed * l, xFixed y, Bool ceil)
  36. {
  37. xFixed dx = l->p2.x - l->p1.x;
  38. xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx;
  39. xFixed dy = l->p2.y - l->p1.y;
  40. if (ceil)
  41. ex += (dy - 1);
  42. return l->p1.x + (xFixed) (ex / dy);
  43. }
  44. void
  45. miTrapezoidBounds(int ntrap, xTrapezoid * traps, BoxPtr box)
  46. {
  47. box->y1 = MAXSHORT;
  48. box->y2 = MINSHORT;
  49. box->x1 = MAXSHORT;
  50. box->x2 = MINSHORT;
  51. for (; ntrap; ntrap--, traps++) {
  52. INT16 x1, y1, x2, y2;
  53. if (!xTrapezoidValid(traps))
  54. continue;
  55. y1 = xFixedToInt(traps->top);
  56. if (y1 < box->y1)
  57. box->y1 = y1;
  58. y2 = xFixedToInt(xFixedCeil(traps->bottom));
  59. if (y2 > box->y2)
  60. box->y2 = y2;
  61. x1 = xFixedToInt(min(miLineFixedX(&traps->left, traps->top, FALSE),
  62. miLineFixedX(&traps->left, traps->bottom, FALSE)));
  63. if (x1 < box->x1)
  64. box->x1 = x1;
  65. x2 = xFixedToInt(xFixedCeil
  66. (max
  67. (miLineFixedX(&traps->right, traps->top, TRUE),
  68. miLineFixedX(&traps->right, traps->bottom, TRUE))));
  69. if (x2 > box->x2)
  70. box->x2 = x2;
  71. }
  72. }