Commit a2952f2b authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

temp_buf_data_clear(): the temp_buf's size is (width * height * bytes).

2001-01-02  Michael Natterer  <mitch@gimp.org>

	* app/temp_buf.[ch]: temp_buf_data_clear(): the temp_buf's size is
	(width * height * bytes). Cleanups.

	* app/fileops.c: removed a debugging g_print().
parent b4fc3293
......@@ -37,8 +37,6 @@
#include "apptypes.h"
#include "appenv.h"
#include "drawable.h"
#include "gdisplay.h"
#include "gimpimage.h"
#include "gimprc.h"
#include "paint_funcs.h"
......@@ -49,10 +47,10 @@
static guchar * temp_buf_allocate (guint);
static void temp_buf_to_color (TempBuf *,
TempBuf *);
static void temp_buf_to_gray (TempBuf *,
TempBuf *);
static void temp_buf_to_color (TempBuf *src_buf,
TempBuf *dest_buf);
static void temp_buf_to_gray (TempBuf *src_buf,
TempBuf *dest_buf);
/* Memory management */
......@@ -76,7 +74,7 @@ temp_buf_to_color (TempBuf *src_buf,
{
guchar *src;
guchar *dest;
long num_bytes;
glong num_bytes;
src = temp_buf_data (src_buf);
dest = temp_buf_data (dest_buf);
......@@ -100,8 +98,8 @@ temp_buf_to_gray (TempBuf *src_buf,
{
guchar *src;
guchar *dest;
long num_bytes;
float pix;
glong num_bytes;
gfloat pix;
src = temp_buf_data (src_buf);
dest = temp_buf_data (dest_buf);
......@@ -118,7 +116,6 @@ temp_buf_to_gray (TempBuf *src_buf,
}
}
TempBuf *
temp_buf_new (gint width,
gint height,
......@@ -127,8 +124,8 @@ temp_buf_new (gint width,
gint y,
guchar *col)
{
long i;
int j;
glong i;
gint j;
guchar *data;
TempBuf *temp;
......@@ -156,26 +153,33 @@ temp_buf_new (gint width,
{
memset (data, *col, width * height * 3);
}
else if ((bytes == 4) && (col[1] == *col) && (*col == col[2]) && (col[2] == col[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 */
guchar * dptr;
guchar *dptr;
/* Fill the first row */
dptr = data;
for (i = width - 1; i >= 0; --i)
{
guchar * init;
guchar *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);
......@@ -187,13 +191,12 @@ temp_buf_new (gint width,
return temp;
}
TempBuf *
temp_buf_copy (TempBuf *src,
TempBuf *dest)
{
TempBuf * new;
long length;
TempBuf *new;
glong length;
if (!src)
{
......@@ -202,7 +205,9 @@ temp_buf_copy (TempBuf *src,
}
if (!dest)
{
new = temp_buf_new (src->width, src->height, src->bytes, 0, 0, NULL);
}
else
{
new = dest;
......@@ -218,6 +223,7 @@ temp_buf_copy (TempBuf *src,
temp_buf_to_color (src, new);
else
g_message ("Cannot convert from indexed color.");
return new;
}
}
......@@ -229,23 +235,24 @@ temp_buf_copy (TempBuf *src,
return new;
}
TempBuf *
temp_buf_resize (TempBuf *buf,
gint bytes,
gint x,
gint y,
gint w,
gint h)
gint width,
gint height)
{
gint size;
/* calculate the requested size */
size = w * h * bytes;
size = width * height * bytes;
/* First, configure the canvas buffer */
if (!buf)
buf = temp_buf_new (w, h, bytes, x, y, NULL);
{
buf = temp_buf_new (width, height, bytes, x, y, NULL);
}
else
{
if (size != (buf->width * buf->height * buf->bytes))
......@@ -260,25 +267,24 @@ temp_buf_resize (TempBuf *buf,
/* Make sure the temp buf fields are valid */
buf->x = x;
buf->y = y;
buf->width = w;
buf->height = h;
buf->width = width;
buf->height = height;
buf->bytes = bytes;
}
return buf;
}
TempBuf *
temp_buf_copy_area (TempBuf *src,
TempBuf *dest,
gint x,
gint y,
gint w,
gint h,
gint width,
gint height,
gint border)
{
TempBuf * new;
TempBuf *new;
PixelRegion srcR, destR;
guchar empty[MAX_CHANNELS] = { 0, 0, 0, 0 };
gint x1, y1, x2, y2;
......@@ -292,19 +298,21 @@ temp_buf_copy_area (TempBuf *src,
/* some bounds checking */
x1 = CLAMP (x, 0, src->width);
y1 = CLAMP (y, 0, src->height);
x2 = CLAMP (x + w, 0, src->width);
y2 = CLAMP (y + h, 0, src->height);
x2 = CLAMP (x + width, 0, src->width);
y2 = CLAMP (y + height, 0, src->height);
if (!(x2 - x1) || !(y2 - y1))
return dest;
x = x1 - border;
y = y1 - border;
w = (x2 - x1) + border * 2;
h = (y2 - y1) + border * 2;
width = (x2 - x1) + border * 2;
height = (y2 - y1) + border * 2;
if (!dest)
new = temp_buf_new (w, h, src->bytes, x, y, empty);
{
new = temp_buf_new (width, height, src->bytes, x, y, empty);
}
else
{
new = dest;
......@@ -331,7 +339,6 @@ temp_buf_copy_area (TempBuf *src,
return new;
}
void
temp_buf_free (TempBuf *temp_buf)
{
......@@ -344,7 +351,6 @@ temp_buf_free (TempBuf *temp_buf)
g_free (temp_buf);
}
guchar *
temp_buf_data (TempBuf *temp_buf)
{
......@@ -360,7 +366,9 @@ temp_buf_data_clear (TempBuf *temp_buf)
if (temp_buf->swapped)
temp_buf_unswap (temp_buf);
memset (temp_buf->data, 0, temp_buf->height * temp_buf->width);
memset (temp_buf->data, 0,
temp_buf->height * temp_buf->width * temp_buf->bytes);
return temp_buf->data;
}
......@@ -375,26 +383,33 @@ mask_buf_new (gint width,
{
static guchar empty = 0;
return (temp_buf_new (width, height, 1, 0, 0, &empty));
return temp_buf_new (width, height, 1, 0, 0, &empty);
}
void
mask_buf_free (MaskBuf *mask)
{
temp_buf_free ((TempBuf *) mask);
}
guchar *
mask_buf_data (MaskBuf *mask_buf)
{
if (mask_buf->swapped)
temp_buf_unswap (mask_buf);
temp_buf_unswap ((TempBuf *) mask_buf);
return mask_buf->data;
}
guchar *
mask_buf_data_clear (MaskBuf *mask_buf)
{
if (mask_buf->swapped)
temp_buf_unswap ((TempBuf *) mask_buf);
return temp_buf_data_clear ((TempBuf *) mask_buf);
}
/******************************************************************
* temp buffer disk caching functions *
......@@ -434,20 +449,20 @@ static gchar *
generate_unique_filename (void)
{
pid_t pid;
pid = getpid ();
return g_strdup_printf ("%s" G_DIR_SEPARATOR_S "gimp%d.%d",
temp_path, (int) pid, swap_index++);
}
void
temp_buf_swap (TempBuf *buf)
{
TempBuf * swap;
gchar * filename;
TempBuf *swap;
gchar *filename;
struct stat stat_buf;
gint err;
FILE * fp;
FILE *fp;
if (!buf || buf->swapped)
return;
......@@ -512,12 +527,11 @@ temp_buf_swap (TempBuf *buf)
swap->filename = filename;
}
void
temp_buf_unswap (TempBuf *buf)
{
struct stat stat_buf;
FILE * fp;
FILE *fp;
gboolean succ = FALSE;
if (!buf || !buf->swapped)
......@@ -563,7 +577,6 @@ temp_buf_unswap (TempBuf *buf)
buf->filename = NULL;
}
void
temp_buf_swap_free (TempBuf *buf)
{
......@@ -596,7 +609,6 @@ temp_buf_swap_free (TempBuf *buf)
buf->filename = NULL;
}
void
swapping_free (void)
{
......
......@@ -36,43 +36,44 @@ struct _TempBuf
/* The temp buffer functions */
TempBuf * temp_buf_new (gint ,
gint ,
gint ,
gint ,
gint ,
guchar *);
TempBuf * temp_buf_copy (TempBuf *,
TempBuf *);
TempBuf * temp_buf_resize (TempBuf *,
gint ,
gint ,
gint ,
gint ,
gint );
TempBuf * temp_buf_copy_area (TempBuf *,
TempBuf *,
gint ,
gint ,
gint ,
gint ,
gint );
void temp_buf_free (TempBuf *);
guchar * temp_buf_data (TempBuf *);
guchar * temp_buf_data_clear (TempBuf *);
TempBuf * temp_buf_new (gint width,
gint height,
gint bytes,
gint x,
gint y,
guchar *col);
TempBuf * temp_buf_copy (TempBuf *src,
TempBuf *dest);
TempBuf * temp_buf_resize (TempBuf *buf,
gint bytes,
gint x,
gint y,
gint width,
gint height);
TempBuf * temp_buf_copy_area (TempBuf *src,
TempBuf *dest,
gint x,
gint y,
gint width,
gint height,
gint border);
void temp_buf_free (TempBuf *buf);
guchar * temp_buf_data (TempBuf *buf);
guchar * temp_buf_data_clear (TempBuf *buf);
/* The mask buffer functions */
MaskBuf * mask_buf_new (gint ,
gint );
void mask_buf_free (MaskBuf *);
guchar * mask_buf_data (MaskBuf *);
MaskBuf * mask_buf_new (gint width,
gint height);
void mask_buf_free (MaskBuf *mask_buf);
guchar * mask_buf_data (MaskBuf *mask_buf);
guchar * mask_buf_data_clear (MaskBuf *mask_buf);
/* The disk caching functions */
void temp_buf_swap (TempBuf *);
void temp_buf_unswap (TempBuf *);
void temp_buf_swap_free (TempBuf *);
void temp_buf_swap (TempBuf *buf);
void temp_buf_unswap (TempBuf *buf);
void temp_buf_swap_free (TempBuf *buf);
/* Called by app_procs:exit() to free up the cached undo buffer */
......
......@@ -617,8 +617,6 @@ file_save_a_copy_as_callback (GtkWidget *widget,
if (! gimp_image_active_drawable (gdisplay->gimage))
return;
g_print ("Save a Copy\n");
the_gimage = gdisplay->gimage;
set_filename = FALSE;
......
......@@ -37,8 +37,6 @@
#include "apptypes.h"
#include "appenv.h"
#include "drawable.h"
#include "gdisplay.h"
#include "gimpimage.h"
#include "gimprc.h"
#include "paint_funcs.h"
......@@ -49,10 +47,10 @@
static guchar * temp_buf_allocate (guint);
static void temp_buf_to_color (TempBuf *,
TempBuf *);
static void temp_buf_to_gray (TempBuf *,
TempBuf *);
static void temp_buf_to_color (TempBuf *src_buf,
TempBuf *dest_buf);
static void temp_buf_to_gray (TempBuf *src_buf,
TempBuf *dest_buf);
/* Memory management */
......@@ -76,7 +74,7 @@ temp_buf_to_color (TempBuf *src_buf,
{
guchar *src;
guchar *dest;
long num_bytes;
glong num_bytes;
src = temp_buf_data (src_buf);
dest = temp_buf_data (dest_buf);
......@@ -100,8 +98,8 @@ temp_buf_to_gray (TempBuf *src_buf,
{
guchar *src;
guchar *dest;
long num_bytes;
float pix;
glong num_bytes;
gfloat pix;
src = temp_buf_data (src_buf);
dest = temp_buf_data (dest_buf);
......@@ -118,7 +116,6 @@ temp_buf_to_gray (TempBuf *src_buf,
}
}
TempBuf *
temp_buf_new (gint width,
gint height,
......@@ -127,8 +124,8 @@ temp_buf_new (gint width,
gint y,
guchar *col)
{
long i;
int j;
glong i;
gint j;
guchar *data;
TempBuf *temp;
......@@ -156,26 +153,33 @@ temp_buf_new (gint width,
{
memset (data, *col, width * height * 3);
}
else if ((bytes == 4) && (col[1] == *col) && (*col == col[2]) && (col[2] == col[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 */
guchar * dptr;
guchar *dptr;
/* Fill the first row */
dptr = data;
for (i = width - 1; i >= 0; --i)
{
guchar * init;
guchar *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);
......@@ -187,13 +191,12 @@ temp_buf_new (gint width,
return temp;
}
TempBuf *
temp_buf_copy (TempBuf *src,
TempBuf *dest)
{
TempBuf * new;
long length;
TempBuf *new;
glong length;
if (!src)
{
......@@ -202,7 +205,9 @@ temp_buf_copy (TempBuf *src,
}
if (!dest)
{
new = temp_buf_new (src->width, src->height, src->bytes, 0, 0, NULL);
}
else
{
new = dest;
......@@ -218,6 +223,7 @@ temp_buf_copy (TempBuf *src,
temp_buf_to_color (src, new);
else
g_message ("Cannot convert from indexed color.");
return new;
}
}
......@@ -229,23 +235,24 @@ temp_buf_copy (TempBuf *src,
return new;
}
TempBuf *
temp_buf_resize (TempBuf *buf,
gint bytes,
gint x,
gint y,
gint w,
gint h)
gint width,
gint height)
{
gint size;
/* calculate the requested size */
size = w * h * bytes;
size = width * height * bytes;
/* First, configure the canvas buffer */
if (!buf)
buf = temp_buf_new (w, h, bytes, x, y, NULL);
{
buf = temp_buf_new (width, height, bytes, x, y, NULL);
}
else
{
if (size != (buf->width * buf->height * buf->bytes))
......@@ -260,25 +267,24 @@ temp_buf_resize (TempBuf *buf,
/* Make sure the temp buf fields are valid */
buf->x = x;
buf->y = y;
buf->width = w;
buf->height = h;
buf->width = width;
buf->height = height;
buf->bytes = bytes;
}
return buf;
}
TempBuf *
temp_buf_copy_area (TempBuf *src,
TempBuf *dest,
gint x,
gint y,
gint w,
gint h,
gint width,
gint height,
gint border)
{
TempBuf * new;
TempBuf *new;
PixelRegion srcR, destR;
guchar empty[MAX_CHANNELS] = { 0, 0, 0, 0 };
gint x1, y1, x2, y2;
......@@ -292,19 +298,21 @@ temp_buf_copy_area (TempBuf *src,
/* some bounds checking */
x1 = CLAMP (x, 0, src->width);
y1 = CLAMP (y, 0, src->height);
x2 = CLAMP (x + w, 0, src->width);
y2 = CLAMP (y + h, 0, src->height);
x2 = CLAMP (x + width, 0, src->width);
y2 = CLAMP (y + height, 0, src->height);
if (!(x2 - x1) || !(y2 - y1))
return dest;
x = x1 - border;
y = y1 - border;
w = (x2 - x1) + border * 2;
h = (y2 - y1) + border * 2;
width = (x2 - x1) + border * 2;
height = (y2 - y1) + border * 2;
if (!dest)
new = temp_buf_new (w, h, src->bytes, x, y, empty);
{
new = temp_buf_new (width, height, src->bytes, x, y, empty);
}
else
{