istereo
diff libs/libjpeg/jutils.c @ 26:862a3329a8f0
wohooo, added a shitload of code from zlib/libpng/libjpeg. When the good lord was raining shared libraries the iphone held a fucking umbrella...
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Thu, 08 Sep 2011 06:28:38 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/libjpeg/jutils.c Thu Sep 08 06:28:38 2011 +0300 1.3 @@ -0,0 +1,179 @@ 1.4 +/* 1.5 + * jutils.c 1.6 + * 1.7 + * Copyright (C) 1991-1996, Thomas G. Lane. 1.8 + * This file is part of the Independent JPEG Group's software. 1.9 + * For conditions of distribution and use, see the accompanying README file. 1.10 + * 1.11 + * This file contains tables and miscellaneous utility routines needed 1.12 + * for both compression and decompression. 1.13 + * Note we prefix all global names with "j" to minimize conflicts with 1.14 + * a surrounding application. 1.15 + */ 1.16 + 1.17 +#define JPEG_INTERNALS 1.18 +#include "jinclude.h" 1.19 +#include "jpeglib.h" 1.20 + 1.21 + 1.22 +/* 1.23 + * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element 1.24 + * of a DCT block read in natural order (left to right, top to bottom). 1.25 + */ 1.26 + 1.27 +#if 0 /* This table is not actually needed in v6a */ 1.28 + 1.29 +const int jpeg_zigzag_order[DCTSIZE2] = { 1.30 + 0, 1, 5, 6, 14, 15, 27, 28, 1.31 + 2, 4, 7, 13, 16, 26, 29, 42, 1.32 + 3, 8, 12, 17, 25, 30, 41, 43, 1.33 + 9, 11, 18, 24, 31, 40, 44, 53, 1.34 + 10, 19, 23, 32, 39, 45, 52, 54, 1.35 + 20, 22, 33, 38, 46, 51, 55, 60, 1.36 + 21, 34, 37, 47, 50, 56, 59, 61, 1.37 + 35, 36, 48, 49, 57, 58, 62, 63 1.38 +}; 1.39 + 1.40 +#endif 1.41 + 1.42 +/* 1.43 + * jpeg_natural_order[i] is the natural-order position of the i'th element 1.44 + * of zigzag order. 1.45 + * 1.46 + * When reading corrupted data, the Huffman decoders could attempt 1.47 + * to reference an entry beyond the end of this array (if the decoded 1.48 + * zero run length reaches past the end of the block). To prevent 1.49 + * wild stores without adding an inner-loop test, we put some extra 1.50 + * "63"s after the real entries. This will cause the extra coefficient 1.51 + * to be stored in location 63 of the block, not somewhere random. 1.52 + * The worst case would be a run-length of 15, which means we need 16 1.53 + * fake entries. 1.54 + */ 1.55 + 1.56 +const int jpeg_natural_order[DCTSIZE2+16] = { 1.57 + 0, 1, 8, 16, 9, 2, 3, 10, 1.58 + 17, 24, 32, 25, 18, 11, 4, 5, 1.59 + 12, 19, 26, 33, 40, 48, 41, 34, 1.60 + 27, 20, 13, 6, 7, 14, 21, 28, 1.61 + 35, 42, 49, 56, 57, 50, 43, 36, 1.62 + 29, 22, 15, 23, 30, 37, 44, 51, 1.63 + 58, 59, 52, 45, 38, 31, 39, 46, 1.64 + 53, 60, 61, 54, 47, 55, 62, 63, 1.65 + 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 1.66 + 63, 63, 63, 63, 63, 63, 63, 63 1.67 +}; 1.68 + 1.69 + 1.70 +/* 1.71 + * Arithmetic utilities 1.72 + */ 1.73 + 1.74 +GLOBAL(long) 1.75 +jdiv_round_up (long a, long b) 1.76 +/* Compute a/b rounded up to next integer, ie, ceil(a/b) */ 1.77 +/* Assumes a >= 0, b > 0 */ 1.78 +{ 1.79 + return (a + b - 1L) / b; 1.80 +} 1.81 + 1.82 + 1.83 +GLOBAL(long) 1.84 +jround_up (long a, long b) 1.85 +/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ 1.86 +/* Assumes a >= 0, b > 0 */ 1.87 +{ 1.88 + a += b - 1L; 1.89 + return a - (a % b); 1.90 +} 1.91 + 1.92 + 1.93 +/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays 1.94 + * and coefficient-block arrays. This won't work on 80x86 because the arrays 1.95 + * are FAR and we're assuming a small-pointer memory model. However, some 1.96 + * DOS compilers provide far-pointer versions of memcpy() and memset() even 1.97 + * in the small-model libraries. These will be used if USE_FMEM is defined. 1.98 + * Otherwise, the routines below do it the hard way. (The performance cost 1.99 + * is not all that great, because these routines aren't very heavily used.) 1.100 + */ 1.101 + 1.102 +#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ 1.103 +#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) 1.104 +#define FMEMZERO(target,size) MEMZERO(target,size) 1.105 +#else /* 80x86 case, define if we can */ 1.106 +#ifdef USE_FMEM 1.107 +#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) 1.108 +#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) 1.109 +#endif 1.110 +#endif 1.111 + 1.112 + 1.113 +GLOBAL(void) 1.114 +jcopy_sample_rows (JSAMPARRAY input_array, int source_row, 1.115 + JSAMPARRAY output_array, int dest_row, 1.116 + int num_rows, JDIMENSION num_cols) 1.117 +/* Copy some rows of samples from one place to another. 1.118 + * num_rows rows are copied from input_array[source_row++] 1.119 + * to output_array[dest_row++]; these areas may overlap for duplication. 1.120 + * The source and destination arrays must be at least as wide as num_cols. 1.121 + */ 1.122 +{ 1.123 + register JSAMPROW inptr, outptr; 1.124 +#ifdef FMEMCOPY 1.125 + register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE)); 1.126 +#else 1.127 + register JDIMENSION count; 1.128 +#endif 1.129 + register int row; 1.130 + 1.131 + input_array += source_row; 1.132 + output_array += dest_row; 1.133 + 1.134 + for (row = num_rows; row > 0; row--) { 1.135 + inptr = *input_array++; 1.136 + outptr = *output_array++; 1.137 +#ifdef FMEMCOPY 1.138 + FMEMCOPY(outptr, inptr, count); 1.139 +#else 1.140 + for (count = num_cols; count > 0; count--) 1.141 + *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */ 1.142 +#endif 1.143 + } 1.144 +} 1.145 + 1.146 + 1.147 +GLOBAL(void) 1.148 +jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, 1.149 + JDIMENSION num_blocks) 1.150 +/* Copy a row of coefficient blocks from one place to another. */ 1.151 +{ 1.152 +#ifdef FMEMCOPY 1.153 + FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))); 1.154 +#else 1.155 + register JCOEFPTR inptr, outptr; 1.156 + register long count; 1.157 + 1.158 + inptr = (JCOEFPTR) input_row; 1.159 + outptr = (JCOEFPTR) output_row; 1.160 + for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) { 1.161 + *outptr++ = *inptr++; 1.162 + } 1.163 +#endif 1.164 +} 1.165 + 1.166 + 1.167 +GLOBAL(void) 1.168 +jzero_far (void FAR * target, size_t bytestozero) 1.169 +/* Zero out a chunk of FAR memory. */ 1.170 +/* This might be sample-array data, block-array data, or alloc_large data. */ 1.171 +{ 1.172 +#ifdef FMEMZERO 1.173 + FMEMZERO(target, bytestozero); 1.174 +#else 1.175 + register char FAR * ptr = (char FAR *) target; 1.176 + register size_t count; 1.177 + 1.178 + for (count = bytestozero; count > 0; count--) { 1.179 + *ptr++ = 0; 1.180 + } 1.181 +#endif 1.182 +}