Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小白菜888
Ffmpeg
提交
7e9e2b55
F
Ffmpeg
项目概览
小白菜888
/
Ffmpeg
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
Ffmpeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7e9e2b55
编写于
7月 12, 2003
作者:
M
Michael Niedermayer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleanup
Originally committed as revision 2038 to
svn://svn.ffmpeg.org/ffmpeg/trunk
上级
5b9d235f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
238 addition
and
213 deletion
+238
-213
libavcodec/mjpeg.c
libavcodec/mjpeg.c
+238
-213
未找到文件。
libavcodec/mjpeg.c
浏览文件 @
7e9e2b55
...
...
@@ -821,10 +821,17 @@ typedef struct MJpegDecodeContext {
int
bits
;
/* bits per component */
int
width
,
height
;
int
mb_width
,
mb_height
;
int
nb_components
;
int
component_id
[
MAX_COMPONENTS
];
int
h_count
[
MAX_COMPONENTS
];
/* horizontal and vertical count for each component */
int
v_count
[
MAX_COMPONENTS
];
int
comp_index
[
MAX_COMPONENTS
];
int
dc_index
[
MAX_COMPONENTS
];
int
ac_index
[
MAX_COMPONENTS
];
int
nb_blocks
[
MAX_COMPONENTS
];
int
h_scount
[
MAX_COMPONENTS
];
int
v_scount
[
MAX_COMPONENTS
];
int
h_max
,
v_max
;
/* maximum h and v counts */
int
quant_index
[
4
];
/* quant table index for each component */
int
last_dc
[
MAX_COMPONENTS
];
/* last DEQUANTIZED dc (XXX: am I right to do that ?) */
...
...
@@ -1155,104 +1162,8 @@ static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
return
0
;
}
static
int
mjpeg_decode_sos
(
MJpegDecodeContext
*
s
)
{
int
len
,
nb_components
,
i
,
j
,
n
,
h
,
v
,
ret
,
point_transform
,
predictor
;
int
mb_width
,
mb_height
,
mb_x
,
mb_y
,
vmax
,
hmax
,
index
,
id
;
int
comp_index
[
4
];
int
dc_index
[
4
];
int
ac_index
[
4
];
int
nb_blocks
[
4
];
int
h_count
[
4
];
int
v_count
[
4
];
const
int
block_size
=
s
->
lossless
?
1
:
8
;
/* XXX: verify len field validity */
len
=
get_bits
(
&
s
->
gb
,
16
);
nb_components
=
get_bits
(
&
s
->
gb
,
8
);
if
(
len
!=
6
+
2
*
nb_components
)
{
dprintf
(
"decode_sos: invalid len (%d)
\n
"
,
len
);
return
-
1
;
}
/* XXX: only interleaved scan accepted */
if
(
nb_components
!=
3
)
{
dprintf
(
"decode_sos: components(%d) mismatch
\n
"
,
nb_components
);
return
-
1
;
}
vmax
=
0
;
hmax
=
0
;
for
(
i
=
0
;
i
<
nb_components
;
i
++
)
{
id
=
get_bits
(
&
s
->
gb
,
8
)
-
1
;
dprintf
(
"component: %d
\n
"
,
id
);
/* find component index */
for
(
index
=
0
;
index
<
s
->
nb_components
;
index
++
)
if
(
id
==
s
->
component_id
[
index
])
break
;
if
(
index
==
s
->
nb_components
)
{
dprintf
(
"decode_sos: index(%d) out of components
\n
"
,
index
);
return
-
1
;
}
comp_index
[
i
]
=
index
;
nb_blocks
[
i
]
=
s
->
h_count
[
index
]
*
s
->
v_count
[
index
];
h_count
[
i
]
=
s
->
h_count
[
index
];
v_count
[
i
]
=
s
->
v_count
[
index
];
dc_index
[
i
]
=
get_bits
(
&
s
->
gb
,
4
);
ac_index
[
i
]
=
get_bits
(
&
s
->
gb
,
4
);
if
(
dc_index
[
i
]
<
0
||
ac_index
[
i
]
<
0
||
dc_index
[
i
]
>=
4
||
ac_index
[
i
]
>=
4
)
goto
out_of_range
;
switch
(
s
->
start_code
)
{
case
SOF0
:
if
(
dc_index
[
i
]
>
1
||
ac_index
[
i
]
>
1
)
goto
out_of_range
;
break
;
case
SOF1
:
case
SOF2
:
if
(
dc_index
[
i
]
>
3
||
ac_index
[
i
]
>
3
)
goto
out_of_range
;
break
;
case
SOF3
:
if
(
dc_index
[
i
]
>
3
||
ac_index
[
i
]
!=
0
)
goto
out_of_range
;
break
;
}
}
predictor
=
get_bits
(
&
s
->
gb
,
8
);
/* lossless predictor or start of spectral (Ss) */
skip_bits
(
&
s
->
gb
,
8
);
/* Se */
skip_bits
(
&
s
->
gb
,
4
);
/* Ah */
point_transform
=
get_bits
(
&
s
->
gb
,
4
);
/* Al */
for
(
i
=
0
;
i
<
nb_components
;
i
++
)
s
->
last_dc
[
i
]
=
1024
;
if
(
nb_components
>
1
)
{
/* interleaved stream */
mb_width
=
(
s
->
width
+
s
->
h_max
*
block_size
-
1
)
/
(
s
->
h_max
*
block_size
);
mb_height
=
(
s
->
height
+
s
->
v_max
*
block_size
-
1
)
/
(
s
->
v_max
*
block_size
);
}
else
{
h
=
s
->
h_max
/
s
->
h_count
[
comp_index
[
0
]];
v
=
s
->
v_max
/
s
->
v_count
[
comp_index
[
0
]];
mb_width
=
(
s
->
width
+
h
*
block_size
-
1
)
/
(
h
*
block_size
);
mb_height
=
(
s
->
height
+
v
*
block_size
-
1
)
/
(
v
*
block_size
);
nb_blocks
[
0
]
=
1
;
h_count
[
0
]
=
1
;
v_count
[
0
]
=
1
;
}
if
(
s
->
avctx
->
debug
&
FF_DEBUG_PICT_INFO
)
printf
(
"%s %s p:%d >>:%d
\n
"
,
s
->
lossless
?
"lossless"
:
"sequencial DCT"
,
s
->
rgb
?
"RGB"
:
""
,
predictor
,
point_transform
);
if
(
s
->
lossless
){
if
(
s
->
rgb
){
static
int
ljpeg_decode_rgb_scan
(
MJpegDecodeContext
*
s
,
int
predictor
,
int
point_transform
){
int
i
,
mb_x
,
mb_y
;
uint16_t
buffer
[
2048
][
4
];
int
left
[
3
],
top
[
3
],
topleft
[
3
];
const
int
linesize
=
s
->
linesize
[
0
];
...
...
@@ -1261,7 +1172,7 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
for
(
i
=
0
;
i
<
3
;
i
++
){
buffer
[
0
][
i
]
=
1
<<
(
s
->
bits
+
point_transform
-
1
);
}
for
(
mb_y
=
0
;
mb_y
<
mb_height
;
mb_y
++
)
{
for
(
mb_y
=
0
;
mb_y
<
s
->
mb_height
;
mb_y
++
)
{
const
int
modified_predictor
=
mb_y
?
1
:
predictor
;
uint8_t
*
ptr
=
s
->
current_picture
[
0
]
+
(
linesize
*
mb_y
);
...
...
@@ -1271,7 +1182,7 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
for
(
i
=
0
;
i
<
3
;
i
++
){
top
[
i
]
=
left
[
i
]
=
topleft
[
i
]
=
buffer
[
0
][
i
];
}
for
(
mb_x
=
0
;
mb_x
<
mb_width
;
mb_x
++
)
{
for
(
mb_x
=
0
;
mb_x
<
s
->
mb_width
;
mb_x
++
)
{
if
(
s
->
restart_interval
&&
!
s
->
restart_count
)
s
->
restart_count
=
s
->
restart_interval
;
...
...
@@ -1284,7 +1195,7 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
PREDICT
(
pred
,
topleft
[
i
],
top
[
i
],
left
[
i
],
modified_predictor
);
left
[
i
]
=
buffer
[
mb_x
][
i
]
=
mask
&
(
pred
+
(
mjpeg_decode_dc
(
s
,
dc_index
[
i
])
<<
point_transform
));
buffer
[
mb_x
][
i
]
=
mask
&
(
pred
+
(
mjpeg_decode_dc
(
s
,
s
->
dc_index
[
i
])
<<
point_transform
));
}
if
(
s
->
restart_interval
&&
!--
s
->
restart_count
)
{
...
...
@@ -1294,39 +1205,45 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
}
if
(
s
->
rct
){
for
(
mb_x
=
0
;
mb_x
<
mb_width
;
mb_x
++
)
{
for
(
mb_x
=
0
;
mb_x
<
s
->
mb_width
;
mb_x
++
)
{
ptr
[
4
*
mb_x
+
1
]
=
buffer
[
mb_x
][
0
]
-
((
buffer
[
mb_x
][
1
]
+
buffer
[
mb_x
][
2
]
-
0x200
)
>>
2
);
ptr
[
4
*
mb_x
+
0
]
=
buffer
[
mb_x
][
1
]
+
ptr
[
4
*
mb_x
+
1
];
ptr
[
4
*
mb_x
+
2
]
=
buffer
[
mb_x
][
2
]
+
ptr
[
4
*
mb_x
+
1
];
}
}
else
if
(
s
->
pegasus_rct
){
for
(
mb_x
=
0
;
mb_x
<
mb_width
;
mb_x
++
)
{
for
(
mb_x
=
0
;
mb_x
<
s
->
mb_width
;
mb_x
++
)
{
ptr
[
4
*
mb_x
+
1
]
=
buffer
[
mb_x
][
0
]
-
((
buffer
[
mb_x
][
1
]
+
buffer
[
mb_x
][
2
])
>>
2
);
ptr
[
4
*
mb_x
+
0
]
=
buffer
[
mb_x
][
1
]
+
ptr
[
4
*
mb_x
+
1
];
ptr
[
4
*
mb_x
+
2
]
=
buffer
[
mb_x
][
2
]
+
ptr
[
4
*
mb_x
+
1
];
}
}
else
{
for
(
mb_x
=
0
;
mb_x
<
mb_width
;
mb_x
++
)
{
for
(
mb_x
=
0
;
mb_x
<
s
->
mb_width
;
mb_x
++
)
{
ptr
[
4
*
mb_x
+
0
]
=
buffer
[
mb_x
][
0
];
ptr
[
4
*
mb_x
+
1
]
=
buffer
[
mb_x
][
1
];
ptr
[
4
*
mb_x
+
2
]
=
buffer
[
mb_x
][
2
];
}
}
}
}
else
{
for
(
mb_y
=
0
;
mb_y
<
mb_height
;
mb_y
++
)
{
for
(
mb_x
=
0
;
mb_x
<
mb_width
;
mb_x
++
)
{
return
0
;
}
static
int
ljpeg_decode_yuv_scan
(
MJpegDecodeContext
*
s
,
int
predictor
,
int
point_transform
){
int
i
,
mb_x
,
mb_y
;
const
int
nb_components
=
3
;
for
(
mb_y
=
0
;
mb_y
<
s
->
mb_height
;
mb_y
++
)
{
for
(
mb_x
=
0
;
mb_x
<
s
->
mb_width
;
mb_x
++
)
{
if
(
s
->
restart_interval
&&
!
s
->
restart_count
)
s
->
restart_count
=
s
->
restart_interval
;
if
(
mb_x
==
0
||
mb_y
==
0
||
s
->
interlaced
){
for
(
i
=
0
;
i
<
nb_components
;
i
++
)
{
uint8_t
*
ptr
;
int
x
,
y
,
c
,
linesize
;
n
=
nb_blocks
[
i
];
c
=
comp_index
[
i
];
h
=
h_
count
[
i
];
v
=
v_
count
[
i
];
int
n
,
h
,
v
,
x
,
y
,
c
,
j
,
linesize
;
n
=
s
->
nb_blocks
[
i
];
c
=
s
->
comp_index
[
i
];
h
=
s
->
h_s
count
[
i
];
v
=
s
->
v_s
count
[
i
];
x
=
0
;
y
=
0
;
linesize
=
s
->
linesize
[
c
];
...
...
@@ -1351,7 +1268,7 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
if
(
s
->
interlaced
&&
s
->
bottom_field
)
ptr
+=
linesize
>>
1
;
*
ptr
=
pred
+
(
mjpeg_decode_dc
(
s
,
dc_index
[
i
])
<<
point_transform
);
*
ptr
=
pred
+
(
mjpeg_decode_dc
(
s
,
s
->
dc_index
[
i
])
<<
point_transform
);
if
(
++
x
==
h
)
{
x
=
0
;
...
...
@@ -1362,11 +1279,11 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
}
else
{
for
(
i
=
0
;
i
<
nb_components
;
i
++
)
{
uint8_t
*
ptr
;
int
x
,
y
,
c
,
linesize
;
n
=
nb_blocks
[
i
];
c
=
comp_index
[
i
];
h
=
h_
count
[
i
];
v
=
v_
count
[
i
];
int
n
,
h
,
v
,
x
,
y
,
c
,
j
,
linesize
;
n
=
s
->
nb_blocks
[
i
];
c
=
s
->
comp_index
[
i
];
h
=
s
->
h_s
count
[
i
];
v
=
s
->
v_s
count
[
i
];
x
=
0
;
y
=
0
;
linesize
=
s
->
linesize
[
c
];
...
...
@@ -1376,7 +1293,7 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
ptr
=
s
->
current_picture
[
c
]
+
(
linesize
*
(
v
*
mb_y
+
y
))
+
(
h
*
mb_x
+
x
);
//FIXME optimize this crap
PREDICT
(
pred
,
ptr
[
-
linesize
-
1
],
ptr
[
-
linesize
],
ptr
[
-
1
],
predictor
);
*
ptr
=
pred
+
(
mjpeg_decode_dc
(
s
,
dc_index
[
i
])
<<
point_transform
);
*
ptr
=
pred
+
(
mjpeg_decode_dc
(
s
,
s
->
dc_index
[
i
])
<<
point_transform
);
if
(
++
x
==
h
)
{
x
=
0
;
y
++
;
...
...
@@ -1390,30 +1307,34 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
}
}
}
}
}
else
{
for
(
mb_y
=
0
;
mb_y
<
mb_height
;
mb_y
++
)
{
for
(
mb_x
=
0
;
mb_x
<
mb_width
;
mb_x
++
)
{
return
0
;
}
static
int
mjpeg_decode_scan
(
MJpegDecodeContext
*
s
){
int
i
,
mb_x
,
mb_y
;
const
int
nb_components
=
3
;
for
(
mb_y
=
0
;
mb_y
<
s
->
mb_height
;
mb_y
++
)
{
for
(
mb_x
=
0
;
mb_x
<
s
->
mb_width
;
mb_x
++
)
{
if
(
s
->
restart_interval
&&
!
s
->
restart_count
)
s
->
restart_count
=
s
->
restart_interval
;
for
(
i
=
0
;
i
<
nb_components
;
i
++
)
{
uint8_t
*
ptr
;
int
x
,
y
,
c
;
n
=
nb_blocks
[
i
];
c
=
comp_index
[
i
];
h
=
h_
count
[
i
];
v
=
v_
count
[
i
];
int
n
,
h
,
v
,
x
,
y
,
c
,
j
;
n
=
s
->
nb_blocks
[
i
];
c
=
s
->
comp_index
[
i
];
h
=
s
->
h_s
count
[
i
];
v
=
s
->
v_s
count
[
i
];
x
=
0
;
y
=
0
;
for
(
j
=
0
;
j
<
n
;
j
++
)
{
memset
(
s
->
block
,
0
,
sizeof
(
s
->
block
));
if
(
decode_block
(
s
,
s
->
block
,
i
,
dc_index
[
i
],
ac_index
[
i
],
s
->
dc_index
[
i
],
s
->
ac_index
[
i
],
s
->
quant_index
[
c
])
<
0
)
{
dprintf
(
"error y=%d x=%d
\n
"
,
mb_y
,
mb_x
);
ret
=
-
1
;
goto
the_end
;
return
-
1
;
}
// dprintf("mb: %d %d processed\n", mb_y, mb_x);
ptr
=
s
->
current_picture
[
c
]
+
...
...
@@ -1433,16 +1354,120 @@ static int mjpeg_decode_sos(MJpegDecodeContext *s)
!--
s
->
restart_count
)
{
align_get_bits
(
&
s
->
gb
);
skip_bits
(
&
s
->
gb
,
16
);
/* skip RSTn */
for
(
j
=
0
;
j
<
nb_components
;
j
++
)
/* reset dc */
s
->
last_dc
[
j
]
=
1024
;
for
(
i
=
0
;
i
<
nb_components
;
i
++
)
/* reset dc */
s
->
last_dc
[
i
]
=
1024
;
}
}
}
return
0
;
}
static
int
mjpeg_decode_sos
(
MJpegDecodeContext
*
s
)
{
int
len
,
nb_components
,
i
,
h
,
v
,
predictor
,
point_transform
,
ilv
;
int
vmax
,
hmax
,
index
,
id
;
const
int
block_size
=
s
->
lossless
?
1
:
8
;
/* XXX: verify len field validity */
len
=
get_bits
(
&
s
->
gb
,
16
);
nb_components
=
get_bits
(
&
s
->
gb
,
8
);
if
(
len
!=
6
+
2
*
nb_components
)
{
dprintf
(
"decode_sos: invalid len (%d)
\n
"
,
len
);
return
-
1
;
}
/* XXX: only interleaved scan accepted */
if
(
nb_components
!=
3
)
{
dprintf
(
"decode_sos: components(%d) mismatch
\n
"
,
nb_components
);
return
-
1
;
}
vmax
=
0
;
hmax
=
0
;
for
(
i
=
0
;
i
<
nb_components
;
i
++
)
{
id
=
get_bits
(
&
s
->
gb
,
8
)
-
1
;
dprintf
(
"component: %d
\n
"
,
id
);
/* find component index */
for
(
index
=
0
;
index
<
s
->
nb_components
;
index
++
)
if
(
id
==
s
->
component_id
[
index
])
break
;
if
(
index
==
s
->
nb_components
)
{
dprintf
(
"decode_sos: index(%d) out of components
\n
"
,
index
);
return
-
1
;
}
s
->
comp_index
[
i
]
=
index
;
s
->
nb_blocks
[
i
]
=
s
->
h_count
[
index
]
*
s
->
v_count
[
index
];
s
->
h_scount
[
i
]
=
s
->
h_count
[
index
];
s
->
v_scount
[
i
]
=
s
->
v_count
[
index
];
s
->
dc_index
[
i
]
=
get_bits
(
&
s
->
gb
,
4
);
s
->
ac_index
[
i
]
=
get_bits
(
&
s
->
gb
,
4
);
if
(
s
->
dc_index
[
i
]
<
0
||
s
->
ac_index
[
i
]
<
0
||
s
->
dc_index
[
i
]
>=
4
||
s
->
ac_index
[
i
]
>=
4
)
goto
out_of_range
;
#if 0 //buggy
switch(s->start_code)
{
case SOF0:
if (dc_index[i] > 1 || ac_index[i] > 1)
goto out_of_range;
break;
case SOF1:
case SOF2:
if (dc_index[i] > 3 || ac_index[i] > 3)
goto out_of_range;
break;
case SOF3:
if (dc_index[i] > 3 || ac_index[i] != 0)
goto out_of_range;
break;
}
#endif
}
predictor
=
get_bits
(
&
s
->
gb
,
8
);
/* lossless predictor or start of spectral (Ss) */
skip_bits
(
&
s
->
gb
,
8
);
/* Se */
skip_bits
(
&
s
->
gb
,
4
);
/* Ah */
point_transform
=
get_bits
(
&
s
->
gb
,
4
);
/* Al */
for
(
i
=
0
;
i
<
nb_components
;
i
++
)
s
->
last_dc
[
i
]
=
1024
;
if
(
nb_components
>
1
)
{
/* interleaved stream */
s
->
mb_width
=
(
s
->
width
+
s
->
h_max
*
block_size
-
1
)
/
(
s
->
h_max
*
block_size
);
s
->
mb_height
=
(
s
->
height
+
s
->
v_max
*
block_size
-
1
)
/
(
s
->
v_max
*
block_size
);
}
else
{
h
=
s
->
h_max
/
s
->
h_scount
[
s
->
comp_index
[
0
]];
v
=
s
->
v_max
/
s
->
v_scount
[
s
->
comp_index
[
0
]];
s
->
mb_width
=
(
s
->
width
+
h
*
block_size
-
1
)
/
(
h
*
block_size
);
s
->
mb_height
=
(
s
->
height
+
v
*
block_size
-
1
)
/
(
v
*
block_size
);
s
->
nb_blocks
[
0
]
=
1
;
s
->
h_scount
[
0
]
=
1
;
s
->
v_scount
[
0
]
=
1
;
}
if
(
s
->
avctx
->
debug
&
FF_DEBUG_PICT_INFO
)
printf
(
"%s %s p:%d >>:%d
\n
"
,
s
->
lossless
?
"lossless"
:
"sequencial DCT"
,
s
->
rgb
?
"RGB"
:
""
,
predictor
,
point_transform
);
if
(
s
->
lossless
){
if
(
s
->
rgb
){
if
(
ljpeg_decode_rgb_scan
(
s
,
predictor
,
point_transform
)
<
0
)
return
-
1
;
}
else
{
if
(
ljpeg_decode_yuv_scan
(
s
,
predictor
,
point_transform
)
<
0
)
return
-
1
;
}
}
else
{
if
(
mjpeg_decode_scan
(
s
)
<
0
)
return
-
1
;
}
ret
=
0
;
the_end:
emms_c
();
return
ret
;
return
0
;
out_of_range:
dprintf
(
"decode_sos: ac/dc index out of range
\n
"
);
return
-
1
;
...
...
@@ -2026,7 +2051,7 @@ read_header:
picture
->
qscale_table
=
s
->
qscale_table
;
memset
(
picture
->
qscale_table
,
picture
->
quality
,
(
s
->
width
+
15
)
/
16
);
if
(
avctx
->
debug
&
FF_DEBUG_QP
)
printf
(
"QP: %
d
\n
"
,
picture
->
quality
);
printf
(
"QP: %
f
\n
"
,
picture
->
quality
);
}
return
buf_ptr
-
buf
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录