Related: rhbz#1602602 fix more clang warnings

This commit is contained in:
Caolán McNamara 2018-08-10 11:55:23 +01:00
parent 0fd82b99cb
commit c062ce6024
2 changed files with 509 additions and 9 deletions

View File

@ -121,10 +121,122 @@ index b37fc2c..c7f3aa0 100644
gdFree (row_pointers);
diff --git a/src/extra/gd/gd_topal.c b/src/extra/gd/gd_topal.c
index 4ca86c9..69ca4d1 100644
index 4ca86c9..ff62507 100644
--- a/src/extra/gd/gd_topal.c
+++ b/src/extra/gd/gd_topal.c
@@ -1031,7 +1031,6 @@ find_best_colors (gdImagePtr im,
@@ -199,65 +199,6 @@ my_cquantizer;
typedef my_cquantizer *my_cquantize_ptr;
-/*
- * Prescan the pixel array.
- *
- * The prescan simply updates the histogram, which has been
- * initialized to zeroes by start_pass.
- *
- */
-
-static void
-prescan_quantize (gdImagePtr im, my_cquantize_ptr cquantize)
-{
- register histptr histp;
- register hist4d histogram = cquantize->histogram;
- int row;
- int col;
- int *ptr;
- int width = im->sx;
-
- for (row = 0; row < im->sy; row++)
- {
- ptr = im->tpixels[row];
- for (col = width; col > 0; col--)
- {
- /* get pixel value and index into the histogram */
- int r, g, b, a;
- r = gdTrueColorGetRed (*ptr) >> C0_SHIFT;
- g = gdTrueColorGetGreen (*ptr) >> C1_SHIFT;
- b = gdTrueColorGetBlue (*ptr) >> C2_SHIFT;
- a = gdTrueColorGetAlpha (*ptr);
- /* We must have 100% opacity and transparency available
- in the color map to do an acceptable job with alpha
- channel, if opacity and transparency are present in the
- original, because of the visual properties of large
- flat-color border areas (requiring 100% transparency)
- and the behavior of poorly implemented browsers
- (requiring 100% opacity). Test for the presence of
- these here, and rescale the most opaque and transparent
- palette entries at the end if so. This avoids the need
- to develop a fuller understanding I have not been able
- to reach so far in my study of this subject. TBB */
- if (a == gdAlphaTransparent)
- {
- cquantize->transparentIsPresent = 1;
- }
- if (a == gdAlphaOpaque)
- {
- cquantize->opaqueIsPresent = 1;
- }
- a >>= C3_SHIFT;
- histp = &histogram[r][g][b][a];
- /* increment, check for overflow and undo increment if so. */
- if (++(*histp) <= 0)
- (*histp)--;
- ptr++;
- }
- }
-}
-
-
/*
* Next we have the really interesting routines: selection of a colormap
* given the completed histogram.
@@ -671,45 +612,6 @@ compute_color (gdImagePtr im, my_cquantize_ptr cquantize,
}
}
-static void
-select_colors (gdImagePtr im, my_cquantize_ptr cquantize, int desired_colors)
-/* Master routine for color selection */
-{
- boxptr boxlist;
- int numboxes;
- int i;
-
- /* Allocate workspace for box list */
- boxlist = (boxptr) gdMalloc (desired_colors * sizeof (box));
- /* Initialize one box containing whole space */
- numboxes = 1;
- /* Note maxval for alpha is different */
- boxlist[0].c0min = 0;
- boxlist[0].c0max = 255 >> C0_SHIFT;
- boxlist[0].c1min = 0;
- boxlist[0].c1max = 255 >> C1_SHIFT;
- boxlist[0].c2min = 0;
- boxlist[0].c2max = 255 >> C2_SHIFT;
- boxlist[0].c3min = 0;
- boxlist[0].c3max = gdAlphaMax >> C3_SHIFT;
- /* Shrink it to actually-used volume and set its statistics */
- update_box (cquantize, &boxlist[0]);
- /* Perform median-cut to produce final box list */
- numboxes = median_cut (cquantize, boxlist, numboxes, desired_colors);
- /* Compute the representative color for each box, fill colormap */
- for (i = 0; i < numboxes; i++)
- compute_color (im, cquantize, &boxlist[i], i);
- /* TBB: if the image contains colors at both scaled ends
- of the alpha range, rescale slightly to make sure alpha
- covers the full spectrum from 100% transparent to 100%
- opaque. Even a faint distinct background color is
- generally considered failure with regard to alpha. */
-
- im->colorsTotal = numboxes;
- gdFree (boxlist);
-}
-
-
/*
* These routines are concerned with the time-critical task of mapping input
* colors to the nearest color in the selected colormap.
@@ -1031,7 +933,6 @@ find_best_colors (gdImagePtr im,
inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
@ -132,11 +244,377 @@ index 4ca86c9..69ca4d1 100644
/* Now loop over all cells in box, updating distance per Thomas method */
bptr = bestdist;
cptr = bestcolor;
@@ -1499,200 +1498,3 @@ zeroHistogram (hist4d histogram)
@@ -1133,566 +1034,3 @@ fill_inverse_cmap (gdImagePtr im, my_cquantize_ptr cquantize,
}
}
}
-
-
-/*
- * Map some rows of pixels to the output colormapped representation.
- */
-
-static void
-pass2_no_dither (gdImagePtr im, my_cquantize_ptr cquantize)
-/* This version performs no dithering */
-{
- hist4d histogram = cquantize->histogram;
- register int *inptr;
- register unsigned char *outptr;
- register histptr cachep;
- register int c0, c1, c2, c3;
- int row;
- int col;
- int width = im->sx;
- int num_rows = im->sy;
- for (row = 0; row < num_rows; row++)
- {
- inptr = im->tpixels[row];
- outptr = im->pixels[row];
- for (col = 0; col < width; col++)
- {
- int r, g, b, a;
- /* get pixel value and index into the cache */
- r = gdTrueColorGetRed (*inptr);
- g = gdTrueColorGetGreen (*inptr);
- b = gdTrueColorGetBlue (*inptr);
- a = gdTrueColorGetAlpha (*inptr++);
- c0 = r >> C0_SHIFT;
- c1 = g >> C1_SHIFT;
- c2 = b >> C2_SHIFT;
- c3 = a >> C3_SHIFT;
- cachep = &histogram[c0][c1][c2][c3];
- /* If we have not seen this color before, find nearest colormap entry */
- /* and update the cache */
- if (*cachep == 0)
- {
-#if 0
- /* TBB: quick and dirty approach for use when testing
- fill_inverse_cmap for errors */
- int i;
- int best = -1;
- int mindist = 0x7FFFFFFF;
- for (i = 0; (i < im->colorsTotal); i++)
- {
- int rdist = (im->red[i] >> C0_SHIFT) - c0;
- int gdist = (im->green[i] >> C1_SHIFT) - c1;
- int bdist = (im->blue[i] >> C2_SHIFT) - c2;
- int adist = (im->alpha[i] >> C3_SHIFT) - c3;
- int dist = (rdist * rdist) * R_SCALE +
- (gdist * gdist) * G_SCALE +
- (bdist * bdist) * B_SCALE +
- (adist * adist) * A_SCALE;
- if (dist < mindist)
- {
- best = i;
- mindist = dist;
- }
- }
- *cachep = best + 1;
-#endif
- fill_inverse_cmap (im, cquantize, c0, c1, c2, c3);
- }
- /* Now emit the colormap index for this cell */
- *outptr++ = (*cachep - 1);
- }
- }
-}
-
-/* We assume that right shift corresponds to signed division by 2 with
- * rounding towards minus infinity. This is correct for typical "arithmetic
- * shift" instructions that shift in copies of the sign bit. But some
- * C compilers implement >> with an unsigned shift. For these machines you
- * must define RIGHT_SHIFT_IS_UNSIGNED.
- * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.
- * It is only applied with constant shift counts. SHIFT_TEMPS must be
- * included in the variables of any routine using RIGHT_SHIFT.
- */
-
-#ifdef RIGHT_SHIFT_IS_UNSIGNED
-#define SHIFT_TEMPS INT32 shift_temp;
-#define RIGHT_SHIFT(x,shft) \
- ((shift_temp = (x)) < 0 ? \
- (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
- (shift_temp >> (shft)))
-#else
-#define SHIFT_TEMPS
-#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
-#endif
-
-
-static void
-pass2_fs_dither (gdImagePtr im, my_cquantize_ptr cquantize)
-
-/* This version performs Floyd-Steinberg dithering */
-{
- hist4d histogram = cquantize->histogram;
- register LOCFSERROR cur0, cur1, cur2, cur3; /* current error or pixel value */
- LOCFSERROR belowerr0, belowerr1, belowerr2, belowerr3; /* error for pixel below cur */
- LOCFSERROR bpreverr0, bpreverr1, bpreverr2, bpreverr3; /* error for below/prev col */
- register FSERRPTR errorptr; /* => fserrors[] at column before current */
- int *inptr; /* => current input pixel */
- unsigned char *outptr; /* => current output pixel */
- histptr cachep;
- int dir; /* +1 or -1 depending on direction */
- int dir4; /* 4*dir, for advancing errorptr */
- int row;
- int col;
- int width = im->sx;
- int num_rows = im->sy;
- int *error_limit = cquantize->error_limiter;
- int *colormap0 = im->red;
- int *colormap1 = im->green;
- int *colormap2 = im->blue;
- int *colormap3 = im->alpha;
- SHIFT_TEMPS
-
- for (row = 0; row < num_rows; row++)
- {
- inptr = im->tpixels[row];
- outptr = im->pixels[row];
- if (cquantize->on_odd_row)
- {
- /* work right to left in this row */
- inptr += (width - 1); /* so point to rightmost pixel */
- outptr += width - 1;
- dir = -1;
- dir4 = -4;
- errorptr = cquantize->fserrors + (width + 1) * 4; /* => entry after last column */
- cquantize->on_odd_row = FALSE; /* flip for next time */
- }
- else
- {
- /* work left to right in this row */
- dir = 1;
- dir4 = 4;
- errorptr = cquantize->fserrors; /* => entry before first real column */
- cquantize->on_odd_row = TRUE; /* flip for next time */
- }
- /* Preset error values: no error propagated to first pixel from left */
- cur0 = cur1 = cur2 = cur3 = 0;
- /* and no error propagated to row below yet */
- belowerr0 = belowerr1 = belowerr2 = belowerr3 = 0;
- bpreverr0 = bpreverr1 = bpreverr2 = bpreverr3 = 0;
-
- for (col = width; col > 0; col--)
- {
- int a;
- /* curN holds the error propagated from the previous pixel on the
- * current line. Add the error propagated from the previous line
- * to form the complete error correction term for this pixel, and
- * round the error term (which is expressed * 16) to an integer.
- * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
- * for either sign of the error value.
- * Note: errorptr points to *previous* column's array entry.
- */
- cur0 = RIGHT_SHIFT (cur0 + errorptr[dir4 + 0] + 8, 4);
- cur1 = RIGHT_SHIFT (cur1 + errorptr[dir4 + 1] + 8, 4);
- cur2 = RIGHT_SHIFT (cur2 + errorptr[dir4 + 2] + 8, 4);
- cur3 = RIGHT_SHIFT (cur3 + errorptr[dir4 + 3] + 8, 4);
- /* Limit the error using transfer function set by init_error_limit.
- * See comments with init_error_limit for rationale.
- */
- cur0 = error_limit[cur0];
- cur1 = error_limit[cur1];
- cur2 = error_limit[cur2];
- cur3 = error_limit[cur3];
- /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
- * The maximum error is +- MAXJSAMPLE (or less with error limiting);
- * but we'll be lazy and just clamp this with an if test (TBB).
- */
- cur0 += gdTrueColorGetRed (*inptr);
- cur1 += gdTrueColorGetGreen (*inptr);
- cur2 += gdTrueColorGetBlue (*inptr);
- /* Expand to 8 bits for consistency with dithering algorithm -- TBB */
- a = gdTrueColorGetAlpha (*inptr);
- cur3 += (a << 1) + (a >> 6);
- if (cur0 < 0)
- {
- cur0 = 0;
- }
- if (cur0 > 255)
- {
- cur0 = 255;
- }
- if (cur1 < 0)
- {
- cur1 = 0;
- }
- if (cur1 > 255)
- {
- cur1 = 255;
- }
- if (cur2 < 0)
- {
- cur2 = 0;
- }
- if (cur2 > 255)
- {
- cur2 = 255;
- }
- if (cur3 < 0)
- {
- cur3 = 0;
- }
- if (cur3 > 255)
- {
- cur3 = 255;
- }
- /* Index into the cache with adjusted pixel value */
- cachep = &histogram
- [cur0 >> C0_SHIFT]
- [cur1 >> C1_SHIFT]
- [cur2 >> C2_SHIFT]
- [cur3 >> (C3_SHIFT + 1)];
- /* If we have not seen this color before, find nearest colormap */
- /* entry and update the cache */
- if (*cachep == 0)
- fill_inverse_cmap (im, cquantize,
- cur0 >> C0_SHIFT, cur1 >> C1_SHIFT, cur2 >> C2_SHIFT,
- cur3 >> (C3_SHIFT + 1));
- /* Now emit the colormap index for this cell */
- {
- register int pixcode = *cachep - 1;
- *outptr = pixcode;
- /* Compute representation error for this pixel */
- cur0 -= colormap0[pixcode];
- cur1 -= colormap1[pixcode];
- cur2 -= colormap2[pixcode];
- cur3 -= ((colormap3[pixcode] << 1) + (colormap3[pixcode] >> 6));
- }
- /* Compute error fractions to be propagated to adjacent pixels.
- * Add these into the running sums, and simultaneously shift the
- * next-line error sums left by 1 column.
- */
- {
- register LOCFSERROR bnexterr, delta;
-
- bnexterr = cur0; /* Process component 0 */
- delta = cur0 * 2;
- cur0 += delta; /* form error * 3 */
- errorptr[0] = (FSERROR) (bpreverr0 + cur0);
- cur0 += delta; /* form error * 5 */
- bpreverr0 = belowerr0 + cur0;
- belowerr0 = bnexterr;
- cur0 += delta; /* form error * 7 */
- bnexterr = cur1; /* Process component 1 */
- delta = cur1 * 2;
- cur1 += delta; /* form error * 3 */
- errorptr[1] = (FSERROR) (bpreverr1 + cur1);
- cur1 += delta; /* form error * 5 */
- bpreverr1 = belowerr1 + cur1;
- belowerr1 = bnexterr;
- cur1 += delta; /* form error * 7 */
- bnexterr = cur2; /* Process component 2 */
- delta = cur2 * 2;
- cur2 += delta; /* form error * 3 */
- errorptr[2] = (FSERROR) (bpreverr2 + cur2);
- cur2 += delta; /* form error * 5 */
- bpreverr2 = belowerr2 + cur2;
- belowerr2 = bnexterr;
- cur2 += delta; /* form error * 7 */
- bnexterr = cur3; /* Process component 3 */
- delta = cur3 * 2;
- cur3 += delta; /* form error * 3 */
- errorptr[3] = (FSERROR) (bpreverr3 + cur3);
- cur3 += delta; /* form error * 5 */
- bpreverr3 = belowerr3 + cur3;
- belowerr3 = bnexterr;
- cur3 += delta; /* form error * 7 */
- }
- /* At this point curN contains the 7/16 error value to be propagated
- * to the next pixel on the current line, and all the errors for the
- * next line have been shifted over. We are therefore ready to move on.
- */
- inptr += dir; /* Advance pixel pointers to next column */
- outptr += dir;
- errorptr += dir4; /* advance errorptr to current column */
- }
- /* Post-loop cleanup: we must unload the final error values into the
- * final fserrors[] entry. Note we need not unload belowerrN because
- * it is for the dummy column before or after the actual array.
- */
- errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
- errorptr[1] = (FSERROR) bpreverr1;
- errorptr[2] = (FSERROR) bpreverr2;
- errorptr[3] = (FSERROR) bpreverr3;
- }
-}
-
-
-/*
- * Initialize the error-limiting transfer function (lookup table).
- * The raw F-S error computation can potentially compute error values of up to
- * +- MAXJSAMPLE. But we want the maximum correction applied to a pixel to be
- * much less, otherwise obviously wrong pixels will be created. (Typical
- * effects include weird fringes at color-area boundaries, isolated bright
- * pixels in a dark area, etc.) The standard advice for avoiding this problem
- * is to ensure that the "corners" of the color cube are allocated as output
- * colors; then repeated errors in the same direction cannot cause cascading
- * error buildup. However, that only prevents the error from getting
- * completely out of hand; Aaron Giles reports that error limiting improves
- * the results even with corner colors allocated.
- * A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty
- * well, but the smoother transfer function used below is even better. Thanks
- * to Aaron Giles for this idea.
- */
-
-static int
-init_error_limit (my_cquantize_ptr cquantize)
-/* Allocate and fill in the error_limiter table */
-{
- int *table;
- int in, out;
-
- cquantize->error_limiter_storage = (int *) gdMalloc ((255 * 2 + 1) * sizeof (int));
- if (!cquantize->error_limiter_storage)
- {
- return 0;
- }
- /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
- cquantize->error_limiter = cquantize->error_limiter_storage + 255;
- table = cquantize->error_limiter;
-#define STEPSIZE ((255+1)/16)
- /* Map errors 1:1 up to +- MAXJSAMPLE/16 */
- out = 0;
- for (in = 0; in < STEPSIZE; in++, out++)
- {
- table[in] = out;
- table[-in] = -out;
- }
- /* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */
- for (; in < STEPSIZE * 3; in++, out += (in & 1) ? 0 : 1)
- {
- table[in] = out;
- table[-in] = -out;
- }
- /* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */
- for (; in <= 255; in++)
- {
- table[in] = out;
- table[-in] = -out;
- }
-#undef STEPSIZE
- return 1;
-}
-
-static void
-zeroHistogram (hist4d histogram)
-{
- int i;
- int j;
- /* Zero the histogram or inverse color map */
- for (i = 0; i < HIST_C0_ELEMS; i++)
- {
- for (j = 0; j < HIST_C1_ELEMS; j++)
- {
- memset (histogram[i][j],
- 0,
- HIST_C2_ELEMS * HIST_C3_ELEMS * sizeof (histcell));
- }
- }
-}
-
-/* Here we go at last. */
-void
-gdImageTrueColorToPalette (gdImagePtr im, int dither, int colorsWanted)
@ -372,17 +850,36 @@ index e4770f5..ff65b97 100644
(*(head->gdCacheRelease)) (elem->userdata);
}
diff --git a/src/extra/gd/gdft.c b/src/extra/gd/gdft.c
index b1e9414..422e1ae 100644
index b1e9414..4aa0f74 100644
--- a/src/extra/gd/gdft.c
+++ b/src/extra/gd/gdft.c
@@ -636,6 +636,7 @@ gdft_draw_bitmap (gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
}
tc_elem = (tweencolor_t *) gdCacheGet (
tc_cache, &tc_key);
@@ -625,23 +625,17 @@ gdft_draw_bitmap (gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y)
}
else
{
+ tc_elem = (tweencolor_t *) gdCacheGet (tc_cache, &tc_key);
+ if (!tc_elem) return tc_cache->error;
/* find antialised color */
if (im->trueColor)
{
tc_key.bgcolor = *tpixel;
- }
- else
- {
- tc_key.bgcolor = *pixel;
- }
- tc_elem = (tweencolor_t *) gdCacheGet (
- tc_cache, &tc_key);
- if (im->trueColor)
- {
*tpixel = tc_elem->tweencolor;
}
else
{
+ tc_key.bgcolor = *pixel;
*pixel = tc_elem->tweencolor;
}
}
diff --git a/src/extra/gd/testac.c b/src/extra/gd/testac.c
index 55a5434..47d466d 100644
--- a/src/extra/gd/testac.c

View File

@ -1,7 +1,7 @@
Summary: Windows MetaFile Library
Name: libwmf
Version: 0.2.9
Release: 2%{?dist}
Release: 3%{?dist}
Group: System Environment/Libraries
#libwmf is under the LGPLv2+, however...
#1. The tarball contains an old version of the urw-fonts under GPL+.
@ -101,6 +101,9 @@ sed -i $RPM_BUILD_ROOT%{_datadir}/libwmf/fonts/fontmap -e 's#libwmf/fonts#fonts/
%changelog
* Fri Aug 10 2018 Caolán McNamara <caolanm@redhat.com> - 0.2.9-3
- Related: rhbz#1602602 fix more clang warnings
* Fri Aug 10 2018 Caolán McNamara <caolanm@redhat.com> - 0.2.9-2
- Related: rhbz#1602602 fix clang warnings