renderedge.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. *
  3. * Copyright © 2004 Keith Packard
  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. #ifndef _RENDEREDGE_H_
  24. #define _RENDEREDGE_H_
  25. #include "picturestr.h"
  26. #define MAX_ALPHA(n) ((1 << (n)) - 1)
  27. #define N_Y_FRAC(n) ((n) == 1 ? 1 : (1 << ((n)/2)) - 1)
  28. #define N_X_FRAC(n) ((1 << ((n)/2)) + 1)
  29. #define STEP_Y_SMALL(n) (xFixed1 / N_Y_FRAC(n))
  30. #define STEP_Y_BIG(n) (xFixed1 - (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
  31. #define Y_FRAC_FIRST(n) (STEP_Y_SMALL(n) / 2)
  32. #define Y_FRAC_LAST(n) (Y_FRAC_FIRST(n) + (N_Y_FRAC(n) - 1) * STEP_Y_SMALL(n))
  33. #define STEP_X_SMALL(n) (xFixed1 / N_X_FRAC(n))
  34. #define STEP_X_BIG(n) (xFixed1 - (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
  35. #define X_FRAC_FIRST(n) (STEP_X_SMALL(n) / 2)
  36. #define X_FRAC_LAST(n) (X_FRAC_FIRST(n) + (N_X_FRAC(n) - 1) * STEP_X_SMALL(n))
  37. #define RenderSamplesX(x,n) ((n) == 1 ? 0 : (xFixedFrac (x) + X_FRAC_FIRST(n)) / STEP_X_SMALL(n))
  38. /*
  39. * An edge structure. This represents a single polygon edge
  40. * and can be quickly stepped across small or large gaps in the
  41. * sample grid
  42. */
  43. typedef struct {
  44. xFixed x;
  45. xFixed e;
  46. xFixed stepx;
  47. xFixed signdx;
  48. xFixed dy;
  49. xFixed dx;
  50. xFixed stepx_small;
  51. xFixed stepx_big;
  52. xFixed dx_small;
  53. xFixed dx_big;
  54. } RenderEdge;
  55. /*
  56. * Step across a small sample grid gap
  57. */
  58. #define RenderEdgeStepSmall(edge) { \
  59. edge->x += edge->stepx_small; \
  60. edge->e += edge->dx_small; \
  61. if (edge->e > 0) \
  62. { \
  63. edge->e -= edge->dy; \
  64. edge->x += edge->signdx; \
  65. } \
  66. }
  67. /*
  68. * Step across a large sample grid gap
  69. */
  70. #define RenderEdgeStepBig(edge) { \
  71. edge->x += edge->stepx_big; \
  72. edge->e += edge->dx_big; \
  73. if (edge->e > 0) \
  74. { \
  75. edge->e -= edge->dy; \
  76. edge->x += edge->signdx; \
  77. } \
  78. }
  79. xFixed RenderSampleCeilY(xFixed y, int bpp);
  80. xFixed RenderSampleFloorY(xFixed y, int bpp);
  81. void
  82. RenderEdgeStep(RenderEdge * e, int n);
  83. void
  84. RenderEdgeInit(RenderEdge * e,
  85. int bpp,
  86. xFixed y_start,
  87. xFixed x_top, xFixed y_top, xFixed x_bot, xFixed y_bot);
  88. void
  89. RenderLineFixedEdgeInit(RenderEdge * e,
  90. int bpp,
  91. xFixed y, xLineFixed * line, int x_off, int y_off);
  92. #endif /* _RENDEREDGE_H_ */