src/java.desktop/share/native/libjavajpeg/jdmainct.c
author adinn
Fri, 26 Jan 2018 16:38:21 +0000
changeset 48682 34e45260c040
parent 47216 71c04702a3d5
permissions -rw-r--r--
8196221: AArch64: Mistake in committed patch for JDK-8195859 Summary: The wrong patch was committed for JDK-8195859 Reviewed-by: aph
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
 * jdmainct.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 main buffer controller for decompression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * The main buffer lies between the JPEG decompressor proper and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * post-processor; it holds downsampled data in the JPEG colorspace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * Note that this code is bypassed in raw-data mode, since the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * supplies the equivalent of the main buffer in that case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
#define JPEG_INTERNALS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
#include "jinclude.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
#include "jpeglib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * In the current system design, the main buffer need never be a full-image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * buffer; any full-height buffers will be found inside the coefficient or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * postprocessing controllers.  Nonetheless, the main controller is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * trivial.  Its responsibility is to provide context rows for upsampling/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * rescaling, and doing this in an efficient fashion is a bit tricky.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Postprocessor input data is counted in "row groups".  A row group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * sample rows of each component.  (We require DCT_scaled_size values to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * chosen such that these numbers are integers.  In practice DCT_scaled_size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * values will likely be powers of two, so we actually have the stronger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * condition that DCT_scaled_size / min_DCT_scaled_size is an integer.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Upsampling will typically produce max_v_samp_factor pixel rows from each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * row group (times any additional scale factor that the upsampler is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * applying).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The coefficient controller will deliver data to us one iMCU row at a time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * exactly min_DCT_scaled_size row groups.  (This amount of data corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * to one row of MCUs when the image is fully interleaved.)  Note that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * number of sample rows varies across components, but the number of row
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * groups does not.  Some garbage sample rows may be included in the last iMCU
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * row at the bottom of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Depending on the vertical scaling algorithm used, the upsampler may need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * access to the sample row(s) above and below its current input row group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The upsampler is required to set need_context_rows TRUE at global selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * time if so.  When need_context_rows is FALSE, this controller can simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * obtain one iMCU row at a time from the coefficient controller and dole it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * out as row groups to the postprocessor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * When need_context_rows is TRUE, this controller guarantees that the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * passed to postprocessing contains at least one row group's worth of samples
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * above and below the row group(s) being processed.  Note that the context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * rows "above" the first passed row group appear at negative row offsets in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * the passed buffer.  At the top and bottom of the image, the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * context rows are manufactured by duplicating the first or last real sample
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * row; this avoids having special cases in the upsampling inner loops.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The amount of context is fixed at one row group just because that's a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * convenient number for this controller to work with.  The existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * upsamplers really only need one sample row of context.  An upsampler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * supporting arbitrary output rescaling might wish for more than one row
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * group of context when shrinking the image; tough, we don't handle that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * (This is justified by the assumption that downsizing will be handled mostly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * by adjusting the DCT_scaled_size values, so that the actual scale factor at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * the upsample step needn't be much less than one.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * To provide the desired context, we have to retain the last two row groups
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * of one iMCU row while reading in the next iMCU row.  (The last row group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * can't be processed until we have another row group for its below-context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * and so we have to save the next-to-last group too for its above-context.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * We could do this most simply by copying data around in our buffer, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * that'd be very slow.  We can avoid copying any data by creating a rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * strange pointer structure.  Here's how it works.  We allocate a workspace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * consisting of M+2 row groups (where M = min_DCT_scaled_size is the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * of row groups per iMCU row).  We create two sets of redundant pointers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * the workspace.  Labeling the physical row groups 0 to M+1, the synthesized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * pointer lists look like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *                   M+1                          M-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * master pointer --> 0         master pointer --> 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *                    1                            1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *                   ...                          ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *                   M-3                          M-3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *                   M-2                           M
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *                   M-1                          M+1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *                    M                           M-2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *                   M+1                          M-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *                    0                            0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * We read alternate iMCU rows using each master pointer; thus the last two
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * row groups of the previous iMCU row remain un-overwritten in the workspace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * The pointer lists are set up so that the required context rows appear to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * be adjacent to the proper places when we pass the pointer lists to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * upsampler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * The above pictures describe the normal state of the pointer lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * At top and bottom of the image, we diddle the pointer lists to duplicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * the first or last sample row as necessary (this is cheaper than copying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * sample rows around).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1.  In that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * situation each iMCU row provides only one row group so the buffering logic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * must be different (eg, we must read two iMCU rows before we can emit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * first row group).  For now, we simply do not support providing context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * rows when min_DCT_scaled_size is 1.  That combination seems unlikely to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * be worth providing --- if someone wants a 1/8th-size preview, they probably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * want it quick and dirty, so a context-free upsampler is sufficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
/* Private buffer controller object */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  struct jpeg_d_main_controller pub; /* public fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  /* Pointer to allocated workspace (M or M+2 row groups). */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
  JSAMPARRAY buffer[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  boolean buffer_full;          /* Have we gotten an iMCU row from decoder? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  JDIMENSION rowgroup_ctr;      /* counts row groups output to postprocessor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  /* Remaining fields are only used in the context case. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  /* These are the master pointers to the funny-order pointer lists. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  JSAMPIMAGE xbuffer[2];        /* pointers to weird pointer lists */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  int whichptr;                 /* indicates which pointer set is now in use */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  int context_state;            /* process_data state machine status */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  JDIMENSION rowgroups_avail;   /* row groups available to postprocessor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  JDIMENSION iMCU_row_ctr;      /* counts iMCU rows to detect image top/bot */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
} my_main_controller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
typedef my_main_controller * my_main_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
/* context_state values: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
#define CTX_PREPARE_FOR_IMCU    0       /* need to prepare for MCU row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
#define CTX_PROCESS_IMCU        1       /* feeding iMCU to postprocessor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#define CTX_POSTPONED_ROW       2       /* feeding postponed row group */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
/* Forward declarations */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
METHODDEF(void) process_data_simple_main
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
             JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
METHODDEF(void) process_data_context_main
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
             JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
#ifdef QUANT_2PASS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
METHODDEF(void) process_data_crank_post
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
             JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
alloc_funny_pointers (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
/* Allocate space for the funny pointer lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * This is done only once, not once per pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
  my_main_ptr _main = (my_main_ptr) cinfo->main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
  int ci, rgroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
  int M = cinfo->min_DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
  jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
  JSAMPARRAY xbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
  /* Get top-level space for component array pointers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
   * We alloc both arrays with one call to save a few cycles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
  _main->xbuffer[0] = (JSAMPIMAGE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
  _main->xbuffer[1] = _main->xbuffer[0] + cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /* Get space for pointer lists --- M+4 row groups in each list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * We alloc both pointer lists with one call to save a few cycles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    xbuf = (JSAMPARRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                  2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    xbuf += rgroup;             /* want one row group at negative offsets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    _main->xbuffer[0][ci] = xbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    xbuf += rgroup * (M + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    _main->xbuffer[1][ci] = xbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
make_funny_pointers (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
/* Create the funny pointer lists discussed in the comments above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * The actual workspace is already allocated (in main->buffer),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * and the space for the pointer lists is allocated too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * This routine just fills in the curiously ordered lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * This will be repeated at the beginning of each pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  my_main_ptr _main = (my_main_ptr) cinfo->main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  int ci, i, rgroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  int M = cinfo->min_DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  JSAMPARRAY buf, xbuf0, xbuf1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    xbuf0 = _main->xbuffer[0][ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    xbuf1 = _main->xbuffer[1][ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /* First copy the workspace pointers as-is */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    buf = _main->buffer[ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    for (i = 0; i < rgroup * (M + 2); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      xbuf0[i] = xbuf1[i] = buf[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /* In the second list, put the last four row groups in swapped order */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    for (i = 0; i < rgroup * 2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
      xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /* The wraparound pointers at top and bottom will be filled later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * (see set_wraparound_pointers, below).  Initially we want the "above"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * pointers to duplicate the first actual data line.  This only needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * to happen in xbuffer[0].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    for (i = 0; i < rgroup; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
      xbuf0[i - rgroup] = xbuf0[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
set_wraparound_pointers (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
/* Set up the "wraparound" pointers at top and bottom of the pointer lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * This changes the pointer list state from top-of-image to the normal state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
  my_main_ptr _main = (my_main_ptr) cinfo->main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
  int ci, i, rgroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  int M = cinfo->min_DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  JSAMPARRAY xbuf0, xbuf1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    xbuf0 = _main->xbuffer[0][ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    xbuf1 = _main->xbuffer[1][ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    for (i = 0; i < rgroup; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      xbuf0[rgroup*(M+2) + i] = xbuf0[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      xbuf1[rgroup*(M+2) + i] = xbuf1[i];
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
set_bottom_pointers (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
/* Change the pointer lists to duplicate the last sample row at the bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * of the image.  whichptr indicates which xbuffer holds the final iMCU row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * Also sets rowgroups_avail to indicate number of nondummy row groups in row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
  my_main_ptr _main = (my_main_ptr) cinfo->main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
  int ci, i, rgroup, iMCUheight, rows_left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
  jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
  JSAMPARRAY xbuf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /* Count sample rows in one iMCU row and in one row group */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /* Count nondummy sample rows remaining for this component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    if (rows_left == 0) rows_left = iMCUheight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /* Count nondummy row groups.  Should get same answer for each component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * so we need only do it once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    if (ci == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      _main->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /* Duplicate the last real sample row rgroup*2 times; this pads out the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * last partial rowgroup and ensures at least one full rowgroup of context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    xbuf = _main->xbuffer[_main->whichptr][ci];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    for (i = 0; i < rgroup * 2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      xbuf[rows_left + i] = xbuf[rows_left-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 * Initialize for a processing pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
start_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
  my_main_ptr _main = (my_main_ptr) cinfo->main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
  switch (pass_mode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
  case JBUF_PASS_THRU:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    if (cinfo->upsample->need_context_rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      _main->pub.process_data = process_data_context_main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      _main->whichptr = 0;      /* Read first iMCU row into xbuffer[0] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      _main->context_state = CTX_PREPARE_FOR_IMCU;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      _main->iMCU_row_ctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
      /* Simple case with no context needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
      _main->pub.process_data = process_data_simple_main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    _main->buffer_full = FALSE; /* Mark buffer empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    _main->rowgroup_ctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
#ifdef QUANT_2PASS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
  case JBUF_CRANK_DEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /* For last pass of 2-pass quantization, just crank the postprocessor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    _main->pub.process_data = process_data_crank_post;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
  default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 * Process some data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 * This handles the simple case where no context is required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
process_data_simple_main (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                          JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                          JDIMENSION out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
  my_main_ptr _main = (my_main_ptr) cinfo->main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
  JDIMENSION rowgroups_avail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
  /* Read input data if we haven't filled the main buffer yet */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
  if (! _main->buffer_full) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    if (! (*cinfo->coef->decompress_data) (cinfo, _main->buffer))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
      return;                   /* suspension forced, can do nothing more */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    _main->buffer_full = TRUE;  /* OK, we have an iMCU row to work with */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
  /* There are always min_DCT_scaled_size row groups in an iMCU row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
  rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
  /* Note: at the bottom of the image, we may pass extra garbage row groups
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
   * to the postprocessor.  The postprocessor has to check for bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
   * of image anyway (at row resolution), so no point in us doing it too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
  /* Feed the postprocessor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
  (*cinfo->post->post_process_data) (cinfo, _main->buffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                     &_main->rowgroup_ctr, rowgroups_avail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                     output_buf, out_row_ctr, out_rows_avail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  if (_main->rowgroup_ctr >= rowgroups_avail) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    _main->buffer_full = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    _main->rowgroup_ctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
}
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
 * Process some data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
 * This handles the case where context rows must be provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
process_data_context_main (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                           JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                           JDIMENSION out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
  my_main_ptr _main = (my_main_ptr) cinfo->main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
  /* Read input data if we haven't filled the _main buffer yet */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
  if (! _main->buffer_full) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    if (! (*cinfo->coef->decompress_data) (cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                           _main->xbuffer[_main->whichptr]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
      return;                   /* suspension forced, can do nothing more */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    _main->buffer_full = TRUE;  /* OK, we have an iMCU row to work with */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    _main->iMCU_row_ctr++;      /* count rows received */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
  /* Postprocessor typically will not swallow all the input data it is handed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
   * in one call (due to filling the output buffer first).  Must be prepared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
   * to exit and restart.  This switch lets us keep track of how far we got.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
   * Note that each case falls through to the next on successful completion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
  switch (_main->context_state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
  case CTX_POSTPONED_ROW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    /* Call postprocessor using previously set pointers for postponed row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    (*cinfo->post->post_process_data) (cinfo, _main->xbuffer[_main->whichptr],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        &_main->rowgroup_ctr, _main->rowgroups_avail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        output_buf, out_row_ctr, out_rows_avail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    if (_main->rowgroup_ctr < _main->rowgroups_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
      return;                   /* Need to suspend */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    _main->context_state = CTX_PREPARE_FOR_IMCU;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    if (*out_row_ctr >= out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
      return;                   /* Postprocessor exactly filled output buf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /*FALLTHROUGH*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
  case CTX_PREPARE_FOR_IMCU:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /* Prepare to process first M-1 row groups of this iMCU row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    _main->rowgroup_ctr = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    _main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /* Check for bottom of image: if so, tweak pointers to "duplicate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * the last sample row, and adjust rowgroups_avail to ignore padding rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    if (_main->iMCU_row_ctr == cinfo->total_iMCU_rows)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
      set_bottom_pointers(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    _main->context_state = CTX_PROCESS_IMCU;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /*FALLTHROUGH*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
  case CTX_PROCESS_IMCU:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /* Call postprocessor using previously set pointers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    (*cinfo->post->post_process_data) (cinfo, _main->xbuffer[_main->whichptr],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        &_main->rowgroup_ctr, _main->rowgroups_avail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        output_buf, out_row_ctr, out_rows_avail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    if (_main->rowgroup_ctr < _main->rowgroups_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
      return;                   /* Need to suspend */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /* After the first iMCU, change wraparound pointers to normal state */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    if (_main->iMCU_row_ctr == 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
      set_wraparound_pointers(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /* Prepare to load new iMCU row using other xbuffer list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    _main->whichptr ^= 1;       /* 0=>1 or 1=>0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    _main->buffer_full = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /* Still need to process last row group of this iMCU row, */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /* which is saved at index M+1 of the other xbuffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    _main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    _main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    _main->context_state = CTX_POSTPONED_ROW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
 * Process some data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
 * Final pass of two-pass quantization: just call the postprocessor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
 * Source data will be the postprocessor controller's internal buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
#ifdef QUANT_2PASS_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
process_data_crank_post (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                         JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                         JDIMENSION out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
  (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                     (JDIMENSION *) NULL, (JDIMENSION) 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                     output_buf, out_row_ctr, out_rows_avail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
#endif /* QUANT_2PASS_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
 * Initialize main buffer controller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
  my_main_ptr _main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
  int ci, rgroup, ngroups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
  jpeg_component_info *compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
  _main = (my_main_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                SIZEOF(my_main_controller));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
  cinfo->main = (struct jpeg_d_main_controller *) _main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
  _main->pub.start_pass = start_pass_main;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
  if (need_full_buffer)         /* shouldn't happen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
  /* Allocate the workspace.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
   * ngroups is the number of row groups we need.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
  if (cinfo->upsample->need_context_rows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
      ERREXIT(cinfo, JERR_NOTIMPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    ngroups = cinfo->min_DCT_scaled_size + 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    ngroups = cinfo->min_DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
      cinfo->min_DCT_scaled_size; /* height of a row group of component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    _main->buffer[ci] = (*cinfo->mem->alloc_sarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                         compptr->width_in_blocks * compptr->DCT_scaled_size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                         (JDIMENSION) (rgroup * ngroups));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
}