Path: blob/master/thirdparty/libwebp/src/enc/vp8li_enc.h
9913 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 encoder: internal header.10//11// Author: Vikas Arora ([email protected])1213#ifndef WEBP_ENC_VP8LI_ENC_H_14#define WEBP_ENC_VP8LI_ENC_H_1516#ifdef HAVE_CONFIG_H17#include "src/webp/config.h"18#endif19// Either WEBP_NEAR_LOSSLESS is defined as 0 in config.h when compiling to20// disable near-lossless, or it is enabled by default.21#ifndef WEBP_NEAR_LOSSLESS22#define WEBP_NEAR_LOSSLESS 123#endif2425#include "src/enc/backward_references_enc.h"26#include "src/enc/histogram_enc.h"27#include "src/utils/bit_writer_utils.h"28#include "src/webp/encode.h"29#include "src/webp/format_constants.h"3031#ifdef __cplusplus32extern "C" {33#endif3435// maximum value of transform_bits_ in VP8LEncoder.36#define MAX_TRANSFORM_BITS (MIN_TRANSFORM_BITS + (1 << NUM_TRANSFORM_BITS) - 1)3738typedef enum {39kEncoderNone = 0,40kEncoderARGB,41kEncoderNearLossless,42kEncoderPalette43} VP8LEncoderARGBContent;4445typedef struct {46const WebPConfig* config_; // user configuration and parameters47const WebPPicture* pic_; // input picture.4849uint32_t* argb_; // Transformed argb image data.50VP8LEncoderARGBContent argb_content_; // Content type of the argb buffer.51uint32_t* argb_scratch_; // Scratch memory for argb rows52// (used for prediction).53uint32_t* transform_data_; // Scratch memory for transform data.54uint32_t* transform_mem_; // Currently allocated memory.55size_t transform_mem_size_; // Currently allocated memory size.5657int current_width_; // Corresponds to packed image width.5859// Encoding parameters derived from quality parameter.60int histo_bits_;61int predictor_transform_bits_; // <= MAX_TRANSFORM_BITS62int cross_color_transform_bits_; // <= MAX_TRANSFORM_BITS63int cache_bits_; // If equal to 0, don't use color cache.6465// Encoding parameters derived from image characteristics.66int use_cross_color_;67int use_subtract_green_;68int use_predict_;69int use_palette_;70int palette_size_;71uint32_t palette_[MAX_PALETTE_SIZE];72// Sorted version of palette_ for cache purposes.73uint32_t palette_sorted_[MAX_PALETTE_SIZE];7475// Some 'scratch' (potentially large) objects.76struct VP8LBackwardRefs refs_[4]; // Backward Refs array for temporaries.77VP8LHashChain hash_chain_; // HashChain data for constructing78// backward references.79} VP8LEncoder;8081//------------------------------------------------------------------------------82// internal functions. Not public.8384// Encodes the picture.85// Returns 0 if config or picture is NULL or picture doesn't have valid argb86// input.87int VP8LEncodeImage(const WebPConfig* const config,88const WebPPicture* const picture);8990// Encodes the main image stream using the supplied bit writer.91// Returns false in case of error (stored in picture->error_code).92int VP8LEncodeStream(const WebPConfig* const config,93const WebPPicture* const picture, VP8LBitWriter* const bw);9495#if (WEBP_NEAR_LOSSLESS == 1)96// in near_lossless.c97// Near lossless preprocessing in RGB color-space.98int VP8ApplyNearLossless(const WebPPicture* const picture, int quality,99uint32_t* const argb_dst);100#endif101102//------------------------------------------------------------------------------103// Image transforms in predictor.c.104105// pic and percent are for progress.106// Returns false in case of error (stored in pic->error_code).107int VP8LResidualImage(int width, int height, int min_bits, int max_bits,108int low_effort, uint32_t* const argb,109uint32_t* const argb_scratch, uint32_t* const image,110int near_lossless, int exact, int used_subtract_green,111const WebPPicture* const pic, int percent_range,112int* const percent, int* const best_bits);113114int VP8LColorSpaceTransform(int width, int height, int bits, int quality,115uint32_t* const argb, uint32_t* image,116const WebPPicture* const pic, int percent_range,117int* const percent, int* const best_bits);118119void VP8LOptimizeSampling(uint32_t* const image, int full_width,120int full_height, int bits, int max_bits,121int* best_bits_out);122123//------------------------------------------------------------------------------124125#ifdef __cplusplus126} // extern "C"127#endif128129#endif // WEBP_ENC_VP8LI_ENC_H_130131132