Coverage Report

Created: 2026-07-25 07:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vp8/encoder/boolhuff.h
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
/****************************************************************************
12
 *
13
 *   Module Title :     boolhuff.h
14
 *
15
 *   Description  :     Bool Coder header file.
16
 *
17
 ****************************************************************************/
18
#ifndef VPX_VP8_ENCODER_BOOLHUFF_H_
19
#define VPX_VP8_ENCODER_BOOLHUFF_H_
20
21
#include "vpx_ports/mem.h"
22
#include "vpx/internal/vpx_codec_internal.h"
23
24
#ifdef __cplusplus
25
extern "C" {
26
#endif
27
28
typedef struct {
29
  unsigned int lowvalue;
30
  unsigned int range;
31
  int count;
32
  unsigned int pos;
33
  unsigned char *buffer;
34
  unsigned char *buffer_end;
35
  struct vpx_internal_error_info *error;
36
} BOOL_CODER;
37
38
void vp8_start_encode(BOOL_CODER *bc, unsigned char *source,
39
                      unsigned char *source_end);
40
41
void vp8_encode_value(BOOL_CODER *bc, int data, int bits);
42
void vp8_stop_encode(BOOL_CODER *bc);
43
extern const unsigned int vp8_prob_cost[256];
44
45
DECLARE_ALIGNED(16, extern const unsigned char, vp8_norm[256]);
46
47
static int validate_buffer(const unsigned char *start, size_t len,
48
                           const unsigned char *end,
49
226M
                           struct vpx_internal_error_info *error) {
50
226M
  if (start + len > start && start + len < end) {
51
226M
    return 1;
52
226M
  } else {
53
3
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
3
                       "Truncated packet or corrupt partition ");
55
3
  }
56
57
3
  return 0;
58
226M
}
Unexecuted instantiation: vp8_cx_iface.c:validate_buffer
Unexecuted instantiation: ethreading.c:validate_buffer
Unexecuted instantiation: onyx_if.c:validate_buffer
Unexecuted instantiation: pickinter.c:validate_buffer
Unexecuted instantiation: picklpf.c:validate_buffer
Unexecuted instantiation: vp8_quantize.c:validate_buffer
Unexecuted instantiation: ratectrl.c:validate_buffer
Unexecuted instantiation: rdopt.c:validate_buffer
Unexecuted instantiation: segmentation.c:validate_buffer
Unexecuted instantiation: vp8_skin_detection.c:validate_buffer
Unexecuted instantiation: tokenize.c:validate_buffer
Unexecuted instantiation: treewriter.c:validate_buffer
Unexecuted instantiation: temporal_filter.c:validate_buffer
bitstream.c:validate_buffer
Line
Count
Source
49
222M
                           struct vpx_internal_error_info *error) {
50
222M
  if (start + len > start && start + len < end) {
51
222M
    return 1;
52
222M
  } else {
53
3
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
3
                       "Truncated packet or corrupt partition ");
55
3
  }
56
57
3
  return 0;
58
222M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
2.97M
                           struct vpx_internal_error_info *error) {
50
2.97M
  if (start + len > start && start + len < end) {
51
2.97M
    return 1;
52
2.97M
  } else {
53
0
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
0
                       "Truncated packet or corrupt partition ");
55
0
  }
56
57
0
  return 0;
58
2.97M
}
Unexecuted instantiation: encodeframe.c:validate_buffer
Unexecuted instantiation: encodeintra.c:validate_buffer
Unexecuted instantiation: encodemb.c:validate_buffer
encodemv.c:validate_buffer
Line
Count
Source
49
788k
                           struct vpx_internal_error_info *error) {
50
788k
  if (start + len > start && start + len < end) {
51
788k
    return 1;
52
788k
  } else {
53
0
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
0
                       "Truncated packet or corrupt partition ");
55
0
  }
56
57
0
  return 0;
58
788k
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
185M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
185M
  unsigned int split;
61
185M
  int count = bc->count;
62
185M
  unsigned int range = bc->range;
63
185M
  unsigned int lowvalue = bc->lowvalue;
64
185M
  int shift;
65
66
185M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
185M
  range = split;
69
70
185M
  if (bit) {
71
33.0M
    lowvalue += split;
72
33.0M
    range = bc->range - split;
73
33.0M
  }
74
75
185M
  shift = vp8_norm[range];
76
77
185M
  range <<= shift;
78
185M
  count += shift;
79
80
185M
  if (count >= 0) {
81
9.37M
    int offset = shift - count;
82
83
9.37M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
498
      int x = bc->pos - 1;
85
86
1.62k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
1.12k
        bc->buffer[x] = (unsigned char)0;
88
1.12k
        x--;
89
1.12k
      }
90
91
498
      bc->buffer[x] += 1;
92
498
    }
93
94
9.37M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
9.37M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
9.37M
    shift = count;
98
9.37M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
9.37M
    count -= 8;
100
9.37M
  }
101
102
185M
  lowvalue <<= shift;
103
185M
  bc->count = count;
104
185M
  bc->lowvalue = lowvalue;
105
185M
  bc->range = range;
106
185M
}
Unexecuted instantiation: vp8_cx_iface.c:vp8_encode_bool
Unexecuted instantiation: ethreading.c:vp8_encode_bool
Unexecuted instantiation: onyx_if.c:vp8_encode_bool
Unexecuted instantiation: pickinter.c:vp8_encode_bool
Unexecuted instantiation: picklpf.c:vp8_encode_bool
Unexecuted instantiation: vp8_quantize.c:vp8_encode_bool
Unexecuted instantiation: ratectrl.c:vp8_encode_bool
Unexecuted instantiation: rdopt.c:vp8_encode_bool
Unexecuted instantiation: segmentation.c:vp8_encode_bool
Unexecuted instantiation: vp8_skin_detection.c:vp8_encode_bool
Unexecuted instantiation: tokenize.c:vp8_encode_bool
Unexecuted instantiation: treewriter.c:vp8_encode_bool
Unexecuted instantiation: temporal_filter.c:vp8_encode_bool
bitstream.c:vp8_encode_bool
Line
Count
Source
59
147M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
147M
  unsigned int split;
61
147M
  int count = bc->count;
62
147M
  unsigned int range = bc->range;
63
147M
  unsigned int lowvalue = bc->lowvalue;
64
147M
  int shift;
65
66
147M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
147M
  range = split;
69
70
147M
  if (bit) {
71
22.1M
    lowvalue += split;
72
22.1M
    range = bc->range - split;
73
22.1M
  }
74
75
147M
  shift = vp8_norm[range];
76
77
147M
  range <<= shift;
78
147M
  count += shift;
79
80
147M
  if (count >= 0) {
81
5.61M
    int offset = shift - count;
82
83
5.61M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
416
      int x = bc->pos - 1;
85
86
1.36k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
950
        bc->buffer[x] = (unsigned char)0;
88
950
        x--;
89
950
      }
90
91
416
      bc->buffer[x] += 1;
92
416
    }
93
94
5.61M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
5.61M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
5.61M
    shift = count;
98
5.61M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
5.61M
    count -= 8;
100
5.61M
  }
101
102
147M
  lowvalue <<= shift;
103
147M
  bc->count = count;
104
147M
  bc->lowvalue = lowvalue;
105
147M
  bc->range = range;
106
147M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
26.0M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
26.0M
  unsigned int split;
61
26.0M
  int count = bc->count;
62
26.0M
  unsigned int range = bc->range;
63
26.0M
  unsigned int lowvalue = bc->lowvalue;
64
26.0M
  int shift;
65
66
26.0M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
26.0M
  range = split;
69
70
26.0M
  if (bit) {
71
8.08M
    lowvalue += split;
72
8.08M
    range = bc->range - split;
73
8.08M
  }
74
75
26.0M
  shift = vp8_norm[range];
76
77
26.0M
  range <<= shift;
78
26.0M
  count += shift;
79
80
26.0M
  if (count >= 0) {
81
2.97M
    int offset = shift - count;
82
83
2.97M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
27
      int x = bc->pos - 1;
85
86
62
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
35
        bc->buffer[x] = (unsigned char)0;
88
35
        x--;
89
35
      }
90
91
27
      bc->buffer[x] += 1;
92
27
    }
93
94
2.97M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
2.97M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
2.97M
    shift = count;
98
2.97M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
2.97M
    count -= 8;
100
2.97M
  }
101
102
26.0M
  lowvalue <<= shift;
103
26.0M
  bc->count = count;
104
26.0M
  bc->lowvalue = lowvalue;
105
26.0M
  bc->range = range;
106
26.0M
}
Unexecuted instantiation: encodeframe.c:vp8_encode_bool
Unexecuted instantiation: encodeintra.c:vp8_encode_bool
Unexecuted instantiation: encodemb.c:vp8_encode_bool
encodemv.c:vp8_encode_bool
Line
Count
Source
59
11.7M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
11.7M
  unsigned int split;
61
11.7M
  int count = bc->count;
62
11.7M
  unsigned int range = bc->range;
63
11.7M
  unsigned int lowvalue = bc->lowvalue;
64
11.7M
  int shift;
65
66
11.7M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
11.7M
  range = split;
69
70
11.7M
  if (bit) {
71
2.72M
    lowvalue += split;
72
2.72M
    range = bc->range - split;
73
2.72M
  }
74
75
11.7M
  shift = vp8_norm[range];
76
77
11.7M
  range <<= shift;
78
11.7M
  count += shift;
79
80
11.7M
  if (count >= 0) {
81
788k
    int offset = shift - count;
82
83
788k
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
55
      int x = bc->pos - 1;
85
86
198
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
143
        bc->buffer[x] = (unsigned char)0;
88
143
        x--;
89
143
      }
90
91
55
      bc->buffer[x] += 1;
92
55
    }
93
94
788k
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
788k
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
788k
    shift = count;
98
788k
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
788k
    count -= 8;
100
788k
  }
101
102
11.7M
  lowvalue <<= shift;
103
11.7M
  bc->count = count;
104
11.7M
  bc->lowvalue = lowvalue;
105
11.7M
  bc->range = range;
106
11.7M
}
Unexecuted instantiation: firstpass.c:vp8_encode_bool
Unexecuted instantiation: mcomp.c:vp8_encode_bool
Unexecuted instantiation: modecosts.c:vp8_encode_bool
107
108
#ifdef __cplusplus
109
}  // extern "C"
110
#endif
111
112
#endif  // VPX_VP8_ENCODER_BOOLHUFF_H_