Coverage Report

Created: 2026-07-16 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libwebp/src/enc/cost_enc.h
Line
Count
Source
1
// Copyright 2011 Google Inc. All Rights Reserved.
2
//
3
// Use of this source code is governed by a BSD-style license
4
// that can be found in the COPYING file in the root of the source
5
// tree. An additional intellectual property rights grant can be found
6
// in the file PATENTS. All contributing project authors may
7
// be found in the AUTHORS file in the root of the source tree.
8
// -----------------------------------------------------------------------------
9
//
10
// Cost tables for level and modes.
11
//
12
// Author: Skal (pascal.massimino@gmail.com)
13
14
#ifndef WEBP_ENC_COST_ENC_H_
15
#define WEBP_ENC_COST_ENC_H_
16
17
#include <assert.h>
18
#include <stdlib.h>
19
20
#include "src/dec/common_dec.h"
21
#include "src/dsp/dsp.h"
22
#include "src/enc/vp8i_enc.h"
23
#include "src/webp/types.h"
24
25
#ifdef __cplusplus
26
extern "C" {
27
#endif
28
29
// On-the-fly info about the current set of residuals. Handy to avoid
30
// passing zillions of params.
31
typedef struct VP8Residual VP8Residual;
32
struct VP8Residual {
33
  int first;
34
  int last;
35
  const int16_t* coeffs;
36
37
  int coeff_type;
38
  ProbaArray* prob;
39
  StatsArray* stats;
40
  CostArrayPtr costs;
41
};
42
43
void VP8InitResidual(int first, int coeff_type, VP8Encoder* const enc,
44
                     VP8Residual* const res);
45
46
int VP8RecordCoeffs(int ctx, const VP8Residual* const res);
47
48
// Record proba context used.
49
2.33G
static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) {
50
2.33G
  proba_t p = *stats;
51
  // An overflow is inbound. Note we handle this at 0xfffe0000u instead of
52
  // 0xffff0000u to make sure p + 1u does not overflow.
53
2.33G
  if (p >= 0xfffe0000u) {
54
762
    p = ((p + 1u) >> 1) & 0x7fff7fffu;  // -> divide the stats by 2.
55
762
  }
56
  // record bit count (lower 16 bits) and increment total count (upper 16 bits).
57
2.33G
  p += 0x00010000u + bit;
58
2.33G
  *stats = p;
59
2.33G
  return bit;
60
2.33G
}
Unexecuted instantiation: webp_enc.c:VP8RecordStats
Unexecuted instantiation: cost.c:VP8RecordStats
Unexecuted instantiation: cost_sse2.c:VP8RecordStats
Unexecuted instantiation: enc_sse2.c:VP8RecordStats
Unexecuted instantiation: frame_enc.c:VP8RecordStats
Unexecuted instantiation: quant_enc.c:VP8RecordStats
token_enc.c:VP8RecordStats
Line
Count
Source
49
948M
static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) {
50
948M
  proba_t p = *stats;
51
  // An overflow is inbound. Note we handle this at 0xfffe0000u instead of
52
  // 0xffff0000u to make sure p + 1u does not overflow.
53
948M
  if (p >= 0xfffe0000u) {
54
406
    p = ((p + 1u) >> 1) & 0x7fff7fffu;  // -> divide the stats by 2.
55
406
  }
56
  // record bit count (lower 16 bits) and increment total count (upper 16 bits).
57
948M
  p += 0x00010000u + bit;
58
948M
  *stats = p;
59
948M
  return bit;
60
948M
}
cost_enc.c:VP8RecordStats
Line
Count
Source
49
1.39G
static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) {
50
1.39G
  proba_t p = *stats;
51
  // An overflow is inbound. Note we handle this at 0xfffe0000u instead of
52
  // 0xffff0000u to make sure p + 1u does not overflow.
53
1.39G
  if (p >= 0xfffe0000u) {
54
356
    p = ((p + 1u) >> 1) & 0x7fff7fffu;  // -> divide the stats by 2.
55
356
  }
56
  // record bit count (lower 16 bits) and increment total count (upper 16 bits).
57
1.39G
  p += 0x00010000u + bit;
58
1.39G
  *stats = p;
59
1.39G
  return bit;
60
1.39G
}
61
62
// Cost of coding one event with probability 'proba'.
63
5.95G
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
64
5.95G
  return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
65
5.95G
}
Unexecuted instantiation: webp_enc.c:VP8BitCost
cost.c:VP8BitCost
Line
Count
Source
63
209M
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
64
209M
  return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
65
209M
}
cost_sse2.c:VP8BitCost
Line
Count
Source
63
401M
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
64
401M
  return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
65
401M
}
Unexecuted instantiation: enc_sse2.c:VP8BitCost
frame_enc.c:VP8BitCost
Line
Count
Source
63
547M
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
64
547M
  return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
65
547M
}
quant_enc.c:VP8BitCost
Line
Count
Source
63
518M
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
64
518M
  return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
65
518M
}
Unexecuted instantiation: token_enc.c:VP8BitCost
cost_enc.c:VP8BitCost
Line
Count
Source
63
4.27G
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
64
4.27G
  return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
65
4.27G
}
66
67
// Level cost calculations
68
void VP8CalculateLevelCosts(VP8EncProba* const proba);
69
2.99G
static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
70
2.99G
  return VP8LevelFixedCosts[level] +
71
2.99G
         table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
72
2.99G
}
Unexecuted instantiation: webp_enc.c:VP8LevelCost
cost.c:VP8LevelCost
Line
Count
Source
69
1.57G
static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
70
1.57G
  return VP8LevelFixedCosts[level] +
71
1.57G
         table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
72
1.57G
}
Unexecuted instantiation: cost_sse2.c:VP8LevelCost
Unexecuted instantiation: enc_sse2.c:VP8LevelCost
Unexecuted instantiation: frame_enc.c:VP8LevelCost
quant_enc.c:VP8LevelCost
Line
Count
Source
69
1.41G
static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
70
1.41G
  return VP8LevelFixedCosts[level] +
71
1.41G
         table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
72
1.41G
}
Unexecuted instantiation: token_enc.c:VP8LevelCost
Unexecuted instantiation: cost_enc.c:VP8LevelCost
73
74
// Mode costs
75
extern const uint16_t VP8FixedCostsUV[4];
76
extern const uint16_t VP8FixedCostsI16[4];
77
extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
78
79
//------------------------------------------------------------------------------
80
81
#ifdef __cplusplus
82
}  // extern "C"
83
#endif
84
85
#endif  // WEBP_ENC_COST_ENC_H_