d_fill.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // d_clear: clears a specified rectangle to the specified color
  16. #include "quakedef.h"
  17. /*
  18. ================
  19. D_FillRect
  20. ================
  21. */
  22. void D_FillRect (vrect_t *rect, int color)
  23. {
  24. int rx, ry, rwidth, rheight;
  25. unsigned char *dest;
  26. unsigned *ldest;
  27. rx = rect->x;
  28. ry = rect->y;
  29. rwidth = rect->width;
  30. rheight = rect->height;
  31. if (rx < 0)
  32. {
  33. rwidth += rx;
  34. rx = 0;
  35. }
  36. if (ry < 0)
  37. {
  38. rheight += ry;
  39. ry = 0;
  40. }
  41. if (rx+rwidth > vid.width)
  42. rwidth = vid.width - rx;
  43. if (ry+rheight > vid.height)
  44. rheight = vid.height - rx;
  45. if (rwidth < 1 || rheight < 1)
  46. return;
  47. dest = ((byte *)vid.buffer + ry*vid.rowbytes + rx);
  48. if (((rwidth & 0x03) == 0) && (((long)dest & 0x03) == 0))
  49. {
  50. // faster aligned dword clear
  51. ldest = (unsigned *)dest;
  52. color += color << 16;
  53. rwidth >>= 2;
  54. color += color << 8;
  55. for (ry=0 ; ry<rheight ; ry++)
  56. {
  57. for (rx=0 ; rx<rwidth ; rx++)
  58. ldest[rx] = color;
  59. ldest = (unsigned *)((byte*)ldest + vid.rowbytes);
  60. }
  61. }
  62. else
  63. {
  64. // slower byte-by-byte clear for unaligned cases
  65. for (ry=0 ; ry<rheight ; ry++)
  66. {
  67. for (rx=0 ; rx<rwidth ; rx++)
  68. dest[rx] = color;
  69. dest += vid.rowbytes;
  70. }
  71. }
  72. }