SURFACE.CPP 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/SURFACE.CPP 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : SURFACE.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 09/08/96 *
  26. * *
  27. * Last Update : September 8, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #if (0)//PG
  33. #include "FUNCTION.H"
  34. #include "surface.h"
  35. Surface::Surface(int w, int h, Buffer const * buffer, int pitch) :
  36. Width(w),
  37. Height(h),
  38. Pitch(pitch)
  39. {
  40. /*
  41. ** If a buffer was specified, then this means that the surface will use the buffer memory
  42. ** and thus not allocate and manage its own memory.
  43. */
  44. if (buffer != NULL) {
  45. SurfaceData = *buffer;
  46. /*
  47. ** Reduce the dimensions if the buffer is not big enough. This size bounding is only
  48. ** possible if the buffer size is known. Otherwise, presume that it is big enough.
  49. */
  50. if (buffer->Get_Size() > 0 && Get_Size() > buffer->Get_Size()) {
  51. Height = buffer->Get_Size() / (Width+Pitch);
  52. if (Height == 0) {
  53. Height = 1;
  54. Width = buffer->Get_Size();
  55. }
  56. }
  57. } else {
  58. /*
  59. ** A new buffer without existing memory specified, will allocate and manage its
  60. ** own memory for the surface.
  61. */
  62. new(&SurfaceData) Buffer(Logical_Size());
  63. }
  64. }
  65. Surface::Surface(Surface const & surface, int x, int y, int w, int h) :
  66. Width(w),
  67. Height(h),
  68. Pitch(surface.Bytes_Per_Line() % w)
  69. {
  70. new(&SurfaceData) Buffer((char*)surface.Get_Buffer() + y*surface.Bytes_Per_Line() + x);
  71. }
  72. void Surface::Copy_To(Buffer & buffer, int x, int y, int w, int h) const
  73. {
  74. assert(buffer.Is_Valid());
  75. /*
  76. ** Determine the width of the region to copy from this surface.
  77. */
  78. int width = w;
  79. if (width == -1) {
  80. width = Width;
  81. }
  82. /*
  83. ** Determine the height of the region to copy from this surface.
  84. */
  85. int height = h;
  86. if (height == -1) {
  87. height = Height;
  88. }
  89. Copy_To(Rect(x, y, width, height), buffer);
  90. }
  91. void Surface::Copy_To(Rect const & fromrect, Buffer & tobuffer) const
  92. {
  93. assert(fromrect.Is_Valid());
  94. assert(tobuffer.Is_Valid());
  95. /*
  96. ** Determine the copy-from rectangle. The size is bounded to the source
  97. ** size of the surface, regardless of what was specified as the source
  98. ** rectangle.
  99. */
  100. Rect rect = fromrect.Intersect(Rect(0, 0, Width, Height));
  101. /*
  102. ** Determine the number of bytes to copy. If this number would be
  103. ** larger than the size of the destination buffer (presuming the size
  104. ** of the destination buffer is known), then limit the copy size
  105. ** to the buffer size.
  106. */
  107. int tocopy = rect.Size();
  108. if (tobuffer.Get_Size() > 0 && tobuffer.Get_Size() > tocopy) {
  109. tocopy = tobuffer.Get_Size();
  110. }
  111. /*
  112. ** Determine the source starting byte pointer.
  113. */
  114. char * source = (char*)Get_Buffer() + rect.Y*Bytes_Per_Line() + rect.X;
  115. /*
  116. ** Determine the destination buffer pointer. This will always be the
  117. ** start of the destination buffer object specified.
  118. */
  119. char * dest = tobuffer;
  120. /*
  121. ** Determine the working pitch value to use. For full width surface
  122. ** copies on surfaces that have no inherent pitch, then a very fast
  123. ** copy-in-one-fast-step operation can be performed.
  124. */
  125. int pitch = Bytes_Per_Line() % rect.Width;
  126. if (pitch == 0) {
  127. memmove(dest, source, tocopy);
  128. } else {
  129. /*
  130. ** Copy the source to the destination in line segments.
  131. */
  132. for (int y = 0; y < rect.Height; y++) {
  133. memmove(dest, source, width);
  134. dest += rect.Width;
  135. source += rect.Width + pitch;
  136. }
  137. }
  138. }
  139. #endif