mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 18:47:53 +00:00
2d0b90011e
--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
355 lines
12 KiB
C
355 lines
12 KiB
C
/*
|
|
* jcprepct.c
|
|
*
|
|
* Copyright (C) 1994-1996, Thomas G. Lane.
|
|
* 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 the compression preprocessing controller.
|
|
* This controller manages the color conversion, downsampling,
|
|
* and edge expansion steps.
|
|
*
|
|
* Most of the complexity here is associated with buffering input rows
|
|
* as required by the downsampler. See the comments at the head of
|
|
* jcsample.c for the downsampler's needs.
|
|
*/
|
|
|
|
#define JPEG_INTERNALS
|
|
#include "jinclude.h"
|
|
#include "jpeglib.h"
|
|
|
|
|
|
/* At present, jcsample.c can request context rows only for smoothing.
|
|
* In the future, we might also need context rows for CCIR601 sampling
|
|
* or other more-complex downsampling procedures. The code to support
|
|
* context rows should be compiled only if needed.
|
|
*/
|
|
#ifdef INPUT_SMOOTHING_SUPPORTED
|
|
#define CONTEXT_ROWS_SUPPORTED
|
|
#endif
|
|
|
|
|
|
/*
|
|
* For the simple (no-context-row) case, we just need to buffer one
|
|
* row group's worth of pixels for the downsampling step. At the bottom of
|
|
* the image, we pad to a full row group by replicating the last pixel row.
|
|
* The downsampler's last output row is then replicated if needed to pad
|
|
* out to a full iMCU row.
|
|
*
|
|
* When providing context rows, we must buffer three row groups' worth of
|
|
* pixels. Three row groups are physically allocated, but the row pointer
|
|
* arrays are made five row groups high, with the extra pointers above and
|
|
* below "wrapping around" to point to the last and first real row groups.
|
|
* This allows the downsampler to access the proper context rows.
|
|
* At the top and bottom of the image, we create dummy context rows by
|
|
* copying the first or last real pixel row. This copying could be avoided
|
|
* by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the
|
|
* trouble on the compression side.
|
|
*/
|
|
|
|
|
|
/* Private buffer controller object */
|
|
|
|
typedef struct {
|
|
struct jpeg_c_prep_controller pub; /* public fields */
|
|
|
|
/* Downsampling input buffer. This buffer holds color-converted data
|
|
* until we have enough to do a downsample step.
|
|
*/
|
|
JSAMPARRAY color_buf[MAX_COMPONENTS];
|
|
|
|
JDIMENSION rows_to_go; /* counts rows remaining in source image */
|
|
int next_buf_row; /* index of next row to store in color_buf */
|
|
|
|
#ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
|
|
int this_row_group; /* starting row index of group to process */
|
|
int next_buf_stop; /* downsample when we reach this index */
|
|
#endif
|
|
} my_prep_controller;
|
|
|
|
typedef my_prep_controller * my_prep_ptr;
|
|
|
|
|
|
/*
|
|
* Initialize for a processing pass.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
|
|
{
|
|
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
|
|
|
if (pass_mode != JBUF_PASS_THRU)
|
|
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
|
|
|
/* Initialize total-height counter for detecting bottom of image */
|
|
prep->rows_to_go = cinfo->image_height;
|
|
/* Mark the conversion buffer empty */
|
|
prep->next_buf_row = 0;
|
|
#ifdef CONTEXT_ROWS_SUPPORTED
|
|
/* Preset additional state variables for context mode.
|
|
* These aren't used in non-context mode, so we needn't test which mode.
|
|
*/
|
|
prep->this_row_group = 0;
|
|
/* Set next_buf_stop to stop after two row groups have been read in. */
|
|
prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
|
|
#endif
|
|
}
|
|
|
|
|
|
/*
|
|
* Expand an image vertically from height input_rows to height output_rows,
|
|
* by duplicating the bottom row.
|
|
*/
|
|
|
|
LOCAL(void)
|
|
expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
|
|
int input_rows, int output_rows)
|
|
{
|
|
register int row;
|
|
|
|
for (row = input_rows; row < output_rows; row++) {
|
|
jcopy_sample_rows(image_data, input_rows-1, image_data, row,
|
|
1, num_cols);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Process some data in the simple no-context case.
|
|
*
|
|
* Preprocessor output data is counted in "row groups". A row group
|
|
* is defined to be v_samp_factor sample rows of each component.
|
|
* Downsampling will produce this much data from each max_v_samp_factor
|
|
* input rows.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
pre_process_data (j_compress_ptr cinfo,
|
|
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
|
JDIMENSION in_rows_avail,
|
|
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
|
JDIMENSION out_row_groups_avail)
|
|
{
|
|
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
|
int numrows, ci;
|
|
JDIMENSION inrows;
|
|
jpeg_component_info * compptr;
|
|
|
|
while (*in_row_ctr < in_rows_avail &&
|
|
*out_row_group_ctr < out_row_groups_avail) {
|
|
/* Do color conversion to fill the conversion buffer. */
|
|
inrows = in_rows_avail - *in_row_ctr;
|
|
numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
|
|
numrows = (int) MIN((JDIMENSION) numrows, inrows);
|
|
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
|
|
prep->color_buf,
|
|
(JDIMENSION) prep->next_buf_row,
|
|
numrows);
|
|
*in_row_ctr += numrows;
|
|
prep->next_buf_row += numrows;
|
|
prep->rows_to_go -= numrows;
|
|
/* If at bottom of image, pad to fill the conversion buffer. */
|
|
if (prep->rows_to_go == 0 &&
|
|
prep->next_buf_row < cinfo->max_v_samp_factor) {
|
|
for (ci = 0; ci < cinfo->num_components; ci++) {
|
|
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
|
|
prep->next_buf_row, cinfo->max_v_samp_factor);
|
|
}
|
|
prep->next_buf_row = cinfo->max_v_samp_factor;
|
|
}
|
|
/* If we've filled the conversion buffer, empty it. */
|
|
if (prep->next_buf_row == cinfo->max_v_samp_factor) {
|
|
(*cinfo->downsample->downsample) (cinfo,
|
|
prep->color_buf, (JDIMENSION) 0,
|
|
output_buf, *out_row_group_ctr);
|
|
prep->next_buf_row = 0;
|
|
(*out_row_group_ctr)++;
|
|
}
|
|
/* If at bottom of image, pad the output to a full iMCU height.
|
|
* Note we assume the caller is providing a one-iMCU-height output buffer!
|
|
*/
|
|
if (prep->rows_to_go == 0 &&
|
|
*out_row_group_ctr < out_row_groups_avail) {
|
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
|
ci++, compptr++) {
|
|
expand_bottom_edge(output_buf[ci],
|
|
compptr->width_in_blocks * DCTSIZE,
|
|
(int) (*out_row_group_ctr * compptr->v_samp_factor),
|
|
(int) (out_row_groups_avail * compptr->v_samp_factor));
|
|
}
|
|
*out_row_group_ctr = out_row_groups_avail;
|
|
break; /* can exit outer loop without test */
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef CONTEXT_ROWS_SUPPORTED
|
|
|
|
/*
|
|
* Process some data in the context case.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
pre_process_context (j_compress_ptr cinfo,
|
|
JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
|
|
JDIMENSION in_rows_avail,
|
|
JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
|
|
JDIMENSION out_row_groups_avail)
|
|
{
|
|
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
|
int numrows, ci;
|
|
int buf_height = cinfo->max_v_samp_factor * 3;
|
|
JDIMENSION inrows;
|
|
|
|
while (*out_row_group_ctr < out_row_groups_avail) {
|
|
if (*in_row_ctr < in_rows_avail) {
|
|
/* Do color conversion to fill the conversion buffer. */
|
|
inrows = in_rows_avail - *in_row_ctr;
|
|
numrows = prep->next_buf_stop - prep->next_buf_row;
|
|
numrows = (int) MIN((JDIMENSION) numrows, inrows);
|
|
(*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
|
|
prep->color_buf,
|
|
(JDIMENSION) prep->next_buf_row,
|
|
numrows);
|
|
/* Pad at top of image, if first time through */
|
|
if (prep->rows_to_go == cinfo->image_height) {
|
|
for (ci = 0; ci < cinfo->num_components; ci++) {
|
|
int row;
|
|
for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
|
|
jcopy_sample_rows(prep->color_buf[ci], 0,
|
|
prep->color_buf[ci], -row,
|
|
1, cinfo->image_width);
|
|
}
|
|
}
|
|
}
|
|
*in_row_ctr += numrows;
|
|
prep->next_buf_row += numrows;
|
|
prep->rows_to_go -= numrows;
|
|
} else {
|
|
/* Return for more data, unless we are at the bottom of the image. */
|
|
if (prep->rows_to_go != 0)
|
|
break;
|
|
/* When at bottom of image, pad to fill the conversion buffer. */
|
|
if (prep->next_buf_row < prep->next_buf_stop) {
|
|
for (ci = 0; ci < cinfo->num_components; ci++) {
|
|
expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
|
|
prep->next_buf_row, prep->next_buf_stop);
|
|
}
|
|
prep->next_buf_row = prep->next_buf_stop;
|
|
}
|
|
}
|
|
/* If we've gotten enough data, downsample a row group. */
|
|
if (prep->next_buf_row == prep->next_buf_stop) {
|
|
(*cinfo->downsample->downsample) (cinfo,
|
|
prep->color_buf,
|
|
(JDIMENSION) prep->this_row_group,
|
|
output_buf, *out_row_group_ctr);
|
|
(*out_row_group_ctr)++;
|
|
/* Advance pointers with wraparound as necessary. */
|
|
prep->this_row_group += cinfo->max_v_samp_factor;
|
|
if (prep->this_row_group >= buf_height)
|
|
prep->this_row_group = 0;
|
|
if (prep->next_buf_row >= buf_height)
|
|
prep->next_buf_row = 0;
|
|
prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Create the wrapped-around downsampling input buffer needed for context mode.
|
|
*/
|
|
|
|
LOCAL(void)
|
|
create_context_buffer (j_compress_ptr cinfo)
|
|
{
|
|
my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
|
|
int rgroup_height = cinfo->max_v_samp_factor;
|
|
int ci, i;
|
|
jpeg_component_info * compptr;
|
|
JSAMPARRAY true_buffer, fake_buffer;
|
|
|
|
/* Grab enough space for fake row pointers for all the components;
|
|
* we need five row groups' worth of pointers for each component.
|
|
*/
|
|
fake_buffer = (JSAMPARRAY)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
(cinfo->num_components * 5 * rgroup_height) *
|
|
SIZEOF(JSAMPROW));
|
|
|
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
|
ci++, compptr++) {
|
|
/* Allocate the actual buffer space (3 row groups) for this component.
|
|
* We make the buffer wide enough to allow the downsampler to edge-expand
|
|
* horizontally within the buffer, if it so chooses.
|
|
*/
|
|
true_buffer = (*cinfo->mem->alloc_sarray)
|
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
|
|
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
|
|
(JDIMENSION) (3 * rgroup_height));
|
|
/* Copy true buffer row pointers into the middle of the fake row array */
|
|
MEMCOPY(fake_buffer + rgroup_height, true_buffer,
|
|
3 * rgroup_height * SIZEOF(JSAMPROW));
|
|
/* Fill in the above and below wraparound pointers */
|
|
for (i = 0; i < rgroup_height; i++) {
|
|
fake_buffer[i] = true_buffer[2 * rgroup_height + i];
|
|
fake_buffer[4 * rgroup_height + i] = true_buffer[i];
|
|
}
|
|
prep->color_buf[ci] = fake_buffer + rgroup_height;
|
|
fake_buffer += 5 * rgroup_height; /* point to space for next component */
|
|
}
|
|
}
|
|
|
|
#endif /* CONTEXT_ROWS_SUPPORTED */
|
|
|
|
|
|
/*
|
|
* Initialize preprocessing controller.
|
|
*/
|
|
|
|
GLOBAL(void)
|
|
jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
|
|
{
|
|
my_prep_ptr prep;
|
|
int ci;
|
|
jpeg_component_info * compptr;
|
|
|
|
if (need_full_buffer) /* safety check */
|
|
ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
|
|
|
|
prep = (my_prep_ptr)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
SIZEOF(my_prep_controller));
|
|
cinfo->prep = (struct jpeg_c_prep_controller *) prep;
|
|
prep->pub.start_pass = start_pass_prep;
|
|
|
|
/* Allocate the color conversion buffer.
|
|
* We make the buffer wide enough to allow the downsampler to edge-expand
|
|
* horizontally within the buffer, if it so chooses.
|
|
*/
|
|
if (cinfo->downsample->need_context_rows) {
|
|
/* Set up to provide context rows */
|
|
#ifdef CONTEXT_ROWS_SUPPORTED
|
|
prep->pub.pre_process_data = pre_process_context;
|
|
create_context_buffer(cinfo);
|
|
#else
|
|
ERREXIT(cinfo, JERR_NOT_COMPILED);
|
|
#endif
|
|
} else {
|
|
/* No context, just make it tall enough for one row group */
|
|
prep->pub.pre_process_data = pre_process_data;
|
|
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
|
|
ci++, compptr++) {
|
|
prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
|
|
((j_common_ptr) cinfo, JPOOL_IMAGE,
|
|
(JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
|
|
cinfo->max_h_samp_factor) / compptr->h_samp_factor),
|
|
(JDIMENSION) cinfo->max_v_samp_factor);
|
|
}
|
|
}
|
|
}
|