Thomas G. Lane | 2cbeb8a | 1991-10-07 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * jutils.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 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 = 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 int i; |
| 73 | register long count; |
| 74 | |
| 75 | for (count = num_blocks; count > 0; count--) { |
| 76 | inptr = *input_row++; |
| 77 | outptr = *output_row++; |
| 78 | for (i = DCTSIZE2; i > 0; i--) |
| 79 | *outptr++ = *inptr++; |
| 80 | } |
| 81 | #else |
| 82 | memcpy((void *) output_row, (void *) input_row, |
| 83 | (size_t) (num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)))); |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | |
| 88 | GLOBAL void |
| 89 | jzero_far (void FAR * target, size_t bytestozero) |
| 90 | /* Zero out a chunk of FAR memory. */ |
| 91 | /* This might be sample-array data, block-array data, or alloc_medium data. */ |
| 92 | { |
| 93 | /* On normal machines we can use MEMZERO(). This won't work on 80x86 |
| 94 | * because we're assuming a small-pointer memory model. |
| 95 | */ |
| 96 | #ifdef NEED_FAR_POINTERS |
| 97 | register char FAR * ptr = (char FAR *) target; |
| 98 | register size_t count; |
| 99 | |
| 100 | for (count = bytestozero; count > 0; count--) { |
| 101 | *ptr++ = 0; |
| 102 | } |
| 103 | #else |
| 104 | MEMZERO((void *) target, bytestozero); |
| 105 | #endif |
| 106 | } |