1991-10-06 20:00:00 -04:00
|
|
|
/*
|
|
|
|
* jutils.c
|
|
|
|
*
|
1992-03-16 19:00:00 -05:00
|
|
|
* Copyright (C) 1991, 1992, Thomas G. Lane.
|
1991-10-06 20:00:00 -04:00
|
|
|
* This file is part of the Independent JPEG Group's software.
|
|
|
|
* For conditions of distribution and use, see the accompanying README file.
|
|
|
|
*
|
|
|
|
* This file contains miscellaneous utility routines needed for both
|
|
|
|
* compression and decompression.
|
|
|
|
* Note we prefix all global names with "j" to minimize conflicts with
|
|
|
|
* a surrounding application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "jinclude.h"
|
|
|
|
|
|
|
|
|
|
|
|
GLOBAL long
|
|
|
|
jround_up (long a, long b)
|
|
|
|
/* Compute a rounded up to next multiple of b; a >= 0, b > 0 */
|
|
|
|
{
|
|
|
|
a += b-1;
|
|
|
|
return a - (a % b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1992-12-09 19:00:00 -05:00
|
|
|
/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
|
|
|
|
* and coefficient-block arrays. This won't work on 80x86 because the arrays
|
|
|
|
* are FAR and we're assuming a small-pointer memory model. However, some
|
|
|
|
* DOS compilers provide far-pointer versions of memcpy() and memset() even
|
|
|
|
* in the small-model libraries. These will be used if USE_FMEM is defined.
|
|
|
|
* Otherwise, the routines below do it the hard way. (The performance cost
|
|
|
|
* is not all that great, because these routines aren't very heavily used.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
|
|
|
|
#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
|
|
|
|
#define FMEMZERO(target,size) MEMZERO(target,size)
|
|
|
|
#else /* 80x86 case, define if we can */
|
|
|
|
#ifdef USE_FMEM
|
|
|
|
#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
|
|
|
|
#define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1991-10-06 20:00:00 -04:00
|
|
|
GLOBAL void
|
|
|
|
jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
|
|
|
|
JSAMPARRAY output_array, int dest_row,
|
|
|
|
int num_rows, long num_cols)
|
|
|
|
/* Copy some rows of samples from one place to another.
|
|
|
|
* num_rows rows are copied from input_array[source_row++]
|
|
|
|
* to output_array[dest_row++]; these areas should not overlap.
|
|
|
|
* The source and destination arrays must be at least as wide as num_cols.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
register JSAMPROW inptr, outptr;
|
1992-12-09 19:00:00 -05:00
|
|
|
#ifdef FMEMCOPY
|
1992-03-16 19:00:00 -05:00
|
|
|
register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
|
1992-12-09 19:00:00 -05:00
|
|
|
#else
|
|
|
|
register long count;
|
1991-10-06 20:00:00 -04:00
|
|
|
#endif
|
|
|
|
register int row;
|
|
|
|
|
|
|
|
input_array += source_row;
|
|
|
|
output_array += dest_row;
|
|
|
|
|
|
|
|
for (row = num_rows; row > 0; row--) {
|
|
|
|
inptr = *input_array++;
|
|
|
|
outptr = *output_array++;
|
1992-12-09 19:00:00 -05:00
|
|
|
#ifdef FMEMCOPY
|
|
|
|
FMEMCOPY(outptr, inptr, count);
|
|
|
|
#else
|
1991-10-06 20:00:00 -04:00
|
|
|
for (count = num_cols; count > 0; count--)
|
|
|
|
*outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GLOBAL void
|
|
|
|
jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, long num_blocks)
|
|
|
|
/* Copy a row of coefficient blocks from one place to another. */
|
|
|
|
{
|
1992-12-09 19:00:00 -05:00
|
|
|
#ifdef FMEMCOPY
|
|
|
|
FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
|
|
|
|
#else
|
1991-10-06 20:00:00 -04:00
|
|
|
register JCOEFPTR inptr, outptr;
|
|
|
|
register long count;
|
|
|
|
|
1992-03-16 19:00:00 -05:00
|
|
|
inptr = (JCOEFPTR) input_row;
|
|
|
|
outptr = (JCOEFPTR) output_row;
|
|
|
|
for (count = num_blocks * DCTSIZE2; count > 0; count--) {
|
|
|
|
*outptr++ = *inptr++;
|
1991-10-06 20:00:00 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GLOBAL void
|
|
|
|
jzero_far (void FAR * target, size_t bytestozero)
|
|
|
|
/* Zero out a chunk of FAR memory. */
|
|
|
|
/* This might be sample-array data, block-array data, or alloc_medium data. */
|
|
|
|
{
|
1992-12-09 19:00:00 -05:00
|
|
|
#ifdef FMEMZERO
|
|
|
|
FMEMZERO(target, bytestozero);
|
|
|
|
#else
|
1991-10-06 20:00:00 -04:00
|
|
|
register char FAR * ptr = (char FAR *) target;
|
|
|
|
register size_t count;
|
|
|
|
|
|
|
|
for (count = bytestozero; count > 0; count--) {
|
|
|
|
*ptr++ = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|