Commit 9f4f94c6 authored by Manish Singh's avatar Manish Singh

plug-ins/animationplay/animationplay.c plug-ins/CEL/CEL.c

* plug-ins/animationplay/animationplay.c
* plug-ins/CEL/CEL.c
* plug-ins/psd/psd.c
* plug-ins/xd/xd.c: applied gimp-joke-980427-0, warning cleanups

* app/temp_buf.c: applied gimp-entity-980427-0, temp_buf swap speedups and
more robust tempfile handling

-Yosh
parent 010dc35e
Mon Apr 27 20:43:14 PDT 1998 Manish Singh <yosh@gimp.org>
* plug-ins/animationplay/animationplay.c
* plug-ins/CEL/CEL.c
* plug-ins/psd/psd.c
* plug-ins/xd/xd.c: applied gimp-joke-980427-0, warning cleanups
* app/temp_buf.c: applied gimp-entity-980427-0, temp_buf swap
speedups and more robust tempfile handling
Mon Apr 27 20:57:26 1998 EDT Matthew Wilson <msw@gimp.org>
* app/curves: Initialize data that is referenced in event handlers
......
......@@ -68,10 +68,11 @@ temp_buf_to_color (src_buf, dest_buf)
while (num_bytes--)
{
unsigned char tmpch;
*dest++ = *src++; /* alpha channel */
*dest++ = *src;
*dest++ = *src;
*dest++ = *src++;
*dest++ = tmpch = *src++;
*dest++ = tmpch;
*dest++ = tmpch;
}
}
......@@ -115,7 +116,7 @@ temp_buf_new (width, height, bytes, x, y, col)
{
long i;
int j;
unsigned char * init, * data;
unsigned char * data;
TempBuf * temp;
temp = (TempBuf *) g_malloc (sizeof (TempBuf));
......@@ -128,21 +129,46 @@ temp_buf_new (width, height, bytes, x, y, col)
temp->swapped = FALSE;
temp->filename = NULL;
temp->data = temp_buf_allocate (width * height * bytes);
temp->data = data = temp_buf_allocate (width * height * bytes);
/* initialize the data */
if (col)
{
i = width * height;
data = temp->data;
while (i--)
{
j = bytes;
init = col;
while (j--)
*data++ = *init++;
}
/* First check if we can save a lot of work */
if (bytes == 1)
{
memset (data, *col, width * height);
}
else if ((bytes == 3) && (col[1] == *col) && (*col == col[2]))
{
memset (data, *col, width * height * 3);
}
else if ((bytes == 4) && (col[1] == *col) && (*col == col[2]) && (col[2] == col[3]))
{
memset (data, *col, (width * height) << 2);
}
else
{
/* No, we cannot */
unsigned char * dptr;
/* Fill the first row */
dptr = data;
for (i = width - 1; i >= 0; --i)
{
unsigned char * init;
j = bytes;
init = col;
while (j--)
*dptr++ = *init++;
}
/* Now copy from it (we set bytes to bytesperrow now) */
bytes *= width;
while (--height)
{
memcpy (dptr, data, bytes);
dptr += bytes;
}
}
}
return temp;
......@@ -170,24 +196,23 @@ temp_buf_copy (src, dest)
new = dest;
if (dest->width != src->width || dest->height != src->height)
warning ("In temp_buf_copy, the widths or heights don't match.");
/* The temp buf is smart, and can translate between color and gray */
/* (only necessary if not we allocated it */
if (src->bytes != new->bytes)
{
if (src->bytes == 4) /* RGB color */
temp_buf_to_gray (src, new);
else if (src->bytes == 2) /* grayscale */
temp_buf_to_color (src, new);
else
warning ("Cannot convert from indexed color.");
return new;
}
}
/* The temp buf is smart, and can translate between color and gray */
if (src->bytes != new->bytes)
{
if (src->bytes == 4) /* RGB color */
temp_buf_to_gray (src, new);
else if (src->bytes == 2) /* grayscale */
temp_buf_to_color (src, new);
else
warning ("Cannot convert from indexed color.");
}
else
{
/* make the copy */
length = src->width * src->height * src->bytes;
memcpy (temp_buf_data (new), temp_buf_data (src), length);
}
/* make the copy */
length = src->width * src->height * src->bytes;
memcpy (temp_buf_data (new), temp_buf_data (src), length);
return new;
}
......@@ -473,6 +498,7 @@ temp_buf_unswap (buf)
{
struct stat stat_buf;
FILE * fp;
gboolean succ = FALSE;
if (!buf || !buf->swapped)
return;
......@@ -491,12 +517,18 @@ temp_buf_unswap (buf)
buf->data = temp_buf_allocate (buf->width * buf->height * buf->bytes);
/* Find out if the filename of the swapped data is an existing file... */
/* (buf->filname HAS to be != 0 */
if (!stat (buf->filename, &stat_buf))
{
if ((fp = fopen (buf->filename, "r")))
{
fread (buf->data, buf->width * buf->height * buf->bytes, 1, fp);
size_t blocksRead;
blocksRead = fread (buf->data, buf->width * buf->height * buf->bytes, 1, fp);
fclose (fp);
if (blocksRead != 1)
perror ("Read error on temp buf");
else
succ = TRUE;
}
else
perror ("Error in temp buf caching");
......@@ -504,11 +536,10 @@ temp_buf_unswap (buf)
/* Delete the swap file */
unlink (buf->filename);
}
else
if (!succ)
warning ("Error in temp buf caching: information swapped to disk was lost!");
if (buf->filename)
g_free (buf->filename); /* free filename */
g_free (buf->filename); /* free filename */
buf->filename = NULL;
}
......
......@@ -68,10 +68,11 @@ temp_buf_to_color (src_buf, dest_buf)
while (num_bytes--)
{
unsigned char tmpch;
*dest++ = *src++; /* alpha channel */
*dest++ = *src;
*dest++ = *src;
*dest++ = *src++;
*dest++ = tmpch = *src++;
*dest++ = tmpch;
*dest++ = tmpch;
}
}
......@@ -115,7 +116,7 @@ temp_buf_new (width, height, bytes, x, y, col)
{
long i;
int j;
unsigned char * init, * data;
unsigned char * data;
TempBuf * temp;
temp = (TempBuf *) g_malloc (sizeof (TempBuf));
......@@ -128,21 +129,46 @@ temp_buf_new (width, height, bytes, x, y, col)
temp->swapped = FALSE;
temp->filename = NULL;
temp->data = temp_buf_allocate (width * height * bytes);
temp->data = data = temp_buf_allocate (width * height * bytes);
/* initialize the data */
if (col)
{
i = width * height;
data = temp->data;
while (i--)
{
j = bytes;
init = col;
while (j--)
*data++ = *init++;
}
/* First check if we can save a lot of work */
if (bytes == 1)
{
memset (data, *col, width * height);
}
else if ((bytes == 3) && (col[1] == *col) && (*col == col[2]))
{
memset (data, *col, width * height * 3);
}
else if ((bytes == 4) && (col[1] == *col) && (*col == col[2]) && (col[2] == col[3]))
{
memset (data, *col, (width * height) << 2);
}
else
{
/* No, we cannot */
unsigned char * dptr;
/* Fill the first row */
dptr = data;
for (i = width - 1; i >= 0; --i)
{
unsigned char * init;
j = bytes;
init = col;
while (j--)
*dptr++ = *init++;
}
/* Now copy from it (we set bytes to bytesperrow now) */
bytes *= width;
while (--height)
{
memcpy (dptr, data, bytes);
dptr += bytes;
}
}
}
return temp;
......@@ -170,24 +196,23 @@ temp_buf_copy (src, dest)
new = dest;
if (dest->width != src->width || dest->height != src->height)
warning ("In temp_buf_copy, the widths or heights don't match.");
/* The temp buf is smart, and can translate between color and gray */
/* (only necessary if not we allocated it */
if (src->bytes != new->bytes)
{
if (src->bytes == 4) /* RGB color */
temp_buf_to_gray (src, new);
else if (src->bytes == 2) /* grayscale */
temp_buf_to_color (src, new);
else
warning ("Cannot convert from indexed color.");
return new;
}
}
/* The temp buf is smart, and can translate between color and gray */
if (src->bytes != new->bytes)
{
if (src->bytes == 4) /* RGB color */
temp_buf_to_gray (src, new);
else if (src->bytes == 2) /* grayscale */
temp_buf_to_color (src, new);
else
warning ("Cannot convert from indexed color.");
}
else
{
/* make the copy */
length = src->width * src->height * src->bytes;
memcpy (temp_buf_data (new), temp_buf_data (src), length);
}
/* make the copy */
length = src->width * src->height * src->bytes;
memcpy (temp_buf_data (new), temp_buf_data (src), length);
return new;
}
......@@ -473,6 +498,7 @@ temp_buf_unswap (buf)
{
struct stat stat_buf;
FILE * fp;
gboolean succ = FALSE;
if (!buf || !buf->swapped)
return;
......@@ -491,12 +517,18 @@ temp_buf_unswap (buf)
buf->data = temp_buf_allocate (buf->width * buf->height * buf->bytes);
/* Find out if the filename of the swapped data is an existing file... */
/* (buf->filname HAS to be != 0 */
if (!stat (buf->filename, &stat_buf))
{
if ((fp = fopen (buf->filename, "r")))
{
fread (buf->data, buf->width * buf->height * buf->bytes, 1, fp);
size_t blocksRead;
blocksRead = fread (buf->data, buf->width * buf->height * buf->bytes, 1, fp);
fclose (fp);
if (blocksRead != 1)
perror ("Read error on temp buf");
else
succ = TRUE;
}
else
perror ("Error in temp buf caching");
......@@ -504,11 +536,10 @@ temp_buf_unswap (buf)
/* Delete the swap file */
unlink (buf->filename);
}
else
if (!succ)
warning ("Error in temp buf caching: information swapped to disk was lost!");
if (buf->filename)
g_free (buf->filename); /* free filename */
g_free (buf->filename); /* free filename */
buf->filename = NULL;
}
......
......@@ -172,7 +172,7 @@ static void run(char *name, int nparams, GParam *param,
static gint32 load_image(char *file, char *brief) {
FILE* fp; /* Read file pointer */
char *progress; /* Title for progress display */
guchar header[32]; /* File header */
gchar header[32]; /* File header */
int height, width, /* Dimensions of image */
colours; /* Number of colours */
......@@ -306,7 +306,7 @@ static gint32 load_image(char *file, char *brief) {
}
static gint load_palette(FILE *fp, guchar palette[]) {
guchar header[32]; /* File header */
gchar header[32]; /* File header */
guchar buffer[2];
int i, bpp, colours= 0;
......@@ -342,7 +342,7 @@ static gint load_palette(FILE *fp, guchar palette[]) {
static gint save_image(char *file, char *brief, gint32 image, gint32 layer) {
FILE* fp; /* Write file pointer */
char *progress; /* Title for progress display */
guchar header[32]; /* File header */
gchar header[32]; /* File header */
gint colours, type; /* Number of colours, type of layer */
guchar *buffer, /* Temporary buffer */
......
......@@ -162,7 +162,7 @@ gint ncolours;
/* for shaping */
guchar *shape_preview_mask;
gchar *shape_preview_mask;
GtkWidget *shape_window;
GtkWidget *shape_fixed;
GtkPreview *shape_preview;
......@@ -295,7 +295,7 @@ parse_disposal_tag (char *str)
static void
reshape_from_bitmap(guchar* bitmap)
reshape_from_bitmap(gchar* bitmap)
{
GdkBitmap *shape_mask;
......
......@@ -172,7 +172,7 @@ static void run(char *name, int nparams, GParam *param,
static gint32 load_image(char *file, char *brief) {
FILE* fp; /* Read file pointer */
char *progress; /* Title for progress display */
guchar header[32]; /* File header */
gchar header[32]; /* File header */
int height, width, /* Dimensions of image */
colours; /* Number of colours */
......@@ -306,7 +306,7 @@ static gint32 load_image(char *file, char *brief) {
}
static gint load_palette(FILE *fp, guchar palette[]) {
guchar header[32]; /* File header */
gchar header[32]; /* File header */
guchar buffer[2];
int i, bpp, colours= 0;
......@@ -342,7 +342,7 @@ static gint load_palette(FILE *fp, guchar palette[]) {
static gint save_image(char *file, char *brief, gint32 image, gint32 layer) {
FILE* fp; /* Write file pointer */
char *progress; /* Title for progress display */
guchar header[32]; /* File header */
gchar header[32]; /* File header */
gint colours, type; /* Number of colours, type of layer */
guchar *buffer, /* Temporary buffer */
......
......@@ -162,7 +162,7 @@ gint ncolours;
/* for shaping */
guchar *shape_preview_mask;
gchar *shape_preview_mask;
GtkWidget *shape_window;
GtkWidget *shape_fixed;
GtkPreview *shape_preview;
......@@ -295,7 +295,7 @@ parse_disposal_tag (char *str)
static void
reshape_from_bitmap(guchar* bitmap)
reshape_from_bitmap(gchar* bitmap)
{
GdkBitmap *shape_mask;
......
......@@ -43,6 +43,17 @@
* Revision History:
*
* $Log$
* Revision 1.12 1998/04/28 03:50:16 yosh
* * plug-ins/animationplay/animationplay.c
* * plug-ins/CEL/CEL.c
* * plug-ins/psd/psd.c
* * plug-ins/xd/xd.c: applied gimp-joke-980427-0, warning cleanups
*
* * app/temp_buf.c: applied gimp-entity-980427-0, temp_buf swap speedups and
* more robust tempfile handling
*
* -Yosh
*
* Revision 1.11 1998/04/27 22:00:59 neo
* Updated sharpen and despeckle. Wow, sharpen is balzingly fast now, while
* despeckle is still sort of lame...
......@@ -139,14 +150,6 @@
#include <libgimp/gimpui.h>
/*
* Macros...
*/
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
/*
* Constants...
*/
......@@ -704,8 +707,9 @@ despeckle_dialog(void)
gtk_rc_parse(gimp_gtkrc());
gdk_set_use_xshm(gimp_use_xshm());
signal(SIGBUS, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
/* signal(SIGBUS, SIG_DFL);
signal(SIGSEGV, SIG_DFL); */
gtk_preview_set_gamma(gimp_gamma());
gtk_preview_set_install_cmap(gimp_install_cmap());
color_cube = gimp_color_cube();
......@@ -1165,12 +1169,6 @@ preview_update(void)
static void
preview_exit(void)
{
int row, /* Looping var */
size; /* Size of row buffer */
size = MAX_RADIUS * 2 + 1;
g_free(preview_src);
g_free(preview_dst);
g_free(preview_sort);
......
......@@ -172,7 +172,7 @@ typedef struct PsdLayer
gboolean protecttrans;
gboolean visible;
guchar* name;
gchar* name;
gint32 lm_x;
gint32 lm_y;
......@@ -211,7 +211,7 @@ static PSDimage psd_image;
static struct {
guchar signature[4];
gchar signature[4];
gushort version;
guchar reserved[6];
gushort channels;
......@@ -247,9 +247,9 @@ static const gchar *prog_name = "PSD";
static void unpack_pb_channel(FILE *fd, guchar *dst, gint32 unpackedlen,
guint32 *offset);
static void decode(long clen, long uclen, gchar *src, gchar *dst, int step);
static void decode(long clen, long uclen, gchar *src, guchar *dst, int step);
static void packbitsdecode(long *clenp, long uclen,
gchar *src, gchar *dst, int step);
gchar *src, guchar *dst, int step);
static void cmyk2rgb(guchar *src, guchar *destp,
long width, long height, int alpha);
static void cmykp2rgb(guchar *src, guchar *destp,
......@@ -262,9 +262,9 @@ static void xfread(FILE *fd, void *buf, long len, gchar *why);
static void *xmalloc(size_t n);
static void read_whole_file(FILE *fd);
static void reshuffle_cmap(guchar *map256);
static guchar *getpascalstring(FILE *fd, guchar *why);
void throwchunk(size_t n, FILE * fd, guchar *why);
void dumpchunk(size_t n, FILE * fd, guchar *why);
static gchar *getpascalstring(FILE *fd, gchar *why);
void throwchunk(size_t n, FILE * fd, gchar *why);
void dumpchunk(size_t n, FILE * fd, gchar *why);
MAIN()
......@@ -1382,9 +1382,11 @@ load_image(char *name)
{
FILE *fd;
gboolean want_aux;
char *name_buf, *cmykbuf;
char *name_buf;
unsigned char *cmykbuf;
static int number = 1;
unsigned char *dest, *temp;
char *temp;
guchar *dest;
long channels, nguchars;
psd_imagetype imagetype;
int cmyk = 0, step = 1;
......@@ -1864,7 +1866,7 @@ load_image(char *name)
static void
decode(long clen, long uclen, char * src, char * dst, int step)
decode(long clen, long uclen, char * src, guchar * dst, int step)
{
gint i, j;
gint32 l;
......@@ -1893,7 +1895,7 @@ decode(long clen, long uclen, char * src, char * dst, int step)
* Decode a PackBits data stream.
*/
static void
packbitsdecode(long * clenp, long uclen, char * src, char * dst, int step)
packbitsdecode(long * clenp, long uclen, char * src, guchar * dst, int step)
{
gint n, b;
gint32 clen = *clenp;
......@@ -2023,7 +2025,7 @@ cmykp2rgb(unsigned char * src, unsigned char * dst,
int r, g, b, k;
int i, j;
long n;
char *rp, *gp, *bp, *kp, *ap;
guchar *rp, *gp, *bp, *kp, *ap;
n = width * height;
rp = src;
......@@ -2081,7 +2083,7 @@ cmyk_to_rgb(gint *c, gint *m, gint *y, gint *k)
void
dumpchunk(size_t n, FILE * fd, guchar *why)
dumpchunk(size_t n, FILE * fd, gchar *why)
{
guint32 i;
......@@ -2097,9 +2099,9 @@ dumpchunk(size_t n, FILE * fd, guchar *why)
void
throwchunk(size_t n, FILE * fd, guchar *why)
throwchunk(size_t n, FILE * fd, gchar *why)
{
guchar *tmpchunk;
gchar *tmpchunk;
if (n==0)
{
......@@ -2125,10 +2127,10 @@ getchunk(size_t n, FILE * fd, char *why)
#endif
static guchar *
getpascalstring(FILE *fd, guchar *why)
static gchar *
getpascalstring(FILE *fd, gchar *why)
{
guchar *tmpchunk;
gchar *tmpchunk;
guchar len;
xfread(fd, &len, 1, why);
......
......@@ -44,6 +44,17 @@
* Revision History:
*
* $Log$
* Revision 1.6 1998/04/28 03:50:19 yosh
* * plug-ins/animationplay/animationplay.c
* * plug-ins/CEL/CEL.c
* * plug-ins/psd/psd.c
* * plug-ins/xd/xd.c: applied gimp-joke-980427-0, warning cleanups
*
* * app/temp_buf.c: applied gimp-entity-980427-0, temp_buf swap speedups and
* more robust tempfile handling
*
* -Yosh
*
* Revision 1.5 1998/04/27 22:01:01 neo
* Updated sharpen and despeckle. Wow, sharpen is balzingly fast now, while
* despeckle is still sort of lame...
......@@ -331,8 +342,8 @@ run(char *name, /* I - Name of filter program. */
default :
status = STATUS_CALLING_ERROR;
break;;
};
break;
}
/*
* Sharpen the image...
......@@ -372,7 +383,7 @@ run(char *name, /* I - Name of filter program. */
}
else
status = STATUS_EXECUTION_ERROR;
};
}
/*
* Reset the current run status...
......@@ -403,7 +414,7 @@ compute_luts(void)
{
pos_lut[i] = 100 * i / fact;
neg_lut[i] = sharpen_percent * i / 8 / fact;
};
}
}
......@@ -452,7 +463,7 @@ sharpen(void)
{
src_rows[row] = g_malloc(width * sizeof(guchar));
neg_rows[row] = g_malloc(width * sizeof(guchar));
};
}
dst_row = g_malloc(width * sizeof(guchar));
......@@ -487,7 +498,7 @@ sharpen(void)
case 4 :