lzo.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWLib *
  23. * *
  24. * $Archive:: /Commando/Code/wwlib/lzo.cpp $*
  25. * *
  26. * Author:: Greg Hjelstrom *
  27. * *
  28. * $Modtime:: 8/24/01 5:07p $*
  29. * *
  30. * $Revision:: 7 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * LZOCompressor::Compress -- compress a buffer using LZO *
  35. * LZOCompressor::Decompress -- decompress a buffer using LZO *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "lzo.h"
  38. #include "mutex.h"
  39. #include "wwdebug.h"
  40. #include <stdlib.h>
  41. /*
  42. ** Work Buffer for the LZOCompressor...
  43. */
  44. lzo_byte LZOCompressor::WorkBuffer[LZO1X_MEM_COMPRESS + 1];
  45. lzo_byte * LZOCompressor::EOWorkBuffer = &(LZOCompressor::WorkBuffer[LZO1X_MEM_COMPRESS + 1]);
  46. static CriticalSectionClass mutex;
  47. #define BUFFER_OVERRUN_TEST_VALUE ((char)0x7d)
  48. /***********************************************************************************************
  49. * LZOCompressor::Compress -- compress a buffer using LZO *
  50. * *
  51. * INPUT: *
  52. * *
  53. * OUTPUT: *
  54. * *
  55. * WARNINGS: *
  56. * *
  57. * HISTORY: *
  58. * 7/19/99 GTH : Created. *
  59. *=============================================================================================*/
  60. int LZOCompressor::Compress
  61. (
  62. const lzo_byte * in,
  63. lzo_uint in_len,
  64. lzo_byte * out,
  65. lzo_uint * out_len
  66. )
  67. {
  68. CriticalSectionClass::LockClass m(mutex);
  69. #ifdef WWDEBUG
  70. // Debugging code to verify that the work buffer is not overrun...
  71. *EOWorkBuffer = BUFFER_OVERRUN_TEST_VALUE;
  72. #endif
  73. int result = lzo1x_1_compress(in,in_len,out,out_len,WorkBuffer);
  74. #ifdef WWDEBUG
  75. WWASSERT(*EOWorkBuffer == BUFFER_OVERRUN_TEST_VALUE);
  76. #endif
  77. return result;
  78. }
  79. /***********************************************************************************************
  80. * LZOCompressor::Decompress -- decompress a buffer using LZO *
  81. * *
  82. * INPUT: *
  83. * *
  84. * OUTPUT: *
  85. * *
  86. * WARNINGS: *
  87. * *
  88. * HISTORY: *
  89. * 7/19/99 GTH : Created. *
  90. *=============================================================================================*/
  91. int LZOCompressor::Decompress
  92. (
  93. const lzo_byte * in,
  94. lzo_uint in_len,
  95. lzo_byte * out,
  96. lzo_uint * out_len
  97. )
  98. {
  99. CriticalSectionClass::LockClass m(mutex);
  100. return lzo1x_decompress(in,in_len,out,out_len,NULL);
  101. }