home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR2 / DVPG30FS.ZIP / JUTILS.C < prev    next >
C/C++ Source or Header  |  1993-02-19  |  3KB  |  115 lines

  1. /*
  2.  * jutils.c
  3.  *
  4.  * Copyright (C) 1991, 1992, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains miscellaneous utility routines needed for both
  9.  * compression and decompression.
  10.  * Note we prefix all global names with "j" to minimize conflicts with
  11.  * a surrounding application.
  12.  */
  13.  
  14. #include "jinclude.h"
  15.  
  16.  
  17. GLOBAL long
  18. jround_up (long a, long b)
  19. /* Compute a rounded up to next multiple of b; a >= 0, b > 0 */
  20. {
  21.   a += b-1;
  22.   return a - (a % b);
  23. }
  24.  
  25.  
  26. /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
  27.  * and coefficient-block arrays.  This won't work on 80x86 because the arrays
  28.  * are FAR and we're assuming a small-pointer memory model.  However, some
  29.  * DOS compilers provide far-pointer versions of memcpy() and memset() even
  30.  * in the small-model libraries.  These will be used if USE_FMEM is defined.
  31.  * Otherwise, the routines below do it the hard way.  (The performance cost
  32.  * is not all that great, because these routines aren't very heavily used.)
  33.  */
  34.  
  35. #ifndef NEED_FAR_POINTERS    /* normal case, same as regular macros */
  36. #define FMEMCOPY(dest,src,size)    MEMCOPY(dest,src,size)
  37. #define FMEMZERO(target,size)    MEMZERO(target,size)
  38. #else                /* 80x86 case, define if we can */
  39. #ifdef USE_FMEM
  40. #define FMEMCOPY(dest,src,size)    _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  41. #define FMEMZERO(target,size)    _fmemset((void FAR *)(target), 0, (size_t)(size))
  42. #endif
  43. #endif
  44.  
  45.  
  46. GLOBAL void
  47. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  48.            JSAMPARRAY output_array, int dest_row,
  49.            int num_rows, long num_cols)
  50. /* Copy some rows of samples from one place to another.
  51.  * num_rows rows are copied from input_array[source_row++]
  52.  * to output_array[dest_row++]; these areas should not overlap.
  53.  * The source and destination arrays must be at least as wide as num_cols.
  54.  */
  55. {
  56.   register JSAMPROW inptr, outptr;
  57. #ifdef FMEMCOPY
  58.   register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  59. #else
  60.   register long count;
  61. #endif
  62.   register int row;
  63.  
  64.   input_array += source_row;
  65.   output_array += dest_row;
  66.  
  67.   for (row = num_rows; row > 0; row--) {
  68.     inptr = *input_array++;
  69.     outptr = *output_array++;
  70. #ifdef FMEMCOPY
  71.     FMEMCOPY(outptr, inptr, count);
  72. #else
  73.     for (count = num_cols; count > 0; count--)
  74.       *outptr++ = *inptr++;    /* needn't bother with GETJSAMPLE() here */
  75. #endif
  76.   }
  77. }
  78.  
  79.  
  80. GLOBAL void
  81. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, long num_blocks)
  82. /* Copy a row of coefficient blocks from one place to another. */
  83. {
  84. #ifdef FMEMCOPY
  85.   FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  86. #else
  87.   register JCOEFPTR inptr, outptr;
  88.   register long count;
  89.  
  90.   inptr = (JCOEFPTR) input_row;
  91.   outptr = (JCOEFPTR) output_row;
  92.   for (count = num_blocks * DCTSIZE2; count > 0; count--) {
  93.     *outptr++ = *inptr++;
  94.   }
  95. #endif
  96. }
  97.  
  98.  
  99. GLOBAL void
  100. jzero_far (void FAR * target, size_t bytestozero)
  101. /* Zero out a chunk of FAR memory. */
  102. /* This might be sample-array data, block-array data, or alloc_medium data. */
  103. {
  104. #ifdef FMEMZERO
  105.   FMEMZERO(target, bytestozero);
  106. #else
  107.   register char FAR * ptr = (char FAR *) target;
  108.   register size_t count;
  109.  
  110.   for (count = bytestozero; count > 0; count--) {
  111.     *ptr++ = 0;
  112.   }
  113. #endif
  114. }
  115.