src/java.desktop/share/native/libjavajpeg/jdmerge.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
 * jdmerge.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * Copyright (C) 1994-1996, Thomas G. Lane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This file is part of the Independent JPEG Group's software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * For conditions of distribution and use, see the accompanying README file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * This file contains code for merged upsampling/color conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * This file combines functions from jdsample.c and jdcolor.c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * read those files first to understand what's going on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * When the chroma components are to be upsampled by simple replication
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * (ie, box filtering), we can save some work in color conversion by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * calculating all the output pixels corresponding to a pair of chroma
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * samples at one time.  In the conversion equations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *      R = Y           + K1 * Cr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 *      G = Y + K2 * Cb + K3 * Cr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 *      B = Y + K4 * Cb
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * only the Y term varies among the group of pixels corresponding to a pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * of chroma samples, so the rest of the terms can be calculated just once.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * At typical sampling ratios, this eliminates half or three-quarters of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * multiplications needed for color conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * This file currently provides implementations for the following cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *      YCbCr => RGB color conversion only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *      Sampling ratios of 2h1v or 2h2v.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *      No scaling needed at upsample time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *      Corner-aligned (non-CCIR601) sampling alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Other special cases could be added, but in most applications these are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * the only common cases.  (For uncommon cases we fall back on the more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * general code in jdsample.c and jdcolor.c.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#define JPEG_INTERNALS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "jinclude.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include "jpeglib.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#ifdef UPSAMPLE_MERGING_SUPPORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/* Private subobject */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
typedef struct {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  struct jpeg_upsampler pub;    /* public fields */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  /* Pointer to routine to do actual upsampling/conversion of one row group */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                           JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                           JSAMPARRAY output_buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  /* Private state for YCC->RGB conversion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  int * Cr_r_tab;               /* => table for Cr to R conversion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  int * Cb_b_tab;               /* => table for Cb to B conversion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  INT32 * Cr_g_tab;             /* => table for Cr to G conversion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  INT32 * Cb_g_tab;             /* => table for Cb to G conversion */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  /* For 2:1 vertical sampling, we produce two output rows at a time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
   * We need a "spare" row buffer to hold the second output row if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   * application provides just a one-row buffer; we also use the spare
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
   * to discard the dummy last row if the image height is odd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  JSAMPROW spare_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  boolean spare_full;           /* T if spare buffer is occupied */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  JDIMENSION out_row_width;     /* samples per output row */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  JDIMENSION rows_to_go;        /* counts rows remaining in image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
} my_upsampler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
typedef my_upsampler * my_upsample_ptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#define SCALEBITS       16      /* speediest right-shift on some machines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#define ONE_HALF        ((INT32) 1 << (SCALEBITS-1))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#define FIX(x)          ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Initialize tables for YCC->RGB colorspace conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * This is taken directly from jdcolor.c; see that file for more info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
LOCAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
build_ycc_rgb_table (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  INT32 x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
  SHIFT_TEMPS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  upsample->Cr_r_tab = (int *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                (MAXJSAMPLE+1) * SIZEOF(int));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  upsample->Cb_b_tab = (int *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                (MAXJSAMPLE+1) * SIZEOF(int));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  upsample->Cr_g_tab = (INT32 *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                (MAXJSAMPLE+1) * SIZEOF(INT32));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
  upsample->Cb_g_tab = (INT32 *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                (MAXJSAMPLE+1) * SIZEOF(INT32));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /* Cr=>R value is nearest int to 1.40200 * x */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    upsample->Cr_r_tab[i] = (int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /* Cb=>B value is nearest int to 1.77200 * x */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    upsample->Cb_b_tab[i] = (int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /* Cr=>G value is scaled-up -0.71414 * x */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /* Cb=>G value is scaled-up -0.34414 * x */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /* We also add in ONE_HALF so that need not do it in inner loop */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * Initialize for an upsampling pass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
start_pass_merged_upsample (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
  /* Mark the spare buffer empty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  upsample->spare_full = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  /* Initialize total-height counter for detecting bottom of image */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
  upsample->rows_to_go = cinfo->output_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * Control routine to do upsampling (and color conversion).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * The control routine just handles the row buffering considerations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
merged_2v_upsample (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    JDIMENSION in_row_groups_avail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    JDIMENSION out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
/* 2:1 vertical sampling case: may need a spare row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  JSAMPROW work_ptrs[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
  JDIMENSION num_rows;          /* number of rows returned to caller */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  if (upsample->spare_full) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /* If we have a spare row saved from a previous cycle, just return it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                      1, upsample->out_row_width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    num_rows = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    upsample->spare_full = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /* Figure number of rows to return to caller. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    num_rows = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /* Not more than the distance to the end of the image. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    if (num_rows > upsample->rows_to_go)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      num_rows = upsample->rows_to_go;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /* And not more than what the client can accept: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    out_rows_avail -= *out_row_ctr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    if (num_rows > out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      num_rows = out_rows_avail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /* Create output pointer array for upsampler. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    work_ptrs[0] = output_buf[*out_row_ctr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    if (num_rows > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      work_ptrs[1] = output_buf[*out_row_ctr + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
      work_ptrs[1] = upsample->spare_row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
      upsample->spare_full = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /* Now do the upsampling. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
  /* Adjust counts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
  *out_row_ctr += num_rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
  upsample->rows_to_go -= num_rows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
  /* When the buffer is emptied, declare this input row group consumed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
  if (! upsample->spare_full)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    (*in_row_group_ctr)++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
merged_1v_upsample (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    JDIMENSION in_row_groups_avail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    JDIMENSION out_rows_avail)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
/* 1:1 vertical sampling case: much easier, never need a spare row. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
  /* Just do the upsampling. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
  (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                         output_buf + *out_row_ctr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  /* Adjust counts */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
  (*out_row_ctr)++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  (*in_row_group_ctr)++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * These are the routines invoked by the control routines to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * the actual upsampling/conversion.  One row group is processed per call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * Note: since we may be writing directly into application-supplied buffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * we have to be honest about the output width; we can't assume the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * has been rounded up to an even width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
h2v1_merged_upsample (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                      JSAMPARRAY output_buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
  register int y, cred, cgreen, cblue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
  int cb, cr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
  register JSAMPROW outptr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
  JSAMPROW inptr0, inptr1, inptr2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
  JDIMENSION col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
  /* copy these pointers into registers if possible */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
  int * Crrtab = upsample->Cr_r_tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
  int * Cbbtab = upsample->Cb_b_tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
  INT32 * Crgtab = upsample->Cr_g_tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
  INT32 * Cbgtab = upsample->Cb_g_tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
  SHIFT_TEMPS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
  inptr0 = input_buf[0][in_row_group_ctr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
  inptr1 = input_buf[1][in_row_group_ctr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
  inptr2 = input_buf[2][in_row_group_ctr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
  outptr = output_buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
  /* Loop for each pair of output pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
  for (col = cinfo->output_width >> 1; col > 0; col--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /* Do the chroma part of the calculation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    cb = GETJSAMPLE(*inptr1++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    cr = GETJSAMPLE(*inptr2++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    cred = Crrtab[cr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    cblue = Cbbtab[cb];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /* Fetch 2 Y values and emit 2 pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    y  = GETJSAMPLE(*inptr0++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    outptr[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    outptr[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    outptr[RGB_BLUE] =  range_limit[y + cblue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    outptr += RGB_PIXELSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    y  = GETJSAMPLE(*inptr0++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    outptr[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    outptr[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    outptr[RGB_BLUE] =  range_limit[y + cblue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    outptr += RGB_PIXELSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
  /* If image width is odd, do the last output column separately */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
  if (cinfo->output_width & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    cb = GETJSAMPLE(*inptr1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    cr = GETJSAMPLE(*inptr2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    cred = Crrtab[cr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    cblue = Cbbtab[cb];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    y  = GETJSAMPLE(*inptr0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    outptr[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    outptr[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    outptr[RGB_BLUE] =  range_limit[y + cblue];
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
METHODDEF(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
h2v2_merged_upsample (j_decompress_ptr cinfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                      JSAMPARRAY output_buf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
  register int y, cred, cgreen, cblue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
  int cb, cr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
  register JSAMPROW outptr0, outptr1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
  JSAMPROW inptr00, inptr01, inptr1, inptr2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
  JDIMENSION col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
  /* copy these pointers into registers if possible */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
  register JSAMPLE * range_limit = cinfo->sample_range_limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
  int * Crrtab = upsample->Cr_r_tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
  int * Cbbtab = upsample->Cb_b_tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
  INT32 * Crgtab = upsample->Cr_g_tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
  INT32 * Cbgtab = upsample->Cb_g_tab;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
  SHIFT_TEMPS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
  inptr00 = input_buf[0][in_row_group_ctr*2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
  inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
  inptr1 = input_buf[1][in_row_group_ctr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
  inptr2 = input_buf[2][in_row_group_ctr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
  outptr0 = output_buf[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
  outptr1 = output_buf[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
  /* Loop for each group of output pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
  for (col = cinfo->output_width >> 1; col > 0; col--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /* Do the chroma part of the calculation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    cb = GETJSAMPLE(*inptr1++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    cr = GETJSAMPLE(*inptr2++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    cred = Crrtab[cr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    cblue = Cbbtab[cb];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /* Fetch 4 Y values and emit 4 pixels */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    y  = GETJSAMPLE(*inptr00++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    outptr0[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    outptr0 += RGB_PIXELSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    y  = GETJSAMPLE(*inptr00++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    outptr0[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    outptr0 += RGB_PIXELSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    y  = GETJSAMPLE(*inptr01++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    outptr1[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    outptr1 += RGB_PIXELSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    y  = GETJSAMPLE(*inptr01++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    outptr1[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    outptr1 += RGB_PIXELSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
  /* If image width is odd, do the last output column separately */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
  if (cinfo->output_width & 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    cb = GETJSAMPLE(*inptr1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    cr = GETJSAMPLE(*inptr2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    cred = Crrtab[cr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    cblue = Cbbtab[cb];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    y  = GETJSAMPLE(*inptr00);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    outptr0[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    outptr0[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    outptr0[RGB_BLUE] =  range_limit[y + cblue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    y  = GETJSAMPLE(*inptr01);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    outptr1[RGB_RED] =   range_limit[y + cred];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    outptr1[RGB_GREEN] = range_limit[y + cgreen];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    outptr1[RGB_BLUE] =  range_limit[y + cblue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
 * Module initialization routine for merged upsampling/color conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
 * NB: this is called under the conditions determined by use_merged_upsample()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
 * in jdmaster.c.  That routine MUST correspond to the actual capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
 * of this module; no safety checks are made here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
GLOBAL(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
jinit_merged_upsampler (j_decompress_ptr cinfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
  my_upsample_ptr upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
  upsample = (my_upsample_ptr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                                SIZEOF(my_upsampler));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
  cinfo->upsample = (struct jpeg_upsampler *) upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
  upsample->pub.start_pass = start_pass_merged_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
  upsample->pub.need_context_rows = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
  upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
  if (cinfo->max_v_samp_factor == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    upsample->pub.upsample = merged_2v_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    upsample->upmethod = h2v2_merged_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /* Allocate a spare row buffer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    upsample->spare_row = (JSAMPROW)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    upsample->pub.upsample = merged_1v_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    upsample->upmethod = h2v1_merged_upsample;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /* No spare row needed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    upsample->spare_row = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
  build_ycc_rgb_table(cinfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
#endif /* UPSAMPLE_MERGING_SUPPORTED */