tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

vp8li_dec.h (5508B)


      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 
     15 #ifndef WEBP_DEC_VP8LI_DEC_H_
     16 #define WEBP_DEC_VP8LI_DEC_H_
     17 
     18 #include <string.h>     // for memcpy()
     19 
     20 #include "src/dec/vp8_dec.h"
     21 #include "src/dec/webpi_dec.h"
     22 #include "src/utils/bit_reader_utils.h"
     23 #include "src/utils/color_cache_utils.h"
     24 #include "src/utils/huffman_utils.h"
     25 #include "src/utils/rescaler_utils.h"
     26 #include "src/webp/decode.h"
     27 #include "src/webp/format_constants.h"
     28 #include "src/webp/types.h"
     29 
     30 #ifdef __cplusplus
     31 extern "C" {
     32 #endif
     33 
     34 typedef enum {
     35  READ_DATA = 0,
     36  READ_HDR = 1,
     37  READ_DIM = 2
     38 } VP8LDecodeState;
     39 
     40 typedef struct VP8LTransform VP8LTransform;
     41 struct VP8LTransform {
     42  VP8LImageTransformType type;   // transform type.
     43  int                    bits;   // subsampling bits defining transform window.
     44  int                    xsize;  // transform window X index.
     45  int                    ysize;  // transform window Y index.
     46  uint32_t*              data;   // transform data.
     47 };
     48 
     49 typedef struct {
     50  int             color_cache_size;
     51  VP8LColorCache  color_cache;
     52  VP8LColorCache  saved_color_cache;  // for incremental
     53 
     54  int             huffman_mask;
     55  int             huffman_subsample_bits;
     56  int             huffman_xsize;
     57  uint32_t*       huffman_image;
     58  int             num_htree_groups;
     59  HTreeGroup*     htree_groups;
     60  HuffmanTables   huffman_tables;
     61 } VP8LMetadata;
     62 
     63 typedef struct VP8LDecoder VP8LDecoder;
     64 struct VP8LDecoder {
     65  VP8StatusCode    status;
     66  VP8LDecodeState  state;
     67  VP8Io*           io;
     68 
     69  const WebPDecBuffer* output;    // shortcut to io->opaque->output
     70 
     71  uint32_t*        pixels;        // Internal data: either uint8_t* for alpha
     72                                  // or uint32_t* for BGRA.
     73  uint32_t*        argb_cache;    // Scratch buffer for temporary BGRA storage.
     74 
     75  VP8LBitReader    br;
     76  int              incremental;   // if true, incremental decoding is expected
     77  VP8LBitReader    saved_br;      // note: could be local variables too
     78  int              saved_last_pixel;
     79 
     80  int              width;
     81  int              height;
     82  int              last_row;      // last input row decoded so far.
     83  int              last_pixel;    // last pixel decoded so far. However, it may
     84                                  // not be transformed, scaled and
     85                                  // color-converted yet.
     86  int              last_out_row;  // last row output so far.
     87 
     88  VP8LMetadata     hdr;
     89 
     90  int              next_transform;
     91  VP8LTransform    transforms[NUM_TRANSFORMS];
     92  // or'd bitset storing the transforms types.
     93  uint32_t         transforms_seen;
     94 
     95  uint8_t*         rescaler_memory;  // Working memory for rescaling work.
     96  WebPRescaler*    rescaler;         // Common rescaler for all channels.
     97 };
     98 
     99 //------------------------------------------------------------------------------
    100 // internal functions. Not public.
    101 
    102 struct ALPHDecoder;  // Defined in dec/alphai.h.
    103 
    104 // in vp8l.c
    105 
    106 // Decodes image header for alpha data stored using lossless compression.
    107 // Returns false in case of error.
    108 WEBP_NODISCARD int VP8LDecodeAlphaHeader(struct ALPHDecoder* const alph_dec,
    109                                         const uint8_t* const data,
    110                                         size_t data_size);
    111 
    112 // Decodes *at least* 'last_row' rows of alpha. If some of the initial rows are
    113 // already decoded in previous call(s), it will resume decoding from where it
    114 // was paused.
    115 // Returns false in case of bitstream error.
    116 WEBP_NODISCARD int VP8LDecodeAlphaImageStream(
    117    struct ALPHDecoder* const alph_dec, int last_row);
    118 
    119 // Allocates and initialize a new lossless decoder instance.
    120 WEBP_NODISCARD VP8LDecoder* VP8LNew(void);
    121 
    122 // Decodes the image header. Returns false in case of error.
    123 WEBP_NODISCARD int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io);
    124 
    125 // Decodes an image. It's required to decode the lossless header before calling
    126 // this function. Returns false in case of error, with updated dec->status.
    127 WEBP_NODISCARD int VP8LDecodeImage(VP8LDecoder* const dec);
    128 
    129 // Clears and deallocate a lossless decoder instance.
    130 void VP8LDelete(VP8LDecoder* const dec);
    131 
    132 // Helper function for reading the different Huffman codes and storing them in
    133 // 'huffman_tables' and 'htree_groups'.
    134 // If mapping is NULL 'num_htree_groups_max' must equal 'num_htree_groups'.
    135 // If it is not NULL, it maps 'num_htree_groups_max' indices to the
    136 // 'num_htree_groups' groups. If 'num_htree_groups_max' > 'num_htree_groups',
    137 // some of those indices map to -1. This is used for non-balanced codes to
    138 // limit memory usage.
    139 WEBP_NODISCARD int ReadHuffmanCodesHelper(
    140    int color_cache_bits, int num_htree_groups, int num_htree_groups_max,
    141    const int* const mapping, VP8LDecoder* const dec,
    142    HuffmanTables* const huffman_tables, HTreeGroup** const htree_groups);
    143 
    144 //------------------------------------------------------------------------------
    145 
    146 #ifdef __cplusplus
    147 }    // extern "C"
    148 #endif
    149 
    150 #endif  // WEBP_DEC_VP8LI_DEC_H_