Coverage Report

Created: 2025-08-28 07:12

/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
229M
                           struct vpx_internal_error_info *error) {
50
229M
  if (start + len > start && start + len < end) {
51
229M
    return 1;
52
229M
  } 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
229M
}
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
225M
                           struct vpx_internal_error_info *error) {
50
225M
  if (start + len > start && start + len < end) {
51
225M
    return 1;
52
225M
  } 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
225M
}
boolhuff.c:validate_buffer
Line
Count
Source
49
3.04M
                           struct vpx_internal_error_info *error) {
50
3.04M
  if (start + len > start && start + len < end) {
51
3.04M
    return 1;
52
3.04M
  } 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.04M
}
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
782k
                           struct vpx_internal_error_info *error) {
50
782k
  if (start + len > start && start + len < end) {
51
782k
    return 1;
52
782k
  } 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
782k
}
Unexecuted instantiation: firstpass.c:validate_buffer
Unexecuted instantiation: mcomp.c:validate_buffer
Unexecuted instantiation: modecosts.c:validate_buffer
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
39.6M
    lowvalue += split;
72
39.6M
    range = bc->range - split;
73
39.6M
  }
74
75
175M
  shift = vp8_norm[range];
76
77
175M
  range <<= shift;
78
175M
  count += shift;
79
80
175M
  if (count >= 0) {
81
10.6M
    int offset = shift - count;
82
83
10.6M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
887
      int x = bc->pos - 1;
85
86
3.66k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.77k
        bc->buffer[x] = (unsigned char)0;
88
2.77k
        x--;
89
2.77k
      }
90
91
887
      bc->buffer[x] += 1;
92
887
    }
93
94
10.6M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
10.6M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
10.6M
    shift = count;
98
10.6M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
10.6M
    count -= 8;
100
10.6M
  }
101
102
175M
  lowvalue <<= shift;
103
175M
  bc->count = count;
104
175M
  bc->lowvalue = lowvalue;
105
175M
  bc->range = range;
106
175M
}
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
138M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
138M
  unsigned int split;
61
138M
  int count = bc->count;
62
138M
  unsigned int range = bc->range;
63
138M
  unsigned int lowvalue = bc->lowvalue;
64
138M
  int shift;
65
66
138M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
138M
  range = split;
69
70
138M
  if (bit) {
71
28.1M
    lowvalue += split;
72
28.1M
    range = bc->range - split;
73
28.1M
  }
74
75
138M
  shift = vp8_norm[range];
76
77
138M
  range <<= shift;
78
138M
  count += shift;
79
80
138M
  if (count >= 0) {
81
6.80M
    int offset = shift - count;
82
83
6.80M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
813
      int x = bc->pos - 1;
85
86
3.36k
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
2.55k
        bc->buffer[x] = (unsigned char)0;
88
2.55k
        x--;
89
2.55k
      }
90
91
813
      bc->buffer[x] += 1;
92
813
    }
93
94
6.80M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
6.80M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
6.80M
    shift = count;
98
6.80M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
6.80M
    count -= 8;
100
6.80M
  }
101
102
138M
  lowvalue <<= shift;
103
138M
  bc->count = count;
104
138M
  bc->lowvalue = lowvalue;
105
138M
  bc->range = range;
106
138M
}
boolhuff.c:vp8_encode_bool
Line
Count
Source
59
26.2M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
26.2M
  unsigned int split;
61
26.2M
  int count = bc->count;
62
26.2M
  unsigned int range = bc->range;
63
26.2M
  unsigned int lowvalue = bc->lowvalue;
64
26.2M
  int shift;
65
66
26.2M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
26.2M
  range = split;
69
70
26.2M
  if (bit) {
71
8.69M
    lowvalue += split;
72
8.69M
    range = bc->range - split;
73
8.69M
  }
74
75
26.2M
  shift = vp8_norm[range];
76
77
26.2M
  range <<= shift;
78
26.2M
  count += shift;
79
80
26.2M
  if (count >= 0) {
81
3.04M
    int offset = shift - count;
82
83
3.04M
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
13
      int x = bc->pos - 1;
85
86
25
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
12
        bc->buffer[x] = (unsigned char)0;
88
12
        x--;
89
12
      }
90
91
13
      bc->buffer[x] += 1;
92
13
    }
93
94
3.04M
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
3.04M
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
3.04M
    shift = count;
98
3.04M
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
3.04M
    count -= 8;
100
3.04M
  }
101
102
26.2M
  lowvalue <<= shift;
103
26.2M
  bc->count = count;
104
26.2M
  bc->lowvalue = lowvalue;
105
26.2M
  bc->range = range;
106
26.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
11.1M
static void vp8_encode_bool(BOOL_CODER *bc, int bit, int probability) {
60
11.1M
  unsigned int split;
61
11.1M
  int count = bc->count;
62
11.1M
  unsigned int range = bc->range;
63
11.1M
  unsigned int lowvalue = bc->lowvalue;
64
11.1M
  int shift;
65
66
11.1M
  split = 1 + (((range - 1) * probability) >> 8);
67
68
11.1M
  range = split;
69
70
11.1M
  if (bit) {
71
2.81M
    lowvalue += split;
72
2.81M
    range = bc->range - split;
73
2.81M
  }
74
75
11.1M
  shift = vp8_norm[range];
76
77
11.1M
  range <<= shift;
78
11.1M
  count += shift;
79
80
11.1M
  if (count >= 0) {
81
782k
    int offset = shift - count;
82
83
782k
    if ((lowvalue << (offset - 1)) & 0x80000000) {
84
61
      int x = bc->pos - 1;
85
86
270
      while (x >= 0 && bc->buffer[x] == 0xff) {
87
209
        bc->buffer[x] = (unsigned char)0;
88
209
        x--;
89
209
      }
90
91
61
      bc->buffer[x] += 1;
92
61
    }
93
94
782k
    validate_buffer(bc->buffer + bc->pos, 1, bc->buffer_end, bc->error);
95
782k
    bc->buffer[bc->pos++] = (lowvalue >> (24 - offset) & 0xff);
96
97
782k
    shift = count;
98
782k
    lowvalue = (int)(((uint64_t)lowvalue << offset) & 0xffffff);
99
782k
    count -= 8;
100
782k
  }
101
102
11.1M
  lowvalue <<= shift;
103
11.1M
  bc->count = count;
104
11.1M
  bc->lowvalue = lowvalue;
105
11.1M
  bc->range = range;
106
11.1M
}
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_