code cleanup.
2006-07-06 Sven Neumann <sven@gimp.org> * app/base/temp-buf.[ch]: code cleanup.
This commit is contained in:

committed by
Sven Neumann

parent
1e29e7dba8
commit
dc4517cd78
@ -1,3 +1,7 @@
|
|||||||
|
2006-07-06 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* app/base/temp-buf.[ch]: code cleanup.
|
||||||
|
|
||||||
2006-07-05 Sven Neumann <sven@gimp.org>
|
2006-07-05 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* app/gui/splash.c (splash_average_text_area): unset the test
|
* app/gui/splash.c (splash_average_text_area): unset the test
|
||||||
|
@ -27,131 +27,26 @@
|
|||||||
|
|
||||||
#include "base-types.h"
|
#include "base-types.h"
|
||||||
|
|
||||||
|
#include "paint-funcs/paint-funcs.h"
|
||||||
|
|
||||||
#include "pixel-region.h"
|
#include "pixel-region.h"
|
||||||
#include "temp-buf.h"
|
#include "temp-buf.h"
|
||||||
|
|
||||||
#include "paint-funcs/paint-funcs.h"
|
|
||||||
|
|
||||||
|
|
||||||
static guchar * temp_buf_allocate (guint size);
|
|
||||||
static void temp_buf_to_color (TempBuf *src_buf,
|
static void temp_buf_to_color (TempBuf *src_buf,
|
||||||
TempBuf *dest_buf);
|
TempBuf *dest_buf);
|
||||||
static void temp_buf_to_gray (TempBuf *src_buf,
|
static void temp_buf_to_gray (TempBuf *src_buf,
|
||||||
TempBuf *dest_buf);
|
TempBuf *dest_buf);
|
||||||
|
|
||||||
|
|
||||||
/* Memory management */
|
|
||||||
|
|
||||||
static guchar *
|
|
||||||
temp_buf_allocate (guint size)
|
|
||||||
{
|
|
||||||
return g_new (guchar, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* The conversion routines */
|
|
||||||
|
|
||||||
static void
|
|
||||||
temp_buf_to_color (TempBuf *src_buf,
|
|
||||||
TempBuf *dest_buf)
|
|
||||||
{
|
|
||||||
guchar *src;
|
|
||||||
guchar *dest;
|
|
||||||
glong num_pixels;
|
|
||||||
|
|
||||||
src = temp_buf_data (src_buf);
|
|
||||||
dest = temp_buf_data (dest_buf);
|
|
||||||
|
|
||||||
num_pixels = src_buf->width * src_buf->height;
|
|
||||||
|
|
||||||
switch (dest_buf->bytes)
|
|
||||||
{
|
|
||||||
case 3:
|
|
||||||
g_return_if_fail (src_buf->bytes == 1);
|
|
||||||
while (num_pixels--)
|
|
||||||
{
|
|
||||||
guchar tmpch;
|
|
||||||
*dest++ = tmpch = *src++;
|
|
||||||
*dest++ = tmpch;
|
|
||||||
*dest++ = tmpch;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
g_return_if_fail (src_buf->bytes == 2);
|
|
||||||
while (num_pixels--)
|
|
||||||
{
|
|
||||||
guchar tmpch;
|
|
||||||
*dest++ = tmpch = *src++;
|
|
||||||
*dest++ = tmpch;
|
|
||||||
*dest++ = tmpch;
|
|
||||||
|
|
||||||
*dest++ = *src++; /* alpha channel */
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_return_if_reached ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
temp_buf_to_gray (TempBuf *src_buf,
|
|
||||||
TempBuf *dest_buf)
|
|
||||||
{
|
|
||||||
guchar *src;
|
|
||||||
guchar *dest;
|
|
||||||
glong num_pixels;
|
|
||||||
gfloat pix;
|
|
||||||
|
|
||||||
src = temp_buf_data (src_buf);
|
|
||||||
dest = temp_buf_data (dest_buf);
|
|
||||||
|
|
||||||
num_pixels = src_buf->width * src_buf->height;
|
|
||||||
|
|
||||||
switch (dest_buf->bytes)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
g_return_if_fail (src_buf->bytes == 3);
|
|
||||||
while (num_pixels--)
|
|
||||||
{
|
|
||||||
pix = GIMP_RGB_LUMINANCE (src[0], src[1], src[2]) + 0.5;
|
|
||||||
*dest++ = (guchar) pix;
|
|
||||||
|
|
||||||
src += 3;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
g_return_if_fail (src_buf->bytes == 4);
|
|
||||||
while (num_pixels--)
|
|
||||||
{
|
|
||||||
pix = GIMP_RGB_LUMINANCE (src[0], src[1], src[2]) + 0.5;
|
|
||||||
*dest++ = (guchar) pix;
|
|
||||||
|
|
||||||
*dest++ = src[3]; /* alpha channel */
|
|
||||||
|
|
||||||
src += 4;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_return_if_reached ();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TempBuf *
|
TempBuf *
|
||||||
temp_buf_new (gint width,
|
temp_buf_new (gint width,
|
||||||
gint height,
|
gint height,
|
||||||
gint bytes,
|
gint bytes,
|
||||||
gint x,
|
gint x,
|
||||||
gint y,
|
gint y,
|
||||||
guchar *col)
|
const guchar *col)
|
||||||
{
|
{
|
||||||
glong i;
|
|
||||||
guchar *data;
|
|
||||||
TempBuf *temp;
|
TempBuf *temp;
|
||||||
|
|
||||||
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
g_return_val_if_fail (width > 0 && height > 0, NULL);
|
||||||
@ -165,11 +60,13 @@ temp_buf_new (gint width,
|
|||||||
temp->x = x;
|
temp->x = x;
|
||||||
temp->y = y;
|
temp->y = y;
|
||||||
|
|
||||||
temp->data = data = temp_buf_allocate (width * height * bytes);
|
temp->data = g_new (guchar, width * height * bytes);
|
||||||
|
|
||||||
/* initialize the data */
|
/* initialize the data */
|
||||||
if (col)
|
if (col)
|
||||||
{
|
{
|
||||||
|
glong i;
|
||||||
|
|
||||||
/* First check if we can save a lot of work */
|
/* First check if we can save a lot of work */
|
||||||
for (i = 1; i < bytes; i++)
|
for (i = 1; i < bytes; i++)
|
||||||
{
|
{
|
||||||
@ -179,20 +76,20 @@ temp_buf_new (gint width,
|
|||||||
|
|
||||||
if (i == bytes)
|
if (i == bytes)
|
||||||
{
|
{
|
||||||
memset (data, *col, width * height * bytes);
|
memset (temp->data, *col, width * height * bytes);
|
||||||
}
|
}
|
||||||
else /* No, we cannot */
|
else /* No, we cannot */
|
||||||
{
|
{
|
||||||
guchar *dptr = data;
|
guchar *dptr = temp->data;
|
||||||
|
|
||||||
/* Fill the first row */
|
/* Fill the first row */
|
||||||
for (i = width - 1; i >= 0; --i)
|
for (i = width - 1; i >= 0; --i)
|
||||||
{
|
{
|
||||||
guchar *init = col;
|
const guchar *c = col;
|
||||||
gint j = bytes;
|
gint j = bytes;
|
||||||
|
|
||||||
while (j--)
|
while (j--)
|
||||||
*dptr++ = *init++;
|
*dptr++ = *c++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now copy from it (we set bytes to bytes-per-row now) */
|
/* Now copy from it (we set bytes to bytes-per-row now) */
|
||||||
@ -200,7 +97,7 @@ temp_buf_new (gint width,
|
|||||||
|
|
||||||
while (--height)
|
while (--height)
|
||||||
{
|
{
|
||||||
memcpy (dptr, data, bytes);
|
memcpy (dptr, temp->data, bytes);
|
||||||
dptr += bytes;
|
dptr += bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +115,7 @@ temp_buf_new_check (gint width,
|
|||||||
GimpCheckType check_type,
|
GimpCheckType check_type,
|
||||||
GimpCheckSize check_size)
|
GimpCheckSize check_size)
|
||||||
{
|
{
|
||||||
TempBuf *newbuf;
|
TempBuf *new;
|
||||||
guchar *data;
|
guchar *data;
|
||||||
guchar check_shift = 0;
|
guchar check_shift = 0;
|
||||||
guchar check_mod = 0;
|
guchar check_mod = 0;
|
||||||
@ -246,8 +143,8 @@ temp_buf_new_check (gint width,
|
|||||||
|
|
||||||
gimp_checks_get_shades (check_type, &check_light, &check_dark);
|
gimp_checks_get_shades (check_type, &check_light, &check_dark);
|
||||||
|
|
||||||
newbuf = temp_buf_new (width, height, 3, 0, 0, NULL);
|
new = temp_buf_new (width, height, 3, 0, 0, NULL);
|
||||||
data = temp_buf_data (newbuf);
|
data = temp_buf_data (new);
|
||||||
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
@ -268,23 +165,19 @@ temp_buf_new_check (gint width,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newbuf;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
TempBuf *
|
TempBuf *
|
||||||
temp_buf_copy (TempBuf *src,
|
temp_buf_copy (TempBuf *src,
|
||||||
TempBuf *dest)
|
TempBuf *dest)
|
||||||
{
|
{
|
||||||
glong length;
|
|
||||||
|
|
||||||
g_return_val_if_fail (src != NULL, NULL);
|
g_return_val_if_fail (src != NULL, NULL);
|
||||||
g_return_val_if_fail (! dest || (dest->width == src->width &&
|
g_return_val_if_fail (! dest || (dest->width == src->width &&
|
||||||
dest->height == src->height), NULL);
|
dest->height == src->height), NULL);
|
||||||
|
|
||||||
if (! dest)
|
if (! dest)
|
||||||
{
|
|
||||||
dest = temp_buf_new (src->width, src->height, src->bytes, 0, 0, NULL);
|
dest = temp_buf_new (src->width, src->height, src->bytes, 0, 0, NULL);
|
||||||
}
|
|
||||||
|
|
||||||
if (src->bytes != dest->bytes)
|
if (src->bytes != dest->bytes)
|
||||||
{
|
{
|
||||||
@ -301,9 +194,9 @@ temp_buf_copy (TempBuf *src,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* make the copy */
|
memcpy (temp_buf_data (dest),
|
||||||
length = src->width * src->height * src->bytes;
|
temp_buf_data (src),
|
||||||
memcpy (temp_buf_data (dest), temp_buf_data (src), length);
|
src->width * src->height * src->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
@ -325,13 +218,11 @@ temp_buf_resize (TempBuf *buf,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gint new_size;
|
gsize size = width * height * bytes;
|
||||||
|
|
||||||
new_size = width * height * bytes;
|
if (size != (buf->width * buf->height * buf->bytes))
|
||||||
|
|
||||||
if (new_size != (buf->width * buf->height * buf->bytes))
|
|
||||||
{
|
{
|
||||||
buf->data = g_renew (guchar, buf->data, new_size);
|
buf->data = g_renew (guchar, buf->data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->x = x;
|
buf->x = x;
|
||||||
@ -349,13 +240,13 @@ temp_buf_scale (TempBuf *src,
|
|||||||
gint new_width,
|
gint new_width,
|
||||||
gint new_height)
|
gint new_height)
|
||||||
{
|
{
|
||||||
gint loop1;
|
TempBuf *dest;
|
||||||
gint loop2;
|
|
||||||
gdouble x_ratio;
|
|
||||||
gdouble y_ratio;
|
|
||||||
guchar *src_data;
|
guchar *src_data;
|
||||||
guchar *dest_data;
|
guchar *dest_data;
|
||||||
TempBuf *dest;
|
gdouble x_ratio;
|
||||||
|
gdouble y_ratio;
|
||||||
|
gint loop1;
|
||||||
|
gint loop2;
|
||||||
|
|
||||||
g_return_val_if_fail (src != NULL, NULL);
|
g_return_val_if_fail (src != NULL, NULL);
|
||||||
g_return_val_if_fail (new_width > 0 && new_height > 0, NULL);
|
g_return_val_if_fail (new_width > 0 && new_height > 0, NULL);
|
||||||
@ -375,9 +266,9 @@ temp_buf_scale (TempBuf *src,
|
|||||||
{
|
{
|
||||||
for (loop2 = 0 ; loop2 < new_width ; loop2++)
|
for (loop2 = 0 ; loop2 < new_width ; loop2++)
|
||||||
{
|
{
|
||||||
gint i;
|
|
||||||
guchar *src_pixel;
|
guchar *src_pixel;
|
||||||
guchar *dest_pixel;
|
guchar *dest_pixel;
|
||||||
|
gint i;
|
||||||
|
|
||||||
src_pixel = src_data +
|
src_pixel = src_data +
|
||||||
(gint) (loop2 * x_ratio) * src->bytes +
|
(gint) (loop2 * x_ratio) * src->bytes +
|
||||||
@ -473,8 +364,6 @@ temp_buf_data (TempBuf *temp_buf)
|
|||||||
guchar *
|
guchar *
|
||||||
temp_buf_data_clear (TempBuf *temp_buf)
|
temp_buf_data_clear (TempBuf *temp_buf)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (temp_buf != NULL, NULL);
|
|
||||||
|
|
||||||
memset (temp_buf->data, 0,
|
memset (temp_buf->data, 0,
|
||||||
temp_buf->height * temp_buf->width * temp_buf->bytes);
|
temp_buf->height * temp_buf->width * temp_buf->bytes);
|
||||||
|
|
||||||
@ -495,6 +384,102 @@ temp_buf_get_memsize (TempBuf *temp_buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The conversion routines */
|
||||||
|
|
||||||
|
static void
|
||||||
|
temp_buf_to_color (TempBuf *src_buf,
|
||||||
|
TempBuf *dest_buf)
|
||||||
|
{
|
||||||
|
guchar *src;
|
||||||
|
guchar *dest;
|
||||||
|
glong num_pixels;
|
||||||
|
|
||||||
|
src = temp_buf_data (src_buf);
|
||||||
|
dest = temp_buf_data (dest_buf);
|
||||||
|
|
||||||
|
num_pixels = src_buf->width * src_buf->height;
|
||||||
|
|
||||||
|
switch (dest_buf->bytes)
|
||||||
|
{
|
||||||
|
case 3:
|
||||||
|
g_return_if_fail (src_buf->bytes == 1);
|
||||||
|
while (num_pixels--)
|
||||||
|
{
|
||||||
|
guchar tmp;
|
||||||
|
|
||||||
|
*dest++ = tmp = *src++;
|
||||||
|
*dest++ = tmp;
|
||||||
|
*dest++ = tmp;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
g_return_if_fail (src_buf->bytes == 2);
|
||||||
|
while (num_pixels--)
|
||||||
|
{
|
||||||
|
guchar tmp;
|
||||||
|
|
||||||
|
*dest++ = tmp = *src++;
|
||||||
|
*dest++ = tmp;
|
||||||
|
*dest++ = tmp;
|
||||||
|
|
||||||
|
*dest++ = *src++; /* alpha channel */
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_return_if_reached ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
temp_buf_to_gray (TempBuf *src_buf,
|
||||||
|
TempBuf *dest_buf)
|
||||||
|
{
|
||||||
|
const guchar *src;
|
||||||
|
guchar *dest;
|
||||||
|
glong num_pixels;
|
||||||
|
|
||||||
|
src = temp_buf_data (src_buf);
|
||||||
|
dest = temp_buf_data (dest_buf);
|
||||||
|
|
||||||
|
num_pixels = src_buf->width * src_buf->height;
|
||||||
|
|
||||||
|
switch (dest_buf->bytes)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
g_return_if_fail (src_buf->bytes == 3);
|
||||||
|
while (num_pixels--)
|
||||||
|
{
|
||||||
|
gint lum = GIMP_RGB_LUMINANCE (src[0], src[1], src[2]) + 0.5;
|
||||||
|
|
||||||
|
*dest++ = (guchar) lum;
|
||||||
|
|
||||||
|
src += 3;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
g_return_if_fail (src_buf->bytes == 4);
|
||||||
|
while (num_pixels--)
|
||||||
|
{
|
||||||
|
gint lum = GIMP_RGB_LUMINANCE (src[0], src[1], src[2]) + 0.5;
|
||||||
|
|
||||||
|
*dest++ = (guchar) lum;
|
||||||
|
*dest++ = src[3]; /* alpha channel */
|
||||||
|
|
||||||
|
src += 4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_return_if_reached ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* Mask buffer functions *
|
* Mask buffer functions *
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
@ -38,7 +38,7 @@ TempBuf * temp_buf_new (gint width,
|
|||||||
gint bytes,
|
gint bytes,
|
||||||
gint x,
|
gint x,
|
||||||
gint y,
|
gint y,
|
||||||
guchar *col);
|
const guchar *col);
|
||||||
TempBuf * temp_buf_new_check (gint width,
|
TempBuf * temp_buf_new_check (gint width,
|
||||||
gint height,
|
gint height,
|
||||||
GimpCheckType check_type,
|
GimpCheckType check_type,
|
||||||
@ -53,7 +53,7 @@ TempBuf * temp_buf_resize (TempBuf *buf,
|
|||||||
gint height);
|
gint height);
|
||||||
TempBuf * temp_buf_scale (TempBuf *buf,
|
TempBuf * temp_buf_scale (TempBuf *buf,
|
||||||
gint width,
|
gint width,
|
||||||
gint height);
|
gint height) G_GNUC_WARN_UNUSED_RESULT;
|
||||||
TempBuf * temp_buf_copy_area (TempBuf *src,
|
TempBuf * temp_buf_copy_area (TempBuf *src,
|
||||||
TempBuf *dest,
|
TempBuf *dest,
|
||||||
gint x,
|
gint x,
|
||||||
|
Reference in New Issue
Block a user