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