src/java.desktop/share/native/libjavajpeg/jdtrans.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
 * jdtrans.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * Copyright (C) 1995-1997, 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 library routines for transcoding decompression,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * that is, reading raw DCT coefficient arrays from an input JPEG file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * The routines in jdapimin.c will also be needed by a transcoder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
#define JPEG_INTERNALS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
#include "jinclude.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
#include "jpeglib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
/* Forward declarations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Read the coefficient arrays from a JPEG file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * jpeg_read_header must be completed before calling this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The entire image is read into a set of virtual coefficient-block arrays,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * one per component.  The return value is a pointer to the array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * virtual-array descriptors.  These can be manipulated directly via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * JPEG memory manager, or handed off to jpeg_write_coefficients().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * To release the memory occupied by the virtual arrays, call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * jpeg_finish_decompress() when done with the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * An alternative usage is to simply obtain access to the coefficient arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * during a buffered-image-mode decompression operation.  This is allowed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * after any jpeg_finish_output() call.  The arrays can be accessed until
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * jpeg_finish_decompress() is called.  (Note that any call to the library
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * may reposition the arrays, so don't rely on access_virt_barray() results
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * to stay valid across library calls.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Returns NULL if suspended.  This case need be checked only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * a suspending data source is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
GLOBAL(jvirt_barray_ptr *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
jpeg_read_coefficients (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  if (cinfo->global_state == DSTATE_READY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /* First call: initialize active modules */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    transdecode_master_selection(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    cinfo->global_state = DSTATE_RDCOEFS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  if (cinfo->global_state == DSTATE_RDCOEFS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /* Absorb whole file into the coef buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
      int retcode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
      /* Call progress monitor hook if present */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
      if (cinfo->progress != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
      /* Absorb some more input */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
      retcode = (*cinfo->inputctl->consume_input) (cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      if (retcode == JPEG_SUSPENDED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
      if (retcode == JPEG_REACHED_EOI)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      /* Advance progress counter if appropriate */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      if (cinfo->progress != NULL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
          (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
          /* startup underestimated number of scans; ratchet up one scan */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
          cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /* Set state so that jpeg_finish_decompress does the right thing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    cinfo->global_state = DSTATE_STOPPING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  /* At this point we should be in state DSTATE_STOPPING if being used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
   * to the coefficients during a full buffered-image-mode decompression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  if ((cinfo->global_state == DSTATE_STOPPING ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
       cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    return cinfo->coef->coef_arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  /* Oops, improper usage */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  return NULL;                  /* keep compiler happy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * Master selection of decompression modules for transcoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * This substitutes for jdmaster.c's initialization of the full decompressor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
transdecode_master_selection (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  /* This is effectively a buffered-image operation. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  cinfo->buffered_image = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  /* Entropy decoding: either Huffman or arithmetic coding. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  if (cinfo->arith_code) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    if (cinfo->progressive_mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
#ifdef D_PROGRESSIVE_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      jinit_phuff_decoder(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      ERREXIT(cinfo, JERR_NOT_COMPILED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      jinit_huff_decoder(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  /* Always get a full-image coefficient buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  jinit_d_coef_controller(cinfo, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  /* We can now tell the memory manager to allocate virtual arrays. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
  /* Initialize input side of decompressor to consume first scan. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  (*cinfo->inputctl->start_input_pass) (cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  /* Initialize progress monitoring. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  if (cinfo->progress != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    int nscans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /* Estimate number of scans to set pass_limit. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    if (cinfo->progressive_mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      nscans = 2 + 3 * cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    } else if (cinfo->inputctl->has_multiple_scans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
      /* For a nonprogressive multiscan file, estimate 1 scan per component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      nscans = cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
      nscans = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    cinfo->progress->pass_counter = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    cinfo->progress->completed_passes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    cinfo->progress->total_passes = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
}