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
368fb748
Commit
368fb748
authored
Oct 12, 2017
by
Clément Bœsch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lavc/pixlet: reduce diff with Libav (cosmetics only)
parent
4b175913
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
144 additions
and
127 deletions
+144
-127
pixlet.c
libavcodec/pixlet.c
+144
-127
No files found.
libavcodec/pixlet.c
View file @
368fb748
...
...
@@ -28,12 +28,14 @@
#include "avcodec.h"
#include "bytestream.h"
#include "get_bits.h"
#include "unary.h"
#include "internal.h"
#include "thread.h"
#include "unary.h"
#define NB_LEVELS 4
#define PIXLET_MAGIC 0xDEADBEEF
#define H 0
#define V 1
...
...
@@ -47,11 +49,11 @@ typedef struct PixletContext {
AVClass
*
class
;
GetByteContext
gb
;
GetBitContext
gbit
;
GetBitContext
bc
;
int
levels
;
int
depth
;
int
h
,
w
;
int
w
,
h
;
int16_t
*
filter
[
2
];
int16_t
*
prediction
;
...
...
@@ -59,6 +61,31 @@ typedef struct PixletContext {
SubBand
band
[
4
][
NB_LEVELS
*
3
+
1
];
}
PixletContext
;
static
av_cold
int
pixlet_init
(
AVCodecContext
*
avctx
)
{
avctx
->
pix_fmt
=
AV_PIX_FMT_YUV420P16
;
avctx
->
color_range
=
AVCOL_RANGE_JPEG
;
return
0
;
}
static
void
free_buffers
(
AVCodecContext
*
avctx
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
av_freep
(
&
ctx
->
filter
[
0
]);
av_freep
(
&
ctx
->
filter
[
1
]);
av_freep
(
&
ctx
->
prediction
);
}
static
av_cold
int
pixlet_close
(
AVCodecContext
*
avctx
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
free_buffers
(
avctx
);
ctx
->
w
=
0
;
ctx
->
h
=
0
;
return
0
;
}
static
int
init_decoder
(
AVCodecContext
*
avctx
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
...
...
@@ -94,35 +121,11 @@ static int init_decoder(AVCodecContext *avctx)
return
0
;
}
static
void
free_buffers
(
AVCodecContext
*
avctx
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
av_freep
(
&
ctx
->
filter
[
0
]);
av_freep
(
&
ctx
->
filter
[
1
]);
av_freep
(
&
ctx
->
prediction
);
}
static
av_cold
int
pixlet_close
(
AVCodecContext
*
avctx
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
free_buffers
(
avctx
);
ctx
->
w
=
0
;
ctx
->
h
=
0
;
return
0
;
}
static
av_cold
int
pixlet_init
(
AVCodecContext
*
avctx
)
{
avctx
->
pix_fmt
=
AV_PIX_FMT_YUV420P16
;
avctx
->
color_range
=
AVCOL_RANGE_JPEG
;
return
0
;
}
static
int
read_low_coeffs
(
AVCodecContext
*
avctx
,
int16_t
*
dst
,
int
size
,
int
width
,
ptrdiff_t
stride
)
static
int
read_low_coeffs
(
AVCodecContext
*
avctx
,
int16_t
*
dst
,
int
size
,
int
width
,
ptrdiff_t
stride
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
GetBitContext
*
b
=
&
ctx
->
gbit
;
GetBitContext
*
b
c
=
&
ctx
->
bc
;
unsigned
cnt1
,
nbits
,
k
,
j
=
0
,
i
=
0
;
int64_t
value
,
state
=
3
;
int
rlen
,
escape
,
flag
=
0
;
...
...
@@ -130,18 +133,18 @@ static int read_low_coeffs(AVCodecContext *avctx, int16_t *dst, int size, int wi
while
(
i
<
size
)
{
nbits
=
FFMIN
(
ff_clz
((
state
>>
8
)
+
3
)
^
0x1F
,
14
);
cnt1
=
get_unary
(
b
,
0
,
8
);
cnt1
=
get_unary
(
b
c
,
0
,
8
);
if
(
cnt1
<
8
)
{
value
=
show_bits
(
b
,
nbits
);
value
=
show_bits
(
b
c
,
nbits
);
if
(
value
<=
1
)
{
skip_bits
(
b
,
nbits
-
1
);
skip_bits
(
b
c
,
nbits
-
1
);
escape
=
((
1
<<
nbits
)
-
1
)
*
cnt1
;
}
else
{
skip_bits
(
b
,
nbits
);
skip_bits
(
b
c
,
nbits
);
escape
=
value
+
((
1
<<
nbits
)
-
1
)
*
cnt1
-
1
;
}
}
else
{
escape
=
get_bits
(
b
,
16
);
escape
=
get_bits
(
b
c
,
16
);
}
value
=
-
((
escape
+
flag
)
&
1
)
|
1
;
...
...
@@ -159,16 +162,16 @@ static int read_low_coeffs(AVCodecContext *avctx, int16_t *dst, int size, int wi
nbits
=
((
state
+
8
)
>>
5
)
+
(
state
?
ff_clz
(
state
)
:
32
)
-
24
;
escape
=
av_mod_uintp2
(
16383
,
nbits
);
cnt1
=
get_unary
(
b
,
0
,
8
);
cnt1
=
get_unary
(
bc
,
0
,
8
);
if
(
cnt1
>
7
)
{
rlen
=
get_bits
(
b
,
16
);
rlen
=
get_bits
(
b
c
,
16
);
}
else
{
value
=
show_bits
(
b
,
nbits
);
value
=
show_bits
(
b
c
,
nbits
);
if
(
value
>
1
)
{
skip_bits
(
b
,
nbits
);
skip_bits
(
b
c
,
nbits
);
rlen
=
value
+
escape
*
cnt1
-
1
;
}
else
{
skip_bits
(
b
,
nbits
-
1
);
skip_bits
(
b
c
,
nbits
-
1
);
rlen
=
escape
*
cnt1
;
}
}
...
...
@@ -189,21 +192,22 @@ static int read_low_coeffs(AVCodecContext *avctx, int16_t *dst, int size, int wi
flag
=
rlen
<
0xFFFF
?
1
:
0
;
}
align_get_bits
(
b
);
return
get_bits_count
(
b
)
>>
3
;
align_get_bits
(
b
c
);
return
get_bits_count
(
b
c
)
>>
3
;
}
static
int
read_high_coeffs
(
AVCodecContext
*
avctx
,
uint8_t
*
src
,
int16_t
*
dst
,
int
size
,
int
c
,
int
a
,
int
d
,
static
int
read_high_coeffs
(
AVCodecContext
*
avctx
,
uint8_t
*
src
,
int16_t
*
dst
,
int
size
,
int
c
,
int
a
,
int
d
,
int
width
,
ptrdiff_t
stride
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
GetBitContext
*
b
=
&
ctx
->
gbit
;
GetBitContext
*
b
c
=
&
ctx
->
bc
;
unsigned
cnt1
,
shbits
,
rlen
,
nbits
,
length
,
i
=
0
,
j
=
0
,
k
;
int
ret
,
escape
,
pfx
,
value
,
yflag
,
xflag
,
flag
=
0
;
int64_t
state
=
3
,
tmp
;
if
((
ret
=
init_get_bits8
(
b
,
src
,
bytestream2_get_bytes_left
(
&
ctx
->
gb
)))
<
0
)
ret
=
init_get_bits8
(
bc
,
src
,
bytestream2_get_bytes_left
(
&
ctx
->
gb
));
if
(
ret
<
0
)
return
ret
;
if
(
a
^
(
a
>>
31
))
{
...
...
@@ -217,26 +221,24 @@ static int read_high_coeffs(AVCodecContext *avctx, uint8_t *src, int16_t *dst, i
length
=
25
-
nbits
;
while
(
i
<
size
)
{
if
(
state
>>
8
!=
-
3
)
{
if
(
state
>>
8
!=
-
3
)
value
=
ff_clz
((
state
>>
8
)
+
3
)
^
0x1F
;
}
else
{
else
value
=
-
1
;
}
cnt1
=
get_unary
(
b
,
0
,
length
);
cnt1
=
get_unary
(
bc
,
0
,
length
);
if
(
cnt1
>=
length
)
{
cnt1
=
get_bits
(
b
,
nbits
);
cnt1
=
get_bits
(
b
c
,
nbits
);
}
else
{
pfx
=
14
+
((((
uint64_t
)(
value
-
14
))
>>
32
)
&
(
value
-
14
));
if
(
pfx
<
1
||
pfx
>
25
)
return
AVERROR_INVALIDDATA
;
cnt1
*=
(
1
<<
pfx
)
-
1
;
shbits
=
show_bits
(
b
,
pfx
);
shbits
=
show_bits
(
b
c
,
pfx
);
if
(
shbits
<=
1
)
{
skip_bits
(
b
,
pfx
-
1
);
skip_bits
(
b
c
,
pfx
-
1
);
}
else
{
skip_bits
(
b
,
pfx
);
skip_bits
(
b
c
,
pfx
);
cnt1
+=
shbits
-
1
;
}
}
...
...
@@ -265,25 +267,26 @@ static int read_high_coeffs(AVCodecContext *avctx, uint8_t *src, int16_t *dst, i
if
((
uint64_t
)
state
>
0xFF
/
4
||
i
>=
size
)
continue
;
pfx
=
((
state
+
8
)
>>
5
)
+
(
state
?
ff_clz
(
state
)
:
32
)
-
24
;
pfx
=
((
state
+
8
)
>>
5
)
+
(
state
?
ff_clz
(
state
)
:
32
)
-
24
;
escape
=
av_mod_uintp2
(
16383
,
pfx
);
cnt1
=
get_unary
(
b
,
0
,
8
);
cnt1
=
get_unary
(
bc
,
0
,
8
);
if
(
cnt1
<
8
)
{
if
(
pfx
<
1
||
pfx
>
25
)
return
AVERROR_INVALIDDATA
;
value
=
show_bits
(
b
,
pfx
);
value
=
show_bits
(
bc
,
pfx
);
if
(
value
>
1
)
{
skip_bits
(
b
,
pfx
);
skip_bits
(
b
c
,
pfx
);
rlen
=
value
+
escape
*
cnt1
-
1
;
}
else
{
skip_bits
(
b
,
pfx
-
1
);
skip_bits
(
b
c
,
pfx
-
1
);
rlen
=
escape
*
cnt1
;
}
}
else
{
if
(
get_bits1
(
b
))
value
=
get_bits
(
b
,
16
);
if
(
get_bits1
(
b
c
))
value
=
get_bits
(
b
c
,
16
);
else
value
=
get_bits
(
b
,
8
);
value
=
get_bits
(
b
c
,
8
);
rlen
=
value
+
8
*
escape
;
}
...
...
@@ -304,11 +307,12 @@ static int read_high_coeffs(AVCodecContext *avctx, uint8_t *src, int16_t *dst, i
flag
=
rlen
<
0xFFFF
?
1
:
0
;
}
align_get_bits
(
b
);
return
get_bits_count
(
b
)
>>
3
;
align_get_bits
(
b
c
);
return
get_bits_count
(
b
c
)
>>
3
;
}
static
int
read_highpass
(
AVCodecContext
*
avctx
,
uint8_t
*
ptr
,
int
plane
,
AVFrame
*
frame
)
static
int
read_highpass
(
AVCodecContext
*
avctx
,
uint8_t
*
ptr
,
int
plane
,
AVFrame
*
frame
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
ptrdiff_t
stride
=
frame
->
linesize
[
plane
]
/
2
;
...
...
@@ -319,15 +323,16 @@ static int read_highpass(AVCodecContext *avctx, uint8_t *ptr, int plane, AVFrame
int32_t
b
=
bytestream2_get_be32
(
&
ctx
->
gb
);
int32_t
c
=
bytestream2_get_be32
(
&
ctx
->
gb
);
int32_t
d
=
bytestream2_get_be32
(
&
ctx
->
gb
);
int16_t
*
dest
=
(
int16_t
*
)
frame
->
data
[
plane
]
+
ctx
->
band
[
plane
][
i
+
1
].
x
+
stride
*
ctx
->
band
[
plane
][
i
+
1
].
y
;
int16_t
*
dest
=
(
int16_t
*
)
frame
->
data
[
plane
]
+
ctx
->
band
[
plane
][
i
+
1
].
x
+
ctx
->
band
[
plane
][
i
+
1
].
y
*
stride
;
unsigned
size
=
ctx
->
band
[
plane
][
i
+
1
].
size
;
uint32_t
magic
;
uint32_t
magic
=
bytestream2_get_be32
(
&
ctx
->
gb
)
;
magic
=
bytestream2_get_be32
(
&
ctx
->
gb
);
if
(
magic
!=
0xDEADBEEF
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"wrong magic number: 0x%08"
PRIX32
" for plane %d, band %d
\n
"
,
magic
,
plane
,
i
);
if
(
magic
!=
PIXLET_MAGIC
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"wrong magic number: 0x%08"
PRIX32
" for plane %d, band %d
\n
"
,
magic
,
plane
,
i
);
return
AVERROR_INVALIDDATA
;
}
...
...
@@ -338,7 +343,9 @@ static int read_highpass(AVCodecContext *avctx, uint8_t *ptr, int plane, AVFrame
c
,
(
b
>=
FFABS
(
a
))
?
b
:
a
,
d
,
ctx
->
band
[
plane
][
i
+
1
].
width
,
stride
);
if
(
ret
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"error in highpass coefficients for plane %d, band %d
\n
"
,
plane
,
i
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"error in highpass coefficients for plane %d, band %d
\n
"
,
plane
,
i
);
return
ret
;
}
bytestream2_skip
(
&
ctx
->
gb
,
ret
);
...
...
@@ -347,7 +354,8 @@ static int read_highpass(AVCodecContext *avctx, uint8_t *ptr, int plane, AVFrame
return
0
;
}
static
void
lowpass_prediction
(
int16_t
*
dst
,
int16_t
*
pred
,
int
width
,
int
height
,
ptrdiff_t
stride
)
static
void
lowpass_prediction
(
int16_t
*
dst
,
int16_t
*
pred
,
int
width
,
int
height
,
ptrdiff_t
stride
)
{
int16_t
val
;
int
i
,
j
;
...
...
@@ -411,29 +419,28 @@ static void filterfn(int16_t *dest, int16_t *tmp, unsigned size, int64_t scale)
}
}
static
void
reconstruction
(
AVCodecContext
*
avctx
,
int16_t
*
dest
,
unsigned
width
,
unsigned
height
,
ptrdiff_t
stride
,
int
nb_levels
,
int64_t
*
scaling_
H
,
int64_t
*
scaling_V
)
static
void
reconstruction
(
AVCodecContext
*
avctx
,
int16_t
*
dest
,
unsigned
width
,
unsigned
height
,
ptrdiff_t
stride
,
int
nb_levels
,
int64_t
*
scaling_
h
,
int64_t
*
scaling_v
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
unsigned
scaled_width
,
scaled_height
;
int64_t
scale_H
,
scale_V
;
int16_t
*
ptr
,
*
tmp
;
int
i
,
j
,
k
;
scaled_height
=
height
>>
nb_levels
;
scaled_width
=
width
>>
nb_levels
;
scaled_height
=
height
>>
nb_levels
;
tmp
=
ctx
->
filter
[
0
];
for
(
i
=
0
;
i
<
nb_levels
;
i
++
)
{
int64_t
scale_v
=
scaling_v
[
i
];
int64_t
scale_h
=
scaling_h
[
i
];
scaled_width
<<=
1
;
scaled_height
<<=
1
;
scale_H
=
scaling_H
[
i
];
scale_V
=
scaling_V
[
i
];
ptr
=
dest
;
for
(
j
=
0
;
j
<
scaled_height
;
j
++
)
{
filterfn
(
ptr
,
ctx
->
filter
[
1
],
scaled_width
,
scale_
V
);
filterfn
(
ptr
,
ctx
->
filter
[
1
],
scaled_width
,
scale_
v
);
ptr
+=
stride
;
}
...
...
@@ -444,7 +451,7 @@ static void reconstruction(AVCodecContext *avctx,
ptr
+=
stride
;
}
filterfn
(
tmp
,
ctx
->
filter
[
1
],
scaled_height
,
scale_
H
);
filterfn
(
tmp
,
ctx
->
filter
[
1
],
scaled_height
,
scale_
h
);
ptr
=
dest
+
j
;
for
(
k
=
0
;
k
<
scaled_height
;
k
++
)
{
...
...
@@ -501,7 +508,8 @@ static void postprocess_chroma(AVFrame *frame, int w, int h, int depth)
}
}
static
int
decode_plane
(
AVCodecContext
*
avctx
,
int
plane
,
AVPacket
*
avpkt
,
AVFrame
*
frame
)
static
int
decode_plane
(
AVCodecContext
*
avctx
,
int
plane
,
AVPacket
*
avpkt
,
AVFrame
*
frame
)
{
PixletContext
*
ctx
=
avctx
->
priv_data
;
ptrdiff_t
stride
=
frame
->
linesize
[
plane
]
/
2
;
...
...
@@ -525,19 +533,25 @@ static int decode_plane(AVCodecContext *avctx, int plane, AVPacket *avpkt, AVFra
dst
=
(
int16_t
*
)
frame
->
data
[
plane
];
dst
[
0
]
=
sign_extend
(
bytestream2_get_be16
(
&
ctx
->
gb
),
16
);
if
((
ret
=
init_get_bits8
(
&
ctx
->
gbit
,
avpkt
->
data
+
bytestream2_tell
(
&
ctx
->
gb
),
bytestream2_get_bytes_left
(
&
ctx
->
gb
)))
<
0
)
ret
=
init_get_bits8
(
&
ctx
->
bc
,
avpkt
->
data
+
bytestream2_tell
(
&
ctx
->
gb
),
bytestream2_get_bytes_left
(
&
ctx
->
gb
));
if
(
ret
<
0
)
return
ret
;
ret
=
read_low_coeffs
(
avctx
,
dst
+
1
,
ctx
->
band
[
plane
][
0
].
width
-
1
,
ctx
->
band
[
plane
][
0
].
width
-
1
,
0
);
ret
=
read_low_coeffs
(
avctx
,
dst
+
1
,
ctx
->
band
[
plane
][
0
].
width
-
1
,
ctx
->
band
[
plane
][
0
].
width
-
1
,
0
);
if
(
ret
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"error in lowpass coefficients for plane %d, top row
\n
"
,
plane
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"error in lowpass coefficients for plane %d, top row
\n
"
,
plane
);
return
ret
;
}
ret
=
read_low_coeffs
(
avctx
,
dst
+
stride
,
ctx
->
band
[
plane
][
0
].
height
-
1
,
1
,
stride
);
ret
=
read_low_coeffs
(
avctx
,
dst
+
stride
,
ctx
->
band
[
plane
][
0
].
height
-
1
,
1
,
stride
);
if
(
ret
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"error in lowpass coefficients for plane %d, left column
\n
"
,
plane
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"error in lowpass coefficients for plane %d, left column
\n
"
,
plane
);
return
ret
;
}
...
...
@@ -545,7 +559,8 @@ static int decode_plane(AVCodecContext *avctx, int plane, AVPacket *avpkt, AVFra
(
ctx
->
band
[
plane
][
0
].
width
-
1
)
*
(
ctx
->
band
[
plane
][
0
].
height
-
1
),
ctx
->
band
[
plane
][
0
].
width
-
1
,
stride
);
if
(
ret
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"error in lowpass coefficients for plane %d, rest
\n
"
,
plane
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"error in lowpass coefficients for plane %d, rest
\n
"
,
plane
);
return
ret
;
}
...
...
@@ -559,11 +574,12 @@ static int decode_plane(AVCodecContext *avctx, int plane, AVPacket *avpkt, AVFra
if
(
ret
<
0
)
return
ret
;
lowpass_prediction
(
dst
,
ctx
->
prediction
,
ctx
->
band
[
plane
][
0
].
width
,
ctx
->
band
[
plane
][
0
].
height
,
stride
);
lowpass_prediction
(
dst
,
ctx
->
prediction
,
ctx
->
band
[
plane
][
0
].
width
,
ctx
->
band
[
plane
][
0
].
height
,
stride
);
reconstruction
(
avctx
,
(
int16_t
*
)
frame
->
data
[
plane
],
ctx
->
w
>>
shift
,
ctx
->
h
>>
shift
,
stride
,
NB_LEVELS
,
ctx
->
scaling
[
plane
][
H
],
ctx
->
scaling
[
plane
][
V
]);
reconstruction
(
avctx
,
(
int16_t
*
)
frame
->
data
[
plane
],
ctx
->
w
>>
shift
,
ctx
->
h
>>
shift
,
stride
,
NB_LEVELS
,
ctx
->
scaling
[
plane
][
H
],
ctx
->
scaling
[
plane
][
V
]);
return
0
;
}
...
...
@@ -667,11 +683,12 @@ static int pixlet_init_thread_copy(AVCodecContext *avctx)
ctx
->
filter
[
0
]
=
NULL
;
ctx
->
filter
[
1
]
=
NULL
;
ctx
->
prediction
=
NULL
;
ctx
->
w
=
ctx
->
h
=
0
;
ctx
->
w
=
0
;
ctx
->
h
=
0
;
return
0
;
}
#endif
#endif
/* HAVE_THREADS */
AVCodec
ff_pixlet_decoder
=
{
.
name
=
"pixlet"
,
...
...
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