src/java.desktop/share/native/libjavajpeg/jccoefct.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
 * jccoefct.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * Copyright (C) 1994-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 the coefficient buffer controller for compression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * This controller is the top level of the JPEG compressor proper.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * The coefficient buffer lies between forward-DCT and entropy encoding steps.
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
/* We use a full-image coefficient buffer when doing Huffman optimization,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * and also for writing multiple-scan JPEG files.  In all cases, the DCT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * step is run during the first pass, and subsequent passes need only read
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * the buffered coefficients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#ifdef ENTROPY_OPT_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#define FULL_COEF_BUFFER_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#ifdef C_MULTISCAN_FILES_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#define FULL_COEF_BUFFER_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#endif
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
/* Private buffer controller object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  struct jpeg_c_coef_controller pub; /* public fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  JDIMENSION iMCU_row_num;      /* iMCU row # within image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  JDIMENSION mcu_ctr;           /* counts MCUs processed in current row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  int MCU_vert_offset;          /* counts MCU rows within iMCU row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  int MCU_rows_per_iMCU_row;    /* number of such rows needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  /* For single-pass compression, it's sufficient to buffer just one MCU
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
   * (although this may prove a bit slow in practice).  We allocate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
   * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
   * MCU constructed and sent.  (On 80x86, the workspace is FAR even though
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
   * it's not really very big; this is to keep the module interfaces unchanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
   * when a large coefficient buffer is necessary.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
   * In multi-pass modes, this array points to the current MCU's blocks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
   * within the virtual arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  /* In multi-pass modes, we need a virtual block array for each component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  jvirt_barray_ptr whole_image[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
} my_coef_controller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
typedef my_coef_controller * my_coef_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
/* Forward declarations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
METHODDEF(boolean) compress_data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#ifdef FULL_COEF_BUFFER_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
METHODDEF(boolean) compress_first_pass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
METHODDEF(boolean) compress_output
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
start_iMCU_row (j_compress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
/* Reset within-iMCU-row counters for a new row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
   * But at the bottom of the image, process only what's left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  if (cinfo->comps_in_scan > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    coef->MCU_rows_per_iMCU_row = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  coef->mcu_ctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  coef->MCU_vert_offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * Initialize for a processing pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
  coef->iMCU_row_num = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  start_iMCU_row(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  switch (pass_mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
  case JBUF_PASS_THRU:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    if (coef->whole_image[0] != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    coef->pub.compress_data = compress_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#ifdef FULL_COEF_BUFFER_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  case JBUF_SAVE_AND_PASS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    if (coef->whole_image[0] == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    coef->pub.compress_data = compress_first_pass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  case JBUF_CRANK_DEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    if (coef->whole_image[0] == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    coef->pub.compress_data = compress_output;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * Process some data in the single-pass case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * per call, ie, v_samp_factor block rows for each component in the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * Returns TRUE if the iMCU row is completed, FALSE if suspended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * NB: input_buf contains a plane for each component in image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * which we index according to the component's SOF position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
METHODDEF(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  int blkn, bi, ci, yindex, yoffset, blockcnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
  JDIMENSION ypos, xpos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
  /* Loop to write as much as one whole iMCU row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
       yoffset++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         MCU_col_num++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
      /* Determine where data comes from in input_buf and do the DCT thing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
       * Each call on forward_DCT processes a horizontal row of DCT blocks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
       * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
       * sequentially.  Dummy blocks at the right or bottom edge are filled in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
       * specially.  The data in them does not matter for image reconstruction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
       * so we fill them with values that will encode to the smallest amount of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
       * data, viz: all zeroes in the AC entries, DC entries equal to previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
       * block's DC value.  (Thanks to Thomas Kinsman for this idea.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      blkn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        compptr = cinfo->cur_comp_info[ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                                : compptr->last_col_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        xpos = MCU_col_num * compptr->MCU_sample_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
          if (coef->iMCU_row_num < last_iMCU_row ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
              yoffset+yindex < compptr->last_row_height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            (*cinfo->fdct->forward_DCT) (cinfo, compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                         input_buf[compptr->component_index],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                         coef->MCU_buffer[blkn],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                         ypos, xpos, (JDIMENSION) blockcnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            if (blockcnt < compptr->MCU_width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
              /* Create some dummy blocks at the right edge of the image. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
              jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                        (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
              for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            /* Create a row of dummy blocks at the bottom of the image. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            jzero_far((void FAR *) coef->MCU_buffer[blkn],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                      compptr->MCU_width * SIZEOF(JBLOCK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            for (bi = 0; bi < compptr->MCU_width; bi++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
              coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
          blkn += compptr->MCU_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
          ypos += DCTSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
      /* Try to write the MCU.  In event of a suspension failure, we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
       * re-DCT the MCU on restart (a bit inefficient, could be fixed...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        /* Suspension forced; update state counters and exit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        coef->MCU_vert_offset = yoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        coef->mcu_ctr = MCU_col_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /* Completed an MCU row, but perhaps not an iMCU row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    coef->mcu_ctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  /* Completed the iMCU row, advance counters for next one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  coef->iMCU_row_num++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
  start_iMCU_row(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
#ifdef FULL_COEF_BUFFER_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * Process some data in the first pass of a multi-pass case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * per call, ie, v_samp_factor block rows for each component in the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * This amount of data is read from the source buffer, DCT'd and quantized,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * and saved into the virtual arrays.  We also generate suitable dummy blocks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * as needed at the right and lower edges.  (The dummy blocks are constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * in the virtual arrays, which have been padded appropriately.)  This makes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * it possible for subsequent passes not to worry about real vs. dummy blocks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * We must also emit the data to the entropy encoder.  This is conveniently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * done by calling compress_output() after we've loaded the current strip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * of the virtual arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * NB: input_buf contains a plane for each component in image.  All
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * components are DCT'd and loaded into the virtual arrays in this pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * However, it may be that only a subset of the components are emitted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * the entropy encoder during this first pass; be careful about looking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * at the scan-dependent variables (MCU dimensions, etc).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
METHODDEF(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  JDIMENSION blocks_across, MCUs_across, MCUindex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
  int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
  JCOEF lastDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
  JBLOCKARRAY buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
  JBLOCKROW thisblockrow, lastblockrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /* Align the virtual buffer for this component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    buffer = (*cinfo->mem->access_virt_barray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      ((j_common_ptr) cinfo, coef->whole_image[ci],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
       coef->iMCU_row_num * compptr->v_samp_factor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
       (JDIMENSION) compptr->v_samp_factor, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /* Count non-dummy DCT block rows in this iMCU row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    if (coef->iMCU_row_num < last_iMCU_row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      block_rows = compptr->v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      /* NB: can't use last_row_height here, since may not be set! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    blocks_across = compptr->width_in_blocks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    h_samp_factor = compptr->h_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /* Count number of dummy blocks to be added at the right margin. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    ndummy = (int) (blocks_across % h_samp_factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    if (ndummy > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      ndummy = h_samp_factor - ndummy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /* Perform DCT for all non-dummy blocks in this iMCU row.  Each call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * on forward_DCT processes a complete horizontal row of DCT blocks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    for (block_row = 0; block_row < block_rows; block_row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      thisblockrow = buffer[block_row];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      (*cinfo->fdct->forward_DCT) (cinfo, compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                                   input_buf[ci], thisblockrow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                                   (JDIMENSION) (block_row * DCTSIZE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                   (JDIMENSION) 0, blocks_across);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      if (ndummy > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        /* Create dummy blocks at the right edge of the image. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        thisblockrow += blocks_across; /* => first dummy block */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        lastDC = thisblockrow[-1][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        for (bi = 0; bi < ndummy; bi++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
          thisblockrow[bi][0] = lastDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /* If at end of image, create dummy block rows as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * The tricky part here is that within each MCU, we want the DC values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * of the dummy blocks to match the last real block's DC value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * This squeezes a few more bytes out of the resulting file...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    if (coef->iMCU_row_num == last_iMCU_row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
      blocks_across += ndummy;  /* include lower right corner */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
      MCUs_across = blocks_across / h_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
      for (block_row = block_rows; block_row < compptr->v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
           block_row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        thisblockrow = buffer[block_row];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        lastblockrow = buffer[block_row-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        jzero_far((void FAR *) thisblockrow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                  (size_t) (blocks_across * SIZEOF(JBLOCK)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
          lastDC = lastblockrow[h_samp_factor-1][0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
          for (bi = 0; bi < h_samp_factor; bi++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            thisblockrow[bi][0] = lastDC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
          thisblockrow += h_samp_factor; /* advance to next MCU in row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
          lastblockrow += h_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
  /* NB: compress_output will increment iMCU_row_num if successful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
   * A suspension return will result in redoing all the work above next time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  /* Emit data to the entropy encoder, sharing code with subsequent passes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
  return compress_output(cinfo, input_buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
 * Process some data in subsequent passes of a multi-pass case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
 * We process the equivalent of one fully interleaved MCU row ("iMCU" row)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
 * per call, ie, v_samp_factor block rows for each component in the scan.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
 * The data is obtained from the virtual arrays and fed to the entropy coder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
 * Returns TRUE if the iMCU row is completed, FALSE if suspended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 * NB: input_buf is ignored; it is likely to be a NULL pointer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
METHODDEF(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
  int blkn, ci, xindex, yindex, yoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
  JDIMENSION start_col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
  JBLOCKROW buffer_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
  jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
  /* Align the virtual buffers for the components used in this scan.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
   * NB: during first pass, this is safe only because the buffers will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
   * already be aligned properly, so jmemmgr.c won't need to do any I/O.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    compptr = cinfo->cur_comp_info[ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    buffer[ci] = (*cinfo->mem->access_virt_barray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
       coef->iMCU_row_num * compptr->v_samp_factor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
       (JDIMENSION) compptr->v_samp_factor, FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
  /* Loop to process one whole iMCU row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
       yoffset++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         MCU_col_num++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
      /* Construct list of pointers to DCT blocks belonging to this MCU */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
      blkn = 0;                 /* index of current DCT block within MCU */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        compptr = cinfo->cur_comp_info[ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        start_col = MCU_col_num * compptr->MCU_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
          buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            coef->MCU_buffer[blkn++] = buffer_ptr++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
      /* Try to write the MCU. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        /* Suspension forced; update state counters and exit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        coef->MCU_vert_offset = yoffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        coef->mcu_ctr = MCU_col_num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /* Completed an MCU row, but perhaps not an iMCU row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    coef->mcu_ctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
  /* Completed the iMCU row, advance counters for next one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
  coef->iMCU_row_num++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
  start_iMCU_row(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
  return TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
#endif /* FULL_COEF_BUFFER_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
 * Initialize coefficient buffer controller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
  my_coef_ptr coef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
  coef = (my_coef_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                                SIZEOF(my_coef_controller));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
  cinfo->coef = (struct jpeg_c_coef_controller *) coef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
  coef->pub.start_pass = start_pass_coef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
  /* Create the coefficient buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
  if (need_full_buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
#ifdef FULL_COEF_BUFFER_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /* Allocate a full-image virtual array for each component, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    int ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         (JDIMENSION) jround_up((long) compptr->width_in_blocks,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                (long) compptr->h_samp_factor),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
         (JDIMENSION) jround_up((long) compptr->height_in_blocks,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                                (long) compptr->v_samp_factor),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
         (JDIMENSION) compptr->v_samp_factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /* We only need a single-MCU buffer. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    JBLOCKROW buffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    buffer = (JBLOCKROW)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                  C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      coef->MCU_buffer[i] = buffer + i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    coef->whole_image[0] = NULL; /* flag for no virtual arrays */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
}