Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

jcprepct.c File Reference

#include "jinclude.h"
#include "jpeglib.h"

Go to the source code of this file.


Data Structures

struct  my_prep_controller

Defines

#define JPEG_INTERNALS
#define CONTEXT_ROWS_SUPPORTED

Typedefs

typedef my_prep_controllermy_prep_ptr

Functions

 start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
 expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows, int output_rows)
 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)
 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)
 create_context_buffer (j_compress_ptr cinfo)
 jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)

Define Documentation

#define CONTEXT_ROWS_SUPPORTED
 

Definition at line 28 of file jcprepct.c.

#define JPEG_INTERNALS
 

Definition at line 17 of file jcprepct.c.


Typedef Documentation

typedef my_prep_controller* my_prep_ptr
 

Definition at line 70 of file jcprepct.c.


Function Documentation

create_context_buffer j_compress_ptr    cinfo
 

Definition at line 267 of file jcprepct.c.

References my_prep_controller::color_buf, compptr, jpeg_component_info::h_samp_factor, i, JPOOL_IMAGE, JSAMPARRAY, JSAMPROW, jpeg_compress_struct::max_v_samp_factor, MEMCOPY, jpeg_compress_struct::prep, SIZEOF, and jpeg_component_info::width_in_blocks.

Referenced by jinit_c_prep_controller().

00268 {
00269   my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
00270   int rgroup_height = cinfo->max_v_samp_factor;
00271   int ci, i;
00272   jpeg_component_info * compptr;
00273   JSAMPARRAY true_buffer, fake_buffer;
00274 
00275   /* Grab enough space for fake row pointers for all the components;
00276    * we need five row groups' worth of pointers for each component.
00277    */
00278   fake_buffer = (JSAMPARRAY)
00279     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00280                                 (cinfo->num_components * 5 * rgroup_height) *
00281                                 SIZEOF(JSAMPROW));
00282 
00283   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00284        ci++, compptr++) {
00285     /* Allocate the actual buffer space (3 row groups) for this component.
00286      * We make the buffer wide enough to allow the downsampler to edge-expand
00287      * horizontally within the buffer, if it so chooses.
00288      */
00289     true_buffer = (*cinfo->mem->alloc_sarray)
00290       ((j_common_ptr) cinfo, JPOOL_IMAGE,
00291        (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
00292                       cinfo->max_h_samp_factor) / compptr->h_samp_factor),
00293        (JDIMENSION) (3 * rgroup_height));
00294     /* Copy true buffer row pointers into the middle of the fake row array */
00295     MEMCOPY(fake_buffer + rgroup_height, true_buffer,
00296             3 * rgroup_height * SIZEOF(JSAMPROW));
00297     /* Fill in the above and below wraparound pointers */
00298     for (i = 0; i < rgroup_height; i++) {
00299       fake_buffer[i] = true_buffer[2 * rgroup_height + i];
00300       fake_buffer[4 * rgroup_height + i] = true_buffer[i];
00301     }
00302     prep->color_buf[ci] = fake_buffer + rgroup_height;
00303     fake_buffer += 5 * rgroup_height; /* point to space for next component */
00304   }
00305 }

expand_bottom_edge JSAMPARRAY    image_data,
JDIMENSION    num_cols,
int    input_rows,
int    output_rows
 

Definition at line 106 of file jcprepct.c.

References jcopy_sample_rows(), JDIMENSION, JSAMPARRAY, and num_cols.

Referenced by pre_process_context(), and pre_process_data().

00108 {
00109   register int row;
00110 
00111   for (row = input_rows; row < output_rows; row++) {
00112     jcopy_sample_rows(image_data, input_rows-1, image_data, row,
00113                       1, num_cols);
00114   }
00115 }

jinit_c_prep_controller j_compress_ptr    cinfo,
boolean    need_full_buffer
 

Definition at line 315 of file jcprepct.c.

References compptr, create_context_buffer(), ERREXIT, jpeg_component_info::h_samp_factor, JPOOL_IMAGE, need_full_buffer, pre_process_context(), pre_process_data(), SIZEOF, start_pass_prep(), and jpeg_component_info::width_in_blocks.

Referenced by jinit_compress_master().

00316 {
00317   my_prep_ptr prep;
00318   int ci;
00319   jpeg_component_info * compptr;
00320 
00321   if (need_full_buffer)         /* safety check */
00322     ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00323 
00324   prep = (my_prep_ptr)
00325     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00326                                 SIZEOF(my_prep_controller));
00327   cinfo->prep = (struct jpeg_c_prep_controller *) prep;
00328   prep->pub.start_pass = start_pass_prep;
00329 
00330   /* Allocate the color conversion buffer.
00331    * We make the buffer wide enough to allow the downsampler to edge-expand
00332    * horizontally within the buffer, if it so chooses.
00333    */
00334   if (cinfo->downsample->need_context_rows) {
00335     /* Set up to provide context rows */
00336 #ifdef CONTEXT_ROWS_SUPPORTED
00337     prep->pub.pre_process_data = pre_process_context;
00338     create_context_buffer(cinfo);
00339 #else
00340     ERREXIT(cinfo, JERR_NOT_COMPILED);
00341 #endif
00342   } else {
00343     /* No context, just make it tall enough for one row group */
00344     prep->pub.pre_process_data = pre_process_data;
00345     for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00346          ci++, compptr++) {
00347       prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
00348         ((j_common_ptr) cinfo, JPOOL_IMAGE,
00349          (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
00350                         cinfo->max_h_samp_factor) / compptr->h_samp_factor),
00351          (JDIMENSION) cinfo->max_v_samp_factor);
00352     }
00353   }
00354 }

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
 

Definition at line 195 of file jcprepct.c.

References jpeg_compress_struct::cconvert, my_prep_controller::color_buf, jpeg_compress_struct::downsample, expand_bottom_edge(), jpeg_compress_struct::image_height, jpeg_compress_struct::image_width, in_row_ctr, in_rows_avail, jcopy_sample_rows(), JDIMENSION, JSAMPARRAY, JSAMPIMAGE, jpeg_compress_struct::max_v_samp_factor, MIN, my_prep_controller::next_buf_row, my_prep_controller::next_buf_stop, jpeg_compress_struct::num_components, jpeg_compress_struct::prep, my_prep_controller::rows_to_go, and my_prep_controller::this_row_group.

Referenced by jinit_c_prep_controller().

00200 {
00201   my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
00202   int numrows, ci;
00203   int buf_height = cinfo->max_v_samp_factor * 3;
00204   JDIMENSION inrows;
00205 
00206   while (*out_row_group_ctr < out_row_groups_avail) {
00207     if (*in_row_ctr < in_rows_avail) {
00208       /* Do color conversion to fill the conversion buffer. */
00209       inrows = in_rows_avail - *in_row_ctr;
00210       numrows = prep->next_buf_stop - prep->next_buf_row;
00211       numrows = (int) MIN((JDIMENSION) numrows, inrows);
00212       (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
00213                                          prep->color_buf,
00214                                          (JDIMENSION) prep->next_buf_row,
00215                                          numrows);
00216       /* Pad at top of image, if first time through */
00217       if (prep->rows_to_go == cinfo->image_height) {
00218         for (ci = 0; ci < cinfo->num_components; ci++) {
00219           int row;
00220           for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
00221             jcopy_sample_rows(prep->color_buf[ci], 0,
00222                               prep->color_buf[ci], -row,
00223                               1, cinfo->image_width);
00224           }
00225         }
00226       }
00227       *in_row_ctr += numrows;
00228       prep->next_buf_row += numrows;
00229       prep->rows_to_go -= numrows;
00230     } else {
00231       /* Return for more data, unless we are at the bottom of the image. */
00232       if (prep->rows_to_go != 0)
00233         break;
00234       /* When at bottom of image, pad to fill the conversion buffer. */
00235       if (prep->next_buf_row < prep->next_buf_stop) {
00236         for (ci = 0; ci < cinfo->num_components; ci++) {
00237           expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
00238                              prep->next_buf_row, prep->next_buf_stop);
00239         }
00240         prep->next_buf_row = prep->next_buf_stop;
00241       }
00242     }
00243     /* If we've gotten enough data, downsample a row group. */
00244     if (prep->next_buf_row == prep->next_buf_stop) {
00245       (*cinfo->downsample->downsample) (cinfo,
00246                                         prep->color_buf,
00247                                         (JDIMENSION) prep->this_row_group,
00248                                         output_buf, *out_row_group_ctr);
00249       (*out_row_group_ctr)++;
00250       /* Advance pointers with wraparound as necessary. */
00251       prep->this_row_group += cinfo->max_v_samp_factor;
00252       if (prep->this_row_group >= buf_height)
00253         prep->this_row_group = 0;
00254       if (prep->next_buf_row >= buf_height)
00255         prep->next_buf_row = 0;
00256       prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
00257     }
00258   }
00259 }

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
 

Definition at line 128 of file jcprepct.c.

References jpeg_compress_struct::cconvert, my_prep_controller::color_buf, jpeg_compress_struct::comp_info, compptr, jpeg_compress_struct::downsample, expand_bottom_edge(), jpeg_compress_struct::image_width, in_row_ctr, in_rows_avail, JDIMENSION, JSAMPARRAY, JSAMPIMAGE, jpeg_compress_struct::max_v_samp_factor, MIN, my_prep_controller::next_buf_row, jpeg_compress_struct::num_components, jpeg_compress_struct::prep, my_prep_controller::rows_to_go, jpeg_component_info::v_samp_factor, and jpeg_component_info::width_in_blocks.

Referenced by jinit_c_prep_controller().

00133 {
00134   my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
00135   int numrows, ci;
00136   JDIMENSION inrows;
00137   jpeg_component_info * compptr;
00138 
00139   while (*in_row_ctr < in_rows_avail &&
00140          *out_row_group_ctr < out_row_groups_avail) {
00141     /* Do color conversion to fill the conversion buffer. */
00142     inrows = in_rows_avail - *in_row_ctr;
00143     numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
00144     numrows = (int) MIN((JDIMENSION) numrows, inrows);
00145     (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
00146                                        prep->color_buf,
00147                                        (JDIMENSION) prep->next_buf_row,
00148                                        numrows);
00149     *in_row_ctr += numrows;
00150     prep->next_buf_row += numrows;
00151     prep->rows_to_go -= numrows;
00152     /* If at bottom of image, pad to fill the conversion buffer. */
00153     if (prep->rows_to_go == 0 &&
00154         prep->next_buf_row < cinfo->max_v_samp_factor) {
00155       for (ci = 0; ci < cinfo->num_components; ci++) {
00156         expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
00157                            prep->next_buf_row, cinfo->max_v_samp_factor);
00158       }
00159       prep->next_buf_row = cinfo->max_v_samp_factor;
00160     }
00161     /* If we've filled the conversion buffer, empty it. */
00162     if (prep->next_buf_row == cinfo->max_v_samp_factor) {
00163       (*cinfo->downsample->downsample) (cinfo,
00164                                         prep->color_buf, (JDIMENSION) 0,
00165                                         output_buf, *out_row_group_ctr);
00166       prep->next_buf_row = 0;
00167       (*out_row_group_ctr)++;
00168     }
00169     /* If at bottom of image, pad the output to a full iMCU height.
00170      * Note we assume the caller is providing a one-iMCU-height output buffer!
00171      */
00172     if (prep->rows_to_go == 0 &&
00173         *out_row_group_ctr < out_row_groups_avail) {
00174       for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00175            ci++, compptr++) {
00176         expand_bottom_edge(output_buf[ci],
00177                            compptr->width_in_blocks * DCTSIZE,
00178                            (int) (*out_row_group_ctr * compptr->v_samp_factor),
00179                            (int) (out_row_groups_avail * compptr->v_samp_factor));
00180       }
00181       *out_row_group_ctr = out_row_groups_avail;
00182       break;                    /* can exit outer loop without test */
00183     }
00184   }
00185 }

start_pass_prep j_compress_ptr    cinfo,
J_BUF_MODE    pass_mode
 

Definition at line 78 of file jcprepct.c.

References ERREXIT, jpeg_compress_struct::image_height, J_BUF_MODE, JBUF_PASS_THRU, jpeg_compress_struct::max_v_samp_factor, my_prep_controller::next_buf_row, my_prep_controller::next_buf_stop, jpeg_compress_struct::prep, my_prep_controller::rows_to_go, and my_prep_controller::this_row_group.

Referenced by jinit_c_prep_controller().

00079 {
00080   my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
00081 
00082   if (pass_mode != JBUF_PASS_THRU)
00083     ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
00084 
00085   /* Initialize total-height counter for detecting bottom of image */
00086   prep->rows_to_go = cinfo->image_height;
00087   /* Mark the conversion buffer empty */
00088   prep->next_buf_row = 0;
00089 #ifdef CONTEXT_ROWS_SUPPORTED
00090   /* Preset additional state variables for context mode.
00091    * These aren't used in non-context mode, so we needn't test which mode.
00092    */
00093   prep->this_row_group = 0;
00094   /* Set next_buf_stop to stop after two row groups have been read in. */
00095   prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
00096 #endif
00097 }
 

Powered by Plone

This site conforms to the following standards: