clip.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
  3. (c) Copyright 2000-2004 Convergence (integrated media) GmbH
  4. All rights reserved.
  5. Written by Denis Oliver Kropp <dok@directfb.org>,
  6. Andreas Hundt <andi@fischlustig.de>,
  7. Sven Neumann <neo@directfb.org>,
  8. Ville Syrjälä <syrjala@sci.fi> and
  9. Claudio Ciccani <klan@users.sf.net>.
  10. This library is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU Lesser General Public
  12. License as published by the Free Software Foundation; either
  13. version 2 of the License, or (at your option) any later version.
  14. This library is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. Lesser General Public License for more details.
  18. You should have received a copy of the GNU Lesser General Public
  19. License along with this library; if not, write to the
  20. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef __GFX__CLIP_H__
  24. #define __GFX__CLIP_H__
  25. #include <directfb.h>
  26. typedef enum {
  27. DFEF_NONE = 0x00000000,
  28. DFEF_LEFT = 0x00000001,
  29. DFEF_RIGHT = 0x00000002,
  30. DFEF_TOP = 0x00000004,
  31. DFEF_BOTTOM = 0x00000008,
  32. DFEF_ALL = 0x0000000F
  33. } DFBEdgeFlags;
  34. /*
  35. * Clips the line to the clipping region.
  36. * Returns DFB_TRUE if at least one pixel of the line resides in the region.
  37. */
  38. DFBBoolean dfb_clip_line( const DFBRegion *clip, DFBRegion *line );
  39. /*
  40. * Clips the rectangle to the clipping region.
  41. * Returns true if there was an intersection with the clipping region.
  42. */
  43. DFBBoolean dfb_clip_rectangle( const DFBRegion *clip, DFBRectangle *rect );
  44. /*
  45. * Clips the rectangle to the clipping region.
  46. * Returns a flag for each edge that wasn't cut off.
  47. */
  48. DFBEdgeFlags dfb_clip_edges( const DFBRegion *clip, DFBRectangle *rect );
  49. static inline DFBBoolean
  50. dfb_clip_needed( const DFBRegion *clip, DFBRectangle *rect )
  51. {
  52. return ((clip->x1 > rect->x) ||
  53. (clip->y1 > rect->y) ||
  54. (clip->x2 < rect->x + rect->w - 1) ||
  55. (clip->y2 < rect->y + rect->h - 1));
  56. }
  57. /*
  58. * Simple check if triangle lies outside the clipping region.
  59. * Returns true if the triangle may be visible within the region.
  60. */
  61. DFBBoolean dfb_clip_triangle_precheck( const DFBRegion *clip,
  62. const DFBTriangle *tri );
  63. /*
  64. * Clips the triangle to the clipping region.
  65. * Returns true if the triangle if visible within the region.
  66. * The vertices of the polygon resulting from intersection are returned in buf.
  67. * The number of vertices is at least 3.
  68. */
  69. DFBBoolean dfb_clip_triangle( const DFBRegion *clip,
  70. const DFBTriangle *tri,
  71. DFBPoint buf[6],
  72. int *num );
  73. /*
  74. * Simple check if requested blitting lies outside of the clipping region.
  75. * Returns true if blitting may need to be performed.
  76. */
  77. static inline DFBBoolean
  78. dfb_clip_blit_precheck( const DFBRegion *clip,
  79. int w, int h, int dx, int dy )
  80. {
  81. if (w < 1 || h < 1 ||
  82. (clip->x1 >= dx + w) ||
  83. (clip->x2 < dx) ||
  84. (clip->y1 >= dy + h) ||
  85. (clip->y2 < dy))
  86. return DFB_FALSE;
  87. return DFB_TRUE;
  88. }
  89. /*
  90. * Clips the blitting request to the clipping region.
  91. * This includes adjustment of source AND destination coordinates.
  92. */
  93. void dfb_clip_blit( const DFBRegion *clip,
  94. DFBRectangle *srect, int *dx, int *dy );
  95. /*
  96. * Clips the stretch blit request to the clipping region.
  97. * This includes adjustment of source AND destination coordinates
  98. * based on the scaling factor.
  99. */
  100. void dfb_clip_stretchblit( const DFBRegion *clip,
  101. DFBRectangle *srect,
  102. DFBRectangle *drect );
  103. #endif