~ubuntu-branches/ubuntu/natty/gavl/natty

« back to all changes in this revision

Viewing changes to include/scale.h

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2006-05-17 14:24:46 UTC
  • Revision ID: james.westby@ubuntu.com-20060517142446-iqm0jgfbkmy27n5w
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 
 
3
  scale.h
 
4
 
 
5
  Copyright (c) 2005 by Burkhard Plaum - plaum@ipf.uni-stuttgart.de
 
6
 
 
7
  http://gmerlin.sourceforge.net
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public License
 
15
  along with this program; if not, write to the Free Software
 
16
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 
17
 
 
18
*****************************************************************/
 
19
 
 
20
#include "video.h"
 
21
 
 
22
/* Typedefs */
 
23
 
 
24
typedef struct gavl_video_scale_context_s gavl_video_scale_context_t;
 
25
 
 
26
typedef void (*gavl_video_scale_scanline_func)(gavl_video_scale_context_t*);
 
27
 
 
28
typedef float (*gavl_video_scale_get_weight)(gavl_video_options_t * opt, double t);
 
29
 
 
30
gavl_video_scale_get_weight gavl_video_scale_get_weight_func(gavl_video_options_t * opt,
 
31
                                                             int * num_points);
 
32
 
 
33
/* Scale functions */
 
34
 
 
35
typedef struct
 
36
  {
 
37
  gavl_video_scale_scanline_func scale_rgb_15;
 
38
  gavl_video_scale_scanline_func scale_rgb_16;
 
39
  gavl_video_scale_scanline_func scale_uint8_x_1;
 
40
  gavl_video_scale_scanline_func scale_uint8_x_3;
 
41
  gavl_video_scale_scanline_func scale_uint8_x_4;
 
42
  gavl_video_scale_scanline_func scale_uint16_x_1;
 
43
  gavl_video_scale_scanline_func scale_uint16_x_3;
 
44
  gavl_video_scale_scanline_func scale_uint16_x_4;
 
45
  gavl_video_scale_scanline_func scale_float_x_3;
 
46
  gavl_video_scale_scanline_func scale_float_x_4;
 
47
 
 
48
  /* Bits needed for the integer scaling coefficient */
 
49
  int bits_rgb_15;
 
50
  int bits_rgb_16;
 
51
  int bits_uint8;
 
52
  int bits_uint16;
 
53
  } gavl_scale_func_tab_t;
 
54
 
 
55
typedef struct
 
56
  {
 
57
  gavl_scale_func_tab_t funcs_x;
 
58
  gavl_scale_func_tab_t funcs_y;
 
59
  gavl_scale_func_tab_t funcs_xy;
 
60
  } gavl_scale_funcs_t;
 
61
 
 
62
void gavl_init_scale_funcs_nearest_c(gavl_scale_funcs_t * tab);
 
63
 
 
64
void gavl_init_scale_funcs_bilinear_c(gavl_scale_funcs_t * tab);
 
65
 
 
66
void gavl_init_scale_funcs_quadratic_c(gavl_scale_funcs_t * tab);
 
67
 
 
68
void gavl_init_scale_funcs_bicubic_c(gavl_scale_funcs_t * tab);
 
69
 
 
70
void gavl_init_scale_funcs_generic_c(gavl_scale_funcs_t * tab);
 
71
#ifdef ARCH_X86
 
72
 
 
73
void gavl_init_scale_funcs_mmxext(gavl_scale_funcs_t * tab,
 
74
                                  gavl_scale_mode_t scale_mode,
 
75
                                  int scale_x, int scale_y, int min_scanline_width);
 
76
void gavl_init_scale_funcs_mmx(gavl_scale_funcs_t * tab,
 
77
                               gavl_scale_mode_t scale_mode,
 
78
                               int scale_x, int scale_y, int min_scanline_width);
 
79
#endif
 
80
 
 
81
typedef struct
 
82
  {
 
83
  float fac_f; /* Scaling coefficient with high precision */
 
84
  int fac_i;   /* Scaling coefficient with lower precision */
 
85
  } gavl_video_scale_factor_t;
 
86
 
 
87
typedef struct
 
88
  {
 
89
  int index; /* Index of the first row/column */
 
90
  gavl_video_scale_factor_t * factor;
 
91
  } gavl_video_scale_pixel_t;
 
92
 
 
93
typedef struct
 
94
  {
 
95
  int pixels_alloc;
 
96
  int factors_alloc;
 
97
  int num_pixels; /* Number of pixels (rows/columns) in the output area */
 
98
  gavl_video_scale_factor_t * factors;
 
99
  gavl_video_scale_pixel_t  * pixels;
 
100
  int factors_per_pixel;
 
101
  } gavl_video_scale_table_t;
 
102
 
 
103
void gavl_video_scale_table_init(gavl_video_scale_table_t * tab,
 
104
                                 gavl_video_options_t * opt,
 
105
                                 double src_off, double src_size,
 
106
                                 int dst_size,
 
107
                                 int src_width);
 
108
 
 
109
void gavl_video_scale_table_init_int(gavl_video_scale_table_t * tab,
 
110
                                     int bits);
 
111
 
 
112
void gavl_video_scale_table_get_src_indices(gavl_video_scale_table_t * tab,
 
113
                                            int * start, int * size);
 
114
 
 
115
void gavl_video_scale_table_shift_indices(gavl_video_scale_table_t * tab,
 
116
                                          int shift);
 
117
 
 
118
 
 
119
 
 
120
void gavl_video_scale_table_cleanup(gavl_video_scale_table_t * tab);
 
121
 
 
122
/* For debugging */
 
123
 
 
124
void gavl_video_scale_table_dump(gavl_video_scale_table_t * tab);
 
125
 
 
126
/* Data needed by the scaline function. */
 
127
 
 
128
typedef struct
 
129
  {
 
130
  /* Offsets and advances are ALWAYS in bytes */
 
131
  int src_advance, dst_advance;
 
132
  int src_offset,  dst_offset;
 
133
  } gavl_video_scale_offsets_t;
 
134
 
 
135
/*
 
136
 *  Scale context is for one plane of one field.
 
137
 *  This means, that depending on the video format, we have 1 - 6 scale contexts.
 
138
 */
 
139
 
 
140
struct gavl_video_scale_context_s
 
141
  {
 
142
  /* Data initialized at start */
 
143
  gavl_video_scale_table_t table_h;
 
144
  gavl_video_scale_table_t table_v;
 
145
  gavl_video_scale_scanline_func func1;
 
146
  gavl_video_scale_scanline_func func2;
 
147
 
 
148
  gavl_video_scale_offsets_t offset1;
 
149
  gavl_video_scale_offsets_t offset2;
 
150
  
 
151
  /* Rectangles */
 
152
  gavl_rectangle_f_t src_rect;
 
153
  gavl_rectangle_i_t dst_rect;
 
154
 
 
155
  /* Number of filter taps */
 
156
  int num_taps;
 
157
    
 
158
  /* Indices of source and destination planes inside the frame. Can be 0 for chroma channels of
 
159
     packed YUV formats */
 
160
  
 
161
  int src_frame_plane, dst_frame_plane;
 
162
 
 
163
  int plane; /* Plane */
 
164
  
 
165
  /* Advances */
 
166
 
 
167
  gavl_video_scale_offsets_t * offset;
 
168
  
 
169
  /* Temporary buffer */
 
170
  uint8_t * buffer;
 
171
  int buffer_alloc;
 
172
  int buffer_stride;
 
173
  
 
174
  /* Size of temporary buffer in pixels */
 
175
  int buffer_width;
 
176
  int buffer_height;
 
177
 
 
178
  int num_directions;
 
179
 
 
180
  /* Minimum and maximum values for clipping.
 
181
     Values can be different for different components */
 
182
  
 
183
  uint32_t min_values[4];
 
184
  uint32_t max_values[4];
 
185
 
 
186
  /* These are used by the generic scaler */
 
187
 
 
188
  int64_t tmp[4]; /* For accumulating values */
 
189
 
 
190
  /* For copying */
 
191
  int bytes_per_line;
 
192
  
 
193
  /* Data changed during scaling */
 
194
  uint8_t * src;
 
195
  int src_stride;
 
196
 
 
197
  uint8_t * dst;
 
198
  int scanline;
 
199
  int dst_size;
 
200
  };
 
201
 
 
202
int gavl_video_scale_context_init(gavl_video_scale_context_t*,
 
203
                                  gavl_video_options_t * opt,
 
204
                                  int plane,
 
205
                                  const gavl_video_format_t * input_format,
 
206
                                  const gavl_video_format_t * output_format,
 
207
                                  gavl_scale_funcs_t * funcs,
 
208
                                  int src_field, int dst_field,
 
209
                                  int src_fields, int dst_fields);
 
210
 
 
211
void gavl_video_scale_context_cleanup(gavl_video_scale_context_t * ctx);
 
212
 
 
213
void gavl_video_scale_context_scale(gavl_video_scale_context_t * ctx,
 
214
                                    gavl_video_frame_t * src, gavl_video_frame_t * dst);
 
215
 
 
216
struct gavl_video_scaler_s
 
217
  {
 
218
  gavl_video_options_t opt;
 
219
 
 
220
  /* a context is obtained with contexts[field][plane] */
 
221
  gavl_video_scale_context_t contexts[2][GAVL_MAX_PLANES];
 
222
  
 
223
  int num_planes;
 
224
 
 
225
  /* If src_fields > dst_fields, we deinterlace */
 
226
  int src_fields;
 
227
  int dst_fields;
 
228
    
 
229
  gavl_video_frame_t * src;
 
230
  gavl_video_frame_t * dst;
 
231
 
 
232
  gavl_video_frame_t * src_field;
 
233
  gavl_video_frame_t * dst_field;
 
234
  
 
235
  gavl_video_format_t src_format;
 
236
  gavl_video_format_t dst_format;
 
237
 
 
238
  gavl_rectangle_i_t dst_rect;
 
239
  //  gavl_rectangle_f_t src_rect;
 
240
 
 
241
  };
 
242