| 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 encoder: internal header. |
| 11 | // |
| 12 | // Author: Vikas Arora (vikaas.arora@gmail.com) |
| 13 | |
| 14 | #ifndef WEBP_ENC_VP8LI_H_ |
| 15 | #define WEBP_ENC_VP8LI_H_ |
| 16 | |
| 17 | #include "./backward_references_enc.h" |
| 18 | #include "./histogram_enc.h" |
| 19 | #include "../utils/bit_writer_utils.h" |
| 20 | #include "../webp/encode.h" |
| 21 | #include "../webp/format_constants.h" |
| 22 | |
| 23 | #ifdef __cplusplus |
| 24 | extern "C" { |
| 25 | #endif |
| 26 | |
| 27 | // maximum value of transform_bits_ in VP8LEncoder. |
| 28 | #define MAX_TRANSFORM_BITS 6 |
| 29 | |
| 30 | typedef struct { |
| 31 | const WebPConfig* config_; // user configuration and parameters |
| 32 | const WebPPicture* pic_; // input picture. |
| 33 | |
| 34 | uint32_t* argb_; // Transformed argb image data. |
| 35 | uint32_t* argb_scratch_; // Scratch memory for argb rows |
| 36 | // (used for prediction). |
| 37 | uint32_t* transform_data_; // Scratch memory for transform data. |
| 38 | uint32_t* transform_mem_; // Currently allocated memory. |
| 39 | size_t transform_mem_size_; // Currently allocated memory size. |
| 40 | |
| 41 | int current_width_; // Corresponds to packed image width. |
| 42 | |
| 43 | // Encoding parameters derived from quality parameter. |
| 44 | int histo_bits_; |
| 45 | int transform_bits_; // <= MAX_TRANSFORM_BITS. |
| 46 | int cache_bits_; // If equal to 0, don't use color cache. |
| 47 | |
| 48 | // Encoding parameters derived from image characteristics. |
| 49 | int use_cross_color_; |
| 50 | int use_subtract_green_; |
| 51 | int use_predict_; |
| 52 | int use_palette_; |
| 53 | int palette_size_; |
| 54 | uint32_t palette_[MAX_PALETTE_SIZE]; |
| 55 | |
| 56 | // Some 'scratch' (potentially large) objects. |
| 57 | struct VP8LBackwardRefs refs_[2]; // Backward Refs array corresponding to |
| 58 | // LZ77 & RLE coding. |
| 59 | VP8LHashChain hash_chain_; // HashChain data for constructing |
| 60 | // backward references. |
| 61 | } VP8LEncoder; |
| 62 | |
| 63 | //------------------------------------------------------------------------------ |
| 64 | // internal functions. Not public. |
| 65 | |
| 66 | // Encodes the picture. |
| 67 | // Returns 0 if config or picture is NULL or picture doesn't have valid argb |
| 68 | // input. |
| 69 | int VP8LEncodeImage(const WebPConfig* const config, |
| 70 | const WebPPicture* const picture); |
| 71 | |
| 72 | // Encodes the main image stream using the supplied bit writer. |
| 73 | // If 'use_cache' is false, disables the use of color cache. |
| 74 | WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, |
| 75 | const WebPPicture* const picture, |
| 76 | VP8LBitWriter* const bw, int use_cache); |
| 77 | |
| 78 | //------------------------------------------------------------------------------ |
| 79 | // Image transforms in predictor.c. |
| 80 | |
| 81 | void VP8LResidualImage(int width, int height, int bits, int low_effort, |
| 82 | uint32_t* const argb, uint32_t* const argb_scratch, |
| 83 | uint32_t* const image, int near_lossless, int exact, |
| 84 | int used_subtract_green); |
| 85 | |
| 86 | void VP8LColorSpaceTransform(int width, int height, int bits, int quality, |
| 87 | uint32_t* const argb, uint32_t* image); |
| 88 | |
| 89 | //------------------------------------------------------------------------------ |
| 90 | |
| 91 | #ifdef __cplusplus |
| 92 | } // extern "C" |
| 93 | #endif |
| 94 | |
| 95 | #endif /* WEBP_ENC_VP8LI_H_ */ |
| 96 | |