]> Creatis software - gdcm.git/blobdiff - src/jpeg/libijg8/jcsample.c
ENH: Remove old build process for libijg12 (meaning modified source files)
[gdcm.git] / src / jpeg / libijg8 / jcsample.c
index 212ec8757c4ca865eba34a80530d42e8d371dec7..1e82aa7ba7890af39e19ba0de2e03a3312727b0f 100644 (file)
 
 /* Pointer to routine to downsample a single component */
 typedef JMETHOD(void, downsample1_ptr,
-               (j_compress_ptr cinfo, jpeg_component_info * compptr,
-                JSAMPARRAY input_data, JSAMPARRAY output_data));
+    (j_compress_ptr cinfo, jpeg_component_info * compptr,
+     JSAMPARRAY input_data, JSAMPARRAY output_data));
 
 /* Private subobject */
 
 typedef struct {
-  struct jpeg_downsampler pub; /* public fields */
+  struct jpeg_downsampler pub;  /* public fields */
 
   /* Downsampling method pointers, one per component */
   downsample1_ptr methods[MAX_COMPONENTS];
@@ -74,6 +74,7 @@ typedef my_downsampler * my_downsample_ptr;
 METHODDEF(void)
 start_pass_downsample (j_compress_ptr cinfo)
 {
+  cinfo = 0;
   /* no work for now */
 }
 
@@ -85,7 +86,7 @@ start_pass_downsample (j_compress_ptr cinfo)
 
 LOCAL(void)
 expand_right_edge (JSAMPARRAY image_data, int num_rows,
-                  JDIMENSION input_cols, JDIMENSION output_cols)
+       JDIMENSION input_cols, JDIMENSION output_cols)
 {
   register JSAMPROW ptr;
   register JSAMPLE pixval;
@@ -96,9 +97,9 @@ expand_right_edge (JSAMPARRAY image_data, int num_rows,
   if (numcols > 0) {
     for (row = 0; row < num_rows; row++) {
       ptr = image_data[row] + input_cols;
-      pixval = ptr[-1];                /* don't need GETJSAMPLE() here */
+      pixval = ptr[-1];    /* don't need GETJSAMPLE() here */
       for (count = numcols; count > 0; count--)
-       *ptr++ = pixval;
+  *ptr++ = pixval;
     }
   }
 }
@@ -112,8 +113,8 @@ expand_right_edge (JSAMPARRAY image_data, int num_rows,
 
 METHODDEF(void)
 sep_downsample (j_compress_ptr cinfo,
-               JSAMPIMAGE input_buf, JDIMENSION in_row_index,
-               JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
+    JSAMPIMAGE input_buf, JDIMENSION in_row_index,
+    JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
 {
   my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
   int ci;
@@ -138,10 +139,10 @@ sep_downsample (j_compress_ptr cinfo,
 
 METHODDEF(void)
 int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
-               JSAMPARRAY input_data, JSAMPARRAY output_data)
+    JSAMPARRAY input_data, JSAMPARRAY output_data)
 {
   int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
-  JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
+  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
   JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
   JSAMPROW inptr, outptr;
   INT32 outvalue;
@@ -156,19 +157,19 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
    * efficient.
    */
   expand_right_edge(input_data, cinfo->max_v_samp_factor,
-                   cinfo->image_width, output_cols * h_expand);
+        cinfo->image_width, output_cols * h_expand);
 
   inrow = 0;
   for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
     outptr = output_data[outrow];
     for (outcol = 0, outcol_h = 0; outcol < output_cols;
-        outcol++, outcol_h += h_expand) {
+   outcol++, outcol_h += h_expand) {
       outvalue = 0;
       for (v = 0; v < v_expand; v++) {
-       inptr = input_data[inrow+v] + outcol_h;
-       for (h = 0; h < h_expand; h++) {
-         outvalue += (INT32) GETJSAMPLE(*inptr++);
-       }
+  inptr = input_data[inrow+v] + outcol_h;
+  for (h = 0; h < h_expand; h++) {
+    outvalue += (INT32) GETJSAMPLE(*inptr++);
+  }
       }
       *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
     }
@@ -185,14 +186,14 @@ int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
 
 METHODDEF(void)
 fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
-                    JSAMPARRAY input_data, JSAMPARRAY output_data)
+         JSAMPARRAY input_data, JSAMPARRAY output_data)
 {
   /* Copy the data */
   jcopy_sample_rows(input_data, 0, output_data, 0,
-                   cinfo->max_v_samp_factor, cinfo->image_width);
+        cinfo->max_v_samp_factor, cinfo->image_width);
   /* Edge-expand */
   expand_right_edge(output_data, cinfo->max_v_samp_factor,
-                   cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
+        cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
 }
 
 
@@ -210,7 +211,7 @@ fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
 
 METHODDEF(void)
 h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
-                JSAMPARRAY input_data, JSAMPARRAY output_data)
+     JSAMPARRAY input_data, JSAMPARRAY output_data)
 {
   int outrow;
   JDIMENSION outcol;
@@ -223,16 +224,16 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
    * efficient.
    */
   expand_right_edge(input_data, cinfo->max_v_samp_factor,
-                   cinfo->image_width, output_cols * 2);
+        cinfo->image_width, output_cols * 2);
 
   for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
     outptr = output_data[outrow];
     inptr = input_data[outrow];
-    bias = 0;                  /* bias = 0,1,0,1,... for successive samples */
+    bias = 0;      /* bias = 0,1,0,1,... for successive samples */
     for (outcol = 0; outcol < output_cols; outcol++) {
       *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
-                             + bias) >> 1);
-      bias ^= 1;               /* 0=>1, 1=>0 */
+            + bias) >> 1);
+      bias ^= 1;    /* 0=>1, 1=>0 */
       inptr += 2;
     }
   }
@@ -247,7 +248,7 @@ h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
 
 METHODDEF(void)
 h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
-                JSAMPARRAY input_data, JSAMPARRAY output_data)
+     JSAMPARRAY input_data, JSAMPARRAY output_data)
 {
   int inrow, outrow;
   JDIMENSION outcol;
@@ -260,19 +261,19 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
    * efficient.
    */
   expand_right_edge(input_data, cinfo->max_v_samp_factor,
-                   cinfo->image_width, output_cols * 2);
+        cinfo->image_width, output_cols * 2);
 
   inrow = 0;
   for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
     outptr = output_data[outrow];
     inptr0 = input_data[inrow];
     inptr1 = input_data[inrow+1];
-    bias = 1;                  /* bias = 1,2,1,2,... for successive samples */
+    bias = 1;      /* bias = 1,2,1,2,... for successive samples */
     for (outcol = 0; outcol < output_cols; outcol++) {
       *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
-                             GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
-                             + bias) >> 2);
-      bias ^= 3;               /* 1=>2, 2=>1 */
+            GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
+            + bias) >> 2);
+      bias ^= 3;    /* 1=>2, 2=>1 */
       inptr0 += 2; inptr1 += 2;
     }
     inrow += 2;
@@ -290,7 +291,7 @@ h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
 
 METHODDEF(void)
 h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
-                       JSAMPARRAY input_data, JSAMPARRAY output_data)
+      JSAMPARRAY input_data, JSAMPARRAY output_data)
 {
   int inrow, outrow;
   JDIMENSION colctr;
@@ -303,7 +304,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
    * efficient.
    */
   expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
-                   cinfo->image_width, output_cols * 2);
+        cinfo->image_width, output_cols * 2);
 
   /* We don't bother to form the individual "smoothed" input pixel values;
    * we can directly compute the output which is the average of the four
@@ -331,14 +332,14 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
 
     /* Special case for first column: pretend column -1 is same as column 0 */
     membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
-               GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
+    GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
     neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
-              GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
-              GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
-              GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
+         GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
+         GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
+         GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
     neighsum += neighsum;
     neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
-               GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
+    GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
     membersum = membersum * memberscale + neighsum * neighscale;
     *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
     inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
@@ -346,17 +347,17 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
     for (colctr = output_cols - 2; colctr > 0; colctr--) {
       /* sum of pixels directly mapped to this output element */
       membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
-                 GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
+      GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
       /* sum of edge-neighbor pixels */
       neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
-                GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
-                GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
-                GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
+     GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
+     GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
+     GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
       /* The edge-neighbors count twice as much as corner-neighbors */
       neighsum += neighsum;
       /* Add in the corner-neighbors */
       neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
-                 GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
+      GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
       /* form final output scaled up by 2^16 */
       membersum = membersum * memberscale + neighsum * neighscale;
       /* round, descale and output it */
@@ -366,14 +367,14 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
 
     /* Special case for last column */
     membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
-               GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
+    GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
     neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
-              GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
-              GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
-              GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
+         GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
+         GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
+         GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
     neighsum += neighsum;
     neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
-               GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
+    GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
     membersum = membersum * memberscale + neighsum * neighscale;
     *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
 
@@ -390,7 +391,7 @@ h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
 
 METHODDEF(void)
 fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
-                           JSAMPARRAY input_data, JSAMPARRAY output_data)
+          JSAMPARRAY input_data, JSAMPARRAY output_data)
 {
   int outrow;
   JDIMENSION colctr;
@@ -404,7 +405,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
    * efficient.
    */
   expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
-                   cinfo->image_width, output_cols);
+        cinfo->image_width, output_cols);
 
   /* Each of the eight neighbor pixels contributes a fraction SF to the
    * smoothed pixel, while the main pixel contributes (1-8*SF).  In order
@@ -423,10 +424,10 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
 
     /* Special case for first column */
     colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
-            GETJSAMPLE(*inptr);
+       GETJSAMPLE(*inptr);
     membersum = GETJSAMPLE(*inptr++);
     nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
-                GETJSAMPLE(*inptr);
+     GETJSAMPLE(*inptr);
     neighsum = colsum + (colsum - membersum) + nextcolsum;
     membersum = membersum * memberscale + neighsum * neighscale;
     *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
@@ -436,7 +437,7 @@ fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
       membersum = GETJSAMPLE(*inptr++);
       above_ptr++; below_ptr++;
       nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
-                  GETJSAMPLE(*inptr);
+       GETJSAMPLE(*inptr);
       neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
       membersum = membersum * memberscale + neighsum * neighscale;
       *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
@@ -470,7 +471,7 @@ jinit_downsampler (j_compress_ptr cinfo)
 
   downsample = (my_downsample_ptr)
     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
-                               SIZEOF(my_downsampler));
+        SIZEOF(my_downsampler));
   cinfo->downsample = (struct jpeg_downsampler *) downsample;
   downsample->pub.start_pass = start_pass_downsample;
   downsample->pub.downsample = sep_downsample;
@@ -483,29 +484,29 @@ jinit_downsampler (j_compress_ptr cinfo)
   for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
        ci++, compptr++) {
     if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
-       compptr->v_samp_factor == cinfo->max_v_samp_factor) {
+  compptr->v_samp_factor == cinfo->max_v_samp_factor) {
 #ifdef INPUT_SMOOTHING_SUPPORTED
       if (cinfo->smoothing_factor) {
-       downsample->methods[ci] = fullsize_smooth_downsample;
-       downsample->pub.need_context_rows = TRUE;
+  downsample->methods[ci] = fullsize_smooth_downsample;
+  downsample->pub.need_context_rows = TRUE;
       } else
 #endif
-       downsample->methods[ci] = fullsize_downsample;
+  downsample->methods[ci] = fullsize_downsample;
     } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
-              compptr->v_samp_factor == cinfo->max_v_samp_factor) {
+         compptr->v_samp_factor == cinfo->max_v_samp_factor) {
       smoothok = FALSE;
       downsample->methods[ci] = h2v1_downsample;
     } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
-              compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
+         compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
 #ifdef INPUT_SMOOTHING_SUPPORTED
       if (cinfo->smoothing_factor) {
-       downsample->methods[ci] = h2v2_smooth_downsample;
-       downsample->pub.need_context_rows = TRUE;
+  downsample->methods[ci] = h2v2_smooth_downsample;
+  downsample->pub.need_context_rows = TRUE;
       } else
 #endif
-       downsample->methods[ci] = h2v2_downsample;
+  downsample->methods[ci] = h2v2_downsample;
     } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
-              (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
+         (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
       smoothok = FALSE;
       downsample->methods[ci] = int_downsample;
     } else