src/java.desktop/share/native/libjavajpeg/jcprepct.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
 * jcprepct.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 the compression preprocessing controller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * This controller manages the color conversion, downsampling,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * and edge expansion steps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * Most of the complexity here is associated with buffering input rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * as required by the downsampler.  See the comments at the head of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * jcsample.c for the downsampler's needs.
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
/* At present, jcsample.c can request context rows only for smoothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * In the future, we might also need context rows for CCIR601 sampling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * or other more-complex downsampling procedures.  The code to support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * context rows should be compiled only if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#ifdef INPUT_SMOOTHING_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#define CONTEXT_ROWS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * For the simple (no-context-row) case, we just need to buffer one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * row group's worth of pixels for the downsampling step.  At the bottom of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the image, we pad to a full row group by replicating the last pixel row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * The downsampler's last output row is then replicated if needed to pad
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * out to a full iMCU row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * When providing context rows, we must buffer three row groups' worth of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * pixels.  Three row groups are physically allocated, but the row pointer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * arrays are made five row groups high, with the extra pointers above and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * below "wrapping around" to point to the last and first real row groups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * This allows the downsampler to access the proper context rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * At the top and bottom of the image, we create dummy context rows by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * copying the first or last real pixel row.  This copying could be avoided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * trouble on the compression side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/* Private buffer controller object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  struct jpeg_c_prep_controller pub; /* public fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  /* Downsampling input buffer.  This buffer holds color-converted data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
   * until we have enough to do a downsample step.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  JSAMPARRAY color_buf[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  JDIMENSION rows_to_go;        /* counts rows remaining in source image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  int next_buf_row;             /* index of next row to store in color_buf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#ifdef CONTEXT_ROWS_SUPPORTED   /* only needed for context case */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  int this_row_group;           /* starting row index of group to process */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  int next_buf_stop;            /* downsample when we reach this index */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
} my_prep_controller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
typedef my_prep_controller * my_prep_ptr;
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
 * Initialize for a processing pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  if (pass_mode != JBUF_PASS_THRU)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  /* Initialize total-height counter for detecting bottom of image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  prep->rows_to_go = cinfo->image_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  /* Mark the conversion buffer empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  prep->next_buf_row = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#ifdef CONTEXT_ROWS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  /* Preset additional state variables for context mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
   * These aren't used in non-context mode, so we needn't test which mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  prep->this_row_group = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  /* Set next_buf_stop to stop after two row groups have been read in. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * Expand an image vertically from height input_rows to height output_rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * by duplicating the bottom row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    int input_rows, int output_rows)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
  register int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
  for (row = input_rows; row < output_rows; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    jcopy_sample_rows(image_data, input_rows-1, image_data, row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                      1, num_cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * Process some data in the simple no-context case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * Preprocessor output data is counted in "row groups".  A row group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * is defined to be v_samp_factor sample rows of each component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * Downsampling will produce this much data from each max_v_samp_factor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * input rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
pre_process_data (j_compress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                  JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                  JDIMENSION in_rows_avail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                  JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                  JDIMENSION out_row_groups_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
  int numrows, ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  JDIMENSION inrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  jpeg_component_info * compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
  while (*in_row_ctr < in_rows_avail &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         *out_row_group_ctr < out_row_groups_avail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /* Do color conversion to fill the conversion buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    inrows = in_rows_avail - *in_row_ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    numrows = (int) MIN((JDIMENSION) numrows, inrows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                       prep->color_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                       (JDIMENSION) prep->next_buf_row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                       numrows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    *in_row_ctr += numrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    prep->next_buf_row += numrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    prep->rows_to_go -= numrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /* If at bottom of image, pad to fill the conversion buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    if (prep->rows_to_go == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        prep->next_buf_row < cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      for (ci = 0; ci < cinfo->num_components; ci++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                           prep->next_buf_row, cinfo->max_v_samp_factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      prep->next_buf_row = cinfo->max_v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /* If we've filled the conversion buffer, empty it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    if (prep->next_buf_row == cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      (*cinfo->downsample->downsample) (cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                        prep->color_buf, (JDIMENSION) 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                        output_buf, *out_row_group_ctr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      prep->next_buf_row = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      (*out_row_group_ctr)++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /* If at bottom of image, pad the output to a full iMCU height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Note we assume the caller is providing a one-iMCU-height output buffer!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    if (prep->rows_to_go == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        *out_row_group_ctr < out_row_groups_avail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
           ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        expand_bottom_edge(output_buf[ci],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                           compptr->width_in_blocks * DCTSIZE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                           (int) (*out_row_group_ctr * compptr->v_samp_factor),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                           (int) (out_row_groups_avail * compptr->v_samp_factor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      *out_row_group_ctr = out_row_groups_avail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      break;                    /* can exit outer loop without test */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
#ifdef CONTEXT_ROWS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * Process some data in the context case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
pre_process_context (j_compress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                     JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                     JDIMENSION in_rows_avail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                     JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                     JDIMENSION out_row_groups_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  int numrows, ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  int buf_height = cinfo->max_v_samp_factor * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  JDIMENSION inrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  while (*out_row_group_ctr < out_row_groups_avail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    if (*in_row_ctr < in_rows_avail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      /* Do color conversion to fill the conversion buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      inrows = in_rows_avail - *in_row_ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
      numrows = prep->next_buf_stop - prep->next_buf_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      numrows = (int) MIN((JDIMENSION) numrows, inrows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                         prep->color_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                         (JDIMENSION) prep->next_buf_row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                         numrows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      /* Pad at top of image, if first time through */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
      if (prep->rows_to_go == cinfo->image_height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        for (ci = 0; ci < cinfo->num_components; ci++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
          int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
          for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            jcopy_sample_rows(prep->color_buf[ci], 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                              prep->color_buf[ci], -row,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                              1, cinfo->image_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      *in_row_ctr += numrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
      prep->next_buf_row += numrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
      prep->rows_to_go -= numrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
      /* Return for more data, unless we are at the bottom of the image. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
      if (prep->rows_to_go != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
      /* When at bottom of image, pad to fill the conversion buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      if (prep->next_buf_row < prep->next_buf_stop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        for (ci = 0; ci < cinfo->num_components; ci++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
          expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                             prep->next_buf_row, prep->next_buf_stop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        prep->next_buf_row = prep->next_buf_stop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /* If we've gotten enough data, downsample a row group. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    if (prep->next_buf_row == prep->next_buf_stop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      (*cinfo->downsample->downsample) (cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                        prep->color_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                        (JDIMENSION) prep->this_row_group,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                        output_buf, *out_row_group_ctr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      (*out_row_group_ctr)++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      /* Advance pointers with wraparound as necessary. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      prep->this_row_group += cinfo->max_v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      if (prep->this_row_group >= buf_height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        prep->this_row_group = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      if (prep->next_buf_row >= buf_height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        prep->next_buf_row = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * Create the wrapped-around downsampling input buffer needed for context mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
create_context_buffer (j_compress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
  int rgroup_height = cinfo->max_v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
  int ci, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
  jpeg_component_info * compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
  JSAMPARRAY true_buffer, fake_buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
  /* Grab enough space for fake row pointers for all the components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
   * we need five row groups' worth of pointers for each component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
  fake_buffer = (JSAMPARRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                (cinfo->num_components * 5 * rgroup_height) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                SIZEOF(JSAMPROW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /* Allocate the actual buffer space (3 row groups) for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * We make the buffer wide enough to allow the downsampler to edge-expand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * horizontally within the buffer, if it so chooses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    true_buffer = (*cinfo->mem->alloc_sarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
       (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                      cinfo->max_h_samp_factor) / compptr->h_samp_factor),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
       (JDIMENSION) (3 * rgroup_height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /* Copy true buffer row pointers into the middle of the fake row array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    MEMCOPY(fake_buffer + rgroup_height, true_buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            3 * rgroup_height * SIZEOF(JSAMPROW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /* Fill in the above and below wraparound pointers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    for (i = 0; i < rgroup_height; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
      fake_buffer[i] = true_buffer[2 * rgroup_height + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
      fake_buffer[4 * rgroup_height + i] = true_buffer[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    prep->color_buf[ci] = fake_buffer + rgroup_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    fake_buffer += 5 * rgroup_height; /* point to space for next component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
#endif /* CONTEXT_ROWS_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
 * Initialize preprocessing controller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
  my_prep_ptr prep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
  int ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
  jpeg_component_info * compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
  if (need_full_buffer)         /* safety check */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
  prep = (my_prep_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                                SIZEOF(my_prep_controller));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
  cinfo->prep = (struct jpeg_c_prep_controller *) prep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
  prep->pub.start_pass = start_pass_prep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
  /* Allocate the color conversion buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
   * We make the buffer wide enough to allow the downsampler to edge-expand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
   * horizontally within the buffer, if it so chooses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
  if (cinfo->downsample->need_context_rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /* Set up to provide context rows */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
#ifdef CONTEXT_ROWS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    prep->pub.pre_process_data = pre_process_context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    create_context_buffer(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    ERREXIT(cinfo, JERR_NOT_COMPILED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /* No context, just make it tall enough for one row group */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    prep->pub.pre_process_data = pre_process_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                        cinfo->max_h_samp_factor) / compptr->h_samp_factor),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         (JDIMENSION) cinfo->max_v_samp_factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
}