mirror of
https://github.com/webmproject/libwebp.git
synced 2025-02-18 18:02:52 +01:00
- Do light weight entropy based histogram combine and leave out CPU intensive stochastic and greedy heuristics for combining the histograms. For 1000 image PNG corpus (m=0), this change yields speedup of 10% at lower quality range (1% drop in compression density) and about 5% for higher quality range (1% drop in compression density). Following is the compression stats (before/after) for method = 0: Before After bpp/MPs bpp/MPs q=0 2.8336/16.577 2.8615/18.000 q=5 2.8336/16.504 2.8615/18.216 q=10 2.8293/16.419 2.8572/18.070 q=15 2.8242/17.582 2.8519/18.371 q=20 2.8182/16.131 2.8454/18.975 q=25 2.7924/7.670 2.8230/8.531 q=30 2.7078/6.635 2.7310/7.706 q=35 2.7028/6.203 2.7253/6.855 q=40 2.7005/6.198 2.7231/6.364 q=45 2.6989/5.570 2.7216/5.844 q=50 2.6970/5.087 2.7196/5.210 q=55 2.6963/4.589 2.7208/4.766 q=60 2.6949/4.292 2.7195/4.495 q=65 2.6940/3.970 2.7185/4.024 q=70 2.6929/3.698 2.7174/3.699 q=75 2.6919/3.427 2.7164/3.449 q=80 2.6918/3.106 2.7161/3.222 q=85 2.6909/2.856 2.7153/2.919 q=90 2.6902/2.695 2.7145/2.766 q=95 2.6881/2.499 2.7124/2.548 q=100 2.6873/2.253 2.6873/2.285 Change-Id: I0567945068f8dc7888041e93d872f9def91f50ba
115 lines
4.3 KiB
C
115 lines
4.3 KiB
C
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
//
|
|
// 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.
|
|
// -----------------------------------------------------------------------------
|
|
//
|
|
// 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 <assert.h>
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "./backward_references.h"
|
|
#include "../webp/format_constants.h"
|
|
#include "../webp/types.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// A simple container for histograms of data.
|
|
typedef struct {
|
|
// literal_ contains green literal, palette-code and
|
|
// copy-length-prefix histogram
|
|
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];
|
|
// Backward reference prefix-code histogram.
|
|
uint32_t distance_[NUM_DISTANCE_CODES];
|
|
int palette_code_bits_;
|
|
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_;
|
|
} VP8LHistogram;
|
|
|
|
// Collection of histograms with fixed capacity, allocated as one
|
|
// big memory chunk. Can be destroyed by calling WebPSafeFree().
|
|
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);
|
|
|
|
// Return the size of the histogram for a given palette_code_bits.
|
|
int VP8LGetHistogramSize(int palette_code_bits);
|
|
|
|
// 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);
|
|
|
|
// 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);
|
|
|
|
// 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);
|
|
|
|
// 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);
|
|
|
|
// Accumulate a token 'v' into a histogram.
|
|
void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo,
|
|
const PixOrCopy* const v);
|
|
|
|
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);
|
|
}
|
|
|
|
// Builds the histogram image.
|
|
int VP8LGetHistoImageSymbols(int xsize, int ysize,
|
|
const VP8LBackwardRefs* const refs,
|
|
int quality, int low_effort,
|
|
int histogram_bits, int cache_bits,
|
|
VP8LHistogramSet* const image_in,
|
|
VP8LHistogramSet* const tmp_histos,
|
|
uint16_t* const histogram_symbols);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // WEBP_ENC_HISTOGRAM_H_
|