tests: fix build on os/x
[schroedinger.git] / schroedinger / schroanalysis.c
blobcc36bf95458b118fab0f87b75f2f5913e448d915
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
6 #include <schroedinger/schro.h>
7 #include <schroedinger/schroorc.h>
9 void
10 schro_encoder_frame_downsample (SchroEncoderFrame * frame)
12 int i;
13 SchroFrame *last;
15 SCHRO_DEBUG ("downsampling frame %d", frame->frame_number);
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];
30 void
31 schro_encoder_frame_upsample (SchroEncoderFrame * frame)
33 SCHRO_ASSERT (frame);
34 SCHRO_DEBUG ("upsampling frame %d", frame->frame_number);
36 if (frame->upsampled_original_frame) {
37 return;
39 schro_frame_ref (frame->filtered_frame);
40 frame->upsampled_original_frame = frame->filtered_frame;
41 schro_upsampled_frame_upsample (frame->upsampled_original_frame);
44 static double
45 schro_frame_component_squared_error (SchroFrameData * a, SchroFrameData * b)
47 int j;
48 double sum;
50 SCHRO_ASSERT (a->width == b->width);
51 SCHRO_ASSERT (a->height == b->height);
53 sum = 0;
54 for (j = 0; j < a->height; j++) {
55 int32_t linesum;
57 orc_sum_square_diff_u8 (&linesum,
58 SCHRO_FRAME_DATA_GET_LINE (a, j),
59 SCHRO_FRAME_DATA_GET_LINE (b, j), a->width);
60 sum += linesum;
62 return sum;
65 void
66 schro_frame_mean_squared_error (SchroFrame * a, SchroFrame * b, double *mse)
68 double sum, n;
70 sum = schro_frame_component_squared_error (&a->components[0],
71 &b->components[0]);
72 n = a->components[0].width * a->components[0].height;
73 mse[0] = sum / n;
75 sum = schro_frame_component_squared_error (&a->components[1],
76 &b->components[1]);
77 n = a->components[1].width * a->components[1].height;
78 mse[1] = sum / n;
80 sum = schro_frame_component_squared_error (&a->components[2],
81 &b->components[2]);
82 n = a->components[2].width * a->components[2].height;
83 mse[2] = sum / n;