Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.3 KiB

  1. /*
  2. * decapi.c
  3. *
  4. * API entry points.
  5. */
  6. #define ALLOC_VARS
  7. #include "decoder.h"
  8. #include <stdio.h>
  9. bool LZX_DecodeInit(
  10. t_decoder_context * context,
  11. long compression_window_size,
  12. PFNALLOC pfnma,
  13. PFNFREE pfnmf,
  14. PFNOPEN pfnopen,
  15. PFNREAD pfnread,
  16. PFNWRITE pfnwrite,
  17. PFNCLOSE pfnclose,
  18. PFNSEEK pfnseek
  19. )
  20. {
  21. context->dec_malloc = pfnma;
  22. context->dec_free = pfnmf;
  23. /* used for 16-bit swap file only */
  24. context->dec_open = pfnopen;
  25. context->dec_read = pfnread;
  26. context->dec_write = pfnwrite;
  27. context->dec_close = pfnclose;
  28. context->dec_seek = pfnseek;
  29. context->dec_window_size = compression_window_size;
  30. context->dec_window_mask = context->dec_window_size - 1;
  31. /*
  32. * Window size must be a power of 2
  33. */
  34. if (context->dec_window_size & context->dec_window_mask)
  35. return false;
  36. if (allocate_decompression_memory(context) == false)
  37. return false;
  38. LZX_DecodeNewGroup(context);
  39. return true;
  40. }
  41. void LZX_DecodeFree(t_decoder_context *context)
  42. {
  43. free_decompression_memory(context);
  44. }
  45. void LZX_DecodeNewGroup(t_decoder_context *context)
  46. {
  47. reset_decoder_trees(context);
  48. decoder_misc_init(context);
  49. init_decoder_translation(context);
  50. context->dec_num_cfdata_frames = 0;
  51. #ifdef BIT16
  52. DComp_Reset(context);
  53. #endif
  54. }
  55. int LZX_Decode(
  56. t_decoder_context *context,
  57. long bytes_to_decode,
  58. byte * compressed_input_buffer,
  59. long compressed_input_size,
  60. byte * uncompressed_output_buffer,
  61. long uncompressed_output_size,
  62. long * bytes_decoded
  63. )
  64. {
  65. long result;
  66. context->dec_input_curpos = compressed_input_buffer;
  67. context->dec_end_input_pos = (compressed_input_buffer + compressed_input_size + 4);
  68. context->dec_output_buffer = uncompressed_output_buffer;
  69. #ifdef BIT16
  70. context->dec_output_curpos = uncompressed_output_buffer;
  71. context->DComp.NumBytes = (unsigned short) uncompressed_output_size;
  72. #endif
  73. init_decoder_input(context);
  74. result = decode_data(context, bytes_to_decode);
  75. context->dec_num_cfdata_frames++;
  76. if (result < 0)
  77. {
  78. *bytes_decoded = 0;
  79. return 1; /* failure */
  80. }
  81. else
  82. {
  83. *bytes_decoded = result;
  84. context->dec_position_at_start += result;
  85. return 0; /* success */
  86. }
  87. }