Skip to content

Commit fd3c796

Browse files
kylophoneli-zhi
authored andcommitted
libvmaf: implement vmaf_fex_float_ms_ssim
1 parent 797d512 commit fd3c796

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

libvmaf/src/feature/feature_extractor.c

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern VmafFeatureExtractor vmaf_fex_float_psnr;
1111
extern VmafFeatureExtractor vmaf_fex_float_adm;
1212
extern VmafFeatureExtractor vmaf_fex_float_vif;
1313
extern VmafFeatureExtractor vmaf_fex_float_motion;
14+
extern VmafFeatureExtractor vmaf_fex_float_ms_ssim;
1415

1516
static VmafFeatureExtractor *feature_extractor_list[] = {
1617
&vmaf_fex_ssim,
@@ -20,6 +21,7 @@ static VmafFeatureExtractor *feature_extractor_list[] = {
2021
&vmaf_fex_float_adm,
2122
&vmaf_fex_float_vif,
2223
&vmaf_fex_float_motion,
24+
&vmaf_fex_float_ms_ssim,
2325
NULL
2426
};
2527

libvmaf/src/feature/float_ms_ssim.c

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <errno.h>
2+
3+
#include "feature_collector.h"
4+
#include "feature_extractor.h"
5+
6+
#include "mem.h"
7+
#include "ms_ssim.h"
8+
#include "picture_copy.h"
9+
10+
typedef struct MsSsimState {
11+
size_t float_stride;
12+
float *ref;
13+
float *dist;
14+
} MsSsimState;
15+
16+
static int init(VmafFeatureExtractor *fex, enum VmafPixelFormat pix_fmt,
17+
unsigned bpc, unsigned w, unsigned h)
18+
{
19+
MsSsimState *s = fex->priv;
20+
s->float_stride = sizeof(float) * w;
21+
s->ref = aligned_malloc(s->float_stride * h, 32);
22+
if (!s->ref) goto fail;
23+
s->dist = aligned_malloc(s->float_stride * h, 32);
24+
if (!s->dist) goto free_ref;
25+
26+
return 0;
27+
28+
free_ref:
29+
free(s->ref);
30+
fail:
31+
return -ENOMEM;
32+
}
33+
34+
static int extract(VmafFeatureExtractor *fex,
35+
VmafPicture *ref_pic, VmafPicture *dist_pic,
36+
unsigned index, VmafFeatureCollector *feature_collector)
37+
{
38+
MsSsimState *s = fex->priv;
39+
int err = 0;
40+
41+
picture_copy(s->ref, ref_pic, 0);
42+
picture_copy(s->dist, dist_pic, 0);
43+
44+
double score, l_scores[5], c_scores[5], s_scores[5];
45+
err = compute_ms_ssim(s->ref, s->dist, ref_pic->w[0], ref_pic->h[0],
46+
s->float_stride, s->float_stride,
47+
&score, l_scores, c_scores, s_scores);
48+
if (err) return err;
49+
err = vmaf_feature_collector_append(feature_collector, "float_ms_ssim",
50+
score, index);
51+
if (err) return err;
52+
return 0;
53+
}
54+
55+
static int close(VmafFeatureExtractor *fex)
56+
{
57+
MsSsimState *s = fex->priv;
58+
if (s->ref) aligned_free(s->ref);
59+
if (s->dist) aligned_free(s->dist);
60+
return 0;
61+
}
62+
63+
static const char *provided_features[] = {
64+
"float_ms_ssim",
65+
NULL
66+
};
67+
68+
VmafFeatureExtractor vmaf_fex_float_ms_ssim = {
69+
.name = "float_ms_ssim",
70+
.init = init,
71+
.extract = extract,
72+
.close = close,
73+
.priv_size = sizeof(MsSsimState),
74+
.provided_features = provided_features,
75+
};

libvmaf/src/feature/ms_ssim.h

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int compute_ms_ssim(const float *ref, const float *cmp, int w, int h,
2+
int ref_stride, int cmp_stride, double *score,
3+
double* l_scores, double* c_scores, double* s_scores);

libvmaf/src/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ libvmaf_rc_feature_sources = [
160160
feature_src_dir + 'float_psnr.c',
161161
feature_src_dir + 'float_motion.c',
162162
feature_src_dir + 'float_ssim.c',
163+
feature_src_dir + 'float_ms_ssim.c',
163164
feature_src_dir + 'float_vif.c',
164165
feature_src_dir + 'integer_ssim.c',
165166
]

0 commit comments

Comments
 (0)