mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.7 KiB
124 lines
4.7 KiB
12 years ago
|
// Copyright 2012 Google Inc. All Rights Reserved.
|
||
|
//
|
||
12 years ago
|
// 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.
|
||
12 years ago
|
// -----------------------------------------------------------------------------
|
||
|
//
|
||
|
// Author: Jyrki Alakuijala (jyrki@google.com)
|
||
|
//
|
||
|
// Models the histograms of literal and distance codes.
|
||
|
|
||
|
#ifndef WEBP_ENC_HISTOGRAM_H_
|
||
|
#define WEBP_ENC_HISTOGRAM_H_
|
||
|
|
||
|
#include <string.h>
|
||
|
|
||
8 years ago
|
#include "./backward_references_enc.h"
|
||
12 years ago
|
#include "../webp/format_constants.h"
|
||
|
#include "../webp/types.h"
|
||
|
|
||
8 years ago
|
#ifdef __cplusplus
|
||
12 years ago
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
8 years ago
|
// Not a trivial literal symbol.
|
||
|
#define VP8L_NON_TRIVIAL_SYM (0xffffffff)
|
||
|
|
||
12 years ago
|
// A simple container for histograms of data.
|
||
|
typedef struct {
|
||
|
// literal_ contains green literal, palette-code and
|
||
|
// copy-length-prefix histogram
|
||
8 years ago
|
uint32_t* literal_; // Pointer to the allocated buffer for literal.
|
||
|
uint32_t red_[NUM_LITERAL_CODES];
|
||
|
uint32_t blue_[NUM_LITERAL_CODES];
|
||
|
uint32_t alpha_[NUM_LITERAL_CODES];
|
||
12 years ago
|
// Backward reference prefix-code histogram.
|
||
8 years ago
|
uint32_t distance_[NUM_DISTANCE_CODES];
|
||
12 years ago
|
int palette_code_bits_;
|
||
8 years ago
|
uint32_t trivial_symbol_; // True, if histograms for Red, Blue & Alpha
|
||
|
// literal symbols are single valued.
|
||
|
double bit_cost_; // cached value of bit cost.
|
||
|
double literal_cost_; // Cached values of dominant entropy costs:
|
||
|
double red_cost_; // literal, red & blue.
|
||
|
double blue_cost_;
|
||
12 years ago
|
} VP8LHistogram;
|
||
|
|
||
|
// Collection of histograms with fixed capacity, allocated as one
|
||
8 years ago
|
// big memory chunk. Can be destroyed by calling WebPSafeFree().
|
||
12 years ago
|
typedef struct {
|
||
|
int size; // number of slots currently in use
|
||
|
int max_size; // maximum capacity
|
||
|
VP8LHistogram** histograms;
|
||
|
} VP8LHistogramSet;
|
||
|
|
||
|
// Create the histogram.
|
||
|
//
|
||
|
// The input data is the PixOrCopy data, which models the literals, stop
|
||
|
// codes and backward references (both distances and lengths). Also: if
|
||
|
// palette_code_bits is >= 0, initialize the histogram with this value.
|
||
|
void VP8LHistogramCreate(VP8LHistogram* const p,
|
||
|
const VP8LBackwardRefs* const refs,
|
||
|
int palette_code_bits);
|
||
|
|
||
8 years ago
|
// Return the size of the histogram for a given palette_code_bits.
|
||
|
int VP8LGetHistogramSize(int palette_code_bits);
|
||
|
|
||
12 years ago
|
// Set the palette_code_bits and reset the stats.
|
||
|
void VP8LHistogramInit(VP8LHistogram* const p, int palette_code_bits);
|
||
|
|
||
|
// Collect all the references into a histogram (without reset)
|
||
|
void VP8LHistogramStoreRefs(const VP8LBackwardRefs* const refs,
|
||
|
VP8LHistogram* const histo);
|
||
|
|
||
8 years ago
|
// Free the memory allocated for the histogram.
|
||
|
void VP8LFreeHistogram(VP8LHistogram* const histo);
|
||
|
|
||
|
// Free the memory allocated for the histogram set.
|
||
|
void VP8LFreeHistogramSet(VP8LHistogramSet* const histo);
|
||
|
|
||
12 years ago
|
// Allocate an array of pointer to histograms, allocated and initialized
|
||
|
// using 'cache_bits'. Return NULL in case of memory error.
|
||
|
VP8LHistogramSet* VP8LAllocateHistogramSet(int size, int cache_bits);
|
||
|
|
||
8 years ago
|
// Allocate and initialize histogram object with specified 'cache_bits'.
|
||
|
// Returns NULL in case of memory error.
|
||
|
// Special case of VP8LAllocateHistogramSet, with size equals 1.
|
||
|
VP8LHistogram* VP8LAllocateHistogram(int cache_bits);
|
||
|
|
||
12 years ago
|
// Accumulate a token 'v' into a histogram.
|
||
|
void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo,
|
||
|
const PixOrCopy* const v);
|
||
|
|
||
8 years ago
|
static WEBP_INLINE int VP8LHistogramNumCodes(int palette_code_bits) {
|
||
|
return NUM_LITERAL_CODES + NUM_LENGTH_CODES +
|
||
|
((palette_code_bits > 0) ? (1 << palette_code_bits) : 0);
|
||
12 years ago
|
}
|
||
|
|
||
|
// Builds the histogram image.
|
||
|
int VP8LGetHistoImageSymbols(int xsize, int ysize,
|
||
|
const VP8LBackwardRefs* const refs,
|
||
8 years ago
|
int quality, int low_effort,
|
||
|
int histogram_bits, int cache_bits,
|
||
12 years ago
|
VP8LHistogramSet* const image_in,
|
||
8 years ago
|
VP8LHistogramSet* const tmp_histos,
|
||
12 years ago
|
uint16_t* const histogram_symbols);
|
||
|
|
||
8 years ago
|
// Returns the entropy for the symbols in the input array.
|
||
|
// Also sets trivial_symbol to the code value, if the array has only one code
|
||
|
// value. Otherwise, set it to VP8L_NON_TRIVIAL_SYM.
|
||
|
double VP8LBitsEntropy(const uint32_t* const array, int n,
|
||
|
uint32_t* const trivial_symbol);
|
||
|
|
||
|
// Estimate how many bits the combined entropy of literals and distance
|
||
|
// approximately maps to.
|
||
|
double VP8LHistogramEstimateBits(const VP8LHistogram* const p);
|
||
|
|
||
|
#ifdef __cplusplus
|
||
12 years ago
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif // WEBP_ENC_HISTOGRAM_H_
|