Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenjutils.c
Go to the documentation of this file.
00001 /* 00002 * jutils.c 00003 * 00004 * Copyright (C) 1991-1996, Thomas G. Lane. 00005 * Modified 2009 by Guido Vollbeding. 00006 * This file is part of the Independent JPEG Group's software. 00007 * For conditions of distribution and use, see the accompanying README file. 00008 * 00009 * This file contains tables and miscellaneous utility routines needed 00010 * for both compression and decompression. 00011 * Note we prefix all global names with "j" to minimize conflicts with 00012 * a surrounding application. 00013 */ 00014 00015 #define JPEG_INTERNALS 00016 #include "jinclude.h" 00017 #include "jpeglib.h" 00018 00019 00020 /* 00021 * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element 00022 * of a DCT block read in natural order (left to right, top to bottom). 00023 */ 00024 00025 #if 0 /* This table is not actually needed in v6a */ 00026 00027 const int jpeg_zigzag_order[DCTSIZE2] = { 00028 0, 1, 5, 6, 14, 15, 27, 28, 00029 2, 4, 7, 13, 16, 26, 29, 42, 00030 3, 8, 12, 17, 25, 30, 41, 43, 00031 9, 11, 18, 24, 31, 40, 44, 53, 00032 10, 19, 23, 32, 39, 45, 52, 54, 00033 20, 22, 33, 38, 46, 51, 55, 60, 00034 21, 34, 37, 47, 50, 56, 59, 61, 00035 35, 36, 48, 49, 57, 58, 62, 63 00036 }; 00037 00038 #endif 00039 00040 /* 00041 * jpeg_natural_order[i] is the natural-order position of the i'th element 00042 * of zigzag order. 00043 * 00044 * When reading corrupted data, the Huffman decoders could attempt 00045 * to reference an entry beyond the end of this array (if the decoded 00046 * zero run length reaches past the end of the block). To prevent 00047 * wild stores without adding an inner-loop test, we put some extra 00048 * "63"s after the real entries. This will cause the extra coefficient 00049 * to be stored in location 63 of the block, not somewhere random. 00050 * The worst case would be a run-length of 15, which means we need 16 00051 * fake entries. 00052 */ 00053 00054 const int jpeg_natural_order[DCTSIZE2+16] = { 00055 0, 1, 8, 16, 9, 2, 3, 10, 00056 17, 24, 32, 25, 18, 11, 4, 5, 00057 12, 19, 26, 33, 40, 48, 41, 34, 00058 27, 20, 13, 6, 7, 14, 21, 28, 00059 35, 42, 49, 56, 57, 50, 43, 36, 00060 29, 22, 15, 23, 30, 37, 44, 51, 00061 58, 59, 52, 45, 38, 31, 39, 46, 00062 53, 60, 61, 54, 47, 55, 62, 63, 00063 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 00064 63, 63, 63, 63, 63, 63, 63, 63 00065 }; 00066 00067 const int jpeg_natural_order7[7*7+16] = { 00068 0, 1, 8, 16, 9, 2, 3, 10, 00069 17, 24, 32, 25, 18, 11, 4, 5, 00070 12, 19, 26, 33, 40, 48, 41, 34, 00071 27, 20, 13, 6, 14, 21, 28, 35, 00072 42, 49, 50, 43, 36, 29, 22, 30, 00073 37, 44, 51, 52, 45, 38, 46, 53, 00074 54, 00075 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 00076 63, 63, 63, 63, 63, 63, 63, 63 00077 }; 00078 00079 const int jpeg_natural_order6[6*6+16] = { 00080 0, 1, 8, 16, 9, 2, 3, 10, 00081 17, 24, 32, 25, 18, 11, 4, 5, 00082 12, 19, 26, 33, 40, 41, 34, 27, 00083 20, 13, 21, 28, 35, 42, 43, 36, 00084 29, 37, 44, 45, 00085 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 00086 63, 63, 63, 63, 63, 63, 63, 63 00087 }; 00088 00089 const int jpeg_natural_order5[5*5+16] = { 00090 0, 1, 8, 16, 9, 2, 3, 10, 00091 17, 24, 32, 25, 18, 11, 4, 12, 00092 19, 26, 33, 34, 27, 20, 28, 35, 00093 36, 00094 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 00095 63, 63, 63, 63, 63, 63, 63, 63 00096 }; 00097 00098 const int jpeg_natural_order4[4*4+16] = { 00099 0, 1, 8, 16, 9, 2, 3, 10, 00100 17, 24, 25, 18, 11, 19, 26, 27, 00101 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 00102 63, 63, 63, 63, 63, 63, 63, 63 00103 }; 00104 00105 const int jpeg_natural_order3[3*3+16] = { 00106 0, 1, 8, 16, 9, 2, 10, 17, 00107 18, 00108 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 00109 63, 63, 63, 63, 63, 63, 63, 63 00110 }; 00111 00112 const int jpeg_natural_order2[2*2+16] = { 00113 0, 1, 8, 9, 00114 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 00115 63, 63, 63, 63, 63, 63, 63, 63 00116 }; 00117 00118 00119 /* 00120 * Arithmetic utilities 00121 */ 00122 00123 GLOBAL(long) 00124 jdiv_round_up (long a, long b) 00125 /* Compute a/b rounded up to next integer, ie, ceil(a/b) */ 00126 /* Assumes a >= 0, b > 0 */ 00127 { 00128 return (a + b - 1L) / b; 00129 } 00130 00131 00132 GLOBAL(long) 00133 jround_up (long a, long b) 00134 /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ 00135 /* Assumes a >= 0, b > 0 */ 00136 { 00137 a += b - 1L; 00138 return a - (a % b); 00139 } 00140 00141 00142 /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays 00143 * and coefficient-block arrays. This won't work on 80x86 because the arrays 00144 * are FAR and we're assuming a small-pointer memory model. However, some 00145 * DOS compilers provide far-pointer versions of memcpy() and memset() even 00146 * in the small-model libraries. These will be used if USE_FMEM is defined. 00147 * Otherwise, the routines below do it the hard way. (The performance cost 00148 * is not all that great, because these routines aren't very heavily used.) 00149 */ 00150 00151 #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ 00152 #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) 00153 #define FMEMZERO(target,size) MEMZERO(target,size) 00154 #else /* 80x86 case, define if we can */ 00155 #ifdef USE_FMEM 00156 #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) 00157 #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) 00158 #endif 00159 #endif 00160 00161 00162 GLOBAL(void) 00163 jcopy_sample_rows (JSAMPARRAY input_array, int source_row, 00164 JSAMPARRAY output_array, int dest_row, 00165 int num_rows, JDIMENSION num_cols) 00166 /* Copy some rows of samples from one place to another. 00167 * num_rows rows are copied from input_array[source_row++] 00168 * to output_array[dest_row++]; these areas may overlap for duplication. 00169 * The source and destination arrays must be at least as wide as num_cols. 00170 */ 00171 { 00172 register JSAMPROW inptr, outptr; 00173 #ifdef FMEMCOPY 00174 register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE)); 00175 #else 00176 register JDIMENSION count; 00177 #endif 00178 register int row; 00179 00180 input_array += source_row; 00181 output_array += dest_row; 00182 00183 for (row = num_rows; row > 0; row--) { 00184 inptr = *input_array++; 00185 outptr = *output_array++; 00186 #ifdef FMEMCOPY 00187 FMEMCOPY(outptr, inptr, count); 00188 #else 00189 for (count = num_cols; count > 0; count--) 00190 *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */ 00191 #endif 00192 } 00193 } 00194 00195 00196 GLOBAL(void) 00197 jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, 00198 JDIMENSION num_blocks) 00199 /* Copy a row of coefficient blocks from one place to another. */ 00200 { 00201 #ifdef FMEMCOPY 00202 FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))); 00203 #else 00204 register JCOEFPTR inptr, outptr; 00205 register long count; 00206 00207 inptr = (JCOEFPTR) input_row; 00208 outptr = (JCOEFPTR) output_row; 00209 for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) { 00210 *outptr++ = *inptr++; 00211 } 00212 #endif 00213 } 00214 00215 00216 GLOBAL(void) 00217 jzero_far (void FAR * target, size_t bytestozero) 00218 /* Zero out a chunk of FAR memory. */ 00219 /* This might be sample-array data, block-array data, or alloc_large data. */ 00220 { 00221 #ifdef FMEMZERO 00222 FMEMZERO(target, bytestozero); 00223 #else 00224 register char FAR * ptr = (char FAR *) target; 00225 register size_t count; 00226 00227 for (count = bytestozero; count > 0; count--) { 00228 *ptr++ = 0; 00229 } 00230 #endif 00231 } Generated on Sat May 26 2012 04:18:14 for ReactOS by
1.7.6.1
|