Path: blob/master/thirdparty/libwebp/src/dec/vp8li_dec.h
21431 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()1819#include "src/dec/vp8_dec.h"20#include "src/dec/webpi_dec.h"21#include "src/utils/bit_reader_utils.h"22#include "src/utils/color_cache_utils.h"23#include "src/utils/huffman_utils.h"24#include "src/utils/rescaler_utils.h"25#include "src/webp/decode.h"26#include "src/webp/format_constants.h"27#include "src/webp/types.h"2829#ifdef __cplusplus30extern "C" {31#endif3233typedef enum {34READ_DATA = 0,35READ_HDR = 1,36READ_DIM = 237} VP8LDecodeState;3839typedef struct VP8LTransform VP8LTransform;40struct VP8LTransform {41VP8LImageTransformType type; // transform type.42int bits; // subsampling bits defining transform window.43int xsize; // transform window X index.44int ysize; // transform window Y index.45uint32_t* data; // transform data.46};4748typedef struct {49int color_cache_size;50VP8LColorCache color_cache;51VP8LColorCache saved_color_cache; // for incremental5253int huffman_mask;54int huffman_subsample_bits;55int huffman_xsize;56uint32_t* huffman_image;57int num_htree_groups;58HTreeGroup* htree_groups;59HuffmanTables huffman_tables;60} VP8LMetadata;6162typedef struct VP8LDecoder VP8LDecoder;63struct VP8LDecoder {64VP8StatusCode status;65VP8LDecodeState state;66VP8Io* io;6768const WebPDecBuffer* output; // shortcut to io->opaque->output6970uint32_t* pixels; // Internal data: either uint8_t* for alpha71// or uint32_t* for BGRA.72uint32_t* argb_cache; // Scratch buffer for temporary BGRA storage.7374VP8LBitReader br;75int incremental; // if true, incremental decoding is expected76VP8LBitReader saved_br; // note: could be local variables too77int saved_last_pixel;7879int width;80int height;81int last_row; // last input row decoded so far.82int last_pixel; // last pixel decoded so far. However, it may83// not be transformed, scaled and84// color-converted yet.85int last_out_row; // last row output so far.8687VP8LMetadata hdr;8889int next_transform;90VP8LTransform transforms[NUM_TRANSFORMS];91// or'd bitset storing the transforms types.92uint32_t transforms_seen;9394uint8_t* rescaler_memory; // Working memory for rescaling work.95WebPRescaler* rescaler; // Common rescaler for all channels.96};9798//------------------------------------------------------------------------------99// internal functions. Not public.100101struct ALPHDecoder; // Defined in dec/alphai.h.102103// in vp8l.c104105// Decodes image header for alpha data stored using lossless compression.106// Returns false in case of error.107WEBP_NODISCARD int VP8LDecodeAlphaHeader(struct ALPHDecoder* const alph_dec,108const uint8_t* const data,109size_t data_size);110111// Decodes *at least* 'last_row' rows of alpha. If some of the initial rows are112// already decoded in previous call(s), it will resume decoding from where it113// was paused.114// Returns false in case of bitstream error.115WEBP_NODISCARD int VP8LDecodeAlphaImageStream(116struct ALPHDecoder* const alph_dec, int last_row);117118// Allocates and initialize a new lossless decoder instance.119WEBP_NODISCARD VP8LDecoder* VP8LNew(void);120121// Decodes the image header. Returns false in case of error.122WEBP_NODISCARD int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);123124// Decodes an image. It's required to decode the lossless header before calling125// this function. Returns false in case of error, with updated dec->status.126WEBP_NODISCARD int VP8LDecodeImage(VP8LDecoder* const dec);127128// Clears and deallocate a lossless decoder instance.129void VP8LDelete(VP8LDecoder* const dec);130131// Helper function for reading the different Huffman codes and storing them in132// 'huffman_tables' and 'htree_groups'.133// If mapping is NULL 'num_htree_groups_max' must equal 'num_htree_groups'.134// If it is not NULL, it maps 'num_htree_groups_max' indices to the135// 'num_htree_groups' groups. If 'num_htree_groups_max' > 'num_htree_groups',136// some of those indices map to -1. This is used for non-balanced codes to137// limit memory usage.138WEBP_NODISCARD int ReadHuffmanCodesHelper(139int color_cache_bits, int num_htree_groups, int num_htree_groups_max,140const int* const mapping, VP8LDecoder* const dec,141HuffmanTables* const huffman_tables, HTreeGroup** const htree_groups);142143//------------------------------------------------------------------------------144145#ifdef __cplusplus146} // extern "C"147#endif148149#endif // WEBP_DEC_VP8LI_DEC_H_150151152