3 { This file contains tables and miscellaneous utility routines needed
4 for both compression and decompression.
5 Note we prefix all global names with "j" to minimize conflicts with
6 a surrounding application. }
8 { Source: jutils.c; Copyright (C) 1991-1996, Thomas G. Lane. }
10 interface
12 {$I imjconfig.inc}
14 uses
15 imjmorecfg,
16 imjinclude,
17 imjpeglib;
20 { jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
21 of a DCT block read in natural order (left to right, top to bottom). }
26 const
37 {$endif}
40 { jpeg_natural_order[i] is the natural-order position of the i'th element
41 of zigzag order.
43 When reading corrupted data, the Huffman decoders could attempt
44 to reference an entry beyond the end of this array (if the decoded
45 zero run length reaches past the end of the block). To prevent
46 wild stores without adding an inner-loop test, we put some extra
47 "63"s after the real entries. This will cause the extra coefficient
48 to be stored in location 63 of the block, not somewhere random.
49 The worst case would be a run-length of 15, which means we need 16
50 fake entries. }
53 const
68 { Arithmetic utilities }
70 {GLOBAL}
73 {GLOBAL}
76 {GLOBAL}
82 {GLOBAL}
87 {GLOBAL}
94 implementation
96 {GLOBAL}
98 { Compute a/b rounded up to next integer, ie, ceil(a/b) }
99 { Assumes a >= 0, b > 0 }
100 begin
105 {GLOBAL}
107 { Compute a rounded up to next multiple of b, ie, ceil(a/b)*b }
108 { Assumes a >= 0, b > 0 }
109 begin
114 { On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
115 and coefficient-block arrays. This won't work on 80x86 because the arrays
116 are FAR and we're assuming a small-pointer memory model. However, some
117 DOS compilers provide far-pointer versions of memcpy() and memset() even
118 in the small-model libraries. These will be used if USE_FMEM is defined.
119 Otherwise, the routines below do it the hard way. (The performance cost
120 is not all that great, because these routines aren't very heavily used.) }
125 begin
130 begin
136 {$ifdef USE_FMEM}
139 {$endif}
140 {$endif}
143 {GLOBAL}
147 { Copy some rows of samples from one place to another.
148 num_rows rows are copied from input_array[source_row++]
149 to output_array[dest_row++]; these areas may overlap for duplication.
150 The source and destination arrays must be at least as wide as num_cols. }
151 var
153 {$ifdef FMEMCOPY}
155 {$else}
157 {$endif}
159 begin
160 {$ifdef FMEMCOPY}
162 {$endif}
167 begin
172 {$ifdef FMEMCOPY}
174 {$else}
176 begin
181 {$endif}
186 {GLOBAL}
190 { Copy a row of coefficient blocks from one place to another. }
191 {$ifdef FMEMCOPY}
192 begin
194 {$else}
195 var
198 begin
202 begin
207 {$endif}
211 {GLOBAL}
213 { Zero out a chunk of FAR memory. }
214 { This might be sample-array data, block-array data, or alloc_large data. }
215 {$ifdef FMEMZERO}
216 begin
218 {$else}
219 var
222 begin
225 begin
229 {$endif}