2012-03-28 13:07:42 +02:00
|
|
|
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
//
|
2013-06-07 08:05:58 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license
|
|
|
|
// that can be found in the COPYING file in the root of the source
|
|
|
|
// tree. An additional intellectual property rights grant can be found
|
|
|
|
// in the file PATENTS. All contributing project authors may
|
|
|
|
// be found in the AUTHORS file in the root of the source tree.
|
2012-03-28 13:07:42 +02:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Lossless encoder: internal header.
|
|
|
|
//
|
2012-04-26 09:19:24 +02:00
|
|
|
// Author: Vikas Arora (vikaas.arora@gmail.com)
|
2012-03-28 13:07:42 +02:00
|
|
|
|
2017-10-21 04:26:52 +02:00
|
|
|
#ifndef WEBP_ENC_VP8LI_ENC_H_
|
|
|
|
#define WEBP_ENC_VP8LI_ENC_H_
|
2012-03-28 13:07:42 +02:00
|
|
|
|
2017-08-31 14:02:05 +02:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2017-10-07 23:15:11 +02:00
|
|
|
#include "src/webp/config.h"
|
2017-08-31 14:02:05 +02:00
|
|
|
#endif
|
|
|
|
// Either WEBP_NEAR_LOSSLESS is defined as 0 in config.h when compiling to
|
|
|
|
// disable near-lossless, or it is enabled by default.
|
|
|
|
#ifndef WEBP_NEAR_LOSSLESS
|
|
|
|
#define WEBP_NEAR_LOSSLESS 1
|
|
|
|
#endif
|
|
|
|
|
2017-10-07 23:15:11 +02:00
|
|
|
#include "src/enc/backward_references_enc.h"
|
|
|
|
#include "src/enc/histogram_enc.h"
|
|
|
|
#include "src/utils/bit_writer_utils.h"
|
|
|
|
#include "src/webp/encode.h"
|
|
|
|
#include "src/webp/format_constants.h"
|
2012-03-28 13:07:42 +02:00
|
|
|
|
2013-11-25 23:43:12 +01:00
|
|
|
#ifdef __cplusplus
|
2012-03-28 13:07:42 +02:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-11-28 17:12:05 +01:00
|
|
|
// maximum value of transform_bits_ in VP8LEncoder.
|
|
|
|
#define MAX_TRANSFORM_BITS 6
|
|
|
|
|
2017-04-20 16:56:36 +02:00
|
|
|
typedef enum {
|
|
|
|
kEncoderNone = 0,
|
|
|
|
kEncoderARGB,
|
|
|
|
kEncoderNearLossless,
|
|
|
|
kEncoderPalette
|
|
|
|
} VP8LEncoderARGBContent;
|
|
|
|
|
2012-03-28 13:07:42 +02:00
|
|
|
typedef struct {
|
2016-02-20 04:22:34 +01:00
|
|
|
const WebPConfig* config_; // user configuration and parameters
|
|
|
|
const WebPPicture* pic_; // input picture.
|
2012-04-10 09:00:36 +02:00
|
|
|
|
2017-04-20 16:56:36 +02:00
|
|
|
uint32_t* argb_; // Transformed argb image data.
|
|
|
|
VP8LEncoderARGBContent argb_content_; // Content type of the argb buffer.
|
|
|
|
uint32_t* argb_scratch_; // Scratch memory for argb rows
|
|
|
|
// (used for prediction).
|
|
|
|
uint32_t* transform_data_; // Scratch memory for transform data.
|
|
|
|
uint32_t* transform_mem_; // Currently allocated memory.
|
|
|
|
size_t transform_mem_size_; // Currently allocated memory size.
|
2016-02-17 05:45:38 +01:00
|
|
|
|
2016-02-20 04:22:34 +01:00
|
|
|
int current_width_; // Corresponds to packed image width.
|
2012-03-28 13:07:42 +02:00
|
|
|
|
|
|
|
// Encoding parameters derived from quality parameter.
|
|
|
|
int histo_bits_;
|
2016-11-28 17:12:05 +01:00
|
|
|
int transform_bits_; // <= MAX_TRANSFORM_BITS.
|
2012-04-26 09:19:24 +02:00
|
|
|
int cache_bits_; // If equal to 0, don't use color cache.
|
2012-03-28 13:07:42 +02:00
|
|
|
|
|
|
|
// Encoding parameters derived from image characteristics.
|
|
|
|
int use_cross_color_;
|
2012-07-25 01:15:36 +02:00
|
|
|
int use_subtract_green_;
|
2012-04-10 09:00:36 +02:00
|
|
|
int use_predict_;
|
|
|
|
int use_palette_;
|
|
|
|
int palette_size_;
|
|
|
|
uint32_t palette_[MAX_PALETTE_SIZE];
|
2014-04-30 23:10:48 +02:00
|
|
|
|
|
|
|
// Some 'scratch' (potentially large) objects.
|
2020-06-09 18:53:56 +02:00
|
|
|
struct VP8LBackwardRefs refs_[4]; // Backward Refs array for temporaries.
|
2014-05-05 20:11:55 +02:00
|
|
|
VP8LHashChain hash_chain_; // HashChain data for constructing
|
|
|
|
// backward references.
|
2012-03-28 13:07:42 +02:00
|
|
|
} VP8LEncoder;
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// internal functions. Not public.
|
|
|
|
|
|
|
|
// Encodes the picture.
|
|
|
|
// Returns 0 if config or picture is NULL or picture doesn't have valid argb
|
|
|
|
// input.
|
|
|
|
int VP8LEncodeImage(const WebPConfig* const config,
|
2012-05-22 12:15:58 +02:00
|
|
|
const WebPPicture* const picture);
|
|
|
|
|
|
|
|
// Encodes the main image stream using the supplied bit writer.
|
2016-03-18 11:01:54 +01:00
|
|
|
// If 'use_cache' is false, disables the use of color cache.
|
2012-05-22 12:15:58 +02:00
|
|
|
WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
|
|
|
|
const WebPPicture* const picture,
|
2016-03-18 11:01:54 +01:00
|
|
|
VP8LBitWriter* const bw, int use_cache);
|
2012-03-28 13:07:42 +02:00
|
|
|
|
2017-08-31 14:02:05 +02:00
|
|
|
#if (WEBP_NEAR_LOSSLESS == 1)
|
2017-08-29 14:09:35 +02:00
|
|
|
// in near_lossless.c
|
|
|
|
// Near lossless preprocessing in RGB color-space.
|
|
|
|
int VP8ApplyNearLossless(const WebPPicture* const picture, int quality,
|
|
|
|
uint32_t* const argb_dst);
|
2017-08-31 14:02:05 +02:00
|
|
|
#endif
|
2017-08-29 14:09:35 +02:00
|
|
|
|
2016-09-13 14:48:50 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Image transforms in predictor.c.
|
|
|
|
|
|
|
|
void VP8LResidualImage(int width, int height, int bits, int low_effort,
|
|
|
|
uint32_t* const argb, uint32_t* const argb_scratch,
|
|
|
|
uint32_t* const image, int near_lossless, int exact,
|
|
|
|
int used_subtract_green);
|
|
|
|
|
|
|
|
void VP8LColorSpaceTransform(int width, int height, int bits, int quality,
|
|
|
|
uint32_t* const argb, uint32_t* image);
|
|
|
|
|
2012-03-28 13:07:42 +02:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-11-25 23:43:12 +01:00
|
|
|
#ifdef __cplusplus
|
2012-03-28 13:07:42 +02:00
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2018-08-22 23:46:53 +02:00
|
|
|
#endif // WEBP_ENC_VP8LI_ENC_H_
|