lha_decoder.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Copyright (c) 2011, 2012, Simon Howard
  3. Permission to use, copy, modify, and/or distribute this software
  4. for any purpose with or without fee is hereby granted, provided
  5. that the above copyright notice and this permission notice appear
  6. in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  8. WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  9. WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  10. AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
  11. CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  12. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef LHASA_LHA_DECODER_H
  17. #define LHASA_LHA_DECODER_H
  18. #include "public/lha_decoder.h"
  19. struct _LHADecoderType {
  20. /**
  21. * Callback function to initialize the decoder.
  22. *
  23. * @param extra_data Pointer to the extra data area allocated for
  24. * the decoder.
  25. * @param callback Callback function to invoke to read more
  26. * compressed data.
  27. * @param callback_data Extra pointer to pass to the callback.
  28. * @return Non-zero for success.
  29. */
  30. int (*init)(void *extra_data,
  31. LHADecoderCallback callback,
  32. void *callback_data);
  33. /**
  34. * Callback function to free the decoder.
  35. *
  36. * @param extra_data Pointer to the extra data area allocated for
  37. * the decoder.
  38. */
  39. void (*free)(void *extra_data);
  40. /**
  41. * Callback function to read (ie. decompress) data from the
  42. * decoder.
  43. *
  44. * @param extra_data Pointer to the decoder's custom data.
  45. * @param buf Pointer to the buffer in which to store
  46. * the decompressed data. The buffer is
  47. * at least 'max_read' bytes in size.
  48. * @return Number of bytes decompressed.
  49. */
  50. size_t (*read)(void *extra_data, uint8_t *buf);
  51. /** Number of bytes of extra data to allocate for the decoder. */
  52. size_t extra_size;
  53. /** Maximum number of bytes that might be put into the buffer by
  54. a single call to read() */
  55. size_t max_read;
  56. /** Block size. Used for calculating number of blocks for
  57. progress bar. */
  58. size_t block_size;
  59. };
  60. struct _LHADecoder {
  61. /** Type of decoder (algorithm) */
  62. LHADecoderType *dtype;
  63. /** Callback function to monitor decoder progress. */
  64. LHADecoderProgressCallback progress_callback;
  65. void *progress_callback_data;
  66. /** Last announced block position, for progress callback. */
  67. unsigned int last_block, total_blocks;
  68. /** Current position in the decode stream, and total length. */
  69. size_t stream_pos, stream_length;
  70. /** Output buffer, containing decoded data not yet returned. */
  71. unsigned int outbuf_pos, outbuf_len;
  72. uint8_t *outbuf;
  73. /** If true, the decoder read() function returned zero. */
  74. unsigned int decoder_failed;
  75. /** Current CRC of the output stream. */
  76. uint16_t crc;
  77. };
  78. #endif /* #ifndef LHASA_LHA_DECODER_H */