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
9f2fa95b
Commit
9f2fa95b
authored
Aug 25, 2015
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/vf_histogram: 9 and 10 bit depth support
Signed-off-by:
Paul B Mahol
<
onemda@gmail.com
>
parent
53bf32fa
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
30 deletions
+106
-30
vf_histogram.c
libavfilter/vf_histogram.c
+106
-30
No files found.
libavfilter/vf_histogram.c
View file @
9f2fa95b
...
@@ -22,6 +22,8 @@
...
@@ -22,6 +22,8 @@
#include "libavutil/opt.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/parseutils.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixdesc.h"
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
#include "avfilter.h"
#include "avfilter.h"
#include "formats.h"
#include "formats.h"
#include "internal.h"
#include "internal.h"
...
@@ -38,7 +40,9 @@ enum HistogramMode {
...
@@ -38,7 +40,9 @@ enum HistogramMode {
typedef
struct
HistogramContext
{
typedef
struct
HistogramContext
{
const
AVClass
*
class
;
///< AVClass context for log and options purpose
const
AVClass
*
class
;
///< AVClass context for log and options purpose
int
mode
;
///< HistogramMode
int
mode
;
///< HistogramMode
unsigned
histogram
[
256
];
unsigned
histogram
[
256
*
256
];
int
histogram_size
;
int
mult
;
int
ncomp
;
int
ncomp
;
const
uint8_t
*
bg_color
;
const
uint8_t
*
bg_color
;
const
uint8_t
*
fg_color
;
const
uint8_t
*
fg_color
;
...
@@ -94,21 +98,46 @@ static const enum AVPixelFormat levels_in_pix_fmts[] = {
...
@@ -94,21 +98,46 @@ static const enum AVPixelFormat levels_in_pix_fmts[] = {
AV_PIX_FMT_YUV411P
,
AV_PIX_FMT_YUVJ411P
,
AV_PIX_FMT_YUV411P
,
AV_PIX_FMT_YUVJ411P
,
AV_PIX_FMT_YUV440P
,
AV_PIX_FMT_YUV410P
,
AV_PIX_FMT_YUV440P
,
AV_PIX_FMT_YUV410P
,
AV_PIX_FMT_YUVA444P
,
AV_PIX_FMT_YUV444P
,
AV_PIX_FMT_YUVJ444P
,
AV_PIX_FMT_YUVA444P
,
AV_PIX_FMT_YUV444P
,
AV_PIX_FMT_YUVJ444P
,
AV_PIX_FMT_YUV420P9
,
AV_PIX_FMT_YUV422P9
,
AV_PIX_FMT_YUV444P9
,
AV_PIX_FMT_YUVA420P9
,
AV_PIX_FMT_YUVA422P9
,
AV_PIX_FMT_YUVA444P9
,
AV_PIX_FMT_YUV420P10
,
AV_PIX_FMT_YUV422P10
,
AV_PIX_FMT_YUV444P10
,
AV_PIX_FMT_YUVA420P10
,
AV_PIX_FMT_YUVA422P10
,
AV_PIX_FMT_YUVA444P10
,
AV_PIX_FMT_GBRAP
,
AV_PIX_FMT_GBRP
,
AV_PIX_FMT_GBRAP
,
AV_PIX_FMT_GBRP
,
AV_PIX_FMT_GBRP9
,
AV_PIX_FMT_GBRP10
,
AV_PIX_FMT_GRAY8
,
AV_PIX_FMT_GRAY8
,
AV_PIX_FMT_NONE
AV_PIX_FMT_NONE
};
};
static
const
enum
AVPixelFormat
levels_out_yuv_pix_fmts
[]
=
{
static
const
enum
AVPixelFormat
levels_out_yuv
8
_pix_fmts
[]
=
{
AV_PIX_FMT_YUVA444P
,
AV_PIX_FMT_YUV444P
,
AV_PIX_FMT_YUVA444P
,
AV_PIX_FMT_YUV444P
,
AV_PIX_FMT_NONE
AV_PIX_FMT_NONE
};
};
static
const
enum
AVPixelFormat
levels_out_rgb_pix_fmts
[]
=
{
static
const
enum
AVPixelFormat
levels_out_yuv9_pix_fmts
[]
=
{
AV_PIX_FMT_YUVA444P9
,
AV_PIX_FMT_YUV444P9
,
AV_PIX_FMT_NONE
};
static
const
enum
AVPixelFormat
levels_out_yuv10_pix_fmts
[]
=
{
AV_PIX_FMT_YUVA444P10
,
AV_PIX_FMT_YUV444P10
,
AV_PIX_FMT_NONE
};
static
const
enum
AVPixelFormat
levels_out_rgb8_pix_fmts
[]
=
{
AV_PIX_FMT_GBRAP
,
AV_PIX_FMT_GBRP
,
AV_PIX_FMT_GBRAP
,
AV_PIX_FMT_GBRP
,
AV_PIX_FMT_NONE
AV_PIX_FMT_NONE
};
};
static
const
enum
AVPixelFormat
levels_out_rgb9_pix_fmts
[]
=
{
AV_PIX_FMT_GBRP9
,
AV_PIX_FMT_NONE
};
static
const
enum
AVPixelFormat
levels_out_rgb10_pix_fmts
[]
=
{
AV_PIX_FMT_GBRP10
,
AV_PIX_FMT_NONE
};
static
const
enum
AVPixelFormat
waveform_pix_fmts
[]
=
{
static
const
enum
AVPixelFormat
waveform_pix_fmts
[]
=
{
AV_PIX_FMT_GBRP
,
AV_PIX_FMT_GBRAP
,
AV_PIX_FMT_GBRP
,
AV_PIX_FMT_GBRAP
,
AV_PIX_FMT_YUV422P
,
AV_PIX_FMT_YUV420P
,
AV_PIX_FMT_YUV422P
,
AV_PIX_FMT_YUV420P
,
...
@@ -136,7 +165,7 @@ static int query_formats(AVFilterContext *ctx)
...
@@ -136,7 +165,7 @@ static int query_formats(AVFilterContext *ctx)
AVFilterFormats
*
avff
;
AVFilterFormats
*
avff
;
const
AVPixFmtDescriptor
*
desc
;
const
AVPixFmtDescriptor
*
desc
;
const
enum
AVPixelFormat
*
out_pix_fmts
;
const
enum
AVPixelFormat
*
out_pix_fmts
;
int
rgb
,
i
;
int
rgb
,
i
,
bits
;
if
(
!
ctx
->
inputs
[
0
]
->
in_formats
||
if
(
!
ctx
->
inputs
[
0
]
->
in_formats
||
!
ctx
->
inputs
[
0
]
->
in_formats
->
nb_formats
)
{
!
ctx
->
inputs
[
0
]
->
in_formats
->
nb_formats
)
{
...
@@ -148,16 +177,26 @@ static int query_formats(AVFilterContext *ctx)
...
@@ -148,16 +177,26 @@ static int query_formats(AVFilterContext *ctx)
avff
=
ctx
->
inputs
[
0
]
->
in_formats
;
avff
=
ctx
->
inputs
[
0
]
->
in_formats
;
desc
=
av_pix_fmt_desc_get
(
avff
->
formats
[
0
]);
desc
=
av_pix_fmt_desc_get
(
avff
->
formats
[
0
]);
rgb
=
desc
->
flags
&
AV_PIX_FMT_FLAG_RGB
;
rgb
=
desc
->
flags
&
AV_PIX_FMT_FLAG_RGB
;
bits
=
desc
->
comp
[
0
].
depth_minus1
;
for
(
i
=
1
;
i
<
avff
->
nb_formats
;
i
++
)
{
for
(
i
=
1
;
i
<
avff
->
nb_formats
;
i
++
)
{
desc
=
av_pix_fmt_desc_get
(
avff
->
formats
[
i
]);
desc
=
av_pix_fmt_desc_get
(
avff
->
formats
[
i
]);
if
(
rgb
!=
(
desc
->
flags
&
AV_PIX_FMT_FLAG_RGB
))
if
((
rgb
!=
desc
->
flags
&
AV_PIX_FMT_FLAG_RGB
)
||
(
bits
!=
desc
->
comp
[
0
].
depth_minus1
))
return
AVERROR
(
EAGAIN
);
return
AVERROR
(
EAGAIN
);
}
}
if
(
rgb
)
if
(
rgb
&&
bits
==
7
)
out_pix_fmts
=
levels_out_rgb_pix_fmts
;
out_pix_fmts
=
levels_out_rgb8_pix_fmts
;
else
else
if
(
rgb
&&
bits
==
8
)
out_pix_fmts
=
levels_out_yuv_pix_fmts
;
out_pix_fmts
=
levels_out_rgb9_pix_fmts
;
else
if
(
rgb
&&
bits
==
9
)
out_pix_fmts
=
levels_out_rgb10_pix_fmts
;
else
if
(
bits
==
7
)
out_pix_fmts
=
levels_out_yuv8_pix_fmts
;
else
if
(
bits
==
8
)
out_pix_fmts
=
levels_out_yuv9_pix_fmts
;
else
// if (bits == 9)
out_pix_fmts
=
levels_out_yuv10_pix_fmts
;
ff_formats_ref
(
ff_make_format_list
(
out_pix_fmts
),
&
ctx
->
outputs
[
0
]
->
in_formats
);
ff_formats_ref
(
ff_make_format_list
(
out_pix_fmts
),
&
ctx
->
outputs
[
0
]
->
in_formats
);
return
0
;
return
0
;
...
@@ -188,8 +227,12 @@ static int config_input(AVFilterLink *inlink)
...
@@ -188,8 +227,12 @@ static int config_input(AVFilterLink *inlink)
h
->
desc
=
av_pix_fmt_desc_get
(
inlink
->
format
);
h
->
desc
=
av_pix_fmt_desc_get
(
inlink
->
format
);
h
->
ncomp
=
h
->
desc
->
nb_components
;
h
->
ncomp
=
h
->
desc
->
nb_components
;
h
->
histogram_size
=
1
<<
(
h
->
desc
->
comp
[
0
].
depth_minus1
+
1
);
h
->
mult
=
h
->
histogram_size
/
256
;
switch
(
inlink
->
format
)
{
switch
(
inlink
->
format
)
{
case
AV_PIX_FMT_GBRP10
:
case
AV_PIX_FMT_GBRP9
:
case
AV_PIX_FMT_GBRAP
:
case
AV_PIX_FMT_GBRAP
:
case
AV_PIX_FMT_GBRP
:
case
AV_PIX_FMT_GBRP
:
h
->
bg_color
=
black_gbrp_color
;
h
->
bg_color
=
black_gbrp_color
;
...
@@ -220,7 +263,7 @@ static int config_output(AVFilterLink *outlink)
...
@@ -220,7 +263,7 @@ static int config_output(AVFilterLink *outlink)
if
((
1
<<
i
)
&
h
->
components
)
if
((
1
<<
i
)
&
h
->
components
)
ncomp
++
;
ncomp
++
;
}
}
outlink
->
w
=
256
;
outlink
->
w
=
h
->
histogram_size
;
outlink
->
h
=
(
h
->
level_height
+
h
->
scale_height
)
*
FFMAX
(
ncomp
*
h
->
display_mode
,
1
);
outlink
->
h
=
(
h
->
level_height
+
h
->
scale_height
)
*
FFMAX
(
ncomp
*
h
->
display_mode
,
1
);
break
;
break
;
case
MODE_WAVEFORM
:
case
MODE_WAVEFORM
:
...
@@ -298,7 +341,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
...
@@ -298,7 +341,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
AVFilterContext
*
ctx
=
inlink
->
dst
;
AVFilterContext
*
ctx
=
inlink
->
dst
;
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
AVFrame
*
out
;
AVFrame
*
out
;
const
uint8_t
*
src
;
uint8_t
*
dst
;
uint8_t
*
dst
;
int
i
,
j
,
k
,
l
,
m
;
int
i
,
j
,
k
,
l
,
m
;
...
@@ -314,10 +356,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
...
@@ -314,10 +356,21 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
const
int
is_chroma
=
(
k
==
1
||
k
==
2
);
const
int
is_chroma
=
(
k
==
1
||
k
==
2
);
const
int
dst_h
=
FF_CEIL_RSHIFT
(
outlink
->
h
,
(
is_chroma
?
h
->
odesc
->
log2_chroma_h
:
0
));
const
int
dst_h
=
FF_CEIL_RSHIFT
(
outlink
->
h
,
(
is_chroma
?
h
->
odesc
->
log2_chroma_h
:
0
));
const
int
dst_w
=
FF_CEIL_RSHIFT
(
outlink
->
w
,
(
is_chroma
?
h
->
odesc
->
log2_chroma_w
:
0
));
const
int
dst_w
=
FF_CEIL_RSHIFT
(
outlink
->
w
,
(
is_chroma
?
h
->
odesc
->
log2_chroma_w
:
0
));
if
(
h
->
histogram_size
<=
256
)
{
for
(
i
=
0
;
i
<
dst_h
;
i
++
)
for
(
i
=
0
;
i
<
dst_h
;
i
++
)
memset
(
out
->
data
[
h
->
odesc
->
comp
[
k
].
plane
]
+
memset
(
out
->
data
[
h
->
odesc
->
comp
[
k
].
plane
]
+
i
*
out
->
linesize
[
h
->
odesc
->
comp
[
k
].
plane
],
i
*
out
->
linesize
[
h
->
odesc
->
comp
[
k
].
plane
],
h
->
bg_color
[
k
],
dst_w
);
h
->
bg_color
[
k
],
dst_w
);
}
else
{
const
int
mult
=
h
->
mult
;
for
(
i
=
0
;
i
<
dst_h
;
i
++
)
for
(
j
=
0
;
j
<
dst_w
;
j
++
)
AV_WN16
(
out
->
data
[
h
->
odesc
->
comp
[
k
].
plane
]
+
i
*
out
->
linesize
[
h
->
odesc
->
comp
[
k
].
plane
]
+
j
*
2
,
h
->
bg_color
[
k
]
*
mult
);
}
}
}
switch
(
h
->
mode
)
{
switch
(
h
->
mode
)
{
...
@@ -326,21 +379,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
...
@@ -326,21 +379,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
const
int
p
=
h
->
desc
->
comp
[
k
].
plane
;
const
int
p
=
h
->
desc
->
comp
[
k
].
plane
;
const
int
height
=
h
->
planeheight
[
p
];
const
int
height
=
h
->
planeheight
[
p
];
const
int
width
=
h
->
planewidth
[
p
];
const
int
width
=
h
->
planewidth
[
p
];
int
start
;
double
max_hval_log
;
double
max_hval_log
;
unsigned
max_hval
=
0
;
unsigned
max_hval
=
0
;
int
start
;
if
(
!
((
1
<<
k
)
&
h
->
components
))
if
(
!
((
1
<<
k
)
&
h
->
components
))
continue
;
continue
;
start
=
m
++
*
(
h
->
level_height
+
h
->
scale_height
)
*
h
->
display_mode
;
start
=
m
++
*
(
h
->
level_height
+
h
->
scale_height
)
*
h
->
display_mode
;
if
(
h
->
histogram_size
<=
256
)
{
for
(
i
=
0
;
i
<
height
;
i
++
)
{
for
(
i
=
0
;
i
<
height
;
i
++
)
{
src
=
in
->
data
[
p
]
+
i
*
in
->
linesize
[
p
];
const
uint8_t
*
src
=
in
->
data
[
p
]
+
i
*
in
->
linesize
[
p
];
for
(
j
=
0
;
j
<
width
;
j
++
)
for
(
j
=
0
;
j
<
width
;
j
++
)
h
->
histogram
[
src
[
j
]]
++
;
h
->
histogram
[
src
[
j
]]
++
;
}
}
}
else
{
for
(
i
=
0
;
i
<
height
;
i
++
)
{
const
uint16_t
*
src
=
(
const
uint16_t
*
)(
in
->
data
[
p
]
+
i
*
in
->
linesize
[
p
]);
for
(
j
=
0
;
j
<
width
;
j
++
)
h
->
histogram
[
src
[
j
]]
++
;
}
}
for
(
i
=
0
;
i
<
256
;
i
++
)
for
(
i
=
0
;
i
<
h
->
histogram_size
;
i
++
)
max_hval
=
FFMAX
(
max_hval
,
h
->
histogram
[
i
]);
max_hval
=
FFMAX
(
max_hval
,
h
->
histogram
[
i
]);
max_hval_log
=
log2
(
max_hval
+
1
);
max_hval_log
=
log2
(
max_hval
+
1
);
...
@@ -352,6 +413,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
...
@@ -352,6 +413,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
else
else
col_height
=
h
->
level_height
-
(
h
->
histogram
[
i
]
*
(
int64_t
)
h
->
level_height
+
max_hval
-
1
)
/
max_hval
;
col_height
=
h
->
level_height
-
(
h
->
histogram
[
i
]
*
(
int64_t
)
h
->
level_height
+
max_hval
-
1
)
/
max_hval
;
if
(
h
->
histogram_size
<=
256
)
{
for
(
j
=
h
->
level_height
-
1
;
j
>=
col_height
;
j
--
)
{
for
(
j
=
h
->
level_height
-
1
;
j
>=
col_height
;
j
--
)
{
if
(
h
->
display_mode
)
{
if
(
h
->
display_mode
)
{
for
(
l
=
0
;
l
<
h
->
ncomp
;
l
++
)
for
(
l
=
0
;
l
<
h
->
ncomp
;
l
++
)
...
@@ -362,9 +424,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
...
@@ -362,9 +424,23 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
}
for
(
j
=
h
->
level_height
+
h
->
scale_height
-
1
;
j
>=
h
->
level_height
;
j
--
)
for
(
j
=
h
->
level_height
+
h
->
scale_height
-
1
;
j
>=
h
->
level_height
;
j
--
)
out
->
data
[
p
][(
j
+
start
)
*
out
->
linesize
[
p
]
+
i
]
=
i
;
out
->
data
[
p
][(
j
+
start
)
*
out
->
linesize
[
p
]
+
i
]
=
i
;
}
else
{
const
int
mult
=
h
->
mult
;
for
(
j
=
h
->
level_height
-
1
;
j
>=
col_height
;
j
--
)
{
if
(
h
->
display_mode
)
{
for
(
l
=
0
;
l
<
h
->
ncomp
;
l
++
)
AV_WN16
(
out
->
data
[
l
]
+
(
j
+
start
)
*
out
->
linesize
[
l
]
+
i
*
2
,
h
->
fg_color
[
l
]
*
mult
);
}
else
{
AV_WN16
(
out
->
data
[
p
]
+
(
j
+
start
)
*
out
->
linesize
[
p
]
+
i
*
2
,
255
*
mult
);
}
}
for
(
j
=
h
->
level_height
+
h
->
scale_height
-
1
;
j
>=
h
->
level_height
;
j
--
)
AV_WN16
(
out
->
data
[
p
]
+
(
j
+
start
)
*
out
->
linesize
[
p
]
+
i
*
2
,
i
);
}
}
}
memset
(
h
->
histogram
,
0
,
256
*
sizeof
(
unsigned
));
memset
(
h
->
histogram
,
0
,
h
->
histogram_size
*
sizeof
(
unsigned
));
}
}
break
;
break
;
case
MODE_WAVEFORM
:
case
MODE_WAVEFORM
:
...
...
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