Path: blob/master/thirdparty/libwebp/src/dec/vp8li_dec.h
9912 views
// Copyright 2012 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Lossless decoder: internal header.10//11// Author: Skal ([email protected])12// Vikas Arora([email protected])1314#ifndef WEBP_DEC_VP8LI_DEC_H_15#define WEBP_DEC_VP8LI_DEC_H_1617#include <string.h> // for memcpy()18#include "src/dec/webpi_dec.h"19#include "src/utils/bit_reader_utils.h"20#include "src/utils/color_cache_utils.h"21#include "src/utils/huffman_utils.h"22#include "src/webp/types.h"2324#ifdef __cplusplus25extern "C" {26#endif2728typedef enum {29READ_DATA = 0,30READ_HDR = 1,31READ_DIM = 232} VP8LDecodeState;3334typedef struct VP8LTransform VP8LTransform;35struct VP8LTransform {36VP8LImageTransformType type_; // transform type.37int bits_; // subsampling bits defining transform window.38int xsize_; // transform window X index.39int ysize_; // transform window Y index.40uint32_t* data_; // transform data.41};4243typedef struct {44int color_cache_size_;45VP8LColorCache color_cache_;46VP8LColorCache saved_color_cache_; // for incremental4748int huffman_mask_;49int huffman_subsample_bits_;50int huffman_xsize_;51uint32_t* huffman_image_;52int num_htree_groups_;53HTreeGroup* htree_groups_;54HuffmanTables huffman_tables_;55} VP8LMetadata;5657typedef struct VP8LDecoder VP8LDecoder;58struct VP8LDecoder {59VP8StatusCode status_;60VP8LDecodeState state_;61VP8Io* io_;6263const WebPDecBuffer* output_; // shortcut to io->opaque->output6465uint32_t* pixels_; // Internal data: either uint8_t* for alpha66// or uint32_t* for BGRA.67uint32_t* argb_cache_; // Scratch buffer for temporary BGRA storage.6869VP8LBitReader br_;70int incremental_; // if true, incremental decoding is expected71VP8LBitReader saved_br_; // note: could be local variables too72int saved_last_pixel_;7374int width_;75int height_;76int last_row_; // last input row decoded so far.77int last_pixel_; // last pixel decoded so far. However, it may78// not be transformed, scaled and79// color-converted yet.80int last_out_row_; // last row output so far.8182VP8LMetadata hdr_;8384int next_transform_;85VP8LTransform transforms_[NUM_TRANSFORMS];86// or'd bitset storing the transforms types.87uint32_t transforms_seen_;8889uint8_t* rescaler_memory; // Working memory for rescaling work.90WebPRescaler* rescaler; // Common rescaler for all channels.91};9293//------------------------------------------------------------------------------94// internal functions. Not public.9596struct ALPHDecoder; // Defined in dec/alphai.h.9798// in vp8l.c99100// Decodes image header for alpha data stored using lossless compression.101// Returns false in case of error.102WEBP_NODISCARD int VP8LDecodeAlphaHeader(struct ALPHDecoder* const alph_dec,103const uint8_t* const data,104size_t data_size);105106// Decodes *at least* 'last_row' rows of alpha. If some of the initial rows are107// already decoded in previous call(s), it will resume decoding from where it108// was paused.109// Returns false in case of bitstream error.110WEBP_NODISCARD int VP8LDecodeAlphaImageStream(111struct ALPHDecoder* const alph_dec, int last_row);112113// Allocates and initialize a new lossless decoder instance.114WEBP_NODISCARD VP8LDecoder* VP8LNew(void);115116// Decodes the image header. Returns false in case of error.117WEBP_NODISCARD int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);118119// Decodes an image. It's required to decode the lossless header before calling120// this function. Returns false in case of error, with updated dec->status_.121WEBP_NODISCARD int VP8LDecodeImage(VP8LDecoder* const dec);122123// Clears and deallocate a lossless decoder instance.124void VP8LDelete(VP8LDecoder* const dec);125126// Helper function for reading the different Huffman codes and storing them in127// 'huffman_tables' and 'htree_groups'.128// If mapping is NULL 'num_htree_groups_max' must equal 'num_htree_groups'.129// If it is not NULL, it maps 'num_htree_groups_max' indices to the130// 'num_htree_groups' groups. If 'num_htree_groups_max' > 'num_htree_groups',131// some of those indices map to -1. This is used for non-balanced codes to132// limit memory usage.133WEBP_NODISCARD int ReadHuffmanCodesHelper(134int color_cache_bits, int num_htree_groups, int num_htree_groups_max,135const int* const mapping, VP8LDecoder* const dec,136HuffmanTables* const huffman_tables, HTreeGroup** const htree_groups);137138//------------------------------------------------------------------------------139140#ifdef __cplusplus141} // extern "C"142#endif143144#endif // WEBP_DEC_VP8LI_DEC_H_145146147