月经推迟一个月不来什么原因| 摘胆对身体有什么影响| 感染科主要看什么病| 冰释前嫌是什么意思| 10月21日什么星座| 三十六计最后一计是什么| 10.28什么星座| 心肌炎是什么症状| 弟弟的儿子叫什么| 虫草有什么作用与功效| ipv是什么| cin是什么意思| 嘴唇肿了是什么原因| 饶舌是什么意思| dw是什么| 飞黄腾达是什么生肖| 11月15日什么星座| x射线是什么| 梦见梯子是什么意思| 非浅表性胃炎是什么意思| 蚕蛹吃什么| 拔牙后吃什么消炎药| 睡觉头晕是什么原因引起的| 你的书包里有什么英文| 什么是个性| 荆芥俗名叫什么| 男性hpv检查挂什么科| 身份证后六位代表什么| 258什么意思| 黛力新是什么药| 9月初是什么星座| 什么是中性洗涤剂| 什么烟好抽又便宜| 慢性萎缩性胃炎是什么意思| 女性得了性病有什么症状| 三伏天什么时候最热| 骨外科是看什么病的| 槟榔肝是由什么引起的| 眼睛皮痒是什么原因| 大象吃什么食物| 炁怎么读什么意思| 早餐做什么简单又好吃| 淘宝预售是什么意思| 吹箫是什么意思| 超负荷是什么意思| 什么牛什么毛| 看胃病挂什么科| 喝什么汤下奶最快最多| 金庸的原名叫什么| 薄如蝉翼是什么意思| 白血球高是什么原因| 女人手心热吃什么药好| 黄体什么意思| 什么是躯体化| 无锡有什么好玩的| 火字旁跟什么有关| 缠头是什么意思| 类风湿是什么原因引起的| 乐捐是什么意思| 虎和什么属相不合| 印枭是什么意思| 藕粉不能和什么一起吃| 物以类聚是什么意思| 驾驶证扣6分有什么影响| 九九年属什么| 希特勒为什么自杀| 来月经腰酸腰痛什么原因造成的| 就此别过是什么意思| 手足是什么意思| 百合有什么功效| 杨桃什么味道| 什么动物吃猫| 门良念什么| 开车撞死猫有什么预兆| 为什么不能叫醒梦游的人| 肠胃炎吃什么药好得快| 168红包代表什么意思| 宫颈柱状上皮异位是什么意思| 胃溃疡有什么症状| 药品经营与管理学什么| 晚上睡觉脚抽搐是什么原因| 血红蛋白浓度偏低是什么原因| 什么是灌肠| 大腿抽筋是什么原因| 糖类抗原是什么| 六字真言是什么意思| 暑假什么时候放| 鼻子肿了又硬又疼是什么原因| 农历七月初七俗称什么| 宜祭祀是什么意思| 土鳖是什么意思| 建设性意见是什么意思| 好哒是什么意思| 什么是癌胚抗原| 男人山根有痣代表什么| 硬核是什么意思| 蚕豆病不能吃什么| 阴道细菌感染用什么药| 什么主食含糖量低| 月经血量少是什么原因| 可卡因是什么| 滴水不漏什么意思| 腿脚肿胀是什么原因引起的| 办慢性病有什么好处| 大林木命忌讳什么颜色| 哭笑不得是什么意思| 离婚需要什么| hpv是什么原因引起的| 一个木一个舌读什么| 内向男生适合什么工作| 汽化是什么意思| pedro是什么牌子| 白粥配什么菜好吃| 血脂高有什么症状表现| 属龙的守护神是什么菩萨| 马赫是什么意思| 胃寒吃什么中成药| 打耳洞不能吃什么| 胰腺在人体起什么作用| 自言自语的近义词是什么| 嫩模是什么意思| mmf是什么药| 拉肚子吃什么药最好| 金鱼藻属于什么植物| 空谷幽兰下一句是什么| 两个水念什么| upup是什么意思| 药流前需要做什么检查| 马蜂泡酒有什么功效| sparkling是什么意思| 澳门是什么时候回归的| 黄山四绝指的是什么| 2037年是什么年| 什么的豆角| 什么胃病需要做手术| 咳嗽吃什么食物好得最快最有效| 陶土色大便是什么颜色| 毛周角化症是什么原因引起的| 脑袋痛什么原因| 剖腹产什么时候可以洗澡| 同房出血要做什么检查| 看灰指甲去医院挂什么科| 开化龙顶属于什么茶| 胸闷气短是什么症状| 狗狗生产需要准备什么| 橱柜用什么材料好| 鹅口疮用什么药效果好| 归元寺求什么最灵验| 腿抽筋吃什么药最好| 毫无意义是什么意思| 血脂高不能吃什么| 黄体不足吃什么补最快| 艾字五行属什么| 乳头为什么会内陷| 地铁什么时候停运| 什么寒什么暖| 医药代表是做什么的| 肠胃不好经常拉肚子吃什么药| 6.27什么星座| 医院医务科是干什么的| 女性吃辅酶q10有什么好处| 脸色暗沉发黑什么原因| 男性吃什么增强性功能| 樱桃有什么营养价值| 下山虎是什么意思| 初中属于什么专业| 梦见血是什么意思| 1120是什么星座| 居酒屋是什么意思| 儿童咳嗽挂什么科| 晋是什么意思| 什么食物增加血管弹性| 产后恶露是什么| PSV是什么意思| 胀气是什么症状| 植物神经紊乱吃什么中成药| 女人细菌感染什么原因引起的| 有机蔬菜是什么意思| 西康省是现在什么地方| 甲醛超标有什么反应| 什么星座最花心| o2o是什么意思| 日斤读什么字| 97年属什么今年多大| 东吴是现在的什么地方| 体育生能报什么专业| angry是什么意思| 一个女一个以念什么| 侍中是什么官| 小便憋不住尿裤子是什么情况| 晚上肚子疼是什么原因| 蝉的幼虫叫什么| 不排便是什么原因| 被电击后身体会有什么后遗症| 夏天吃什么水果最好| 5月份出生的是什么星座| 95年属什么的| 血糖高喝什么好| 什么是包茎| 食禄是什么意思| 年收入10万什么水平| 同房后小腹疼痛是什么原因| 吃狗肉有什么危害| 开宠物医院需要什么条件| 色弱和色盲有什么区别| 吃什么能快速降血压| 冰火两重天是什么意思| 建字五行属什么| 扁桃体肥大是什么原因造成的| 脑电图是检查什么的| 干眼症吃什么药| 婚检都查什么| mg是什么元素| 自然卷的头发适合什么发型| 宫外孕出血是什么颜色| 帝王是什么意思| 男人吃四环素治什么病| ih医学上是什么意思| 1977属什么生肖| 皮肤过敏涂什么药膏| 磨砂膏有什么作用| 男生为什么喜欢摸胸| 有什么好听的名字| 梦见狐狸是什么预兆| 老是饿是什么原因| 吃了发芽的土豆会有什么症状| 巨蟹座有什么特点| md是什么意思| 夏字五行属什么| 炸东西用什么淀粉| 妇科假丝酵母菌是什么病| 糖尿病喝什么茶| 吃阿莫西林过敏有什么症状| 买什么样的老花镜好| 特工是什么意思| 喝酒为什么会吐| 133是什么意思| 跖疣是什么原因引起的| rich什么意思| mac是什么意思啊| 火气重喝什么茶| 什么水果是降火的| 朱砂有什么用| 三月24号是什么星座的| 闲鱼卖出的东西钱什么时候到账| 血糖高的人可以吃什么水果| 甲状腺吃什么食物好| ala是什么氨基酸| 左手麻木是什么原因引起的| 宫颈纳氏囊肿是什么意思| 反式脂肪酸是什么意思| 牛角尖是什么意思| 灰指甲长什么样子图片| epa和dha是什么| 1月22日是什么星座| 12月8号是什么星座| 遥字五行属什么| 耳朵痛用什么药| 禁忌什么意思| 睡觉趴着睡什么原因| 什么人不能吃皮蛋| 庆帝为什么杀叶轻眉| instagram是什么软件| 客家人为什么叫客家人| 百度

揭露运营商小秘密,你是不是办了一个“假宽带”?


Directory: ../../../ffmpeg/
File: src/libavcodec/jpeglsdec.c
Date: 2025-08-04 11:35:17
Exec Total Coverage
Lines: 206 314 65.6%
Functions: 5 5 100.0%
Branches: 141 244 57.8%

Line Branch Exec Source
1 /*
2 * JPEG-LS decoder
3 * Copyright (c) 2003 Michael Niedermayer
4 * Copyright (c) 2006 Konstantin Shishkov
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * JPEG-LS decoder.
26 */
27
28 #include "libavutil/mem.h"
29 #include "avcodec.h"
30 #include "codec_internal.h"
31 #include "get_bits.h"
32 #include "golomb.h"
33 #include "mathops.h"
34 #include "mjpegdec.h"
35 #include "jpegls.h"
36 #include "jpeglsdec.h"
37
38 /*
39 * Uncomment this to significantly speed up decoding of broken JPEG-LS
40 * (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit.
41 *
42 * There is no Golomb code with length >= 32 bits possible, so check and
43 * avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow
44 * on this errors.
45 */
46 //#define JLS_BROKEN
47
48 /**
49 * Decode LSE block with initialization parameters
50 */
51 16 int ff_jpegls_decode_lse(MJpegDecodeContext *s)
52 {
53 int id;
54 int tid, wt, maxtab, i, j;
55
56 16 int len = get_bits(&s->gb, 16);
57 16 id = get_bits(&s->gb, 8);
58
59
1/5
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
16 switch (id) {
60 case 1:
61 if (len < 13)
62 return AVERROR_INVALIDDATA;
63
64 s->maxval = get_bits(&s->gb, 16);
65 s->t1 = get_bits(&s->gb, 16);
66 s->t2 = get_bits(&s->gb, 16);
67 s->t3 = get_bits(&s->gb, 16);
68 s->reset = get_bits(&s->gb, 16);
69
70 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
71 av_log(s->avctx, AV_LOG_DEBUG, "Coding parameters maxval:%d T1:%d T2:%d T3:%d reset:%d\n",
72 s->maxval, s->t1, s->t2, s->t3, s->reset);
73 }
74
75 // ff_jpegls_reset_coding_parameters(s, 0);
76 //FIXME quant table?
77 break;
78 16 case 2:
79 16 s->palette_index = 0;
80 16 case 3:
81 16 tid= get_bits(&s->gb, 8);
82 16 wt = get_bits(&s->gb, 8);
83
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (len < 5)
85 return AVERROR_INVALIDDATA;
86
87
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
16 if (wt < 1 || wt > MAX_COMPONENTS) {
88 avpriv_request_sample(s->avctx, "wt %d", wt);
89 return AVERROR_PATCHWELCOME;
90 }
91
92
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if (!s->maxval)
93 16 maxtab = 255;
94 else if ((5 + wt*(s->maxval+1)) < 65535)
95 maxtab = s->maxval;
96 else
97 maxtab = 65530/wt - 1;
98
99
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
100 av_log(s->avctx, AV_LOG_DEBUG, "LSE palette %d tid:%d wt:%d maxtab:%d\n", id, tid, wt, maxtab);
101 }
102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (maxtab >= 256) {
103 avpriv_request_sample(s->avctx, ">8bit palette");
104 return AVERROR_PATCHWELCOME;
105 }
106 16 maxtab = FFMIN(maxtab, (len - 5) / wt + s->palette_index);
107
108
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (s->palette_index > maxtab)
109 return AVERROR_INVALIDDATA;
110
111
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
16 if ((s->avctx->pix_fmt == AV_PIX_FMT_GRAY8 || s->avctx->pix_fmt == AV_PIX_FMT_PAL8) &&
112
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
16 (s->picture_ptr->format == AV_PIX_FMT_GRAY8 || s->picture_ptr->format == AV_PIX_FMT_PAL8)) {
113 16 uint32_t *pal = (uint32_t *)s->picture_ptr->data[1];
114 16 int shift = 0;
115
116
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 if (s->avctx->bits_per_raw_sample > 0 && s->avctx->bits_per_raw_sample < 8) {
117
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 maxtab = FFMIN(maxtab, (1<<s->avctx->bits_per_raw_sample)-1);
118 16 shift = 8 - s->avctx->bits_per_raw_sample;
119 }
120
121 16 s->force_pal8++;
122
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (!pal) {
123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (s->force_pal8 > 1)
124 return AVERROR_INVALIDDATA;
125 8 return 1;
126 }
127
128
2/2
✓ Branch 0 taken 344 times.
✓ Branch 1 taken 8 times.
352 for (i=s->palette_index; i<=maxtab; i++) {
129 344 uint8_t k = i << shift;
130
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 pal[k] = wt < 4 ? 0xFF000000 : 0;
131
2/2
✓ Branch 0 taken 1032 times.
✓ Branch 1 taken 344 times.
1376 for (j=0; j<wt; j++) {
132 1032 pal[k] |= get_bits(&s->gb, 8) << (8*(wt-j-1));
133 }
134 }
135 8 s->palette_index = i;
136 }
137 8 break;
138 case 4:
139 avpriv_request_sample(s->avctx, "oversize image");
140 return AVERROR(ENOSYS);
141 default:
142 av_log(s->avctx, AV_LOG_ERROR, "invalid id %d\n", id);
143 return AVERROR_INVALIDDATA;
144 }
145 ff_dlog(s->avctx, "ID=%i, T=%i,%i,%i\n", id, s->t1, s->t2, s->t3);
146
147 8 return 0;
148 }
149
150 /**
151 * Get context-dependent Golomb code, decode it and update context
152 */
153 46507616 static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q)
154 {
155 int k, ret;
156
157
2/2
✓ Branch 0 taken 120390394 times.
✓ Branch 1 taken 46507616 times.
166898010 for (k = 0; ((unsigned)state->N[Q] << k) < state->A[Q]; k++)
158 ;
159
160 #ifdef JLS_BROKEN
161 if (!show_bits_long(gb, 32))
162 return -1;
163 #endif
164 46507616 ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp);
165
166 /* decode mapped error */
167
2/2
✓ Branch 0 taken 23829574 times.
✓ Branch 1 taken 22678042 times.
46507616 if (ret & 1)
168 23829574 ret = -(ret + 1 >> 1);
169 else
170 22678042 ret >>= 1;
171
172 /* for NEAR=0, k=0 and 2*B[Q] <= - N[Q] mapping is reversed */
173
5/6
✓ Branch 0 taken 46507616 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2699029 times.
✓ Branch 3 taken 43808587 times.
✓ Branch 4 taken 840496 times.
✓ Branch 5 taken 1858533 times.
46507616 if (!state->near && !k && (2 * state->B[Q] <= -state->N[Q]))
174 840496 ret = -(ret + 1);
175
176 46507616 ret = ff_jpegls_update_state_regular(state, Q, ret);
177
178 46507616 return ret;
179 }
180
181 /**
182 * Get Golomb code, decode it and update state for run termination
183 */
184 783661 static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state,
185 int RItype, int limit_add)
186 {
187 int k, ret, temp, map;
188 783661 int Q = 365 + RItype;
189
190 783661 temp = state->A[Q];
191
2/2
✓ Branch 0 taken 509232 times.
✓ Branch 1 taken 274429 times.
783661 if (RItype)
192 509232 temp += state->N[Q] >> 1;
193
194
2/2
✓ Branch 0 taken 1884419 times.
✓ Branch 1 taken 783661 times.
2668080 for (k = 0; ((unsigned)state->N[Q] << k) < temp; k++)
195 ;
196
197 #ifdef JLS_BROKEN
198 if (!show_bits_long(gb, 32))
199 return -1;
200 #endif
201 783661 ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1,
202 state->qbpp);
203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 783661 times.
783661 if (ret < 0)
204 return -0x10000;
205
206 /* decode mapped error */
207 783661 map = 0;
208
8/8
✓ Branch 0 taken 153938 times.
✓ Branch 1 taken 629723 times.
✓ Branch 2 taken 26894 times.
✓ Branch 3 taken 127044 times.
✓ Branch 4 taken 2304 times.
✓ Branch 5 taken 24590 times.
✓ Branch 6 taken 60548 times.
✓ Branch 7 taken 68800 times.
783661 if (!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q]))
209 60548 map = 1;
210 783661 ret += RItype + map;
211
212
2/2
✓ Branch 0 taken 351896 times.
✓ Branch 1 taken 431765 times.
783661 if (ret & 1) {
213 351896 ret = map - (ret + 1 >> 1);
214 351896 state->B[Q]++;
215 } else {
216 431765 ret = ret >> 1;
217 }
218
219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 783661 times.
783661 if (FFABS(ret) > 0xFFFF)
220 return -0x10000;
221 /* update state */
222 783661 state->A[Q] += FFABS(ret) - RItype;
223 783661 ret *= state->twonear;
224 783661 ff_jpegls_downscale_state(state, Q);
225
226 783661 return ret;
227 }
228
229 /**
230 * Decode one line of image
231 */
232 143946 static inline int ls_decode_line(JLSState *state, MJpegDecodeContext *s,
233 void *last, void *dst, int last2, int w,
234 int stride, int comp, int bits)
235 {
236 143946 int i, x = 0;
237 int Ra, Rb, Rc, Rd;
238 int D0, D1, D2;
239
240
2/2
✓ Branch 0 taken 47299272 times.
✓ Branch 1 taken 135951 times.
47435223 while (x < w) {
241 int err, pred;
242
243
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 47299272 times.
47299272 if (get_bits_left(&s->gb) <= 0)
244 return AVERROR_INVALIDDATA;
245
246 /* compute gradients */
247
4/6
✓ Branch 0 taken 47155326 times.
✓ Branch 1 taken 143946 times.
✓ Branch 2 taken 47155326 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 143946 times.
✗ Branch 5 not taken.
47299272 Ra = x ? R(dst, x - stride) : R(last, x);
248
1/2
✓ Branch 0 taken 47299272 times.
✗ Branch 1 not taken.
47299272 Rb = R(last, x);
249
3/4
✓ Branch 0 taken 47155326 times.
✓ Branch 1 taken 143946 times.
✓ Branch 2 taken 47155326 times.
✗ Branch 3 not taken.
47299272 Rc = x ? R(last, x - stride) : last2;
250
4/6
✓ Branch 0 taken 136999 times.
✓ Branch 1 taken 47162273 times.
✓ Branch 2 taken 136999 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 47162273 times.
✗ Branch 5 not taken.
47299272 Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride);
251 47299272 D0 = Rd - Rb;
252 47299272 D1 = Rb - Rc;
253 47299272 D2 = Rc - Ra;
254 /* run mode */
255
2/2
✓ Branch 0 taken 5800192 times.
✓ Branch 1 taken 41499080 times.
47299272 if ((FFABS(D0) <= state->near) &&
256
2/2
✓ Branch 0 taken 2188180 times.
✓ Branch 1 taken 3612012 times.
5800192 (FFABS(D1) <= state->near) &&
257
2/2
✓ Branch 0 taken 791656 times.
✓ Branch 1 taken 1396524 times.
2971841 (FFABS(D2) <= state->near)) {
258 int r;
259 int RItype;
260
261 /* decode full runs while available */
262
2/2
✓ Branch 1 taken 737915 times.
✓ Branch 2 taken 783661 times.
1521576 while (get_bits1(&s->gb)) {
263 int r;
264 737915 r = 1 << ff_log2_run[state->run_index[comp]];
265
2/2
✓ Branch 0 taken 6338 times.
✓ Branch 1 taken 731577 times.
737915 if (x + r * stride > w)
266 6338 r = (w - x) / stride;
267
2/2
✓ Branch 0 taken 2755018 times.
✓ Branch 1 taken 737915 times.
3492933 for (i = 0; i < r; i++) {
268
1/2
✓ Branch 0 taken 2755018 times.
✗ Branch 1 not taken.
2755018 W(dst, x, Ra);
269 2755018 x += stride;
270 }
271 /* if EOL reached, we stop decoding */
272
2/2
✓ Branch 0 taken 6338 times.
✓ Branch 1 taken 731577 times.
737915 if (r != 1 << ff_log2_run[state->run_index[comp]])
273 6338 return 0;
274
1/2
✓ Branch 0 taken 731577 times.
✗ Branch 1 not taken.
731577 if (state->run_index[comp] < 31)
275 731577 state->run_index[comp]++;
276
2/2
✓ Branch 0 taken 1657 times.
✓ Branch 1 taken 729920 times.
731577 if (x + stride > w)
277 1657 return 0;
278 }
279 /* decode aborted run */
280 783661 r = ff_log2_run[state->run_index[comp]];
281
2/2
✓ Branch 0 taken 647235 times.
✓ Branch 1 taken 136426 times.
783661 if (r)
282 647235 r = get_bits(&s->gb, r);
283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 783661 times.
783661 if (x + r * stride > w) {
284 r = (w - x) / stride;
285 }
286
2/2
✓ Branch 0 taken 1010453 times.
✓ Branch 1 taken 783661 times.
1794114 for (i = 0; i < r; i++) {
287
1/2
✓ Branch 0 taken 1010453 times.
✗ Branch 1 not taken.
1010453 W(dst, x, Ra);
288 1010453 x += stride;
289 }
290
291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 783661 times.
783661 if (x >= w) {
292 av_log(NULL, AV_LOG_ERROR, "run overflow\n");
293 av_assert0(x <= w);
294 return AVERROR_INVALIDDATA;
295 }
296
297 /* decode run termination value */
298
1/2
✓ Branch 0 taken 783661 times.
✗ Branch 1 not taken.
783661 Rb = R(last, x);
299 783661 RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0;
300 783661 err = ls_get_code_runterm(&s->gb, state, RItype,
301 783661 ff_log2_run[state->run_index[comp]]);
302
2/2
✓ Branch 0 taken 729428 times.
✓ Branch 1 taken 54233 times.
783661 if (state->run_index[comp])
303 729428 state->run_index[comp]--;
304
305
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 783661 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
783661 if (state->near && RItype) {
306 pred = Ra + err;
307 } else {
308
2/2
✓ Branch 0 taken 170007 times.
✓ Branch 1 taken 613654 times.
783661 if (Rb < Ra)
309 170007 pred = Rb - err;
310 else
311 613654 pred = Rb + err;
312 }
313 } else { /* regular mode */
314 int context, sign;
315
316 46507616 context = ff_jpegls_quantize(state, D0) * 81 +
317 46507616 ff_jpegls_quantize(state, D1) * 9 +
318 46507616 ff_jpegls_quantize(state, D2);
319 46507616 pred = mid_pred(Ra, Ra + Rb - Rc, Rb);
320
321
2/2
✓ Branch 0 taken 19034217 times.
✓ Branch 1 taken 27473399 times.
46507616 if (context < 0) {
322 19034217 context = -context;
323 19034217 sign = 1;
324 } else {
325 27473399 sign = 0;
326 }
327
328
2/2
✓ Branch 0 taken 19034217 times.
✓ Branch 1 taken 27473399 times.
46507616 if (sign) {
329 19034217 pred = av_clip(pred - state->C[context], 0, state->maxval);
330 19034217 err = -ls_get_code_regular(&s->gb, state, context);
331 } else {
332 27473399 pred = av_clip(pred + state->C[context], 0, state->maxval);
333 27473399 err = ls_get_code_regular(&s->gb, state, context);
334 }
335
336 /* we have to do something more for near-lossless coding */
337 46507616 pred += err;
338 }
339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47291277 times.
47291277 if (state->near) {
340 if (pred < -state->near)
341 pred += state->range * state->twonear;
342 else if (pred > state->maxval + state->near)
343 pred -= state->range * state->twonear;
344 pred = av_clip(pred, 0, state->maxval);
345 }
346
347 47291277 pred &= state->maxval;
348
1/2
✓ Branch 0 taken 47291277 times.
✗ Branch 1 not taken.
47291277 W(dst, x, pred);
349 47291277 x += stride;
350 }
351
352 135951 return 0;
353 }
354
355 213 int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near,
356 int point_transform, int ilv)
357 {
358 213 int i, t = 0;
359 uint8_t *zero, *last, *cur;
360 213 JLSState *state = s->jls_state;
361 213 int off = 0, stride = 1, width, shift, ret = 0;
362 213 int decoded_height = 0;
363
364
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 196 times.
213 if (!state) {
365 17 state = av_malloc(sizeof(*state));
366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if (!state)
367 return AVERROR(ENOMEM);
368 17 s->jls_state = state;
369 }
370 213 zero = av_mallocz(s->picture_ptr->linesize[0]);
371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 213 times.
213 if (!zero)
372 return AVERROR(ENOMEM);
373 213 last = zero;
374 213 cur = s->picture_ptr->data[0];
375
376 /* initialize JPEG-LS state from JPEG parameters */
377 213 memset(state, 0, sizeof(*state));
378 213 state->near = near;
379 213 state->bpp = (s->bits < 2) ? 2 : s->bits;
380 213 state->maxval = s->maxval;
381 213 state->T1 = s->t1;
382 213 state->T2 = s->t2;
383 213 state->T3 = s->t3;
384 213 state->reset = s->reset;
385 213 ff_jpegls_reset_coding_parameters(state, 0);
386
387 /* Testing parameters here, we cannot test in LSE or SOF because
388 * these interdepend and are allowed in either order
389 */
390
1/2
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
213 if (state->maxval >= (1<<state->bpp) ||
391
1/2
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
213 state->T1 > state->T2 ||
392
1/2
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
213 state->T2 > state->T3 ||
393
1/2
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
213 state->T3 > state->maxval ||
394
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 213 times.
213 state->reset > FFMAX(255, state->maxval)) {
395 ret = AVERROR_INVALIDDATA;
396 goto end;
397 }
398
399 213 ff_jpegls_init_state(state);
400
401
1/2
✓ Branch 0 taken 213 times.
✗ Branch 1 not taken.
213 if (s->bits <= 8)
402 213 shift = point_transform + (8 - s->bits);
403 else
404 shift = point_transform + (16 - s->bits);
405
406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 213 times.
213 if (shift >= 16) {
407 ret = AVERROR_INVALIDDATA;
408 goto end;
409 }
410
411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 213 times.
213 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
412 av_log(s->avctx, AV_LOG_DEBUG,
413 "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) "
414 "RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",
415 s->width, s->height, state->near, state->maxval,
416 state->T1, state->T2, state->T3,
417 state->reset, state->limit, state->qbpp, state->range);
418 av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n",
419 ilv, point_transform, s->bits, s->cur_scan);
420 }
421
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 213 times.
213 if (get_bits_left(&s->gb) < s->height) {
422 ret = AVERROR_INVALIDDATA;
423 goto end;
424 }
425
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 205 times.
213 if (ilv == 0) { /* separate planes */
426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (s->cur_scan > s->nb_components) {
427 ret = AVERROR_INVALIDDATA;
428 goto end;
429 }
430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 stride = (s->nb_components > 1) ? 3 : 1;
431 8 off = av_clip(s->cur_scan - 1, 0, stride - 1);
432 8 width = s->width * stride;
433 8 cur += off;
434
2/2
✓ Branch 0 taken 5688 times.
✓ Branch 1 taken 8 times.
5696 for (i = 0; i < s->height; i++) {
435 int ret;
436
1/2
✓ Branch 0 taken 5688 times.
✗ Branch 1 not taken.
5688 if (s->bits <= 8) {
437 5688 ret = ls_decode_line(state, s, last, cur, t, width, stride, off, 8);
438 5688 t = last[0];
439 } else {
440 ret = ls_decode_line(state, s, last, cur, t, width, stride, off, 16);
441 t = *((uint16_t *)last);
442 }
443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5688 times.
5688 if (ret < 0)
444 break;
445 5688 last = cur;
446 5688 cur += s->picture_ptr->linesize[0];
447
448
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5688 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5688 if (s->restart_interval && !--s->restart_count) {
449 align_get_bits(&s->gb);
450 skip_bits(&s->gb, 16); /* skip RSTn */
451 }
452 }
453 8 decoded_height = i;
454
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 } else if (ilv == 1) { /* line interleaving */
455 int j;
456 205 int Rc[3] = { 0, 0, 0 };
457
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 stride = (s->nb_components > 1) ? 3 : 1;
458 205 memset(cur, 0, s->picture_ptr->linesize[0]);
459 205 width = s->width * stride;
460
2/2
✓ Branch 0 taken 46086 times.
✓ Branch 1 taken 205 times.
46291 for (i = 0; i < s->height; i++) {
461 int ret;
462
2/2
✓ Branch 0 taken 138258 times.
✓ Branch 1 taken 46086 times.
184344 for (j = 0; j < stride; j++) {
463 138258 ret = ls_decode_line(state, s, last + j, cur + j,
464 Rc[j], width, stride, j, 8);
465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138258 times.
138258 if (ret < 0)
466 break;
467 138258 Rc[j] = last[j];
468
469
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 138258 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
138258 if (s->restart_interval && !--s->restart_count) {
470 align_get_bits(&s->gb);
471 skip_bits(&s->gb, 16); /* skip RSTn */
472 }
473 }
474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46086 times.
46086 if (ret < 0)
475 break;
476 46086 last = cur;
477 46086 cur += s->picture_ptr->linesize[0];
478 }
479 205 decoded_height = i;
480 } else if (ilv == 2) { /* sample interleaving */
481 avpriv_report_missing_feature(s->avctx, "Sample interleaved images");
482 ret = AVERROR_PATCHWELCOME;
483 goto end;
484 } else { /* unknown interleaving */
485 avpriv_report_missing_feature(s->avctx, "Unknown interleaved images");
486 ret = AVERROR_PATCHWELCOME;
487 goto end;
488 }
489
490
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 213 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
213 if (s->xfrm && s->nb_components == 3) {
491 int x, w;
492
493 w = s->width * s->nb_components;
494
495 if (s->bits <= 8) {
496 uint8_t *src = s->picture_ptr->data[0];
497
498 for (i = 0; i < s->height; i++) {
499 switch(s->xfrm) {
500 case 1:
501 for (x = off; x + 2 < w; x += 3) {
502 src[x ] += src[x+1] + 128;
503 src[x+2] += src[x+1] + 128;
504 }
505 break;
506 case 2:
507 for (x = off; x + 2 < w; x += 3) {
508 src[x ] += src[x+1] + 128;
509 src[x+2] += ((src[x ] + src[x+1])>>1) + 128;
510 }
511 break;
512 case 3:
513 for (x = off; x + 2 < w; x += 3) {
514 int g = src[x+0] - ((src[x+2]+src[x+1])>>2) + 64;
515 src[x+0] = src[x+2] + g + 128;
516 src[x+2] = src[x+1] + g + 128;
517 src[x+1] = g;
518 }
519 break;
520 case 4:
521 for (x = off; x + 2 < w; x += 3) {
522 int r = src[x+0] - (( 359 * (src[x+2]-128) + 490) >> 8);
523 int g = src[x+0] - (( 88 * (src[x+1]-128) - 183 * (src[x+2]-128) + 30) >> 8);
524 int b = src[x+0] + ((454 * (src[x+1]-128) + 574) >> 8);
525 src[x+0] = av_clip_uint8(r);
526 src[x+1] = av_clip_uint8(g);
527 src[x+2] = av_clip_uint8(b);
528 }
529 break;
530 }
531 src += s->picture_ptr->linesize[0];
532 }
533 }else
534 avpriv_report_missing_feature(s->avctx, "16bit xfrm");
535 }
536
537
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 8 times.
213 if (shift) { /* we need to do point transform or normalize samples */
538 int x, w;
539
540 8 w = s->width * s->nb_components;
541
542
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (s->bits <= 8) {
543 8 uint8_t *src = s->picture_ptr->data[0];
544
545
2/2
✓ Branch 0 taken 5688 times.
✓ Branch 1 taken 8 times.
5696 for (i = 0; i < decoded_height; i++) {
546
2/2
✓ Branch 0 taken 4044168 times.
✓ Branch 1 taken 5688 times.
4049856 for (x = off; x < w; x += stride)
547 4044168 src[x] <<= shift;
548 5688 src += s->picture_ptr->linesize[0];
549 }
550 } else {
551 uint16_t *src = (uint16_t *)s->picture_ptr->data[0];
552
553 for (i = 0; i < decoded_height; i++) {
554 for (x = 0; x < w; x++)
555 src[x] <<= shift;
556 src += s->picture_ptr->linesize[0] / 2;
557 }
558 }
559 }
560
561 205 end:
562 213 av_free(zero);
563
564 213 return ret;
565 }
566
567 const FFCodec ff_jpegls_decoder = {
568 .p.name = "jpegls",
569 CODEC_LONG_NAME("JPEG-LS"),
570 .p.type = AVMEDIA_TYPE_VIDEO,
571 .p.id = AV_CODEC_ID_JPEGLS,
572 .priv_data_size = sizeof(MJpegDecodeContext),
573 .init = ff_mjpeg_decode_init,
574 .close = ff_mjpeg_decode_end,
575 FF_CODEC_DECODE_CB(ff_mjpeg_decode_frame),
576 .p.capabilities = AV_CODEC_CAP_DR1,
577 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
578 };
579

石钟乳是什么 夜来非是什么意思 为什么一直下雨 刘备代表什么生肖 就藩什么意思
男人吃蚂蚱有什么好处 孩子脾胃虚弱吃什么药 什么是意象 胃窦糜烂是什么意思严重吗 七叶一枝花主治什么病
血管炎是什么症状 安娜苏香水什么档次 免冠照片是什么意思 口水臭是什么原因引起的 爱的本质是什么
体检前一天晚上吃什么 农历7月25日是什么星座 刚怀孕吃什么对胎儿好 三级护理是什么意思 人红是非多什么意思
peaches是什么意思hcv8jop3ns5r.cn brat什么意思hcv8jop4ns2r.cn 得不到的永远在骚动什么意思hcv8jop3ns7r.cn courvoisier是什么酒hcv9jop5ns9r.cn 左眼一直跳有什么预兆hcv8jop4ns2r.cn
果冻是什么做的hcv8jop2ns9r.cn 开店做什么生意好hcv9jop5ns2r.cn 煤油是什么油hcv8jop1ns0r.cn 录取通知书是什么生肖hcv9jop8ns1r.cn y是什么意思hcv8jop3ns0r.cn
射精出血吃什么药最好hcv9jop2ns2r.cn 吸入甲醛会有什么症状hcv8jop6ns8r.cn 蚂蟥是什么naasee.com 落花生是什么意思qingzhougame.com 比特币是什么意思hcv7jop6ns4r.cn
杨柳代表什么生肖mmeoe.com 血小板偏低有什么危害hcv8jop9ns5r.cn 耳石症吃什么药hcv8jop2ns3r.cn 一吃就吐是什么病症hcv8jop0ns5r.cn 我的手机是什么型号hcv7jop5ns0r.cn
百度