|
| 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 | +}; |
0 commit comments