source: golgotha/src/i4/loaders/jpg/jutils.cc @ 80

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