耳朵闷闷的堵住的感觉是什么原因| 梦见自己掉河里了是什么意思| 屏幕发黄是什么原因| 健康是什么意思| 8月15日是什么星座| 忆字五行属什么| 2005属什么| 梦到水是什么意思| 山楂可以和什么一起泡水喝| 孕中期头疼是什么原因| 6月25日是什么星座| 晚上十点是什么时辰| 依非韦伦片治什么病的| 被电击后身体会有什么后遗症| 氨气是什么| 双鱼座有什么特点| 宫寒吃什么药调理最好| 汉高祖叫什么名字| 隐翅虫咬到擦什么药膏| 晕车吃什么能缓解| 婴儿补铁吃什么铁剂| 肾素低说明什么| 肝病晚期什么症状| 护士是干什么的| 宝宝睡觉头上出汗多是什么原因| 维生素吃多了有什么副作用| 空调长时间不用再开注意什么| 提高免疫力吃什么维生素| kb是什么| 安徽菜属于什么菜系| 双重否定句是什么意思| 肠炎吃什么药好的快| 蚁后长什么样| 什么时候同房最容易怀孕| 火龙果跟什么榨汁好喝| 女生吃什么补气血| 心衰的症状是什么| 甲流是什么病| 拉黑和删除有什么区别| 炁读什么| 脸上长痘是什么原因| 豪五行属什么| 天蝎座有什么特点| 胃气不通什么症状| 不知道为了什么| 吃芹菜有什么好处| 姜子牙是什么神仙| 97年五行属什么| 圆是什么结构| 经期适合什么运动| 高血压注意什么事项| 嗓子痛吃什么药| 三伏贴什么时候贴最好| 一个火一个宣念什么| 氧化性是什么意思| 血亏什么意思| 三秦是什么意思| 阴道骚痒是什么原因| 明天吃什么| 虾吃什么食物| 黄绿色是什么颜色| 什么叫便秘| 春什么秋什么| 失眠可以吃什么药| 乳腺增生应该注意些什么| 脚脱皮是什么原因| 早上嘴苦是什么原因| 做梦车丢了有什么预兆| 心脏疼是什么病| 梦见牛顶我是什么意思| 单丛属于什么茶| 什么时候敷面膜是最佳时间| 什么工作最赚钱| 麦芽糖是什么做的| 右手有痣代表什么| 天秤座的幸运色是什么| 男人吃鸽子有什么好处| 什么是肾虚| 八哥鸟吃什么饲料最好| 荨麻疹是什么| 回执单是什么意思| 眼睛干涩用什么药水| 鼻子和嘴巴连接的地方叫什么| 开心果为什么叫开心果| 盐酸氯米帕明片有什么作用| 喝铁观音茶有什么好处| 标新立异什么意思| 尿隐血1十是什么| 牡蛎和生蚝有什么区别| 一岁半打什么疫苗| 为什么不建议小孩吃罗红霉素| 头部mra是什么检查| v是什么化学元素| 莲子有什么作用| 平步青云什么意思| 失态是什么意思| 盆腔积液是什么意思| seiko是什么牌子| 咳嗽痰多吃什么药| 胆结石是什么症状| 什么水果去湿气效果最好| 竹叶青是什么茶| 杨枝甘露是什么意思| 尿酸高可以吃什么肉| 签发是什么意思| 耳朵里面疼用什么药| 什么食物对眼睛视力好| 梦到蛇是什么意思周公解梦| 头上长了个包挂什么科| 英语八级是什么水平| 古怪是什么意思| 轻度抑郁症吃什么药| 蒙字五行属什么| 剌是什么意思| 补充微量元素吃什么| 两三分钟就射什么原因| 无纺布是什么材料做的| 京东自营是什么意思| 落枕贴什么膏药| 道貌岸然是什么生肖| 舌头裂纹是什么病| 翡翠对人体有什么好处| 转氨酶高不能吃什么| 怀孕有什么感觉| 1990年是什么命| 胆囊壁增厚是什么意思| 金字旁的字和什么有关| 类胡萝卜素主要吸收什么光| 胃泌素瘤是什么意思| 天空什么的什么的| acg文化是什么意思| 宝宝喝什么奶粉好| 什么时间入伏| 例假为什么第一天最疼| 喝桑叶茶有什么好处| 乳头突然疼痛什么原因| 银鱼是什么鱼| cc代表什么意思| 十月30号是什么星座| 什么是洗钱| 呼吸胸口疼是什么原因| 捞佬是什么意思| 右耳朵发烫是什么征兆| 老是放臭屁是什么原因| 五联什么时候打| 心力衰竭吃什么药| 膝关节疼痛用什么药效果最好| vampire是什么意思| 微波炉加热用什么容器| 云州是现在的什么地方| 户籍地址是什么| 九品芝麻官是什么级别| 女性盆腔炎吃什么药| b超回声不均匀是什么意思| 营卫是什么意思| 吃什么降血脂| 出马什么意思| 坐月子可以吃什么蔬菜| 榴莲为什么会苦| 张卫健属什么生肖| 肝不好吃什么水果| 医院打耳洞挂什么科| 鸟在电线上为什么不会触电| 阳虚吃什么药| 祛湿吃什么食物| 补体c1q偏高说明什么| 虎头虎脑是什么生肖| 鱼翅是什么鱼身上的| 什么是山海经| 肠胃胀气吃什么药| 一根长寿眉预示什么| 1930年属什么生肖| blue是什么颜色| 上海最高楼叫什么大厦有多少米高| 猪蹄炖什么好吃| 养肝护肝吃什么药| 甲鱼跟什么炖最补| 家里进黄鼠狼是什么预兆| 7月初二是什么星座| 为什么老是肚子疼| 贞操是什么意思| 只是女人容易一往情深是什么歌| 朱迅和朱军是什么关系| 临字五行属什么| 胃左边疼是什么原因| 猪脆肠是什么器官| 手指缝痒是什么原因| 左侧卵巢内无回声是什么意思| 高血糖吃什么食物好| 什么叫耳石症| 喝酒后手麻是什么原因| 双相情感障碍吃什么药| 梦见掉了两颗牙齿是什么意思| 卧轨什么意思| 秋葵长什么样| 生二胎需要什么手续| 乙肝大三阳是什么意思| nt是什么货币| 急性上呼吸道感染是什么引起的| mews评分是什么意思| 尿血是什么原因女性| 排尿带血是什么原因| 痒痒粉在药店叫什么| 用字五行属什么| 16什么意思| 鼻子上长痘痘是什么原因| 什么人不能念阿弥陀佛| 软骨炎是什么病| 篦子是什么东西| 角膜炎吃什么消炎药| 肌肉一跳一跳什么原因| igm是什么| 猪巴皮是什么材质| 阴虱什么症状| 孑孓什么意思| 脾虚吃什么中成药| 怀孕第一天有什么症状| 锁骨上有痣代表什么| 筋膜炎吃什么药最有效| 夏季有什么花| 征兵什么时候开始| 破伤风伤口有什么症状| 小腹胀痛吃什么药| 什么是开光| 1943年属什么| 什么情况要做支气管镜| 药剂师是什么专业| 男性阴虱用什么药最好| 辰代表什么意思| 杏仁有什么功效| 禾加比读什么| 鲜花又什么又什么| 紧急避孕药有什么副作用| 舒张压偏高是什么原因造成的| 惯犯是什么意思| 冯字五行属什么| 产检建档需要什么资料| 体香是什么味道| 什么是岩茶| 丹参是什么样子的图片| 净身是什么| 吃b族维生素有什么好处| 体重下降是什么原因| 梦见灵堂是什么预兆| 什么是原发性高血压和继发性高血压| 戒备心是什么意思| 非经期少量出血是什么原因| 什么什么的眼睛| 棕色用什么颜色调出来| 什么是微信号| 节育环是什么| 脑血管痉挛是什么症状| 煤气是什么气体| 鼎字五行属什么| 黄帝叫什么名字| 体癣是什么原因引起的| 早搏吃什么药最管用| 二便是什么意思| 头发一把一把的掉是什么原因| 手掌发红是什么原因| 书字五行属什么的| 彩金和黄金有什么区别| 手肿是什么病的前兆| 一加一为什么等于二| 百度

hello中文是什么意思


Directory: ../../../ffmpeg/
File: src/libavcodec/rasc.c
Date: 2025-08-04 00:43:16
Exec Total Coverage
Lines: 0 472 0.0%
Functions: 0 15 0.0%
Branches: 0 300 0.0%

Line Branch Exec Source
1 /*
2 * RemotelyAnywhere Screen Capture decoder
3 *
4 * Copyright (c) 2018 Paul B Mahol
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 #include <stdio.h>
24 #include <string.h>
25
26 #include "libavutil/mem.h"
27 #include "libavutil/opt.h"
28
29 #include "avcodec.h"
30 #include "bytestream.h"
31 #include "codec_internal.h"
32 #include "decode.h"
33 #include "zlib_wrapper.h"
34
35 #include <zlib.h>
36
37 #define KBND MKTAG('K', 'B', 'N', 'D')
38 #define FINT MKTAG('F', 'I', 'N', 'T')
39 #define INIT MKTAG('I', 'N', 'I', 'T')
40 #define BNDL MKTAG('B', 'N', 'D', 'L')
41 #define KFRM MKTAG('K', 'F', 'R', 'M')
42 #define DLTA MKTAG('D', 'L', 'T', 'A')
43 #define MOUS MKTAG('M', 'O', 'U', 'S')
44 #define MPOS MKTAG('M', 'P', 'O', 'S')
45 #define MOVE MKTAG('M', 'O', 'V', 'E')
46 #define EMPT MKTAG('E', 'M', 'P', 'T')
47
48 typedef struct RASCContext {
49 AVClass *class;
50 int skip_cursor;
51 GetByteContext gb;
52 uint8_t *delta;
53 int delta_size;
54 uint8_t *cursor;
55 int cursor_size;
56 unsigned cursor_w;
57 unsigned cursor_h;
58 unsigned cursor_x;
59 unsigned cursor_y;
60 int stride;
61 int bpp;
62 AVFrame *frame;
63 AVFrame *frame1;
64 AVFrame *frame2;
65 FFZStream zstream;
66 } RASCContext;
67
68 static void clear_plane(AVCodecContext *avctx, AVFrame *frame)
69 {
70 RASCContext *s = avctx->priv_data;
71 uint8_t *dst = frame->data[0];
72
73 if (!dst)
74 return;
75
76 for (int y = 0; y < avctx->height; y++) {
77 memset(dst, 0, avctx->width * s->bpp);
78 dst += frame->linesize[0];
79 }
80 }
81
82 static void copy_plane(AVCodecContext *avctx, AVFrame *src, AVFrame *dst)
83 {
84 RASCContext *s = avctx->priv_data;
85 uint8_t *srcp = src->data[0];
86 uint8_t *dstp = dst->data[0];
87
88 for (int y = 0; y < avctx->height; y++) {
89 memcpy(dstp, srcp, s->stride);
90 srcp += src->linesize[0];
91 dstp += dst->linesize[0];
92 }
93 }
94
95 static int init_frames(AVCodecContext *avctx)
96 {
97 RASCContext *s = avctx->priv_data;
98 int ret;
99
100 av_frame_unref(s->frame1);
101 av_frame_unref(s->frame2);
102 if ((ret = ff_get_buffer(avctx, s->frame1, 0)) < 0)
103 return ret;
104
105 if ((ret = ff_get_buffer(avctx, s->frame2, 0)) < 0)
106 return ret;
107
108 clear_plane(avctx, s->frame2);
109 clear_plane(avctx, s->frame1);
110
111 return 0;
112 }
113
114 static int decode_fint(AVCodecContext *avctx,
115 const AVPacket *avpkt, unsigned size)
116 {
117 RASCContext *s = avctx->priv_data;
118 GetByteContext *gb = &s->gb;
119 unsigned w, h, fmt;
120 int ret;
121
122 if (bytestream2_peek_le32(gb) != 0x65) {
123 if (!s->frame2->data[0] || !s->frame1->data[0])
124 return AVERROR_INVALIDDATA;
125
126 clear_plane(avctx, s->frame2);
127 clear_plane(avctx, s->frame1);
128 return 0;
129 }
130 if (bytestream2_get_bytes_left(gb) < 72)
131 return AVERROR_INVALIDDATA;
132
133 bytestream2_skip(gb, 8);
134 w = bytestream2_get_le32(gb);
135 h = bytestream2_get_le32(gb);
136 bytestream2_skip(gb, 30);
137 fmt = bytestream2_get_le16(gb);
138 bytestream2_skip(gb, 24);
139
140 switch (fmt) {
141 case 8: s->stride = FFALIGN(w, 4);
142 s->bpp = 1;
143 fmt = AV_PIX_FMT_PAL8; break;
144 case 16: s->stride = w * 2;
145 s->bpp = 2;
146 fmt = AV_PIX_FMT_RGB555LE; break;
147 case 32: s->stride = w * 4;
148 s->bpp = 4;
149 fmt = AV_PIX_FMT_BGR0; break;
150 default: return AVERROR_INVALIDDATA;
151 }
152
153 ret = ff_set_dimensions(avctx, w, h);
154 if (ret < 0)
155 return ret;
156 avctx->width = w;
157 avctx->height = h;
158 avctx->pix_fmt = fmt;
159
160 ret = init_frames(avctx);
161 if (ret < 0)
162 return ret;
163
164 if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
165 uint32_t *pal = (uint32_t *)s->frame2->data[1];
166
167 for (int i = 0; i < 256; i++)
168 pal[i] = bytestream2_get_le32(gb) | 0xFF000000u;
169 }
170
171 return 0;
172 }
173
174 static int decode_zlib(AVCodecContext *avctx, const AVPacket *avpkt,
175 unsigned size, unsigned uncompressed_size)
176 {
177 RASCContext *s = avctx->priv_data;
178 z_stream *const zstream = &s->zstream.zstream;
179 GetByteContext *gb = &s->gb;
180 int zret;
181
182 zret = inflateReset(zstream);
183 if (zret != Z_OK) {
184 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
185 return AVERROR_EXTERNAL;
186 }
187
188 av_fast_padded_malloc(&s->delta, &s->delta_size, uncompressed_size);
189 if (!s->delta)
190 return AVERROR(ENOMEM);
191
192 zstream->next_in = avpkt->data + bytestream2_tell(gb);
193 zstream->avail_in = FFMIN(size, bytestream2_get_bytes_left(gb));
194
195 zstream->next_out = s->delta;
196 zstream->avail_out = s->delta_size;
197
198 zret = inflate(zstream, Z_FINISH);
199 if (zret != Z_STREAM_END) {
200 av_log(avctx, AV_LOG_ERROR,
201 "Inflate failed with return code: %d.\n", zret);
202 return AVERROR_INVALIDDATA;
203 }
204
205 return 0;
206 }
207
208 static int decode_move(AVCodecContext *avctx,
209 const AVPacket *avpkt, unsigned size)
210 {
211 RASCContext *s = avctx->priv_data;
212 GetByteContext *gb = &s->gb;
213 GetByteContext mc;
214 unsigned pos, compression, nb_moves;
215 unsigned uncompressed_size;
216 int ret;
217
218 pos = bytestream2_tell(gb);
219 bytestream2_skip(gb, 8);
220 nb_moves = bytestream2_get_le32(gb);
221 bytestream2_skip(gb, 8);
222 compression = bytestream2_get_le32(gb);
223
224 if (nb_moves > INT32_MAX / 16 || nb_moves > avctx->width * avctx->height)
225 return AVERROR_INVALIDDATA;
226
227 uncompressed_size = 16 * nb_moves;
228
229 if (compression == 1) {
230 ret = decode_zlib(avctx, avpkt,
231 size - (bytestream2_tell(gb) - pos),
232 uncompressed_size);
233 if (ret < 0)
234 return ret;
235 bytestream2_init(&mc, s->delta, uncompressed_size);
236 } else if (compression == 0) {
237 bytestream2_init(&mc, avpkt->data + bytestream2_tell(gb),
238 bytestream2_get_bytes_left(gb));
239 } else if (compression == 2) {
240 avpriv_request_sample(avctx, "compression %d", compression);
241 return AVERROR_PATCHWELCOME;
242 } else {
243 return AVERROR_INVALIDDATA;
244 }
245
246 if (bytestream2_get_bytes_left(&mc) < uncompressed_size)
247 return AVERROR_INVALIDDATA;
248
249 for (int i = 0; i < nb_moves; i++) {
250 int type, start_x, start_y, end_x, end_y, mov_x, mov_y;
251 uint8_t *e2, *b1, *b2;
252 int w, h;
253
254 type = bytestream2_get_le16(&mc);
255 start_x = bytestream2_get_le16(&mc);
256 start_y = bytestream2_get_le16(&mc);
257 end_x = bytestream2_get_le16(&mc);
258 end_y = bytestream2_get_le16(&mc);
259 mov_x = bytestream2_get_le16(&mc);
260 mov_y = bytestream2_get_le16(&mc);
261 bytestream2_skip(&mc, 2);
262
263 if (start_x >= avctx->width || start_y >= avctx->height ||
264 end_x >= avctx->width || end_y >= avctx->height ||
265 mov_x >= avctx->width || mov_y >= avctx->height) {
266 continue;
267 }
268
269 if (start_x >= end_x || start_y >= end_y)
270 continue;
271
272 w = end_x - start_x;
273 h = end_y - start_y;
274
275 if (mov_x + w > avctx->width || mov_y + h > avctx->height)
276 continue;
277
278 if (!s->frame2->data[0] || !s->frame1->data[0])
279 return AVERROR_INVALIDDATA;
280
281 b1 = s->frame1->data[0] + s->frame1->linesize[0] * (start_y + h - 1) + start_x * s->bpp;
282 b2 = s->frame2->data[0] + s->frame2->linesize[0] * (start_y + h - 1) + start_x * s->bpp;
283 e2 = s->frame2->data[0] + s->frame2->linesize[0] * (mov_y + h - 1) + mov_x * s->bpp;
284
285 if (type == 2) {
286 for (int j = 0; j < h; j++) {
287 memcpy(b1, b2, w * s->bpp);
288 b1 -= s->frame1->linesize[0];
289 b2 -= s->frame2->linesize[0];
290 }
291 } else if (type == 1) {
292 for (int j = 0; j < h; j++) {
293 memset(b2, 0, w * s->bpp);
294 b2 -= s->frame2->linesize[0];
295 }
296 } else if (type == 0) {
297 uint8_t *buffer;
298
299 av_fast_padded_malloc(&s->delta, &s->delta_size, w * h * s->bpp);
300 buffer = s->delta;
301 if (!buffer)
302 return AVERROR(ENOMEM);
303
304 for (int j = 0; j < h; j++) {
305 memcpy(buffer + j * w * s->bpp, e2, w * s->bpp);
306 e2 -= s->frame2->linesize[0];
307 }
308
309 for (int j = 0; j < h; j++) {
310 memcpy(b2, buffer + j * w * s->bpp, w * s->bpp);
311 b2 -= s->frame2->linesize[0];
312 }
313 } else {
314 return AVERROR_INVALIDDATA;
315 }
316 }
317
318 bytestream2_skip(gb, size - (bytestream2_tell(gb) - pos));
319
320 return 0;
321 }
322
323 #define NEXT_LINE \
324 if (cx >= w * s->bpp) { \
325 cx = 0; \
326 cy--; \
327 b1 -= s->frame1->linesize[0]; \
328 b2 -= s->frame2->linesize[0]; \
329 } \
330 len--;
331
332 static int decode_dlta(AVCodecContext *avctx,
333 const AVPacket *avpkt, unsigned size)
334 {
335 RASCContext *s = avctx->priv_data;
336 GetByteContext *gb = &s->gb;
337 GetByteContext dc;
338 unsigned uncompressed_size, pos;
339 unsigned x, y, w, h;
340 int ret, cx, cy, compression;
341 uint8_t *b1, *b2;
342
343 pos = bytestream2_tell(gb);
344 bytestream2_skip(gb, 12);
345 uncompressed_size = bytestream2_get_le32(gb);
346 x = bytestream2_get_le32(gb);
347 y = bytestream2_get_le32(gb);
348 w = bytestream2_get_le32(gb);
349 h = bytestream2_get_le32(gb);
350
351 if (x >= avctx->width || y >= avctx->height ||
352 w > avctx->width || h > avctx->height)
353 return AVERROR_INVALIDDATA;
354
355 if (x + w > avctx->width || y + h > avctx->height)
356 return AVERROR_INVALIDDATA;
357
358 bytestream2_skip(gb, 4);
359 compression = bytestream2_get_le32(gb);
360
361 if (compression == 1) {
362 if (w * h * s->bpp * 3 < uncompressed_size)
363 return AVERROR_INVALIDDATA;
364 ret = decode_zlib(avctx, avpkt, size, uncompressed_size);
365 if (ret < 0)
366 return ret;
367 bytestream2_init(&dc, s->delta, uncompressed_size);
368 } else if (compression == 0) {
369 if (bytestream2_get_bytes_left(gb) < uncompressed_size)
370 return AVERROR_INVALIDDATA;
371 bytestream2_init(&dc, avpkt->data + bytestream2_tell(gb),
372 uncompressed_size);
373 } else if (compression == 2) {
374 avpriv_request_sample(avctx, "compression %d", compression);
375 return AVERROR_PATCHWELCOME;
376 } else {
377 return AVERROR_INVALIDDATA;
378 }
379
380 if (!s->frame2->data[0] || !s->frame1->data[0])
381 return AVERROR_INVALIDDATA;
382
383 b1 = s->frame1->data[0] + s->frame1->linesize[0] * (int)(y + h - 1) + ((int)x) * s->bpp;
384 b2 = s->frame2->data[0] + s->frame2->linesize[0] * (int)(y + h - 1) + ((int)x) * s->bpp;
385 cx = 0, cy = h;
386 while (bytestream2_get_bytes_left(&dc) > 0) {
387 int type = bytestream2_get_byte(&dc);
388 int len = bytestream2_get_byte(&dc);
389 unsigned fill;
390
391 switch (type) {
392 case 1:
393 while (len > 0 && cy > 0) {
394 cx++;
395 NEXT_LINE
396 }
397 break;
398 case 2:
399 while (len > 0 && cy > 0) {
400 int v0 = b1[cx];
401 int v1 = b2[cx];
402
403 b2[cx] = v0;
404 b1[cx] = v1;
405 cx++;
406 NEXT_LINE
407 }
408 break;
409 case 3:
410 while (len > 0 && cy > 0) {
411 fill = bytestream2_get_byte(&dc);
412 b1[cx] = b2[cx];
413 b2[cx] = fill;
414 cx++;
415 NEXT_LINE
416 }
417 break;
418 case 4:
419 fill = bytestream2_get_byte(&dc);
420 while (len > 0 && cy > 0) {
421 AV_WL32(b1 + cx, AV_RL32(b2 + cx));
422 AV_WL32(b2 + cx, fill);
423 cx++;
424 NEXT_LINE
425 }
426 break;
427 case 7:
428 fill = bytestream2_get_le32(&dc);
429 while (len > 0 && cy > 0) {
430 AV_WL32(b1 + cx, AV_RL32(b2 + cx));
431 AV_WL32(b2 + cx, fill);
432 cx += 4;
433 NEXT_LINE
434 }
435 break;
436 case 10:
437 while (len > 0 && cy > 0) {
438 cx += 4;
439 NEXT_LINE
440 }
441 break;
442 case 12:
443 while (len > 0 && cy > 0) {
444 unsigned v0, v1;
445
446 v0 = AV_RL32(b2 + cx);
447 v1 = AV_RL32(b1 + cx);
448 AV_WL32(b2 + cx, v1);
449 AV_WL32(b1 + cx, v0);
450 cx += 4;
451 NEXT_LINE
452 }
453 break;
454 case 13:
455 while (len > 0 && cy > 0) {
456 fill = bytestream2_get_le32(&dc);
457 AV_WL32(b1 + cx, AV_RL32(b2 + cx));
458 AV_WL32(b2 + cx, fill);
459 cx += 4;
460 NEXT_LINE
461 }
462 break;
463 default:
464 avpriv_request_sample(avctx, "runlen %d", type);
465 return AVERROR_INVALIDDATA;
466 }
467 }
468
469 bytestream2_skip(gb, size - (bytestream2_tell(gb) - pos));
470
471 return 0;
472 }
473
474 static int decode_kfrm(AVCodecContext *avctx,
475 const AVPacket *avpkt, unsigned size)
476 {
477 RASCContext *s = avctx->priv_data;
478 z_stream *const zstream = &s->zstream.zstream;
479 GetByteContext *gb = &s->gb;
480 uint8_t *dst;
481 unsigned pos;
482 int zret, ret;
483
484 pos = bytestream2_tell(gb);
485 if (bytestream2_peek_le32(gb) == 0x65) {
486 ret = decode_fint(avctx, avpkt, size);
487 if (ret < 0)
488 return ret;
489 }
490
491 if (!s->frame2->data[0])
492 return AVERROR_INVALIDDATA;
493
494 zret = inflateReset(zstream);
495 if (zret != Z_OK) {
496 av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
497 return AVERROR_EXTERNAL;
498 }
499
500 zstream->next_in = avpkt->data + bytestream2_tell(gb);
501 zstream->avail_in = bytestream2_get_bytes_left(gb);
502
503 dst = s->frame2->data[0] + (avctx->height - 1) * s->frame2->linesize[0];
504 for (int i = 0; i < avctx->height; i++) {
505 zstream->next_out = dst;
506 zstream->avail_out = s->stride;
507
508 zret = inflate(zstream, Z_SYNC_FLUSH);
509 if (zret != Z_OK && zret != Z_STREAM_END) {
510 av_log(avctx, AV_LOG_ERROR,
511 "Inflate failed with return code: %d.\n", zret);
512 return AVERROR_INVALIDDATA;
513 }
514
515 dst -= s->frame2->linesize[0];
516 }
517
518 dst = s->frame1->data[0] + (avctx->height - 1) * s->frame1->linesize[0];
519 for (int i = 0; i < avctx->height; i++) {
520 zstream->next_out = dst;
521 zstream->avail_out = s->stride;
522
523 zret = inflate(zstream, Z_SYNC_FLUSH);
524 if (zret != Z_OK && zret != Z_STREAM_END) {
525 av_log(avctx, AV_LOG_ERROR,
526 "Inflate failed with return code: %d.\n", zret);
527 return AVERROR_INVALIDDATA;
528 }
529
530 dst -= s->frame1->linesize[0];
531 }
532
533 bytestream2_skip(gb, size - (bytestream2_tell(gb) - pos));
534
535 return 0;
536 }
537
538 static int decode_mous(AVCodecContext *avctx,
539 const AVPacket *avpkt, unsigned size)
540 {
541 RASCContext *s = avctx->priv_data;
542 GetByteContext *gb = &s->gb;
543 unsigned w, h, pos, uncompressed_size;
544 int ret;
545
546 pos = bytestream2_tell(gb);
547 bytestream2_skip(gb, 8);
548 w = bytestream2_get_le32(gb);
549 h = bytestream2_get_le32(gb);
550 bytestream2_skip(gb, 12);
551 uncompressed_size = bytestream2_get_le32(gb);
552
553 if (w > avctx->width || h > avctx->height)
554 return AVERROR_INVALIDDATA;
555
556 if (uncompressed_size != 3 * w * h)
557 return AVERROR_INVALIDDATA;
558
559 av_fast_padded_malloc(&s->cursor, &s->cursor_size, uncompressed_size);
560 if (!s->cursor)
561 return AVERROR(ENOMEM);
562
563 ret = decode_zlib(avctx, avpkt,
564 size - (bytestream2_tell(gb) - pos),
565 uncompressed_size);
566 if (ret < 0)
567 return ret;
568 memcpy(s->cursor, s->delta, uncompressed_size);
569
570 bytestream2_skip(gb, size - (bytestream2_tell(gb) - pos));
571
572 s->cursor_w = w;
573 s->cursor_h = h;
574
575 return 0;
576 }
577
578 static int decode_mpos(AVCodecContext *avctx,
579 const AVPacket *avpkt, unsigned size)
580 {
581 RASCContext *s = avctx->priv_data;
582 GetByteContext *gb = &s->gb;
583 unsigned pos;
584
585 pos = bytestream2_tell(gb);
586 bytestream2_skip(gb, 8);
587 s->cursor_x = bytestream2_get_le32(gb);
588 s->cursor_y = bytestream2_get_le32(gb);
589
590 bytestream2_skip(gb, size - (bytestream2_tell(gb) - pos));
591
592 return 0;
593 }
594
595 static void draw_cursor(AVCodecContext *avctx)
596 {
597 RASCContext *s = avctx->priv_data;
598 uint8_t *dst, *pal;
599
600 if (!s->cursor)
601 return;
602
603 if (s->cursor_x >= avctx->width || s->cursor_y >= avctx->height)
604 return;
605
606 if (s->cursor_x + s->cursor_w > avctx->width ||
607 s->cursor_y + s->cursor_h > avctx->height)
608 return;
609
610 if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
611 pal = s->frame->data[1];
612 for (int i = 0; i < s->cursor_h; i++) {
613 for (int j = 0; j < s->cursor_w; j++) {
614 int cr = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 0];
615 int cg = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 1];
616 int cb = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 2];
617 int best = INT_MAX;
618 int index = 0;
619 int dist;
620
621 if (cr == s->cursor[0] && cg == s->cursor[1] && cb == s->cursor[2])
622 continue;
623
624 dst = s->frame->data[0] + s->frame->linesize[0] * (int)(s->cursor_y + i) + (int)(s->cursor_x + j);
625 for (int k = 0; k < 256; k++) {
626 int pr = pal[k * 4 + 0];
627 int pg = pal[k * 4 + 1];
628 int pb = pal[k * 4 + 2];
629
630 dist = FFABS(cr - pr) + FFABS(cg - pg) + FFABS(cb - pb);
631 if (dist < best) {
632 best = dist;
633 index = k;
634 }
635 }
636 dst[0] = index;
637 }
638 }
639 } else if (avctx->pix_fmt == AV_PIX_FMT_RGB555LE) {
640 for (int i = 0; i < s->cursor_h; i++) {
641 for (int j = 0; j < s->cursor_w; j++) {
642 int cr = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 0];
643 int cg = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 1];
644 int cb = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 2];
645
646 if (cr == s->cursor[0] && cg == s->cursor[1] && cb == s->cursor[2])
647 continue;
648
649 cr >>= 3; cg >>=3; cb >>= 3;
650 dst = s->frame->data[0] + s->frame->linesize[0] * (int)(s->cursor_y + i) + 2 * (s->cursor_x + j);
651 AV_WL16(dst, cr | cg << 5 | cb << 10);
652 }
653 }
654 } else if (avctx->pix_fmt == AV_PIX_FMT_BGR0) {
655 for (int i = 0; i < s->cursor_h; i++) {
656 for (int j = 0; j < s->cursor_w; j++) {
657 int cr = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 0];
658 int cg = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 1];
659 int cb = s->cursor[3 * s->cursor_w * (s->cursor_h - i - 1) + 3 * j + 2];
660
661 if (cr == s->cursor[0] && cg == s->cursor[1] && cb == s->cursor[2])
662 continue;
663
664 dst = s->frame->data[0] + s->frame->linesize[0] * (int)(s->cursor_y + i) + 4 * (s->cursor_x + j);
665 dst[0] = cb;
666 dst[1] = cg;
667 dst[2] = cr;
668 }
669 }
670 }
671 }
672
673 static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
674 int *got_frame, AVPacket *avpkt)
675 {
676 RASCContext *s = avctx->priv_data;
677 GetByteContext *gb = &s->gb;
678 int ret, intra = 0;
679
680 bytestream2_init(gb, avpkt->data, avpkt->size);
681
682 if (bytestream2_peek_le32(gb) == EMPT)
683 return avpkt->size;
684
685 s->frame = frame;
686
687 while (bytestream2_get_bytes_left(gb) > 0) {
688 unsigned type, size = 0;
689
690 if (bytestream2_get_bytes_left(gb) < 8)
691 return AVERROR_INVALIDDATA;
692
693 type = bytestream2_get_le32(gb);
694 if (type == KBND || type == BNDL) {
695 intra = type == KBND;
696 type = bytestream2_get_le32(gb);
697 }
698
699 size = bytestream2_get_le32(gb);
700 if (bytestream2_get_bytes_left(gb) < size)
701 return AVERROR_INVALIDDATA;
702
703 switch (type) {
704 case FINT:
705 case INIT:
706 ret = decode_fint(avctx, avpkt, size);
707 break;
708 case KFRM:
709 ret = decode_kfrm(avctx, avpkt, size);
710 break;
711 case DLTA:
712 ret = decode_dlta(avctx, avpkt, size);
713 break;
714 case MOVE:
715 ret = decode_move(avctx, avpkt, size);
716 break;
717 case MOUS:
718 ret = decode_mous(avctx, avpkt, size);
719 break;
720 case MPOS:
721 ret = decode_mpos(avctx, avpkt, size);
722 break;
723 default:
724 bytestream2_skip(gb, size);
725 ret = 0;
726 }
727
728 if (ret < 0)
729 return ret;
730 }
731
732 if (!s->frame2->data[0] || !s->frame1->data[0])
733 return AVERROR_INVALIDDATA;
734
735 if ((ret = ff_get_buffer(avctx, s->frame, 0)) < 0)
736 return ret;
737
738 copy_plane(avctx, s->frame2, s->frame);
739 if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
740 memcpy(s->frame->data[1], s->frame2->data[1], 1024);
741 if (!s->skip_cursor)
742 draw_cursor(avctx);
743
744 if (intra)
745 s->frame->flags |= AV_FRAME_FLAG_KEY;
746 else
747 s->frame->flags &= ~AV_FRAME_FLAG_KEY;
748 s->frame->pict_type = intra ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
749
750 *got_frame = 1;
751
752 return avpkt->size;
753 }
754
755 static av_cold int decode_init(AVCodecContext *avctx)
756 {
757 RASCContext *s = avctx->priv_data;
758
759 s->frame1 = av_frame_alloc();
760 s->frame2 = av_frame_alloc();
761 if (!s->frame1 || !s->frame2)
762 return AVERROR(ENOMEM);
763
764 return ff_inflate_init(&s->zstream, avctx);
765 }
766
767 static av_cold int decode_close(AVCodecContext *avctx)
768 {
769 RASCContext *s = avctx->priv_data;
770
771 av_freep(&s->cursor);
772 s->cursor_size = 0;
773 av_freep(&s->delta);
774 s->delta_size = 0;
775 av_frame_free(&s->frame1);
776 av_frame_free(&s->frame2);
777 ff_inflate_end(&s->zstream);
778
779 return 0;
780 }
781
782 static av_cold void decode_flush(AVCodecContext *avctx)
783 {
784 RASCContext *s = avctx->priv_data;
785
786 clear_plane(avctx, s->frame1);
787 clear_plane(avctx, s->frame2);
788 }
789
790 static const AVOption options[] = {
791 { "skip_cursor", "skip the cursor", offsetof(RASCContext, skip_cursor), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
792 { NULL },
793 };
794
795 static const AVClass rasc_decoder_class = {
796 .class_name = "rasc decoder",
797 .item_name = av_default_item_name,
798 .option = options,
799 .version = LIBAVUTIL_VERSION_INT,
800 };
801
802 const FFCodec ff_rasc_decoder = {
803 .p.name = "rasc",
804 CODEC_LONG_NAME("RemotelyAnywhere Screen Capture"),
805 .p.type = AVMEDIA_TYPE_VIDEO,
806 .p.id = AV_CODEC_ID_RASC,
807 .priv_data_size = sizeof(RASCContext),
808 .init = decode_init,
809 .close = decode_close,
810 FF_CODEC_DECODE_CB(decode_frame),
811 .flush = decode_flush,
812 .p.capabilities = AV_CODEC_CAP_DR1,
813 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
814 .p.priv_class = &rasc_decoder_class,
815 };
816

吃樱桃有什么好处 gop是什么 心脏在乳房的什么位置 肝脏b超能检查出什么 属鸡与什么属相最配
湿疹不能吃什么 lancome是什么品牌 生气什么什么 头晕眼花吃什么药 你好是什么意思
述求是什么意思 心率高有什么危害 股骨头疼痛什么原因 黑便是什么原因 查激素水平挂什么科
尿肌酐低说明什么原因 fomo是什么意思 虾子不能和什么一起吃 金匮肾气丸治什么病 为什么会干呕
刑警队是干什么的hcv9jop5ns0r.cn mlb是什么牌子hcv7jop7ns2r.cn 阿里郎是什么意思hcv8jop8ns4r.cn 暑伏为什么要吃饺子hcv9jop5ns9r.cn 黑色素痣挂什么科hcv8jop0ns0r.cn
血粘度查什么项目hcv8jop7ns9r.cn 舌苔厚白腻是什么原因引起的hcv9jop2ns9r.cn 中耳炎去药店买什么药hcv7jop9ns9r.cn 蛋白尿吃什么食物好cj623037.com 脑白质变性什么意思hcv8jop2ns6r.cn
wl是什么意思hcv9jop3ns4r.cn les是什么意思chuanglingweilai.com 回执单是什么hcv8jop0ns8r.cn 信佛有什么好处hcv7jop6ns3r.cn 月经9天了还没干净是什么原因hcv7jop5ns3r.cn
四大美女指什么生肖hcv8jop0ns1r.cn 大便什么颜色是正常的hcv9jop7ns3r.cn 念想是什么意思0735v.com 无中生有是什么生肖hcv8jop6ns5r.cn cj什么意思hcv8jop1ns8r.cn
百度