lib: media_player: fix libvlc_MediaPlayerMediaChanged event
[vlc.git] / modules / video_filter / adjust_sat_hue.c
blob6968fcad1b0bdebe83c1dc13f242497f17b9cb8c
1 /*****************************************************************************
2 * adjust_sat_hue.c : Hue/Saturation executive part of adjust plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2011 VideoLAN
6 * Authors: Simon Latapie <garf@via.ecp.fr>
7 * Antoine Cellerier <dionoea -at- videolan d0t org>
8 * Martin Briza <gamajun@seznam.cz> (SSE)
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <assert.h>
30 #include <vlc_filter.h>
31 #include <vlc_picture.h>
32 #include "filter_picture.h"
33 #include "adjust_sat_hue.h"
35 #define I_RANGE( i_bpp ) (1 << i_bpp)
36 #define I_MAX( i_bpp ) (I_RANGE( i_bpp ) - 1)
37 #define I_MID( i_bpp ) (I_RANGE( i_bpp ) >> 1)
39 #define PLANAR_WRITE_UV_CLIP( i_bpp ) \
40 i_u = *p_in++ ; i_v = *p_in_v++ ; \
41 *p_out++ = VLC_CLIP( ((( (((i_u * i_cos + i_v * i_sin - i_x) + I_MID( i_bpp )) >> i_bpp) \
42 * i_sat) + I_MID( i_bpp )) >> i_bpp) + I_MID( i_bpp ), 0, I_MAX( i_bpp ) ); \
43 *p_out_v++ = VLC_CLIP( ((( (((i_v * i_cos - i_u * i_sin - i_y) + I_MID( i_bpp )) >> i_bpp) \
44 * i_sat) + I_MID( i_bpp )) >> i_bpp) + I_MID( i_bpp ), 0, I_MAX( i_bpp ) )
46 #define PLANAR_WRITE_UV( i_bpp ) \
47 i_u = *p_in++ ; i_v = *p_in_v++ ; \
48 *p_out++ = ((( (((i_u * i_cos + i_v * i_sin - i_x) + I_MID( i_bpp )) >> i_bpp) \
49 * i_sat) + I_MID( i_bpp )) >> i_bpp) + I_MID( i_bpp ); \
50 *p_out_v++ = ((( (((i_v * i_cos - i_u * i_sin - i_y) + I_MID( i_bpp )) >> i_bpp) \
51 * i_sat) + I_MID( i_bpp )) >> i_bpp) + I_MID( i_bpp )
53 #define PACKED_WRITE_UV_CLIP() \
54 i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \
55 *p_out = clip_uint8_vlc( ((( (((i_u * i_cos + i_v * i_sin - i_x) + I_MID( 8 )) >> 8) \
56 * i_sat) + I_MID( 8 )) >> 8) + 128); \
57 p_out += 4; \
58 *p_out_v = clip_uint8_vlc( ((( (((i_v * i_cos - i_u * i_sin - i_y) + I_MID( 8 )) >> 8) \
59 * i_sat) + I_MID( 8 )) >> 8) + 128); \
60 p_out_v += 4
62 #define PACKED_WRITE_UV() \
63 i_u = *p_in; p_in += 4; i_v = *p_in_v; p_in_v += 4; \
64 *p_out = ((( (((i_u * i_cos + i_v * i_sin - i_x) + I_MID( 8 )) >> 8) \
65 * i_sat) + I_MID( 8 )) >> 8) + 128; \
66 p_out += 4; \
67 *p_out_v = ((( (((i_v * i_cos - i_u * i_sin - i_y) + I_MID( 8 )) >> 8) \
68 * i_sat) + I_MID( 8 )) >> 8) + 128; \
69 p_out_v += 4
71 #define ADJUST_8_TIMES(x) x; x; x; x; x; x; x; x
73 /*****************************************************************************
74 * Hue and saturation adjusting routines
75 *****************************************************************************/
77 int planar_sat_hue_clip_C( picture_t * p_pic, picture_t * p_outpic, int i_sin, int i_cos,
78 int i_sat, int i_x, int i_y )
80 uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
81 uint8_t *p_out, *p_out_v;
83 p_in = p_pic->p[U_PLANE].p_pixels;
84 p_in_v = p_pic->p[V_PLANE].p_pixels;
85 p_in_end = p_in + p_pic->p[U_PLANE].i_visible_lines
86 * p_pic->p[U_PLANE].i_pitch - 8;
88 p_out = p_outpic->p[U_PLANE].p_pixels;
89 p_out_v = p_outpic->p[V_PLANE].p_pixels;
91 uint8_t i_u, i_v;
93 for( ; p_in < p_in_end ; )
95 p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8;
97 for( ; p_in < p_line_end ; )
99 /* Do 8 pixels at a time */
100 ADJUST_8_TIMES( PLANAR_WRITE_UV_CLIP( 8 ) );
103 p_line_end += 8;
105 for( ; p_in < p_line_end ; )
107 PLANAR_WRITE_UV_CLIP( 8 );
110 p_in += p_pic->p[U_PLANE].i_pitch
111 - p_pic->p[U_PLANE].i_visible_pitch;
112 p_in_v += p_pic->p[V_PLANE].i_pitch
113 - p_pic->p[V_PLANE].i_visible_pitch;
114 p_out += p_outpic->p[U_PLANE].i_pitch
115 - p_outpic->p[U_PLANE].i_visible_pitch;
116 p_out_v += p_outpic->p[V_PLANE].i_pitch
117 - p_outpic->p[V_PLANE].i_visible_pitch;
120 return VLC_SUCCESS;
123 int planar_sat_hue_C( picture_t * p_pic, picture_t * p_outpic, int i_sin, int i_cos,
124 int i_sat, int i_x, int i_y )
126 uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
127 uint8_t *p_out, *p_out_v;
129 p_in = p_pic->p[U_PLANE].p_pixels;
130 p_in_v = p_pic->p[V_PLANE].p_pixels;
131 p_in_end = p_in + p_pic->p[U_PLANE].i_visible_lines
132 * p_pic->p[U_PLANE].i_pitch - 8;
134 p_out = p_outpic->p[U_PLANE].p_pixels;
135 p_out_v = p_outpic->p[V_PLANE].p_pixels;
137 uint8_t i_u, i_v;
139 for( ; p_in < p_in_end ; )
141 p_line_end = p_in + p_pic->p[U_PLANE].i_visible_pitch - 8;
143 for( ; p_in < p_line_end ; )
145 /* Do 8 pixels at a time */
146 ADJUST_8_TIMES( PLANAR_WRITE_UV( 8 ) );
149 p_line_end += 8;
151 for( ; p_in < p_line_end ; )
153 PLANAR_WRITE_UV( 8 );
156 p_in += p_pic->p[U_PLANE].i_pitch
157 - p_pic->p[U_PLANE].i_visible_pitch;
158 p_in_v += p_pic->p[V_PLANE].i_pitch
159 - p_pic->p[V_PLANE].i_visible_pitch;
160 p_out += p_outpic->p[U_PLANE].i_pitch
161 - p_outpic->p[U_PLANE].i_visible_pitch;
162 p_out_v += p_outpic->p[V_PLANE].i_pitch
163 - p_outpic->p[V_PLANE].i_visible_pitch;
166 return VLC_SUCCESS;
169 int planar_sat_hue_clip_C_16( picture_t * p_pic, picture_t * p_outpic, int i_sin, int i_cos,
170 int i_sat, int i_x, int i_y )
172 uint16_t *p_in, *p_in_v, *p_in_end, *p_line_end;
173 uint16_t *p_out, *p_out_v;
175 int i_bpp;
176 switch( p_pic->format.i_chroma )
178 CASE_PLANAR_YUV10
179 i_bpp = 10;
180 break;
181 CASE_PLANAR_YUV9
182 i_bpp = 9;
183 break;
184 default:
185 vlc_assert_unreachable();
188 p_in = (uint16_t *) p_pic->p[U_PLANE].p_pixels;
189 p_in_v = (uint16_t *) p_pic->p[V_PLANE].p_pixels;
190 p_in_end = p_in + p_pic->p[U_PLANE].i_visible_lines
191 * (p_pic->p[U_PLANE].i_pitch >> 1) - 8;
193 p_out = (uint16_t *) p_outpic->p[U_PLANE].p_pixels;
194 p_out_v = (uint16_t *) p_outpic->p[V_PLANE].p_pixels;
196 uint16_t i_u, i_v;
198 for( ; p_in < p_in_end ; )
200 p_line_end = p_in + (p_pic->p[U_PLANE].i_visible_pitch >> 1) - 8;
202 for( ; p_in < p_line_end ; )
204 /* Do 8 pixels at a time */
205 ADJUST_8_TIMES( PLANAR_WRITE_UV_CLIP( i_bpp ) );
208 p_line_end += 8;
210 for( ; p_in < p_line_end ; )
212 PLANAR_WRITE_UV_CLIP( i_bpp );
215 p_in += (p_pic->p[U_PLANE].i_pitch >> 1)
216 - (p_pic->p[U_PLANE].i_visible_pitch >> 1);
217 p_in_v += (p_pic->p[V_PLANE].i_pitch >> 1)
218 - (p_pic->p[V_PLANE].i_visible_pitch >> 1);
219 p_out += (p_outpic->p[U_PLANE].i_pitch >> 1)
220 - (p_outpic->p[U_PLANE].i_visible_pitch >> 1);
221 p_out_v += (p_outpic->p[V_PLANE].i_pitch >> 1)
222 - (p_outpic->p[V_PLANE].i_visible_pitch >> 1);
225 return VLC_SUCCESS;
228 int planar_sat_hue_C_16( picture_t * p_pic, picture_t * p_outpic, int i_sin, int i_cos,
229 int i_sat, int i_x, int i_y )
231 uint16_t *p_in, *p_in_v, *p_in_end, *p_line_end;
232 uint16_t *p_out, *p_out_v;
234 int i_bpp;
235 switch( p_pic->format.i_chroma )
237 CASE_PLANAR_YUV10
238 i_bpp = 10;
239 break;
240 CASE_PLANAR_YUV9
241 i_bpp = 9;
242 break;
243 default:
244 vlc_assert_unreachable();
247 p_in = (uint16_t *) p_pic->p[U_PLANE].p_pixels;
248 p_in_v = (uint16_t *) p_pic->p[V_PLANE].p_pixels;
249 p_in_end = (uint16_t *) p_in + p_pic->p[U_PLANE].i_visible_lines
250 * (p_pic->p[U_PLANE].i_pitch >> 1) - 8;
252 p_out = (uint16_t *) p_outpic->p[U_PLANE].p_pixels;
253 p_out_v = (uint16_t *) p_outpic->p[V_PLANE].p_pixels;
255 uint16_t i_u, i_v;
257 for( ; p_in < p_in_end ; )
259 p_line_end = p_in + (p_pic->p[U_PLANE].i_visible_pitch >> 1) - 8;
261 for( ; p_in < p_line_end ; )
263 /* Do 8 pixels at a time */
264 ADJUST_8_TIMES( PLANAR_WRITE_UV( i_bpp ) );
267 p_line_end += 8;
269 for( ; p_in < p_line_end ; )
271 PLANAR_WRITE_UV( i_bpp );
274 p_in += (p_pic->p[U_PLANE].i_pitch >> 1)
275 - (p_pic->p[U_PLANE].i_visible_pitch >> 1);
276 p_in_v += (p_pic->p[V_PLANE].i_pitch >> 1)
277 - (p_pic->p[V_PLANE].i_visible_pitch >> 1);
278 p_out += (p_outpic->p[U_PLANE].i_pitch >> 1)
279 - (p_outpic->p[U_PLANE].i_visible_pitch >> 1);
280 p_out_v += (p_outpic->p[V_PLANE].i_pitch >> 1)
281 - (p_outpic->p[V_PLANE].i_visible_pitch >> 1);
284 return VLC_SUCCESS;
287 int packed_sat_hue_clip_C( picture_t * p_pic, picture_t * p_outpic, int i_sin, int i_cos,
288 int i_sat, int i_x, int i_y )
290 uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
291 uint8_t *p_out, *p_out_v;
293 int i_y_offset, i_u_offset, i_v_offset;
294 int i_visible_lines, i_pitch, i_visible_pitch;
297 if ( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset,
298 &i_u_offset, &i_v_offset ) != VLC_SUCCESS )
299 return VLC_EGENERIC;
301 i_visible_lines = p_pic->p->i_visible_lines;
302 i_pitch = p_pic->p->i_pitch;
303 i_visible_pitch = p_pic->p->i_visible_pitch;
305 p_in = p_pic->p->p_pixels + i_u_offset;
306 p_in_v = p_pic->p->p_pixels + i_v_offset;
307 p_in_end = p_in + i_visible_lines * i_pitch - 8 * 4;
309 p_out = p_outpic->p->p_pixels + i_u_offset;
310 p_out_v = p_outpic->p->p_pixels + i_v_offset;
312 uint8_t i_u, i_v;
314 for( ; p_in < p_in_end ; )
316 p_line_end = p_in + i_visible_pitch - 8 * 4;
318 for( ; p_in < p_line_end ; )
320 /* Do 8 pixels at a time */
321 ADJUST_8_TIMES( PACKED_WRITE_UV_CLIP() );
324 p_line_end += 8 * 4;
326 for( ; p_in < p_line_end ; )
328 PACKED_WRITE_UV_CLIP();
331 p_in += i_pitch - i_visible_pitch;
332 p_in_v += i_pitch - i_visible_pitch;
333 p_out += i_pitch - i_visible_pitch;
334 p_out_v += i_pitch - i_visible_pitch;
337 return VLC_SUCCESS;
340 int packed_sat_hue_C( picture_t * p_pic, picture_t * p_outpic, int i_sin,
341 int i_cos, int i_sat, int i_x, int i_y )
343 uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
344 uint8_t *p_out, *p_out_v;
346 int i_y_offset, i_u_offset, i_v_offset;
347 int i_visible_lines, i_pitch, i_visible_pitch;
350 if ( GetPackedYuvOffsets( p_pic->format.i_chroma, &i_y_offset,
351 &i_u_offset, &i_v_offset ) != VLC_SUCCESS )
352 return VLC_EGENERIC;
354 i_visible_lines = p_pic->p->i_visible_lines;
355 i_pitch = p_pic->p->i_pitch;
356 i_visible_pitch = p_pic->p->i_visible_pitch;
358 p_in = p_pic->p->p_pixels + i_u_offset;
359 p_in_v = p_pic->p->p_pixels + i_v_offset;
360 p_in_end = p_in + i_visible_lines * i_pitch - 8 * 4;
362 p_out = p_outpic->p->p_pixels + i_u_offset;
363 p_out_v = p_outpic->p->p_pixels + i_v_offset;
365 uint8_t i_u, i_v;
367 for( ; p_in < p_in_end ; )
369 p_line_end = p_in + i_visible_pitch - 8 * 4;
371 for( ; p_in < p_line_end ; )
373 /* Do 8 pixels at a time */
374 ADJUST_8_TIMES( PACKED_WRITE_UV() );
377 p_line_end += 8 * 4;
379 for( ; p_in < p_line_end ; )
381 PACKED_WRITE_UV();
384 p_in += i_pitch - i_visible_pitch;
385 p_in_v += i_pitch - i_visible_pitch;
386 p_out += i_pitch - i_visible_pitch;
387 p_out_v += i_pitch - i_visible_pitch;
390 return VLC_SUCCESS;