"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "htmldoc/image.cxx" between
htmldoc-1.9.14-source.tar.gz and htmldoc-1.9.15-source.tar.gz

About: HTMLDOC converts HTML and Markdown source files into indexed HTML, EPUB, PostScript, or PDF files (but doesn’t support CSS).

image.cxx  (htmldoc-1.9.14-source):image.cxx  (htmldoc-1.9.15-source)
/* /*
* Image handling routines for HTMLDOC, a HTML document processing program. * Image handling routines for HTMLDOC, a HTML document processing program.
* *
* Copyright © 2011-2021 by Michael R Sweet. * Copyright © 2011-2022 by Michael R Sweet.
* Copyright © 1997-2010 by Easy Software Products. All rights reserved. * Copyright © 1997-2010 by Easy Software Products. All rights reserved.
* *
* This program is free software. Distribution and use rights are outlined in * This program is free software. Distribution and use rights are outlined in
* the file "COPYING". * the file "COPYING".
*/ */
/* /*
* Include necessary headers. * Include necessary headers.
*/ */
skipping to change at line 218 skipping to change at line 218
} }
if ((curbit + (unsigned)code_size) >= lastbit) if ((curbit + (unsigned)code_size) >= lastbit)
{ {
/* /*
* Don't have enough bits to hold the code... * Don't have enough bits to hold the code...
*/ */
if (done) if (done)
{ {
progress_error(HD_ERROR_READ_ERROR, progress_error(HD_ERROR_READ_ERROR, "Not enough data left to read GIF comp
"Not enough data left to read GIF compression code."); ression code.");
return (-1); /* Sorry, no more... */ return (-1); /* Sorry, no more... */
} }
/* /*
* Move last two bytes to front of buffer... * Move last two bytes to front of buffer...
*/ */
if (last_byte > 1) if (last_byte > 1)
{ {
buf[0] = buf[last_byte - 2]; buf[0] = buf[last_byte - 2];
skipping to change at line 243 skipping to change at line 242
else if (last_byte == 1) else if (last_byte == 1)
{ {
buf[0] = buf[last_byte - 1]; buf[0] = buf[last_byte - 1];
last_byte = 1; last_byte = 1;
} }
/* /*
* Read in another buffer... * Read in another buffer...
*/ */
if ((count = gif_get_block (fp, buf + last_byte)) <= 0) if ((count = gif_get_block(fp, buf + last_byte)) <= 0)
{ {
/* /*
* Whoops, no more data! * Whoops, no more data!
*/ */
done = 1; done = 1;
return (-1); return (-1);
} }
/* /*
* Update buffer state... * Update buffer state...
*/ */
curbit = (curbit - lastbit) + 8 * last_byte; curbit = curbit + 8 * last_byte - lastbit;
last_byte += (unsigned)count; last_byte += (unsigned)count;
lastbit = last_byte * 8; lastbit = last_byte * 8;
} }
for (ret = 0, i = curbit + (unsigned)code_size - 1, j = (unsigned)code_size; for (ret = 0, i = curbit + (unsigned)code_size - 1, j = (unsigned)code_size;
j > 0; j > 0;
i --, j --) i --, j --)
ret = (ret << 1) | ((buf[i / 8] & bits[i & 7]) != 0); ret = (ret << 1) | ((buf[i / 8] & bits[i & 7]) != 0);
curbit += (unsigned)code_size; curbit += (unsigned)code_size;
skipping to change at line 297 skipping to change at line 296
pass; /* Current pass */ pass; /* Current pass */
int pixel; /* Current pixel */ int pixel; /* Current pixel */
static int xpasses[4] = { 8, 8, 4, 2 }, static int xpasses[4] = { 8, 8, 4, 2 },
ypasses[5] = { 0, 4, 2, 1, 999999 }; ypasses[5] = { 0, 4, 2, 1, 999999 };
xpos = 0; xpos = 0;
ypos = 0; ypos = 0;
pass = 0; pass = 0;
code_size = (uchar)getc(fp); code_size = (uchar)getc(fp);
if (code_size > 12)
{
progress_error(HD_ERROR_READ_ERROR, "Bad GIF file \"%s\" - invalid code size
%d.", img->filename, code_size);
return (-1);
}
if (gif_read_lzw(fp, 1, code_size) < 0) if (gif_read_lzw(fp, 1, code_size) < 0)
return (-1); return (-1);
temp = img->pixels; temp = img->pixels;
while ((pixel = gif_read_lzw(fp, 0, code_size)) >= 0 && pixel < 256) while ((pixel = gif_read_lzw(fp, 0, code_size)) >= 0 && pixel < 256)
{ {
temp[0] = cmap[pixel][0]; temp[0] = cmap[pixel][0];
if (img->depth > 1) if (img->depth > 1)
skipping to change at line 422 skipping to change at line 427
do do
firstcode = oldcode = (short)gif_get_code(fp, code_size, 0); firstcode = oldcode = (short)gif_get_code(fp, code_size, 0);
while (firstcode == clear_code); while (firstcode == clear_code);
return (firstcode); return (firstcode);
} }
if (sp > stack) if (sp > stack)
return (*--sp); return (*--sp);
while ((code = gif_get_code (fp, code_size, 0)) >= 0) while ((code = gif_get_code(fp, code_size, 0)) >= 0)
{ {
if (code == clear_code) if (code == clear_code)
{ {
for (i = 0; i < clear_code; i ++) for (i = 0; i < clear_code; i ++)
{ {
table[0][i] = 0; table[0][i] = 0;
table[1][i] = (short)i; table[1][i] = (short)i;
} }
for (; i < 4096; i ++) for (; i < 4096; i ++)
skipping to change at line 465 skipping to change at line 470
incode = code; incode = code;
if (code >= max_code) if (code >= max_code)
{ {
*sp++ = firstcode; *sp++ = firstcode;
code = oldcode; code = oldcode;
} }
while (code >= clear_code) while (code >= clear_code)
{ {
if (sp >= (stack + sizeof(stack)))
return (255);
*sp++ = table[1][code]; *sp++ = table[1][code];
if (code == table[0][code]) if (code == table[0][code])
return (255); return (255);
code = table[0][code]; code = table[0][code];
} }
if (sp >= (stack + sizeof(stack)))
return (255);
*sp++ = firstcode = table[1][code]; *sp++ = firstcode = table[1][code];
code = max_code;
if (code < 4096) if ((code = max_code) < 4096)
{ {
table[0][code] = oldcode; table[0][code] = oldcode;
table[1][code] = firstcode; table[1][code] = firstcode;
max_code ++; max_code ++;
if (max_code >= max_code_size && max_code_size < 4096) if (max_code >= max_code_size && max_code_size < 4096)
{ {
max_code_size *= 2; max_code_size *= 2;
code_size ++; code_size ++;
} }
skipping to change at line 1163 skipping to change at line 1174
} }
else else
color = getc(fp); color = getc(fp);
} }
/* /*
* Get a new color as needed... * Get a new color as needed...
*/ */
if (color < 0) if (color < 0)
temp = getc(fp); temp = getc(fp) & 255;
else else
temp = color; temp = color;
count --; count --;
/* /*
* Copy the color value... * Copy the color value...
*/ */
if (!gray) if (!gray)
skipping to change at line 1286 skipping to change at line 1297
fread(buf, 9, 1, fp); fread(buf, 9, 1, fp);
if (buf[8] & GIF_COLORMAP) if (buf[8] & GIF_COLORMAP)
{ {
ncolors = 2 << (buf[8] & 0x07); ncolors = 2 << (buf[8] & 0x07);
if (gif_read_cmap(fp, ncolors, cmap, &gray)) if (gif_read_cmap(fp, ncolors, cmap, &gray))
return (-1); return (-1);
} }
img->width = (buf[5] << 8) | buf[4];
img->height = (buf[7] << 8) | buf[6];
img->depth = gray ? 1 : 3;
if (img->width <= 0 || img->width > 32767 || img->height <= 0 || img->h
eight > 32767)
return (-1);
if (transparent >= 0) if (transparent >= 0)
{ {
/* /*
* Map transparent color to background color... * Map transparent color to background color...
*/ */
if (BodyColor[0]) if (BodyColor[0])
{ {
float rgb[3]; /* RGB color */ float rgb[3]; /* RGB color */
skipping to change at line 1316 skipping to change at line 1334
cmap[transparent][2] = 255; cmap[transparent][2] = 255;
} }
/* /*
* Allocate a mask image... * Allocate a mask image...
*/ */
image_need_mask(img); image_need_mask(img);
} }
img->width = (buf[5] << 8) | buf[4];
img->height = (buf[7] << 8) | buf[6];
img->depth = gray ? 1 : 3;
if (img->width <= 0 || img->width > 32767 || img->height <= 0 || img->h
eight > 32767)
return (-1);
if (!load_data) if (!load_data)
return (0); return (0);
img->pixels = (uchar *)malloc((size_t)(img->width * img->height * img- >depth)); img->pixels = (uchar *)malloc((size_t)(img->width * img->height * img- >depth));
if (img->pixels == NULL) if (img->pixels == NULL)
return (-1); return (-1);
return (gif_read_image(fp, img, cmap, buf[8] & GIF_INTERLACE, transpare nt)); return (gif_read_image(fp, img, cmap, buf[8] & GIF_INTERLACE, transpare nt));
} }
} }
skipping to change at line 1447 skipping to change at line 1458
static int /* O - 0 = success, -1 = fail */ static int /* O - 0 = success, -1 = fail */
image_load_png(image_t *img, /* I - Image pointer */ image_load_png(image_t *img, /* I - Image pointer */
FILE *fp, /* I - File to read from */ FILE *fp, /* I - File to read from */
int gray, /* I - 0 = color, 1 = grayscale */ int gray, /* I - 0 = color, 1 = grayscale */
int load_data)/* I - 1 = load image data, 0 = just info */ int load_data)/* I - 1 = load image data, 0 = just info */
{ {
int i, j; /* Looping vars */ int i, j; /* Looping vars */
png_structp pp; /* PNG read pointer */ png_structp pp; /* PNG read pointer */
png_infop info; /* PNG info pointers */ png_infop info; /* PNG info pointers */
int depth; /* Input image depth */ int depth; /* Input image depth */
png_bytep *rows; /* PNG row pointers */ png_bytep *rows = NULL; /* PNG row pointers */
uchar *inptr, /* Input pixels */ uchar *inptr, /* Input pixels */
*outptr; /* Output pixels */ *outptr; /* Output pixels */
int color_type, /* PNG color mode */ int color_type, /* PNG color mode */
bit_depth; /* PNG bit depth */ bit_depth; /* PNG bit depth */
/* /*
* Setup the PNG data structures... * Setup the PNG data structures...
*/ */
pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
skipping to change at line 1476 skipping to change at line 1487
if (!info) if (!info)
{ {
progress_error(HD_ERROR_OUT_OF_MEMORY, "Unable to allocate memory for PNG in fo: %s", progress_error(HD_ERROR_OUT_OF_MEMORY, "Unable to allocate memory for PNG in fo: %s",
strerror(errno)); strerror(errno));
png_destroy_read_struct(&pp, NULL, NULL); png_destroy_read_struct(&pp, NULL, NULL);
return (-1); return (-1);
} }
rows = NULL;
if (setjmp(png_jmpbuf(pp))) if (setjmp(png_jmpbuf(pp)))
{ {
progress_error(HD_ERROR_BAD_FORMAT, "PNG file contains errors!"); progress_error(HD_ERROR_BAD_FORMAT, "PNG file contains errors!");
png_destroy_read_struct(&pp, &info, NULL); png_destroy_read_struct(&pp, &info, NULL);
if (img != NULL && img->pixels != NULL) if (img != NULL)
{
free(img->pixels); free(img->pixels);
img->pixels = NULL;
}
if (rows != NULL) free(rows);
free(rows); rows = NULL;
return (-1); return (-1);
} }
/* /*
* Initialize the PNG read "engine"... * Initialize the PNG read "engine"...
*/ */
png_init_io(pp, fp); png_init_io(pp, fp);
skipping to change at line 1585 skipping to change at line 1597
if (color_type & PNG_COLOR_MASK_PALETTE) if (color_type & PNG_COLOR_MASK_PALETTE)
puts(" PALETTE"); puts(" PALETTE");
# endif // DEBUG # endif // DEBUG
if (!load_data) if (!load_data)
{ {
png_destroy_read_struct(&pp, &info, NULL); png_destroy_read_struct(&pp, &info, NULL);
return (0); return (0);
} }
img->pixels = (uchar *)calloc(1,(size_t)(img->width * img->height * depth)); img->pixels = (uchar *)calloc(1, (size_t)(img->width * img->height * depth));
/* /*
* Allocate pointers... * Allocate pointers...
*/ */
rows = (png_bytep *)calloc(png_get_image_height(pp, info), sizeof(png_bytep)); rows = (png_bytep *)calloc(png_get_image_height(pp, info), sizeof(png_bytep));
for (i = 0; i < (int)png_get_image_height(pp, info); i ++) for (i = 0; i < (int)png_get_image_height(pp, info); i ++)
rows[i] = img->pixels + i * img->width * depth; rows[i] = img->pixels + i * img->width * depth;
skipping to change at line 1677 skipping to change at line 1689
i > 0; i > 0;
inptr ++, i --) inptr ++, i --)
*outptr++ = *inptr++; *outptr++ = *inptr++;
} }
} }
/* /*
* Free memory and return... * Free memory and return...
*/ */
free(rows);
png_read_end(pp, info); png_read_end(pp, info);
png_destroy_read_struct(&pp, &info, NULL); png_destroy_read_struct(&pp, &info, NULL);
free(rows);
return (0); return (0);
} }
#endif // HAVE_LIBPNG #endif // HAVE_LIBPNG
/* /*
* 'image_need_mask()' - Allocate memory for the image mask... * 'image_need_mask()' - Allocate memory for the image mask...
*/ */
static void static void
image_need_mask(image_t *img, /* I - Image to add mask to */ image_need_mask(image_t *img, /* I - Image to add mask to */
skipping to change at line 1748 skipping to change at line 1760
}; };
static uchar dither[4][4] = // Simple 4x4 clustered-dot dither static uchar dither[4][4] = // Simple 4x4 clustered-dot dither
{ {
{ 0, 2, 15, 6 }, { 0, 2, 15, 6 },
{ 4, 12, 9, 11 }, { 4, 12, 9, 11 },
{ 14, 7, 1, 3 }, { 14, 7, 1, 3 },
{ 8, 10, 5, 13 } { 8, 10, 5, 13 }
}; };
if (img == NULL || img->mask == NULL || x < 0 || x >= img->width || if (img == NULL || img->mask == NULL || x < 0 || x >= img->width ||
y < 0 || y > img->height) y < 0 || y >= img->height)
return; return;
if (img->maskscale == 8) if (img->maskscale == 8)
{ {
// Store the alpha value directly... // Store the alpha value directly...
if (PSLevel) if (PSLevel)
img->mask[y * img->maskwidth + x] = 255 - alpha; img->mask[y * img->maskwidth + x] = 255 - alpha;
else else
img->mask[y * img->maskwidth + x] = alpha; img->mask[y * img->maskwidth + x] = alpha;
} }
 End of changes. 23 change blocks. 
27 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)