/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/portaudio/src/common/pa_converters.c
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/portaudio/src/common/pa_converters.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22