| 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_ENC_H_ | 
| 15 | #define WEBP_ENC_VP8LI_ENC_H_ | 
| 16 |  | 
| 17 | #ifdef HAVE_CONFIG_H | 
| 18 | #include "src/webp/config.h" | 
| 19 | #endif | 
| 20 | // Either WEBP_NEAR_LOSSLESS is defined as 0 in config.h when compiling to | 
| 21 | // disable near-lossless, or it is enabled by default. | 
| 22 | #ifndef WEBP_NEAR_LOSSLESS | 
| 23 | #define WEBP_NEAR_LOSSLESS 1 | 
| 24 | #endif | 
| 25 |  | 
| 26 | #include "src/enc/backward_references_enc.h" | 
| 27 | #include "src/enc/histogram_enc.h" | 
| 28 | #include "src/utils/bit_writer_utils.h" | 
| 29 | #include "src/webp/encode.h" | 
| 30 | #include "src/webp/format_constants.h" | 
| 31 |  | 
| 32 | #ifdef __cplusplus | 
| 33 | extern "C"  { | 
| 34 | #endif | 
| 35 |  | 
| 36 | // maximum value of transform_bits_ in VP8LEncoder. | 
| 37 | #define MAX_TRANSFORM_BITS 6 | 
| 38 |  | 
| 39 | typedef enum { | 
| 40 |   kEncoderNone = 0, | 
| 41 |   kEncoderARGB, | 
| 42 |   kEncoderNearLossless, | 
| 43 |   kEncoderPalette | 
| 44 | } VP8LEncoderARGBContent; | 
| 45 |  | 
| 46 | typedef struct { | 
| 47 |   const WebPConfig* config_;      // user configuration and parameters | 
| 48 |   const WebPPicture* pic_;        // input picture. | 
| 49 |  | 
| 50 |   uint32_t* argb_;                       // Transformed argb image data. | 
| 51 |   VP8LEncoderARGBContent argb_content_;  // Content type of the argb buffer. | 
| 52 |   uint32_t* argb_scratch_;               // Scratch memory for argb rows | 
| 53 |                                          // (used for prediction). | 
| 54 |   uint32_t* transform_data_;             // Scratch memory for transform data. | 
| 55 |   uint32_t* transform_mem_;              // Currently allocated memory. | 
| 56 |   size_t    transform_mem_size_;         // Currently allocated memory size. | 
| 57 |  | 
| 58 |   int       current_width_;       // Corresponds to packed image width. | 
| 59 |  | 
| 60 |   // Encoding parameters derived from quality parameter. | 
| 61 |   int histo_bits_; | 
| 62 |   int transform_bits_;    // <= MAX_TRANSFORM_BITS. | 
| 63 |   int cache_bits_;        // If equal to 0, don't use color cache. | 
| 64 |  | 
| 65 |   // Encoding parameters derived from image characteristics. | 
| 66 |   int use_cross_color_; | 
| 67 |   int use_subtract_green_; | 
| 68 |   int use_predict_; | 
| 69 |   int use_palette_; | 
| 70 |   int palette_size_; | 
| 71 |   uint32_t palette_[MAX_PALETTE_SIZE]; | 
| 72 |  | 
| 73 |   // Some 'scratch' (potentially large) objects. | 
| 74 |   struct VP8LBackwardRefs refs_[3];  // Backward Refs array for temporaries. | 
| 75 |   VP8LHashChain hash_chain_;         // HashChain data for constructing | 
| 76 |                                      // backward references. | 
| 77 | } VP8LEncoder; | 
| 78 |  | 
| 79 | //------------------------------------------------------------------------------ | 
| 80 | // internal functions. Not public. | 
| 81 |  | 
| 82 | // Encodes the picture. | 
| 83 | // Returns 0 if config or picture is NULL or picture doesn't have valid argb | 
| 84 | // input. | 
| 85 | int VP8LEncodeImage(const WebPConfig* const config, | 
| 86 |                     const WebPPicture* const picture); | 
| 87 |  | 
| 88 | // Encodes the main image stream using the supplied bit writer. | 
| 89 | // If 'use_cache' is false, disables the use of color cache. | 
| 90 | WebPEncodingError VP8LEncodeStream(const WebPConfig* const config, | 
| 91 |                                    const WebPPicture* const picture, | 
| 92 |                                    VP8LBitWriter* const bw, int use_cache); | 
| 93 |  | 
| 94 | #if (WEBP_NEAR_LOSSLESS == 1) | 
| 95 | // in near_lossless.c | 
| 96 | // Near lossless preprocessing in RGB color-space. | 
| 97 | int VP8ApplyNearLossless(const WebPPicture* const picture, int quality, | 
| 98 |                          uint32_t* const argb_dst); | 
| 99 | #endif | 
| 100 |  | 
| 101 | //------------------------------------------------------------------------------ | 
| 102 | // Image transforms in predictor.c. | 
| 103 |  | 
| 104 | void VP8LResidualImage(int width, int height, int bits, int low_effort, | 
| 105 |                        uint32_t* const argb, uint32_t* const argb_scratch, | 
| 106 |                        uint32_t* const image, int near_lossless, int exact, | 
| 107 |                        int used_subtract_green); | 
| 108 |  | 
| 109 | void VP8LColorSpaceTransform(int width, int height, int bits, int quality, | 
| 110 |                              uint32_t* const argb, uint32_t* image); | 
| 111 |  | 
| 112 | //------------------------------------------------------------------------------ | 
| 113 |  | 
| 114 | #ifdef __cplusplus | 
| 115 | }    // extern "C" | 
| 116 | #endif | 
| 117 |  | 
| 118 | #endif  // WEBP_ENC_VP8LI_ENC_H_ | 
| 119 |  |