Coverage Report

Created: 2026-05-23 07:06

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
286M
                           struct vpx_internal_error_info *error) {
50
286M
  if (start + len > start && start + len < end) {
51
286M
    return 1;
52
286M
  } 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
286M
}
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
281M
                           struct vpx_internal_error_info *error) {
50
281M
  if (start + len > start && start + len < end) {
51
281M
    return 1;
52
281M
  } 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
281M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
3.54M
                           struct vpx_internal_error_info *error) {
50
3.54M
  if (start + len > start && start + len < end) {
51
3.54M
    return 1;
52
3.54M
  } 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.54M
}
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
904k
                           struct vpx_internal_error_info *error) {
50
904k
  if (start + len > start && start + len < end) {
51
904k
    return 1;
52
904k
  } 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
904k
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
222M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
222M
  unsigned int split;
61
222M
  int count = bc->count;
62
222M
  unsigned int range = bc->range;
63
222M
  unsigned int lowvalue = bc->lowvalue;
64
222M
  int shift;
65
66
222M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
222M
  range = split;
69
70
222M
  if (bit) {
71
43.8M
    lowvalue += split;
72
43.8M
    range = bc->range - split;
73
43.8M
  }
74
75
222M
  shift = vp8_norm[range];
76
77
222M
  range <<= shift;
78
222M
  count += shift;
79
80
222M
  if (count >= 0) {
81
12.0M
    int offset = shift - count;
82
83
12.0M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
735
      int x = bc->pos - 1;
85
86
3.36k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.62k
        bc->buffer[x] = (unsigned char)0;
88
2.62k
        x--;
89
2.62k
      }
90
91
735
      bc->buffer[x] += 1;
92
735
    }
93
94
12.0M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
12.0M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
12.0M
    shift = count;
98
12.0M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
12.0M
    count -= 8;
100
12.0M
  }
101
102
222M
  lowvalue <<= shift;
103
222M
  bc->count = count;
104
222M
  bc->lowvalue = lowvalue;
105
222M
  bc->range = range;
106
222M
}
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
177M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
177M
  unsigned int split;
61
177M
  int count = bc->count;
62
177M
  unsigned int range = bc->range;
63
177M
  unsigned int lowvalue = bc->lowvalue;
64
177M
  int shift;
65
66
177M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
177M
  range = split;
69
70
177M
  if (bit) {
71
30.8M
    lowvalue += split;
72
30.8M
    range = bc->range - split;
73
30.8M
  }
74
75
177M
  shift = vp8_norm[range];
76
77
177M
  range <<= shift;
78
177M
  count += shift;
79
80
177M
  if (count >= 0) {
81
7.59M
    int offset = shift - count;
82
83
7.59M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
659
      int x = bc->pos - 1;
85
86
3.06k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.40k
        bc->buffer[x] = (unsigned char)0;
88
2.40k
        x--;
89
2.40k
      }
90
91
659
      bc->buffer[x] += 1;
92
659
    }
93
94
7.59M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
7.59M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
7.59M
    shift = count;
98
7.59M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
7.59M
    count -= 8;
100
7.59M
  }
101
102
177M
  lowvalue <<= shift;
103
177M
  bc->count = count;
104
177M
  bc->lowvalue = lowvalue;
105
177M
  bc->range = range;
106
177M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
31.1M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
31.1M
  unsigned int split;
61
31.1M
  int count = bc->count;
62
31.1M
  unsigned int range = bc->range;
63
31.1M
  unsigned int lowvalue = bc->lowvalue;
64
31.1M
  int shift;
65
66
31.1M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
31.1M
  range = split;
69
70
31.1M
  if (bit) {
71
9.77M
    lowvalue += split;
72
9.77M
    range = bc->range - split;
73
9.77M
  }
74
75
31.1M
  shift = vp8_norm[range];
76
77
31.1M
  range <<= shift;
78
31.1M
  count += shift;
79
80
31.1M
  if (count >= 0) {
81
3.54M
    int offset = shift - count;
82
83
3.54M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
11
      int x = bc->pos - 1;
85
86
30
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
19
        bc->buffer[x] = (unsigned char)0;
88
19
        x--;
89
19
      }
90
91
11
      bc->buffer[x] += 1;
92
11
    }
93
94
3.54M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
3.54M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
3.54M
    shift = count;
98
3.54M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
3.54M
    count -= 8;
100
3.54M
  }
101
102
31.1M
  lowvalue <<= shift;
103
31.1M
  bc->count = count;
104
31.1M
  bc->lowvalue = lowvalue;
105
31.1M
  bc->range = range;
106
31.1M
}
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.20M
    lowvalue += split;
72
3.20M
    range = bc->range - split;
73
3.20M
  }
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
904k
    int offset = shift - count;
82
83
904k
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
65
      int x = bc->pos - 1;
85
86
269
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
204
        bc->buffer[x] = (unsigned char)0;
88
204
        x--;
89
204
      }
90
91
65
      bc->buffer[x] += 1;
92
65
    }
93
94
904k
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
904k
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
904k
    shift = count;
98
904k
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
904k
    count -= 8;
100
904k
  }
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_