lib: media_player: fix libvlc_MediaPlayerMediaChanged event
[vlc.git] / modules / video_filter / filter_picture.h
blob43bde3f237f7b1324e48a23df437072f02f423a4
1 /*****************************************************************************
2 * filter_picture.h: Common picture functions for filters
3 *****************************************************************************
4 * Copyright (C) 2007 VLC authors and VideoLAN
6 * Authors: Antoine Cellerier <dionoea at videolan dot org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 /* FIXME: do all of these really have square pixels? */
24 #define CASE_PLANAR_YUV_SQUARE \
25 case VLC_CODEC_I420: \
26 case VLC_CODEC_J420: \
27 case VLC_CODEC_YV12: \
28 case VLC_CODEC_I411: \
29 case VLC_CODEC_I410: \
30 case VLC_CODEC_I444: \
31 case VLC_CODEC_J444: \
32 case VLC_CODEC_YUVA:
34 #define CASE_PLANAR_YUV_NONSQUARE \
35 case VLC_CODEC_I422: \
36 case VLC_CODEC_J422:
38 #define CASE_PLANAR_YUV10 \
39 case VLC_CODEC_I420_10L: \
40 case VLC_CODEC_I420_10B: \
41 case VLC_CODEC_I444_10L: \
42 case VLC_CODEC_I444_10B:
44 #define CASE_PLANAR_YUV9 \
45 case VLC_CODEC_I420_9L: \
46 case VLC_CODEC_I420_9B: \
47 case VLC_CODEC_I444_9L: \
48 case VLC_CODEC_I444_9B:
50 #define CASE_PLANAR_YUV \
51 CASE_PLANAR_YUV_SQUARE \
52 CASE_PLANAR_YUV_NONSQUARE \
54 #define CASE_PACKED_YUV_422 \
55 case VLC_CODEC_UYVY: \
56 case VLC_CODEC_YUYV: \
57 case VLC_CODEC_YVYU:
59 static inline int GetPackedYuvOffsets( vlc_fourcc_t i_chroma,
60 int *i_y_offset, int *i_u_offset, int *i_v_offset )
62 switch( i_chroma )
64 case VLC_CODEC_UYVY:
65 /* UYVY */
66 *i_y_offset = 1;
67 *i_u_offset = 0;
68 *i_v_offset = 2;
69 return VLC_SUCCESS;
70 case VLC_CODEC_VYUY:
71 /* VYUY */
72 *i_y_offset = 1;
73 *i_u_offset = 2;
74 *i_v_offset = 0;
75 return VLC_SUCCESS;
76 case VLC_CODEC_YUYV:
77 /* YUYV */
78 *i_y_offset = 0;
79 *i_u_offset = 1;
80 *i_v_offset = 3;
81 return VLC_SUCCESS;
82 case VLC_CODEC_YVYU:
83 /* YVYU */
84 *i_y_offset = 0;
85 *i_u_offset = 3;
86 *i_v_offset = 1;
87 return VLC_SUCCESS;
88 default:
89 return VLC_EGENERIC;
93 static inline int GetPackedRgbIndexes( const video_format_t *p_fmt, int *i_r_index,
94 int *i_g_index, int *i_b_index )
96 if( p_fmt->i_chroma != VLC_CODEC_RGB24 && p_fmt->i_chroma != VLC_CODEC_RGB32 )
97 return VLC_EGENERIC;
99 #ifdef WORDS_BIGENDIAN
100 const int i_mask_bits = p_fmt->i_chroma == VLC_CODEC_RGB24 ? 16 : 24;
101 *i_r_index = (i_mask_bits - vlc_ctz(p_fmt->i_rmask)) / 8;
102 *i_g_index = (i_mask_bits - vlc_ctz(p_fmt->i_gmask)) / 8;
103 *i_b_index = (i_mask_bits - vlc_ctz(p_fmt->i_bmask)) / 8;
104 #else
105 *i_r_index = vlc_ctz(p_fmt->i_rmask) / 8;
106 *i_g_index = vlc_ctz(p_fmt->i_gmask) / 8;
107 *i_b_index = vlc_ctz(p_fmt->i_bmask) / 8;
108 #endif
109 return VLC_SUCCESS;
112 static inline uint8_t vlc_uint8( int v )
114 if( v > 255 )
115 return 255;
116 else if( v < 0 )
117 return 0;
118 return v;
121 static inline void yuv_to_rgb( int *r, int *g, int *b,
122 uint8_t y1, uint8_t u1, uint8_t v1 )
124 /* macros used for YUV pixel conversions */
125 # define SCALEBITS 10
126 # define ONE_HALF (1 << (SCALEBITS - 1))
127 # define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
129 int y, cb, cr, r_add, g_add, b_add;
131 cb = u1 - 128;
132 cr = v1 - 128;
133 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
134 g_add = - FIX(0.34414*255.0/224.0) * cb
135 - FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
136 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
137 y = (y1 - 16) * FIX(255.0/219.0);
138 *r = vlc_uint8( (y + r_add) >> SCALEBITS );
139 *g = vlc_uint8( (y + g_add) >> SCALEBITS );
140 *b = vlc_uint8( (y + b_add) >> SCALEBITS );
141 #undef FIX
142 #undef ONE_HALF
143 #undef SCALEBITS
146 static inline void rgb_to_yuv( uint8_t *y, uint8_t *u, uint8_t *v,
147 int r, int g, int b )
149 *y = ( ( ( 66 * r + 129 * g + 25 * b + 128 ) >> 8 ) + 16 );
150 *u = ( ( -38 * r - 74 * g + 112 * b + 128 ) >> 8 ) + 128 ;
151 *v = ( ( 112 * r - 94 * g - 18 * b + 128 ) >> 8 ) + 128 ;
154 /*****************************************************************************
156 *****************************************************************************/
157 static inline picture_t *CopyInfoAndRelease( picture_t *p_outpic, picture_t *p_inpic )
159 picture_CopyProperties( p_outpic, p_inpic );
161 picture_Release( p_inpic );
163 return p_outpic;