blob: be50e45bdb52af84f489c765592af31741e67b84 [file] [log] [blame]
Vikas Aroraa2415722012-08-09 16:18:58 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// This code is licensed under the same terms as WebM:
4// Software License Agreement: http://www.webmproject.org/license/software/
5// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6// -----------------------------------------------------------------------------
7//
8// Lossless decoder: internal header.
9//
10// Author: Skal (pascal.massimino@gmail.com)
11// Vikas Arora(vikaas.arora@gmail.com)
12
13#ifndef WEBP_DEC_VP8LI_H_
14#define WEBP_DEC_VP8LI_H_
15
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#include "webp/format_constants.h"
22
23#if defined(__cplusplus) || defined(c_plusplus)
24extern "C" {
25#endif
26
27typedef enum {
28 READ_DATA = 0,
29 READ_HDR = 1,
30 READ_DIM = 2
31} VP8LDecodeState;
32
33typedef struct VP8LTransform VP8LTransform;
34struct VP8LTransform {
35 VP8LImageTransformType type_; // transform type.
36 int bits_; // subsampling bits defining transform window.
37 int xsize_; // transform window X index.
38 int ysize_; // transform window Y index.
39 uint32_t *data_; // transform data.
40};
41
42typedef struct {
43 HuffmanTree htrees_[HUFFMAN_CODES_PER_META_CODE];
44} HTreeGroup;
45
46typedef struct {
47 int color_cache_size_;
48 VP8LColorCache color_cache_;
49
50 int huffman_mask_;
51 int huffman_subsample_bits_;
52 int huffman_xsize_;
53 uint32_t *huffman_image_;
54 int num_htree_groups_;
55 HTreeGroup *htree_groups_;
56} VP8LMetadata;
57
58typedef struct {
59 VP8StatusCode status_;
60 VP8LDecodeState action_;
61 VP8LDecodeState state_;
62 VP8Io *io_;
63
64 const WebPDecBuffer *output_; // shortcut to io->opaque->output
65
66 uint32_t *argb_; // Internal data: always in BGRA color mode.
67 uint32_t *argb_cache_; // Scratch buffer for temporary BGRA storage.
68
69 VP8LBitReader br_;
70
71 int width_;
72 int height_;
73 int last_row_; // last input row decoded so far.
74 int last_out_row_; // last row output so far.
75
76 VP8LMetadata hdr_;
77
78 int next_transform_;
79 VP8LTransform transforms_[NUM_TRANSFORMS];
80 // or'd bitset storing the transforms types.
81 uint32_t transforms_seen_;
82
83 uint8_t *rescaler_memory; // Working memory for rescaling work.
84 WebPRescaler *rescaler; // Common rescaler for all channels.
85} VP8LDecoder;
86
87//------------------------------------------------------------------------------
88// internal functions. Not public.
89
90// in vp8l.c
91
92// Decodes a raw image stream (without header) and store the alpha data
93// into *output, which must be of size width x height. Returns false in case
94// of error.
95int VP8LDecodeAlphaImageStream(int width, int height, const uint8_t* const data,
96 size_t data_size, uint8_t* const output);
97
98// Allocates and initialize a new lossless decoder instance.
99VP8LDecoder* VP8LNew(void);
100
101// Decodes the image header. Returns false in case of error.
102int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);
103
104// Decodes an image. It's required to decode the lossless header before calling
105// this function. Returns false in case of error, with updated dec->status_.
106int VP8LDecodeImage(VP8LDecoder* const dec);
107
108// Resets the decoder in its initial state, reclaiming memory.
109// Preserves the dec->status_ value.
110void VP8LClear(VP8LDecoder* const dec);
111
112// Clears and deallocate a lossless decoder instance.
113void VP8LDelete(VP8LDecoder* const dec);
114
115//------------------------------------------------------------------------------
116
117#if defined(__cplusplus) || defined(c_plusplus)
118} // extern "C"
119#endif
120
121#endif /* WEBP_DEC_VP8LI_H_ */