istereo2

annotate libs/libjpeg/jutils.c @ 8:661bf09db398

- replaced Quartz timer with cross-platform timer code - protected goatkit builtin theme function from being optimized out
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 24 Sep 2015 07:09:37 +0300
parents
children
rev   line source
nuclear@2 1 /*
nuclear@2 2 * jutils.c
nuclear@2 3 *
nuclear@2 4 * Copyright (C) 1991-1996, Thomas G. Lane.
nuclear@2 5 * This file is part of the Independent JPEG Group's software.
nuclear@2 6 * For conditions of distribution and use, see the accompanying README file.
nuclear@2 7 *
nuclear@2 8 * This file contains tables and miscellaneous utility routines needed
nuclear@2 9 * for both compression and decompression.
nuclear@2 10 * Note we prefix all global names with "j" to minimize conflicts with
nuclear@2 11 * a surrounding application.
nuclear@2 12 */
nuclear@2 13
nuclear@2 14 #define JPEG_INTERNALS
nuclear@2 15 #include "jinclude.h"
nuclear@2 16 #include "jpeglib.h"
nuclear@2 17
nuclear@2 18
nuclear@2 19 /*
nuclear@2 20 * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
nuclear@2 21 * of a DCT block read in natural order (left to right, top to bottom).
nuclear@2 22 */
nuclear@2 23
nuclear@2 24 #if 0 /* This table is not actually needed in v6a */
nuclear@2 25
nuclear@2 26 const int jpeg_zigzag_order[DCTSIZE2] = {
nuclear@2 27 0, 1, 5, 6, 14, 15, 27, 28,
nuclear@2 28 2, 4, 7, 13, 16, 26, 29, 42,
nuclear@2 29 3, 8, 12, 17, 25, 30, 41, 43,
nuclear@2 30 9, 11, 18, 24, 31, 40, 44, 53,
nuclear@2 31 10, 19, 23, 32, 39, 45, 52, 54,
nuclear@2 32 20, 22, 33, 38, 46, 51, 55, 60,
nuclear@2 33 21, 34, 37, 47, 50, 56, 59, 61,
nuclear@2 34 35, 36, 48, 49, 57, 58, 62, 63
nuclear@2 35 };
nuclear@2 36
nuclear@2 37 #endif
nuclear@2 38
nuclear@2 39 /*
nuclear@2 40 * jpeg_natural_order[i] is the natural-order position of the i'th element
nuclear@2 41 * of zigzag order.
nuclear@2 42 *
nuclear@2 43 * When reading corrupted data, the Huffman decoders could attempt
nuclear@2 44 * to reference an entry beyond the end of this array (if the decoded
nuclear@2 45 * zero run length reaches past the end of the block). To prevent
nuclear@2 46 * wild stores without adding an inner-loop test, we put some extra
nuclear@2 47 * "63"s after the real entries. This will cause the extra coefficient
nuclear@2 48 * to be stored in location 63 of the block, not somewhere random.
nuclear@2 49 * The worst case would be a run-length of 15, which means we need 16
nuclear@2 50 * fake entries.
nuclear@2 51 */
nuclear@2 52
nuclear@2 53 const int jpeg_natural_order[DCTSIZE2+16] = {
nuclear@2 54 0, 1, 8, 16, 9, 2, 3, 10,
nuclear@2 55 17, 24, 32, 25, 18, 11, 4, 5,
nuclear@2 56 12, 19, 26, 33, 40, 48, 41, 34,
nuclear@2 57 27, 20, 13, 6, 7, 14, 21, 28,
nuclear@2 58 35, 42, 49, 56, 57, 50, 43, 36,
nuclear@2 59 29, 22, 15, 23, 30, 37, 44, 51,
nuclear@2 60 58, 59, 52, 45, 38, 31, 39, 46,
nuclear@2 61 53, 60, 61, 54, 47, 55, 62, 63,
nuclear@2 62 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
nuclear@2 63 63, 63, 63, 63, 63, 63, 63, 63
nuclear@2 64 };
nuclear@2 65
nuclear@2 66
nuclear@2 67 /*
nuclear@2 68 * Arithmetic utilities
nuclear@2 69 */
nuclear@2 70
nuclear@2 71 GLOBAL(long)
nuclear@2 72 jdiv_round_up (long a, long b)
nuclear@2 73 /* Compute a/b rounded up to next integer, ie, ceil(a/b) */
nuclear@2 74 /* Assumes a >= 0, b > 0 */
nuclear@2 75 {
nuclear@2 76 return (a + b - 1L) / b;
nuclear@2 77 }
nuclear@2 78
nuclear@2 79
nuclear@2 80 GLOBAL(long)
nuclear@2 81 jround_up (long a, long b)
nuclear@2 82 /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
nuclear@2 83 /* Assumes a >= 0, b > 0 */
nuclear@2 84 {
nuclear@2 85 a += b - 1L;
nuclear@2 86 return a - (a % b);
nuclear@2 87 }
nuclear@2 88
nuclear@2 89
nuclear@2 90 /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
nuclear@2 91 * and coefficient-block arrays. This won't work on 80x86 because the arrays
nuclear@2 92 * are FAR and we're assuming a small-pointer memory model. However, some
nuclear@2 93 * DOS compilers provide far-pointer versions of memcpy() and memset() even
nuclear@2 94 * in the small-model libraries. These will be used if USE_FMEM is defined.
nuclear@2 95 * Otherwise, the routines below do it the hard way. (The performance cost
nuclear@2 96 * is not all that great, because these routines aren't very heavily used.)
nuclear@2 97 */
nuclear@2 98
nuclear@2 99 #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
nuclear@2 100 #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
nuclear@2 101 #define FMEMZERO(target,size) MEMZERO(target,size)
nuclear@2 102 #else /* 80x86 case, define if we can */
nuclear@2 103 #ifdef USE_FMEM
nuclear@2 104 #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
nuclear@2 105 #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
nuclear@2 106 #endif
nuclear@2 107 #endif
nuclear@2 108
nuclear@2 109
nuclear@2 110 GLOBAL(void)
nuclear@2 111 jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
nuclear@2 112 JSAMPARRAY output_array, int dest_row,
nuclear@2 113 int num_rows, JDIMENSION num_cols)
nuclear@2 114 /* Copy some rows of samples from one place to another.
nuclear@2 115 * num_rows rows are copied from input_array[source_row++]
nuclear@2 116 * to output_array[dest_row++]; these areas may overlap for duplication.
nuclear@2 117 * The source and destination arrays must be at least as wide as num_cols.
nuclear@2 118 */
nuclear@2 119 {
nuclear@2 120 register JSAMPROW inptr, outptr;
nuclear@2 121 #ifdef FMEMCOPY
nuclear@2 122 register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
nuclear@2 123 #else
nuclear@2 124 register JDIMENSION count;
nuclear@2 125 #endif
nuclear@2 126 register int row;
nuclear@2 127
nuclear@2 128 input_array += source_row;
nuclear@2 129 output_array += dest_row;
nuclear@2 130
nuclear@2 131 for (row = num_rows; row > 0; row--) {
nuclear@2 132 inptr = *input_array++;
nuclear@2 133 outptr = *output_array++;
nuclear@2 134 #ifdef FMEMCOPY
nuclear@2 135 FMEMCOPY(outptr, inptr, count);
nuclear@2 136 #else
nuclear@2 137 for (count = num_cols; count > 0; count--)
nuclear@2 138 *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
nuclear@2 139 #endif
nuclear@2 140 }
nuclear@2 141 }
nuclear@2 142
nuclear@2 143
nuclear@2 144 GLOBAL(void)
nuclear@2 145 jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
nuclear@2 146 JDIMENSION num_blocks)
nuclear@2 147 /* Copy a row of coefficient blocks from one place to another. */
nuclear@2 148 {
nuclear@2 149 #ifdef FMEMCOPY
nuclear@2 150 FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
nuclear@2 151 #else
nuclear@2 152 register JCOEFPTR inptr, outptr;
nuclear@2 153 register long count;
nuclear@2 154
nuclear@2 155 inptr = (JCOEFPTR) input_row;
nuclear@2 156 outptr = (JCOEFPTR) output_row;
nuclear@2 157 for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
nuclear@2 158 *outptr++ = *inptr++;
nuclear@2 159 }
nuclear@2 160 #endif
nuclear@2 161 }
nuclear@2 162
nuclear@2 163
nuclear@2 164 GLOBAL(void)
nuclear@2 165 jzero_far (void FAR * target, size_t bytestozero)
nuclear@2 166 /* Zero out a chunk of FAR memory. */
nuclear@2 167 /* This might be sample-array data, block-array data, or alloc_large data. */
nuclear@2 168 {
nuclear@2 169 #ifdef FMEMZERO
nuclear@2 170 FMEMZERO(target, bytestozero);
nuclear@2 171 #else
nuclear@2 172 register char FAR * ptr = (char FAR *) target;
nuclear@2 173 register size_t count;
nuclear@2 174
nuclear@2 175 for (count = bytestozero; count > 0; count--) {
nuclear@2 176 *ptr++ = 0;
nuclear@2 177 }
nuclear@2 178 #endif
nuclear@2 179 }