mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
Merge "simplify the Histogram struct, to only store max_value and last_nz"
This commit is contained in:
@ -151,13 +151,22 @@ typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16],
|
||||
const struct VP8Matrix* const mtx);
|
||||
extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT;
|
||||
|
||||
// Collect histogram for susceptibility calculation and accumulate in histo[].
|
||||
struct VP8Histogram;
|
||||
extern const int VP8DspScan[16 + 4 + 4];
|
||||
|
||||
// Collect histogram for susceptibility calculation.
|
||||
#define MAX_COEFF_THRESH 31 // size of histogram used by CollectHistogram.
|
||||
typedef struct {
|
||||
// We only need to store max_value and last_non_zero, not the distribution.
|
||||
int max_value;
|
||||
int last_non_zero;
|
||||
} VP8Histogram;
|
||||
typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred,
|
||||
int start_block, int end_block,
|
||||
struct VP8Histogram* const histo);
|
||||
extern const int VP8DspScan[16 + 4 + 4];
|
||||
VP8Histogram* const histo);
|
||||
extern VP8CHisto VP8CollectHistogram;
|
||||
// General-purpose util function to help VP8CollectHistogram().
|
||||
void VP8LSetHistogramData(const int distribution[MAX_COEFF_THRESH + 1],
|
||||
VP8Histogram* const histo);
|
||||
|
||||
// must be called before using any of the above
|
||||
WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspInit(void);
|
||||
|
@ -40,10 +40,27 @@ const int VP8DspScan[16 + 4 + 4] = {
|
||||
8 + 0 * BPS, 12 + 0 * BPS, 8 + 4 * BPS, 12 + 4 * BPS // V
|
||||
};
|
||||
|
||||
// general-purpose util function
|
||||
void VP8LSetHistogramData(const int distribution[MAX_COEFF_THRESH + 1],
|
||||
VP8Histogram* const histo) {
|
||||
int max_value = 0, last_non_zero = 1;
|
||||
int k;
|
||||
for (k = 0; k <= MAX_COEFF_THRESH; ++k) {
|
||||
const int value = distribution[k];
|
||||
if (value > 0) {
|
||||
if (value > max_value) max_value = value;
|
||||
last_non_zero = k;
|
||||
}
|
||||
}
|
||||
histo->max_value = max_value;
|
||||
histo->last_non_zero = last_non_zero;
|
||||
}
|
||||
|
||||
static void CollectHistogram(const uint8_t* ref, const uint8_t* pred,
|
||||
int start_block, int end_block,
|
||||
VP8Histogram* const histo) {
|
||||
int j;
|
||||
int distribution[MAX_COEFF_THRESH + 1] = { 0 };
|
||||
for (j = start_block; j < end_block; ++j) {
|
||||
int k;
|
||||
int16_t out[16];
|
||||
@ -54,9 +71,10 @@ static void CollectHistogram(const uint8_t* ref, const uint8_t* pred,
|
||||
for (k = 0; k < 16; ++k) {
|
||||
const int v = abs(out[k]) >> 3; // TODO(skal): add rounding?
|
||||
const int clipped_value = clip_max(v, MAX_COEFF_THRESH);
|
||||
histo->distribution[clipped_value]++;
|
||||
++distribution[clipped_value];
|
||||
}
|
||||
}
|
||||
VP8LSetHistogramData(distribution, histo);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -727,6 +727,7 @@ static void CollectHistogram(const uint8_t* ref, const uint8_t* pred,
|
||||
VP8Histogram* const histo) {
|
||||
const uint16x8_t max_coeff_thresh = vdupq_n_u16(MAX_COEFF_THRESH);
|
||||
int j;
|
||||
int distribution[MAX_COEFF_THRESH + 1] = { 0 };
|
||||
for (j = start_block; j < end_block; ++j) {
|
||||
int16_t out[16];
|
||||
FTransform(ref + VP8DspScan[j], pred + VP8DspScan[j], out);
|
||||
@ -744,10 +745,11 @@ static void CollectHistogram(const uint8_t* ref, const uint8_t* pred,
|
||||
vst1q_s16(out + 8, vreinterpretq_s16_u16(b3));
|
||||
// Convert coefficients to bin.
|
||||
for (k = 0; k < 16; ++k) {
|
||||
histo->distribution[out[k]]++;
|
||||
++distribution[out[k]];
|
||||
}
|
||||
}
|
||||
}
|
||||
VP8LSetHistogramData(distribution, histo);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -59,6 +59,7 @@ static void CollectHistogram(const uint8_t* ref, const uint8_t* pred,
|
||||
VP8Histogram* const histo) {
|
||||
const __m128i max_coeff_thresh = _mm_set1_epi16(MAX_COEFF_THRESH);
|
||||
int j;
|
||||
int distribution[MAX_COEFF_THRESH + 1] = { 0 };
|
||||
for (j = start_block; j < end_block; ++j) {
|
||||
int16_t out[16];
|
||||
int k;
|
||||
@ -91,9 +92,10 @@ static void CollectHistogram(const uint8_t* ref, const uint8_t* pred,
|
||||
|
||||
// Convert coefficients to bin.
|
||||
for (k = 0; k < 16; ++k) {
|
||||
histo->distribution[out[k]]++;
|
||||
++distribution[out[k]];
|
||||
}
|
||||
}
|
||||
VP8LSetHistogramData(distribution, histo);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user