Path: blob/master/thirdparty/libwebp/src/dsp/lossless.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// Image transforms and color space conversion methods for lossless decoder.10//11// Authors: Vikas Arora ([email protected])12// Jyrki Alakuijala ([email protected])1314#ifndef WEBP_DSP_LOSSLESS_H_15#define WEBP_DSP_LOSSLESS_H_1617#include "src/webp/types.h"18#include "src/webp/decode.h"1920#include "src/dsp/dsp.h"21#include "src/enc/histogram_enc.h"22#include "src/utils/utils.h"2324#ifdef __cplusplus25extern "C" {26#endif2728//------------------------------------------------------------------------------29// Decoding3031typedef uint32_t (*VP8LPredictorFunc)(const uint32_t* const left,32const uint32_t* const top);33extern VP8LPredictorFunc VP8LPredictors[16];3435uint32_t VP8LPredictor2_C(const uint32_t* const left,36const uint32_t* const top);37uint32_t VP8LPredictor3_C(const uint32_t* const left,38const uint32_t* const top);39uint32_t VP8LPredictor4_C(const uint32_t* const left,40const uint32_t* const top);41uint32_t VP8LPredictor5_C(const uint32_t* const left,42const uint32_t* const top);43uint32_t VP8LPredictor6_C(const uint32_t* const left,44const uint32_t* const top);45uint32_t VP8LPredictor7_C(const uint32_t* const left,46const uint32_t* const top);47uint32_t VP8LPredictor8_C(const uint32_t* const left,48const uint32_t* const top);49uint32_t VP8LPredictor9_C(const uint32_t* const left,50const uint32_t* const top);51uint32_t VP8LPredictor10_C(const uint32_t* const left,52const uint32_t* const top);53uint32_t VP8LPredictor11_C(const uint32_t* const left,54const uint32_t* const top);55uint32_t VP8LPredictor12_C(const uint32_t* const left,56const uint32_t* const top);57uint32_t VP8LPredictor13_C(const uint32_t* const left,58const uint32_t* const top);5960// These Add/Sub function expects upper[-1] and out[-1] to be readable.61typedef void (*VP8LPredictorAddSubFunc)(const uint32_t* in,62const uint32_t* upper, int num_pixels,63uint32_t* WEBP_RESTRICT out);64extern VP8LPredictorAddSubFunc VP8LPredictorsAdd[16];65extern VP8LPredictorAddSubFunc VP8LPredictorsAdd_C[16];6667typedef void (*VP8LProcessDecBlueAndRedFunc)(const uint32_t* src,68int num_pixels, uint32_t* dst);69extern VP8LProcessDecBlueAndRedFunc VP8LAddGreenToBlueAndRed;7071typedef struct {72// Note: the members are uint8_t, so that any negative values are73// automatically converted to "mod 256" values.74uint8_t green_to_red_;75uint8_t green_to_blue_;76uint8_t red_to_blue_;77} VP8LMultipliers;78typedef void (*VP8LTransformColorInverseFunc)(const VP8LMultipliers* const m,79const uint32_t* src,80int num_pixels, uint32_t* dst);81extern VP8LTransformColorInverseFunc VP8LTransformColorInverse;8283struct VP8LTransform; // Defined in dec/vp8li.h.8485// Performs inverse transform of data given transform information, start and end86// rows. Transform will be applied to rows [row_start, row_end[.87// The *in and *out pointers refer to source and destination data respectively88// corresponding to the intermediate row (row_start).89void VP8LInverseTransform(const struct VP8LTransform* const transform,90int row_start, int row_end,91const uint32_t* const in, uint32_t* const out);9293// Color space conversion.94typedef void (*VP8LConvertFunc)(const uint32_t* WEBP_RESTRICT src,95int num_pixels, uint8_t* WEBP_RESTRICT dst);96extern VP8LConvertFunc VP8LConvertBGRAToRGB;97extern VP8LConvertFunc VP8LConvertBGRAToRGBA;98extern VP8LConvertFunc VP8LConvertBGRAToRGBA4444;99extern VP8LConvertFunc VP8LConvertBGRAToRGB565;100extern VP8LConvertFunc VP8LConvertBGRAToBGR;101102// Converts from BGRA to other color spaces.103void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,104WEBP_CSP_MODE out_colorspace, uint8_t* const rgba);105106typedef void (*VP8LMapARGBFunc)(const uint32_t* src,107const uint32_t* const color_map,108uint32_t* dst, int y_start,109int y_end, int width);110typedef void (*VP8LMapAlphaFunc)(const uint8_t* src,111const uint32_t* const color_map,112uint8_t* dst, int y_start,113int y_end, int width);114115extern VP8LMapARGBFunc VP8LMapColor32b;116extern VP8LMapAlphaFunc VP8LMapColor8b;117118// Similar to the static method ColorIndexInverseTransform() that is part of119// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than120// uint32_t) arguments for 'src' and 'dst'.121void VP8LColorIndexInverseTransformAlpha(122const struct VP8LTransform* const transform, int y_start, int y_end,123const uint8_t* src, uint8_t* dst);124125// Expose some C-only fallback functions126void VP8LTransformColorInverse_C(const VP8LMultipliers* const m,127const uint32_t* src, int num_pixels,128uint32_t* dst);129130void VP8LConvertBGRAToRGB_C(const uint32_t* WEBP_RESTRICT src, int num_pixels,131uint8_t* WEBP_RESTRICT dst);132void VP8LConvertBGRAToRGBA_C(const uint32_t* WEBP_RESTRICT src, int num_pixels,133uint8_t* WEBP_RESTRICT dst);134void VP8LConvertBGRAToRGBA4444_C(const uint32_t* WEBP_RESTRICT src,135int num_pixels, uint8_t* WEBP_RESTRICT dst);136void VP8LConvertBGRAToRGB565_C(const uint32_t* WEBP_RESTRICT src,137int num_pixels, uint8_t* WEBP_RESTRICT dst);138void VP8LConvertBGRAToBGR_C(const uint32_t* WEBP_RESTRICT src, int num_pixels,139uint8_t* WEBP_RESTRICT dst);140void VP8LAddGreenToBlueAndRed_C(const uint32_t* src, int num_pixels,141uint32_t* dst);142143// Must be called before calling any of the above methods.144void VP8LDspInit(void);145146//------------------------------------------------------------------------------147// Encoding148149typedef void (*VP8LProcessEncBlueAndRedFunc)(uint32_t* dst, int num_pixels);150extern VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;151typedef void (*VP8LTransformColorFunc)(152const VP8LMultipliers* WEBP_RESTRICT const m, uint32_t* WEBP_RESTRICT dst,153int num_pixels);154extern VP8LTransformColorFunc VP8LTransformColor;155typedef void (*VP8LCollectColorBlueTransformsFunc)(156const uint32_t* WEBP_RESTRICT argb, int stride,157int tile_width, int tile_height,158int green_to_blue, int red_to_blue, uint32_t histo[]);159extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;160161typedef void (*VP8LCollectColorRedTransformsFunc)(162const uint32_t* WEBP_RESTRICT argb, int stride,163int tile_width, int tile_height,164int green_to_red, uint32_t histo[]);165extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;166167// Expose some C-only fallback functions168void VP8LTransformColor_C(const VP8LMultipliers* WEBP_RESTRICT const m,169uint32_t* WEBP_RESTRICT data, int num_pixels);170void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels);171void VP8LCollectColorRedTransforms_C(const uint32_t* WEBP_RESTRICT argb,172int stride,173int tile_width, int tile_height,174int green_to_red, uint32_t histo[]);175void VP8LCollectColorBlueTransforms_C(const uint32_t* WEBP_RESTRICT argb,176int stride,177int tile_width, int tile_height,178int green_to_blue, int red_to_blue,179uint32_t histo[]);180181extern VP8LPredictorAddSubFunc VP8LPredictorsSub[16];182extern VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16];183184// -----------------------------------------------------------------------------185// Huffman-cost related functions.186187typedef uint32_t (*VP8LCostFunc)(const uint32_t* population, int length);188typedef uint32_t (*VP8LCostCombinedFunc)(const uint32_t* WEBP_RESTRICT X,189const uint32_t* WEBP_RESTRICT Y,190int length);191typedef uint64_t (*VP8LCombinedShannonEntropyFunc)(const uint32_t X[256],192const uint32_t Y[256]);193typedef uint64_t (*VP8LShannonEntropyFunc)(const uint32_t* X, int length);194195extern VP8LCostFunc VP8LExtraCost;196extern VP8LCostCombinedFunc VP8LExtraCostCombined;197extern VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;198extern VP8LShannonEntropyFunc VP8LShannonEntropy;199200typedef struct { // small struct to hold counters201int counts[2]; // index: 0=zero streak, 1=non-zero streak202int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3]203} VP8LStreaks;204205typedef struct { // small struct to hold bit entropy results206uint64_t entropy; // entropy207uint32_t sum; // sum of the population208int nonzeros; // number of non-zero elements in the population209uint32_t max_val; // maximum value in the population210uint32_t nonzero_code; // index of the last non-zero in the population211} VP8LBitEntropy;212213void VP8LBitEntropyInit(VP8LBitEntropy* const entropy);214215// Get the combined symbol bit entropy and Huffman cost stats for the216// distributions 'X' and 'Y'. Those results can then be refined according to217// codec specific heuristics.218typedef void (*VP8LGetCombinedEntropyUnrefinedFunc)(219const uint32_t X[], const uint32_t Y[], int length,220VP8LBitEntropy* WEBP_RESTRICT const bit_entropy,221VP8LStreaks* WEBP_RESTRICT const stats);222extern VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;223224// Get the entropy for the distribution 'X'.225typedef void (*VP8LGetEntropyUnrefinedFunc)(226const uint32_t X[], int length,227VP8LBitEntropy* WEBP_RESTRICT const bit_entropy,228VP8LStreaks* WEBP_RESTRICT const stats);229extern VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;230231void VP8LBitsEntropyUnrefined(const uint32_t* WEBP_RESTRICT const array, int n,232VP8LBitEntropy* WEBP_RESTRICT const entropy);233234typedef void (*VP8LAddVectorFunc)(const uint32_t* WEBP_RESTRICT a,235const uint32_t* WEBP_RESTRICT b,236uint32_t* WEBP_RESTRICT out, int size);237extern VP8LAddVectorFunc VP8LAddVector;238typedef void (*VP8LAddVectorEqFunc)(const uint32_t* WEBP_RESTRICT a,239uint32_t* WEBP_RESTRICT out, int size);240extern VP8LAddVectorEqFunc VP8LAddVectorEq;241void VP8LHistogramAdd(const VP8LHistogram* WEBP_RESTRICT const a,242const VP8LHistogram* WEBP_RESTRICT const b,243VP8LHistogram* WEBP_RESTRICT const out);244245// -----------------------------------------------------------------------------246// PrefixEncode()247248typedef int (*VP8LVectorMismatchFunc)(const uint32_t* const array1,249const uint32_t* const array2, int length);250// Returns the first index where array1 and array2 are different.251extern VP8LVectorMismatchFunc VP8LVectorMismatch;252253typedef void (*VP8LBundleColorMapFunc)(const uint8_t* WEBP_RESTRICT const row,254int width, int xbits,255uint32_t* WEBP_RESTRICT dst);256extern VP8LBundleColorMapFunc VP8LBundleColorMap;257void VP8LBundleColorMap_C(const uint8_t* WEBP_RESTRICT const row,258int width, int xbits, uint32_t* WEBP_RESTRICT dst);259260// Must be called before calling any of the above methods.261void VP8LEncDspInit(void);262263//------------------------------------------------------------------------------264265#ifdef __cplusplus266} // extern "C"267#endif268269#endif // WEBP_DSP_LOSSLESS_H_270271272