Coverage Report

Created: 2026-01-16 07:48

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
268M
                           struct vpx_internal_error_info *error) {
50
268M
  if (start + len > start && start + len < end) {
51
268M
    return 1;
52
268M
  } 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
268M
}
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
264M
                           struct vpx_internal_error_info *error) {
50
264M
  if (start + len > start && start + len < end) {
51
264M
    return 1;
52
264M
  } 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
264M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
3.35M
                           struct vpx_internal_error_info *error) {
50
3.35M
  if (start + len > start && start + len < end) {
51
3.35M
    return 1;
52
3.35M
  } 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.35M
}
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
898k
                           struct vpx_internal_error_info *error) {
50
898k
  if (start + len > start && start + len < end) {
51
898k
    return 1;
52
898k
  } 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
898k
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
211M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
211M
  unsigned int split;
61
211M
  int count = bc->count;
62
211M
  unsigned int range = bc->range;
63
211M
  unsigned int lowvalue = bc->lowvalue;
64
211M
  int shift;
65
66
211M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
211M
  range = split;
69
70
211M
  if (bit) {
71
41.9M
    lowvalue += split;
72
41.9M
    range = bc->range - split;
73
41.9M
  }
74
75
211M
  shift = vp8_norm[range];
76
77
211M
  range <<= shift;
78
211M
  count += shift;
79
80
211M
  if (count >= 0) {
81
11.5M
    int offset = shift - count;
82
83
11.5M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
552
      int x = bc->pos - 1;
85
86
2.86k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.30k
        bc->buffer[x] = (unsigned char)0;
88
2.30k
        x--;
89
2.30k
      }
90
91
552
      bc->buffer[x] += 1;
92
552
    }
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
211M
  lowvalue <<= shift;
103
211M
  bc->count = count;
104
211M
  bc->lowvalue = lowvalue;
105
211M
  bc->range = range;
106
211M
}
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
168M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
168M
  unsigned int split;
61
168M
  int count = bc->count;
62
168M
  unsigned int range = bc->range;
63
168M
  unsigned int lowvalue = bc->lowvalue;
64
168M
  int shift;
65
66
168M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
168M
  range = split;
69
70
168M
  if (bit) {
71
29.4M
    lowvalue += split;
72
29.4M
    range = bc->range - split;
73
29.4M
  }
74
75
168M
  shift = vp8_norm[range];
76
77
168M
  range <<= shift;
78
168M
  count += shift;
79
80
168M
  if (count >= 0) {
81
7.27M
    int offset = shift - count;
82
83
7.27M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
509
      int x = bc->pos - 1;
85
86
2.64k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.13k
        bc->buffer[x] = (unsigned char)0;
88
2.13k
        x--;
89
2.13k
      }
90
91
509
      bc->buffer[x] += 1;
92
509
    }
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
168M
  lowvalue <<= shift;
103
168M
  bc->count = count;
104
168M
  bc->lowvalue = lowvalue;
105
168M
  bc->range = range;
106
168M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
29.3M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
29.3M
  unsigned int split;
61
29.3M
  int count = bc->count;
62
29.3M
  unsigned int range = bc->range;
63
29.3M
  unsigned int lowvalue = bc->lowvalue;
64
29.3M
  int shift;
65
66
29.3M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
29.3M
  range = split;
69
70
29.3M
  if (bit) {
71
9.33M
    lowvalue += split;
72
9.33M
    range = bc->range - split;
73
9.33M
  }
74
75
29.3M
  shift = vp8_norm[range];
76
77
29.3M
  range <<= shift;
78
29.3M
  count += shift;
79
80
29.3M
  if (count >= 0) {
81
3.35M
    int offset = shift - count;
82
83
3.35M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
10
      int x = bc->pos - 1;
85
86
48
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
38
        bc->buffer[x] = (unsigned char)0;
88
38
        x--;
89
38
      }
90
91
10
      bc->buffer[x] += 1;
92
10
    }
93
94
3.35M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
3.35M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
3.35M
    shift = count;
98
3.35M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
3.35M
    count -= 8;
100
3.35M
  }
101
102
29.3M
  lowvalue <<= shift;
103
29.3M
  bc->count = count;
104
29.3M
  bc->lowvalue = lowvalue;
105
29.3M
  bc->range = range;
106
29.3M
}
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.2M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
13.2M
  unsigned int split;
61
13.2M
  int count = bc->count;
62
13.2M
  unsigned int range = bc->range;
63
13.2M
  unsigned int lowvalue = bc->lowvalue;
64
13.2M
  int shift;
65
66
13.2M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
13.2M
  range = split;
69
70
13.2M
  if (bit) {
71
3.17M
    lowvalue += split;
72
3.17M
    range = bc->range - split;
73
3.17M
  }
74
75
13.2M
  shift = vp8_norm[range];
76
77
13.2M
  range <<= shift;
78
13.2M
  count += shift;
79
80
13.2M
  if (count >= 0) {
81
898k
    int offset = shift - count;
82
83
898k
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
33
      int x = bc->pos - 1;
85
86
172
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
139
        bc->buffer[x] = (unsigned char)0;
88
139
        x--;
89
139
      }
90
91
33
      bc->buffer[x] += 1;
92
33
    }
93
94
898k
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
898k
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
898k
    shift = count;
98
898k
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
898k
    count -= 8;
100
898k
  }
101
102
13.2M
  lowvalue <<= shift;
103
13.2M
  bc->count = count;
104
13.2M
  bc->lowvalue = lowvalue;
105
13.2M
  bc->range = range;
106
13.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_