Debian Codegraph @

3rdparty/iaxclient/lib/portaudio/src/common/pa_converters.c

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