Path: blob/master/thirdparty/libwebp/src/dsp/lossless.h
21472 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/dsp/dsp.h"18#include "src/webp/types.h"19#include "src/webp/decode.h"2021#ifdef __cplusplus22extern "C" {23#endif2425//------------------------------------------------------------------------------26// Decoding2728typedef uint32_t (*VP8LPredictorFunc)(const uint32_t* const left,29const uint32_t* const top);30extern VP8LPredictorFunc VP8LPredictors[16];3132uint32_t VP8LPredictor2_C(const uint32_t* const left,33const uint32_t* const top);34uint32_t VP8LPredictor3_C(const uint32_t* const left,35const uint32_t* const top);36uint32_t VP8LPredictor4_C(const uint32_t* const left,37const uint32_t* const top);38uint32_t VP8LPredictor5_C(const uint32_t* const left,39const uint32_t* const top);40uint32_t VP8LPredictor6_C(const uint32_t* const left,41const uint32_t* const top);42uint32_t VP8LPredictor7_C(const uint32_t* const left,43const uint32_t* const top);44uint32_t VP8LPredictor8_C(const uint32_t* const left,45const uint32_t* const top);46uint32_t VP8LPredictor9_C(const uint32_t* const left,47const uint32_t* const top);48uint32_t VP8LPredictor10_C(const uint32_t* const left,49const uint32_t* const top);50uint32_t VP8LPredictor11_C(const uint32_t* const left,51const uint32_t* const top);52uint32_t VP8LPredictor12_C(const uint32_t* const left,53const uint32_t* const top);54uint32_t VP8LPredictor13_C(const uint32_t* const left,55const uint32_t* const top);5657// These Add/Sub function expects upper[-1] and out[-1] to be readable.58typedef void (*VP8LPredictorAddSubFunc)(const uint32_t* in,59const uint32_t* upper, int num_pixels,60uint32_t* WEBP_RESTRICT out);61extern VP8LPredictorAddSubFunc VP8LPredictorsAdd[16];62extern VP8LPredictorAddSubFunc VP8LPredictorsAdd_C[16];63extern VP8LPredictorAddSubFunc VP8LPredictorsAdd_SSE[16];6465typedef void (*VP8LProcessDecBlueAndRedFunc)(const uint32_t* src,66int num_pixels, uint32_t* dst);67extern VP8LProcessDecBlueAndRedFunc VP8LAddGreenToBlueAndRed;68extern VP8LProcessDecBlueAndRedFunc VP8LAddGreenToBlueAndRed_SSE;6970typedef struct {71// Note: the members are uint8_t, so that any negative values are72// automatically converted to "mod 256" values.73uint8_t green_to_red;74uint8_t green_to_blue;75uint8_t red_to_blue;76} VP8LMultipliers;77typedef void (*VP8LTransformColorInverseFunc)(const VP8LMultipliers* const m,78const uint32_t* src,79int num_pixels, uint32_t* dst);80extern VP8LTransformColorInverseFunc VP8LTransformColorInverse;81extern VP8LTransformColorInverseFunc VP8LTransformColorInverse_SSE;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;101extern VP8LConvertFunc VP8LConvertBGRAToRGB_SSE;102extern VP8LConvertFunc VP8LConvertBGRAToRGBA_SSE;103104// Converts from BGRA to other color spaces.105void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,106WEBP_CSP_MODE out_colorspace, uint8_t* const rgba);107108typedef void (*VP8LMapARGBFunc)(const uint32_t* src,109const uint32_t* const color_map,110uint32_t* dst, int y_start,111int y_end, int width);112typedef void (*VP8LMapAlphaFunc)(const uint8_t* src,113const uint32_t* const color_map,114uint8_t* dst, int y_start,115int y_end, int width);116117extern VP8LMapARGBFunc VP8LMapColor32b;118extern VP8LMapAlphaFunc VP8LMapColor8b;119120// Similar to the static method ColorIndexInverseTransform() that is part of121// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than122// uint32_t) arguments for 'src' and 'dst'.123void VP8LColorIndexInverseTransformAlpha(124const struct VP8LTransform* const transform, int y_start, int y_end,125const uint8_t* src, uint8_t* dst);126127// Expose some C-only fallback functions128void VP8LTransformColorInverse_C(const VP8LMultipliers* const m,129const uint32_t* src, int num_pixels,130uint32_t* dst);131132void VP8LConvertBGRAToRGB_C(const uint32_t* WEBP_RESTRICT src, int num_pixels,133uint8_t* WEBP_RESTRICT dst);134void VP8LConvertBGRAToRGBA_C(const uint32_t* WEBP_RESTRICT src, int num_pixels,135uint8_t* WEBP_RESTRICT dst);136void VP8LConvertBGRAToRGBA4444_C(const uint32_t* WEBP_RESTRICT src,137int num_pixels, uint8_t* WEBP_RESTRICT dst);138void VP8LConvertBGRAToRGB565_C(const uint32_t* WEBP_RESTRICT src,139int num_pixels, uint8_t* WEBP_RESTRICT dst);140void VP8LConvertBGRAToBGR_C(const uint32_t* WEBP_RESTRICT src, int num_pixels,141uint8_t* WEBP_RESTRICT dst);142void VP8LAddGreenToBlueAndRed_C(const uint32_t* src, int num_pixels,143uint32_t* dst);144145// Must be called before calling any of the above methods.146void VP8LDspInit(void);147148//------------------------------------------------------------------------------149// Encoding150151typedef void (*VP8LProcessEncBlueAndRedFunc)(uint32_t* dst, int num_pixels);152extern VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;153extern VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed_SSE;154typedef void (*VP8LTransformColorFunc)(155const VP8LMultipliers* WEBP_RESTRICT const m, uint32_t* WEBP_RESTRICT dst,156int num_pixels);157extern VP8LTransformColorFunc VP8LTransformColor;158extern VP8LTransformColorFunc VP8LTransformColor_SSE;159typedef void (*VP8LCollectColorBlueTransformsFunc)(160const uint32_t* WEBP_RESTRICT argb, int stride,161int tile_width, int tile_height,162int green_to_blue, int red_to_blue, uint32_t histo[]);163extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;164extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms_SSE;165166typedef void (*VP8LCollectColorRedTransformsFunc)(167const uint32_t* WEBP_RESTRICT argb, int stride,168int tile_width, int tile_height,169int green_to_red, uint32_t histo[]);170extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;171extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms_SSE;172173// Expose some C-only fallback functions174void VP8LTransformColor_C(const VP8LMultipliers* WEBP_RESTRICT const m,175uint32_t* WEBP_RESTRICT data, int num_pixels);176void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels);177void VP8LCollectColorRedTransforms_C(const uint32_t* WEBP_RESTRICT argb,178int stride,179int tile_width, int tile_height,180int green_to_red, uint32_t histo[]);181void VP8LCollectColorBlueTransforms_C(const uint32_t* WEBP_RESTRICT argb,182int stride,183int tile_width, int tile_height,184int green_to_blue, int red_to_blue,185uint32_t histo[]);186187extern VP8LPredictorAddSubFunc VP8LPredictorsSub[16];188extern VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16];189extern VP8LPredictorAddSubFunc VP8LPredictorsSub_SSE[16];190191// -----------------------------------------------------------------------------192// Huffman-cost related functions.193194typedef uint32_t (*VP8LCostFunc)(const uint32_t* population, int length);195typedef uint64_t (*VP8LCombinedShannonEntropyFunc)(const uint32_t X[256],196const uint32_t Y[256]);197typedef uint64_t (*VP8LShannonEntropyFunc)(const uint32_t* X, int length);198199extern VP8LCostFunc VP8LExtraCost;200extern VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;201extern VP8LShannonEntropyFunc VP8LShannonEntropy;202203typedef struct { // small struct to hold counters204int counts[2]; // index: 0=zero streak, 1=non-zero streak205int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3]206} VP8LStreaks;207208typedef struct { // small struct to hold bit entropy results209uint64_t entropy; // entropy210uint32_t sum; // sum of the population211int nonzeros; // number of non-zero elements in the population212uint32_t max_val; // maximum value in the population213uint32_t nonzero_code; // index of the last non-zero in the population214} VP8LBitEntropy;215216void VP8LBitEntropyInit(VP8LBitEntropy* const entropy);217218// Get the combined symbol bit entropy and Huffman cost stats for the219// distributions 'X' and 'Y'. Those results can then be refined according to220// codec specific heuristics.221typedef void (*VP8LGetCombinedEntropyUnrefinedFunc)(222const uint32_t X[], const uint32_t Y[], int length,223VP8LBitEntropy* WEBP_RESTRICT const bit_entropy,224VP8LStreaks* WEBP_RESTRICT const stats);225extern VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;226227// Get the entropy for the distribution 'X'.228typedef void (*VP8LGetEntropyUnrefinedFunc)(229const uint32_t X[], int length,230VP8LBitEntropy* WEBP_RESTRICT const bit_entropy,231VP8LStreaks* WEBP_RESTRICT const stats);232extern VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;233234void VP8LBitsEntropyUnrefined(const uint32_t* WEBP_RESTRICT const array, int n,235VP8LBitEntropy* WEBP_RESTRICT const entropy);236237typedef void (*VP8LAddVectorFunc)(const uint32_t* WEBP_RESTRICT a,238const uint32_t* WEBP_RESTRICT b,239uint32_t* WEBP_RESTRICT out, int size);240extern VP8LAddVectorFunc VP8LAddVector;241typedef void (*VP8LAddVectorEqFunc)(const uint32_t* WEBP_RESTRICT a,242uint32_t* WEBP_RESTRICT out, int size);243extern VP8LAddVectorEqFunc VP8LAddVectorEq;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;257extern VP8LBundleColorMapFunc VP8LBundleColorMap_SSE;258void VP8LBundleColorMap_C(const uint8_t* WEBP_RESTRICT const row,259int width, int xbits, uint32_t* WEBP_RESTRICT dst);260261// Must be called before calling any of the above methods.262void VP8LEncDspInit(void);263264//------------------------------------------------------------------------------265266#ifdef __cplusplus267} // extern "C"268#endif269270#endif // WEBP_DSP_LOSSLESS_H_271272273