Coverage Report

Created: 2026-08-31 06:35

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
70.4M
                           struct vpx_internal_error_info *error) {
50
70.4M
  if (start + len > start && start + len < end) {
51
70.4M
    return 1;
52
70.4M
  } 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
70.4M
}
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
57.9M
                           struct vpx_internal_error_info *error) {
50
57.9M
  if (start + len > start && start + len < end) {
51
57.9M
    return 1;
52
57.9M
  } 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
57.9M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
11.1M
                           struct vpx_internal_error_info *error) {
50
11.1M
  if (start + len > start && start + len < end) {
51
11.1M
    return 1;
52
11.1M
  } 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
11.1M
}
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
1.33M
                           struct vpx_internal_error_info *error) {
50
1.33M
  if (start + len > start && start + len < end) {
51
1.33M
    return 1;
52
1.33M
  } 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
1.33M
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
491M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
491M
  unsigned int split;
61
491M
  int count = bc->count;
62
491M
  unsigned int range = bc->range;
63
491M
  unsigned int lowvalue = bc->lowvalue;
64
491M
  int shift;
65
66
491M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
491M
  range = split;
69
70
491M
  if (bit) {
71
50.0M
    lowvalue += split;
72
50.0M
    range = bc->range - split;
73
50.0M
  }
74
75
491M
  shift = vp8_norm[range];
76
77
491M
  range <<= shift;
78
491M
  count += shift;
79
80
491M
  if (count >= 0) {
81
19.7M
    int offset = shift - count;
82
83
19.7M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
1.13k
      int x = bc->pos - 1;
85
86
1.53k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
404
        bc->buffer[x] = (unsigned char)0;
88
404
        x--;
89
404
      }
90
91
1.13k
      bc->buffer[x] += 1;
92
1.13k
    }
93
94
19.7M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
19.7M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
19.7M
    shift = count;
98
19.7M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
19.7M
    count -= 8;
100
19.7M
  }
101
102
491M
  lowvalue <<= shift;
103
491M
  bc->count = count;
104
491M
  bc->lowvalue = lowvalue;
105
491M
  bc->range = range;
106
491M
}
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
377M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
377M
  unsigned int split;
61
377M
  int count = bc->count;
62
377M
  unsigned int range = bc->range;
63
377M
  unsigned int lowvalue = bc->lowvalue;
64
377M
  int shift;
65
66
377M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
377M
  range = split;
69
70
377M
  if (bit) {
71
23.5M
    lowvalue += split;
72
23.5M
    range = bc->range - split;
73
23.5M
  }
74
75
377M
  shift = vp8_norm[range];
76
77
377M
  range <<= shift;
78
377M
  count += shift;
79
80
377M
  if (count >= 0) {
81
7.27M
    int offset = shift - count;
82
83
7.27M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
761
      int x = bc->pos - 1;
85
86
1.08k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
322
        bc->buffer[x] = (unsigned char)0;
88
322
        x--;
89
322
      }
90
91
761
      bc->buffer[x] += 1;
92
761
    }
93
94
7.27M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
7.27M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
7.27M
    shift = count;
98
7.27M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
7.27M
    count -= 8;
100
7.27M
  }
101
102
377M
  lowvalue <<= shift;
103
377M
  bc->count = count;
104
377M
  bc->lowvalue = lowvalue;
105
377M
  bc->range = range;
106
377M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
89.5M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
89.5M
  unsigned int split;
61
89.5M
  int count = bc->count;
62
89.5M
  unsigned int range = bc->range;
63
89.5M
  unsigned int lowvalue = bc->lowvalue;
64
89.5M
  int shift;
65
66
89.5M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
89.5M
  range = split;
69
70
89.5M
  if (bit) {
71
22.3M
    lowvalue += split;
72
22.3M
    range = bc->range - split;
73
22.3M
  }
74
75
89.5M
  shift = vp8_norm[range];
76
77
89.5M
  range <<= shift;
78
89.5M
  count += shift;
79
80
89.5M
  if (count >= 0) {
81
11.1M
    int offset = shift - count;
82
83
11.1M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
174
      int x = bc->pos - 1;
85
86
208
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
34
        bc->buffer[x] = (unsigned char)0;
88
34
        x--;
89
34
      }
90
91
174
      bc->buffer[x] += 1;
92
174
    }
93
94
11.1M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
11.1M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
11.1M
    shift = count;
98
11.1M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
11.1M
    count -= 8;
100
11.1M
  }
101
102
89.5M
  lowvalue <<= shift;
103
89.5M
  bc->count = count;
104
89.5M
  bc->lowvalue = lowvalue;
105
89.5M
  bc->range = range;
106
89.5M
}
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
24.2M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
24.2M
  unsigned int split;
61
24.2M
  int count = bc->count;
62
24.2M
  unsigned int range = bc->range;
63
24.2M
  unsigned int lowvalue = bc->lowvalue;
64
24.2M
  int shift;
65
66
24.2M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
24.2M
  range = split;
69
70
24.2M
  if (bit) {
71
4.14M
    lowvalue += split;
72
4.14M
    range = bc->range - split;
73
4.14M
  }
74
75
24.2M
  shift = vp8_norm[range];
76
77
24.2M
  range <<= shift;
78
24.2M
  count += shift;
79
80
24.2M
  if (count >= 0) {
81
1.33M
    int offset = shift - count;
82
83
1.33M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
198
      int x = bc->pos - 1;
85
86
246
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
48
        bc->buffer[x] = (unsigned char)0;
88
48
        x--;
89
48
      }
90
91
198
      bc->buffer[x] += 1;
92
198
    }
93
94
1.33M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
1.33M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
1.33M
    shift = count;
98
1.33M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
1.33M
    count -= 8;
100
1.33M
  }
101
102
24.2M
  lowvalue <<= shift;
103
24.2M
  bc->count = count;
104
24.2M
  bc->lowvalue = lowvalue;
105
24.2M
  bc->range = range;
106
24.2M
}
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_