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  

jdsample.c File Reference

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

Go to the source code of this file.


Data Structures

struct  my_upsampler

Defines

#define JPEG_INTERNALS

Typedefs

typedef my_upsamplermy_upsample_ptr

Functions

typedef JMETHOD (void, upsample1_ptr,(j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr))
 start_pass_upsample (j_decompress_ptr cinfo)
 sep_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)
 fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
 noop_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
 int_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
 h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
 h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
 h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
 h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)
 jinit_upsampler (j_decompress_ptr cinfo)

Define Documentation

#define JPEG_INTERNALS
 

Definition at line 21 of file jdsample.c.


Typedef Documentation

typedef my_upsampler* my_upsample_ptr
 

Definition at line 61 of file jdsample.c.


Function Documentation

fullsize_upsample j_decompress_ptr    cinfo,
jpeg_component_info   compptr,
JSAMPARRAY    input_data,
JSAMPARRAY   output_data_ptr
 

Definition at line 157 of file jdsample.c.

References compptr, and JSAMPARRAY.

Referenced by jinit_upsampler().

00159 {
00160   *output_data_ptr = input_data;
00161 }

h2v1_fancy_upsample j_decompress_ptr    cinfo,
jpeg_component_info   compptr,
JSAMPARRAY    input_data,
JSAMPARRAY   output_data_ptr
 

Definition at line 304 of file jdsample.c.

References compptr, jpeg_component_info::downsampled_width, GETJSAMPLE, JDIMENSION, JSAMPARRAY, JSAMPROW, and jpeg_decompress_struct::max_v_samp_factor.

Referenced by jinit_upsampler().

00306 {
00307   JSAMPARRAY output_data = *output_data_ptr;
00308   register JSAMPROW inptr, outptr;
00309   register int invalue;
00310   register JDIMENSION colctr;
00311   int inrow;
00312 
00313   for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
00314     inptr = input_data[inrow];
00315     outptr = output_data[inrow];
00316     /* Special case for first column */
00317     invalue = GETJSAMPLE(*inptr++);
00318     *outptr++ = (JSAMPLE) invalue;
00319     *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
00320 
00321     for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
00322       /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
00323       invalue = GETJSAMPLE(*inptr++) * 3;
00324       *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
00325       *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
00326     }
00327 
00328     /* Special case for last column */
00329     invalue = GETJSAMPLE(*inptr);
00330     *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
00331     *outptr++ = (JSAMPLE) invalue;
00332   }
00333 }

h2v1_upsample j_decompress_ptr    cinfo,
jpeg_component_info   compptr,
JSAMPARRAY    input_data,
JSAMPARRAY   output_data_ptr
 

Definition at line 233 of file jdsample.c.

References compptr, JSAMPARRAY, JSAMPLE, JSAMPROW, jpeg_decompress_struct::max_v_samp_factor, and jpeg_decompress_struct::output_width.

Referenced by jinit_upsampler().

00235 {
00236   JSAMPARRAY output_data = *output_data_ptr;
00237   register JSAMPROW inptr, outptr;
00238   register JSAMPLE invalue;
00239   JSAMPROW outend;
00240   int inrow;
00241 
00242   for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
00243     inptr = input_data[inrow];
00244     outptr = output_data[inrow];
00245     outend = outptr + cinfo->output_width;
00246     while (outptr < outend) {
00247       invalue = *inptr++;       /* don't need GETJSAMPLE() here */
00248       *outptr++ = invalue;
00249       *outptr++ = invalue;
00250     }
00251   }
00252 }

h2v2_fancy_upsample j_decompress_ptr    cinfo,
jpeg_component_info   compptr,
JSAMPARRAY    input_data,
JSAMPARRAY   output_data_ptr
 

Definition at line 345 of file jdsample.c.

References compptr, jpeg_component_info::downsampled_width, GETJSAMPLE, INT32, JDIMENSION, JSAMPARRAY, JSAMPROW, jpeg_decompress_struct::max_v_samp_factor, and v.

Referenced by jinit_upsampler().

00347 {
00348   JSAMPARRAY output_data = *output_data_ptr;
00349   register JSAMPROW inptr0, inptr1, outptr;
00350 #if BITS_IN_JSAMPLE == 8
00351   register int thiscolsum, lastcolsum, nextcolsum;
00352 #else
00353   register INT32 thiscolsum, lastcolsum, nextcolsum;
00354 #endif
00355   register JDIMENSION colctr;
00356   int inrow, outrow, v;
00357 
00358   inrow = outrow = 0;
00359   while (outrow < cinfo->max_v_samp_factor) {
00360     for (v = 0; v < 2; v++) {
00361       /* inptr0 points to nearest input row, inptr1 points to next nearest */
00362       inptr0 = input_data[inrow];
00363       if (v == 0)               /* next nearest is row above */
00364         inptr1 = input_data[inrow-1];
00365       else                      /* next nearest is row below */
00366         inptr1 = input_data[inrow+1];
00367       outptr = output_data[outrow++];
00368 
00369       /* Special case for first column */
00370       thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
00371       nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
00372       *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
00373       *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
00374       lastcolsum = thiscolsum; thiscolsum = nextcolsum;
00375 
00376       for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
00377         /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
00378         /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
00379         nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
00380         *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
00381         *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
00382         lastcolsum = thiscolsum; thiscolsum = nextcolsum;
00383       }
00384 
00385       /* Special case for last column */
00386       *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
00387       *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
00388     }
00389     inrow++;
00390   }
00391 }

h2v2_upsample j_decompress_ptr    cinfo,
jpeg_component_info   compptr,
JSAMPARRAY    input_data,
JSAMPARRAY   output_data_ptr
 

Definition at line 261 of file jdsample.c.

References compptr, jcopy_sample_rows(), JSAMPARRAY, JSAMPLE, JSAMPROW, jpeg_decompress_struct::max_v_samp_factor, and jpeg_decompress_struct::output_width.

Referenced by jinit_upsampler().

00263 {
00264   JSAMPARRAY output_data = *output_data_ptr;
00265   register JSAMPROW inptr, outptr;
00266   register JSAMPLE invalue;
00267   JSAMPROW outend;
00268   int inrow, outrow;
00269 
00270   inrow = outrow = 0;
00271   while (outrow < cinfo->max_v_samp_factor) {
00272     inptr = input_data[inrow];
00273     outptr = output_data[outrow];
00274     outend = outptr + cinfo->output_width;
00275     while (outptr < outend) {
00276       invalue = *inptr++;       /* don't need GETJSAMPLE() here */
00277       *outptr++ = invalue;
00278       *outptr++ = invalue;
00279     }
00280     jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
00281                       1, cinfo->output_width);
00282     inrow++;
00283     outrow += 2;
00284   }
00285 }

int_upsample j_decompress_ptr    cinfo,
jpeg_component_info   compptr,
JSAMPARRAY    input_data,
JSAMPARRAY   output_data_ptr
 

Definition at line 189 of file jdsample.c.

References jpeg_component_info::component_index, compptr, my_upsampler::h_expand, jcopy_sample_rows(), JSAMPARRAY, JSAMPLE, JSAMPROW, jpeg_decompress_struct::max_v_samp_factor, jpeg_decompress_struct::output_width, jpeg_decompress_struct::upsample, and my_upsampler::v_expand.

Referenced by jinit_upsampler().

00191 {
00192   my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
00193   JSAMPARRAY output_data = *output_data_ptr;
00194   register JSAMPROW inptr, outptr;
00195   register JSAMPLE invalue;
00196   register int h;
00197   JSAMPROW outend;
00198   int h_expand, v_expand;
00199   int inrow, outrow;
00200 
00201   h_expand = upsample->h_expand[compptr->component_index];
00202   v_expand = upsample->v_expand[compptr->component_index];
00203 
00204   inrow = outrow = 0;
00205   while (outrow < cinfo->max_v_samp_factor) {
00206     /* Generate one output row with proper horizontal expansion */
00207     inptr = input_data[inrow];
00208     outptr = output_data[outrow];
00209     outend = outptr + cinfo->output_width;
00210     while (outptr < outend) {
00211       invalue = *inptr++;       /* don't need GETJSAMPLE() here */
00212       for (h = h_expand; h > 0; h--) {
00213         *outptr++ = invalue;
00214       }
00215     }
00216     /* Generate any additional output rows by duplicating the first one */
00217     if (v_expand > 1) {
00218       jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
00219                         v_expand-1, cinfo->output_width);
00220     }
00221     inrow++;
00222     outrow += v_expand;
00223   }
00224 }

jinit_upsampler j_decompress_ptr    cinfo
 

Definition at line 399 of file jdsample.c.

References jpeg_component_info::component_needed, compptr, jpeg_component_info::DCT_scaled_size, jpeg_component_info::downsampled_width, ERREXIT, fullsize_upsample(), h2v1_fancy_upsample(), h2v1_upsample(), h2v2_fancy_upsample(), h2v2_upsample(), jpeg_component_info::h_samp_factor, int_upsample(), JPOOL_IMAGE, jround_up(), jpeg_upsampler::need_context_rows, noop_upsample(), sep_upsample(), SIZEOF, start_pass_upsample(), and jpeg_component_info::v_samp_factor.

Referenced by master_selection().

00400 {
00401   my_upsample_ptr upsample;
00402   int ci;
00403   jpeg_component_info * compptr;
00404   boolean need_buffer, do_fancy;
00405   int h_in_group, v_in_group, h_out_group, v_out_group;
00406 
00407   upsample = (my_upsample_ptr)
00408     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00409                                 SIZEOF(my_upsampler));
00410   cinfo->upsample = (struct jpeg_upsampler *) upsample;
00411   upsample->pub.start_pass = start_pass_upsample;
00412   upsample->pub.upsample = sep_upsample;
00413   upsample->pub.need_context_rows = FALSE; /* until we find out differently */
00414 
00415   if (cinfo->CCIR601_sampling)  /* this isn't supported */
00416     ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
00417 
00418   /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
00419    * so don't ask for it.
00420    */
00421   do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
00422 
00423   /* Verify we can handle the sampling factors, select per-component methods,
00424    * and create storage as needed.
00425    */
00426   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00427        ci++, compptr++) {
00428     /* Compute size of an "input group" after IDCT scaling.  This many samples
00429      * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
00430      */
00431     h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
00432                  cinfo->min_DCT_scaled_size;
00433     v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
00434                  cinfo->min_DCT_scaled_size;
00435     h_out_group = cinfo->max_h_samp_factor;
00436     v_out_group = cinfo->max_v_samp_factor;
00437     upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
00438     need_buffer = TRUE;
00439     if (! compptr->component_needed) {
00440       /* Don't bother to upsample an uninteresting component. */
00441       upsample->methods[ci] = noop_upsample;
00442       need_buffer = FALSE;
00443     } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
00444       /* Fullsize components can be processed without any work. */
00445       upsample->methods[ci] = fullsize_upsample;
00446       need_buffer = FALSE;
00447     } else if (h_in_group * 2 == h_out_group &&
00448                v_in_group == v_out_group) {
00449       /* Special cases for 2h1v upsampling */
00450       if (do_fancy && compptr->downsampled_width > 2)
00451         upsample->methods[ci] = h2v1_fancy_upsample;
00452       else
00453         upsample->methods[ci] = h2v1_upsample;
00454     } else if (h_in_group * 2 == h_out_group &&
00455                v_in_group * 2 == v_out_group) {
00456       /* Special cases for 2h2v upsampling */
00457       if (do_fancy && compptr->downsampled_width > 2) {
00458         upsample->methods[ci] = h2v2_fancy_upsample;
00459         upsample->pub.need_context_rows = TRUE;
00460       } else
00461         upsample->methods[ci] = h2v2_upsample;
00462     } else if ((h_out_group % h_in_group) == 0 &&
00463                (v_out_group % v_in_group) == 0) {
00464       /* Generic integral-factors upsampling method */
00465       upsample->methods[ci] = int_upsample;
00466       upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
00467       upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
00468     } else
00469       ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
00470     if (need_buffer) {
00471       upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
00472         ((j_common_ptr) cinfo, JPOOL_IMAGE,
00473          (JDIMENSION) jround_up((long) cinfo->output_width,
00474                                 (long) cinfo->max_h_samp_factor),
00475          (JDIMENSION) cinfo->max_v_samp_factor);
00476     }
00477   }
00478 }

typedef JMETHOD void   ,
upsample1_ptr   ,
(j_decompress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY input_data, JSAMPARRAY *output_data_ptr)   
 

noop_upsample j_decompress_ptr    cinfo,
jpeg_component_info   compptr,
JSAMPARRAY    input_data,
JSAMPARRAY   output_data_ptr
 

Definition at line 170 of file jdsample.c.

References compptr, and JSAMPARRAY.

Referenced by jinit_upsampler().

00172 {
00173   *output_data_ptr = NULL;      /* safety check */
00174 }

sep_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
 

Definition at line 89 of file jdsample.c.

References jpeg_decompress_struct::cconvert, my_upsampler::color_buf, jpeg_decompress_struct::comp_info, compptr, in_row_group_ctr, in_row_groups_avail, JDIMENSION, JSAMPARRAY, JSAMPIMAGE, jpeg_decompress_struct::max_v_samp_factor, my_upsampler::methods, my_upsampler::next_row_out, jpeg_decompress_struct::num_components, num_rows, my_upsampler::rowgroup_height, my_upsampler::rows_to_go, and jpeg_decompress_struct::upsample.

Referenced by jinit_upsampler().

00094 {
00095   my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
00096   int ci;
00097   jpeg_component_info * compptr;
00098   JDIMENSION num_rows;
00099 
00100   /* Fill the conversion buffer, if it's empty */
00101   if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
00102     for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
00103          ci++, compptr++) {
00104       /* Invoke per-component upsample method.  Notice we pass a POINTER
00105        * to color_buf[ci], so that fullsize_upsample can change it.
00106        */
00107       (*upsample->methods[ci]) (cinfo, compptr,
00108         input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
00109         upsample->color_buf + ci);
00110     }
00111     upsample->next_row_out = 0;
00112   }
00113 
00114   /* Color-convert and emit rows */
00115 
00116   /* How many we have in the buffer: */
00117   num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
00118   /* Not more than the distance to the end of the image.  Need this test
00119    * in case the image height is not a multiple of max_v_samp_factor:
00120    */
00121   if (num_rows > upsample->rows_to_go) 
00122     num_rows = upsample->rows_to_go;
00123   /* And not more than what the client can accept: */
00124   out_rows_avail -= *out_row_ctr;
00125   if (num_rows > out_rows_avail)
00126     num_rows = out_rows_avail;
00127 
00128   (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
00129                                      (JDIMENSION) upsample->next_row_out,
00130                                      output_buf + *out_row_ctr,
00131                                      (int) num_rows);
00132 
00133   /* Adjust counts */
00134   *out_row_ctr += num_rows;
00135   upsample->rows_to_go -= num_rows;
00136   upsample->next_row_out += num_rows;
00137   /* When the buffer is emptied, declare this input row group consumed */
00138   if (upsample->next_row_out >= cinfo->max_v_samp_factor)
00139     (*in_row_group_ctr)++;
00140 }

start_pass_upsample j_decompress_ptr    cinfo
 

Definition at line 69 of file jdsample.c.

References jpeg_decompress_struct::max_v_samp_factor, my_upsampler::next_row_out, jpeg_decompress_struct::output_height, my_upsampler::rows_to_go, and jpeg_decompress_struct::upsample.

Referenced by jinit_upsampler().

00070 {
00071   my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
00072 
00073   /* Mark the conversion buffer empty */
00074   upsample->next_row_out = cinfo->max_v_samp_factor;
00075   /* Initialize total-height counter for detecting bottom of image */
00076   upsample->rows_to_go = cinfo->output_height;
00077 }
 

Powered by Plone

This site conforms to the following standards: