src/java.desktop/share/native/libjavajpeg/jutils.c
author jiefu
Fri, 15 Nov 2019 20:39:26 +0800
changeset 59110 8c4c358272a9
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234232: [TESTBUG] gc/shenandoah/jvmti/TestHeapDump.java fails with -Xcomp Reviewed-by: zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * jutils.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * Copyright (C) 1991-1996, Thomas G. Lane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This file is part of the Independent JPEG Group's software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * For conditions of distribution and use, see the accompanying README file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * This file contains tables and miscellaneous utility routines needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * for both compression and decompression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * Note we prefix all global names with "j" to minimize conflicts with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * a surrounding application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
#define JPEG_INTERNALS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
#include "jinclude.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
#include "jpeglib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * of a DCT block read in natural order (left to right, top to bottom).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#if 0                           /* This table is not actually needed in v6a */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
const int jpeg_zigzag_order[DCTSIZE2] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
   0,  1,  5,  6, 14, 15, 27, 28,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
   2,  4,  7, 13, 16, 26, 29, 42,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
   3,  8, 12, 17, 25, 30, 41, 43,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
   9, 11, 18, 24, 31, 40, 44, 53,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  10, 19, 23, 32, 39, 45, 52, 54,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  20, 22, 33, 38, 46, 51, 55, 60,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  21, 34, 37, 47, 50, 56, 59, 61,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  35, 36, 48, 49, 57, 58, 62, 63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * jpeg_natural_order[i] is the natural-order position of the i'th element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * of zigzag order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * When reading corrupted data, the Huffman decoders could attempt
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * to reference an entry beyond the end of this array (if the decoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * zero run length reaches past the end of the block).  To prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * wild stores without adding an inner-loop test, we put some extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * "63"s after the real entries.  This will cause the extra coefficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * to be stored in location 63 of the block, not somewhere random.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The worst case would be a run-length of 15, which means we need 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * fake entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
const int jpeg_natural_order[DCTSIZE2+16] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  0,  1,  8, 16,  9,  2,  3, 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 17, 24, 32, 25, 18, 11,  4,  5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 12, 19, 26, 33, 40, 48, 41, 34,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 27, 20, 13,  6,  7, 14, 21, 28,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 35, 42, 49, 56, 57, 50, 43, 36,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 29, 22, 15, 23, 30, 37, 44, 51,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 58, 59, 52, 45, 38, 31, 39, 46,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 53, 60, 61, 54, 47, 55, 62, 63,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 63, 63, 63, 63, 63, 63, 63, 63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Arithmetic utilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
GLOBAL(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
jdiv_round_up (long a, long b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/* Compute a/b rounded up to next integer, ie, ceil(a/b) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
/* Assumes a >= 0, b > 0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  return (a + b - 1L) / b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
GLOBAL(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
jround_up (long a, long b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
/* Assumes a >= 0, b > 0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  a += b - 1L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  return a - (a % b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * and coefficient-block arrays.  This won't work on 80x86 because the arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * are FAR and we're assuming a small-pointer memory model.  However, some
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * DOS compilers provide far-pointer versions of memcpy() and memset() even
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * in the small-model libraries.  These will be used if USE_FMEM is defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * Otherwise, the routines below do it the hard way.  (The performance cost
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * is not all that great, because these routines aren't very heavily used.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#ifndef NEED_FAR_POINTERS       /* normal case, same as regular macros */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
#define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#define FMEMZERO(target,size)   MEMZERO(target,size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#else                           /* 80x86 case, define if we can */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
#ifdef USE_FMEM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
#define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
#define FMEMZERO(target,size)   _fmemset((void FAR *)(target), 0, (size_t)(size))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                   JSAMPARRAY output_array, int dest_row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                   int num_rows, JDIMENSION num_cols)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
/* Copy some rows of samples from one place to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * num_rows rows are copied from input_array[source_row++]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * to output_array[dest_row++]; these areas may overlap for duplication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * The source and destination arrays must be at least as wide as num_cols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  register JSAMPROW inptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
#ifdef FMEMCOPY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  register JDIMENSION count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  register int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  input_array += source_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  output_array += dest_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  for (row = num_rows; row > 0; row--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    inptr = *input_array++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    outptr = *output_array++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
#ifdef FMEMCOPY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    FMEMCOPY(outptr, inptr, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    for (count = num_cols; count > 0; count--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      *outptr++ = *inptr++;     /* needn't bother with GETJSAMPLE() here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                 JDIMENSION num_blocks)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
/* Copy a row of coefficient blocks from one place to another. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
#ifdef FMEMCOPY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
  FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  register JCOEFPTR inptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
  register long count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  inptr = (JCOEFPTR) input_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  outptr = (JCOEFPTR) output_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    *outptr++ = *inptr++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
jzero_far (void FAR * target, size_t bytestozero)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
/* Zero out a chunk of FAR memory. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
/* This might be sample-array data, block-array data, or alloc_large data. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
#ifdef FMEMZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
  FMEMZERO(target, bytestozero);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
  register char FAR * ptr = (char FAR *) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  register size_t count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
  for (count = bytestozero; count > 0; count--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    *ptr++ = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
}