Coverage Report

Created: 2026-04-01 07:42

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
266M
                           struct vpx_internal_error_info *error) {
50
266M
  if (start + len > start && start + len < end) {
51
266M
    return 1;
52
266M
  } 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
266M
}
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
261M
                           struct vpx_internal_error_info *error) {
50
261M
  if (start + len > start && start + len < end) {
51
261M
    return 1;
52
261M
  } 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
261M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
3.45M
                           struct vpx_internal_error_info *error) {
50
3.45M
  if (start + len > start && start + len < end) {
51
3.45M
    return 1;
52
3.45M
  } 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.45M
}
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
219M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
219M
  unsigned int split;
61
219M
  int count = bc->count;
62
219M
  unsigned int range = bc->range;
63
219M
  unsigned int lowvalue = bc->lowvalue;
64
219M
  int shift;
65
66
219M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
219M
  range = split;
69
70
219M
  if (bit) {
71
42.4M
    lowvalue += split;
72
42.4M
    range = bc->range - split;
73
42.4M
  }
74
75
219M
  shift = vp8_norm[range];
76
77
219M
  range <<= shift;
78
219M
  count += shift;
79
80
219M
  if (count >= 0) {
81
11.6M
    int offset = shift - count;
82
83
11.6M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
741
      int x = bc->pos - 1;
85
86
3.64k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.90k
        bc->buffer[x] = (unsigned char)0;
88
2.90k
        x--;
89
2.90k
      }
90
91
741
      bc->buffer[x] += 1;
92
741
    }
93
94
11.6M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
11.6M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
11.6M
    shift = count;
98
11.6M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
11.6M
    count -= 8;
100
11.6M
  }
101
102
219M
  lowvalue <<= shift;
103
219M
  bc->count = count;
104
219M
  bc->lowvalue = lowvalue;
105
219M
  bc->range = range;
106
219M
}
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
175M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
175M
  unsigned int split;
61
175M
  int count = bc->count;
62
175M
  unsigned int range = bc->range;
63
175M
  unsigned int lowvalue = bc->lowvalue;
64
175M
  int shift;
65
66
175M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
175M
  range = split;
69
70
175M
  if (bit) {
71
29.7M
    lowvalue += split;
72
29.7M
    range = bc->range - split;
73
29.7M
  }
74
75
175M
  shift = vp8_norm[range];
76
77
175M
  range <<= shift;
78
175M
  count += shift;
79
80
175M
  if (count >= 0) {
81
7.26M
    int offset = shift - count;
82
83
7.26M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
684
      int x = bc->pos - 1;
85
86
3.35k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.67k
        bc->buffer[x] = (unsigned char)0;
88
2.67k
        x--;
89
2.67k
      }
90
91
684
      bc->buffer[x] += 1;
92
684
    }
93
94
7.26M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
7.26M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
7.26M
    shift = count;
98
7.26M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
7.26M
    count -= 8;
100
7.26M
  }
101
102
175M
  lowvalue <<= shift;
103
175M
  bc->count = count;
104
175M
  bc->lowvalue = lowvalue;
105
175M
  bc->range = range;
106
175M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
30.4M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
30.4M
  unsigned int split;
61
30.4M
  int count = bc->count;
62
30.4M
  unsigned int range = bc->range;
63
30.4M
  unsigned int lowvalue = bc->lowvalue;
64
30.4M
  int shift;
65
66
30.4M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
30.4M
  range = split;
69
70
30.4M
  if (bit) {
71
9.48M
    lowvalue += split;
72
9.48M
    range = bc->range - split;
73
9.48M
  }
74
75
30.4M
  shift = vp8_norm[range];
76
77
30.4M
  range <<= shift;
78
30.4M
  count += shift;
79
80
30.4M
  if (count >= 0) {
81
3.45M
    int offset = shift - count;
82
83
3.45M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
9
      int x = bc->pos - 1;
85
86
28
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
19
        bc->buffer[x] = (unsigned char)0;
88
19
        x--;
89
19
      }
90
91
9
      bc->buffer[x] += 1;
92
9
    }
93
94
3.45M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
3.45M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
3.45M
    shift = count;
98
3.45M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
3.45M
    count -= 8;
100
3.45M
  }
101
102
30.4M
  lowvalue <<= shift;
103
30.4M
  bc->count = count;
104
30.4M
  bc->lowvalue = lowvalue;
105
30.4M
  bc->range = range;
106
30.4M
}
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.5M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
13.5M
  unsigned int split;
61
13.5M
  int count = bc->count;
62
13.5M
  unsigned int range = bc->range;
63
13.5M
  unsigned int lowvalue = bc->lowvalue;
64
13.5M
  int shift;
65
66
13.5M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
13.5M
  range = split;
69
70
13.5M
  if (bit) {
71
3.22M
    lowvalue += split;
72
3.22M
    range = bc->range - split;
73
3.22M
  }
74
75
13.5M
  shift = vp8_norm[range];
76
77
13.5M
  range <<= shift;
78
13.5M
  count += shift;
79
80
13.5M
  if (count >= 0) {
81
904k
    int offset = shift - count;
82
83
904k
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
48
      int x = bc->pos - 1;
85
86
261
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
213
        bc->buffer[x] = (unsigned char)0;
88
213
        x--;
89
213
      }
90
91
48
      bc->buffer[x] += 1;
92
48
    }
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.5M
  lowvalue <<= shift;
103
13.5M
  bc->count = count;
104
13.5M
  bc->lowvalue = lowvalue;
105
13.5M
  bc->range = range;
106
13.5M
}
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_