annotate libmpcodecs/vf_dsize.c @ 21090:777e1db59946

Oops, the loader stuff needs to be in COMMON_LIBS.
author diego
date Mon, 20 Nov 2006 14:49:08 +0000
parents f9b0c8fe997e
children 00fff9a3b735
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
1 #include <stdio.h>
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
2 #include <stdlib.h>
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
3 #include <string.h>
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
4 #include <inttypes.h>
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
5
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16040
diff changeset
6 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16040
diff changeset
7 #include "mp_msg.h"
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
8
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
9 #include "img_format.h"
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
10 #include "mp_image.h"
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
11 #include "vf.h"
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
12
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
13 struct vf_priv_s {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
14 int w, h;
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
15 int method; // aspect method, 0 -> downscale, 1-> upscale. +2 -> original aspect.
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
16 int round;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
17 float aspect;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
18 };
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
19
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
20 static int config(struct vf_instance_s* vf,
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
21 int width, int height, int d_width, int d_height,
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
22 unsigned int flags, unsigned int outfmt)
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
23 {
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
24 if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
25 if (vf->priv->w == 0) vf->priv->w = d_width;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
26 if (vf->priv->h == 0) vf->priv->h = d_height;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
27 if (vf->priv->w == -1) vf->priv->w = width;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
28 if (vf->priv->h == -1) vf->priv->h = height;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
29 if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
30 if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
31 if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
32 if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
33 if (vf->priv->method > -1) {
17227
c2b50fc5d86a I screwed up keep aspect param, made behavior the opposite of man page.
ods15
parents: 17012
diff changeset
34 double aspect = (vf->priv->method & 2) ? ((double)height / width) : ((double)d_height / d_width);
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
35 if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->method & 1)) {
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
36 vf->priv->h = vf->priv->w * aspect;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
37 } else {
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
38 vf->priv->w = vf->priv->h / aspect;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
39 }
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
40 }
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
41 if (vf->priv->round > 1) { // round up
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
42 vf->priv->w += (vf->priv->round - 1 - (vf->priv->w - 1) % vf->priv->round);
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
43 vf->priv->h += (vf->priv->round - 1 - (vf->priv->h - 1) % vf->priv->round);
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
44 }
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
45 d_width = vf->priv->w;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
46 d_height = vf->priv->h;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
47 } else {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
48 if (vf->priv->aspect * height > width) {
18390
f9b0c8fe997e fix float rounding error
ods15
parents: 17227
diff changeset
49 d_width = height * vf->priv->aspect + .5;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
50 d_height = height;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
51 } else {
18390
f9b0c8fe997e fix float rounding error
ods15
parents: 17227
diff changeset
52 d_height = width / vf->priv->aspect + .5;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
53 d_width = width;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
54 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
55 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
56 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
57 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
58
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
59 static void uninit(vf_instance_t *vf) {
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
60 free(vf->priv);
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
61 vf->priv = NULL;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
62 }
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
63
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
64 static int open(vf_instance_t *vf, char* args)
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
65 {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
66 vf->config = config;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
67 vf->draw_slice = vf_next_draw_slice;
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
68 vf->uninit = uninit;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
69 //vf->default_caps = 0;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
70 vf->priv = calloc(sizeof(struct vf_priv_s), 1);
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
71 vf->priv->aspect = 0.;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
72 vf->priv->w = -1;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
73 vf->priv->h = -1;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
74 vf->priv->method = -1;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
75 vf->priv->round = 1;
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
76 if (args) {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
77 if (strchr(args, '/')) {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
78 int w, h;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
79 sscanf(args, "%d/%d", &w, &h);
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
80 vf->priv->aspect = (float)w/h;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
81 } else if (strchr(args, '.')) {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
82 sscanf(args, "%f", &vf->priv->aspect);
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
83 } else {
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
84 sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round);
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
85 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
86 }
16040
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
87 if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) ||
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
88 ((vf->priv->w < -1) && (vf->priv->h < -1)) ||
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
89 (vf->priv->method < -1) || (vf->priv->method > 3) ||
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
90 (vf->priv->round < 0)) {
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
91 mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->method, vf->priv->round);
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
92 free(vf->priv); vf->priv = NULL;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
93 return -1;
72215ea57015 aspect and round params for vf_dsize.
ods15
parents: 10006
diff changeset
94 }
10006
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
95 return 1;
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
96 }
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
97
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
98 vf_info_t vf_info_dsize = {
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
99 "reset displaysize/aspect",
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
100 "dsize",
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
101 "Rich Felker",
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
102 "",
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
103 open,
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
104 NULL
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
105 };
6293e6f02fe3 display size/aspect adjusting filter
rfelker
parents:
diff changeset
106