Coverage Report

Created: 2026-04-29 06:43

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
65.5M
                           struct vpx_internal_error_info *error) {
50
65.5M
  if (start + len > start && start + len < end) {
51
65.5M
    return 1;
52
65.5M
  } 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
65.5M
}
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
53.4M
                           struct vpx_internal_error_info *error) {
50
53.4M
  if (start + len > start && start + len < end) {
51
53.4M
    return 1;
52
53.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
53.4M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
10.9M
                           struct vpx_internal_error_info *error) {
50
10.9M
  if (start + len > start && start + len < end) {
51
10.9M
    return 1;
52
10.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
10.9M
}
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.11M
                           struct vpx_internal_error_info *error) {
50
1.11M
  if (start + len > start && start + len < end) {
51
1.11M
    return 1;
52
1.11M
  } 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.11M
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
59
490M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
490M
  unsigned int split;
61
490M
  int count = bc->count;
62
490M
  unsigned int range = bc->range;
63
490M
  unsigned int lowvalue = bc->lowvalue;
64
490M
  int shift;
65
66
490M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
490M
  range = split;
69
70
490M
  if (bit) {
71
46.6M
    lowvalue += split;
72
46.6M
    range = bc->range - split;
73
46.6M
  }
74
75
490M
  shift = vp8_norm[range];
76
77
490M
  range <<= shift;
78
490M
  count += shift;
79
80
490M
  if (count >= 0) {
81
18.8M
    int offset = shift - count;
82
83
18.8M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
867
      int x = bc->pos - 1;
85
86
1.20k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
335
        bc->buffer[x] = (unsigned char)0;
88
335
        x--;
89
335
      }
90
91
867
      bc->buffer[x] += 1;
92
867
    }
93
94
18.8M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
18.8M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
18.8M
    shift = count;
98
18.8M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
18.8M
    count -= 8;
100
18.8M
  }
101
102
490M
  lowvalue <<= shift;
103
490M
  bc->count = count;
104
490M
  bc->lowvalue = lowvalue;
105
490M
  bc->range = range;
106
490M
}
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
380M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
380M
  unsigned int split;
61
380M
  int count = bc->count;
62
380M
  unsigned int range = bc->range;
63
380M
  unsigned int lowvalue = bc->lowvalue;
64
380M
  int shift;
65
66
380M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
380M
  range = split;
69
70
380M
  if (bit) {
71
21.7M
    lowvalue += split;
72
21.7M
    range = bc->range - split;
73
21.7M
  }
74
75
380M
  shift = vp8_norm[range];
76
77
380M
  range <<= shift;
78
380M
  count += shift;
79
80
380M
  if (count >= 0) {
81
6.78M
    int offset = shift - count;
82
83
6.78M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
655
      int x = bc->pos - 1;
85
86
942
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
287
        bc->buffer[x] = (unsigned char)0;
88
287
        x--;
89
287
      }
90
91
655
      bc->buffer[x] += 1;
92
655
    }
93
94
6.78M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
6.78M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
6.78M
    shift = count;
98
6.78M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
6.78M
    count -= 8;
100
6.78M
  }
101
102
380M
  lowvalue <<= shift;
103
380M
  bc->count = count;
104
380M
  bc->lowvalue = lowvalue;
105
380M
  bc->range = range;
106
380M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
87.9M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
87.9M
  unsigned int split;
61
87.9M
  int count = bc->count;
62
87.9M
  unsigned int range = bc->range;
63
87.9M
  unsigned int lowvalue = bc->lowvalue;
64
87.9M
  int shift;
65
66
87.9M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
87.9M
  range = split;
69
70
87.9M
  if (bit) {
71
21.5M
    lowvalue += split;
72
21.5M
    range = bc->range - split;
73
21.5M
  }
74
75
87.9M
  shift = vp8_norm[range];
76
77
87.9M
  range <<= shift;
78
87.9M
  count += shift;
79
80
87.9M
  if (count >= 0) {
81
10.9M
    int offset = shift - count;
82
83
10.9M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
111
      int x = bc->pos - 1;
85
86
142
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
31
        bc->buffer[x] = (unsigned char)0;
88
31
        x--;
89
31
      }
90
91
111
      bc->buffer[x] += 1;
92
111
    }
93
94
10.9M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
10.9M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
10.9M
    shift = count;
98
10.9M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
10.9M
    count -= 8;
100
10.9M
  }
101
102
87.9M
  lowvalue <<= shift;
103
87.9M
  bc->count = count;
104
87.9M
  bc->lowvalue = lowvalue;
105
87.9M
  bc->range = range;
106
87.9M
}
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
21.8M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
21.8M
  unsigned int split;
61
21.8M
  int count = bc->count;
62
21.8M
  unsigned int range = bc->range;
63
21.8M
  unsigned int lowvalue = bc->lowvalue;
64
21.8M
  int shift;
65
66
21.8M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
21.8M
  range = split;
69
70
21.8M
  if (bit) {
71
3.36M
    lowvalue += split;
72
3.36M
    range = bc->range - split;
73
3.36M
  }
74
75
21.8M
  shift = vp8_norm[range];
76
77
21.8M
  range <<= shift;
78
21.8M
  count += shift;
79
80
21.8M
  if (count >= 0) {
81
1.11M
    int offset = shift - count;
82
83
1.11M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
101
      int x = bc->pos - 1;
85
86
118
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
17
        bc->buffer[x] = (unsigned char)0;
88
17
        x--;
89
17
      }
90
91
101
      bc->buffer[x] += 1;
92
101
    }
93
94
1.11M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
1.11M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
1.11M
    shift = count;
98
1.11M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
1.11M
    count -= 8;
100
1.11M
  }
101
102
21.8M
  lowvalue <<= shift;
103
21.8M
  bc->count = count;
104
21.8M
  bc->lowvalue = lowvalue;
105
21.8M
  bc->range = range;
106
21.8M
}
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_