1 /*
2  * Copyright (C) 2000-2020 the xine project
3  *
4  * This file is part of xine, a free video player.
5  *
6  * xine is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * xine is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19  *
20  * vo_scale.h
21  *
22  * keeps video scaling information
23  */
24 
25 #ifndef HAVE_VO_SCALE_H
26 #define HAVE_VO_SCALE_H
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <xine/configfile.h>
33 
34 typedef struct {
35   int x, y;
36   int w, h;
37 } vo_scale_rect_t;
38 
39 struct vo_scale_s {
40 
41   /* true if driver supports frame zooming */
42   int                support_zoom;
43 
44   /* forces direct mapping between frame pixels and screen pixels */
45   int                scaling_disabled;
46 
47   /* size / aspect ratio calculations */
48 
49   /*
50    * "delivered" size:
51    * frame dimension / aspect as delivered by the decoder
52    * used (among other things) to detect frame size changes
53    * units: frame pixels
54    */
55   int                delivered_width;
56   int                delivered_height;
57   double             delivered_ratio;
58 
59   /*
60    * required cropping:
61    * units: frame pixels
62    */
63   int                crop_left;
64   int                crop_right;
65   int                crop_top;
66   int                crop_bottom;
67 
68   /*
69    * displayed part of delivered images,
70    * taking zoom into account
71    * units: frame pixels
72    */
73   int                displayed_xoffset;
74   int                displayed_yoffset;
75   int                displayed_width;
76   int                displayed_height;
77   double             zoom_factor_x, zoom_factor_y;
78 
79   /*
80    * user's aspect selection
81    */
82   int                user_ratio;
83 
84   /*
85    * "gui" size / offset:
86    * what gui told us about where to display the video
87    * units: screen pixels
88    */
89   int                gui_x, gui_y;
90   int                gui_width, gui_height;
91   int                gui_win_x, gui_win_y;
92 
93   /* */
94   int                force_redraw;
95 
96   /*
97    * video + display pixel aspect
98    * One pixel of height 1 has this width
99    * This may be corrected by the driver in order to fit the video seamlessly
100    */
101   double             gui_pixel_aspect;
102   double             video_pixel_aspect;
103 
104   /*
105    * "output" size:
106    *
107    * this is finally the ideal size "fitted" into the
108    * gui size while maintaining the aspect ratio
109    * units: screen pixels
110    */
111   int                output_width;
112   int                output_height;
113   int                output_xoffset;
114   int                output_yoffset;
115 
116 
117   /* gui callbacks */
118 
119   void              *user_data;
120   void (*frame_output_cb) (void *user_data,
121 			   int video_width, int video_height,
122                            double video_pixel_aspect,
123 			   int *dest_x, int *dest_y,
124 			   int *dest_width, int *dest_height,
125                            double *dest_pixel_aspect,
126 			   int *win_x, int *win_y);
127 
128   void (*dest_size_cb) (void *user_data,
129 			int video_width, int video_height,
130                         double video_pixel_aspect,
131 			int *dest_width, int *dest_height,
132                         double *dest_pixel_aspect);
133 
134   /* borders */
135   vo_scale_rect_t     border[4];
136 
137   /*
138    * border ratios to determine image position in the
139    * viewport; these are set by user config
140    */
141   double             output_horizontal_position;
142   double             output_vertical_position;
143 
144 };
145 
146 typedef struct vo_scale_s vo_scale_t;
147 
148 
149 /*
150  * convert delivered height/width to ideal width/height
151  * taking into account aspect ratio and zoom factor
152  */
153 
154 void _x_vo_scale_compute_ideal_size (vo_scale_t *self) XINE_PROTECTED;
155 
156 
157 /*
158  * make ideal width/height "fit" into the gui
159  */
160 
161 void _x_vo_scale_compute_output_size (vo_scale_t *self) XINE_PROTECTED;
162 
163 /*
164  * return true if a redraw is needed due resizing, zooming,
165  * aspect ratio changing, etc.
166  */
167 
168 int _x_vo_scale_redraw_needed (vo_scale_t *self) XINE_PROTECTED;
169 
170 /*
171  *
172  */
173 
174 void _x_vo_scale_translate_gui2video(vo_scale_t *self,
175 				     int x, int y,
176 				     int *vid_x, int *vid_y) XINE_PROTECTED;
177 
178 typedef struct {
179   struct {
180     int x0, y0, x1, y1;
181   } in, out;
182 } vo_scale_map_t;
183 
184 typedef enum {
185   VO_SCALE_MAP_OK = 0,     /** << Fine. */
186   VO_SCALE_MAP_OUTSIDE,    /** << rect completely outside visible video. */
187   VO_SCALE_MAP_WRONG_ARGS, /** << NULL passed. */
188   VO_SCALE_MAP_ERROR       /** << vo_scale yet unset. */
189 } vo_scale_map_res_t;
190 
191 /** @brief Map a rectangle to video out window.
192  *  @param self The vo_scale status to use.
193  *  @param map  On call: map.in = {0, 0, width, height} of input rect.
194  *                       map.out = {left, top, extent_width, extent_height} where input should go.
195  *                                 Extents may be 0 if same as video size.
196  *              On return: map.in = {left, top, right, bottom} to use from input rect.
197  *                         map.out = {left, top, right, bottom} inside video out.
198  * @return What went wrong. */
199 vo_scale_map_res_t _x_vo_scale_map (vo_scale_t *self, vo_scale_map_t *map) XINE_PROTECTED;
200 
201 /*
202  * Returns description of a given ratio code
203  */
204 
205 extern const char _x_vo_scale_aspect_ratio_name_table[][8] XINE_PROTECTED;
206 
207 /*
208  * initialize rescaling struct
209  */
210 
211 void _x_vo_scale_init(vo_scale_t *self, int support_zoom,
212 		      int scaling_disabled, config_values_t *config ) XINE_PROTECTED;
213 
214 void _x_vo_scale_cleanup(vo_scale_t *self, config_values_t *config) XINE_PROTECTED;
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif
221