libwmf/covscan.patch
2018-08-10 11:55:23 +01:00

1176 lines
35 KiB
Diff

diff --git a/src/extra/gd/gd.c b/src/extra/gd/gd.c
index 6296472..dc6a9a7 100644
--- a/src/extra/gd/gd.c
+++ b/src/extra/gd/gd.c
@@ -1995,7 +1995,7 @@ gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX
else
{
/* Find or create the best match */
- mapTo = gdImageColorResolveAlpha (dst,
+ nc = gdImageColorResolveAlpha (dst,
gdTrueColorGetRed (c),
gdTrueColorGetGreen (c),
gdTrueColorGetBlue (c),
diff --git a/src/extra/gd/gd.h b/src/extra/gd/gd.h
index 619ddd3..8c19354 100644
--- a/src/extra/gd/gd.h
+++ b/src/extra/gd/gd.h
@@ -308,24 +308,6 @@ int gdImageColorResolveAlpha(gdImagePtr im, int r, int g, int b, int a);
void gdImageColorDeallocate(gdImagePtr im, int color);
-/* Converts a truecolor image to a palette-based image,
- using a high-quality two-pass quantization routine
- which attempts to preserve alpha channel information
- as well as R/G/B color information when creating
- a palette. If ditherFlag is set, the image will be
- dithered to approximate colors better, at the expense
- of some obvious "speckling." colorsWanted can be
- anything up to 256. If the original source image
- includes photographic information or anything that
- came out of a JPEG, 256 is strongly recommended.
-
- Better yet, don't use this function -- write real
- truecolor PNGs and JPEGs. The disk space gain of
- conversion to palette is not great (for small images
- it can be negative) and the quality loss is ugly. */
-
-void gdImageTrueColorToPalette(gdImagePtr im, int ditherFlag, int colorsWanted);
-
/* Specifies a color index (if a palette image) or an
RGB color (if a truecolor image) which should be
considered 100% transparent. FOR TRUECOLOR IMAGES,
diff --git a/src/extra/gd/gd_gd2.c b/src/extra/gd/gd_gd2.c
index 602b869..05d8dcb 100644
--- a/src/extra/gd/gd_gd2.c
+++ b/src/extra/gd/gd_gd2.c
@@ -361,7 +361,7 @@ gdImageCreateFromGd2Ctx (gdIOCtxPtr in)
xhi = im->sx;
};
/*GD2_DBG(printf("y=%d: ",y)); */
- if (fmt == GD2_FMT_RAW)
+ if (fmt != GD2_FMT_COMPRESSED)
{
for (x = xlo; x < xhi; x++)
{
@@ -617,7 +617,7 @@ gdImageCreateFromGd2PartCtx (gdIOCtx * in, int srcx, int srcy, int w, int h)
for (x = xlo; x < xhi; x++)
{
- if (fmt == GD2_FMT_RAW)
+ if (fmt != GD2_FMT_COMPRESSED)
{
if (im->trueColor)
{
diff --git a/src/extra/gd/gd_png.c b/src/extra/gd/gd_png.c
index b37fc2c..c7f3aa0 100644
--- a/src/extra/gd/gd_png.c
+++ b/src/extra/gd/gd_png.c
@@ -131,7 +131,6 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
gdImagePtr im = NULL;
int i, j, *open;
volatile int transparent = -1;
- volatile int palette_allocated = FALSE;
/* Make sure the signature can't match by dumb luck -- TBB */
memset (sig, 0, sizeof (sig));
@@ -177,6 +176,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
}
#endif
open = NULL;
+ palette = NULL;
png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
@@ -254,7 +254,6 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
gdImageDestroy(im);
return NULL;
}
- palette_allocated = TRUE;
if (bit_depth < 8)
{
num_palette = 1 << bit_depth;
@@ -321,8 +320,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
fprintf (stderr, "gd-png error: cannot allocate image data\n");
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
gdImageDestroy(im);
- if (palette_allocated)
- gdFree (palette);
+ gdFree(palette);
return NULL;
}
if ((row_pointers = (png_bytepp) gdMalloc (height * sizeof (png_bytep))) == NULL)
@@ -331,8 +329,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
gdFree (image_data);
gdImageDestroy(im);
- if (palette_allocated)
- gdFree (palette);
+ gdFree(palette);
return NULL;
}
@@ -429,8 +426,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
}
#endif
- if (palette_allocated)
- gdFree (palette);
+ gdFree (palette);
gdFree (image_data);
gdFree (row_pointers);
diff --git a/src/extra/gd/gd_topal.c b/src/extra/gd/gd_topal.c
index 4ca86c9..ff62507 100644
--- a/src/extra/gd/gd_topal.c
+++ b/src/extra/gd/gd_topal.c
@@ -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;
- inc3 = inc3 * (2 * STEP_C3) + STEP_C3 * STEP_C3;
/* Now loop over all cells in box, updating distance per Thomas method */
bptr = bestdist;
cptr = bestcolor;
@@ -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)
-{
- my_cquantize_ptr cquantize = 0;
- int i;
- size_t arraysize;
- if (!im->trueColor)
- {
- /* Nothing to do! */
- return;
- }
- if (colorsWanted > gdMaxColors)
- {
- colorsWanted = gdMaxColors;
- }
- im->pixels = gdCalloc (sizeof (unsigned char *), im->sy);
- if (!im->pixels)
- {
- /* No can do */
- goto outOfMemory;
- }
- for (i = 0; (i < im->sy); i++)
- {
- im->pixels[i] = (unsigned char *) gdCalloc (sizeof (unsigned char), im->sx);
- if (!im->pixels[i])
- {
- goto outOfMemory;
- }
- }
- cquantize = (my_cquantize_ptr) gdCalloc (sizeof (my_cquantizer), 1);
- if (!cquantize)
- {
- /* No can do */
- goto outOfMemory;
- }
- /* Allocate the histogram/inverse colormap storage */
- cquantize->histogram = (hist4d) gdMalloc (HIST_C0_ELEMS * sizeof (hist3d));
- for (i = 0; i < HIST_C0_ELEMS; i++)
- {
- int j;
- cquantize->histogram[i] = (hist3d) gdCalloc (HIST_C1_ELEMS,
- sizeof (hist2d));
- if (!cquantize->histogram[i])
- {
- goto outOfMemory;
- }
- for (j = 0; (j < HIST_C1_ELEMS); j++)
- {
- cquantize->histogram[i][j] = (hist2d) gdCalloc (HIST_C2_ELEMS * HIST_C3_ELEMS,
- sizeof (histcell));
- if (!cquantize->histogram[i][j])
- {
- goto outOfMemory;
- }
- }
- }
- cquantize->fserrors = (FSERRPTR) gdMalloc (4 * sizeof (FSERROR));
- init_error_limit (cquantize);
- arraysize = (size_t) ((im->sx + 2) *
- (4 * sizeof (FSERROR)));
- /* Allocate Floyd-Steinberg workspace. */
- cquantize->fserrors = gdCalloc (arraysize, 1);
- if (!cquantize->fserrors)
- {
- goto outOfMemory;
- }
- cquantize->on_odd_row = FALSE;
-
- /* Do the work! */
- zeroHistogram (cquantize->histogram);
- prescan_quantize (im, cquantize);
- select_colors (im, cquantize, 256);
- /* TBB HACK REMOVE */
- {
- FILE *out = fopen ("palettemap.png", "wb");
- int i;
- gdImagePtr im2 = gdImageCreateTrueColor (256, 256);
- for (i = 0; (i < 256); i++)
- {
- gdImageFilledRectangle (im2, (i % 16) * 16, (i / 16) * 16,
- (i % 16) * 16 + 15, (i / 16) * 16 + 15,
- gdTrueColorAlpha (im->red[i], im->green[i],
- im->blue[i], im->alpha[i]));
- }
- gdImagePng (im2, out);
- fclose (out);
- gdImageDestroy (im2);
- }
- zeroHistogram (cquantize->histogram);
- if (dither)
- {
- pass2_fs_dither (im, cquantize);
- }
- else
- {
- pass2_no_dither (im, cquantize);
- }
- if (cquantize->transparentIsPresent)
- {
- int mt = -1;
- for (i = 0; (i < im->colorsTotal); i++)
- {
- if (im->alpha[i] > mt)
- {
- mt = im->alpha[i];
- }
- }
- for (i = 0; (i < im->colorsTotal); i++)
- {
- if (im->alpha[i] == mt)
- {
- im->alpha[i] = gdAlphaTransparent;
- }
- }
- }
- if (cquantize->opaqueIsPresent)
- {
- int mo = 128;
- int moIndex = -1;
- for (i = 0; (i < im->colorsTotal); i++)
- {
- if (im->alpha[i] < mo)
- {
- moIndex = i;
- mo = im->alpha[i];
- }
- }
- for (i = 0; (i < im->colorsTotal); i++)
- {
- if (im->alpha[i] == mo)
- {
- im->alpha[i] = gdAlphaOpaque;
- }
- }
- }
- /* Success! Get rid of the truecolor image data. */
- im->trueColor = 0;
- /* Junk the truecolor pixels */
- for (i = 0; i < im->sy; i++)
- {
- gdFree (im->tpixels[i]);
- }
- gdFree (im->tpixels);
- im->tpixels = 0;
- /* Tediously free stuff. */
-outOfMemory:
- if (im->trueColor)
- {
- if (im->pixels)
- {
- /* On failure only */
- for (i = 0; i < im->sy; i++)
- {
- if (im->pixels[i])
- {
- gdFree (im->pixels[i]);
- }
- }
- gdFree (im->pixels);
- }
- im->pixels = 0;
- }
-
- if (!cquantize)
- return;
-
- for (i = 0; i < HIST_C0_ELEMS; i++)
- {
- if (cquantize->histogram[i])
- {
- int j;
- for (j = 0; j < HIST_C1_ELEMS; j++)
- {
- if (cquantize->histogram[i][j])
- {
- gdFree (cquantize->histogram[i][j]);
- }
- }
- gdFree (cquantize->histogram[i]);
- }
- }
- if (cquantize->histogram)
- {
- gdFree (cquantize->histogram);
- }
- if (cquantize->fserrors)
- {
- gdFree (cquantize->fserrors);
- }
- if (cquantize->error_limiter_storage)
- {
- gdFree (cquantize->error_limiter_storage);
- }
- gdFree (cquantize);
-}
diff --git a/src/extra/gd/gd_wbmp.c b/src/extra/gd/gd_wbmp.c
index 5281337..f1258da 100644
--- a/src/extra/gd/gd_wbmp.c
+++ b/src/extra/gd/gd_wbmp.c
@@ -105,7 +105,10 @@ gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
/* create the WBMP */
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL)
- fprintf (stderr, "Could not create WBMP\n");
+ {
+ fprintf (stderr, "Could not create WBMP\n");
+ return;
+ }
/* fill up the WBMP structure */
pos = 0;
diff --git a/src/extra/gd/gdcache.c b/src/extra/gd/gdcache.c
index e4770f5..ff65b97 100644
--- a/src/extra/gd/gdcache.c
+++ b/src/extra/gd/gdcache.c
@@ -1,5 +1,6 @@
#include "gd.h"
#include "gdhelpers.h"
+#include <assert.h>
#ifdef HAVE_LIBTTF
#define NEED_CACHE 1
@@ -130,7 +131,9 @@ gdCacheGet (gdCache_head_t * head, void *keydata)
else
{ /* cache full - replace least-recently-used */
/* preveprev becomes new end of list */
- prevprev->next = NULL;
+ assert (prevprev);
+ if (prevprev)
+ prevprev->next = NULL;
elem = prev;
(*(head->gdCacheRelease)) (elem->userdata);
}
diff --git a/src/extra/gd/gdft.c b/src/extra/gd/gdft.c
index b1e9414..4aa0f74 100644
--- a/src/extra/gd/gdft.c
+++ b/src/extra/gd/gdft.c
@@ -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
+++ b/src/extra/gd/testac.c
@@ -115,13 +115,6 @@ testDrawing (
Otherwise the file would typically be slightly larger. */
gdImageSaveAlpha (im_out, !blending);
- /* If requested, convert from truecolor to palette. */
- if (palette)
- {
- /* Dithering, 256 colors. */
- gdImageTrueColorToPalette (im_out, 1, 256);
- }
-
gdImagePng (im_out, out);
fclose (out);
diff --git a/src/extra/trio/strio.c b/src/extra/trio/strio.c
index 0e7196c..c6796af 100644
--- a/src/extra/trio/strio.c
+++ b/src/extra/trio/strio.c
@@ -20,8 +20,6 @@
* - StrToLongDouble
*/
-static const char rcsid[] = "@(#)$Id: strio.c,v 1.1 2001/06/07 08:23:02 fjfranklin Exp $";
-
#if defined(unix) || defined(__xlC__)
# define PLATFORM_UNIX
#elif defined(WIN32) || defined(_WIN32)
diff --git a/src/extra/trio/trio.c b/src/extra/trio/trio.c
index 83a2ce9..930e210 100644
--- a/src/extra/trio/trio.c
+++ b/src/extra/trio/trio.c
@@ -41,8 +41,6 @@
* immediately followed by an 's'.
*/
-static const char rcsid[] = "@(#)$Id: trio.c,v 1.1 2001/06/07 08:23:02 fjfranklin Exp $";
-
#if defined(unix) || defined(__xlC__) /* AIX xlC workaround */
# define PLATFORM_UNIX
#elif defined(AMIGA) && defined(__GNUC__)
diff --git a/src/font.c b/src/font.c
index b3927c9..6b88499 100644
--- a/src/font.c
+++ b/src/font.c
@@ -535,6 +535,8 @@ static void ipa_font_add_api (wmfAPI* API,char* name)
float wmf_ipa_font_stringwidth (wmfAPI* API,wmfFont* font,char* str)
{ FT_Face face = WMF_FONT_FTFACE (font);
+ if (!face) return 0.0;
+
FT_Vector delta;
FT_Bool use_kerning;
@@ -592,6 +594,8 @@ float wmf_ipa_font_stringwidth (wmfAPI* API,wmfFont* font,char* str)
static float ipa_char_position (wmfFont* font,char* str,char* last)
{ FT_Face face = WMF_FONT_FTFACE (font);
+ if (!face) return 0.0;
+
FT_Vector delta;
FT_Bool use_kerning;
@@ -1218,14 +1222,19 @@ static char* ipa_font_gs_readline (wmfAPI* API,FILE* in)
line = more;
if (line == 0)
- { fContinue = wmf_false;
+ {
break;
}
}
if (line == 0) return (0);
- if (fReadExtra) while (buf[strlen(buf)-1] != '\n') fgets (buf,128,in);
+ if (fReadExtra)
+ {
+ while (buf[strlen(buf)-1] != '\n')
+ if (fgets (buf,128,in) == 0)
+ break;
+ }
/* Strip the string */
diff --git a/src/ipa/ipa/bmp.h b/src/ipa/ipa/bmp.h
index 568d26e..94a1a17 100644
--- a/src/ipa/ipa/bmp.h
+++ b/src/ipa/ipa/bmp.h
@@ -947,8 +947,8 @@ static int DecodeImage (wmfBMP* bmp,BMPSource* src,unsigned int compression,unsi
}
/* ?? TODO if (QuantumTick (y,image->rows)) MagickMonitor (LoadImageText,y,image->rows); */
}
- byte = ReadBlobByte (src); /* end of line */
- byte = ReadBlobByte (src);
+ ReadBlobByte (src); /* end of line */
+ ReadBlobByte (src);
return 1;
}
diff --git a/src/ipa/svg.c b/src/ipa/svg.c
index 0692296..9c4adf7 100644
--- a/src/ipa/svg.c
+++ b/src/ipa/svg.c
@@ -156,7 +156,6 @@ static void wmf_svg_draw_text (wmfAPI* API,wmfDrawText_t* draw_text)
svgPoint pt;
float font_height;
- float font_ratio;
float sin_theta;
float cos_theta;
@@ -172,8 +171,6 @@ static void wmf_svg_draw_text (wmfAPI* API,wmfDrawText_t* draw_text)
pt = svg_translate (API,draw_text->pt);
font_height = svg_height (API,(float) draw_text->font_height);
- font_ratio = svg_width (API,(float) (draw_text->font_height * draw_text->font_ratio));
- font_ratio /= font_height;
theta = - WMF_TEXT_ANGLE (draw_text->dc->font);
diff --git a/src/ipa/xgd/font.h b/src/ipa/xgd/font.h
index 79b5d87..5b15e57 100644
--- a/src/ipa/xgd/font.h
+++ b/src/ipa/xgd/font.h
@@ -157,10 +157,6 @@ static void gd_draw_ftbitmap (wmfAPI* API,FT_Bitmap* bitmap,gdPoint pt,wmfRGB* f
fg_pixel = gdImageColorResolve (gd->image,fg->r,fg->g,fg->b);
- if (bitmap->pixel_mode == ft_pixel_mode_mono)
- { color = fg_pixel;
- }
-
for (row = 0; row < rows; row++)
{ buffer = bitmap->buffer + row * bitmap->pitch;
diff --git a/src/meta.c b/src/meta.c
index cf046a5..ea14f94 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -441,7 +441,6 @@ static void write_b64 (wmfAPI * API, const unsigned char * buffer, unsigned long
b32 = (b32 << 16);
*ptr++ = B64[(b32 >> 18) ];
*ptr++ = B64[(b32 >> 12) & 0x3f];
- remaining -= 1;
}
*ptr++ = '\n';
diff --git a/src/player.c b/src/player.c
index 9b66eb7..813a2bf 100644
--- a/src/player.c
+++ b/src/player.c
@@ -554,7 +554,7 @@ static wmf_error_t WmfPlayMetaFile (wmfAPI* API)
case META_SETVIEWPORTORG:
SCAN_DIAGNOSTIC (API,"New Record: SETVIEWPORTORG");
- changed = meta_orgext (API,&Record);
+ meta_orgext (API,&Record);
if (SCAN (API)) wmf_write (API, Size, Function, "setviewportorg",
atts->atts, Record.parameter, Record.size * 2);
SCAN_DIAGNOSTIC (API,"\n");
diff --git a/src/player/meta.h b/src/player/meta.h
index d656dfd..b9762e3 100644
--- a/src/player/meta.h
+++ b/src/player/meta.h
@@ -412,16 +412,12 @@ static int meta_arc (wmfAPI* API,wmfRecord* Record)
d_pt.y = c_pt.y;
D_Coord_Register (API,d_pt,scope);
/* fallthrough */
+ default:
case '2':
d_pt.x = c_pt.x;
d_pt.y = drawarc.TL.y;
D_Coord_Register (API,d_pt,scope);
break;
-
- default:
- WMF_ERROR (API,"Glitch!");
- API->err = wmf_E_Glitch;
- break;
}
break;
@@ -445,16 +441,12 @@ static int meta_arc (wmfAPI* API,wmfRecord* Record)
d_pt.y = drawarc.BR.y;
D_Coord_Register (API,d_pt,scope);
/* fallthrough */
+ default:
case '3':
d_pt.x = drawarc.TL.x;
d_pt.y = c_pt.y;
D_Coord_Register (API,d_pt,scope);
break;
-
- default:
- WMF_ERROR (API,"Glitch!");
- API->err = wmf_E_Glitch;
- break;
}
break;
@@ -478,20 +470,17 @@ static int meta_arc (wmfAPI* API,wmfRecord* Record)
d_pt.y = c_pt.y;
D_Coord_Register (API,d_pt,scope);
/* fallthrough */
+ default:
case '4':
d_pt.x = c_pt.x;
d_pt.y = drawarc.BR.y;
D_Coord_Register (API,d_pt,scope);
break;
-
- default:
- WMF_ERROR (API,"Glitch!");
- API->err = wmf_E_Glitch;
- break;
}
break;
case '4':
+ default:
switch (Qe)
{
case '4':
@@ -511,23 +500,14 @@ static int meta_arc (wmfAPI* API,wmfRecord* Record)
d_pt.y = drawarc.TL.y;
D_Coord_Register (API,d_pt,scope);
/* fallthrough */
+ default:
case '1':
d_pt.x = drawarc.BR.x;
d_pt.y = c_pt.y;
D_Coord_Register (API,d_pt,scope);
break;
-
- default:
- WMF_ERROR (API,"Glitch!");
- API->err = wmf_E_Glitch;
- break;
}
break;
-
- default:
- WMF_ERROR (API,"Glitch!");
- API->err = wmf_E_Glitch;
- break;
}
return (changed);
@@ -2428,7 +2408,7 @@ static int meta_dc_color (wmfAPI* API,wmfRecord* Record,wmfAttributes* attrlist)
hash[5] = hex[(color.b >> 4) & 0x0f];
hash[6] = hex[ color.b & 0x0f];
hash[7] = 0;
- value = wmf_attr_add (API, attrlist, "color", hash);
+ wmf_attr_add (API, attrlist, "color", hash);
}
if (SCAN (API)) wmf_ipa_color_add (API,&color);
@@ -3152,7 +3132,7 @@ static int meta_pen_create (wmfAPI* API,wmfRecord* Record,wmfAttributes* attrlis
hash[5] = hex[(color.b >> 4) & 0x0f];
hash[6] = hex[ color.b & 0x0f];
hash[7] = 0;
- value = wmf_attr_add (API, attrlist, "color", hash);
+ wmf_attr_add (API, attrlist, "color", hash);
}
WMF_PEN_SET_COLOR (pen,&color);
@@ -3254,7 +3234,7 @@ static int meta_brush_create (wmfAPI* API,wmfRecord* Record,wmfAttributes* attrl
hash[5] = hex[(color.b >> 4) & 0x0f];
hash[6] = hex[ color.b & 0x0f];
hash[7] = 0;
- value = wmf_attr_add (API, attrlist, "color", hash);
+ wmf_attr_add (API, attrlist, "color", hash);
}
WMF_BRUSH_SET_COLOR (brush,&color);
diff --git a/src/recorder.c b/src/recorder.c
index b5e6431..ff371a7 100644
--- a/src/recorder.c
+++ b/src/recorder.c
@@ -48,6 +48,9 @@ static void s_rbox_set (wmfAPI * API, wmfConstruct * construct,
{
WMF_ERROR (API, "Hmm. Record out of range...");
API->err = wmf_E_Glitch;
+ rbox->start = NULL;
+ rbox->end = NULL;
+ rbox->ptr = NULL;
return;
}
rbox->start = construct->buffer + construct->rec_offset[n ];