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
490dcda6
Commit
490dcda6
authored
Jan 01, 2012
by
Kostya Shishkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utvideo: proper median prediction for interlaced videos
parent
c04a954d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
7 deletions
+94
-7
utvideo.c
libavcodec/utvideo.c
+94
-7
No files found.
libavcodec/utvideo.c
View file @
490dcda6
...
...
@@ -282,6 +282,77 @@ static void restore_median(uint8_t *src, int step, int stride,
}
}
/* UtVideo interlaced mode treats every two lines as a single one,
* so restoring function should take care of possible padding between
* two parts of the same "line".
*/
static
void
restore_median_il
(
uint8_t
*
src
,
int
step
,
int
stride
,
int
width
,
int
height
,
int
slices
,
int
rmode
)
{
int
i
,
j
,
slice
;
int
A
,
B
,
C
;
uint8_t
*
bsrc
;
int
slice_start
,
slice_height
;
const
int
cmask
=
~
(
rmode
?
3
:
1
);
const
int
stride2
=
stride
<<
1
;
for
(
slice
=
0
;
slice
<
slices
;
slice
++
)
{
slice_start
=
((
slice
*
height
)
/
slices
)
&
cmask
;
slice_height
=
((((
slice
+
1
)
*
height
)
/
slices
)
&
cmask
)
-
slice_start
;
slice_height
>>=
1
;
bsrc
=
src
+
slice_start
*
stride
;
// first line - left neighbour prediction
bsrc
[
0
]
+=
0x80
;
A
=
bsrc
[
0
];
for
(
i
=
step
;
i
<
width
*
step
;
i
+=
step
)
{
bsrc
[
i
]
+=
A
;
A
=
bsrc
[
i
];
}
for
(
i
=
0
;
i
<
width
*
step
;
i
+=
step
)
{
bsrc
[
stride
+
i
]
+=
A
;
A
=
bsrc
[
stride
+
i
];
}
bsrc
+=
stride2
;
if
(
slice_height
==
1
)
continue
;
// second line - first element has top predition, the rest uses median
C
=
bsrc
[
-
stride2
];
bsrc
[
0
]
+=
C
;
A
=
bsrc
[
0
];
for
(
i
=
step
;
i
<
width
*
step
;
i
+=
step
)
{
B
=
bsrc
[
i
-
stride2
];
bsrc
[
i
]
+=
mid_pred
(
A
,
B
,
(
uint8_t
)(
A
+
B
-
C
));
C
=
B
;
A
=
bsrc
[
i
];
}
for
(
i
=
0
;
i
<
width
*
step
;
i
+=
step
)
{
B
=
bsrc
[
i
-
stride
];
bsrc
[
stride
+
i
]
+=
mid_pred
(
A
,
B
,
(
uint8_t
)(
A
+
B
-
C
));
C
=
B
;
A
=
bsrc
[
stride
+
i
];
}
bsrc
+=
stride2
;
// the rest of lines use continuous median prediction
for
(
j
=
2
;
j
<
slice_height
;
j
++
)
{
for
(
i
=
0
;
i
<
width
*
step
;
i
+=
step
)
{
B
=
bsrc
[
i
-
stride2
];
bsrc
[
i
]
+=
mid_pred
(
A
,
B
,
(
uint8_t
)(
A
+
B
-
C
));
C
=
B
;
A
=
bsrc
[
i
];
}
for
(
i
=
0
;
i
<
width
*
step
;
i
+=
step
)
{
B
=
bsrc
[
i
-
stride
];
bsrc
[
i
+
stride
]
+=
mid_pred
(
A
,
B
,
(
uint8_t
)(
A
+
B
-
C
));
C
=
B
;
A
=
bsrc
[
i
+
stride
];
}
bsrc
+=
stride2
;
}
}
}
static
int
decode_frame
(
AVCodecContext
*
avctx
,
void
*
data
,
int
*
data_size
,
AVPacket
*
avpkt
)
{
const
uint8_t
*
buf
=
avpkt
->
data
;
...
...
@@ -381,10 +452,18 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
c
->
frame_pred
==
PRED_LEFT
);
if
(
ret
)
return
ret
;
if
(
c
->
frame_pred
==
PRED_MEDIAN
)
restore_median
(
c
->
pic
.
data
[
i
],
1
,
c
->
pic
.
linesize
[
i
],
avctx
->
width
>>
!!
i
,
avctx
->
height
>>
!!
i
,
c
->
slices
,
!
i
);
if
(
c
->
frame_pred
==
PRED_MEDIAN
)
{
if
(
!
c
->
interlaced
)
{
restore_median
(
c
->
pic
.
data
[
i
],
1
,
c
->
pic
.
linesize
[
i
],
avctx
->
width
>>
!!
i
,
avctx
->
height
>>
!!
i
,
c
->
slices
,
!
i
);
}
else
{
restore_median_il
(
c
->
pic
.
data
[
i
],
1
,
c
->
pic
.
linesize
[
i
],
avctx
->
width
>>
!!
i
,
avctx
->
height
>>
!!
i
,
c
->
slices
,
!
i
);
}
}
}
break
;
case
PIX_FMT_YUV422P
:
...
...
@@ -395,9 +474,17 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
c
->
frame_pred
==
PRED_LEFT
);
if
(
ret
)
return
ret
;
if
(
c
->
frame_pred
==
PRED_MEDIAN
)
restore_median
(
c
->
pic
.
data
[
i
],
1
,
c
->
pic
.
linesize
[
i
],
avctx
->
width
>>
!!
i
,
avctx
->
height
,
c
->
slices
,
0
);
if
(
c
->
frame_pred
==
PRED_MEDIAN
)
{
if
(
!
c
->
interlaced
)
{
restore_median
(
c
->
pic
.
data
[
i
],
1
,
c
->
pic
.
linesize
[
i
],
avctx
->
width
>>
!!
i
,
avctx
->
height
,
c
->
slices
,
0
);
}
else
{
restore_median_il
(
c
->
pic
.
data
[
i
],
1
,
c
->
pic
.
linesize
[
i
],
avctx
->
width
>>
!!
i
,
avctx
->
height
,
c
->
slices
,
0
);
}
}
}
break
;
}
...
...
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