mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
f21bd429e5
--HG-- rename : jpeg/MOZCHANGES => media/libjpeg/MOZCHANGES rename : jpeg/Makefile.in => media/libjpeg/Makefile.in rename : jpeg/README => media/libjpeg/README rename : jpeg/README-turbo.txt => media/libjpeg/README-turbo.txt rename : jpeg/cderror.h => media/libjpeg/cderror.h rename : jpeg/cdjpeg.h => media/libjpeg/cdjpeg.h rename : jpeg/jaricom.c => media/libjpeg/jaricom.c rename : jpeg/jcapimin.c => media/libjpeg/jcapimin.c rename : jpeg/jcapistd.c => media/libjpeg/jcapistd.c rename : jpeg/jcarith.c => media/libjpeg/jcarith.c rename : jpeg/jccoefct.c => media/libjpeg/jccoefct.c rename : jpeg/jccolor.c => media/libjpeg/jccolor.c rename : jpeg/jcdctmgr.c => media/libjpeg/jcdctmgr.c rename : jpeg/jchuff.c => media/libjpeg/jchuff.c rename : jpeg/jchuff.h => media/libjpeg/jchuff.h rename : jpeg/jcinit.c => media/libjpeg/jcinit.c rename : jpeg/jcmainct.c => media/libjpeg/jcmainct.c rename : jpeg/jcmarker.c => media/libjpeg/jcmarker.c rename : jpeg/jcmaster.c => media/libjpeg/jcmaster.c rename : jpeg/jcomapi.c => media/libjpeg/jcomapi.c rename : jpeg/jconfig.h => media/libjpeg/jconfig.h rename : jpeg/jconfig.h.in => media/libjpeg/jconfig.h.in rename : jpeg/jcparam.c => media/libjpeg/jcparam.c rename : jpeg/jcphuff.c => media/libjpeg/jcphuff.c rename : jpeg/jcprepct.c => media/libjpeg/jcprepct.c rename : jpeg/jcsample.c => media/libjpeg/jcsample.c rename : jpeg/jdapimin.c => media/libjpeg/jdapimin.c rename : jpeg/jdapistd.c => media/libjpeg/jdapistd.c rename : jpeg/jdarith.c => media/libjpeg/jdarith.c rename : jpeg/jdatadst.c => media/libjpeg/jdatadst.c rename : jpeg/jdatasrc.c => media/libjpeg/jdatasrc.c rename : jpeg/jdcoefct.c => media/libjpeg/jdcoefct.c rename : jpeg/jdcolor.c => media/libjpeg/jdcolor.c rename : jpeg/jdct.h => media/libjpeg/jdct.h rename : jpeg/jddctmgr.c => media/libjpeg/jddctmgr.c rename : jpeg/jdhuff.c => media/libjpeg/jdhuff.c rename : jpeg/jdhuff.h => media/libjpeg/jdhuff.h rename : jpeg/jdinput.c => media/libjpeg/jdinput.c rename : jpeg/jdmainct.c => media/libjpeg/jdmainct.c rename : jpeg/jdmarker.c => media/libjpeg/jdmarker.c rename : jpeg/jdmaster.c => media/libjpeg/jdmaster.c rename : jpeg/jdmerge.c => media/libjpeg/jdmerge.c rename : jpeg/jdphuff.c => media/libjpeg/jdphuff.c rename : jpeg/jdpostct.c => media/libjpeg/jdpostct.c rename : jpeg/jdsample.c => media/libjpeg/jdsample.c rename : jpeg/jdtrans.c => media/libjpeg/jdtrans.c rename : jpeg/jerror.c => media/libjpeg/jerror.c rename : jpeg/jerror.h => media/libjpeg/jerror.h rename : jpeg/jfdctflt.c => media/libjpeg/jfdctflt.c rename : jpeg/jfdctfst.c => media/libjpeg/jfdctfst.c rename : jpeg/jfdctint.c => media/libjpeg/jfdctint.c rename : jpeg/jidctflt.c => media/libjpeg/jidctflt.c rename : jpeg/jidctfst.c => media/libjpeg/jidctfst.c rename : jpeg/jidctint.c => media/libjpeg/jidctint.c rename : jpeg/jidctred.c => media/libjpeg/jidctred.c rename : jpeg/jinclude.h => media/libjpeg/jinclude.h rename : jpeg/jmemmgr.c => media/libjpeg/jmemmgr.c rename : jpeg/jmemnobs.c => media/libjpeg/jmemnobs.c rename : jpeg/jmemsys.h => media/libjpeg/jmemsys.h rename : jpeg/jmorecfg.h => media/libjpeg/jmorecfg.h rename : jpeg/jpegcomp.h => media/libjpeg/jpegcomp.h rename : jpeg/jpegint.h => media/libjpeg/jpegint.h rename : jpeg/jpeglib.h => media/libjpeg/jpeglib.h rename : jpeg/jquant1.c => media/libjpeg/jquant1.c rename : jpeg/jquant2.c => media/libjpeg/jquant2.c rename : jpeg/jsimd.h => media/libjpeg/jsimd.h rename : jpeg/jsimd_none.c => media/libjpeg/jsimd_none.c rename : jpeg/jsimddct.h => media/libjpeg/jsimddct.h rename : jpeg/jutils.c => media/libjpeg/jutils.c rename : jpeg/jversion.h => media/libjpeg/jversion.h rename : jpeg/simd/Makefile.in => media/libjpeg/simd/Makefile.in rename : jpeg/simd/jcclrmmx.asm => media/libjpeg/simd/jcclrmmx.asm rename : jpeg/simd/jcclrss2-64.asm => media/libjpeg/simd/jcclrss2-64.asm rename : jpeg/simd/jcclrss2.asm => media/libjpeg/simd/jcclrss2.asm rename : jpeg/simd/jccolmmx.asm => media/libjpeg/simd/jccolmmx.asm rename : jpeg/simd/jccolss2-64.asm => media/libjpeg/simd/jccolss2-64.asm rename : jpeg/simd/jccolss2.asm => media/libjpeg/simd/jccolss2.asm rename : jpeg/simd/jcolsamp.inc => media/libjpeg/simd/jcolsamp.inc rename : jpeg/simd/jcqnt3dn.asm => media/libjpeg/simd/jcqnt3dn.asm rename : jpeg/simd/jcqntmmx.asm => media/libjpeg/simd/jcqntmmx.asm rename : jpeg/simd/jcqnts2f-64.asm => media/libjpeg/simd/jcqnts2f-64.asm rename : jpeg/simd/jcqnts2f.asm => media/libjpeg/simd/jcqnts2f.asm rename : jpeg/simd/jcqnts2i-64.asm => media/libjpeg/simd/jcqnts2i-64.asm rename : jpeg/simd/jcqnts2i.asm => media/libjpeg/simd/jcqnts2i.asm rename : jpeg/simd/jcqntsse.asm => media/libjpeg/simd/jcqntsse.asm rename : jpeg/simd/jcsammmx.asm => media/libjpeg/simd/jcsammmx.asm rename : jpeg/simd/jcsamss2-64.asm => media/libjpeg/simd/jcsamss2-64.asm rename : jpeg/simd/jcsamss2.asm => media/libjpeg/simd/jcsamss2.asm rename : jpeg/simd/jdclrmmx.asm => media/libjpeg/simd/jdclrmmx.asm rename : jpeg/simd/jdclrss2-64.asm => media/libjpeg/simd/jdclrss2-64.asm rename : jpeg/simd/jdclrss2.asm => media/libjpeg/simd/jdclrss2.asm rename : jpeg/simd/jdcolmmx.asm => media/libjpeg/simd/jdcolmmx.asm rename : jpeg/simd/jdcolss2-64.asm => media/libjpeg/simd/jdcolss2-64.asm rename : jpeg/simd/jdcolss2.asm => media/libjpeg/simd/jdcolss2.asm rename : jpeg/simd/jdct.inc => media/libjpeg/simd/jdct.inc rename : jpeg/simd/jdmermmx.asm => media/libjpeg/simd/jdmermmx.asm rename : jpeg/simd/jdmerss2-64.asm => media/libjpeg/simd/jdmerss2-64.asm rename : jpeg/simd/jdmerss2.asm => media/libjpeg/simd/jdmerss2.asm rename : jpeg/simd/jdmrgmmx.asm => media/libjpeg/simd/jdmrgmmx.asm rename : jpeg/simd/jdmrgss2-64.asm => media/libjpeg/simd/jdmrgss2-64.asm rename : jpeg/simd/jdmrgss2.asm => media/libjpeg/simd/jdmrgss2.asm rename : jpeg/simd/jdsammmx.asm => media/libjpeg/simd/jdsammmx.asm rename : jpeg/simd/jdsamss2-64.asm => media/libjpeg/simd/jdsamss2-64.asm rename : jpeg/simd/jdsamss2.asm => media/libjpeg/simd/jdsamss2.asm rename : jpeg/simd/jf3dnflt.asm => media/libjpeg/simd/jf3dnflt.asm rename : jpeg/simd/jfmmxfst.asm => media/libjpeg/simd/jfmmxfst.asm rename : jpeg/simd/jfmmxint.asm => media/libjpeg/simd/jfmmxint.asm rename : jpeg/simd/jfss2fst-64.asm => media/libjpeg/simd/jfss2fst-64.asm rename : jpeg/simd/jfss2fst.asm => media/libjpeg/simd/jfss2fst.asm rename : jpeg/simd/jfss2int-64.asm => media/libjpeg/simd/jfss2int-64.asm rename : jpeg/simd/jfss2int.asm => media/libjpeg/simd/jfss2int.asm rename : jpeg/simd/jfsseflt-64.asm => media/libjpeg/simd/jfsseflt-64.asm rename : jpeg/simd/jfsseflt.asm => media/libjpeg/simd/jfsseflt.asm rename : jpeg/simd/ji3dnflt.asm => media/libjpeg/simd/ji3dnflt.asm rename : jpeg/simd/jimmxfst.asm => media/libjpeg/simd/jimmxfst.asm rename : jpeg/simd/jimmxint.asm => media/libjpeg/simd/jimmxint.asm rename : jpeg/simd/jimmxred.asm => media/libjpeg/simd/jimmxred.asm rename : jpeg/simd/jiss2flt-64.asm => media/libjpeg/simd/jiss2flt-64.asm rename : jpeg/simd/jiss2flt.asm => media/libjpeg/simd/jiss2flt.asm rename : jpeg/simd/jiss2fst-64.asm => media/libjpeg/simd/jiss2fst-64.asm rename : jpeg/simd/jiss2fst.asm => media/libjpeg/simd/jiss2fst.asm rename : jpeg/simd/jiss2int-64.asm => media/libjpeg/simd/jiss2int-64.asm rename : jpeg/simd/jiss2int.asm => media/libjpeg/simd/jiss2int.asm rename : jpeg/simd/jiss2red-64.asm => media/libjpeg/simd/jiss2red-64.asm rename : jpeg/simd/jiss2red.asm => media/libjpeg/simd/jiss2red.asm rename : jpeg/simd/jisseflt.asm => media/libjpeg/simd/jisseflt.asm rename : jpeg/simd/jsimd.h => media/libjpeg/simd/jsimd.h rename : jpeg/simd/jsimd_i386.c => media/libjpeg/simd/jsimd_i386.c rename : jpeg/simd/jsimd_x86_64.c => media/libjpeg/simd/jsimd_x86_64.c rename : jpeg/simd/jsimdcfg.inc => media/libjpeg/simd/jsimdcfg.inc rename : jpeg/simd/jsimdcfg.inc.h => media/libjpeg/simd/jsimdcfg.inc.h rename : jpeg/simd/jsimdcpu.asm => media/libjpeg/simd/jsimdcpu.asm rename : jpeg/simd/jsimdext.inc => media/libjpeg/simd/jsimdext.inc rename : jpeg/transupp.h => media/libjpeg/transupp.h
410 lines
15 KiB
C
410 lines
15 KiB
C
/*
|
|
* jdmerge.c
|
|
*
|
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
|
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
* Copyright (C) 2009, D. R. Commander.
|
|
* This file is part of the Independent JPEG Group's software.
|
|
* For conditions of distribution and use, see the accompanying README file.
|
|
*
|
|
* This file contains code for merged upsampling/color conversion.
|
|
*
|
|
* This file combines functions from jdsample.c and jdcolor.c;
|
|
* read those files first to understand what's going on.
|
|
*
|
|
* When the chroma components are to be upsampled by simple replication
|
|
* (ie, box filtering), we can save some work in color conversion by
|
|
* calculating all the output pixels corresponding to a pair of chroma
|
|
* samples at one time. In the conversion equations
|
|
* R = Y + K1 * Cr
|
|
* G = Y + K2 * Cb + K3 * Cr
|
|
* B = Y + K4 * Cb
|
|
* only the Y term varies among the group of pixels corresponding to a pair
|
|
* of chroma samples, so the rest of the terms can be calculated just once.
|
|
* At typical sampling ratios, this eliminates half or three-quarters of the
|
|
* multiplications needed for color conversion.
|
|
*
|
|
* This file currently provides implementations for the following cases:
|
|
* YCbCr => RGB color conversion only.
|
|
* Sampling ratios of 2h1v or 2h2v.
|
|
* No scaling needed at upsample time.
|
|
* Corner-aligned (non-CCIR601) sampling alignment.
|
|
* Other special cases could be added, but in most applications these are
|
|
* the only common cases. (For uncommon cases we fall back on the more
|
|
* general code in jdsample.c and jdcolor.c.)
|
|
*/
|
|
|
|
#define JPEG_INTERNALS
|
|
#include "jinclude.h"
|
|
#include "jpeglib.h"
|
|
#include "jsimd.h"
|
|
|
|
#ifdef UPSAMPLE_MERGING_SUPPORTED
|
|
|
|
|
|
/* Private subobject */
|
|
|
|
typedef struct {
|
|
struct jpeg_upsampler pub; /* public fields */
|
|
|
|
/* Pointer to routine to do actual upsampling/conversion of one row group */
|
|
JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
|
|
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
|
JSAMPARRAY output_buf));
|
|
|
|
/* Private state for YCC->RGB conversion */
|
|
int * Cr_r_tab; /* => table for Cr to R conversion */
|
|
int * Cb_b_tab; /* => table for Cb to B conversion */
|
|
INT32 * Cr_g_tab; /* => table for Cr to G conversion */
|
|
INT32 * Cb_g_tab; /* => table for Cb to G conversion */
|
|
|
|
/* For 2:1 vertical sampling, we produce two output rows at a time.
|
|
* We need a "spare" row buffer to hold the second output row if the
|
|
* application provides just a one-row buffer; we also use the spare
|
|
* to discard the dummy last row if the image height is odd.
|
|
*/
|
|
JSAMPROW spare_row;
|
|
boolean spare_full; /* T if spare buffer is occupied */
|
|
|
|
JDIMENSION out_row_width; /* samples per output row */
|
|
JDIMENSION rows_to_go; /* counts rows remaining in image */
|
|
} my_upsampler;
|
|
|
|
typedef my_upsampler * my_upsample_ptr;
|
|
|
|
#define SCALEBITS 16 /* speediest right-shift on some machines */
|
|
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
|
|
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
|
|
|
|
|
|
/*
|
|
* Initialize tables for YCC->RGB colorspace conversion.
|
|
* This is taken directly from jdcolor.c; see that file for more info.
|
|
*/
|
|
|
|
LOCAL(void)
|
|
build_ycc_rgb_table (j_decompress_ptr cinfo)
|
|
{
|
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
|
int i;
|
|
INT32 x;
|
|
SHIFT_TEMPS
|
|
|
|
upsample->Cr_r_tab = (int *)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
(MAXJSAMPLE+1) * SIZEOF(int));
|
|
upsample->Cb_b_tab = (int *)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
(MAXJSAMPLE+1) * SIZEOF(int));
|
|
upsample->Cr_g_tab = (INT32 *)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
|
upsample->Cb_g_tab = (INT32 *)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
(MAXJSAMPLE+1) * SIZEOF(INT32));
|
|
|
|
for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
|
|
/* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
|
|
/* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
|
|
/* Cr=>R value is nearest int to 1.40200 * x */
|
|
upsample->Cr_r_tab[i] = (int)
|
|
RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
|
|
/* Cb=>B value is nearest int to 1.77200 * x */
|
|
upsample->Cb_b_tab[i] = (int)
|
|
RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
|
|
/* Cr=>G value is scaled-up -0.71414 * x */
|
|
upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
|
|
/* Cb=>G value is scaled-up -0.34414 * x */
|
|
/* We also add in ONE_HALF so that need not do it in inner loop */
|
|
upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Initialize for an upsampling pass.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
start_pass_merged_upsample (j_decompress_ptr cinfo)
|
|
{
|
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
|
|
|
/* Mark the spare buffer empty */
|
|
upsample->spare_full = FALSE;
|
|
/* Initialize total-height counter for detecting bottom of image */
|
|
upsample->rows_to_go = cinfo->output_height;
|
|
}
|
|
|
|
|
|
/*
|
|
* Control routine to do upsampling (and color conversion).
|
|
*
|
|
* The control routine just handles the row buffering considerations.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
merged_2v_upsample (j_decompress_ptr cinfo,
|
|
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
|
JDIMENSION in_row_groups_avail,
|
|
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
|
JDIMENSION out_rows_avail)
|
|
/* 2:1 vertical sampling case: may need a spare row. */
|
|
{
|
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
|
JSAMPROW work_ptrs[2];
|
|
JDIMENSION num_rows; /* number of rows returned to caller */
|
|
|
|
if (upsample->spare_full) {
|
|
/* If we have a spare row saved from a previous cycle, just return it. */
|
|
jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
|
|
1, upsample->out_row_width);
|
|
num_rows = 1;
|
|
upsample->spare_full = FALSE;
|
|
} else {
|
|
/* Figure number of rows to return to caller. */
|
|
num_rows = 2;
|
|
/* Not more than the distance to the end of the image. */
|
|
if (num_rows > upsample->rows_to_go)
|
|
num_rows = upsample->rows_to_go;
|
|
/* And not more than what the client can accept: */
|
|
out_rows_avail -= *out_row_ctr;
|
|
if (num_rows > out_rows_avail)
|
|
num_rows = out_rows_avail;
|
|
/* Create output pointer array for upsampler. */
|
|
work_ptrs[0] = output_buf[*out_row_ctr];
|
|
if (num_rows > 1) {
|
|
work_ptrs[1] = output_buf[*out_row_ctr + 1];
|
|
} else {
|
|
work_ptrs[1] = upsample->spare_row;
|
|
upsample->spare_full = TRUE;
|
|
}
|
|
/* Now do the upsampling. */
|
|
(*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
|
|
}
|
|
|
|
/* Adjust counts */
|
|
*out_row_ctr += num_rows;
|
|
upsample->rows_to_go -= num_rows;
|
|
/* When the buffer is emptied, declare this input row group consumed */
|
|
if (! upsample->spare_full)
|
|
(*in_row_group_ctr)++;
|
|
}
|
|
|
|
|
|
METHODDEF(void)
|
|
merged_1v_upsample (j_decompress_ptr cinfo,
|
|
JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
|
|
JDIMENSION in_row_groups_avail,
|
|
JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
|
|
JDIMENSION out_rows_avail)
|
|
/* 1:1 vertical sampling case: much easier, never need a spare row. */
|
|
{
|
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
|
|
|
/* Just do the upsampling. */
|
|
(*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
|
|
output_buf + *out_row_ctr);
|
|
/* Adjust counts */
|
|
(*out_row_ctr)++;
|
|
(*in_row_group_ctr)++;
|
|
}
|
|
|
|
|
|
/*
|
|
* These are the routines invoked by the control routines to do
|
|
* the actual upsampling/conversion. One row group is processed per call.
|
|
*
|
|
* Note: since we may be writing directly into application-supplied buffers,
|
|
* we have to be honest about the output width; we can't assume the buffer
|
|
* has been rounded up to an even width.
|
|
*/
|
|
|
|
|
|
/*
|
|
* Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
h2v1_merged_upsample (j_decompress_ptr cinfo,
|
|
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
|
JSAMPARRAY output_buf)
|
|
{
|
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
|
register int y, cred, cgreen, cblue;
|
|
int cb, cr;
|
|
register JSAMPROW outptr;
|
|
JSAMPROW inptr0, inptr1, inptr2;
|
|
JDIMENSION col;
|
|
/* copy these pointers into registers if possible */
|
|
register JSAMPLE * range_limit = cinfo->sample_range_limit;
|
|
int * Crrtab = upsample->Cr_r_tab;
|
|
int * Cbbtab = upsample->Cb_b_tab;
|
|
INT32 * Crgtab = upsample->Cr_g_tab;
|
|
INT32 * Cbgtab = upsample->Cb_g_tab;
|
|
SHIFT_TEMPS
|
|
|
|
inptr0 = input_buf[0][in_row_group_ctr];
|
|
inptr1 = input_buf[1][in_row_group_ctr];
|
|
inptr2 = input_buf[2][in_row_group_ctr];
|
|
outptr = output_buf[0];
|
|
/* Loop for each pair of output pixels */
|
|
for (col = cinfo->output_width >> 1; col > 0; col--) {
|
|
/* Do the chroma part of the calculation */
|
|
cb = GETJSAMPLE(*inptr1++);
|
|
cr = GETJSAMPLE(*inptr2++);
|
|
cred = Crrtab[cr];
|
|
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
cblue = Cbbtab[cb];
|
|
/* Fetch 2 Y values and emit 2 pixels */
|
|
y = GETJSAMPLE(*inptr0++);
|
|
outptr[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
outptr += rgb_pixelsize[cinfo->out_color_space];
|
|
y = GETJSAMPLE(*inptr0++);
|
|
outptr[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
outptr += rgb_pixelsize[cinfo->out_color_space];
|
|
}
|
|
/* If image width is odd, do the last output column separately */
|
|
if (cinfo->output_width & 1) {
|
|
cb = GETJSAMPLE(*inptr1);
|
|
cr = GETJSAMPLE(*inptr2);
|
|
cred = Crrtab[cr];
|
|
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
cblue = Cbbtab[cb];
|
|
y = GETJSAMPLE(*inptr0);
|
|
outptr[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
h2v2_merged_upsample (j_decompress_ptr cinfo,
|
|
JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
|
|
JSAMPARRAY output_buf)
|
|
{
|
|
my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
|
|
register int y, cred, cgreen, cblue;
|
|
int cb, cr;
|
|
register JSAMPROW outptr0, outptr1;
|
|
JSAMPROW inptr00, inptr01, inptr1, inptr2;
|
|
JDIMENSION col;
|
|
/* copy these pointers into registers if possible */
|
|
register JSAMPLE * range_limit = cinfo->sample_range_limit;
|
|
int * Crrtab = upsample->Cr_r_tab;
|
|
int * Cbbtab = upsample->Cb_b_tab;
|
|
INT32 * Crgtab = upsample->Cr_g_tab;
|
|
INT32 * Cbgtab = upsample->Cb_g_tab;
|
|
SHIFT_TEMPS
|
|
|
|
inptr00 = input_buf[0][in_row_group_ctr*2];
|
|
inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
|
|
inptr1 = input_buf[1][in_row_group_ctr];
|
|
inptr2 = input_buf[2][in_row_group_ctr];
|
|
outptr0 = output_buf[0];
|
|
outptr1 = output_buf[1];
|
|
/* Loop for each group of output pixels */
|
|
for (col = cinfo->output_width >> 1; col > 0; col--) {
|
|
/* Do the chroma part of the calculation */
|
|
cb = GETJSAMPLE(*inptr1++);
|
|
cr = GETJSAMPLE(*inptr2++);
|
|
cred = Crrtab[cr];
|
|
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
cblue = Cbbtab[cb];
|
|
/* Fetch 4 Y values and emit 4 pixels */
|
|
y = GETJSAMPLE(*inptr00++);
|
|
outptr0[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr0[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
outptr0 += RGB_PIXELSIZE;
|
|
y = GETJSAMPLE(*inptr00++);
|
|
outptr0[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr0[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
outptr0 += RGB_PIXELSIZE;
|
|
y = GETJSAMPLE(*inptr01++);
|
|
outptr1[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr1[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
outptr1 += RGB_PIXELSIZE;
|
|
y = GETJSAMPLE(*inptr01++);
|
|
outptr1[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr1[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
outptr1 += RGB_PIXELSIZE;
|
|
}
|
|
/* If image width is odd, do the last output column separately */
|
|
if (cinfo->output_width & 1) {
|
|
cb = GETJSAMPLE(*inptr1);
|
|
cr = GETJSAMPLE(*inptr2);
|
|
cred = Crrtab[cr];
|
|
cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
|
|
cblue = Cbbtab[cb];
|
|
y = GETJSAMPLE(*inptr00);
|
|
outptr0[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr0[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr0[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
y = GETJSAMPLE(*inptr01);
|
|
outptr1[rgb_red[cinfo->out_color_space]] = range_limit[y + cred];
|
|
outptr1[rgb_green[cinfo->out_color_space]] = range_limit[y + cgreen];
|
|
outptr1[rgb_blue[cinfo->out_color_space]] = range_limit[y + cblue];
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Module initialization routine for merged upsampling/color conversion.
|
|
*
|
|
* NB: this is called under the conditions determined by use_merged_upsample()
|
|
* in jdmaster.c. That routine MUST correspond to the actual capabilities
|
|
* of this module; no safety checks are made here.
|
|
*/
|
|
|
|
GLOBAL(void)
|
|
jinit_merged_upsampler (j_decompress_ptr cinfo)
|
|
{
|
|
my_upsample_ptr upsample;
|
|
|
|
upsample = (my_upsample_ptr)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
SIZEOF(my_upsampler));
|
|
cinfo->upsample = (struct jpeg_upsampler *) upsample;
|
|
upsample->pub.start_pass = start_pass_merged_upsample;
|
|
upsample->pub.need_context_rows = FALSE;
|
|
|
|
upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
|
|
|
|
if (cinfo->max_v_samp_factor == 2) {
|
|
upsample->pub.upsample = merged_2v_upsample;
|
|
if (jsimd_can_h2v2_merged_upsample())
|
|
upsample->upmethod = jsimd_h2v2_merged_upsample;
|
|
else
|
|
upsample->upmethod = h2v2_merged_upsample;
|
|
/* Allocate a spare row buffer */
|
|
upsample->spare_row = (JSAMPROW)
|
|
(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
|
|
} else {
|
|
upsample->pub.upsample = merged_1v_upsample;
|
|
if (jsimd_can_h2v1_merged_upsample())
|
|
upsample->upmethod = jsimd_h2v1_merged_upsample;
|
|
else
|
|
upsample->upmethod = h2v1_merged_upsample;
|
|
/* No spare row needed */
|
|
upsample->spare_row = NULL;
|
|
}
|
|
|
|
build_ycc_rgb_table(cinfo);
|
|
}
|
|
|
|
#endif /* UPSAMPLE_MERGING_SUPPORTED */
|