Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
9155c595
Commit
9155c595
authored
10 years ago
by
Derek Buitenhuis
Browse files
Options
Downloads
Patches
Plain Diff
fic: Support rendering cursors
Signed-off-by:
Derek Buitenhuis
<
derek.buitenhuis@gmail.com
>
parent
40b331e1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavcodec/fic.c
+111
-1
111 additions, 1 deletion
libavcodec/fic.c
with
111 additions
and
1 deletion
libavcodec/fic.c
+
111
−
1
View file @
9155c595
...
@@ -38,6 +38,7 @@ typedef struct FICThreadContext {
...
@@ -38,6 +38,7 @@ typedef struct FICThreadContext {
typedef
struct
FICContext
{
typedef
struct
FICContext
{
AVCodecContext
*
avctx
;
AVCodecContext
*
avctx
;
AVFrame
*
frame
;
AVFrame
*
frame
;
AVFrame
*
final_frame
;
FICThreadContext
*
slice_data
;
FICThreadContext
*
slice_data
;
int
slice_data_size
;
int
slice_data_size
;
...
@@ -48,6 +49,8 @@ typedef struct FICContext {
...
@@ -48,6 +49,8 @@ typedef struct FICContext {
int
aligned_width
,
aligned_height
;
int
aligned_width
,
aligned_height
;
int
num_slices
,
slice_h
;
int
num_slices
,
slice_h
;
uint8_t
cursor_buf
[
4096
];
}
FICContext
;
}
FICContext
;
static
const
uint8_t
fic_qmat_hq
[
64
]
=
{
static
const
uint8_t
fic_qmat_hq
[
64
]
=
{
...
@@ -186,6 +189,69 @@ static int fic_decode_slice(AVCodecContext *avctx, void *tdata)
...
@@ -186,6 +189,69 @@ static int fic_decode_slice(AVCodecContext *avctx, void *tdata)
return
0
;
return
0
;
}
}
static
av_always_inline
void
fic_alpha_blend
(
uint8_t
*
dst
,
uint8_t
*
src
,
int
size
,
uint8_t
*
alpha
)
{
int
i
;
for
(
i
=
0
;
i
<
size
;
i
++
)
dst
[
i
]
=
(
dst
[
i
]
*
(
256
-
alpha
[
i
])
+
src
[
i
]
*
alpha
[
i
])
>>
8
;
}
static
void
fic_draw_cursor
(
AVCodecContext
*
avctx
,
int
cur_x
,
int
cur_y
)
{
FICContext
*
ctx
=
avctx
->
priv_data
;
uint8_t
*
ptr
=
ctx
->
cursor_buf
;
uint8_t
*
dstptr
[
3
];
uint8_t
planes
[
4
][
1024
];
uint8_t
chroma
[
3
][
256
];
int
i
,
j
,
p
;
/* Convert to YUVA444. */
for
(
i
=
0
;
i
<
1024
;
i
++
)
{
planes
[
0
][
i
]
=
av_clip_uint8
(((
25
*
ptr
[
0
]
+
129
*
ptr
[
1
]
+
66
*
ptr
[
2
])
/
255
)
+
16
);
planes
[
1
][
i
]
=
av_clip_uint8
(((
-
38
*
ptr
[
0
]
+
112
*
ptr
[
1
]
+
-
74
*
ptr
[
2
])
/
255
)
+
128
);
planes
[
2
][
i
]
=
av_clip_uint8
(((
-
18
*
ptr
[
0
]
+
112
*
ptr
[
1
]
+
-
94
*
ptr
[
2
])
/
255
)
+
128
);
planes
[
3
][
i
]
=
ptr
[
3
];
ptr
+=
4
;
}
/* Subsample chroma. */
for
(
i
=
0
;
i
<
32
;
i
+=
2
)
for
(
j
=
0
;
j
<
32
;
j
+=
2
)
for
(
p
=
0
;
p
<
3
;
p
++
)
chroma
[
p
][
16
*
(
i
/
2
)
+
j
/
2
]
=
(
planes
[
p
+
1
][
32
*
i
+
j
]
+
planes
[
p
+
1
][
32
*
i
+
j
+
1
]
+
planes
[
p
+
1
][
32
*
(
i
+
1
)
+
j
]
+
planes
[
p
+
1
][
32
*
(
i
+
1
)
+
j
+
1
])
/
4
;
/* Seek to x/y pos of cursor. */
for
(
i
=
0
;
i
<
3
;
i
++
)
dstptr
[
i
]
=
ctx
->
final_frame
->
data
[
i
]
+
(
ctx
->
final_frame
->
linesize
[
i
]
*
(
cur_y
>>
!!
i
))
+
(
cur_x
>>
!!
i
)
+
!!
i
;
/* Copy. */
for
(
i
=
0
;
i
<
FFMIN
(
32
,
avctx
->
height
-
cur_y
)
-
1
;
i
+=
2
)
{
int
lsize
=
FFMIN
(
32
,
avctx
->
width
-
cur_x
);
int
csize
=
lsize
/
2
;
fic_alpha_blend
(
dstptr
[
0
],
planes
[
0
]
+
i
*
32
,
lsize
,
planes
[
3
]
+
i
*
32
);
fic_alpha_blend
(
dstptr
[
0
]
+
ctx
->
final_frame
->
linesize
[
0
],
planes
[
0
]
+
(
i
+
1
)
*
32
,
lsize
,
planes
[
3
]
+
(
i
+
1
)
*
32
);
fic_alpha_blend
(
dstptr
[
1
],
chroma
[
0
]
+
(
i
/
2
)
*
16
,
csize
,
chroma
[
2
]
+
(
i
/
2
)
*
16
);
fic_alpha_blend
(
dstptr
[
2
],
chroma
[
1
]
+
(
i
/
2
)
*
16
,
csize
,
chroma
[
2
]
+
(
i
/
2
)
*
16
);
dstptr
[
0
]
+=
ctx
->
final_frame
->
linesize
[
0
]
*
2
;
dstptr
[
1
]
+=
ctx
->
final_frame
->
linesize
[
1
];
dstptr
[
2
]
+=
ctx
->
final_frame
->
linesize
[
2
];
}
}
static
int
fic_decode_frame
(
AVCodecContext
*
avctx
,
void
*
data
,
static
int
fic_decode_frame
(
AVCodecContext
*
avctx
,
void
*
data
,
int
*
got_frame
,
AVPacket
*
avpkt
)
int
*
got_frame
,
AVPacket
*
avpkt
)
{
{
...
@@ -195,6 +261,8 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data,
...
@@ -195,6 +261,8 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data,
int
slice
,
nslices
;
int
slice
,
nslices
;
int
msize
;
int
msize
;
int
tsize
;
int
tsize
;
int
cur_x
,
cur_y
;
int
skip_cursor
=
0
;
uint8_t
*
sdata
;
uint8_t
*
sdata
;
if
((
ret
=
ff_reget_buffer
(
avctx
,
ctx
->
frame
))
<
0
)
{
if
((
ret
=
ff_reget_buffer
(
avctx
,
ctx
->
frame
))
<
0
)
{
...
@@ -232,6 +300,28 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data,
...
@@ -232,6 +300,28 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data,
return
AVERROR_INVALIDDATA
;
return
AVERROR_INVALIDDATA
;
}
}
if
(
tsize
<
32
)
{
av_log
(
avctx
,
AV_LOG_WARNING
,
"Cursor data too small. Skipping cursor.
\n
"
);
skip_cursor
=
1
;
}
/* Cursor position. */
cur_x
=
AV_RL16
(
src
+
33
);
cur_y
=
AV_RL16
(
src
+
35
);
if
(
cur_x
>
avctx
->
width
||
cur_y
>
avctx
->
height
)
{
av_log
(
avctx
,
AV_LOG_WARNING
,
"Invalid cursor position: (%d,%d). Skipping cusor.
\n
"
,
cur_x
,
cur_y
);
skip_cursor
=
1
;
}
if
(
AV_RL16
(
src
+
37
)
!=
32
||
AV_RL16
(
src
+
39
)
!=
32
)
{
av_log
(
avctx
,
AV_LOG_WARNING
,
"Invalid cursor size. Skipping cursor.
\n
"
);
skip_cursor
=
1
;
}
/* Slice height for all but the last slice. */
/* Slice height for all but the last slice. */
ctx
->
slice_h
=
16
*
(
ctx
->
aligned_height
>>
4
)
/
nslices
;
ctx
->
slice_h
=
16
*
(
ctx
->
aligned_height
>>
4
)
/
nslices
;
if
(
ctx
->
slice_h
%
16
)
if
(
ctx
->
slice_h
%
16
)
...
@@ -296,9 +386,28 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data,
...
@@ -296,9 +386,28 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data,
NULL
,
nslices
,
sizeof
(
ctx
->
slice_data
[
0
])))
<
0
)
NULL
,
nslices
,
sizeof
(
ctx
->
slice_data
[
0
])))
<
0
)
return
ret
;
return
ret
;
av_frame_free
(
&
ctx
->
final_frame
);
ctx
->
final_frame
=
av_frame_clone
(
ctx
->
frame
);
if
(
!
ctx
->
final_frame
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Could not clone frame buffer.
\n
"
);
return
AVERROR
(
ENOMEM
);
}
/* Make sure we use a user-supplied buffer. */
if
((
ret
=
ff_reget_buffer
(
avctx
,
ctx
->
final_frame
))
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Could not make frame writable.
\n
"
);
return
ret
;
}
/* Draw cursor. */
if
(
!
skip_cursor
)
{
memcpy
(
ctx
->
cursor_buf
,
src
+
59
,
32
*
32
*
4
);
fic_draw_cursor
(
avctx
,
cur_x
,
cur_y
);
}
skip:
skip:
*
got_frame
=
1
;
*
got_frame
=
1
;
if
((
ret
=
av_frame_ref
(
data
,
ctx
->
frame
))
<
0
)
if
((
ret
=
av_frame_ref
(
data
,
ctx
->
final_
frame
))
<
0
)
return
ret
;
return
ret
;
return
avpkt
->
size
;
return
avpkt
->
size
;
...
@@ -309,6 +418,7 @@ static av_cold int fic_decode_close(AVCodecContext *avctx)
...
@@ -309,6 +418,7 @@ static av_cold int fic_decode_close(AVCodecContext *avctx)
FICContext
*
ctx
=
avctx
->
priv_data
;
FICContext
*
ctx
=
avctx
->
priv_data
;
av_freep
(
&
ctx
->
slice_data
);
av_freep
(
&
ctx
->
slice_data
);
av_frame_free
(
&
ctx
->
final_frame
);
av_frame_free
(
&
ctx
->
frame
);
av_frame_free
(
&
ctx
->
frame
);
return
0
;
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment