Coverage Report

Created: 2026-05-16 07:49

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
296M
                           struct vpx_internal_error_info *error) {
50
296M
  if (start + len > start && start + len < end) {
51
296M
    return 1;
52
296M
  } 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
296M
}
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
291M
                           struct vpx_internal_error_info *error) {
50
291M
  if (start + len > start && start + len < end) {
51
291M
    return 1;
52
291M
  } 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
291M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
3.66M
                           struct vpx_internal_error_info *error) {
50
3.66M
  if (start + len > start && start + len < end) {
51
3.66M
    return 1;
52
3.66M
  } 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.66M
}
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
984k
                           struct vpx_internal_error_info *error) {
50
984k
  if (start + len > start && start + len < end) {
51
984k
    return 1;
52
984k
  } 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
984k
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
230M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
230M
  unsigned int split;
61
230M
  int count = bc->count;
62
230M
  unsigned int range = bc->range;
63
230M
  unsigned int lowvalue = bc->lowvalue;
64
230M
  int shift;
65
66
230M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
230M
  range = split;
69
70
230M
  if (bit) {
71
46.1M
    lowvalue += split;
72
46.1M
    range = bc->range - split;
73
46.1M
  }
74
75
230M
  shift = vp8_norm[range];
76
77
230M
  range <<= shift;
78
230M
  count += shift;
79
80
230M
  if (count >= 0) {
81
12.5M
    int offset = shift - count;
82
83
12.5M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
802
      int x = bc->pos - 1;
85
86
3.76k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.95k
        bc->buffer[x] = (unsigned char)0;
88
2.95k
        x--;
89
2.95k
      }
90
91
802
      bc->buffer[x] += 1;
92
802
    }
93
94
12.5M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
12.5M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
12.5M
    shift = count;
98
12.5M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
12.5M
    count -= 8;
100
12.5M
  }
101
102
230M
  lowvalue <<= shift;
103
230M
  bc->count = count;
104
230M
  bc->lowvalue = lowvalue;
105
230M
  bc->range = range;
106
230M
}
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
184M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
184M
  unsigned int split;
61
184M
  int count = bc->count;
62
184M
  unsigned int range = bc->range;
63
184M
  unsigned int lowvalue = bc->lowvalue;
64
184M
  int shift;
65
66
184M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
184M
  range = split;
69
70
184M
  if (bit) {
71
32.5M
    lowvalue += split;
72
32.5M
    range = bc->range - split;
73
32.5M
  }
74
75
184M
  shift = vp8_norm[range];
76
77
184M
  range <<= shift;
78
184M
  count += shift;
79
80
184M
  if (count >= 0) {
81
7.91M
    int offset = shift - count;
82
83
7.91M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
731
      int x = bc->pos - 1;
85
86
3.41k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.68k
        bc->buffer[x] = (unsigned char)0;
88
2.68k
        x--;
89
2.68k
      }
90
91
731
      bc->buffer[x] += 1;
92
731
    }
93
94
7.91M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
7.91M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
7.91M
    shift = count;
98
7.91M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
7.91M
    count -= 8;
100
7.91M
  }
101
102
184M
  lowvalue <<= shift;
103
184M
  bc->count = count;
104
184M
  bc->lowvalue = lowvalue;
105
184M
  bc->range = range;
106
184M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
32.2M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
32.2M
  unsigned int split;
61
32.2M
  int count = bc->count;
62
32.2M
  unsigned int range = bc->range;
63
32.2M
  unsigned int lowvalue = bc->lowvalue;
64
32.2M
  int shift;
65
66
32.2M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
32.2M
  range = split;
69
70
32.2M
  if (bit) {
71
10.1M
    lowvalue += split;
72
10.1M
    range = bc->range - split;
73
10.1M
  }
74
75
32.2M
  shift = vp8_norm[range];
76
77
32.2M
  range <<= shift;
78
32.2M
  count += shift;
79
80
32.2M
  if (count >= 0) {
81
3.66M
    int offset = shift - count;
82
83
3.66M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
19
      int x = bc->pos - 1;
85
86
53
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
34
        bc->buffer[x] = (unsigned char)0;
88
34
        x--;
89
34
      }
90
91
19
      bc->buffer[x] += 1;
92
19
    }
93
94
3.66M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
3.66M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
3.66M
    shift = count;
98
3.66M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
3.66M
    count -= 8;
100
3.66M
  }
101
102
32.2M
  lowvalue <<= shift;
103
32.2M
  bc->count = count;
104
32.2M
  bc->lowvalue = lowvalue;
105
32.2M
  bc->range = range;
106
32.2M
}
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
14.4M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
14.4M
  unsigned int split;
61
14.4M
  int count = bc->count;
62
14.4M
  unsigned int range = bc->range;
63
14.4M
  unsigned int lowvalue = bc->lowvalue;
64
14.4M
  int shift;
65
66
14.4M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
14.4M
  range = split;
69
70
14.4M
  if (bit) {
71
3.49M
    lowvalue += split;
72
3.49M
    range = bc->range - split;
73
3.49M
  }
74
75
14.4M
  shift = vp8_norm[range];
76
77
14.4M
  range <<= shift;
78
14.4M
  count += shift;
79
80
14.4M
  if (count >= 0) {
81
984k
    int offset = shift - count;
82
83
984k
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
52
      int x = bc->pos - 1;
85
86
297
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
245
        bc->buffer[x] = (unsigned char)0;
88
245
        x--;
89
245
      }
90
91
52
      bc->buffer[x] += 1;
92
52
    }
93
94
984k
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
984k
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
984k
    shift = count;
98
984k
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
984k
    count -= 8;
100
984k
  }
101
102
14.4M
  lowvalue <<= shift;
103
14.4M
  bc->count = count;
104
14.4M
  bc->lowvalue = lowvalue;
105
14.4M
  bc->range = range;
106
14.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_