Coverage Report

Created: 2026-03-15 06:28

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
67.3M
                           struct vpx_internal_error_info *error) {
50
67.3M
  if (start + len > start && start + len < end) {
51
67.3M
    return 1;
52
67.3M
  } 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
67.3M
}
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
54.8M
                           struct vpx_internal_error_info *error) {
50
54.8M
  if (start + len > start && start + len < end) {
51
54.8M
    return 1;
52
54.8M
  } 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
54.8M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
11.2M
                           struct vpx_internal_error_info *error) {
50
11.2M
  if (start + len > start && start + len < end) {
51
11.2M
    return 1;
52
11.2M
  } 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.2M
}
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.17M
                           struct vpx_internal_error_info *error) {
50
1.17M
  if (start + len > start && start + len < end) {
51
1.17M
    return 1;
52
1.17M
  } 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.17M
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
502M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
502M
  unsigned int split;
61
502M
  int count = bc->count;
62
502M
  unsigned int range = bc->range;
63
502M
  unsigned int lowvalue = bc->lowvalue;
64
502M
  int shift;
65
66
502M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
502M
  range = split;
69
70
502M
  if (bit) {
71
48.2M
    lowvalue += split;
72
48.2M
    range = bc->range - split;
73
48.2M
  }
74
75
502M
  shift = vp8_norm[range];
76
77
502M
  range <<= shift;
78
502M
  count += shift;
79
80
502M
  if (count >= 0) {
81
19.5M
    int offset = shift - count;
82
83
19.5M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
727
      int x = bc->pos - 1;
85
86
1.00k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
282
        bc->buffer[x] = (unsigned char)0;
88
282
        x--;
89
282
      }
90
91
727
      bc->buffer[x] += 1;
92
727
    }
93
94
19.5M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
19.5M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
19.5M
    shift = count;
98
19.5M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
19.5M
    count -= 8;
100
19.5M
  }
101
102
502M
  lowvalue <<= shift;
103
502M
  bc->count = count;
104
502M
  bc->lowvalue = lowvalue;
105
502M
  bc->range = range;
106
502M
}
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
389M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
389M
  unsigned int split;
61
389M
  int count = bc->count;
62
389M
  unsigned int range = bc->range;
63
389M
  unsigned int lowvalue = bc->lowvalue;
64
389M
  int shift;
65
66
389M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
389M
  range = split;
69
70
389M
  if (bit) {
71
22.4M
    lowvalue += split;
72
22.4M
    range = bc->range - split;
73
22.4M
  }
74
75
389M
  shift = vp8_norm[range];
76
77
389M
  range <<= shift;
78
389M
  count += shift;
79
80
389M
  if (count >= 0) {
81
7.04M
    int offset = shift - count;
82
83
7.04M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
581
      int x = bc->pos - 1;
85
86
822
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
241
        bc->buffer[x] = (unsigned char)0;
88
241
        x--;
89
241
      }
90
91
581
      bc->buffer[x] += 1;
92
581
    }
93
94
7.04M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
7.04M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
7.04M
    shift = count;
98
7.04M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
7.04M
    count -= 8;
100
7.04M
  }
101
102
389M
  lowvalue <<= shift;
103
389M
  bc->count = count;
104
389M
  bc->lowvalue = lowvalue;
105
389M
  bc->range = range;
106
389M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
90.6M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
90.6M
  unsigned int split;
61
90.6M
  int count = bc->count;
62
90.6M
  unsigned int range = bc->range;
63
90.6M
  unsigned int lowvalue = bc->lowvalue;
64
90.6M
  int shift;
65
66
90.6M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
90.6M
  range = split;
69
70
90.6M
  if (bit) {
71
22.2M
    lowvalue += split;
72
22.2M
    range = bc->range - split;
73
22.2M
  }
74
75
90.6M
  shift = vp8_norm[range];
76
77
90.6M
  range <<= shift;
78
90.6M
  count += shift;
79
80
90.6M
  if (count >= 0) {
81
11.2M
    int offset = shift - count;
82
83
11.2M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
76
      int x = bc->pos - 1;
85
86
101
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
25
        bc->buffer[x] = (unsigned char)0;
88
25
        x--;
89
25
      }
90
91
76
      bc->buffer[x] += 1;
92
76
    }
93
94
11.2M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
11.2M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
11.2M
    shift = count;
98
11.2M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
11.2M
    count -= 8;
100
11.2M
  }
101
102
90.6M
  lowvalue <<= shift;
103
90.6M
  bc->count = count;
104
90.6M
  bc->lowvalue = lowvalue;
105
90.6M
  bc->range = range;
106
90.6M
}
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
22.7M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
22.7M
  unsigned int split;
61
22.7M
  int count = bc->count;
62
22.7M
  unsigned int range = bc->range;
63
22.7M
  unsigned int lowvalue = bc->lowvalue;
64
22.7M
  int shift;
65
66
22.7M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
22.7M
  range = split;
69
70
22.7M
  if (bit) {
71
3.56M
    lowvalue += split;
72
3.56M
    range = bc->range - split;
73
3.56M
  }
74
75
22.7M
  shift = vp8_norm[range];
76
77
22.7M
  range <<= shift;
78
22.7M
  count += shift;
79
80
22.7M
  if (count >= 0) {
81
1.17M
    int offset = shift - count;
82
83
1.17M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
70
      int x = bc->pos - 1;
85
86
86
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
16
        bc->buffer[x] = (unsigned char)0;
88
16
        x--;
89
16
      }
90
91
70
      bc->buffer[x] += 1;
92
70
    }
93
94
1.17M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
1.17M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
1.17M
    shift = count;
98
1.17M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
1.17M
    count -= 8;
100
1.17M
  }
101
102
22.7M
  lowvalue <<= shift;
103
22.7M
  bc->count = count;
104
22.7M
  bc->lowvalue = lowvalue;
105
22.7M
  bc->range = range;
106
22.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_