Coverage Report

Created: 2026-02-14 06:59

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
246M
                           struct vpx_internal_error_info *error) {
50
246M
  if (start + len > start && start + len < end) {
51
246M
    return 1;
52
246M
  } else {
53
2
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
2
                       "Truncated packet or corrupt partition ");
55
2
  }
56
57
2
  return 0;
58
246M
}
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
241M
                           struct vpx_internal_error_info *error) {
50
241M
  if (start + len > start && start + len < end) {
51
241M
    return 1;
52
241M
  } else {
53
2
    vpx_internal_error(error, VPX_CODEC_CORRUPT_FRAME,
54
2
                       "Truncated packet or corrupt partition ");
55
2
  }
56
57
2
  return 0;
58
241M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
3.51M
                           struct vpx_internal_error_info *error) {
50
3.51M
  if (start + len > start && start + len < end) {
51
3.51M
    return 1;
52
3.51M
  } 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
3.51M
}
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
896k
                           struct vpx_internal_error_info *error) {
50
896k
  if (start + len > start && start + len < end) {
51
896k
    return 1;
52
896k
  } 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
896k
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
219M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
219M
  unsigned int split;
61
219M
  int count = bc->count;
62
219M
  unsigned int range = bc->range;
63
219M
  unsigned int lowvalue = bc->lowvalue;
64
219M
  int shift;
65
66
219M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
219M
  range = split;
69
70
219M
  if (bit) {
71
41.8M
    lowvalue += split;
72
41.8M
    range = bc->range - split;
73
41.8M
  }
74
75
219M
  shift = vp8_norm[range];
76
77
219M
  range <<= shift;
78
219M
  count += shift;
79
80
219M
  if (count >= 0) {
81
11.5M
    int offset = shift - count;
82
83
11.5M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
619
      int x = bc->pos - 1;
85
86
3.16k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.55k
        bc->buffer[x] = (unsigned char)0;
88
2.55k
        x--;
89
2.55k
      }
90
91
619
      bc->buffer[x] += 1;
92
619
    }
93
94
11.5M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
11.5M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
11.5M
    shift = count;
98
11.5M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
11.5M
    count -= 8;
100
11.5M
  }
101
102
219M
  lowvalue <<= shift;
103
219M
  bc->count = count;
104
219M
  bc->lowvalue = lowvalue;
105
219M
  bc->range = range;
106
219M
}
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
175M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
175M
  unsigned int split;
61
175M
  int count = bc->count;
62
175M
  unsigned int range = bc->range;
63
175M
  unsigned int lowvalue = bc->lowvalue;
64
175M
  int shift;
65
66
175M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
175M
  range = split;
69
70
175M
  if (bit) {
71
29.0M
    lowvalue += split;
72
29.0M
    range = bc->range - split;
73
29.0M
  }
74
75
175M
  shift = vp8_norm[range];
76
77
175M
  range <<= shift;
78
175M
  count += shift;
79
80
175M
  if (count >= 0) {
81
7.13M
    int offset = shift - count;
82
83
7.13M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
567
      int x = bc->pos - 1;
85
86
2.91k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.34k
        bc->buffer[x] = (unsigned char)0;
88
2.34k
        x--;
89
2.34k
      }
90
91
567
      bc->buffer[x] += 1;
92
567
    }
93
94
7.13M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
7.13M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
7.13M
    shift = count;
98
7.13M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
7.13M
    count -= 8;
100
7.13M
  }
101
102
175M
  lowvalue <<= shift;
103
175M
  bc->count = count;
104
175M
  bc->lowvalue = lowvalue;
105
175M
  bc->range = range;
106
175M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
30.9M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
30.9M
  unsigned int split;
61
30.9M
  int count = bc->count;
62
30.9M
  unsigned int range = bc->range;
63
30.9M
  unsigned int lowvalue = bc->lowvalue;
64
30.9M
  int shift;
65
66
30.9M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
30.9M
  range = split;
69
70
30.9M
  if (bit) {
71
9.70M
    lowvalue += split;
72
9.70M
    range = bc->range - split;
73
9.70M
  }
74
75
30.9M
  shift = vp8_norm[range];
76
77
30.9M
  range <<= shift;
78
30.9M
  count += shift;
79
80
30.9M
  if (count >= 0) {
81
3.51M
    int offset = shift - count;
82
83
3.51M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
15
      int x = bc->pos - 1;
85
86
33
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
18
        bc->buffer[x] = (unsigned char)0;
88
18
        x--;
89
18
      }
90
91
15
      bc->buffer[x] += 1;
92
15
    }
93
94
3.51M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
3.51M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
3.51M
    shift = count;
98
3.51M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
3.51M
    count -= 8;
100
3.51M
  }
101
102
30.9M
  lowvalue <<= shift;
103
30.9M
  bc->count = count;
104
30.9M
  bc->lowvalue = lowvalue;
105
30.9M
  bc->range = range;
106
30.9M
}
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
13.4M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
13.4M
  unsigned int split;
61
13.4M
  int count = bc->count;
62
13.4M
  unsigned int range = bc->range;
63
13.4M
  unsigned int lowvalue = bc->lowvalue;
64
13.4M
  int shift;
65
66
13.4M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
13.4M
  range = split;
69
70
13.4M
  if (bit) {
71
3.16M
    lowvalue += split;
72
3.16M
    range = bc->range - split;
73
3.16M
  }
74
75
13.4M
  shift = vp8_norm[range];
76
77
13.4M
  range <<= shift;
78
13.4M
  count += shift;
79
80
13.4M
  if (count >= 0) {
81
896k
    int offset = shift - count;
82
83
896k
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
37
      int x = bc->pos - 1;
85
86
225
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
188
        bc->buffer[x] = (unsigned char)0;
88
188
        x--;
89
188
      }
90
91
37
      bc->buffer[x] += 1;
92
37
    }
93
94
896k
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
896k
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
896k
    shift = count;
98
896k
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
896k
    count -= 8;
100
896k
  }
101
102
13.4M
  lowvalue <<= shift;
103
13.4M
  bc->count = count;
104
13.4M
  bc->lowvalue = lowvalue;
105
13.4M
  bc->range = range;
106
13.4M
}
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_