Shoaib Ahmed / Mbed 2 deprecated uzairkhan

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers jutils.c Source File

jutils.c

00001 /*
00002  * jutils.c
00003  *
00004  * Copyright (C) 1991-1996, Thomas G. Lane.
00005  * Modified 2009-2011 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 macro */
00152 #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
00153 #else               /* 80x86 case, define if we can */
00154 #ifdef USE_FMEM
00155 #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
00156 #else
00157 /* This function is for use by the FMEMZERO macro defined in jpegint.h.
00158  * Do not call this function directly, use the FMEMZERO macro instead.
00159  */
00160 GLOBAL(void)
00161 jzero_far (void FAR * target, size_t bytestozero)
00162 /* Zero out a chunk of FAR memory. */
00163 /* This might be sample-array data, block-array data, or alloc_large data. */
00164 {
00165   register char FAR * ptr = (char FAR *) target;
00166   register size_t count;
00167 
00168   for (count = bytestozero; count > 0; count--) {
00169     *ptr++ = 0;
00170   }
00171 }
00172 #endif
00173 #endif
00174 
00175 
00176 GLOBAL(void)
00177 jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
00178            JSAMPARRAY output_array, int dest_row,
00179            int num_rows, JDIMENSION num_cols)
00180 /* Copy some rows of samples from one place to another.
00181  * num_rows rows are copied from input_array[source_row++]
00182  * to output_array[dest_row++]; these areas may overlap for duplication.
00183  * The source and destination arrays must be at least as wide as num_cols.
00184  */
00185 {
00186   register JSAMPROW inptr, outptr;
00187 #ifdef FMEMCOPY
00188   register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
00189 #else
00190   register JDIMENSION count;
00191 #endif
00192   register int row;
00193 
00194   input_array += source_row;
00195   output_array += dest_row;
00196 
00197   for (row = num_rows; row > 0; row--) {
00198     inptr = *input_array++;
00199     outptr = *output_array++;
00200 #ifdef FMEMCOPY
00201     FMEMCOPY(outptr, inptr, count);
00202 #else
00203     for (count = num_cols; count > 0; count--)
00204       *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
00205 #endif
00206   }
00207 }
00208 
00209 
00210 GLOBAL(void)
00211 jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
00212          JDIMENSION num_blocks)
00213 /* Copy a row of coefficient blocks from one place to another. */
00214 {
00215 #ifdef FMEMCOPY
00216   FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
00217 #else
00218   register JCOEFPTR inptr, outptr;
00219   register long count;
00220 
00221   inptr = (JCOEFPTR) input_row;
00222   outptr = (JCOEFPTR) output_row;
00223   for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
00224     *outptr++ = *inptr++;
00225   }
00226 #endif
00227 }