FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mqcenc.c
Date: 2024-04-25 15:36:26
Exec Total Coverage
Lines: 75 75 100.0%
Functions: 7 7 100.0%
Branches: 23 24 95.8%

Line Branch Exec Source
1 /*
2 * MQ-coder encoder
3 * Copyright (c) 2007 Kamil Nowosad
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * MQ-coder encoder
24 * @file
25 * @author Kamil Nowosad
26 */
27
28 #include <string.h>
29
30 #include "libavutil/avassert.h"
31 #include "mqc.h"
32
33 204356704 static void byteout(MqcState *mqc)
34 {
35 210500716 retry:
36
2/2
✓ Branch 0 taken 1458491 times.
✓ Branch 1 taken 209042225 times.
210500716 if (*mqc->bp == 0xff){
37 1458491 mqc->bp++;
38 1458491 *mqc->bp = mqc->c >> 20;
39 1458491 mqc->c &= 0xfffff;
40 1458491 mqc->ct = 7;
41
2/2
✓ Branch 0 taken 6144012 times.
✓ Branch 1 taken 202898213 times.
209042225 } else if ((mqc->c & 0x8000000)){
42 6144012 (*mqc->bp)++;
43 6144012 mqc->c &= 0x7ffffff;
44 6144012 goto retry;
45 } else{
46 202898213 mqc->bp++;
47 202898213 *mqc->bp = mqc->c >> 19;
48 202898213 mqc->c &= 0x7ffff;
49 202898213 mqc->ct = 8;
50 }
51 204356704 }
52
53 1005151614 static void renorme(MqcState *mqc)
54 {
55 do{
56 1294456361 mqc->a += mqc->a;
57 1294456361 mqc->c += mqc->c;
58
2/2
✓ Branch 0 taken 161112506 times.
✓ Branch 1 taken 1133343855 times.
1294456361 if (!--mqc->ct)
59 161112506 byteout(mqc);
60
2/2
✓ Branch 0 taken 289304747 times.
✓ Branch 1 taken 1005151614 times.
1294456361 } while (!(mqc->a & 0x8000));
61 1005151614 }
62
63 21622099 static void setbits(MqcState *mqc)
64 {
65 21622099 int tmp = mqc->c + mqc->a;
66 21622099 mqc->c |= 0xffff;
67
2/2
✓ Branch 0 taken 6048907 times.
✓ Branch 1 taken 15573192 times.
21622099 if (mqc->c >= tmp)
68 6048907 mqc->c -= 0x8000;
69 21622099 }
70
71 895700 void ff_mqc_initenc(MqcState *mqc, uint8_t *bp)
72 {
73 895700 ff_mqc_init_contexts(mqc);
74 895700 mqc->a = 0x8000;
75 895700 mqc->c = 0;
76 895700 mqc->bp = bp-1;
77 895700 mqc->bpstart = bp;
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 895700 times.
895700 mqc->ct = 12 + (*mqc->bp == 0xff);
79 895700 }
80
81 1533831004 void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d)
82 {
83 int qe;
84
85 1533831004 qe = ff_mqc_qe[*cxstate];
86 1533831004 mqc->a -= qe;
87
2/2
✓ Branch 0 taken 1005445185 times.
✓ Branch 1 taken 528385819 times.
1533831004 if ((*cxstate & 1) == d){
88
2/2
✓ Branch 0 taken 476765795 times.
✓ Branch 1 taken 528679390 times.
1005445185 if (!(mqc->a & 0x8000)){
89
2/2
✓ Branch 0 taken 137128679 times.
✓ Branch 1 taken 339637116 times.
476765795 if (mqc->a < qe)
90 137128679 mqc->a = qe;
91 else
92 339637116 mqc->c += qe;
93 476765795 *cxstate = ff_mqc_nmps[*cxstate];
94 476765795 renorme(mqc);
95 } else
96 528679390 mqc->c += qe;
97 } else{
98
2/2
✓ Branch 0 taken 126038102 times.
✓ Branch 1 taken 402347717 times.
528385819 if (mqc->a < qe)
99 126038102 mqc->c += qe;
100 else
101 402347717 mqc->a = qe;
102 528385819 *cxstate = ff_mqc_nlps[*cxstate];
103 528385819 renorme(mqc);
104 }
105 1533831004 }
106
107 21622099 static int mqc_flush(MqcState *mqc)
108 {
109 21622099 setbits(mqc);
110 21622099 mqc->c = mqc->c << mqc->ct;
111 21622099 byteout(mqc);
112 21622099 mqc->c = mqc->c << mqc->ct;
113 21622099 byteout(mqc);
114
2/2
✓ Branch 0 taken 5253366 times.
✓ Branch 1 taken 16368733 times.
21622099 if (*mqc->bp != 0xff)
115 5253366 mqc->bp++;
116 21622099 return mqc->bp - mqc->bpstart;
117 }
118
119 21622099 int ff_mqc_flush_to(MqcState *mqc, uint8_t *dst, int *dst_len)
120 {
121 21622099 MqcState mqc2 = *mqc;
122 21622099 mqc2.bpstart=
123 21622099 mqc2.bp = dst;
124 21622099 *mqc2.bp = *mqc->bp;
125 21622099 mqc_flush(&mqc2);
126 21622099 *dst_len = mqc2.bp - dst;
127
2/2
✓ Branch 0 taken 164862 times.
✓ Branch 1 taken 21457237 times.
21622099 if (mqc->bp < mqc->bpstart) {
128 av_assert1(mqc->bpstart - mqc->bp == 1);
129 av_assert1(*dst_len > 0);
130 av_assert1(mqc->bp[0] == 0 && dst[0] == 0);
131 164862 (*dst_len) --;
132 164862 memmove(dst, dst+1, *dst_len);
133 164862 return mqc->bp - mqc->bpstart + 1 + *dst_len;
134 }
135 21457237 return mqc->bp - mqc->bpstart + *dst_len;
136 }
137