Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
6a6bc43f
Commit
6a6bc43f
authored
Sep 03, 2015
by
Luca Barbato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dxtory: Factorize slice size checks
They are always the same.
parent
db9fd1e9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
76 deletions
+48
-76
dxtory.c
libavcodec/dxtory.c
+48
-76
No files found.
libavcodec/dxtory.c
View file @
6a6bc43f
...
@@ -192,6 +192,34 @@ static inline uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
...
@@ -192,6 +192,34 @@ static inline uint8_t decode_sym(GetBitContext *gb, uint8_t lru[8])
return
val
;
return
val
;
}
}
static
int
check_slice_size
(
AVCodecContext
*
avctx
,
const
uint8_t
*
src
,
int
src_size
,
int
slice_size
,
int
off
)
{
int
cur_slice_size
;
if
(
slice_size
>
src_size
-
off
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
" (only %"
PRIu32
" bytes left)
\n
"
,
slice_size
,
src_size
-
off
);
return
AVERROR_INVALIDDATA
;
}
if
(
slice_size
<=
16
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
"
\n
"
,
slice_size
);
return
AVERROR_INVALIDDATA
;
}
cur_slice_size
=
AV_RL32
(
src
+
off
);
if
(
cur_slice_size
!=
slice_size
-
16
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Slice sizes mismatch: got %"
PRIu32
" instead of %"
PRIu32
"
\n
"
,
cur_slice_size
,
slice_size
-
16
);
}
return
0
;
}
static
inline
uint8_t
decode_sym_565
(
GetBitContext
*
gb
,
uint8_t
lru
[
8
],
static
inline
uint8_t
decode_sym_565
(
GetBitContext
*
gb
,
uint8_t
lru
[
8
],
int
bits
)
int
bits
)
{
{
...
@@ -269,22 +297,11 @@ static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic,
...
@@ -269,22 +297,11 @@ static int dxtory_decode_v2_565(AVCodecContext *avctx, AVFrame *pic,
dst
=
pic
->
data
[
0
];
dst
=
pic
->
data
[
0
];
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
slice_size
=
bytestream2_get_le32
(
&
gb
);
slice_size
=
bytestream2_get_le32
(
&
gb
);
if
(
slice_size
>
src_size
-
off
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
" (only %"
PRIu32
" bytes left)
\n
"
,
slice_size
,
src_size
-
off
);
return
AVERROR_INVALIDDATA
;
}
if
(
slice_size
<=
16
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
"
\n
"
,
slice_size
);
return
AVERROR_INVALIDDATA
;
}
if
(
AV_RL32
(
src
+
off
)
!=
slice_size
-
16
)
{
ret
=
check_slice_size
(
avctx
,
src
,
src_size
,
slice_size
,
off
);
av_log
(
avctx
,
AV_LOG_ERROR
,
if
(
ret
<
0
)
"Slice sizes mismatch: got %"
PRIu32
" instead of %"
PRIu32
"
\n
"
,
return
ret
;
AV_RL32
(
src
+
off
),
slice_size
-
16
);
}
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
dx2_decode_slice_565
(
&
gb2
,
avctx
->
width
,
slice_height
,
dst
,
dx2_decode_slice_565
(
&
gb2
,
avctx
->
width
,
slice_height
,
dst
,
pic
->
linesize
[
0
],
is_565
);
pic
->
linesize
[
0
],
is_565
);
...
@@ -350,23 +367,11 @@ static int dxtory_decode_v2_rgb(AVCodecContext *avctx, AVFrame *pic,
...
@@ -350,23 +367,11 @@ static int dxtory_decode_v2_rgb(AVCodecContext *avctx, AVFrame *pic,
dst
=
pic
->
data
[
0
];
dst
=
pic
->
data
[
0
];
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
slice_size
=
bytestream2_get_le32
(
&
gb
);
slice_size
=
bytestream2_get_le32
(
&
gb
);
if
(
slice_size
>
src_size
-
off
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
" (only %"
PRIu32
" bytes left)
\n
"
,
slice_size
,
src_size
-
off
);
return
AVERROR_INVALIDDATA
;
}
if
(
slice_size
<=
16
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
"
\n
"
,
slice_size
);
return
AVERROR_INVALIDDATA
;
}
if
(
AV_RL32
(
src
+
off
)
!=
slice_size
-
16
)
{
ret
=
check_slice_size
(
avctx
,
src
,
src_size
,
slice_size
,
off
);
av_log
(
avctx
,
AV_LOG_ERROR
,
if
(
ret
<
0
)
"Slice sizes mismatch: got %"
PRIu32
" instead of %"
PRIu32
"
\n
"
,
return
ret
;
AV_RL32
(
src
+
off
),
slice_size
-
16
);
}
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
dx2_decode_slice_rgb
(
&
gb2
,
avctx
->
width
,
slice_height
,
dst
,
dx2_decode_slice_rgb
(
&
gb2
,
avctx
->
width
,
slice_height
,
dst
,
pic
->
linesize
[
0
]);
pic
->
linesize
[
0
]);
...
@@ -449,22 +454,11 @@ static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic,
...
@@ -449,22 +454,11 @@ static int dxtory_decode_v2_410(AVCodecContext *avctx, AVFrame *pic,
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
slice_size
=
bytestream2_get_le32
(
&
gb
);
slice_size
=
bytestream2_get_le32
(
&
gb
);
slice_height
=
(
next_y
&
~
3
)
-
(
cur_y
&
~
3
);
slice_height
=
(
next_y
&
~
3
)
-
(
cur_y
&
~
3
);
if
(
slice_size
>
src_size
-
off
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
" (only %"
PRIu32
" bytes left)
\n
"
,
slice_size
,
src_size
-
off
);
return
AVERROR_INVALIDDATA
;
}
if
(
slice_size
<=
16
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
"
\n
"
,
slice_size
);
return
AVERROR_INVALIDDATA
;
}
if
(
AV_RL32
(
src
+
off
)
!=
slice_size
-
16
)
{
ret
=
check_slice_size
(
avctx
,
src
,
src_size
,
slice_size
,
off
);
av_log
(
avctx
,
AV_LOG_ERROR
,
if
(
ret
<
0
)
"Slice sizes mismatch: got %"
PRIu32
" instead of %"
PRIu32
"
\n
"
,
return
ret
;
AV_RL32
(
src
+
off
),
slice_size
-
16
);
}
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
dx2_decode_slice_410
(
&
gb2
,
avctx
->
width
,
slice_height
,
Y
,
U
,
V
,
dx2_decode_slice_410
(
&
gb2
,
avctx
->
width
,
slice_height
,
Y
,
U
,
V
,
pic
->
linesize
[
0
],
pic
->
linesize
[
1
],
pic
->
linesize
[
0
],
pic
->
linesize
[
1
],
...
@@ -553,22 +547,11 @@ static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,
...
@@ -553,22 +547,11 @@ static int dxtory_decode_v2_420(AVCodecContext *avctx, AVFrame *pic,
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
slice_size
=
bytestream2_get_le32
(
&
gb
);
slice_size
=
bytestream2_get_le32
(
&
gb
);
slice_height
=
(
next_y
&
~
1
)
-
(
cur_y
&
~
1
);
slice_height
=
(
next_y
&
~
1
)
-
(
cur_y
&
~
1
);
if
(
slice_size
>
src_size
-
off
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
" (only %"
PRIu32
" bytes left)
\n
"
,
slice_size
,
src_size
-
off
);
return
AVERROR_INVALIDDATA
;
}
if
(
slice_size
<=
16
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
"
\n
"
,
slice_size
);
return
AVERROR_INVALIDDATA
;
}
if
(
AV_RL32
(
src
+
off
)
!=
slice_size
-
16
)
{
ret
=
check_slice_size
(
avctx
,
src
,
src_size
,
slice_size
,
off
);
av_log
(
avctx
,
AV_LOG_ERROR
,
if
(
ret
<
0
)
"Slice sizes mismatch: got %"
PRIu32
" instead of %"
PRIu32
"
\n
"
,
return
ret
;
AV_RL32
(
src
+
off
),
slice_size
-
16
);
}
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
dx2_decode_slice_420
(
&
gb2
,
avctx
->
width
,
slice_height
,
Y
,
U
,
V
,
dx2_decode_slice_420
(
&
gb2
,
avctx
->
width
,
slice_height
,
Y
,
U
,
V
,
pic
->
linesize
[
0
],
pic
->
linesize
[
1
],
pic
->
linesize
[
0
],
pic
->
linesize
[
1
],
...
@@ -646,22 +629,11 @@ static int dxtory_decode_v2_444(AVCodecContext *avctx, AVFrame *pic,
...
@@ -646,22 +629,11 @@ static int dxtory_decode_v2_444(AVCodecContext *avctx, AVFrame *pic,
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
for
(
slice
=
0
;
slice
<
nslices
;
slice
++
)
{
slice_size
=
bytestream2_get_le32
(
&
gb
);
slice_size
=
bytestream2_get_le32
(
&
gb
);
if
(
slice_size
>
src_size
-
off
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
" (only %"
PRIu32
" bytes left)
\n
"
,
slice_size
,
src_size
-
off
);
return
AVERROR_INVALIDDATA
;
}
if
(
slice_size
<=
16
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"invalid slice size %"
PRIu32
"
\n
"
,
slice_size
);
return
AVERROR_INVALIDDATA
;
}
if
(
AV_RL32
(
src
+
off
)
!=
slice_size
-
16
)
{
ret
=
check_slice_size
(
avctx
,
src
,
src_size
,
slice_size
,
off
);
av_log
(
avctx
,
AV_LOG_ERROR
,
if
(
ret
<
0
)
"Slice sizes mismatch: got %"
PRIu32
" instead of %"
PRIu32
"
\n
"
,
return
ret
;
AV_RL32
(
src
+
off
),
slice_size
-
16
);
}
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
init_get_bits
(
&
gb2
,
src
+
off
+
16
,
(
slice_size
-
16
)
*
8
);
dx2_decode_slice_444
(
&
gb2
,
avctx
->
width
,
slice_height
,
Y
,
U
,
V
,
dx2_decode_slice_444
(
&
gb2
,
avctx
->
width
,
slice_height
,
Y
,
U
,
V
,
pic
->
linesize
[
0
],
pic
->
linesize
[
1
],
pic
->
linesize
[
0
],
pic
->
linesize
[
1
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment