1
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
5
6 #include <schroedinger/schro.h>
7 #include <schroedinger/schroorc.h>
8
9 void
schro_encoder_frame_downsample(SchroEncoderFrame * frame)10 schro_encoder_frame_downsample (SchroEncoderFrame * frame)
11 {
12 int i;
13 SchroFrame *last;
14
15 SCHRO_DEBUG ("downsampling frame %d", frame->frame_number);
16
17 last = frame->filtered_frame;
18 for (i = 0; i < frame->encoder->downsample_levels; i++) {
19 frame->downsampled_frames[i] =
20 schro_frame_new_and_alloc_extended (NULL, frame->filtered_frame->format,
21 ROUND_UP_SHIFT (frame->filtered_frame->width, i + 1),
22 ROUND_UP_SHIFT (frame->filtered_frame->height, i + 1),
23 MAX (frame->params.xbsep_luma, frame->params.ybsep_luma));
24 schro_frame_downsample (frame->downsampled_frames[i], last);
25 schro_frame_mc_edgeextend (frame->downsampled_frames[i]);
26 last = frame->downsampled_frames[i];
27 }
28 }
29
30 void
schro_encoder_frame_upsample(SchroEncoderFrame * frame)31 schro_encoder_frame_upsample (SchroEncoderFrame * frame)
32 {
33 SCHRO_ASSERT (frame);
34 SCHRO_DEBUG ("upsampling frame %d", frame->frame_number);
35
36 if (frame->upsampled_original_frame) {
37 return;
38 }
39 schro_frame_ref (frame->filtered_frame);
40 frame->upsampled_original_frame =
41 schro_upsampled_frame_new (frame->filtered_frame);
42 schro_upsampled_frame_upsample (frame->upsampled_original_frame);
43 }
44
45 static double
schro_frame_component_squared_error(SchroFrameData * a,SchroFrameData * b)46 schro_frame_component_squared_error (SchroFrameData * a, SchroFrameData * b)
47 {
48 int j;
49 double sum;
50
51 SCHRO_ASSERT (a->width == b->width);
52 SCHRO_ASSERT (a->height == b->height);
53
54 sum = 0;
55 for (j = 0; j < a->height; j++) {
56 int32_t linesum;
57
58 orc_sum_square_diff_u8 (&linesum,
59 SCHRO_FRAME_DATA_GET_LINE (a, j),
60 SCHRO_FRAME_DATA_GET_LINE (b, j), a->width);
61 sum += linesum;
62 }
63 return sum;
64 }
65
66 void
schro_frame_mean_squared_error(SchroFrame * a,SchroFrame * b,double * mse)67 schro_frame_mean_squared_error (SchroFrame * a, SchroFrame * b, double *mse)
68 {
69 double sum, n;
70
71 sum = schro_frame_component_squared_error (&a->components[0],
72 &b->components[0]);
73 n = a->components[0].width * a->components[0].height;
74 mse[0] = sum / n;
75
76 sum = schro_frame_component_squared_error (&a->components[1],
77 &b->components[1]);
78 n = a->components[1].width * a->components[1].height;
79 mse[1] = sum / n;
80
81 sum = schro_frame_component_squared_error (&a->components[2],
82 &b->components[2]);
83 n = a->components[2].width * a->components[2].height;
84 mse[2] = sum / n;
85 }
86