src/java.desktop/share/native/libjavajpeg/jcsample.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
 * jcsample.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 downsampling routines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * Downsampling input data is counted in "row groups".  A row group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * is defined to be max_v_samp_factor pixel rows of each component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * from which the downsampler produces v_samp_factor sample rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * A single row group is processed in each call to the downsampler module.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * The downsampler is responsible for edge-expansion of its output data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * to fill an integral number of DCT blocks horizontally.  The source buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * may be modified if it is helpful for this purpose (the source buffer is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * allocated wide enough to correspond to the desired output width).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * The caller (the prep controller) is responsible for vertical padding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * The downsampler may request "context rows" by setting need_context_rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * during startup.  In this case, the input arrays will contain at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * one row group's worth of pixels above and below the passed-in data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * the caller will create dummy rows at image top and bottom by replicating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * the first or last real pixel row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * An excellent reference for image resampling is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *   Digital Image Warping, George Wolberg, 1990.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * The downsampling algorithm used here is a simple average of the source
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * pixels covered by the output pixel.  The hi-falutin sampling literature
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * refers to this as a "box filter".  In general the characteristics of a box
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * filter are not very good, but for the specific cases we normally use (1:1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * nearly so bad.  If you intend to use other sampling ratios, you'd be well
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * advised to improve this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A simple input-smoothing capability is provided.  This is mainly intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * for cleaning up color-dithered GIF input files (if you find it inadequate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * we suggest using an external filtering program such as pnmconvol).  When
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * enabled, each input pixel P is replaced by a weighted sum of itself and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * eight neighbors.  P's weight is 1-8*SF and each neighbor's weight is SF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * where SF = (smoothing_factor / 1024).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Currently, smoothing is only supported for 2h2v sampling factors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#define JPEG_INTERNALS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include "jinclude.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#include "jpeglib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/* Pointer to routine to downsample a single component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
typedef JMETHOD(void, downsample1_ptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                (j_compress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                 JSAMPARRAY input_data, JSAMPARRAY output_data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/* Private subobject */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  struct jpeg_downsampler pub;  /* public fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  /* Downsampling method pointers, one per component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  downsample1_ptr methods[MAX_COMPONENTS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
} my_downsampler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
typedef my_downsampler * my_downsample_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Initialize for a downsampling pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
start_pass_downsample (j_compress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  /* no work for now */
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Expand a component horizontally from width input_cols to width output_cols,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * by duplicating the rightmost samples.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
expand_right_edge (JSAMPARRAY image_data, int num_rows,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                   JDIMENSION input_cols, JDIMENSION output_cols)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  register JSAMPROW ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
  register JSAMPLE pixval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  register int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  int numcols = (int) (output_cols - input_cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  if (numcols > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    for (row = 0; row < num_rows; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      ptr = image_data[row] + input_cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
      pixval = ptr[-1];         /* don't need GETJSAMPLE() here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      for (count = numcols; count > 0; count--)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        *ptr++ = pixval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * Do downsampling for a whole row group (all components).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * In this version we simply downsample each component independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
sep_downsample (j_compress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                JSAMPIMAGE input_buf, JDIMENSION in_row_index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
  my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
  int ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  jpeg_component_info * compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
  JSAMPARRAY in_ptr, out_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    in_ptr = input_buf[ci] + in_row_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * Downsample pixel values of a single component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * One row group is processed per call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * This version handles arbitrary integral sampling ratios, without smoothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * Note that this version is not actually used for customary sampling ratios.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                JSAMPARRAY input_data, JSAMPARRAY output_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
  JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
  JSAMPROW inptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
  INT32 outvalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  numpix = h_expand * v_expand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  numpix2 = numpix/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  /* Expand input data enough to let all the output samples be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
   * by the standard loop.  Special-casing padded output would be more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
   * efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  expand_right_edge(input_data, cinfo->max_v_samp_factor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    cinfo->image_width, output_cols * h_expand);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  inrow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    outptr = output_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         outcol++, outcol_h += h_expand) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      outvalue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      for (v = 0; v < v_expand; v++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        inptr = input_data[inrow+v] + outcol_h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        for (h = 0; h < h_expand; h++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
          outvalue += (INT32) GETJSAMPLE(*inptr++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    inrow += v_expand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * Downsample pixel values of a single component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * This version handles the special case of a full-size component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * without smoothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                     JSAMPARRAY input_data, JSAMPARRAY output_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
  /* Copy the data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
  jcopy_sample_rows(input_data, 0, output_data, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    cinfo->max_v_samp_factor, cinfo->image_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
  /* Edge-expand */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  expand_right_edge(output_data, cinfo->max_v_samp_factor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * Downsample pixel values of a single component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * This version handles the common case of 2:1 horizontal and 1:1 vertical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * without smoothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * A note about the "bias" calculations: when rounding fractional values to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * integer, we do not want to always round 0.5 up to the next integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * If we did that, we'd introduce a noticeable bias towards larger values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * Instead, this code is arranged so that 0.5 will be rounded up or down at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * alternate pixel locations (a simple ordered dither pattern).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                 JSAMPARRAY input_data, JSAMPARRAY output_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  int outrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
  JDIMENSION outcol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  register JSAMPROW inptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  register int bias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
  /* Expand input data enough to let all the output samples be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
   * by the standard loop.  Special-casing padded output would be more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
   * efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
  expand_right_edge(input_data, cinfo->max_v_samp_factor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    cinfo->image_width, output_cols * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    outptr = output_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    inptr = input_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    bias = 0;                   /* bias = 0,1,0,1,... for successive samples */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    for (outcol = 0; outcol < output_cols; outcol++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                              + bias) >> 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      bias ^= 1;                /* 0=>1, 1=>0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
      inptr += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * Downsample pixel values of a single component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 * without smoothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                 JSAMPARRAY input_data, JSAMPARRAY output_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
  int inrow, outrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
  JDIMENSION outcol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
  JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
  register JSAMPROW inptr0, inptr1, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
  register int bias;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
  /* Expand input data enough to let all the output samples be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
   * by the standard loop.  Special-casing padded output would be more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
   * efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
  expand_right_edge(input_data, cinfo->max_v_samp_factor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    cinfo->image_width, output_cols * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
  inrow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    outptr = output_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    inptr0 = input_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    inptr1 = input_data[inrow+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    bias = 1;                   /* bias = 1,2,1,2,... for successive samples */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    for (outcol = 0; outcol < output_cols; outcol++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                              GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                              + bias) >> 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
      bias ^= 3;                /* 1=>2, 2=>1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
      inptr0 += 2; inptr1 += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    inrow += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
#ifdef INPUT_SMOOTHING_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * Downsample pixel values of a single component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * with smoothing.  One row of context is required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        JSAMPARRAY input_data, JSAMPARRAY output_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
  int inrow, outrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
  JDIMENSION colctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
  JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
  register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  INT32 membersum, neighsum, memberscale, neighscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
  /* Expand input data enough to let all the output samples be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
   * by the standard loop.  Special-casing padded output would be more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
   * efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    cinfo->image_width, output_cols * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
  /* We don't bother to form the individual "smoothed" input pixel values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
   * we can directly compute the output which is the average of the four
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
   * smoothed values.  Each of the four member pixels contributes a fraction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
   * (1-8*SF) to its own smoothed image and a fraction SF to each of the three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
   * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
   * output.  The four corner-adjacent neighbor pixels contribute a fraction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
   * SF to just one smoothed pixel, or SF/4 to the final output; while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
   * eight edge-adjacent neighbors contribute SF to each of two smoothed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
   * pixels, or SF/2 overall.  In order to use integer arithmetic, these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
   * factors are scaled by 2^16 = 65536.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
   * Also recall that SF = smoothing_factor / 1024.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
  memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
  neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
  inrow = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    outptr = output_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    inptr0 = input_data[inrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    inptr1 = input_data[inrow+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    above_ptr = input_data[inrow-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    below_ptr = input_data[inrow+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /* Special case for first column: pretend column -1 is same as column 0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
               GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
               GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
               GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    neighsum += neighsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    membersum = membersum * memberscale + neighsum * neighscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      /* sum of pixels directly mapped to this output element */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                  GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
      /* sum of edge-neighbor pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
      neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                 GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                 GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                 GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
      /* The edge-neighbors count twice as much as corner-neighbors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
      neighsum += neighsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
      /* Add in the corner-neighbors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
      neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                  GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
      /* form final output scaled up by 2^16 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
      membersum = membersum * memberscale + neighsum * neighscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
      /* round, descale and output it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
      *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
      inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /* Special case for last column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
               GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
               GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
               GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    neighsum += neighsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    membersum = membersum * memberscale + neighsum * neighscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    inrow += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
 * Downsample pixel values of a single component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
 * This version handles the special case of a full-size component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
 * with smoothing.  One row of context is required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                            JSAMPARRAY input_data, JSAMPARRAY output_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
  int outrow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
  JDIMENSION colctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
  JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
  register JSAMPROW inptr, above_ptr, below_ptr, outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
  INT32 membersum, neighsum, memberscale, neighscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
  int colsum, lastcolsum, nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
  /* Expand input data enough to let all the output samples be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
   * by the standard loop.  Special-casing padded output would be more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
   * efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    cinfo->image_width, output_cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
  /* Each of the eight neighbor pixels contributes a fraction SF to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
   * smoothed pixel, while the main pixel contributes (1-8*SF).  In order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
   * to use integer arithmetic, these factors are multiplied by 2^16 = 65536.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
   * Also recall that SF = smoothing_factor / 1024.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    outptr = output_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    inptr = input_data[outrow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    above_ptr = input_data[outrow-1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    below_ptr = input_data[outrow+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /* Special case for first column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
             GETJSAMPLE(*inptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    membersum = GETJSAMPLE(*inptr++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                 GETJSAMPLE(*inptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    neighsum = colsum + (colsum - membersum) + nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    membersum = membersum * memberscale + neighsum * neighscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    lastcolsum = colsum; colsum = nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
      membersum = GETJSAMPLE(*inptr++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
      above_ptr++; below_ptr++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
      nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                   GETJSAMPLE(*inptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
      membersum = membersum * memberscale + neighsum * neighscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
      lastcolsum = colsum; colsum = nextcolsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /* Special case for last column */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    membersum = GETJSAMPLE(*inptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    neighsum = lastcolsum + (colsum - membersum) + colsum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    membersum = membersum * memberscale + neighsum * neighscale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
#endif /* INPUT_SMOOTHING_SUPPORTED */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
 * Module initialization routine for downsampling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
 * Note that we must select a routine for each component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
jinit_downsampler (j_compress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
  my_downsample_ptr downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
  int ci;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
  jpeg_component_info * compptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
  boolean smoothok = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
  downsample = (my_downsample_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                SIZEOF(my_downsampler));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
  cinfo->downsample = (struct jpeg_downsampler *) downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
  downsample->pub.start_pass = start_pass_downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
  downsample->pub.downsample = sep_downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
  downsample->pub.need_context_rows = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
  if (cinfo->CCIR601_sampling)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
  /* Verify we can handle the sampling factors, and set up method pointers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
       ci++, compptr++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
#ifdef INPUT_SMOOTHING_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
      if (cinfo->smoothing_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        downsample->methods[ci] = fullsize_smooth_downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        downsample->pub.need_context_rows = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
      } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        downsample->methods[ci] = fullsize_downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
      smoothok = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
      downsample->methods[ci] = h2v1_downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
#ifdef INPUT_SMOOTHING_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
      if (cinfo->smoothing_factor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        downsample->methods[ci] = h2v2_smooth_downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        downsample->pub.need_context_rows = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
      } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        downsample->methods[ci] = h2v2_downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      smoothok = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      downsample->methods[ci] = int_downsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
#ifdef INPUT_SMOOTHING_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
  if (cinfo->smoothing_factor && !smoothok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
}