src/java.desktop/share/native/libjavajpeg/jcapistd.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
 * jcapistd.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * Copyright (C) 1994-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 application interface code for the compression half
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * of the JPEG library.  These are the "standard" API routines that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * used in the normal full-compression case.  They are not used by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * transcoding-only application.  Note that if an application links in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * jpeg_start_compress, it will end up linking in the entire compressor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * We thus must separate this file from jcapimin.c to avoid linking the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * whole compression library into a transcoder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
#define JPEG_INTERNALS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
#include "jinclude.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
#include "jpeglib.h"
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
 * Compression initialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * Before calling this, all parameters and a data destination must be set up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * We require a write_all_tables parameter as a failsafe check when writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * multiple datastreams from the same compression object.  Since prior runs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * will have left all the tables marked sent_table=TRUE, a subsequent run
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * would emit an abbreviated stream (no tables) by default.  This may be what
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * is wanted, but for safety's sake it should not be the default behavior:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * programmers should have to make a deliberate choice to emit abbreviated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * images.  Therefore the documentation and examples should encourage people
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * to pass write_all_tables=TRUE; then it will take active thought to do the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * wrong thing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  if (cinfo->global_state != CSTATE_START)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  if (write_all_tables)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  /* (Re)initialize error mgr and destination modules */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  (*cinfo->dest->init_destination) (cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  /* Perform master selection of active modules */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  jinit_compress_master(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  /* Set up for the first pass */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  (*cinfo->master->prepare_for_pass) (cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  /* Ready for application to drive first pass through jpeg_write_scanlines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
   * or jpeg_write_raw_data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  cinfo->next_scanline = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Write some scanlines of data to the JPEG compressor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * The return value will be the number of lines actually written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * This should be less than the supplied num_lines only in case that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * the data destination module has requested suspension of the compressor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * or if more than image_height scanlines are passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Note: we warn about excess calls to jpeg_write_scanlines() since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * this likely signals an application programmer error.  However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * excess scanlines passed in the last valid call are *silently* ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * so that the application need not adjust num_lines for end-of-image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * when using a multiple-scanline buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
GLOBAL(JDIMENSION)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                      JDIMENSION num_lines)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  JDIMENSION row_ctr, rows_left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  if (cinfo->global_state != CSTATE_SCANNING)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
  if (cinfo->next_scanline >= cinfo->image_height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  /* Call progress monitor hook if present */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  if (cinfo->progress != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    cinfo->progress->pass_limit = (long) cinfo->image_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  /* Give master control module another chance if this is first call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
   * jpeg_write_scanlines.  This lets output of the frame/scan headers be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
   * delayed so that application can write COM, etc, markers between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
   * jpeg_start_compress and jpeg_write_scanlines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  if (cinfo->master->call_pass_startup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    (*cinfo->master->pass_startup) (cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  /* Ignore any extra scanlines at bottom of image. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  rows_left = cinfo->image_height - cinfo->next_scanline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  if (num_lines > rows_left)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    num_lines = rows_left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  row_ctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
  cinfo->next_scanline += row_ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
  return row_ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * Alternate entry point to write raw data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * Processes exactly one iMCU row per call, unless suspended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
GLOBAL(JDIMENSION)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                     JDIMENSION num_lines)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  JDIMENSION lines_per_iMCU_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  if (cinfo->global_state != CSTATE_RAW_OK)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
  if (cinfo->next_scanline >= cinfo->image_height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  /* Call progress monitor hook if present */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  if (cinfo->progress != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    cinfo->progress->pass_counter = (long) cinfo->next_scanline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    cinfo->progress->pass_limit = (long) cinfo->image_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  /* Give master control module another chance if this is first call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
   * jpeg_write_raw_data.  This lets output of the frame/scan headers be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
   * delayed so that application can write COM, etc, markers between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
   * jpeg_start_compress and jpeg_write_raw_data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  if (cinfo->master->call_pass_startup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    (*cinfo->master->pass_startup) (cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  /* Verify that at least one iMCU row has been passed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  if (num_lines < lines_per_iMCU_row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  /* Directly compress the row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
  if (! (*cinfo->coef->compress_data) (cinfo, data)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /* If compressor did not consume the whole row, suspend processing. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  /* OK, we processed one iMCU row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
  cinfo->next_scanline += lines_per_iMCU_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  return lines_per_iMCU_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
}