home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GRAPHICS / jpeglib_5a.lzh / JPEG_5A / jutils.c < prev    next >
Text File  |  1995-01-14  |  4KB  |  132 lines

  1. /*
  2.  * jutils.c
  3.  *
  4.  * Copyright (C) 1991-1994, 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. #define JPEG_INTERNALS
  15. #include "jinclude.h"
  16. #include "jpeglib.h"
  17.  
  18.  
  19. /*
  20.  * Arithmetic utilities
  21.  */
  22.  
  23. GLOBAL long
  24. jdiv_round_up (long a, long b)
  25. /* Compute a/b rounded up to next integer, ie, ceil(a/b) */
  26. /* Assumes a >= 0, b > 0 */
  27. {
  28.   return (a + b - 1L) / b;
  29. }
  30.  
  31.  
  32. GLOBAL long
  33. jround_up (long a, long b)
  34. /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
  35. /* Assumes a >= 0, b > 0 */
  36. {
  37.   a += b - 1L;
  38.   return a - (a % b);
  39. }
  40.  
  41.  
  42. /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
  43.  * and coefficient-block arrays.  This won't work on 80x86 because the arrays
  44.  * are FAR and we're assuming a small-pointer memory model.  However, some
  45.  * DOS compilers provide far-pointer versions of memcpy() and memset() even
  46.  * in the small-model libraries.  These will be used if USE_FMEM is defined.
  47.  * Otherwise, the routines below do it the hard way.  (The performance cost
  48.  * is not all that great, because these routines aren't very heavily used.)
  49.  */
  50.  
  51. #ifndef NEED_FAR_POINTERS    /* normal case, same as regular macros */
  52. #define FMEMCOPY(dest,src,size)    MEMCOPY(dest,src,size)
  53. #define FMEMZERO(target,size)    MEMZERO(target,size)
  54. #else                /* 80x86 case, define if we can */
  55. #ifdef USE_FMEM
  56. #define FMEMCOPY(dest,src,size)    _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  57. #define FMEMZERO(target,size)    _fmemset((void FAR *)(target), 0, (size_t)(size))
  58. #endif
  59. #endif
  60.  
  61.  
  62. GLOBAL void
  63. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  64.            JSAMPARRAY output_array, int dest_row,
  65.            int num_rows, JDIMENSION num_cols)
  66. /* Copy some rows of samples from one place to another.
  67.  * num_rows rows are copied from input_array[source_row++]
  68.  * to output_array[dest_row++]; these areas may overlap for duplication.
  69.  * The source and destination arrays must be at least as wide as num_cols.
  70.  */
  71. {
  72.   register JSAMPROW inptr, outptr;
  73. #ifdef FMEMCOPY
  74.   register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  75. #else
  76.   register JDIMENSION count;
  77. #endif
  78.   register int row;
  79.  
  80.   input_array += source_row;
  81.   output_array += dest_row;
  82.  
  83.   for (row = num_rows; row > 0; row--) {
  84.     inptr = *input_array++;
  85.     outptr = *output_array++;
  86. #ifdef FMEMCOPY
  87.     FMEMCOPY(outptr, inptr, count);
  88. #else
  89.     for (count = num_cols; count > 0; count--)
  90.       *outptr++ = *inptr++;    /* needn't bother with GETJSAMPLE() here */
  91. #endif
  92.   }
  93. }
  94.  
  95.  
  96. GLOBAL void
  97. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  98.          JDIMENSION num_blocks)
  99. /* Copy a row of coefficient blocks from one place to another. */
  100. {
  101. #ifdef FMEMCOPY
  102.   FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  103. #else
  104.   register JCOEFPTR inptr, outptr;
  105.   register long count;
  106.  
  107.   inptr = (JCOEFPTR) input_row;
  108.   outptr = (JCOEFPTR) output_row;
  109.   for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  110.     *outptr++ = *inptr++;
  111.   }
  112. #endif
  113. }
  114.  
  115.  
  116. GLOBAL void
  117. jzero_far (void FAR * target, size_t bytestozero)
  118. /* Zero out a chunk of FAR memory. */
  119. /* This might be sample-array data, block-array data, or alloc_medium data. */
  120. {
  121. #ifdef FMEMZERO
  122.   FMEMZERO(target, bytestozero);
  123. #else
  124.   register char FAR * ptr = (char FAR *) target;
  125.   register size_t count;
  126.  
  127.   for (count = bytestozero; count > 0; count--) {
  128.     *ptr++ = 0;
  129.   }
  130. #endif
  131. }
  132.