72 #define OFFSET(x) offsetof(SSIMContext, x)
73 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
86 snprintf(value,
sizeof(value),
"%0.2f", d);
89 snprintf(key2,
sizeof(key2),
"%s%c", key, comp);
97 const uint8_t *ref8, ptrdiff_t ref_stride,
98 int64_t (*sums)[4],
int width)
100 const uint16_t *main16 = (
const uint16_t *)main8;
101 const uint16_t *ref16 = (
const uint16_t *)ref8;
107 for (z = 0; z <
width; z++) {
108 uint64_t
s1 = 0,
s2 = 0,
ss = 0, s12 = 0;
110 for (y = 0; y < 4; y++) {
111 for (x = 0; x < 4; x++) {
112 unsigned a = main16[x + y * main_stride];
113 unsigned b = ref16[x + y * ref_stride];
134 int (*sums)[4],
int width)
138 for (z = 0; z <
width; z++) {
139 uint32_t
s1 = 0,
s2 = 0,
ss = 0, s12 = 0;
141 for (y = 0; y < 4; y++) {
142 for (x = 0; x < 4; x++) {
143 int a = main[x + y * main_stride];
144 int b = ref[x + y * ref_stride];
165 int64_t ssim_c1 = (int64_t)(.01*.01*max*max*64 + .5);
166 int64_t ssim_c2 = (int64_t)(.03*.03*max*max*64*63 + .5);
172 int64_t
vars = fss * 64 - fs1 * fs1 - fs2 * fs2;
173 int64_t covar = fs12 * 64 - fs1 * fs2;
175 return (
float)(2 * fs1 * fs2 + ssim_c1) * (
float)(2 * covar + ssim_c2)
176 / ((
float)(fs1 * fs1 + fs2 * fs2 + ssim_c1) * (
float)(vars + ssim_c2));
181 static const int ssim_c1 = (
int)(.01*.01*255*255*64 + .5);
182 static const int ssim_c2 = (
int)(.03*.03*255*255*64*63 + .5);
188 int vars = fss * 64 - fs1 * fs1 - fs2 * fs2;
189 int covar = fs12 * 64 - fs1 * fs2;
191 return (
float)(2 * fs1 * fs2 + ssim_c1) * (
float)(2 * covar + ssim_c2)
192 / ((
float)(fs1 * fs1 + fs2 * fs2 + ssim_c1) * (
float)(vars + ssim_c2));
200 for (i = 0; i <
width; i++)
201 ssim +=
ssim_end1x(sum0[i][0] + sum0[i + 1][0] + sum1[i][0] + sum1[i + 1][0],
202 sum0[i][1] + sum0[i + 1][1] + sum1[i][1] + sum1[i + 1][1],
203 sum0[i][2] + sum0[i + 1][2] + sum1[i][2] + sum1[i + 1][2],
204 sum0[i][3] + sum0[i + 1][3] + sum1[i][3] + sum1[i + 1][3],
214 for (i = 0; i <
width; i++)
215 ssim +=
ssim_end1(sum0[i][0] + sum0[i + 1][0] + sum1[i][0] + sum1[i + 1][0],
216 sum0[i][1] + sum0[i + 1][1] + sum1[i][1] + sum1[i + 1][1],
217 sum0[i][2] + sum0[i + 1][2] + sum1[i][2] + sum1[i + 1][2],
218 sum0[i][3] + sum0[i + 1][3] + sum1[i][3] + sum1[i + 1][3]);
222 #define SUM_LEN(w) (((w) >> 2) + 3)
225 uint8_t *main,
int main_stride,
232 int64_t (*sum0)[4] =
temp;
233 int64_t (*sum1)[4] = sum0 +
SUM_LEN(width);
238 for (y = 1; y <
height; y++) {
239 for (; z <= y; z++) {
240 FFSWAP(
void*, sum0, sum1);
242 &ref[4 * z * ref_stride], ref_stride,
246 ssim +=
ssim_endn_16bit((
const int64_t (*)[4])sum0, (
const int64_t (*)[4])sum1, width - 1, max);
249 return ssim / ((height - 1) * (width - 1));
253 uint8_t *main,
int main_stride,
266 for (y = 1; y <
height; y++) {
267 for (; z <= y; z++) {
268 FFSWAP(
void*, sum0, sum1);
270 &ref[4 * z * ref_stride], ref_stride,
274 ssim += dsp->
ssim_end_line((
const int (*)[4])sum0, (
const int (*)[4])sum1, width - 1);
277 return ssim / ((height - 1) * (width - 1));
282 return 10 * log10(weight / (weight - ssim));
291 float c[4], ssimv = 0.0;
308 ssimv += s->
coefs[i] * c[i];
317 set_meta(metadata,
"lavfi.ssim.All", 0, ssimv);
368 #define PF(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf, AV_PIX_FMT_GBR##suf
437 outlink->
w = mainlink->
w;
438 outlink->
h = mainlink->
h;
504 .preinit = ssim_framesync_preinit,
510 .priv_class = &ssim_class,
float(* ssim_plane)(SSIMDSPContext *dsp, uint8_t *main, int main_stride, uint8_t *ref, int ref_stride, int width, int height, void *temp, int max)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static av_cold void uninit(AVFilterContext *ctx)
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
int h
agreed upon image height
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
static void ssim_4x4xn_8bit(const uint8_t *main, ptrdiff_t main_stride, const uint8_t *ref, ptrdiff_t ref_stride, int(*sums)[4], int width)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define AV_PIX_FMT_GRAY10
const char * name
Pad name.
AVFilterContext * parent
Parent filter context.
#define AV_PIX_FMT_GRAY12
FRAMESYNC_DEFINE_CLASS(ssim, SSIMContext, fs)
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static av_cold int init(AVFilterContext *ctx)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
static const AVFilterPad ssim_inputs[]
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
static void ssim_4x4xn_16bit(const uint8_t *main8, ptrdiff_t main_stride, const uint8_t *ref8, ptrdiff_t ref_stride, int64_t(*sums)[4], int width)
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
AVDictionary * metadata
metadata.
static float ssim_end1(int s1, int s2, int ss, int s12)
int main(int argc, char *argv[])
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void ff_ssim_init_x86(SSIMDSPContext *dsp)
void * priv
private data for use by the filter
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
uint8_t nb_components
The number of components each pixel has, (1-4)
#define AV_PIX_FMT_GRAY16
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
GLsizei GLboolean const GLfloat * value
AVFilterContext * src
source filter
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
int format
agreed upon media format
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
static const AVOption ssim_options[]
static const uint8_t vars[2][12]
#define AV_LOG_INFO
Standard information.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static float ssim_plane(SSIMDSPContext *dsp, uint8_t *main, int main_stride, uint8_t *ref, int ref_stride, int width, int height, void *temp, int max)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static int config_input_ref(AVFilterLink *inlink)
Describe the class of an AVClass context structure.
void(* ssim_4x4_line)(const uint8_t *buf, ptrdiff_t buf_stride, const uint8_t *ref, ptrdiff_t ref_stride, int(*sums)[4], int w)
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
const char * name
Filter name.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterLink ** outputs
array of pointers to output links
static int weight(int i, int blen, int offset)
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
static double ssim_db(double ssim, double weight)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int activate(AVFilterContext *ctx)
static int ref[MAX_W *MAX_W]
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static int config_output(AVFilterLink *outlink)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static float ssim_endn_16bit(const int64_t(*sum0)[4], const int64_t(*sum1)[4], int width, int max)
static float ssim_end1x(int64_t s1, int64_t s2, int64_t ss, int64_t s12, int max)
static const AVFilterPad ssim_outputs[]
AVFilterContext * dst
dest filter
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
float(* ssim_end_line)(const int(*sum0)[4], const int(*sum1)[4], int w)
static int query_formats(AVFilterContext *ctx)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static float ssim_endn_8bit(const int(*sum0)[4], const int(*sum1)[4], int width)
#define FFSWAP(type, a, b)
static float ssim_plane_16bit(SSIMDSPContext *dsp, uint8_t *main, int main_stride, uint8_t *ref, int ref_stride, int width, int height, void *temp, int max)
int depth
Number of bits in the component.
static int do_ssim(FFFrameSync *fs)
static void set_meta(AVDictionary **metadata, const char *key, char comp, float d)
AVPixelFormat
Pixel format.
void * av_mallocz_array(size_t nmemb, size_t size)
#define AV_CEIL_RSHIFT(a, b)