vp8li_enc.h (5066B)
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 21 #include <stddef.h> 22 23 // Either WEBP_NEAR_LOSSLESS is defined as 0 in config.h when compiling to 24 // disable near-lossless, or it is enabled by default. 25 #ifndef WEBP_NEAR_LOSSLESS 26 #define WEBP_NEAR_LOSSLESS 1 27 #endif 28 29 #include "src/webp/types.h" 30 #include "src/enc/backward_references_enc.h" 31 #include "src/enc/histogram_enc.h" 32 #include "src/utils/bit_writer_utils.h" 33 #include "src/webp/encode.h" 34 #include "src/webp/format_constants.h" 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 // maximum value of 'transform_bits' in VP8LEncoder. 41 #define MAX_TRANSFORM_BITS (MIN_TRANSFORM_BITS + (1 << NUM_TRANSFORM_BITS) - 1) 42 43 typedef enum { 44 kEncoderNone = 0, 45 kEncoderARGB, 46 kEncoderNearLossless, 47 kEncoderPalette 48 } VP8LEncoderARGBContent; 49 50 typedef struct { 51 const WebPConfig* config; // user configuration and parameters 52 const WebPPicture* pic; // input picture. 53 54 uint32_t* argb; // Transformed argb image data. 55 VP8LEncoderARGBContent argb_content; // Content type of the argb buffer. 56 uint32_t* argb_scratch; // Scratch memory for argb rows 57 // (used for prediction). 58 uint32_t* transform_data; // Scratch memory for transform data. 59 uint32_t* transform_mem; // Currently allocated memory. 60 size_t transform_mem_size; // Currently allocated memory size. 61 62 int current_width; // Corresponds to packed image width. 63 64 // Encoding parameters derived from quality parameter. 65 int histo_bits; 66 int predictor_transform_bits; // <= MAX_TRANSFORM_BITS 67 int cross_color_transform_bits; // <= MAX_TRANSFORM_BITS 68 int cache_bits; // If equal to 0, don't use color cache. 69 70 // Encoding parameters derived from image characteristics. 71 int use_cross_color; 72 int use_subtract_green; 73 int use_predict; 74 int use_palette; 75 int palette_size; 76 uint32_t palette[MAX_PALETTE_SIZE]; 77 // Sorted version of palette for cache purposes. 78 uint32_t palette_sorted[MAX_PALETTE_SIZE]; 79 80 // Some 'scratch' (potentially large) objects. 81 struct VP8LBackwardRefs refs[4]; // Backward Refs array for temporaries. 82 VP8LHashChain hash_chain; // HashChain data for constructing 83 // backward references. 84 } VP8LEncoder; 85 86 //------------------------------------------------------------------------------ 87 // internal functions. Not public. 88 89 // Encodes the picture. 90 // Returns 0 if config or picture is NULL or picture doesn't have valid argb 91 // input. 92 int VP8LEncodeImage(const WebPConfig* const config, 93 const WebPPicture* const picture); 94 95 // Encodes the main image stream using the supplied bit writer. 96 // Returns false in case of error (stored in picture->error_code). 97 int VP8LEncodeStream(const WebPConfig* const config, 98 const WebPPicture* const picture, VP8LBitWriter* const bw); 99 100 #if (WEBP_NEAR_LOSSLESS == 1) 101 // in near_lossless.c 102 // Near lossless preprocessing in RGB color-space. 103 int VP8ApplyNearLossless(const WebPPicture* const picture, int quality, 104 uint32_t* const argb_dst); 105 #endif 106 107 //------------------------------------------------------------------------------ 108 // Image transforms in predictor.c. 109 110 // pic and percent are for progress. 111 // Returns false in case of error (stored in pic->error_code). 112 int VP8LResidualImage(int width, int height, int min_bits, int max_bits, 113 int low_effort, uint32_t* const argb, 114 uint32_t* const argb_scratch, uint32_t* const image, 115 int near_lossless, int exact, int used_subtract_green, 116 const WebPPicture* const pic, int percent_range, 117 int* const percent, int* const best_bits); 118 119 int VP8LColorSpaceTransform(int width, int height, int bits, int quality, 120 uint32_t* const argb, uint32_t* image, 121 const WebPPicture* const pic, int percent_range, 122 int* const percent, int* const best_bits); 123 124 void VP8LOptimizeSampling(uint32_t* const image, int full_width, 125 int full_height, int bits, int max_bits, 126 int* best_bits_out); 127 128 //------------------------------------------------------------------------------ 129 130 #ifdef __cplusplus 131 } // extern "C" 132 #endif 133 134 #endif // WEBP_ENC_VP8LI_ENC_H_