vp8li_dec.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // Copyright 2012 Google Inc. All Rights Reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the COPYING file in the root of the source
  5. // tree. An additional intellectual property rights grant can be found
  6. // in the file PATENTS. All contributing project authors may
  7. // be found in the AUTHORS file in the root of the source tree.
  8. // -----------------------------------------------------------------------------
  9. //
  10. // Lossless decoder: internal header.
  11. //
  12. // Author: Skal (pascal.massimino@gmail.com)
  13. // Vikas Arora(vikaas.arora@gmail.com)
  14. #ifndef WEBP_DEC_VP8LI_DEC_H_
  15. #define WEBP_DEC_VP8LI_DEC_H_
  16. #include <string.h> // for memcpy()
  17. #include "./webpi_dec.h"
  18. #include "../utils/bit_reader_utils.h"
  19. #include "../utils/color_cache_utils.h"
  20. #include "../utils/huffman_utils.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. typedef enum {
  25. READ_DATA = 0,
  26. READ_HDR = 1,
  27. READ_DIM = 2
  28. } VP8LDecodeState;
  29. typedef struct VP8LTransform VP8LTransform;
  30. struct VP8LTransform {
  31. VP8LImageTransformType type_; // transform type.
  32. int bits_; // subsampling bits defining transform window.
  33. int xsize_; // transform window X index.
  34. int ysize_; // transform window Y index.
  35. uint32_t* data_; // transform data.
  36. };
  37. typedef struct {
  38. int color_cache_size_;
  39. VP8LColorCache color_cache_;
  40. VP8LColorCache saved_color_cache_; // for incremental
  41. int huffman_mask_;
  42. int huffman_subsample_bits_;
  43. int huffman_xsize_;
  44. uint32_t* huffman_image_;
  45. int num_htree_groups_;
  46. HTreeGroup* htree_groups_;
  47. HuffmanCode* huffman_tables_;
  48. } VP8LMetadata;
  49. typedef struct VP8LDecoder VP8LDecoder;
  50. struct VP8LDecoder {
  51. VP8StatusCode status_;
  52. VP8LDecodeState state_;
  53. VP8Io* io_;
  54. const WebPDecBuffer* output_; // shortcut to io->opaque->output
  55. uint32_t* pixels_; // Internal data: either uint8_t* for alpha
  56. // or uint32_t* for BGRA.
  57. uint32_t* argb_cache_; // Scratch buffer for temporary BGRA storage.
  58. VP8LBitReader br_;
  59. int incremental_; // if true, incremental decoding is expected
  60. VP8LBitReader saved_br_; // note: could be local variables too
  61. int saved_last_pixel_;
  62. int width_;
  63. int height_;
  64. int last_row_; // last input row decoded so far.
  65. int last_pixel_; // last pixel decoded so far. However, it may
  66. // not be transformed, scaled and
  67. // color-converted yet.
  68. int last_out_row_; // last row output so far.
  69. VP8LMetadata hdr_;
  70. int next_transform_;
  71. VP8LTransform transforms_[NUM_TRANSFORMS];
  72. // or'd bitset storing the transforms types.
  73. uint32_t transforms_seen_;
  74. uint8_t* rescaler_memory; // Working memory for rescaling work.
  75. WebPRescaler* rescaler; // Common rescaler for all channels.
  76. };
  77. //------------------------------------------------------------------------------
  78. // internal functions. Not public.
  79. struct ALPHDecoder; // Defined in dec/alphai.h.
  80. // in vp8l.c
  81. // Decodes image header for alpha data stored using lossless compression.
  82. // Returns false in case of error.
  83. int VP8LDecodeAlphaHeader(struct ALPHDecoder* const alph_dec,
  84. const uint8_t* const data, size_t data_size);
  85. // Decodes *at least* 'last_row' rows of alpha. If some of the initial rows are
  86. // already decoded in previous call(s), it will resume decoding from where it
  87. // was paused.
  88. // Returns false in case of bitstream error.
  89. int VP8LDecodeAlphaImageStream(struct ALPHDecoder* const alph_dec,
  90. int last_row);
  91. // Allocates and initialize a new lossless decoder instance.
  92. VP8LDecoder* VP8LNew(void);
  93. // Decodes the image header. Returns false in case of error.
  94. int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);
  95. // Decodes an image. It's required to decode the lossless header before calling
  96. // this function. Returns false in case of error, with updated dec->status_.
  97. int VP8LDecodeImage(VP8LDecoder* const dec);
  98. // Resets the decoder in its initial state, reclaiming memory.
  99. // Preserves the dec->status_ value.
  100. void VP8LClear(VP8LDecoder* const dec);
  101. // Clears and deallocate a lossless decoder instance.
  102. void VP8LDelete(VP8LDecoder* const dec);
  103. //------------------------------------------------------------------------------
  104. #ifdef __cplusplus
  105. } // extern "C"
  106. #endif
  107. #endif // WEBP_DEC_VP8LI_DEC_H_