src/java.desktop/share/native/libjavajpeg/jdsample.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
 * jdsample.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * Copyright (C) 1991-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 upsampling routines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * Upsampling input data is counted in "row groups".  A row group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * sample rows of each component.  Upsampling will normally produce
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * max_v_samp_factor pixel rows from each row group (but this could vary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * if the upsampler is applying a scale factor of its own).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * An excellent reference for image resampling is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *   Digital Image Warping, George Wolberg, 1990.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
#define JPEG_INTERNALS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "jinclude.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "jpeglib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/* Pointer to routine to upsample a single component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
typedef JMETHOD(void, upsample1_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
                (j_decompress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
                 JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/* Private subobject */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  struct jpeg_upsampler pub;    /* public fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  /* Color conversion buffer.  When using separate upsampling and color
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
   * conversion steps, this buffer holds one upsampled row group until it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
   * has been color converted and output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
   * Note: we do not allocate any storage for component(s) which are full-size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
   * ie do not need rescaling.  The corresponding entry of color_buf[] is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
   * simply set to point to the input data array, thereby avoiding copying.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  JSAMPARRAY color_buf[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  /* Per-component upsampling method pointers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  upsample1_ptr methods[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  int next_row_out;             /* counts rows emitted from color_buf */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  JDIMENSION rows_to_go;        /* counts rows remaining in image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  /* Height of an input row group for each component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  int rowgroup_height[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  /* These arrays save pixel expansion factors so that int_expand need not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   * recompute them each time.  They are unused for other upsampling methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  UINT8 h_expand[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  UINT8 v_expand[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
} my_upsampler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
typedef my_upsampler * my_upsample_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * Initialize for an upsampling pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
start_pass_upsample (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  /* Mark the conversion buffer empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  upsample->next_row_out = cinfo->max_v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  /* Initialize total-height counter for detecting bottom of image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  upsample->rows_to_go = cinfo->output_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Control routine to do upsampling (and color conversion).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * In this version we upsample each component independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * We upsample one row group into the conversion buffer, then apply
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * color conversion a row at a time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
sep_upsample (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
              JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
              JDIMENSION in_row_groups_avail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
              JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
              JDIMENSION out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  int ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
  jpeg_component_info * compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  JDIMENSION num_rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  /* Fill the conversion buffer, if it's empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      /* Invoke per-component upsample method.  Notice we pass a POINTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
       * to color_buf[ci], so that fullsize_upsample can change it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      (*upsample->methods[ci]) (cinfo, compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        upsample->color_buf + ci);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    upsample->next_row_out = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  /* Color-convert and emit rows */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  /* How many we have in the buffer: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
  /* Not more than the distance to the end of the image.  Need this test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
   * in case the image height is not a multiple of max_v_samp_factor:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  if (num_rows > upsample->rows_to_go)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    num_rows = upsample->rows_to_go;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  /* And not more than what the client can accept: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
  out_rows_avail -= *out_row_ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
  if (num_rows > out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    num_rows = out_rows_avail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                     (JDIMENSION) upsample->next_row_out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                     output_buf + *out_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                     (int) num_rows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  /* Adjust counts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
  *out_row_ctr += num_rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
  upsample->rows_to_go -= num_rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
  upsample->next_row_out += num_rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
  /* When the buffer is emptied, declare this input row group consumed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    (*in_row_group_ctr)++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * These are the routines invoked by sep_upsample to upsample pixel values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * of a single component.  One row group is processed per call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * For full-size components, we just make color_buf[ci] point at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * input buffer, and thus avoid copying any data.  Note that this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * safe only because sep_upsample doesn't declare the input row group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * "consumed" until we are done color converting and emitting it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                   JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  *output_data_ptr = input_data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * This is a no-op version used for "uninteresting" components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * These components will not be referenced by color conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
               JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
  *output_data_ptr = NULL;      /* safety check */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * This version handles any integral sampling ratios.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * This is not used for typical JPEG files, so it need not be fast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * Nor, for that matter, is it particularly accurate: the algorithm is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * simple replication of the input pixel onto the corresponding output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * pixels.  The hi-falutin sampling literature refers to this as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * "box filter".  A box filter tends to introduce visible artifacts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * so if you are actually going to use 3:1 or 4:1 sampling ratios
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * you would be well advised to improve this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
              JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
  JSAMPARRAY output_data = *output_data_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  register JSAMPROW inptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
  register JSAMPLE invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
  register int h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
  JSAMPROW outend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
  int h_expand, v_expand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
  int inrow, outrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
  h_expand = upsample->h_expand[compptr->component_index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  v_expand = upsample->v_expand[compptr->component_index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
  inrow = outrow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  while (outrow < cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /* Generate one output row with proper horizontal expansion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    inptr = input_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    outptr = output_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    outend = outptr + cinfo->output_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    while (outptr < outend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      invalue = *inptr++;       /* don't need GETJSAMPLE() here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      for (h = h_expand; h > 0; h--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        *outptr++ = invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /* Generate any additional output rows by duplicating the first one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    if (v_expand > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                        v_expand-1, cinfo->output_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    inrow++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    outrow += v_expand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * It's still a box filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
               JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  JSAMPARRAY output_data = *output_data_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
  register JSAMPROW inptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  register JSAMPLE invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  JSAMPROW outend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
  int inrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    inptr = input_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    outptr = output_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    outend = outptr + cinfo->output_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    while (outptr < outend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      invalue = *inptr++;       /* don't need GETJSAMPLE() here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      *outptr++ = invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      *outptr++ = invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 * It's still a box filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
               JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
  JSAMPARRAY output_data = *output_data_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
  register JSAMPROW inptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
  register JSAMPLE invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
  JSAMPROW outend;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
  int inrow, outrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
  inrow = outrow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
  while (outrow < cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    inptr = input_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    outptr = output_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    outend = outptr + cinfo->output_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    while (outptr < outend) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      invalue = *inptr++;       /* don't need GETJSAMPLE() here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      *outptr++ = invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
      *outptr++ = invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                      1, cinfo->output_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    inrow++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    outrow += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * The upsampling algorithm is linear interpolation between pixel centers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * also known as a "triangle filter".  This is a good compromise between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * speed and visual quality.  The centers of the output pixels are 1/4 and 3/4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * of the way between input pixel centers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * A note about the "bias" calculations: when rounding fractional values to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * integer, we do not want to always round 0.5 up to the next integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * If we did that, we'd introduce a noticeable bias towards larger values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * Instead, this code is arranged so that 0.5 will be rounded up or down at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 * alternate pixel locations (a simple ordered dither pattern).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                     JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
  JSAMPARRAY output_data = *output_data_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
  register JSAMPROW inptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
  register int invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
  register JDIMENSION colctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
  int inrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    inptr = input_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    outptr = output_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /* Special case for first column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    invalue = GETJSAMPLE(*inptr++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    *outptr++ = (JSAMPLE) invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
      invalue = GETJSAMPLE(*inptr++) * 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
      *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
      *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /* Special case for last column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    invalue = GETJSAMPLE(*inptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    *outptr++ = (JSAMPLE) invalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
 * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
 * Again a triangle filter; see comments for h2v1 case, above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
 * It is OK for us to reference the adjacent input rows because we demanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 * context from the main buffer controller (see initialization code).
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
h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                     JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
  JSAMPARRAY output_data = *output_data_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
  register JSAMPROW inptr0, inptr1, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
#if BITS_IN_JSAMPLE == 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
  register int thiscolsum, lastcolsum, nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
  register INT32 thiscolsum, lastcolsum, nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
  register JDIMENSION colctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
  int inrow, outrow, v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
  inrow = outrow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
  while (outrow < cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    for (v = 0; v < 2; v++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
      inptr0 = input_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
      if (v == 0)               /* next nearest is row above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        inptr1 = input_data[inrow-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
      else                      /* next nearest is row below */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        inptr1 = input_data[inrow+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
      outptr = output_data[outrow++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
      /* Special case for first column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
      thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
      nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
      *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
      *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
      lastcolsum = thiscolsum; thiscolsum = nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        lastcolsum = thiscolsum; thiscolsum = nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
      /* Special case for last column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
      *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
      *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    inrow++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
 * Module initialization routine for upsampling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
jinit_upsampler (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
  my_upsample_ptr upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
  int ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
  jpeg_component_info * compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
  boolean need_buffer, do_fancy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
  int h_in_group, v_in_group, h_out_group, v_out_group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
  upsample = (my_upsample_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                SIZEOF(my_upsampler));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
  cinfo->upsample = (struct jpeg_upsampler *) upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
  upsample->pub.start_pass = start_pass_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
  upsample->pub.upsample = sep_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
  upsample->pub.need_context_rows = FALSE; /* until we find out differently */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
   * so don't ask for it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
  do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
  /* Verify we can handle the sampling factors, select per-component methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
   * and create storage as needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /* Compute size of an "input group" after IDCT scaling.  This many samples
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                 cinfo->min_DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                 cinfo->min_DCT_scaled_size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    h_out_group = cinfo->max_h_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    v_out_group = cinfo->max_v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    need_buffer = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    if (! compptr->component_needed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
      /* Don't bother to upsample an uninteresting component. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
      upsample->methods[ci] = noop_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      need_buffer = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      /* Fullsize components can be processed without any work. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      upsample->methods[ci] = fullsize_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
      need_buffer = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    } else if (h_in_group * 2 == h_out_group &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
               v_in_group == v_out_group) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
      /* Special cases for 2h1v upsampling */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
      if (do_fancy && compptr->downsampled_width > 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        upsample->methods[ci] = h2v1_fancy_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        upsample->methods[ci] = h2v1_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    } else if (h_in_group * 2 == h_out_group &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
               v_in_group * 2 == v_out_group) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
      /* Special cases for 2h2v upsampling */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
      if (do_fancy && compptr->downsampled_width > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        upsample->methods[ci] = h2v2_fancy_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        upsample->pub.need_context_rows = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
      } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        upsample->methods[ci] = h2v2_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    } else if ((h_out_group % h_in_group) == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
               (v_out_group % v_in_group) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
      /* Generic integral-factors upsampling method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
      upsample->methods[ci] = int_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    if (need_buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
      upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         (JDIMENSION) jround_up((long) cinfo->output_width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                                (long) cinfo->max_h_samp_factor),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         (JDIMENSION) cinfo->max_v_samp_factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
}