Path: blob/master/3rdparty/libwebp/src/dsp/lossless.h
16348 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/enc/histogram_enc.h"21#include "src/utils/utils.h"2223#ifdef __cplusplus24extern "C" {25#endif2627//------------------------------------------------------------------------------28// Decoding2930typedef uint32_t (*VP8LPredictorFunc)(uint32_t left, const uint32_t* const top);31extern VP8LPredictorFunc VP8LPredictors[16];32extern VP8LPredictorFunc VP8LPredictors_C[16];33// These Add/Sub function expects upper[-1] and out[-1] to be readable.34typedef void (*VP8LPredictorAddSubFunc)(const uint32_t* in,35const uint32_t* upper, int num_pixels,36uint32_t* out);37extern VP8LPredictorAddSubFunc VP8LPredictorsAdd[16];38extern VP8LPredictorAddSubFunc VP8LPredictorsAdd_C[16];3940typedef void (*VP8LProcessDecBlueAndRedFunc)(const uint32_t* src,41int num_pixels, uint32_t* dst);42extern VP8LProcessDecBlueAndRedFunc VP8LAddGreenToBlueAndRed;4344typedef struct {45// Note: the members are uint8_t, so that any negative values are46// automatically converted to "mod 256" values.47uint8_t green_to_red_;48uint8_t green_to_blue_;49uint8_t red_to_blue_;50} VP8LMultipliers;51typedef void (*VP8LTransformColorInverseFunc)(const VP8LMultipliers* const m,52const uint32_t* src,53int num_pixels, uint32_t* dst);54extern VP8LTransformColorInverseFunc VP8LTransformColorInverse;5556struct VP8LTransform; // Defined in dec/vp8li.h.5758// Performs inverse transform of data given transform information, start and end59// rows. Transform will be applied to rows [row_start, row_end[.60// The *in and *out pointers refer to source and destination data respectively61// corresponding to the intermediate row (row_start).62void VP8LInverseTransform(const struct VP8LTransform* const transform,63int row_start, int row_end,64const uint32_t* const in, uint32_t* const out);6566// Color space conversion.67typedef void (*VP8LConvertFunc)(const uint32_t* src, int num_pixels,68uint8_t* dst);69extern VP8LConvertFunc VP8LConvertBGRAToRGB;70extern VP8LConvertFunc VP8LConvertBGRAToRGBA;71extern VP8LConvertFunc VP8LConvertBGRAToRGBA4444;72extern VP8LConvertFunc VP8LConvertBGRAToRGB565;73extern VP8LConvertFunc VP8LConvertBGRAToBGR;7475// Converts from BGRA to other color spaces.76void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,77WEBP_CSP_MODE out_colorspace, uint8_t* const rgba);7879typedef void (*VP8LMapARGBFunc)(const uint32_t* src,80const uint32_t* const color_map,81uint32_t* dst, int y_start,82int y_end, int width);83typedef void (*VP8LMapAlphaFunc)(const uint8_t* src,84const uint32_t* const color_map,85uint8_t* dst, int y_start,86int y_end, int width);8788extern VP8LMapARGBFunc VP8LMapColor32b;89extern VP8LMapAlphaFunc VP8LMapColor8b;9091// Similar to the static method ColorIndexInverseTransform() that is part of92// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than93// uint32_t) arguments for 'src' and 'dst'.94void VP8LColorIndexInverseTransformAlpha(95const struct VP8LTransform* const transform, int y_start, int y_end,96const uint8_t* src, uint8_t* dst);9798// Expose some C-only fallback functions99void VP8LTransformColorInverse_C(const VP8LMultipliers* const m,100const uint32_t* src, int num_pixels,101uint32_t* dst);102103void VP8LConvertBGRAToRGB_C(const uint32_t* src, int num_pixels, uint8_t* dst);104void VP8LConvertBGRAToRGBA_C(const uint32_t* src, int num_pixels, uint8_t* dst);105void VP8LConvertBGRAToRGBA4444_C(const uint32_t* src,106int num_pixels, uint8_t* dst);107void VP8LConvertBGRAToRGB565_C(const uint32_t* src,108int num_pixels, uint8_t* dst);109void VP8LConvertBGRAToBGR_C(const uint32_t* src, int num_pixels, uint8_t* dst);110void VP8LAddGreenToBlueAndRed_C(const uint32_t* src, int num_pixels,111uint32_t* dst);112113// Must be called before calling any of the above methods.114void VP8LDspInit(void);115116//------------------------------------------------------------------------------117// Encoding118119typedef void (*VP8LProcessEncBlueAndRedFunc)(uint32_t* dst, int num_pixels);120extern VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;121typedef void (*VP8LTransformColorFunc)(const VP8LMultipliers* const m,122uint32_t* dst, int num_pixels);123extern VP8LTransformColorFunc VP8LTransformColor;124typedef void (*VP8LCollectColorBlueTransformsFunc)(125const uint32_t* argb, int stride,126int tile_width, int tile_height,127int green_to_blue, int red_to_blue, int histo[]);128extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;129130typedef void (*VP8LCollectColorRedTransformsFunc)(131const uint32_t* argb, int stride,132int tile_width, int tile_height,133int green_to_red, int histo[]);134extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;135136// Expose some C-only fallback functions137void VP8LTransformColor_C(const VP8LMultipliers* const m,138uint32_t* data, int num_pixels);139void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels);140void VP8LCollectColorRedTransforms_C(const uint32_t* argb, int stride,141int tile_width, int tile_height,142int green_to_red, int histo[]);143void VP8LCollectColorBlueTransforms_C(const uint32_t* argb, int stride,144int tile_width, int tile_height,145int green_to_blue, int red_to_blue,146int histo[]);147148extern VP8LPredictorAddSubFunc VP8LPredictorsSub[16];149extern VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16];150151// -----------------------------------------------------------------------------152// Huffman-cost related functions.153154typedef double (*VP8LCostFunc)(const uint32_t* population, int length);155typedef double (*VP8LCostCombinedFunc)(const uint32_t* X, const uint32_t* Y,156int length);157typedef float (*VP8LCombinedShannonEntropyFunc)(const int X[256],158const int Y[256]);159160extern VP8LCostFunc VP8LExtraCost;161extern VP8LCostCombinedFunc VP8LExtraCostCombined;162extern VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;163164typedef struct { // small struct to hold counters165int counts[2]; // index: 0=zero steak, 1=non-zero streak166int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3]167} VP8LStreaks;168169typedef struct { // small struct to hold bit entropy results170double entropy; // entropy171uint32_t sum; // sum of the population172int nonzeros; // number of non-zero elements in the population173uint32_t max_val; // maximum value in the population174uint32_t nonzero_code; // index of the last non-zero in the population175} VP8LBitEntropy;176177void VP8LBitEntropyInit(VP8LBitEntropy* const entropy);178179// Get the combined symbol bit entropy and Huffman cost stats for the180// distributions 'X' and 'Y'. Those results can then be refined according to181// codec specific heuristics.182typedef void (*VP8LGetCombinedEntropyUnrefinedFunc)(183const uint32_t X[], const uint32_t Y[], int length,184VP8LBitEntropy* const bit_entropy, VP8LStreaks* const stats);185extern VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;186187// Get the entropy for the distribution 'X'.188typedef void (*VP8LGetEntropyUnrefinedFunc)(const uint32_t X[], int length,189VP8LBitEntropy* const bit_entropy,190VP8LStreaks* const stats);191extern VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;192193void VP8LBitsEntropyUnrefined(const uint32_t* const array, int n,194VP8LBitEntropy* const entropy);195196typedef void (*VP8LHistogramAddFunc)(const VP8LHistogram* const a,197const VP8LHistogram* const b,198VP8LHistogram* const out);199extern VP8LHistogramAddFunc VP8LHistogramAdd;200201// -----------------------------------------------------------------------------202// PrefixEncode()203204typedef int (*VP8LVectorMismatchFunc)(const uint32_t* const array1,205const uint32_t* const array2, int length);206// Returns the first index where array1 and array2 are different.207extern VP8LVectorMismatchFunc VP8LVectorMismatch;208209typedef void (*VP8LBundleColorMapFunc)(const uint8_t* const row, int width,210int xbits, uint32_t* dst);211extern VP8LBundleColorMapFunc VP8LBundleColorMap;212void VP8LBundleColorMap_C(const uint8_t* const row, int width, int xbits,213uint32_t* dst);214215// Must be called before calling any of the above methods.216void VP8LEncDspInit(void);217218//------------------------------------------------------------------------------219220#ifdef __cplusplus221} // extern "C"222#endif223224#endif // WEBP_DSP_LOSSLESS_H_225226227