cannam@140
|
1 /*
|
cannam@140
|
2 * $Id$
|
cannam@140
|
3 * Portable Audio I/O Library sample conversion mechanism
|
cannam@140
|
4 *
|
cannam@140
|
5 * Based on the Open Source API proposed by Ross Bencina
|
cannam@140
|
6 * Copyright (c) 1999-2002 Phil Burk, Ross Bencina
|
cannam@140
|
7 *
|
cannam@140
|
8 * Permission is hereby granted, free of charge, to any person obtaining
|
cannam@140
|
9 * a copy of this software and associated documentation files
|
cannam@140
|
10 * (the "Software"), to deal in the Software without restriction,
|
cannam@140
|
11 * including without limitation the rights to use, copy, modify, merge,
|
cannam@140
|
12 * publish, distribute, sublicense, and/or sell copies of the Software,
|
cannam@140
|
13 * and to permit persons to whom the Software is furnished to do so,
|
cannam@140
|
14 * subject to the following conditions:
|
cannam@140
|
15 *
|
cannam@140
|
16 * The above copyright notice and this permission notice shall be
|
cannam@140
|
17 * included in all copies or substantial portions of the Software.
|
cannam@140
|
18 *
|
cannam@140
|
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
cannam@140
|
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
cannam@140
|
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
cannam@140
|
22 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
cannam@140
|
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
cannam@140
|
24 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
cannam@140
|
25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
cannam@140
|
26 */
|
cannam@140
|
27
|
cannam@140
|
28 /*
|
cannam@140
|
29 * The text above constitutes the entire PortAudio license; however,
|
cannam@140
|
30 * the PortAudio community also makes the following non-binding requests:
|
cannam@140
|
31 *
|
cannam@140
|
32 * Any person wishing to distribute modifications to the Software is
|
cannam@140
|
33 * requested to send the modifications to the original developer so that
|
cannam@140
|
34 * they can be incorporated into the canonical version. It is also
|
cannam@140
|
35 * requested that these non-binding requests be included along with the
|
cannam@140
|
36 * license above.
|
cannam@140
|
37 */
|
cannam@140
|
38
|
cannam@140
|
39 /** @file
|
cannam@140
|
40 @ingroup common_src
|
cannam@140
|
41
|
cannam@140
|
42 @brief Conversion function implementations.
|
cannam@140
|
43
|
cannam@140
|
44 If the C9x function lrintf() is available, define PA_USE_C99_LRINTF to use it
|
cannam@140
|
45
|
cannam@140
|
46 @todo Consider whether functions which dither but don't clip should exist,
|
cannam@140
|
47 V18 automatically enabled clipping whenever dithering was selected. Perhaps
|
cannam@140
|
48 we should do the same.
|
cannam@140
|
49 see: "require clipping for dithering sample conversion functions?"
|
cannam@140
|
50 http://www.portaudio.com/trac/ticket/112
|
cannam@140
|
51
|
cannam@140
|
52 @todo implement the converters marked IMPLEMENT ME: Int32_To_Int24_Dither,
|
cannam@140
|
53 Int32_To_UInt8_Dither, Int24_To_Int16_Dither, Int24_To_Int8_Dither,
|
cannam@140
|
54 Int24_To_UInt8_Dither, Int16_To_Int8_Dither, Int16_To_UInt8_Dither
|
cannam@140
|
55 see: "some conversion functions are not implemented in pa_converters.c"
|
cannam@140
|
56 http://www.portaudio.com/trac/ticket/35
|
cannam@140
|
57
|
cannam@140
|
58 @todo review the converters marked REVIEW: Float32_To_Int32,
|
cannam@140
|
59 Float32_To_Int32_Dither, Float32_To_Int32_Clip, Float32_To_Int32_DitherClip,
|
cannam@140
|
60 Int32_To_Int16_Dither, Int32_To_Int8_Dither, Int16_To_Int32
|
cannam@140
|
61 */
|
cannam@140
|
62
|
cannam@140
|
63
|
cannam@140
|
64 #include "pa_converters.h"
|
cannam@140
|
65 #include "pa_dither.h"
|
cannam@140
|
66 #include "pa_endianness.h"
|
cannam@140
|
67 #include "pa_types.h"
|
cannam@140
|
68
|
cannam@140
|
69
|
cannam@140
|
70 PaSampleFormat PaUtil_SelectClosestAvailableFormat(
|
cannam@140
|
71 PaSampleFormat availableFormats, PaSampleFormat format )
|
cannam@140
|
72 {
|
cannam@140
|
73 PaSampleFormat result;
|
cannam@140
|
74
|
cannam@140
|
75 format &= ~paNonInterleaved;
|
cannam@140
|
76 availableFormats &= ~paNonInterleaved;
|
cannam@140
|
77
|
cannam@140
|
78 if( (format & availableFormats) == 0 )
|
cannam@140
|
79 {
|
cannam@140
|
80 /* NOTE: this code depends on the sample format constants being in
|
cannam@140
|
81 descending order of quality - ie best quality is 0
|
cannam@140
|
82 FIXME: should write an assert which checks that all of the
|
cannam@140
|
83 known constants conform to that requirement.
|
cannam@140
|
84 */
|
cannam@140
|
85
|
cannam@140
|
86 if( format != 0x01 )
|
cannam@140
|
87 {
|
cannam@140
|
88 /* scan for better formats */
|
cannam@140
|
89 result = format;
|
cannam@140
|
90 do
|
cannam@140
|
91 {
|
cannam@140
|
92 result >>= 1;
|
cannam@140
|
93 }
|
cannam@140
|
94 while( (result & availableFormats) == 0 && result != 0 );
|
cannam@140
|
95 }
|
cannam@140
|
96 else
|
cannam@140
|
97 {
|
cannam@140
|
98 result = 0;
|
cannam@140
|
99 }
|
cannam@140
|
100
|
cannam@140
|
101 if( result == 0 ){
|
cannam@140
|
102 /* scan for worse formats */
|
cannam@140
|
103 result = format;
|
cannam@140
|
104 do
|
cannam@140
|
105 {
|
cannam@140
|
106 result <<= 1;
|
cannam@140
|
107 }
|
cannam@140
|
108 while( (result & availableFormats) == 0 && result != paCustomFormat );
|
cannam@140
|
109
|
cannam@140
|
110 if( (result & availableFormats) == 0 )
|
cannam@140
|
111 result = paSampleFormatNotSupported;
|
cannam@140
|
112 }
|
cannam@140
|
113
|
cannam@140
|
114 }else{
|
cannam@140
|
115 result = format;
|
cannam@140
|
116 }
|
cannam@140
|
117
|
cannam@140
|
118 return result;
|
cannam@140
|
119 }
|
cannam@140
|
120
|
cannam@140
|
121 /* -------------------------------------------------------------------------- */
|
cannam@140
|
122
|
cannam@140
|
123 #define PA_SELECT_FORMAT_( format, float32, int32, int24, int16, int8, uint8 ) \
|
cannam@140
|
124 switch( format & ~paNonInterleaved ){ \
|
cannam@140
|
125 case paFloat32: \
|
cannam@140
|
126 float32 \
|
cannam@140
|
127 case paInt32: \
|
cannam@140
|
128 int32 \
|
cannam@140
|
129 case paInt24: \
|
cannam@140
|
130 int24 \
|
cannam@140
|
131 case paInt16: \
|
cannam@140
|
132 int16 \
|
cannam@140
|
133 case paInt8: \
|
cannam@140
|
134 int8 \
|
cannam@140
|
135 case paUInt8: \
|
cannam@140
|
136 uint8 \
|
cannam@140
|
137 default: return 0; \
|
cannam@140
|
138 }
|
cannam@140
|
139
|
cannam@140
|
140 /* -------------------------------------------------------------------------- */
|
cannam@140
|
141
|
cannam@140
|
142 #define PA_SELECT_CONVERTER_DITHER_CLIP_( flags, source, destination ) \
|
cannam@140
|
143 if( flags & paClipOff ){ /* no clip */ \
|
cannam@140
|
144 if( flags & paDitherOff ){ /* no dither */ \
|
cannam@140
|
145 return paConverters. source ## _To_ ## destination; \
|
cannam@140
|
146 }else{ /* dither */ \
|
cannam@140
|
147 return paConverters. source ## _To_ ## destination ## _Dither; \
|
cannam@140
|
148 } \
|
cannam@140
|
149 }else{ /* clip */ \
|
cannam@140
|
150 if( flags & paDitherOff ){ /* no dither */ \
|
cannam@140
|
151 return paConverters. source ## _To_ ## destination ## _Clip; \
|
cannam@140
|
152 }else{ /* dither */ \
|
cannam@140
|
153 return paConverters. source ## _To_ ## destination ## _DitherClip; \
|
cannam@140
|
154 } \
|
cannam@140
|
155 }
|
cannam@140
|
156
|
cannam@140
|
157 /* -------------------------------------------------------------------------- */
|
cannam@140
|
158
|
cannam@140
|
159 #define PA_SELECT_CONVERTER_DITHER_( flags, source, destination ) \
|
cannam@140
|
160 if( flags & paDitherOff ){ /* no dither */ \
|
cannam@140
|
161 return paConverters. source ## _To_ ## destination; \
|
cannam@140
|
162 }else{ /* dither */ \
|
cannam@140
|
163 return paConverters. source ## _To_ ## destination ## _Dither; \
|
cannam@140
|
164 }
|
cannam@140
|
165
|
cannam@140
|
166 /* -------------------------------------------------------------------------- */
|
cannam@140
|
167
|
cannam@140
|
168 #define PA_USE_CONVERTER_( source, destination )\
|
cannam@140
|
169 return paConverters. source ## _To_ ## destination;
|
cannam@140
|
170
|
cannam@140
|
171 /* -------------------------------------------------------------------------- */
|
cannam@140
|
172
|
cannam@140
|
173 #define PA_UNITY_CONVERSION_( wordlength )\
|
cannam@140
|
174 return paConverters. Copy_ ## wordlength ## _To_ ## wordlength;
|
cannam@140
|
175
|
cannam@140
|
176 /* -------------------------------------------------------------------------- */
|
cannam@140
|
177
|
cannam@140
|
178 PaUtilConverter* PaUtil_SelectConverter( PaSampleFormat sourceFormat,
|
cannam@140
|
179 PaSampleFormat destinationFormat, PaStreamFlags flags )
|
cannam@140
|
180 {
|
cannam@140
|
181 PA_SELECT_FORMAT_( sourceFormat,
|
cannam@140
|
182 /* paFloat32: */
|
cannam@140
|
183 PA_SELECT_FORMAT_( destinationFormat,
|
cannam@140
|
184 /* paFloat32: */ PA_UNITY_CONVERSION_( 32 ),
|
cannam@140
|
185 /* paInt32: */ PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, Int32 ),
|
cannam@140
|
186 /* paInt24: */ PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, Int24 ),
|
cannam@140
|
187 /* paInt16: */ PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, Int16 ),
|
cannam@140
|
188 /* paInt8: */ PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, Int8 ),
|
cannam@140
|
189 /* paUInt8: */ PA_SELECT_CONVERTER_DITHER_CLIP_( flags, Float32, UInt8 )
|
cannam@140
|
190 ),
|
cannam@140
|
191 /* paInt32: */
|
cannam@140
|
192 PA_SELECT_FORMAT_( destinationFormat,
|
cannam@140
|
193 /* paFloat32: */ PA_USE_CONVERTER_( Int32, Float32 ),
|
cannam@140
|
194 /* paInt32: */ PA_UNITY_CONVERSION_( 32 ),
|
cannam@140
|
195 /* paInt24: */ PA_SELECT_CONVERTER_DITHER_( flags, Int32, Int24 ),
|
cannam@140
|
196 /* paInt16: */ PA_SELECT_CONVERTER_DITHER_( flags, Int32, Int16 ),
|
cannam@140
|
197 /* paInt8: */ PA_SELECT_CONVERTER_DITHER_( flags, Int32, Int8 ),
|
cannam@140
|
198 /* paUInt8: */ PA_SELECT_CONVERTER_DITHER_( flags, Int32, UInt8 )
|
cannam@140
|
199 ),
|
cannam@140
|
200 /* paInt24: */
|
cannam@140
|
201 PA_SELECT_FORMAT_( destinationFormat,
|
cannam@140
|
202 /* paFloat32: */ PA_USE_CONVERTER_( Int24, Float32 ),
|
cannam@140
|
203 /* paInt32: */ PA_USE_CONVERTER_( Int24, Int32 ),
|
cannam@140
|
204 /* paInt24: */ PA_UNITY_CONVERSION_( 24 ),
|
cannam@140
|
205 /* paInt16: */ PA_SELECT_CONVERTER_DITHER_( flags, Int24, Int16 ),
|
cannam@140
|
206 /* paInt8: */ PA_SELECT_CONVERTER_DITHER_( flags, Int24, Int8 ),
|
cannam@140
|
207 /* paUInt8: */ PA_SELECT_CONVERTER_DITHER_( flags, Int24, UInt8 )
|
cannam@140
|
208 ),
|
cannam@140
|
209 /* paInt16: */
|
cannam@140
|
210 PA_SELECT_FORMAT_( destinationFormat,
|
cannam@140
|
211 /* paFloat32: */ PA_USE_CONVERTER_( Int16, Float32 ),
|
cannam@140
|
212 /* paInt32: */ PA_USE_CONVERTER_( Int16, Int32 ),
|
cannam@140
|
213 /* paInt24: */ PA_USE_CONVERTER_( Int16, Int24 ),
|
cannam@140
|
214 /* paInt16: */ PA_UNITY_CONVERSION_( 16 ),
|
cannam@140
|
215 /* paInt8: */ PA_SELECT_CONVERTER_DITHER_( flags, Int16, Int8 ),
|
cannam@140
|
216 /* paUInt8: */ PA_SELECT_CONVERTER_DITHER_( flags, Int16, UInt8 )
|
cannam@140
|
217 ),
|
cannam@140
|
218 /* paInt8: */
|
cannam@140
|
219 PA_SELECT_FORMAT_( destinationFormat,
|
cannam@140
|
220 /* paFloat32: */ PA_USE_CONVERTER_( Int8, Float32 ),
|
cannam@140
|
221 /* paInt32: */ PA_USE_CONVERTER_( Int8, Int32 ),
|
cannam@140
|
222 /* paInt24: */ PA_USE_CONVERTER_( Int8, Int24 ),
|
cannam@140
|
223 /* paInt16: */ PA_USE_CONVERTER_( Int8, Int16 ),
|
cannam@140
|
224 /* paInt8: */ PA_UNITY_CONVERSION_( 8 ),
|
cannam@140
|
225 /* paUInt8: */ PA_USE_CONVERTER_( Int8, UInt8 )
|
cannam@140
|
226 ),
|
cannam@140
|
227 /* paUInt8: */
|
cannam@140
|
228 PA_SELECT_FORMAT_( destinationFormat,
|
cannam@140
|
229 /* paFloat32: */ PA_USE_CONVERTER_( UInt8, Float32 ),
|
cannam@140
|
230 /* paInt32: */ PA_USE_CONVERTER_( UInt8, Int32 ),
|
cannam@140
|
231 /* paInt24: */ PA_USE_CONVERTER_( UInt8, Int24 ),
|
cannam@140
|
232 /* paInt16: */ PA_USE_CONVERTER_( UInt8, Int16 ),
|
cannam@140
|
233 /* paInt8: */ PA_USE_CONVERTER_( UInt8, Int8 ),
|
cannam@140
|
234 /* paUInt8: */ PA_UNITY_CONVERSION_( 8 )
|
cannam@140
|
235 )
|
cannam@140
|
236 )
|
cannam@140
|
237 }
|
cannam@140
|
238
|
cannam@140
|
239 /* -------------------------------------------------------------------------- */
|
cannam@140
|
240
|
cannam@140
|
241 #ifdef PA_NO_STANDARD_CONVERTERS
|
cannam@140
|
242
|
cannam@140
|
243 /* -------------------------------------------------------------------------- */
|
cannam@140
|
244
|
cannam@140
|
245 PaUtilConverterTable paConverters = {
|
cannam@140
|
246 0, /* PaUtilConverter *Float32_To_Int32; */
|
cannam@140
|
247 0, /* PaUtilConverter *Float32_To_Int32_Dither; */
|
cannam@140
|
248 0, /* PaUtilConverter *Float32_To_Int32_Clip; */
|
cannam@140
|
249 0, /* PaUtilConverter *Float32_To_Int32_DitherClip; */
|
cannam@140
|
250
|
cannam@140
|
251 0, /* PaUtilConverter *Float32_To_Int24; */
|
cannam@140
|
252 0, /* PaUtilConverter *Float32_To_Int24_Dither; */
|
cannam@140
|
253 0, /* PaUtilConverter *Float32_To_Int24_Clip; */
|
cannam@140
|
254 0, /* PaUtilConverter *Float32_To_Int24_DitherClip; */
|
cannam@140
|
255
|
cannam@140
|
256 0, /* PaUtilConverter *Float32_To_Int16; */
|
cannam@140
|
257 0, /* PaUtilConverter *Float32_To_Int16_Dither; */
|
cannam@140
|
258 0, /* PaUtilConverter *Float32_To_Int16_Clip; */
|
cannam@140
|
259 0, /* PaUtilConverter *Float32_To_Int16_DitherClip; */
|
cannam@140
|
260
|
cannam@140
|
261 0, /* PaUtilConverter *Float32_To_Int8; */
|
cannam@140
|
262 0, /* PaUtilConverter *Float32_To_Int8_Dither; */
|
cannam@140
|
263 0, /* PaUtilConverter *Float32_To_Int8_Clip; */
|
cannam@140
|
264 0, /* PaUtilConverter *Float32_To_Int8_DitherClip; */
|
cannam@140
|
265
|
cannam@140
|
266 0, /* PaUtilConverter *Float32_To_UInt8; */
|
cannam@140
|
267 0, /* PaUtilConverter *Float32_To_UInt8_Dither; */
|
cannam@140
|
268 0, /* PaUtilConverter *Float32_To_UInt8_Clip; */
|
cannam@140
|
269 0, /* PaUtilConverter *Float32_To_UInt8_DitherClip; */
|
cannam@140
|
270
|
cannam@140
|
271 0, /* PaUtilConverter *Int32_To_Float32; */
|
cannam@140
|
272 0, /* PaUtilConverter *Int32_To_Int24; */
|
cannam@140
|
273 0, /* PaUtilConverter *Int32_To_Int24_Dither; */
|
cannam@140
|
274 0, /* PaUtilConverter *Int32_To_Int16; */
|
cannam@140
|
275 0, /* PaUtilConverter *Int32_To_Int16_Dither; */
|
cannam@140
|
276 0, /* PaUtilConverter *Int32_To_Int8; */
|
cannam@140
|
277 0, /* PaUtilConverter *Int32_To_Int8_Dither; */
|
cannam@140
|
278 0, /* PaUtilConverter *Int32_To_UInt8; */
|
cannam@140
|
279 0, /* PaUtilConverter *Int32_To_UInt8_Dither; */
|
cannam@140
|
280
|
cannam@140
|
281 0, /* PaUtilConverter *Int24_To_Float32; */
|
cannam@140
|
282 0, /* PaUtilConverter *Int24_To_Int32; */
|
cannam@140
|
283 0, /* PaUtilConverter *Int24_To_Int16; */
|
cannam@140
|
284 0, /* PaUtilConverter *Int24_To_Int16_Dither; */
|
cannam@140
|
285 0, /* PaUtilConverter *Int24_To_Int8; */
|
cannam@140
|
286 0, /* PaUtilConverter *Int24_To_Int8_Dither; */
|
cannam@140
|
287 0, /* PaUtilConverter *Int24_To_UInt8; */
|
cannam@140
|
288 0, /* PaUtilConverter *Int24_To_UInt8_Dither; */
|
cannam@140
|
289
|
cannam@140
|
290 0, /* PaUtilConverter *Int16_To_Float32; */
|
cannam@140
|
291 0, /* PaUtilConverter *Int16_To_Int32; */
|
cannam@140
|
292 0, /* PaUtilConverter *Int16_To_Int24; */
|
cannam@140
|
293 0, /* PaUtilConverter *Int16_To_Int8; */
|
cannam@140
|
294 0, /* PaUtilConverter *Int16_To_Int8_Dither; */
|
cannam@140
|
295 0, /* PaUtilConverter *Int16_To_UInt8; */
|
cannam@140
|
296 0, /* PaUtilConverter *Int16_To_UInt8_Dither; */
|
cannam@140
|
297
|
cannam@140
|
298 0, /* PaUtilConverter *Int8_To_Float32; */
|
cannam@140
|
299 0, /* PaUtilConverter *Int8_To_Int32; */
|
cannam@140
|
300 0, /* PaUtilConverter *Int8_To_Int24 */
|
cannam@140
|
301 0, /* PaUtilConverter *Int8_To_Int16; */
|
cannam@140
|
302 0, /* PaUtilConverter *Int8_To_UInt8; */
|
cannam@140
|
303
|
cannam@140
|
304 0, /* PaUtilConverter *UInt8_To_Float32; */
|
cannam@140
|
305 0, /* PaUtilConverter *UInt8_To_Int32; */
|
cannam@140
|
306 0, /* PaUtilConverter *UInt8_To_Int24; */
|
cannam@140
|
307 0, /* PaUtilConverter *UInt8_To_Int16; */
|
cannam@140
|
308 0, /* PaUtilConverter *UInt8_To_Int8; */
|
cannam@140
|
309
|
cannam@140
|
310 0, /* PaUtilConverter *Copy_8_To_8; */
|
cannam@140
|
311 0, /* PaUtilConverter *Copy_16_To_16; */
|
cannam@140
|
312 0, /* PaUtilConverter *Copy_24_To_24; */
|
cannam@140
|
313 0 /* PaUtilConverter *Copy_32_To_32; */
|
cannam@140
|
314 };
|
cannam@140
|
315
|
cannam@140
|
316 /* -------------------------------------------------------------------------- */
|
cannam@140
|
317
|
cannam@140
|
318 #else /* PA_NO_STANDARD_CONVERTERS is not defined */
|
cannam@140
|
319
|
cannam@140
|
320 /* -------------------------------------------------------------------------- */
|
cannam@140
|
321
|
cannam@140
|
322 #define PA_CLIP_( val, min, max )\
|
cannam@140
|
323 { val = ((val) < (min)) ? (min) : (((val) > (max)) ? (max) : (val)); }
|
cannam@140
|
324
|
cannam@140
|
325
|
cannam@140
|
326 static const float const_1_div_128_ = 1.0f / 128.0f; /* 8 bit multiplier */
|
cannam@140
|
327
|
cannam@140
|
328 static const float const_1_div_32768_ = 1.0f / 32768.f; /* 16 bit multiplier */
|
cannam@140
|
329
|
cannam@140
|
330 static const double const_1_div_2147483648_ = 1.0 / 2147483648.0; /* 32 bit multiplier */
|
cannam@140
|
331
|
cannam@140
|
332 /* -------------------------------------------------------------------------- */
|
cannam@140
|
333
|
cannam@140
|
334 static void Float32_To_Int32(
|
cannam@140
|
335 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
336 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
337 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
338 {
|
cannam@140
|
339 float *src = (float*)sourceBuffer;
|
cannam@140
|
340 PaInt32 *dest = (PaInt32*)destinationBuffer;
|
cannam@140
|
341 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
342
|
cannam@140
|
343 while( count-- )
|
cannam@140
|
344 {
|
cannam@140
|
345 /* REVIEW */
|
cannam@140
|
346 #ifdef PA_USE_C99_LRINTF
|
cannam@140
|
347 float scaled = *src * 0x7FFFFFFF;
|
cannam@140
|
348 *dest = lrintf(scaled-0.5f);
|
cannam@140
|
349 #else
|
cannam@140
|
350 double scaled = *src * 0x7FFFFFFF;
|
cannam@140
|
351 *dest = (PaInt32) scaled;
|
cannam@140
|
352 #endif
|
cannam@140
|
353
|
cannam@140
|
354 src += sourceStride;
|
cannam@140
|
355 dest += destinationStride;
|
cannam@140
|
356 }
|
cannam@140
|
357 }
|
cannam@140
|
358
|
cannam@140
|
359 /* -------------------------------------------------------------------------- */
|
cannam@140
|
360
|
cannam@140
|
361 static void Float32_To_Int32_Dither(
|
cannam@140
|
362 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
363 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
364 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
365 {
|
cannam@140
|
366 float *src = (float*)sourceBuffer;
|
cannam@140
|
367 PaInt32 *dest = (PaInt32*)destinationBuffer;
|
cannam@140
|
368
|
cannam@140
|
369 while( count-- )
|
cannam@140
|
370 {
|
cannam@140
|
371 /* REVIEW */
|
cannam@140
|
372 #ifdef PA_USE_C99_LRINTF
|
cannam@140
|
373 float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
374 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
375 float dithered = ((float)*src * (2147483646.0f)) + dither;
|
cannam@140
|
376 *dest = lrintf(dithered - 0.5f);
|
cannam@140
|
377 #else
|
cannam@140
|
378 double dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
379 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
380 double dithered = ((double)*src * (2147483646.0)) + dither;
|
cannam@140
|
381 *dest = (PaInt32) dithered;
|
cannam@140
|
382 #endif
|
cannam@140
|
383 src += sourceStride;
|
cannam@140
|
384 dest += destinationStride;
|
cannam@140
|
385 }
|
cannam@140
|
386 }
|
cannam@140
|
387
|
cannam@140
|
388 /* -------------------------------------------------------------------------- */
|
cannam@140
|
389
|
cannam@140
|
390 static void Float32_To_Int32_Clip(
|
cannam@140
|
391 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
392 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
393 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
394 {
|
cannam@140
|
395 float *src = (float*)sourceBuffer;
|
cannam@140
|
396 PaInt32 *dest = (PaInt32*)destinationBuffer;
|
cannam@140
|
397 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
398
|
cannam@140
|
399 while( count-- )
|
cannam@140
|
400 {
|
cannam@140
|
401 /* REVIEW */
|
cannam@140
|
402 #ifdef PA_USE_C99_LRINTF
|
cannam@140
|
403 float scaled = *src * 0x7FFFFFFF;
|
cannam@140
|
404 PA_CLIP_( scaled, -2147483648.f, 2147483647.f );
|
cannam@140
|
405 *dest = lrintf(scaled-0.5f);
|
cannam@140
|
406 #else
|
cannam@140
|
407 double scaled = *src * 0x7FFFFFFF;
|
cannam@140
|
408 PA_CLIP_( scaled, -2147483648., 2147483647. );
|
cannam@140
|
409 *dest = (PaInt32) scaled;
|
cannam@140
|
410 #endif
|
cannam@140
|
411
|
cannam@140
|
412 src += sourceStride;
|
cannam@140
|
413 dest += destinationStride;
|
cannam@140
|
414 }
|
cannam@140
|
415 }
|
cannam@140
|
416
|
cannam@140
|
417 /* -------------------------------------------------------------------------- */
|
cannam@140
|
418
|
cannam@140
|
419 static void Float32_To_Int32_DitherClip(
|
cannam@140
|
420 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
421 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
422 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
423 {
|
cannam@140
|
424 float *src = (float*)sourceBuffer;
|
cannam@140
|
425 PaInt32 *dest = (PaInt32*)destinationBuffer;
|
cannam@140
|
426
|
cannam@140
|
427 while( count-- )
|
cannam@140
|
428 {
|
cannam@140
|
429 /* REVIEW */
|
cannam@140
|
430 #ifdef PA_USE_C99_LRINTF
|
cannam@140
|
431 float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
432 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
433 float dithered = ((float)*src * (2147483646.0f)) + dither;
|
cannam@140
|
434 PA_CLIP_( dithered, -2147483648.f, 2147483647.f );
|
cannam@140
|
435 *dest = lrintf(dithered-0.5f);
|
cannam@140
|
436 #else
|
cannam@140
|
437 double dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
438 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
439 double dithered = ((double)*src * (2147483646.0)) + dither;
|
cannam@140
|
440 PA_CLIP_( dithered, -2147483648., 2147483647. );
|
cannam@140
|
441 *dest = (PaInt32) dithered;
|
cannam@140
|
442 #endif
|
cannam@140
|
443
|
cannam@140
|
444 src += sourceStride;
|
cannam@140
|
445 dest += destinationStride;
|
cannam@140
|
446 }
|
cannam@140
|
447 }
|
cannam@140
|
448
|
cannam@140
|
449 /* -------------------------------------------------------------------------- */
|
cannam@140
|
450
|
cannam@140
|
451 static void Float32_To_Int24(
|
cannam@140
|
452 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
453 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
454 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
455 {
|
cannam@140
|
456 float *src = (float*)sourceBuffer;
|
cannam@140
|
457 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
458 PaInt32 temp;
|
cannam@140
|
459
|
cannam@140
|
460 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
461
|
cannam@140
|
462 while( count-- )
|
cannam@140
|
463 {
|
cannam@140
|
464 /* convert to 32 bit and drop the low 8 bits */
|
cannam@140
|
465 double scaled = (double)(*src) * 2147483647.0;
|
cannam@140
|
466 temp = (PaInt32) scaled;
|
cannam@140
|
467
|
cannam@140
|
468 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
469 dest[0] = (unsigned char)(temp >> 8);
|
cannam@140
|
470 dest[1] = (unsigned char)(temp >> 16);
|
cannam@140
|
471 dest[2] = (unsigned char)(temp >> 24);
|
cannam@140
|
472 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
473 dest[0] = (unsigned char)(temp >> 24);
|
cannam@140
|
474 dest[1] = (unsigned char)(temp >> 16);
|
cannam@140
|
475 dest[2] = (unsigned char)(temp >> 8);
|
cannam@140
|
476 #endif
|
cannam@140
|
477
|
cannam@140
|
478 src += sourceStride;
|
cannam@140
|
479 dest += destinationStride * 3;
|
cannam@140
|
480 }
|
cannam@140
|
481 }
|
cannam@140
|
482
|
cannam@140
|
483 /* -------------------------------------------------------------------------- */
|
cannam@140
|
484
|
cannam@140
|
485 static void Float32_To_Int24_Dither(
|
cannam@140
|
486 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
487 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
488 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
489 {
|
cannam@140
|
490 float *src = (float*)sourceBuffer;
|
cannam@140
|
491 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
492 PaInt32 temp;
|
cannam@140
|
493
|
cannam@140
|
494 while( count-- )
|
cannam@140
|
495 {
|
cannam@140
|
496 /* convert to 32 bit and drop the low 8 bits */
|
cannam@140
|
497
|
cannam@140
|
498 double dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
499 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
500 double dithered = ((double)*src * (2147483646.0)) + dither;
|
cannam@140
|
501
|
cannam@140
|
502 temp = (PaInt32) dithered;
|
cannam@140
|
503
|
cannam@140
|
504 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
505 dest[0] = (unsigned char)(temp >> 8);
|
cannam@140
|
506 dest[1] = (unsigned char)(temp >> 16);
|
cannam@140
|
507 dest[2] = (unsigned char)(temp >> 24);
|
cannam@140
|
508 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
509 dest[0] = (unsigned char)(temp >> 24);
|
cannam@140
|
510 dest[1] = (unsigned char)(temp >> 16);
|
cannam@140
|
511 dest[2] = (unsigned char)(temp >> 8);
|
cannam@140
|
512 #endif
|
cannam@140
|
513
|
cannam@140
|
514 src += sourceStride;
|
cannam@140
|
515 dest += destinationStride * 3;
|
cannam@140
|
516 }
|
cannam@140
|
517 }
|
cannam@140
|
518
|
cannam@140
|
519 /* -------------------------------------------------------------------------- */
|
cannam@140
|
520
|
cannam@140
|
521 static void Float32_To_Int24_Clip(
|
cannam@140
|
522 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
523 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
524 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
525 {
|
cannam@140
|
526 float *src = (float*)sourceBuffer;
|
cannam@140
|
527 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
528 PaInt32 temp;
|
cannam@140
|
529
|
cannam@140
|
530 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
531
|
cannam@140
|
532 while( count-- )
|
cannam@140
|
533 {
|
cannam@140
|
534 /* convert to 32 bit and drop the low 8 bits */
|
cannam@140
|
535 double scaled = *src * 0x7FFFFFFF;
|
cannam@140
|
536 PA_CLIP_( scaled, -2147483648., 2147483647. );
|
cannam@140
|
537 temp = (PaInt32) scaled;
|
cannam@140
|
538
|
cannam@140
|
539 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
540 dest[0] = (unsigned char)(temp >> 8);
|
cannam@140
|
541 dest[1] = (unsigned char)(temp >> 16);
|
cannam@140
|
542 dest[2] = (unsigned char)(temp >> 24);
|
cannam@140
|
543 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
544 dest[0] = (unsigned char)(temp >> 24);
|
cannam@140
|
545 dest[1] = (unsigned char)(temp >> 16);
|
cannam@140
|
546 dest[2] = (unsigned char)(temp >> 8);
|
cannam@140
|
547 #endif
|
cannam@140
|
548
|
cannam@140
|
549 src += sourceStride;
|
cannam@140
|
550 dest += destinationStride * 3;
|
cannam@140
|
551 }
|
cannam@140
|
552 }
|
cannam@140
|
553
|
cannam@140
|
554 /* -------------------------------------------------------------------------- */
|
cannam@140
|
555
|
cannam@140
|
556 static void Float32_To_Int24_DitherClip(
|
cannam@140
|
557 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
558 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
559 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
560 {
|
cannam@140
|
561 float *src = (float*)sourceBuffer;
|
cannam@140
|
562 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
563 PaInt32 temp;
|
cannam@140
|
564
|
cannam@140
|
565 while( count-- )
|
cannam@140
|
566 {
|
cannam@140
|
567 /* convert to 32 bit and drop the low 8 bits */
|
cannam@140
|
568
|
cannam@140
|
569 double dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
570 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
571 double dithered = ((double)*src * (2147483646.0)) + dither;
|
cannam@140
|
572 PA_CLIP_( dithered, -2147483648., 2147483647. );
|
cannam@140
|
573
|
cannam@140
|
574 temp = (PaInt32) dithered;
|
cannam@140
|
575
|
cannam@140
|
576 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
577 dest[0] = (unsigned char)(temp >> 8);
|
cannam@140
|
578 dest[1] = (unsigned char)(temp >> 16);
|
cannam@140
|
579 dest[2] = (unsigned char)(temp >> 24);
|
cannam@140
|
580 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
581 dest[0] = (unsigned char)(temp >> 24);
|
cannam@140
|
582 dest[1] = (unsigned char)(temp >> 16);
|
cannam@140
|
583 dest[2] = (unsigned char)(temp >> 8);
|
cannam@140
|
584 #endif
|
cannam@140
|
585
|
cannam@140
|
586 src += sourceStride;
|
cannam@140
|
587 dest += destinationStride * 3;
|
cannam@140
|
588 }
|
cannam@140
|
589 }
|
cannam@140
|
590
|
cannam@140
|
591 /* -------------------------------------------------------------------------- */
|
cannam@140
|
592
|
cannam@140
|
593 static void Float32_To_Int16(
|
cannam@140
|
594 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
595 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
596 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
597 {
|
cannam@140
|
598 float *src = (float*)sourceBuffer;
|
cannam@140
|
599 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
600 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
601
|
cannam@140
|
602 while( count-- )
|
cannam@140
|
603 {
|
cannam@140
|
604 #ifdef PA_USE_C99_LRINTF
|
cannam@140
|
605 float tempf = (*src * (32767.0f)) ;
|
cannam@140
|
606 *dest = lrintf(tempf-0.5f);
|
cannam@140
|
607 #else
|
cannam@140
|
608 short samp = (short) (*src * (32767.0f));
|
cannam@140
|
609 *dest = samp;
|
cannam@140
|
610 #endif
|
cannam@140
|
611
|
cannam@140
|
612 src += sourceStride;
|
cannam@140
|
613 dest += destinationStride;
|
cannam@140
|
614 }
|
cannam@140
|
615 }
|
cannam@140
|
616
|
cannam@140
|
617 /* -------------------------------------------------------------------------- */
|
cannam@140
|
618
|
cannam@140
|
619 static void Float32_To_Int16_Dither(
|
cannam@140
|
620 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
621 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
622 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
623 {
|
cannam@140
|
624 float *src = (float*)sourceBuffer;
|
cannam@140
|
625 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
626
|
cannam@140
|
627 while( count-- )
|
cannam@140
|
628 {
|
cannam@140
|
629
|
cannam@140
|
630 float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
631 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
632 float dithered = (*src * (32766.0f)) + dither;
|
cannam@140
|
633
|
cannam@140
|
634 #ifdef PA_USE_C99_LRINTF
|
cannam@140
|
635 *dest = lrintf(dithered-0.5f);
|
cannam@140
|
636 #else
|
cannam@140
|
637 *dest = (PaInt16) dithered;
|
cannam@140
|
638 #endif
|
cannam@140
|
639
|
cannam@140
|
640 src += sourceStride;
|
cannam@140
|
641 dest += destinationStride;
|
cannam@140
|
642 }
|
cannam@140
|
643 }
|
cannam@140
|
644
|
cannam@140
|
645 /* -------------------------------------------------------------------------- */
|
cannam@140
|
646
|
cannam@140
|
647 static void Float32_To_Int16_Clip(
|
cannam@140
|
648 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
649 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
650 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
651 {
|
cannam@140
|
652 float *src = (float*)sourceBuffer;
|
cannam@140
|
653 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
654 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
655
|
cannam@140
|
656 while( count-- )
|
cannam@140
|
657 {
|
cannam@140
|
658 #ifdef PA_USE_C99_LRINTF
|
cannam@140
|
659 long samp = lrintf((*src * (32767.0f)) -0.5f);
|
cannam@140
|
660 #else
|
cannam@140
|
661 long samp = (PaInt32) (*src * (32767.0f));
|
cannam@140
|
662 #endif
|
cannam@140
|
663 PA_CLIP_( samp, -0x8000, 0x7FFF );
|
cannam@140
|
664 *dest = (PaInt16) samp;
|
cannam@140
|
665
|
cannam@140
|
666 src += sourceStride;
|
cannam@140
|
667 dest += destinationStride;
|
cannam@140
|
668 }
|
cannam@140
|
669 }
|
cannam@140
|
670
|
cannam@140
|
671 /* -------------------------------------------------------------------------- */
|
cannam@140
|
672
|
cannam@140
|
673 static void Float32_To_Int16_DitherClip(
|
cannam@140
|
674 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
675 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
676 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
677 {
|
cannam@140
|
678 float *src = (float*)sourceBuffer;
|
cannam@140
|
679 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
680 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
681
|
cannam@140
|
682 while( count-- )
|
cannam@140
|
683 {
|
cannam@140
|
684
|
cannam@140
|
685 float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
686 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
687 float dithered = (*src * (32766.0f)) + dither;
|
cannam@140
|
688 PaInt32 samp = (PaInt32) dithered;
|
cannam@140
|
689 PA_CLIP_( samp, -0x8000, 0x7FFF );
|
cannam@140
|
690 #ifdef PA_USE_C99_LRINTF
|
cannam@140
|
691 *dest = lrintf(samp-0.5f);
|
cannam@140
|
692 #else
|
cannam@140
|
693 *dest = (PaInt16) samp;
|
cannam@140
|
694 #endif
|
cannam@140
|
695
|
cannam@140
|
696 src += sourceStride;
|
cannam@140
|
697 dest += destinationStride;
|
cannam@140
|
698 }
|
cannam@140
|
699 }
|
cannam@140
|
700
|
cannam@140
|
701 /* -------------------------------------------------------------------------- */
|
cannam@140
|
702
|
cannam@140
|
703 static void Float32_To_Int8(
|
cannam@140
|
704 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
705 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
706 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
707 {
|
cannam@140
|
708 float *src = (float*)sourceBuffer;
|
cannam@140
|
709 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
710 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
711
|
cannam@140
|
712 while( count-- )
|
cannam@140
|
713 {
|
cannam@140
|
714 signed char samp = (signed char) (*src * (127.0f));
|
cannam@140
|
715 *dest = samp;
|
cannam@140
|
716
|
cannam@140
|
717 src += sourceStride;
|
cannam@140
|
718 dest += destinationStride;
|
cannam@140
|
719 }
|
cannam@140
|
720 }
|
cannam@140
|
721
|
cannam@140
|
722 /* -------------------------------------------------------------------------- */
|
cannam@140
|
723
|
cannam@140
|
724 static void Float32_To_Int8_Dither(
|
cannam@140
|
725 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
726 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
727 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
728 {
|
cannam@140
|
729 float *src = (float*)sourceBuffer;
|
cannam@140
|
730 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
731
|
cannam@140
|
732 while( count-- )
|
cannam@140
|
733 {
|
cannam@140
|
734 float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
735 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
736 float dithered = (*src * (126.0f)) + dither;
|
cannam@140
|
737 PaInt32 samp = (PaInt32) dithered;
|
cannam@140
|
738 *dest = (signed char) samp;
|
cannam@140
|
739
|
cannam@140
|
740 src += sourceStride;
|
cannam@140
|
741 dest += destinationStride;
|
cannam@140
|
742 }
|
cannam@140
|
743 }
|
cannam@140
|
744
|
cannam@140
|
745 /* -------------------------------------------------------------------------- */
|
cannam@140
|
746
|
cannam@140
|
747 static void Float32_To_Int8_Clip(
|
cannam@140
|
748 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
749 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
750 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
751 {
|
cannam@140
|
752 float *src = (float*)sourceBuffer;
|
cannam@140
|
753 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
754 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
755
|
cannam@140
|
756 while( count-- )
|
cannam@140
|
757 {
|
cannam@140
|
758 PaInt32 samp = (PaInt32)(*src * (127.0f));
|
cannam@140
|
759 PA_CLIP_( samp, -0x80, 0x7F );
|
cannam@140
|
760 *dest = (signed char) samp;
|
cannam@140
|
761
|
cannam@140
|
762 src += sourceStride;
|
cannam@140
|
763 dest += destinationStride;
|
cannam@140
|
764 }
|
cannam@140
|
765 }
|
cannam@140
|
766
|
cannam@140
|
767 /* -------------------------------------------------------------------------- */
|
cannam@140
|
768
|
cannam@140
|
769 static void Float32_To_Int8_DitherClip(
|
cannam@140
|
770 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
771 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
772 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
773 {
|
cannam@140
|
774 float *src = (float*)sourceBuffer;
|
cannam@140
|
775 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
776 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
777
|
cannam@140
|
778 while( count-- )
|
cannam@140
|
779 {
|
cannam@140
|
780 float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
781 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
782 float dithered = (*src * (126.0f)) + dither;
|
cannam@140
|
783 PaInt32 samp = (PaInt32) dithered;
|
cannam@140
|
784 PA_CLIP_( samp, -0x80, 0x7F );
|
cannam@140
|
785 *dest = (signed char) samp;
|
cannam@140
|
786
|
cannam@140
|
787 src += sourceStride;
|
cannam@140
|
788 dest += destinationStride;
|
cannam@140
|
789 }
|
cannam@140
|
790 }
|
cannam@140
|
791
|
cannam@140
|
792 /* -------------------------------------------------------------------------- */
|
cannam@140
|
793
|
cannam@140
|
794 static void Float32_To_UInt8(
|
cannam@140
|
795 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
796 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
797 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
798 {
|
cannam@140
|
799 float *src = (float*)sourceBuffer;
|
cannam@140
|
800 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
801 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
802
|
cannam@140
|
803 while( count-- )
|
cannam@140
|
804 {
|
cannam@140
|
805 unsigned char samp = (unsigned char)(128 + ((unsigned char) (*src * (127.0f))));
|
cannam@140
|
806 *dest = samp;
|
cannam@140
|
807
|
cannam@140
|
808 src += sourceStride;
|
cannam@140
|
809 dest += destinationStride;
|
cannam@140
|
810 }
|
cannam@140
|
811 }
|
cannam@140
|
812
|
cannam@140
|
813 /* -------------------------------------------------------------------------- */
|
cannam@140
|
814
|
cannam@140
|
815 static void Float32_To_UInt8_Dither(
|
cannam@140
|
816 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
817 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
818 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
819 {
|
cannam@140
|
820 float *src = (float*)sourceBuffer;
|
cannam@140
|
821 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
822
|
cannam@140
|
823 while( count-- )
|
cannam@140
|
824 {
|
cannam@140
|
825 float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
826 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
827 float dithered = (*src * (126.0f)) + dither;
|
cannam@140
|
828 PaInt32 samp = (PaInt32) dithered;
|
cannam@140
|
829 *dest = (unsigned char) (128 + samp);
|
cannam@140
|
830
|
cannam@140
|
831 src += sourceStride;
|
cannam@140
|
832 dest += destinationStride;
|
cannam@140
|
833 }
|
cannam@140
|
834 }
|
cannam@140
|
835
|
cannam@140
|
836 /* -------------------------------------------------------------------------- */
|
cannam@140
|
837
|
cannam@140
|
838 static void Float32_To_UInt8_Clip(
|
cannam@140
|
839 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
840 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
841 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
842 {
|
cannam@140
|
843 float *src = (float*)sourceBuffer;
|
cannam@140
|
844 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
845 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
846
|
cannam@140
|
847 while( count-- )
|
cannam@140
|
848 {
|
cannam@140
|
849 PaInt32 samp = 128 + (PaInt32)(*src * (127.0f));
|
cannam@140
|
850 PA_CLIP_( samp, 0x0000, 0x00FF );
|
cannam@140
|
851 *dest = (unsigned char) samp;
|
cannam@140
|
852
|
cannam@140
|
853 src += sourceStride;
|
cannam@140
|
854 dest += destinationStride;
|
cannam@140
|
855 }
|
cannam@140
|
856 }
|
cannam@140
|
857
|
cannam@140
|
858 /* -------------------------------------------------------------------------- */
|
cannam@140
|
859
|
cannam@140
|
860 static void Float32_To_UInt8_DitherClip(
|
cannam@140
|
861 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
862 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
863 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
864 {
|
cannam@140
|
865 float *src = (float*)sourceBuffer;
|
cannam@140
|
866 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
867 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
868
|
cannam@140
|
869 while( count-- )
|
cannam@140
|
870 {
|
cannam@140
|
871 float dither = PaUtil_GenerateFloatTriangularDither( ditherGenerator );
|
cannam@140
|
872 /* use smaller scaler to prevent overflow when we add the dither */
|
cannam@140
|
873 float dithered = (*src * (126.0f)) + dither;
|
cannam@140
|
874 PaInt32 samp = 128 + (PaInt32) dithered;
|
cannam@140
|
875 PA_CLIP_( samp, 0x0000, 0x00FF );
|
cannam@140
|
876 *dest = (unsigned char) samp;
|
cannam@140
|
877
|
cannam@140
|
878 src += sourceStride;
|
cannam@140
|
879 dest += destinationStride;
|
cannam@140
|
880 }
|
cannam@140
|
881 }
|
cannam@140
|
882
|
cannam@140
|
883 /* -------------------------------------------------------------------------- */
|
cannam@140
|
884
|
cannam@140
|
885 static void Int32_To_Float32(
|
cannam@140
|
886 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
887 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
888 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
889 {
|
cannam@140
|
890 PaInt32 *src = (PaInt32*)sourceBuffer;
|
cannam@140
|
891 float *dest = (float*)destinationBuffer;
|
cannam@140
|
892 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
893
|
cannam@140
|
894 while( count-- )
|
cannam@140
|
895 {
|
cannam@140
|
896 *dest = (float) ((double)*src * const_1_div_2147483648_);
|
cannam@140
|
897
|
cannam@140
|
898 src += sourceStride;
|
cannam@140
|
899 dest += destinationStride;
|
cannam@140
|
900 }
|
cannam@140
|
901 }
|
cannam@140
|
902
|
cannam@140
|
903 /* -------------------------------------------------------------------------- */
|
cannam@140
|
904
|
cannam@140
|
905 static void Int32_To_Int24(
|
cannam@140
|
906 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
907 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
908 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
909 {
|
cannam@140
|
910 PaInt32 *src = (PaInt32*)sourceBuffer;
|
cannam@140
|
911 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
912 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
913
|
cannam@140
|
914 while( count-- )
|
cannam@140
|
915 {
|
cannam@140
|
916 /* REVIEW */
|
cannam@140
|
917 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
918 dest[0] = (unsigned char)(*src >> 8);
|
cannam@140
|
919 dest[1] = (unsigned char)(*src >> 16);
|
cannam@140
|
920 dest[2] = (unsigned char)(*src >> 24);
|
cannam@140
|
921 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
922 dest[0] = (unsigned char)(*src >> 24);
|
cannam@140
|
923 dest[1] = (unsigned char)(*src >> 16);
|
cannam@140
|
924 dest[2] = (unsigned char)(*src >> 8);
|
cannam@140
|
925 #endif
|
cannam@140
|
926 src += sourceStride;
|
cannam@140
|
927 dest += destinationStride * 3;
|
cannam@140
|
928 }
|
cannam@140
|
929 }
|
cannam@140
|
930
|
cannam@140
|
931 /* -------------------------------------------------------------------------- */
|
cannam@140
|
932
|
cannam@140
|
933 static void Int32_To_Int24_Dither(
|
cannam@140
|
934 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
935 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
936 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
937 {
|
cannam@140
|
938 (void) destinationBuffer; /* unused parameters */
|
cannam@140
|
939 (void) destinationStride; /* unused parameters */
|
cannam@140
|
940 (void) sourceBuffer; /* unused parameters */
|
cannam@140
|
941 (void) sourceStride; /* unused parameters */
|
cannam@140
|
942 (void) count; /* unused parameters */
|
cannam@140
|
943 (void) ditherGenerator; /* unused parameters */
|
cannam@140
|
944 /* IMPLEMENT ME */
|
cannam@140
|
945 }
|
cannam@140
|
946
|
cannam@140
|
947 /* -------------------------------------------------------------------------- */
|
cannam@140
|
948
|
cannam@140
|
949 static void Int32_To_Int16(
|
cannam@140
|
950 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
951 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
952 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
953 {
|
cannam@140
|
954 PaInt32 *src = (PaInt32*)sourceBuffer;
|
cannam@140
|
955 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
956 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
957
|
cannam@140
|
958 while( count-- )
|
cannam@140
|
959 {
|
cannam@140
|
960 *dest = (PaInt16) ((*src) >> 16);
|
cannam@140
|
961
|
cannam@140
|
962 src += sourceStride;
|
cannam@140
|
963 dest += destinationStride;
|
cannam@140
|
964 }
|
cannam@140
|
965 }
|
cannam@140
|
966
|
cannam@140
|
967 /* -------------------------------------------------------------------------- */
|
cannam@140
|
968
|
cannam@140
|
969 static void Int32_To_Int16_Dither(
|
cannam@140
|
970 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
971 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
972 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
973 {
|
cannam@140
|
974 PaInt32 *src = (PaInt32*)sourceBuffer;
|
cannam@140
|
975 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
976 PaInt32 dither;
|
cannam@140
|
977
|
cannam@140
|
978 while( count-- )
|
cannam@140
|
979 {
|
cannam@140
|
980 /* REVIEW */
|
cannam@140
|
981 dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
|
cannam@140
|
982 *dest = (PaInt16) ((((*src)>>1) + dither) >> 15);
|
cannam@140
|
983
|
cannam@140
|
984 src += sourceStride;
|
cannam@140
|
985 dest += destinationStride;
|
cannam@140
|
986 }
|
cannam@140
|
987 }
|
cannam@140
|
988
|
cannam@140
|
989 /* -------------------------------------------------------------------------- */
|
cannam@140
|
990
|
cannam@140
|
991 static void Int32_To_Int8(
|
cannam@140
|
992 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
993 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
994 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
995 {
|
cannam@140
|
996 PaInt32 *src = (PaInt32*)sourceBuffer;
|
cannam@140
|
997 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
998 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
999
|
cannam@140
|
1000 while( count-- )
|
cannam@140
|
1001 {
|
cannam@140
|
1002 *dest = (signed char) ((*src) >> 24);
|
cannam@140
|
1003
|
cannam@140
|
1004 src += sourceStride;
|
cannam@140
|
1005 dest += destinationStride;
|
cannam@140
|
1006 }
|
cannam@140
|
1007 }
|
cannam@140
|
1008
|
cannam@140
|
1009 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1010
|
cannam@140
|
1011 static void Int32_To_Int8_Dither(
|
cannam@140
|
1012 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1013 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1014 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1015 {
|
cannam@140
|
1016 PaInt32 *src = (PaInt32*)sourceBuffer;
|
cannam@140
|
1017 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
1018 PaInt32 dither;
|
cannam@140
|
1019
|
cannam@140
|
1020 while( count-- )
|
cannam@140
|
1021 {
|
cannam@140
|
1022 /* REVIEW */
|
cannam@140
|
1023 dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
|
cannam@140
|
1024 *dest = (signed char) ((((*src)>>1) + dither) >> 23);
|
cannam@140
|
1025
|
cannam@140
|
1026 src += sourceStride;
|
cannam@140
|
1027 dest += destinationStride;
|
cannam@140
|
1028 }
|
cannam@140
|
1029 }
|
cannam@140
|
1030
|
cannam@140
|
1031 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1032
|
cannam@140
|
1033 static void Int32_To_UInt8(
|
cannam@140
|
1034 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1035 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1036 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1037 {
|
cannam@140
|
1038 PaInt32 *src = (PaInt32*)sourceBuffer;
|
cannam@140
|
1039 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1040 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1041
|
cannam@140
|
1042 while( count-- )
|
cannam@140
|
1043 {
|
cannam@140
|
1044 (*dest) = (unsigned char)(((*src) >> 24) + 128);
|
cannam@140
|
1045
|
cannam@140
|
1046 src += sourceStride;
|
cannam@140
|
1047 dest += destinationStride;
|
cannam@140
|
1048 }
|
cannam@140
|
1049 }
|
cannam@140
|
1050
|
cannam@140
|
1051 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1052
|
cannam@140
|
1053 static void Int32_To_UInt8_Dither(
|
cannam@140
|
1054 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1055 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1056 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1057 {
|
cannam@140
|
1058 PaInt32 *src = (PaInt32*)sourceBuffer;
|
cannam@140
|
1059 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1060 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1061
|
cannam@140
|
1062 while( count-- )
|
cannam@140
|
1063 {
|
cannam@140
|
1064 /* IMPLEMENT ME */
|
cannam@140
|
1065
|
cannam@140
|
1066 src += sourceStride;
|
cannam@140
|
1067 dest += destinationStride;
|
cannam@140
|
1068 }
|
cannam@140
|
1069 }
|
cannam@140
|
1070
|
cannam@140
|
1071 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1072
|
cannam@140
|
1073 static void Int24_To_Float32(
|
cannam@140
|
1074 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1075 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1076 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1077 {
|
cannam@140
|
1078 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1079 float *dest = (float*)destinationBuffer;
|
cannam@140
|
1080 PaInt32 temp;
|
cannam@140
|
1081
|
cannam@140
|
1082 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1083
|
cannam@140
|
1084 while( count-- )
|
cannam@140
|
1085 {
|
cannam@140
|
1086
|
cannam@140
|
1087 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1088 temp = (((PaInt32)src[0]) << 8);
|
cannam@140
|
1089 temp = temp | (((PaInt32)src[1]) << 16);
|
cannam@140
|
1090 temp = temp | (((PaInt32)src[2]) << 24);
|
cannam@140
|
1091 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1092 temp = (((PaInt32)src[0]) << 24);
|
cannam@140
|
1093 temp = temp | (((PaInt32)src[1]) << 16);
|
cannam@140
|
1094 temp = temp | (((PaInt32)src[2]) << 8);
|
cannam@140
|
1095 #endif
|
cannam@140
|
1096
|
cannam@140
|
1097 *dest = (float) ((double)temp * const_1_div_2147483648_);
|
cannam@140
|
1098
|
cannam@140
|
1099 src += sourceStride * 3;
|
cannam@140
|
1100 dest += destinationStride;
|
cannam@140
|
1101 }
|
cannam@140
|
1102 }
|
cannam@140
|
1103
|
cannam@140
|
1104 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1105
|
cannam@140
|
1106 static void Int24_To_Int32(
|
cannam@140
|
1107 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1108 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1109 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1110 {
|
cannam@140
|
1111 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1112 PaInt32 *dest = (PaInt32*) destinationBuffer;
|
cannam@140
|
1113 PaInt32 temp;
|
cannam@140
|
1114
|
cannam@140
|
1115 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1116
|
cannam@140
|
1117 while( count-- )
|
cannam@140
|
1118 {
|
cannam@140
|
1119
|
cannam@140
|
1120 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1121 temp = (((PaInt32)src[0]) << 8);
|
cannam@140
|
1122 temp = temp | (((PaInt32)src[1]) << 16);
|
cannam@140
|
1123 temp = temp | (((PaInt32)src[2]) << 24);
|
cannam@140
|
1124 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1125 temp = (((PaInt32)src[0]) << 24);
|
cannam@140
|
1126 temp = temp | (((PaInt32)src[1]) << 16);
|
cannam@140
|
1127 temp = temp | (((PaInt32)src[2]) << 8);
|
cannam@140
|
1128 #endif
|
cannam@140
|
1129
|
cannam@140
|
1130 *dest = temp;
|
cannam@140
|
1131
|
cannam@140
|
1132 src += sourceStride * 3;
|
cannam@140
|
1133 dest += destinationStride;
|
cannam@140
|
1134 }
|
cannam@140
|
1135 }
|
cannam@140
|
1136
|
cannam@140
|
1137 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1138
|
cannam@140
|
1139 static void Int24_To_Int16(
|
cannam@140
|
1140 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1141 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1142 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1143 {
|
cannam@140
|
1144 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1145 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
1146
|
cannam@140
|
1147 PaInt16 temp;
|
cannam@140
|
1148
|
cannam@140
|
1149 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1150
|
cannam@140
|
1151 while( count-- )
|
cannam@140
|
1152 {
|
cannam@140
|
1153
|
cannam@140
|
1154 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1155 /* src[0] is discarded */
|
cannam@140
|
1156 temp = (((PaInt16)src[1]));
|
cannam@140
|
1157 temp = temp | (PaInt16)(((PaInt16)src[2]) << 8);
|
cannam@140
|
1158 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1159 /* src[2] is discarded */
|
cannam@140
|
1160 temp = (PaInt16)(((PaInt16)src[0]) << 8);
|
cannam@140
|
1161 temp = temp | (((PaInt16)src[1]));
|
cannam@140
|
1162 #endif
|
cannam@140
|
1163
|
cannam@140
|
1164 *dest = temp;
|
cannam@140
|
1165
|
cannam@140
|
1166 src += sourceStride * 3;
|
cannam@140
|
1167 dest += destinationStride;
|
cannam@140
|
1168 }
|
cannam@140
|
1169 }
|
cannam@140
|
1170
|
cannam@140
|
1171 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1172
|
cannam@140
|
1173 static void Int24_To_Int16_Dither(
|
cannam@140
|
1174 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1175 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1176 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1177 {
|
cannam@140
|
1178 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1179 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
1180
|
cannam@140
|
1181 PaInt32 temp, dither;
|
cannam@140
|
1182
|
cannam@140
|
1183 while( count-- )
|
cannam@140
|
1184 {
|
cannam@140
|
1185
|
cannam@140
|
1186 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1187 temp = (((PaInt32)src[0]) << 8);
|
cannam@140
|
1188 temp = temp | (((PaInt32)src[1]) << 16);
|
cannam@140
|
1189 temp = temp | (((PaInt32)src[2]) << 24);
|
cannam@140
|
1190 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1191 temp = (((PaInt32)src[0]) << 24);
|
cannam@140
|
1192 temp = temp | (((PaInt32)src[1]) << 16);
|
cannam@140
|
1193 temp = temp | (((PaInt32)src[2]) << 8);
|
cannam@140
|
1194 #endif
|
cannam@140
|
1195
|
cannam@140
|
1196 /* REVIEW */
|
cannam@140
|
1197 dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
|
cannam@140
|
1198 *dest = (PaInt16) (((temp >> 1) + dither) >> 15);
|
cannam@140
|
1199
|
cannam@140
|
1200 src += sourceStride * 3;
|
cannam@140
|
1201 dest += destinationStride;
|
cannam@140
|
1202 }
|
cannam@140
|
1203 }
|
cannam@140
|
1204
|
cannam@140
|
1205 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1206
|
cannam@140
|
1207 static void Int24_To_Int8(
|
cannam@140
|
1208 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1209 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1210 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1211 {
|
cannam@140
|
1212 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1213 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
1214
|
cannam@140
|
1215 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1216
|
cannam@140
|
1217 while( count-- )
|
cannam@140
|
1218 {
|
cannam@140
|
1219
|
cannam@140
|
1220 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1221 /* src[0] is discarded */
|
cannam@140
|
1222 /* src[1] is discarded */
|
cannam@140
|
1223 *dest = src[2];
|
cannam@140
|
1224 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1225 /* src[2] is discarded */
|
cannam@140
|
1226 /* src[1] is discarded */
|
cannam@140
|
1227 *dest = src[0];
|
cannam@140
|
1228 #endif
|
cannam@140
|
1229
|
cannam@140
|
1230 src += sourceStride * 3;
|
cannam@140
|
1231 dest += destinationStride;
|
cannam@140
|
1232 }
|
cannam@140
|
1233 }
|
cannam@140
|
1234
|
cannam@140
|
1235 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1236
|
cannam@140
|
1237 static void Int24_To_Int8_Dither(
|
cannam@140
|
1238 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1239 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1240 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1241 {
|
cannam@140
|
1242 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1243 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
1244
|
cannam@140
|
1245 PaInt32 temp, dither;
|
cannam@140
|
1246
|
cannam@140
|
1247 while( count-- )
|
cannam@140
|
1248 {
|
cannam@140
|
1249
|
cannam@140
|
1250 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1251 temp = (((PaInt32)src[0]) << 8);
|
cannam@140
|
1252 temp = temp | (((PaInt32)src[1]) << 16);
|
cannam@140
|
1253 temp = temp | (((PaInt32)src[2]) << 24);
|
cannam@140
|
1254 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1255 temp = (((PaInt32)src[0]) << 24);
|
cannam@140
|
1256 temp = temp | (((PaInt32)src[1]) << 16);
|
cannam@140
|
1257 temp = temp | (((PaInt32)src[2]) << 8);
|
cannam@140
|
1258 #endif
|
cannam@140
|
1259
|
cannam@140
|
1260 /* REVIEW */
|
cannam@140
|
1261 dither = PaUtil_Generate16BitTriangularDither( ditherGenerator );
|
cannam@140
|
1262 *dest = (signed char) (((temp >> 1) + dither) >> 23);
|
cannam@140
|
1263
|
cannam@140
|
1264 src += sourceStride * 3;
|
cannam@140
|
1265 dest += destinationStride;
|
cannam@140
|
1266 }
|
cannam@140
|
1267 }
|
cannam@140
|
1268
|
cannam@140
|
1269 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1270
|
cannam@140
|
1271 static void Int24_To_UInt8(
|
cannam@140
|
1272 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1273 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1274 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1275 {
|
cannam@140
|
1276 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1277 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1278
|
cannam@140
|
1279 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1280
|
cannam@140
|
1281 while( count-- )
|
cannam@140
|
1282 {
|
cannam@140
|
1283
|
cannam@140
|
1284 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1285 /* src[0] is discarded */
|
cannam@140
|
1286 /* src[1] is discarded */
|
cannam@140
|
1287 *dest = (unsigned char)(src[2] + 128);
|
cannam@140
|
1288 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1289 *dest = (unsigned char)(src[0] + 128);
|
cannam@140
|
1290 /* src[1] is discarded */
|
cannam@140
|
1291 /* src[2] is discarded */
|
cannam@140
|
1292 #endif
|
cannam@140
|
1293
|
cannam@140
|
1294 src += sourceStride * 3;
|
cannam@140
|
1295 dest += destinationStride;
|
cannam@140
|
1296 }
|
cannam@140
|
1297 }
|
cannam@140
|
1298
|
cannam@140
|
1299 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1300
|
cannam@140
|
1301 static void Int24_To_UInt8_Dither(
|
cannam@140
|
1302 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1303 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1304 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1305 {
|
cannam@140
|
1306 (void) destinationBuffer; /* unused parameters */
|
cannam@140
|
1307 (void) destinationStride; /* unused parameters */
|
cannam@140
|
1308 (void) sourceBuffer; /* unused parameters */
|
cannam@140
|
1309 (void) sourceStride; /* unused parameters */
|
cannam@140
|
1310 (void) count; /* unused parameters */
|
cannam@140
|
1311 (void) ditherGenerator; /* unused parameters */
|
cannam@140
|
1312 /* IMPLEMENT ME */
|
cannam@140
|
1313 }
|
cannam@140
|
1314
|
cannam@140
|
1315 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1316
|
cannam@140
|
1317 static void Int16_To_Float32(
|
cannam@140
|
1318 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1319 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1320 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1321 {
|
cannam@140
|
1322 PaInt16 *src = (PaInt16*)sourceBuffer;
|
cannam@140
|
1323 float *dest = (float*)destinationBuffer;
|
cannam@140
|
1324 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1325
|
cannam@140
|
1326 while( count-- )
|
cannam@140
|
1327 {
|
cannam@140
|
1328 float samp = *src * const_1_div_32768_; /* FIXME: i'm concerned about this being asymetrical with float->int16 -rb */
|
cannam@140
|
1329 *dest = samp;
|
cannam@140
|
1330
|
cannam@140
|
1331 src += sourceStride;
|
cannam@140
|
1332 dest += destinationStride;
|
cannam@140
|
1333 }
|
cannam@140
|
1334 }
|
cannam@140
|
1335
|
cannam@140
|
1336 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1337
|
cannam@140
|
1338 static void Int16_To_Int32(
|
cannam@140
|
1339 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1340 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1341 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1342 {
|
cannam@140
|
1343 PaInt16 *src = (PaInt16*)sourceBuffer;
|
cannam@140
|
1344 PaInt32 *dest = (PaInt32*)destinationBuffer;
|
cannam@140
|
1345 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1346
|
cannam@140
|
1347 while( count-- )
|
cannam@140
|
1348 {
|
cannam@140
|
1349 /* REVIEW: we should consider something like
|
cannam@140
|
1350 (*src << 16) | (*src & 0xFFFF)
|
cannam@140
|
1351 */
|
cannam@140
|
1352
|
cannam@140
|
1353 *dest = *src << 16;
|
cannam@140
|
1354
|
cannam@140
|
1355 src += sourceStride;
|
cannam@140
|
1356 dest += destinationStride;
|
cannam@140
|
1357 }
|
cannam@140
|
1358 }
|
cannam@140
|
1359
|
cannam@140
|
1360 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1361
|
cannam@140
|
1362 static void Int16_To_Int24(
|
cannam@140
|
1363 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1364 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1365 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1366 {
|
cannam@140
|
1367 PaInt16 *src = (PaInt16*) sourceBuffer;
|
cannam@140
|
1368 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1369 PaInt16 temp;
|
cannam@140
|
1370
|
cannam@140
|
1371 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1372
|
cannam@140
|
1373 while( count-- )
|
cannam@140
|
1374 {
|
cannam@140
|
1375 temp = *src;
|
cannam@140
|
1376
|
cannam@140
|
1377 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1378 dest[0] = 0;
|
cannam@140
|
1379 dest[1] = (unsigned char)(temp);
|
cannam@140
|
1380 dest[2] = (unsigned char)(temp >> 8);
|
cannam@140
|
1381 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1382 dest[0] = (unsigned char)(temp >> 8);
|
cannam@140
|
1383 dest[1] = (unsigned char)(temp);
|
cannam@140
|
1384 dest[2] = 0;
|
cannam@140
|
1385 #endif
|
cannam@140
|
1386
|
cannam@140
|
1387 src += sourceStride;
|
cannam@140
|
1388 dest += destinationStride * 3;
|
cannam@140
|
1389 }
|
cannam@140
|
1390 }
|
cannam@140
|
1391
|
cannam@140
|
1392 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1393
|
cannam@140
|
1394 static void Int16_To_Int8(
|
cannam@140
|
1395 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1396 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1397 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1398 {
|
cannam@140
|
1399 PaInt16 *src = (PaInt16*)sourceBuffer;
|
cannam@140
|
1400 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
1401 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1402
|
cannam@140
|
1403 while( count-- )
|
cannam@140
|
1404 {
|
cannam@140
|
1405 (*dest) = (signed char)((*src) >> 8);
|
cannam@140
|
1406
|
cannam@140
|
1407 src += sourceStride;
|
cannam@140
|
1408 dest += destinationStride;
|
cannam@140
|
1409 }
|
cannam@140
|
1410 }
|
cannam@140
|
1411
|
cannam@140
|
1412 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1413
|
cannam@140
|
1414 static void Int16_To_Int8_Dither(
|
cannam@140
|
1415 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1416 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1417 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1418 {
|
cannam@140
|
1419 PaInt16 *src = (PaInt16*)sourceBuffer;
|
cannam@140
|
1420 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
1421 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1422
|
cannam@140
|
1423 while( count-- )
|
cannam@140
|
1424 {
|
cannam@140
|
1425 /* IMPLEMENT ME */
|
cannam@140
|
1426
|
cannam@140
|
1427 src += sourceStride;
|
cannam@140
|
1428 dest += destinationStride;
|
cannam@140
|
1429 }
|
cannam@140
|
1430 }
|
cannam@140
|
1431
|
cannam@140
|
1432 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1433
|
cannam@140
|
1434 static void Int16_To_UInt8(
|
cannam@140
|
1435 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1436 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1437 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1438 {
|
cannam@140
|
1439 PaInt16 *src = (PaInt16*)sourceBuffer;
|
cannam@140
|
1440 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1441 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1442
|
cannam@140
|
1443 while( count-- )
|
cannam@140
|
1444 {
|
cannam@140
|
1445 (*dest) = (unsigned char)(((*src) >> 8) + 128);
|
cannam@140
|
1446
|
cannam@140
|
1447 src += sourceStride;
|
cannam@140
|
1448 dest += destinationStride;
|
cannam@140
|
1449 }
|
cannam@140
|
1450 }
|
cannam@140
|
1451
|
cannam@140
|
1452 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1453
|
cannam@140
|
1454 static void Int16_To_UInt8_Dither(
|
cannam@140
|
1455 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1456 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1457 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1458 {
|
cannam@140
|
1459 PaInt16 *src = (PaInt16*)sourceBuffer;
|
cannam@140
|
1460 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1461 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1462
|
cannam@140
|
1463 while( count-- )
|
cannam@140
|
1464 {
|
cannam@140
|
1465 /* IMPLEMENT ME */
|
cannam@140
|
1466
|
cannam@140
|
1467 src += sourceStride;
|
cannam@140
|
1468 dest += destinationStride;
|
cannam@140
|
1469 }
|
cannam@140
|
1470 }
|
cannam@140
|
1471
|
cannam@140
|
1472 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1473
|
cannam@140
|
1474 static void Int8_To_Float32(
|
cannam@140
|
1475 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1476 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1477 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1478 {
|
cannam@140
|
1479 signed char *src = (signed char*)sourceBuffer;
|
cannam@140
|
1480 float *dest = (float*)destinationBuffer;
|
cannam@140
|
1481 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1482
|
cannam@140
|
1483 while( count-- )
|
cannam@140
|
1484 {
|
cannam@140
|
1485 float samp = *src * const_1_div_128_;
|
cannam@140
|
1486 *dest = samp;
|
cannam@140
|
1487
|
cannam@140
|
1488 src += sourceStride;
|
cannam@140
|
1489 dest += destinationStride;
|
cannam@140
|
1490 }
|
cannam@140
|
1491 }
|
cannam@140
|
1492
|
cannam@140
|
1493 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1494
|
cannam@140
|
1495 static void Int8_To_Int32(
|
cannam@140
|
1496 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1497 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1498 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1499 {
|
cannam@140
|
1500 signed char *src = (signed char*)sourceBuffer;
|
cannam@140
|
1501 PaInt32 *dest = (PaInt32*)destinationBuffer;
|
cannam@140
|
1502 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1503
|
cannam@140
|
1504 while( count-- )
|
cannam@140
|
1505 {
|
cannam@140
|
1506 (*dest) = (*src) << 24;
|
cannam@140
|
1507
|
cannam@140
|
1508 src += sourceStride;
|
cannam@140
|
1509 dest += destinationStride;
|
cannam@140
|
1510 }
|
cannam@140
|
1511 }
|
cannam@140
|
1512
|
cannam@140
|
1513 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1514
|
cannam@140
|
1515 static void Int8_To_Int24(
|
cannam@140
|
1516 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1517 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1518 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1519 {
|
cannam@140
|
1520 signed char *src = (signed char*)sourceBuffer;
|
cannam@140
|
1521 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1522 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1523
|
cannam@140
|
1524 while( count-- )
|
cannam@140
|
1525 {
|
cannam@140
|
1526
|
cannam@140
|
1527 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1528 dest[0] = 0;
|
cannam@140
|
1529 dest[1] = 0;
|
cannam@140
|
1530 dest[2] = (*src);
|
cannam@140
|
1531 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1532 dest[0] = (*src);
|
cannam@140
|
1533 dest[1] = 0;
|
cannam@140
|
1534 dest[2] = 0;
|
cannam@140
|
1535 #endif
|
cannam@140
|
1536
|
cannam@140
|
1537 src += sourceStride;
|
cannam@140
|
1538 dest += destinationStride * 3;
|
cannam@140
|
1539 }
|
cannam@140
|
1540 }
|
cannam@140
|
1541
|
cannam@140
|
1542 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1543
|
cannam@140
|
1544 static void Int8_To_Int16(
|
cannam@140
|
1545 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1546 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1547 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1548 {
|
cannam@140
|
1549 signed char *src = (signed char*)sourceBuffer;
|
cannam@140
|
1550 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
1551 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1552
|
cannam@140
|
1553 while( count-- )
|
cannam@140
|
1554 {
|
cannam@140
|
1555 (*dest) = (PaInt16)((*src) << 8);
|
cannam@140
|
1556
|
cannam@140
|
1557 src += sourceStride;
|
cannam@140
|
1558 dest += destinationStride;
|
cannam@140
|
1559 }
|
cannam@140
|
1560 }
|
cannam@140
|
1561
|
cannam@140
|
1562 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1563
|
cannam@140
|
1564 static void Int8_To_UInt8(
|
cannam@140
|
1565 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1566 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1567 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1568 {
|
cannam@140
|
1569 signed char *src = (signed char*)sourceBuffer;
|
cannam@140
|
1570 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1571 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1572
|
cannam@140
|
1573 while( count-- )
|
cannam@140
|
1574 {
|
cannam@140
|
1575 (*dest) = (unsigned char)(*src + 128);
|
cannam@140
|
1576
|
cannam@140
|
1577 src += sourceStride;
|
cannam@140
|
1578 dest += destinationStride;
|
cannam@140
|
1579 }
|
cannam@140
|
1580 }
|
cannam@140
|
1581
|
cannam@140
|
1582 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1583
|
cannam@140
|
1584 static void UInt8_To_Float32(
|
cannam@140
|
1585 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1586 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1587 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1588 {
|
cannam@140
|
1589 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1590 float *dest = (float*)destinationBuffer;
|
cannam@140
|
1591 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1592
|
cannam@140
|
1593 while( count-- )
|
cannam@140
|
1594 {
|
cannam@140
|
1595 float samp = (*src - 128) * const_1_div_128_;
|
cannam@140
|
1596 *dest = samp;
|
cannam@140
|
1597
|
cannam@140
|
1598 src += sourceStride;
|
cannam@140
|
1599 dest += destinationStride;
|
cannam@140
|
1600 }
|
cannam@140
|
1601 }
|
cannam@140
|
1602
|
cannam@140
|
1603 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1604
|
cannam@140
|
1605 static void UInt8_To_Int32(
|
cannam@140
|
1606 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1607 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1608 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1609 {
|
cannam@140
|
1610 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1611 PaInt32 *dest = (PaInt32*)destinationBuffer;
|
cannam@140
|
1612 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1613
|
cannam@140
|
1614 while( count-- )
|
cannam@140
|
1615 {
|
cannam@140
|
1616 (*dest) = (*src - 128) << 24;
|
cannam@140
|
1617
|
cannam@140
|
1618 src += sourceStride;
|
cannam@140
|
1619 dest += destinationStride;
|
cannam@140
|
1620 }
|
cannam@140
|
1621 }
|
cannam@140
|
1622
|
cannam@140
|
1623 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1624
|
cannam@140
|
1625 static void UInt8_To_Int24(
|
cannam@140
|
1626 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1627 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1628 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1629 {
|
cannam@140
|
1630 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1631 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1632 (void) ditherGenerator; /* unused parameters */
|
cannam@140
|
1633
|
cannam@140
|
1634 while( count-- )
|
cannam@140
|
1635 {
|
cannam@140
|
1636
|
cannam@140
|
1637 #if defined(PA_LITTLE_ENDIAN)
|
cannam@140
|
1638 dest[0] = 0;
|
cannam@140
|
1639 dest[1] = 0;
|
cannam@140
|
1640 dest[2] = (unsigned char)(*src - 128);
|
cannam@140
|
1641 #elif defined(PA_BIG_ENDIAN)
|
cannam@140
|
1642 dest[0] = (unsigned char)(*src - 128);
|
cannam@140
|
1643 dest[1] = 0;
|
cannam@140
|
1644 dest[2] = 0;
|
cannam@140
|
1645 #endif
|
cannam@140
|
1646
|
cannam@140
|
1647 src += sourceStride;
|
cannam@140
|
1648 dest += destinationStride * 3;
|
cannam@140
|
1649 }
|
cannam@140
|
1650 }
|
cannam@140
|
1651
|
cannam@140
|
1652 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1653
|
cannam@140
|
1654 static void UInt8_To_Int16(
|
cannam@140
|
1655 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1656 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1657 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1658 {
|
cannam@140
|
1659 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1660 PaInt16 *dest = (PaInt16*)destinationBuffer;
|
cannam@140
|
1661 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1662
|
cannam@140
|
1663 while( count-- )
|
cannam@140
|
1664 {
|
cannam@140
|
1665 (*dest) = (PaInt16)((*src - 128) << 8);
|
cannam@140
|
1666
|
cannam@140
|
1667 src += sourceStride;
|
cannam@140
|
1668 dest += destinationStride;
|
cannam@140
|
1669 }
|
cannam@140
|
1670 }
|
cannam@140
|
1671
|
cannam@140
|
1672 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1673
|
cannam@140
|
1674 static void UInt8_To_Int8(
|
cannam@140
|
1675 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1676 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1677 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1678 {
|
cannam@140
|
1679 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1680 signed char *dest = (signed char*)destinationBuffer;
|
cannam@140
|
1681 (void)ditherGenerator; /* unused parameter */
|
cannam@140
|
1682
|
cannam@140
|
1683 while( count-- )
|
cannam@140
|
1684 {
|
cannam@140
|
1685 (*dest) = (signed char)(*src - 128);
|
cannam@140
|
1686
|
cannam@140
|
1687 src += sourceStride;
|
cannam@140
|
1688 dest += destinationStride;
|
cannam@140
|
1689 }
|
cannam@140
|
1690 }
|
cannam@140
|
1691
|
cannam@140
|
1692 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1693
|
cannam@140
|
1694 static void Copy_8_To_8(
|
cannam@140
|
1695 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1696 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1697 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1698 {
|
cannam@140
|
1699 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1700 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1701
|
cannam@140
|
1702 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1703
|
cannam@140
|
1704 while( count-- )
|
cannam@140
|
1705 {
|
cannam@140
|
1706 *dest = *src;
|
cannam@140
|
1707
|
cannam@140
|
1708 src += sourceStride;
|
cannam@140
|
1709 dest += destinationStride;
|
cannam@140
|
1710 }
|
cannam@140
|
1711 }
|
cannam@140
|
1712
|
cannam@140
|
1713 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1714
|
cannam@140
|
1715 static void Copy_16_To_16(
|
cannam@140
|
1716 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1717 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1718 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1719 {
|
cannam@140
|
1720 PaUint16 *src = (PaUint16 *)sourceBuffer;
|
cannam@140
|
1721 PaUint16 *dest = (PaUint16 *)destinationBuffer;
|
cannam@140
|
1722
|
cannam@140
|
1723 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1724
|
cannam@140
|
1725 while( count-- )
|
cannam@140
|
1726 {
|
cannam@140
|
1727 *dest = *src;
|
cannam@140
|
1728
|
cannam@140
|
1729 src += sourceStride;
|
cannam@140
|
1730 dest += destinationStride;
|
cannam@140
|
1731 }
|
cannam@140
|
1732 }
|
cannam@140
|
1733
|
cannam@140
|
1734 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1735
|
cannam@140
|
1736 static void Copy_24_To_24(
|
cannam@140
|
1737 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1738 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1739 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1740 {
|
cannam@140
|
1741 unsigned char *src = (unsigned char*)sourceBuffer;
|
cannam@140
|
1742 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1743
|
cannam@140
|
1744 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1745
|
cannam@140
|
1746 while( count-- )
|
cannam@140
|
1747 {
|
cannam@140
|
1748 dest[0] = src[0];
|
cannam@140
|
1749 dest[1] = src[1];
|
cannam@140
|
1750 dest[2] = src[2];
|
cannam@140
|
1751
|
cannam@140
|
1752 src += sourceStride * 3;
|
cannam@140
|
1753 dest += destinationStride * 3;
|
cannam@140
|
1754 }
|
cannam@140
|
1755 }
|
cannam@140
|
1756
|
cannam@140
|
1757 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1758
|
cannam@140
|
1759 static void Copy_32_To_32(
|
cannam@140
|
1760 void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1761 void *sourceBuffer, signed int sourceStride,
|
cannam@140
|
1762 unsigned int count, struct PaUtilTriangularDitherGenerator *ditherGenerator )
|
cannam@140
|
1763 {
|
cannam@140
|
1764 PaUint32 *dest = (PaUint32 *)destinationBuffer;
|
cannam@140
|
1765 PaUint32 *src = (PaUint32 *)sourceBuffer;
|
cannam@140
|
1766
|
cannam@140
|
1767 (void) ditherGenerator; /* unused parameter */
|
cannam@140
|
1768
|
cannam@140
|
1769 while( count-- )
|
cannam@140
|
1770 {
|
cannam@140
|
1771 *dest = *src;
|
cannam@140
|
1772
|
cannam@140
|
1773 src += sourceStride;
|
cannam@140
|
1774 dest += destinationStride;
|
cannam@140
|
1775 }
|
cannam@140
|
1776 }
|
cannam@140
|
1777
|
cannam@140
|
1778 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1779
|
cannam@140
|
1780 PaUtilConverterTable paConverters = {
|
cannam@140
|
1781 Float32_To_Int32, /* PaUtilConverter *Float32_To_Int32; */
|
cannam@140
|
1782 Float32_To_Int32_Dither, /* PaUtilConverter *Float32_To_Int32_Dither; */
|
cannam@140
|
1783 Float32_To_Int32_Clip, /* PaUtilConverter *Float32_To_Int32_Clip; */
|
cannam@140
|
1784 Float32_To_Int32_DitherClip, /* PaUtilConverter *Float32_To_Int32_DitherClip; */
|
cannam@140
|
1785
|
cannam@140
|
1786 Float32_To_Int24, /* PaUtilConverter *Float32_To_Int24; */
|
cannam@140
|
1787 Float32_To_Int24_Dither, /* PaUtilConverter *Float32_To_Int24_Dither; */
|
cannam@140
|
1788 Float32_To_Int24_Clip, /* PaUtilConverter *Float32_To_Int24_Clip; */
|
cannam@140
|
1789 Float32_To_Int24_DitherClip, /* PaUtilConverter *Float32_To_Int24_DitherClip; */
|
cannam@140
|
1790
|
cannam@140
|
1791 Float32_To_Int16, /* PaUtilConverter *Float32_To_Int16; */
|
cannam@140
|
1792 Float32_To_Int16_Dither, /* PaUtilConverter *Float32_To_Int16_Dither; */
|
cannam@140
|
1793 Float32_To_Int16_Clip, /* PaUtilConverter *Float32_To_Int16_Clip; */
|
cannam@140
|
1794 Float32_To_Int16_DitherClip, /* PaUtilConverter *Float32_To_Int16_DitherClip; */
|
cannam@140
|
1795
|
cannam@140
|
1796 Float32_To_Int8, /* PaUtilConverter *Float32_To_Int8; */
|
cannam@140
|
1797 Float32_To_Int8_Dither, /* PaUtilConverter *Float32_To_Int8_Dither; */
|
cannam@140
|
1798 Float32_To_Int8_Clip, /* PaUtilConverter *Float32_To_Int8_Clip; */
|
cannam@140
|
1799 Float32_To_Int8_DitherClip, /* PaUtilConverter *Float32_To_Int8_DitherClip; */
|
cannam@140
|
1800
|
cannam@140
|
1801 Float32_To_UInt8, /* PaUtilConverter *Float32_To_UInt8; */
|
cannam@140
|
1802 Float32_To_UInt8_Dither, /* PaUtilConverter *Float32_To_UInt8_Dither; */
|
cannam@140
|
1803 Float32_To_UInt8_Clip, /* PaUtilConverter *Float32_To_UInt8_Clip; */
|
cannam@140
|
1804 Float32_To_UInt8_DitherClip, /* PaUtilConverter *Float32_To_UInt8_DitherClip; */
|
cannam@140
|
1805
|
cannam@140
|
1806 Int32_To_Float32, /* PaUtilConverter *Int32_To_Float32; */
|
cannam@140
|
1807 Int32_To_Int24, /* PaUtilConverter *Int32_To_Int24; */
|
cannam@140
|
1808 Int32_To_Int24_Dither, /* PaUtilConverter *Int32_To_Int24_Dither; */
|
cannam@140
|
1809 Int32_To_Int16, /* PaUtilConverter *Int32_To_Int16; */
|
cannam@140
|
1810 Int32_To_Int16_Dither, /* PaUtilConverter *Int32_To_Int16_Dither; */
|
cannam@140
|
1811 Int32_To_Int8, /* PaUtilConverter *Int32_To_Int8; */
|
cannam@140
|
1812 Int32_To_Int8_Dither, /* PaUtilConverter *Int32_To_Int8_Dither; */
|
cannam@140
|
1813 Int32_To_UInt8, /* PaUtilConverter *Int32_To_UInt8; */
|
cannam@140
|
1814 Int32_To_UInt8_Dither, /* PaUtilConverter *Int32_To_UInt8_Dither; */
|
cannam@140
|
1815
|
cannam@140
|
1816 Int24_To_Float32, /* PaUtilConverter *Int24_To_Float32; */
|
cannam@140
|
1817 Int24_To_Int32, /* PaUtilConverter *Int24_To_Int32; */
|
cannam@140
|
1818 Int24_To_Int16, /* PaUtilConverter *Int24_To_Int16; */
|
cannam@140
|
1819 Int24_To_Int16_Dither, /* PaUtilConverter *Int24_To_Int16_Dither; */
|
cannam@140
|
1820 Int24_To_Int8, /* PaUtilConverter *Int24_To_Int8; */
|
cannam@140
|
1821 Int24_To_Int8_Dither, /* PaUtilConverter *Int24_To_Int8_Dither; */
|
cannam@140
|
1822 Int24_To_UInt8, /* PaUtilConverter *Int24_To_UInt8; */
|
cannam@140
|
1823 Int24_To_UInt8_Dither, /* PaUtilConverter *Int24_To_UInt8_Dither; */
|
cannam@140
|
1824
|
cannam@140
|
1825 Int16_To_Float32, /* PaUtilConverter *Int16_To_Float32; */
|
cannam@140
|
1826 Int16_To_Int32, /* PaUtilConverter *Int16_To_Int32; */
|
cannam@140
|
1827 Int16_To_Int24, /* PaUtilConverter *Int16_To_Int24; */
|
cannam@140
|
1828 Int16_To_Int8, /* PaUtilConverter *Int16_To_Int8; */
|
cannam@140
|
1829 Int16_To_Int8_Dither, /* PaUtilConverter *Int16_To_Int8_Dither; */
|
cannam@140
|
1830 Int16_To_UInt8, /* PaUtilConverter *Int16_To_UInt8; */
|
cannam@140
|
1831 Int16_To_UInt8_Dither, /* PaUtilConverter *Int16_To_UInt8_Dither; */
|
cannam@140
|
1832
|
cannam@140
|
1833 Int8_To_Float32, /* PaUtilConverter *Int8_To_Float32; */
|
cannam@140
|
1834 Int8_To_Int32, /* PaUtilConverter *Int8_To_Int32; */
|
cannam@140
|
1835 Int8_To_Int24, /* PaUtilConverter *Int8_To_Int24 */
|
cannam@140
|
1836 Int8_To_Int16, /* PaUtilConverter *Int8_To_Int16; */
|
cannam@140
|
1837 Int8_To_UInt8, /* PaUtilConverter *Int8_To_UInt8; */
|
cannam@140
|
1838
|
cannam@140
|
1839 UInt8_To_Float32, /* PaUtilConverter *UInt8_To_Float32; */
|
cannam@140
|
1840 UInt8_To_Int32, /* PaUtilConverter *UInt8_To_Int32; */
|
cannam@140
|
1841 UInt8_To_Int24, /* PaUtilConverter *UInt8_To_Int24; */
|
cannam@140
|
1842 UInt8_To_Int16, /* PaUtilConverter *UInt8_To_Int16; */
|
cannam@140
|
1843 UInt8_To_Int8, /* PaUtilConverter *UInt8_To_Int8; */
|
cannam@140
|
1844
|
cannam@140
|
1845 Copy_8_To_8, /* PaUtilConverter *Copy_8_To_8; */
|
cannam@140
|
1846 Copy_16_To_16, /* PaUtilConverter *Copy_16_To_16; */
|
cannam@140
|
1847 Copy_24_To_24, /* PaUtilConverter *Copy_24_To_24; */
|
cannam@140
|
1848 Copy_32_To_32 /* PaUtilConverter *Copy_32_To_32; */
|
cannam@140
|
1849 };
|
cannam@140
|
1850
|
cannam@140
|
1851 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1852
|
cannam@140
|
1853 #endif /* PA_NO_STANDARD_CONVERTERS */
|
cannam@140
|
1854
|
cannam@140
|
1855 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1856
|
cannam@140
|
1857 PaUtilZeroer* PaUtil_SelectZeroer( PaSampleFormat destinationFormat )
|
cannam@140
|
1858 {
|
cannam@140
|
1859 switch( destinationFormat & ~paNonInterleaved ){
|
cannam@140
|
1860 case paFloat32:
|
cannam@140
|
1861 return paZeroers.Zero32;
|
cannam@140
|
1862 case paInt32:
|
cannam@140
|
1863 return paZeroers.Zero32;
|
cannam@140
|
1864 case paInt24:
|
cannam@140
|
1865 return paZeroers.Zero24;
|
cannam@140
|
1866 case paInt16:
|
cannam@140
|
1867 return paZeroers.Zero16;
|
cannam@140
|
1868 case paInt8:
|
cannam@140
|
1869 return paZeroers.Zero8;
|
cannam@140
|
1870 case paUInt8:
|
cannam@140
|
1871 return paZeroers.ZeroU8;
|
cannam@140
|
1872 default: return 0;
|
cannam@140
|
1873 }
|
cannam@140
|
1874 }
|
cannam@140
|
1875
|
cannam@140
|
1876 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1877
|
cannam@140
|
1878 #ifdef PA_NO_STANDARD_ZEROERS
|
cannam@140
|
1879
|
cannam@140
|
1880 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1881
|
cannam@140
|
1882 PaUtilZeroerTable paZeroers = {
|
cannam@140
|
1883 0, /* PaUtilZeroer *ZeroU8; */
|
cannam@140
|
1884 0, /* PaUtilZeroer *Zero8; */
|
cannam@140
|
1885 0, /* PaUtilZeroer *Zero16; */
|
cannam@140
|
1886 0, /* PaUtilZeroer *Zero24; */
|
cannam@140
|
1887 0, /* PaUtilZeroer *Zero32; */
|
cannam@140
|
1888 };
|
cannam@140
|
1889
|
cannam@140
|
1890 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1891
|
cannam@140
|
1892 #else /* PA_NO_STANDARD_ZEROERS is not defined */
|
cannam@140
|
1893
|
cannam@140
|
1894 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1895
|
cannam@140
|
1896 static void ZeroU8( void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1897 unsigned int count )
|
cannam@140
|
1898 {
|
cannam@140
|
1899 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1900
|
cannam@140
|
1901 while( count-- )
|
cannam@140
|
1902 {
|
cannam@140
|
1903 *dest = 128;
|
cannam@140
|
1904
|
cannam@140
|
1905 dest += destinationStride;
|
cannam@140
|
1906 }
|
cannam@140
|
1907 }
|
cannam@140
|
1908
|
cannam@140
|
1909 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1910
|
cannam@140
|
1911 static void Zero8( void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1912 unsigned int count )
|
cannam@140
|
1913 {
|
cannam@140
|
1914 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1915
|
cannam@140
|
1916 while( count-- )
|
cannam@140
|
1917 {
|
cannam@140
|
1918 *dest = 0;
|
cannam@140
|
1919
|
cannam@140
|
1920 dest += destinationStride;
|
cannam@140
|
1921 }
|
cannam@140
|
1922 }
|
cannam@140
|
1923
|
cannam@140
|
1924 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1925
|
cannam@140
|
1926 static void Zero16( void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1927 unsigned int count )
|
cannam@140
|
1928 {
|
cannam@140
|
1929 PaUint16 *dest = (PaUint16 *)destinationBuffer;
|
cannam@140
|
1930
|
cannam@140
|
1931 while( count-- )
|
cannam@140
|
1932 {
|
cannam@140
|
1933 *dest = 0;
|
cannam@140
|
1934
|
cannam@140
|
1935 dest += destinationStride;
|
cannam@140
|
1936 }
|
cannam@140
|
1937 }
|
cannam@140
|
1938
|
cannam@140
|
1939 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1940
|
cannam@140
|
1941 static void Zero24( void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1942 unsigned int count )
|
cannam@140
|
1943 {
|
cannam@140
|
1944 unsigned char *dest = (unsigned char*)destinationBuffer;
|
cannam@140
|
1945
|
cannam@140
|
1946 while( count-- )
|
cannam@140
|
1947 {
|
cannam@140
|
1948 dest[0] = 0;
|
cannam@140
|
1949 dest[1] = 0;
|
cannam@140
|
1950 dest[2] = 0;
|
cannam@140
|
1951
|
cannam@140
|
1952 dest += destinationStride * 3;
|
cannam@140
|
1953 }
|
cannam@140
|
1954 }
|
cannam@140
|
1955
|
cannam@140
|
1956 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1957
|
cannam@140
|
1958 static void Zero32( void *destinationBuffer, signed int destinationStride,
|
cannam@140
|
1959 unsigned int count )
|
cannam@140
|
1960 {
|
cannam@140
|
1961 PaUint32 *dest = (PaUint32 *)destinationBuffer;
|
cannam@140
|
1962
|
cannam@140
|
1963 while( count-- )
|
cannam@140
|
1964 {
|
cannam@140
|
1965 *dest = 0;
|
cannam@140
|
1966
|
cannam@140
|
1967 dest += destinationStride;
|
cannam@140
|
1968 }
|
cannam@140
|
1969 }
|
cannam@140
|
1970
|
cannam@140
|
1971 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1972
|
cannam@140
|
1973 PaUtilZeroerTable paZeroers = {
|
cannam@140
|
1974 ZeroU8, /* PaUtilZeroer *ZeroU8; */
|
cannam@140
|
1975 Zero8, /* PaUtilZeroer *Zero8; */
|
cannam@140
|
1976 Zero16, /* PaUtilZeroer *Zero16; */
|
cannam@140
|
1977 Zero24, /* PaUtilZeroer *Zero24; */
|
cannam@140
|
1978 Zero32, /* PaUtilZeroer *Zero32; */
|
cannam@140
|
1979 };
|
cannam@140
|
1980
|
cannam@140
|
1981 /* -------------------------------------------------------------------------- */
|
cannam@140
|
1982
|
cannam@140
|
1983 #endif /* PA_NO_STANDARD_ZEROERS */
|