home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / compresn / jpegv3sr / jutils.c < prev    next >
C/C++ Source or Header  |  1992-02-29  |  3KB  |  105 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. GLOBAL void
  27. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  28.            JSAMPARRAY output_array, int dest_row,
  29.            int num_rows, long num_cols)
  30. /* Copy some rows of samples from one place to another.
  31.  * num_rows rows are copied from input_array[source_row++]
  32.  * to output_array[dest_row++]; these areas should not overlap.
  33.  * The source and destination arrays must be at least as wide as num_cols.
  34.  */
  35. {
  36.   /* On normal machines we can use memcpy().  This won't work on 80x86 because
  37.    * the sample arrays are FAR and we're assuming a small-pointer memory model.
  38.    */
  39.   register JSAMPROW inptr, outptr;
  40. #ifdef NEED_FAR_POINTERS
  41.   register long count;
  42. #else
  43.   register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  44. #endif
  45.   register int row;
  46.  
  47.   input_array += source_row;
  48.   output_array += dest_row;
  49.  
  50.   for (row = num_rows; row > 0; row--) {
  51.     inptr = *input_array++;
  52.     outptr = *output_array++;
  53. #ifdef NEED_FAR_POINTERS
  54.     for (count = num_cols; count > 0; count--)
  55.       *outptr++ = *inptr++;    /* needn't bother with GETJSAMPLE() here */
  56. #else
  57.     memcpy((void *) outptr, (void *) inptr, count);
  58. #endif
  59.   }
  60. }
  61.  
  62.  
  63. GLOBAL void
  64. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, long num_blocks)
  65. /* Copy a row of coefficient blocks from one place to another. */
  66. {
  67.   /* On normal machines we can use memcpy().  This won't work on 80x86 because
  68.    * the block arrays are FAR and we're assuming a small-pointer memory model.
  69.    */
  70. #ifdef NEED_FAR_POINTERS
  71.   register JCOEFPTR inptr, outptr;
  72.   register long count;
  73.  
  74.   inptr = (JCOEFPTR) input_row;
  75.   outptr = (JCOEFPTR) output_row;
  76.   for (count = num_blocks * DCTSIZE2; count > 0; count--) {
  77.     *outptr++ = *inptr++;
  78.   }
  79. #else
  80.     memcpy((void *) output_row, (void *) input_row,
  81.        (size_t) (num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))));
  82. #endif
  83. }
  84.  
  85.  
  86. GLOBAL void
  87. jzero_far (void FAR * target, size_t bytestozero)
  88. /* Zero out a chunk of FAR memory. */
  89. /* This might be sample-array data, block-array data, or alloc_medium data. */
  90. {
  91.   /* On normal machines we can use MEMZERO().  This won't work on 80x86
  92.    * because we're assuming a small-pointer memory model.
  93.    */
  94. #ifdef NEED_FAR_POINTERS
  95.   register char FAR * ptr = (char FAR *) target;
  96.   register size_t count;
  97.  
  98.   for (count = bytestozero; count > 0; count--) {
  99.     *ptr++ = 0;
  100.   }
  101. #else
  102.   MEMZERO((void *) target, bytestozero);
  103. #endif
  104. }
  105.