comparison common.h @ 909:73a9ad2a11bd libavutil

Write clip-related decimal numbers into hex, where they make more sense.
author rbultje
date Mon, 26 Apr 2010 21:00:33 +0000
parents de9d2bfb3ceb
children 6dcab870b03b
comparison
equal deleted inserted replaced
908:de9d2bfb3ceb 909:73a9ad2a11bd
116 * @param a value to clip 116 * @param a value to clip
117 * @return clipped value 117 * @return clipped value
118 */ 118 */
119 static inline av_const uint8_t av_clip_uint8(int a) 119 static inline av_const uint8_t av_clip_uint8(int a)
120 { 120 {
121 if (a&(~255)) return (-a)>>31; 121 if (a&(~0xFF)) return (-a)>>31;
122 else return a; 122 else return a;
123 } 123 }
124 124
125 /** 125 /**
126 * Clips a signed integer value into the 0-65535 range. 126 * Clips a signed integer value into the 0-65535 range.
127 * @param a value to clip 127 * @param a value to clip
128 * @return clipped value 128 * @return clipped value
129 */ 129 */
130 static inline av_const uint16_t av_clip_uint16(int a) 130 static inline av_const uint16_t av_clip_uint16(int a)
131 { 131 {
132 if (a&(~65535)) return (-a)>>31; 132 if (a&(~0xFFFF)) return (-a)>>31;
133 else return a; 133 else return a;
134 } 134 }
135 135
136 /** 136 /**
137 * Clips a signed integer value into the -32768,32767 range. 137 * Clips a signed integer value into the -32768,32767 range.
138 * @param a value to clip 138 * @param a value to clip
139 * @return clipped value 139 * @return clipped value
140 */ 140 */
141 static inline av_const int16_t av_clip_int16(int a) 141 static inline av_const int16_t av_clip_int16(int a)
142 { 142 {
143 if ((a+32768) & ~65535) return (a>>31) ^ 32767; 143 if ((a+0x8000) & ~0xFFFF) return (a>>31) ^ 0x7FFF;
144 else return a; 144 else return a;
145 } 145 }
146 146
147 /** 147 /**
148 * Clips a signed 64-bit integer value into the -2147483648,2147483647 range. 148 * Clips a signed 64-bit integer value into the -2147483648,2147483647 range.