vp8li.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_H_
  15. #define WEBP_DEC_VP8LI_H_
  16. #include <string.h> // for memcpy()
  17. #include "./webpi.h"
  18. #include "../utils/bit_reader.h"
  19. #include "../utils/color_cache.h"
  20. #include "../utils/huffman.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. int huffman_mask_;
  41. int huffman_subsample_bits_;
  42. int huffman_xsize_;
  43. uint32_t *huffman_image_;
  44. int num_htree_groups_;
  45. HTreeGroup *htree_groups_;
  46. } VP8LMetadata;
  47. typedef struct VP8LDecoder VP8LDecoder;
  48. struct VP8LDecoder {
  49. VP8StatusCode status_;
  50. VP8LDecodeState action_;
  51. VP8LDecodeState state_;
  52. VP8Io *io_;
  53. const WebPDecBuffer *output_; // shortcut to io->opaque->output
  54. uint32_t *pixels_; // Internal data: either uint8_t* for alpha
  55. // or uint32_t* for BGRA.
  56. uint32_t *argb_cache_; // Scratch buffer for temporary BGRA storage.
  57. VP8LBitReader br_;
  58. int width_;
  59. int height_;
  60. int last_row_; // last input row decoded so far.
  61. int last_pixel_; // last pixel decoded so far. However, it may
  62. // not be transformed, scaled and
  63. // color-converted yet.
  64. int last_out_row_; // last row output so far.
  65. VP8LMetadata hdr_;
  66. int next_transform_;
  67. VP8LTransform transforms_[NUM_TRANSFORMS];
  68. // or'd bitset storing the transforms types.
  69. uint32_t transforms_seen_;
  70. uint8_t *rescaler_memory; // Working memory for rescaling work.
  71. WebPRescaler *rescaler; // Common rescaler for all channels.
  72. };
  73. //------------------------------------------------------------------------------
  74. // internal functions. Not public.
  75. struct ALPHDecoder; // Defined in dec/alphai.h.
  76. // in vp8l.c
  77. // Decodes image header for alpha data stored using lossless compression.
  78. // Returns false in case of error.
  79. int VP8LDecodeAlphaHeader(struct ALPHDecoder* const alph_dec,
  80. const uint8_t* const data, size_t data_size,
  81. uint8_t* const output);
  82. // Decodes *at least* 'last_row' rows of alpha. If some of the initial rows are
  83. // already decoded in previous call(s), it will resume decoding from where it
  84. // was paused.
  85. // Returns false in case of bitstream error.
  86. int VP8LDecodeAlphaImageStream(struct ALPHDecoder* const alph_dec,
  87. int last_row);
  88. // Allocates and initialize a new lossless decoder instance.
  89. VP8LDecoder* VP8LNew(void);
  90. // Decodes the image header. Returns false in case of error.
  91. int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);
  92. // Decodes an image. It's required to decode the lossless header before calling
  93. // this function. Returns false in case of error, with updated dec->status_.
  94. int VP8LDecodeImage(VP8LDecoder* const dec);
  95. // Resets the decoder in its initial state, reclaiming memory.
  96. // Preserves the dec->status_ value.
  97. void VP8LClear(VP8LDecoder* const dec);
  98. // Clears and deallocate a lossless decoder instance.
  99. void VP8LDelete(VP8LDecoder* const dec);
  100. //------------------------------------------------------------------------------
  101. #ifdef __cplusplus
  102. } // extern "C"
  103. #endif
  104. #endif /* WEBP_DEC_VP8LI_H_ */