Commit 24bbdbef authored by Sven Neumann's avatar Sven Neumann
Browse files

applied a bunch of patches:

Simon Budigs patch sent to the list Sun, 20 Feb 2000
gimp-kirchgessner-000217-0
gimp-cosmin-20000212
gimp-mattias-000227-0


--Sven
parent 64c30031
Fri Mar 10 18:10:56 CET 2000 Sven Neumann <sven@gimp.org>
* plug-ins/pygimp/plug-ins/pdbbrowse.py
* plug-ins/pygimp/plug-ins/sphere.py: applied patch from Simon Budig
makes the scripts use env instead of hardcoded path to python
* plug-ins/common/ps.c: applied gimp-kirchgessner-000217-0
fixes problem with toggle PostScript Level 2
fixes problem with reading EPS-files that have no showpage command
adds runlength encoding to PostScript Level 2 files
* plug-ins/common/jpeg.c: applied gimp-cosmin-20000212
guards parasite code with #ifdef GIMP_HAVE_PARASITES
do not save comment if comment string is empty
* app/fileops.c
* plug-ins/common/CEL.c
* plug-ins/common/bz2.c
* plug-ins/common/gicon.c
* plug-ins/common/mpeg.c
* plug-ins/common/psd.c
* plug-ins/common/psp.c
* plug-ins/common/tga.c
* plug-ins/common/xpm.c
* plug-ins/common/xwd.c: applied gimp-mattias-000227-0
Changes the file format auto-detection algorithm to do the following:
1. See if the file name matches extensions of formats that do NOT have
any magic registered
2. Check all file formats with registered magic
3. Check all extensions
Adds, removes or fixes existing magic in tga, cel, bz2, gicon, mpeg,
psd, psp, xpm, xwd
Please test this heavily (especially the file magic). If this patch
turns out to be bogus, we'll revert it. If the changes are correct,
it's an important fix.
Fri Mar 10 12:29:57 CET 2000 Sven Neumann <sven@gimp.org>
* plug-ins/sel2path/*.c: do not include malloc.h but use the
......
......@@ -1754,16 +1754,63 @@ file_overwrite_no_callback (GtkWidget *widget,
gtk_widget_set_sensitive (GTK_WIDGET (filesave), TRUE);
}
static PlugInProcDef *
file_proc_find_by_name(GSList *procs,
gchar *filename,
gboolean skip_magic)
{
GSList *p;
gchar *ext = strrchr(filename, '.');
if (ext)
ext++;
for (p = procs; p; p = p->next)
{
PlugInProcDef *proc = p->data;
GSList *prefixes;
if (skip_magic && proc->magics_list)
continue;
for (prefixes = proc->prefixes_list; prefixes; prefixes = prefixes->next)
{
if (strncmp(filename, prefixes->data, strlen(prefixes->data)) == 0)
return proc;
}
}
for (p = procs; p; p = p->next)
{
PlugInProcDef *proc = p->data;
GSList *extensions;
for (extensions = proc->extensions_list; ext && extensions; extensions = extensions->next)
{
gchar *p1 = ext;
gchar *p2 = (gchar *)extensions->data;
if (skip_magic && proc->magics_list)
continue;
while (*p1 && *p2)
{
if (tolower (*p1) != tolower (*p2))
break;
p1++;
p2++;
}
if (!(*p1) && !(*p2))
return proc;
}
}
return NULL;
}
PlugInProcDef *
file_proc_find (GSList *procs,
gchar *filename)
{
PlugInProcDef *file_proc, *size_matched_proc;
GSList *all_procs = procs;
GSList *extensions;
GSList *prefixes;
gchar *extension;
gchar *p1, *p2;
FILE *ifp = NULL;
gint head_size = -2, size_match_count = 0;
gint match_val;
......@@ -1771,11 +1818,11 @@ file_proc_find (GSList *procs,
size_matched_proc = NULL;
extension = strrchr (filename, '.');
if (extension)
extension += 1;
/* First, check magicless prefixes/suffixes */
if ( (file_proc = file_proc_find_by_name(all_procs, filename, TRUE)) != NULL)
return file_proc;
/* At first look for magics */
/* Then look for magics */
while (procs)
{
file_proc = procs->data;
......@@ -1810,46 +1857,8 @@ file_proc_find (GSList *procs,
if (size_match_count == 1)
return (size_matched_proc);
procs = all_procs;
while (procs)
{
file_proc = procs->data;
procs = procs->next;
for (prefixes = file_proc->prefixes_list; prefixes; prefixes = prefixes->next)
{
p1 = filename;
p2 = (gchar *) prefixes->data;
if (strncmp (filename, prefixes->data, strlen (prefixes->data)) == 0)
return file_proc;
}
}
procs = all_procs;
while (procs)
{
file_proc = procs->data;
procs = procs->next;
for (extensions = file_proc->extensions_list; extension && extensions; extensions = extensions->next)
{
p1 = extension;
p2 = (gchar *) extensions->data;
while (*p1 && *p2)
{
if (tolower (*p1) != tolower (*p2))
break;
p1 += 1;
p2 += 1;
}
if (!(*p1) && !(*p2))
return file_proc;
}
}
return NULL;
/* As a last ditch, try matching by name */
return file_proc_find_by_name(all_procs, filename, FALSE);
}
static void
......
......@@ -132,7 +132,7 @@ query (void)
gimp_register_magic_load_handler ("file_cel_load",
"cel",
"",
"0,string,KiSS\040");
"0,string,KiSS\\040");
gimp_register_save_handler ("file_cel_save",
"cel",
"");
......
......@@ -132,9 +132,10 @@ query (void)
nsave_args, 0,
save_args, NULL);
gimp_register_load_handler ("file_bz2_load",
"xcf.bz2,bz2,xcfbz2",
"");
gimp_register_magic_load_handler ("file_bz2_load",
"xcf.bz2,bz2,xcfbz2",
"",
"0,string,BZh");
gimp_register_save_handler ("file_bz2_save",
"xcf.bz2,bz2,xcfbz2",
"");
......
......@@ -146,9 +146,11 @@ query (void)
nsave_args, 0,
save_args, NULL);
gimp_register_load_handler ("file_gicon_load",
"ico",
"");
gimp_register_magic_load_handler ("file_gicon_load",
"ico",
"",
"0,string,"
"/*\\040\\040GIMP\\040icon\\040image");
gimp_register_save_handler ("file_gicon_save",
"ico",
"");
......
......@@ -1043,7 +1043,8 @@ load_image (gchar *filename,
/* pw - Last of all, attach the parasites (couldn't do it earlier -
there was no image. */
#ifdef GIMP_HAVE_PARASITES
if (!preview)
{
if (comment_parasite)
......@@ -1057,6 +1058,7 @@ load_image (gchar *filename,
parasite_free (vals_parasite);
}
}
#endif /* GIMP_HAVE_PARASITES */
return image_ID;
}
......@@ -1382,7 +1384,7 @@ save_image (char *filename,
jpeg_start_compress (&cinfo, TRUE);
/* Step 4.1: Write the comment out - pw */
if (image_comment)
if (image_comment && *image_comment)
{
jpeg_write_marker (&cinfo,
JPEG_COM,
......
......@@ -133,9 +133,10 @@ query (void)
nload_args, nload_return_vals,
load_args, load_return_vals);
gimp_register_load_handler ("file_mpeg_load",
"mpg,mpeg",
"");
gimp_register_magic_load_handler ("file_mpeg_load",
"mpg,mpeg",
""
"0,long,0x000001b3,0,long,0x000001ba");
}
static void
......
......@@ -45,10 +45,13 @@
* Ghostview may hang when displaying the files.
* V 1.07, PK, 14-Sep-99: Add resolution to image
* V 1.08, PK, 16-Jan-2000: Add PostScript-Level 2 by Austin Donnelly
* V 1.09, PK, 15-Feb-2000: Force showpage on EPS-files
* Add "RunLength" compression
* Fix problem with "Level 2" toggle
*/
#define VERSIO 1.08
static char dversio[] = "v1.08 16-Jan-2000";
static char ident[] = "@(#) GIMP PostScript/PDF file-plugin v1.08 16-Jan-2000";
#define VERSIO 1.09
static char dversio[] = "v1.09 15-Feb-2000";
static char ident[] = "@(#) GIMP PostScript/PDF file-plugin v1.09 15-Feb-2000";
#include "config.h"
......@@ -196,8 +199,9 @@ static FILE *ps_open (gchar *filename,
const PSLoadVals *loadopt,
gint *llx,
gint *lly,
int *urx,
gint *ury);
gint *urx,
gint *ury,
gint *is_epsf);
static void ps_close (FILE *ifp);
......@@ -249,7 +253,6 @@ static void save_ok_callback (GtkWidget *widget,
static void save_unit_toggle_update (GtkWidget *widget,
gpointer data);
GPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
......@@ -262,6 +265,11 @@ GPlugInInfo PLUG_IN_INFO =
/* The run mode */
static GRunModeType l_run_mode;
static void compress_packbits (int nin,
unsigned char *src,
int *nout,
unsigned char *dst);
static guint32 ascii85_buf;
static int ascii85_len = 0;
......@@ -321,6 +329,16 @@ ascii85_out (unsigned char byte, FILE *ofp)
ascii85_len++;
}
static void
ascii85_nout (int n, unsigned char *uptr, FILE *ofp)
{
while (n-- > 0)
{
ascii85_out (*uptr, ofp);
uptr++;
}
}
static void
ascii85_done (FILE *ofp)
{
......@@ -337,6 +355,88 @@ ascii85_done (FILE *ofp)
}
static void
compress_packbits (int nin,
unsigned char *src,
int *nout,
unsigned char *dst)
{register unsigned char c;
int nrepeat, nliteral;
unsigned char *run_start;
unsigned char *start_dst = dst;
unsigned char *last_literal = NULL;
for (;;)
{
if (nin <= 0) break;
run_start = src;
c = *run_start;
/* Search repeat bytes */
if ((nin > 1) && (c == src[1]))
{
nrepeat = 1;
nin -= 2;
src += 2;
while ((nin > 0) && (c == *src))
{
nrepeat++;
src++;
nin--;
if (nrepeat == 127) break; /* Maximum repeat */
}
/* Add two-byte repeat to last literal run ? */
if ( (nrepeat == 1)
&& (last_literal != NULL) && (((*last_literal)+1)+2 <= 128))
{
*last_literal += 2;
*(dst++) = c;
*(dst++) = c;
continue;
}
/* Add repeat run */
*(dst++) = (unsigned char)((-nrepeat) & 0xff);
*(dst++) = c;
last_literal = NULL;
continue;
}
/* Search literal bytes */
nliteral = 1;
nin--;
src++;
for (;;)
{
if (nin <= 0) break;
if ((nin >= 2) && (src[0] == src[1])) /* A two byte repeat ? */
break;
nliteral++;
nin--;
src++;
if (nliteral == 128) break; /* Maximum literal run */
}
/* Could be added to last literal run ? */
if ((last_literal != NULL) && (((*last_literal)+1)+nliteral <= 128))
{
*last_literal += nliteral;
}
else
{
last_literal = dst;
*(dst++) = (unsigned char)(nliteral-1);
}
while (nliteral-- > 0) *(dst++) = *(run_start++);
}
*nout = dst - start_dst;
}
MAIN ()
......@@ -421,7 +521,7 @@ query (void)
gimp_install_procedure ("file_ps_save",
"save file in PostScript file format",
"PostScript saving handles all image types except those with alpha channels.",
"Peter Kirchgessner <pkirchg@aol.com>",
"Peter Kirchgessner <peter@kirchgessner.net>",
"Peter Kirchgessner",
dversio,
"<Save>/PostScript",
......@@ -562,13 +662,13 @@ run (gchar *name,
image_ID = orig_image_ID = param[1].data.d_int32;
drawable_ID = param[2].data.d_int32;
/* eventually export the image */
/* eventually export the image */
switch (run_mode)
{
case RUN_INTERACTIVE:
case RUN_WITH_LAST_VALS:
init_gtk ();
export = gimp_export_image (&image_ID, &drawable_ID, "PS",
export = gimp_export_image (&image_ID, &drawable_ID, "PS",
(CAN_HANDLE_RGB |
CAN_HANDLE_GRAY |
CAN_HANDLE_INDEXED));
......@@ -697,6 +797,7 @@ load_image (gchar *filename)
char *temp;
int llx, lly, urx, ury;
int k, n_images, max_images, max_pagenum;
int is_epsf;
#ifdef PS_DEBUG
g_print ("load_image:\n resolution = %d\n", plvals.resolution);
......@@ -723,7 +824,7 @@ load_image (gchar *filename)
g_free (temp);
}
ifp = ps_open (filename, &plvals, &llx, &lly, &urx, &ury);
ifp = ps_open (filename, &plvals, &llx, &lly, &urx, &ury, &is_epsf);
if (!ifp)
{
g_message (_("PS: can't interprete file"));
......@@ -735,6 +836,7 @@ load_image (gchar *filename)
max_images = 10;
max_pagenum = 9999; /* Try to get the maximum pagenumber to read */
if (is_epsf) max_pagenum = 1;
if (!page_in_list (plvals.pages, max_pagenum)) /* Is there a limit in list ? */
{
max_pagenum = -1;
......@@ -757,7 +859,7 @@ load_image (gchar *filename)
image_ID = load_ps (filename, page_count, ifp, llx, lly, urx, ury);
if (image_ID == -1) break;
#ifdef GIMP_HAVE_RESOLUTION_INFO
gimp_image_set_resolution (image_ID,
gimp_image_set_resolution (image_ID,
(double) plvals.resolution,
(double) plvals.resolution);
#endif
......@@ -1059,7 +1161,8 @@ ps_open (gchar *filename,
gint *llx,
gint *lly,
gint *urx,
gint *ury)
gint *ury,
gint *is_epsf)
{
char *cmd, *gs, *gs_opts, *driver;
FILE *fd_popen;
......@@ -1077,6 +1180,8 @@ ps_open (gchar *filename,
/* Check if the file is a PDF. For PDF, we cant set geometry */
is_pdf = 0;
/* Check if it is a EPS-file */
*is_epsf = 0;
#ifndef __EMX__
fd_popen = fopen (filename, "r");
#else
......@@ -1084,10 +1189,22 @@ ps_open (gchar *filename,
#endif
if (fd_popen != NULL)
{
char hdr[4];
char hdr[512];
fread (hdr, 1, 4, fd_popen);
fread (hdr, 1, sizeof(hdr), fd_popen);
is_pdf = (strncmp (hdr, "%PDF", 4) == 0);
if (!is_pdf) /* Check for EPSF */
{char *adobe, *epsf;
int ds = 0;
hdr[sizeof(hdr)-1] = '\0';
adobe = strstr (hdr, "PS-Adobe-");
epsf = strstr (hdr, "EPSF-");
if ((adobe != NULL) && (epsf != NULL))
ds = epsf - adobe;
*is_epsf = ((ds >= 11) && (ds <= 15));
}
fclose (fd_popen);
}
......@@ -1153,10 +1270,11 @@ ps_open (gchar *filename,
sprintf (geometry,"-g%dx%d ", width, height);
cmd = g_strdup_printf ("%s -sDEVICE=%s -r%d %s%s%s-q -dNOPAUSE %s \
-sOutputFile=%s %s -c quit",
-sOutputFile=%s %s %s-c quit",
gs, driver, resolution, geometry,
TextAlphaBits, GraphicsAlphaBits,
gs_opts, pnmfile, filename);
gs_opts, pnmfile, filename,
*is_epsf ? "-c showpage " : "");
#ifdef PS_DEBUG
g_print ("Going to start ghostscript with:\n%s\n", cmd);
#endif
......@@ -1579,7 +1697,7 @@ save_ps_setup (FILE *ofp,
fprintf (ofp, "%%%%BeginProlog\n");
fprintf (ofp, "%% Use own dictionary to avoid conflicts\n");
fprintf (ofp, "5 dict begin\n");
fprintf (ofp, "10 dict begin\n");
fprintf (ofp, "%%%%EndProlog\n");
fprintf (ofp, "%%%%Page: 1 1\n");
fprintf (ofp, "%% Translate for offset\n");
......@@ -1843,6 +1961,7 @@ save_gray (FILE *ofp,
int height, width, i, j;
int tile_height;
unsigned char *data, *src;
unsigned char *packb = NULL;
GPixelRgn pixel_rgn;
GDrawable *drawable;
GDrawableType drawable_type;
......@@ -1869,8 +1988,10 @@ save_gray (FILE *ofp,
}
else
{
fprintf (ofp, "currentfile /ASCII85Decode filter\n");
fprintf (ofp,"currentfile /ASCII85Decode filter /RunLengthDecode filter\n");
ascii85_init ();
/* Allocate buffer for packbits data. Worst case: Less than 1% increase */
packb = (guchar *)g_malloc ((width * 105)/100+2);
}
fprintf (ofp, "image\n");
......@@ -1894,16 +2015,23 @@ save_gray (FILE *ofp,
putc ('\n', ofp);
}
else
{
for (j = 0; j < width; j++)
ascii85_out (*(src++), ofp);
{int nout;
compress_packbits (width, src, &nout, packb);
ascii85_nout (nout, packb, ofp);
src += width;
}
if ((l_run_mode != RUN_NONINTERACTIVE) && ((i % 20) == 0))
gimp_progress_update ((double) i / (double) height);
}
if (level2) ascii85_done (ofp);
if (level2)
{
ascii85_out (128, ofp); /* Write EOD of RunLengthDecode filter */
ascii85_done (ofp);
}
fprintf (ofp, "showpage\n");
g_free (data);
if (packb) g_free (packb);
gimp_drawable_detach (drawable);
......@@ -1927,6 +2055,7 @@ save_bw (FILE *ofp,
int tile_height;
guchar *cmap, *ct;
guchar *data, *src;
guchar *packb = NULL;
guchar *scanline, *dst, mask;
guchar *hex_scanline;
GPixelRgn pixel_rgn;
......@@ -1960,8 +2089,10 @@ save_bw (FILE *ofp,
}
else
{
fprintf (ofp, "currentfile /ASCII85Decode filter\n");
fprintf (ofp,"currentfile /ASCII85Decode filter /RunLengthDecode filter\n");
ascii85_init ();
/* Allocate buffer for packbits data. Worst case: Less than 1% increase */
packb = (guchar *)g_malloc (((nbsl+1) * 105)/100+2);
}
fprintf (ofp, "image\n");
......@@ -2006,20 +2137,25 @@ save_bw (FILE *ofp,
}
}
else
{
dst = scanline;
for (j = 0; j < nbsl; j++)
ascii85_out (*(dst++), ofp);
{int nout;
compress_packbits (nbsl, scanline, &nout, packb);
ascii85_nout (nout, packb, ofp);
}
if ((l_run_mode != RUN_NONINTERACTIVE) && ((i % 20) == 0))
gimp_progress_update ((double) i / (double) height);
}
if (level2) ascii85_done (ofp);
if (level2)
{
ascii85_out (128, ofp); /* Write EOD of RunLengthDecode filter */
ascii85_done (ofp);
}
fprintf (ofp, "showpage\n");
g_free (hex_scanline);
g_free (scanline);
g_free (data);
if (packb != NULL) g_free (packb);