Blame src/dsp/lossless.h

Packit 9c6abc
// Copyright 2012 Google Inc. All Rights Reserved.
Packit 9c6abc
//
Packit 9c6abc
// Use of this source code is governed by a BSD-style license
Packit 9c6abc
// that can be found in the COPYING file in the root of the source
Packit 9c6abc
// tree. An additional intellectual property rights grant can be found
Packit 9c6abc
// in the file PATENTS. All contributing project authors may
Packit 9c6abc
// be found in the AUTHORS file in the root of the source tree.
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
//
Packit 9c6abc
// Image transforms and color space conversion methods for lossless decoder.
Packit 9c6abc
//
Packit 9c6abc
// Authors: Vikas Arora (vikaas.arora@gmail.com)
Packit 9c6abc
//          Jyrki Alakuijala (jyrki@google.com)
Packit 9c6abc
Packit 9c6abc
#ifndef WEBP_DSP_LOSSLESS_H_
Packit 9c6abc
#define WEBP_DSP_LOSSLESS_H_
Packit 9c6abc
Packit 9c6abc
#include "src/webp/types.h"
Packit 9c6abc
#include "src/webp/decode.h"
Packit 9c6abc
Packit 9c6abc
#include "src/enc/histogram_enc.h"
Packit 9c6abc
#include "src/utils/utils.h"
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
extern "C" {
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Decoding
Packit 9c6abc
Packit 9c6abc
typedef uint32_t (*VP8LPredictorFunc)(uint32_t left, const uint32_t* const top);
Packit 9c6abc
extern VP8LPredictorFunc VP8LPredictors[16];
Packit 9c6abc
extern VP8LPredictorFunc VP8LPredictors_C[16];
Packit 9c6abc
// These Add/Sub function expects upper[-1] and out[-1] to be readable.
Packit 9c6abc
typedef void (*VP8LPredictorAddSubFunc)(const uint32_t* in,
Packit 9c6abc
                                        const uint32_t* upper, int num_pixels,
Packit 9c6abc
                                        uint32_t* out);
Packit 9c6abc
extern VP8LPredictorAddSubFunc VP8LPredictorsAdd[16];
Packit 9c6abc
extern VP8LPredictorAddSubFunc VP8LPredictorsAdd_C[16];
Packit 9c6abc
Packit 9c6abc
typedef void (*VP8LProcessDecBlueAndRedFunc)(const uint32_t* src,
Packit 9c6abc
                                             int num_pixels, uint32_t* dst);
Packit 9c6abc
extern VP8LProcessDecBlueAndRedFunc VP8LAddGreenToBlueAndRed;
Packit 9c6abc
Packit 9c6abc
typedef struct {
Packit 9c6abc
  // Note: the members are uint8_t, so that any negative values are
Packit 9c6abc
  // automatically converted to "mod 256" values.
Packit 9c6abc
  uint8_t green_to_red_;
Packit 9c6abc
  uint8_t green_to_blue_;
Packit 9c6abc
  uint8_t red_to_blue_;
Packit 9c6abc
} VP8LMultipliers;
Packit 9c6abc
typedef void (*VP8LTransformColorInverseFunc)(const VP8LMultipliers* const m,
Packit 9c6abc
                                              const uint32_t* src,
Packit 9c6abc
                                              int num_pixels, uint32_t* dst);
Packit 9c6abc
extern VP8LTransformColorInverseFunc VP8LTransformColorInverse;
Packit 9c6abc
Packit 9c6abc
struct VP8LTransform;  // Defined in dec/vp8li.h.
Packit 9c6abc
Packit 9c6abc
// Performs inverse transform of data given transform information, start and end
Packit 9c6abc
// rows. Transform will be applied to rows [row_start, row_end[.
Packit 9c6abc
// The *in and *out pointers refer to source and destination data respectively
Packit 9c6abc
// corresponding to the intermediate row (row_start).
Packit 9c6abc
void VP8LInverseTransform(const struct VP8LTransform* const transform,
Packit 9c6abc
                          int row_start, int row_end,
Packit 9c6abc
                          const uint32_t* const in, uint32_t* const out);
Packit 9c6abc
Packit 9c6abc
// Color space conversion.
Packit 9c6abc
typedef void (*VP8LConvertFunc)(const uint32_t* src, int num_pixels,
Packit 9c6abc
                                uint8_t* dst);
Packit 9c6abc
extern VP8LConvertFunc VP8LConvertBGRAToRGB;
Packit 9c6abc
extern VP8LConvertFunc VP8LConvertBGRAToRGBA;
Packit 9c6abc
extern VP8LConvertFunc VP8LConvertBGRAToRGBA4444;
Packit 9c6abc
extern VP8LConvertFunc VP8LConvertBGRAToRGB565;
Packit 9c6abc
extern VP8LConvertFunc VP8LConvertBGRAToBGR;
Packit 9c6abc
Packit 9c6abc
// Converts from BGRA to other color spaces.
Packit 9c6abc
void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,
Packit 9c6abc
                         WEBP_CSP_MODE out_colorspace, uint8_t* const rgba);
Packit 9c6abc
Packit 9c6abc
typedef void (*VP8LMapARGBFunc)(const uint32_t* src,
Packit 9c6abc
                                const uint32_t* const color_map,
Packit 9c6abc
                                uint32_t* dst, int y_start,
Packit 9c6abc
                                int y_end, int width);
Packit 9c6abc
typedef void (*VP8LMapAlphaFunc)(const uint8_t* src,
Packit 9c6abc
                                 const uint32_t* const color_map,
Packit 9c6abc
                                 uint8_t* dst, int y_start,
Packit 9c6abc
                                 int y_end, int width);
Packit 9c6abc
Packit 9c6abc
extern VP8LMapARGBFunc VP8LMapColor32b;
Packit 9c6abc
extern VP8LMapAlphaFunc VP8LMapColor8b;
Packit 9c6abc
Packit 9c6abc
// Similar to the static method ColorIndexInverseTransform() that is part of
Packit 9c6abc
// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than
Packit 9c6abc
// uint32_t) arguments for 'src' and 'dst'.
Packit 9c6abc
void VP8LColorIndexInverseTransformAlpha(
Packit 9c6abc
    const struct VP8LTransform* const transform, int y_start, int y_end,
Packit 9c6abc
    const uint8_t* src, uint8_t* dst);
Packit 9c6abc
Packit 9c6abc
// Expose some C-only fallback functions
Packit 9c6abc
void VP8LTransformColorInverse_C(const VP8LMultipliers* const m,
Packit 9c6abc
                                 const uint32_t* src, int num_pixels,
Packit 9c6abc
                                 uint32_t* dst);
Packit 9c6abc
Packit 9c6abc
void VP8LConvertBGRAToRGB_C(const uint32_t* src, int num_pixels, uint8_t* dst);
Packit 9c6abc
void VP8LConvertBGRAToRGBA_C(const uint32_t* src, int num_pixels, uint8_t* dst);
Packit 9c6abc
void VP8LConvertBGRAToRGBA4444_C(const uint32_t* src,
Packit 9c6abc
                                 int num_pixels, uint8_t* dst);
Packit 9c6abc
void VP8LConvertBGRAToRGB565_C(const uint32_t* src,
Packit 9c6abc
                               int num_pixels, uint8_t* dst);
Packit 9c6abc
void VP8LConvertBGRAToBGR_C(const uint32_t* src, int num_pixels, uint8_t* dst);
Packit 9c6abc
void VP8LAddGreenToBlueAndRed_C(const uint32_t* src, int num_pixels,
Packit 9c6abc
                                uint32_t* dst);
Packit 9c6abc
Packit 9c6abc
// Must be called before calling any of the above methods.
Packit 9c6abc
void VP8LDspInit(void);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Encoding
Packit 9c6abc
Packit 9c6abc
typedef void (*VP8LProcessEncBlueAndRedFunc)(uint32_t* dst, int num_pixels);
Packit 9c6abc
extern VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;
Packit 9c6abc
typedef void (*VP8LTransformColorFunc)(const VP8LMultipliers* const m,
Packit 9c6abc
                                       uint32_t* dst, int num_pixels);
Packit 9c6abc
extern VP8LTransformColorFunc VP8LTransformColor;
Packit 9c6abc
typedef void (*VP8LCollectColorBlueTransformsFunc)(
Packit 9c6abc
    const uint32_t* argb, int stride,
Packit 9c6abc
    int tile_width, int tile_height,
Packit 9c6abc
    int green_to_blue, int red_to_blue, int histo[]);
Packit 9c6abc
extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;
Packit 9c6abc
Packit 9c6abc
typedef void (*VP8LCollectColorRedTransformsFunc)(
Packit 9c6abc
    const uint32_t* argb, int stride,
Packit 9c6abc
    int tile_width, int tile_height,
Packit 9c6abc
    int green_to_red, int histo[]);
Packit 9c6abc
extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;
Packit 9c6abc
Packit 9c6abc
// Expose some C-only fallback functions
Packit 9c6abc
void VP8LTransformColor_C(const VP8LMultipliers* const m,
Packit 9c6abc
                          uint32_t* data, int num_pixels);
Packit 9c6abc
void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels);
Packit 9c6abc
void VP8LCollectColorRedTransforms_C(const uint32_t* argb, int stride,
Packit 9c6abc
                                     int tile_width, int tile_height,
Packit 9c6abc
                                     int green_to_red, int histo[]);
Packit 9c6abc
void VP8LCollectColorBlueTransforms_C(const uint32_t* argb, int stride,
Packit 9c6abc
                                      int tile_width, int tile_height,
Packit 9c6abc
                                      int green_to_blue, int red_to_blue,
Packit 9c6abc
                                      int histo[]);
Packit 9c6abc
Packit 9c6abc
extern VP8LPredictorAddSubFunc VP8LPredictorsSub[16];
Packit 9c6abc
extern VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16];
Packit 9c6abc
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
// Huffman-cost related functions.
Packit 9c6abc
Packit 9c6abc
typedef double (*VP8LCostFunc)(const uint32_t* population, int length);
Packit 9c6abc
typedef double (*VP8LCostCombinedFunc)(const uint32_t* X, const uint32_t* Y,
Packit 9c6abc
                                       int length);
Packit 9c6abc
typedef float (*VP8LCombinedShannonEntropyFunc)(const int X[256],
Packit 9c6abc
                                                const int Y[256]);
Packit 9c6abc
Packit 9c6abc
extern VP8LCostFunc VP8LExtraCost;
Packit 9c6abc
extern VP8LCostCombinedFunc VP8LExtraCostCombined;
Packit 9c6abc
extern VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;
Packit 9c6abc
Packit 9c6abc
typedef struct {        // small struct to hold counters
Packit 9c6abc
  int counts[2];        // index: 0=zero steak, 1=non-zero streak
Packit 9c6abc
  int streaks[2][2];    // [zero/non-zero][streak<3 / streak>=3]
Packit 9c6abc
} VP8LStreaks;
Packit 9c6abc
Packit 9c6abc
typedef struct {            // small struct to hold bit entropy results
Packit 9c6abc
  double entropy;           // entropy
Packit 9c6abc
  uint32_t sum;             // sum of the population
Packit 9c6abc
  int nonzeros;             // number of non-zero elements in the population
Packit 9c6abc
  uint32_t max_val;         // maximum value in the population
Packit 9c6abc
  uint32_t nonzero_code;    // index of the last non-zero in the population
Packit 9c6abc
} VP8LBitEntropy;
Packit 9c6abc
Packit 9c6abc
void VP8LBitEntropyInit(VP8LBitEntropy* const entropy);
Packit 9c6abc
Packit 9c6abc
// Get the combined symbol bit entropy and Huffman cost stats for the
Packit 9c6abc
// distributions 'X' and 'Y'. Those results can then be refined according to
Packit 9c6abc
// codec specific heuristics.
Packit 9c6abc
typedef void (*VP8LGetCombinedEntropyUnrefinedFunc)(
Packit 9c6abc
    const uint32_t X[], const uint32_t Y[], int length,
Packit 9c6abc
    VP8LBitEntropy* const bit_entropy, VP8LStreaks* const stats);
Packit 9c6abc
extern VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;
Packit 9c6abc
Packit 9c6abc
// Get the entropy for the distribution 'X'.
Packit 9c6abc
typedef void (*VP8LGetEntropyUnrefinedFunc)(const uint32_t X[], int length,
Packit 9c6abc
                                            VP8LBitEntropy* const bit_entropy,
Packit 9c6abc
                                            VP8LStreaks* const stats);
Packit 9c6abc
extern VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;
Packit 9c6abc
Packit 9c6abc
void VP8LBitsEntropyUnrefined(const uint32_t* const array, int n,
Packit 9c6abc
                              VP8LBitEntropy* const entropy);
Packit 9c6abc
Packit 9c6abc
typedef void (*VP8LHistogramAddFunc)(const VP8LHistogram* const a,
Packit 9c6abc
                                     const VP8LHistogram* const b,
Packit 9c6abc
                                     VP8LHistogram* const out);
Packit 9c6abc
extern VP8LHistogramAddFunc VP8LHistogramAdd;
Packit 9c6abc
Packit 9c6abc
// -----------------------------------------------------------------------------
Packit 9c6abc
// PrefixEncode()
Packit 9c6abc
Packit 9c6abc
typedef int (*VP8LVectorMismatchFunc)(const uint32_t* const array1,
Packit 9c6abc
                                      const uint32_t* const array2, int length);
Packit 9c6abc
// Returns the first index where array1 and array2 are different.
Packit 9c6abc
extern VP8LVectorMismatchFunc VP8LVectorMismatch;
Packit 9c6abc
Packit 9c6abc
typedef void (*VP8LBundleColorMapFunc)(const uint8_t* const row, int width,
Packit 9c6abc
                                       int xbits, uint32_t* dst);
Packit 9c6abc
extern VP8LBundleColorMapFunc VP8LBundleColorMap;
Packit 9c6abc
void VP8LBundleColorMap_C(const uint8_t* const row, int width, int xbits,
Packit 9c6abc
                          uint32_t* dst);
Packit 9c6abc
Packit 9c6abc
// Must be called before calling any of the above methods.
Packit 9c6abc
void VP8LEncDspInit(void);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
}    // extern "C"
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#endif  // WEBP_DSP_LOSSLESS_H_