Commit bd7a4bf1 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/Makefile.am new file with one set of functions...

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

	* app/Makefile.am
	* app/gimpdrawablepreview.[ch]: new file with one set of functions...

	* app/channel.[ch]
	* app/layer.[ch]: ...instead of having everything duplicated three
	times here.

	* app/channels_dialog.c
	* app/floating_sel.c
	* app/floating_sel.h
	* app/gimpdnd.c
	* app/gimpimage.c
	* app/layer_select.c
	* app/layers_dialog.c
	* app/selection.c
	* app/pdb/drawable_cmds.c
	* tools/pdbgen/pdb/drawable.pdb: changed accordingly, cleanup.
parent b832a469
2001-01-29 Michael Natterer <mitch@gimp.org>
* app/Makefile.am
* app/gimpdrawablepreview.[ch]: new file with one set of functions...
* app/channel.[ch]
* app/layer.[ch]: ...instead of having everything duplicated three
times here.
* app/channels_dialog.c
* app/floating_sel.c
* app/floating_sel.h
* app/gimpdnd.c
* app/gimpimage.c
* app/layer_select.c
* app/layers_dialog.c
* app/selection.c
* app/pdb/drawable_cmds.c
* tools/pdbgen/pdb/drawable.pdb: changed accordingly, cleanup.
2001-01-29 Sven Neumann <sven@gimp.org>
* HACKING: defined The GIMP Hackordnung (ACHTUNG!)
......
......@@ -119,6 +119,8 @@ gimp_SOURCES = \
gimpdnd.h \
gimpdrawable.c \
gimpdrawable.h \
gimpdrawablepreview.c \
gimpdrawablepreview.h \
gimphelp.c \
gimphelp.h \
gimphistogram.c \
......
......@@ -23,6 +23,7 @@
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "apptypes.h"
......@@ -50,16 +51,12 @@
#include "libgimp/gimpintl.h"
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_destroy (GtkObject *object);
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_destroy (GtkObject *object);
static TempBuf * gimp_channel_preview_private (GimpChannel *channel,
gint width,
gint height);
static GimpDrawableClass *parent_class = NULL;
static GimpDrawableClass * parent_class = NULL;
GtkType
......@@ -102,11 +99,44 @@ gimp_channel_class_init (GimpChannelClass *klass)
static void
gimp_channel_init (GimpChannel *channel)
{
gimp_rgba_set (&channel->color, 0.0, 0.0, 0.0, 1.0);
channel->show_masked = FALSE;
/* Selection mask variables */
channel->boundary_known = TRUE;
channel->segs_in = NULL;
channel->segs_out = NULL;
channel->num_segs_in = 0;
channel->num_segs_out = 0;
channel->empty = TRUE;
channel->bounds_known = TRUE;
channel->x1 = 0;
channel->y1 = 0;
channel->x2 = 0;
channel->y2 = 0;
}
/**************************/
/* Function definitions */
/**************************/
static void
gimp_channel_destroy (GtkObject *object)
{
GimpChannel *channel;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_CHANNEL (object));
channel = GIMP_CHANNEL (object);
/* free the segments? */
if (channel->segs_in)
g_free (channel->segs_in);
if (channel->segs_out)
g_free (channel->segs_out);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_channel_validate (TileManager *tm,
......@@ -139,17 +169,8 @@ gimp_channel_new (GimpImage *gimage,
channel->show_masked = TRUE;
/* selection mask variables */
channel->empty = TRUE;
channel->segs_in = NULL;
channel->segs_out = NULL;
channel->num_segs_in = 0;
channel->num_segs_out = 0;
channel->bounds_known = TRUE;
channel->boundary_known = TRUE;
channel->x1 = 0;
channel->y1 = 0;
channel->x2 = width;
channel->y2 = height;
channel->x2 = width;
channel->y2 = height;
return channel;
}
......@@ -227,7 +248,7 @@ gimp_channel_get_color (const GimpChannel *channel)
return &channel->color;
}
gint
gimp_channel_get_opacity (const GimpChannel *channel)
{
......@@ -249,26 +270,6 @@ gimp_channel_set_opacity (GimpChannel *channel,
channel->color.a = opacity / 100.0;
}
static void
gimp_channel_destroy (GtkObject *object)
{
GimpChannel *channel;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_CHANNEL (object));
channel = GIMP_CHANNEL (object);
/* free the segments? */
if (channel->segs_in)
g_free (channel->segs_in);
if (channel->segs_out)
g_free (channel->segs_out);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
void
gimp_channel_scale (GimpChannel *channel,
gint new_width,
......@@ -436,92 +437,6 @@ gimp_channel_toggle_visibility (GimpChannel *channel)
return GIMP_DRAWABLE (channel)->visible;
}
TempBuf *
gimp_channel_preview (GimpChannel *channel,
gint width,
gint height)
{
/* Ok prime the cache with a large preview if the cache is invalid */
if (! GIMP_DRAWABLE (channel)->preview_valid &&
width <= PREVIEW_CACHE_PRIME_WIDTH &&
height <= PREVIEW_CACHE_PRIME_HEIGHT &&
GIMP_DRAWABLE (channel)->gimage &&
GIMP_DRAWABLE (channel)->gimage->width > PREVIEW_CACHE_PRIME_WIDTH &&
GIMP_DRAWABLE (channel)->gimage->height > PREVIEW_CACHE_PRIME_HEIGHT)
{
TempBuf * tb = gimp_channel_preview_private (channel,
PREVIEW_CACHE_PRIME_WIDTH,
PREVIEW_CACHE_PRIME_HEIGHT);
/* Save the 2nd call */
if (width == PREVIEW_CACHE_PRIME_WIDTH &&
height == PREVIEW_CACHE_PRIME_HEIGHT)
return tb;
}
/* Second call - should NOT visit the tile cache... */
return gimp_channel_preview_private (channel, width, height);
}
static TempBuf *
gimp_channel_preview_private (GimpChannel *channel,
gint width,
gint height)
{
MaskBuf *preview_buf;
PixelRegion srcPR;
PixelRegion destPR;
gint subsample;
TempBuf *ret_buf;
g_return_val_if_fail (channel != NULL, NULL);
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL);
/* The easy way */
if (GIMP_DRAWABLE (channel)->preview_valid &&
(ret_buf =
gimp_preview_cache_get (& (GIMP_DRAWABLE (channel)->preview_cache),
width, height)))
{
return ret_buf;
}
/* The hard way */
else
{
/* calculate 'acceptable' subsample */
subsample = 1;
if (width < 1) width = 1;
if (height < 1) height = 1;
while ((width * (subsample + 1) * 2 < GIMP_DRAWABLE (channel)->width) &&
(height * (subsample + 1) * 2 < GIMP_DRAWABLE (channel)->height))
subsample = subsample + 1;
pixel_region_init (&srcPR, GIMP_DRAWABLE (channel)->tiles,
0, 0,
GIMP_DRAWABLE (channel)->width,
GIMP_DRAWABLE (channel)->height, FALSE);
preview_buf = mask_buf_new (width, height);
destPR.bytes = 1;
destPR.x = 0;
destPR.y = 0;
destPR.w = width;
destPR.h = height;
destPR.rowstride = width;
destPR.data = mask_buf_data (preview_buf);
subsample_region (&srcPR, &destPR, subsample);
if (!GIMP_DRAWABLE (channel)->preview_valid)
gimp_preview_cache_invalidate (&(GIMP_DRAWABLE(channel)->preview_cache));
GIMP_DRAWABLE (channel)->preview_valid = TRUE;
gimp_preview_cache_add (&(GIMP_DRAWABLE (channel)->preview_cache),
preview_buf);
return preview_buf;
}
}
/******************************/
/* selection mask functions */
/******************************/
......
......@@ -110,12 +110,7 @@ void gimp_channel_resize (GimpChannel *channel,
gint offy);
void gimp_channel_update (GimpChannel *channel);
/* access functions */
gboolean gimp_channel_toggle_visibility (GimpChannel *channel);
TempBuf * gimp_channel_preview (GimpChannel *channel,
gint width,
gint height);
/* selection mask functions */
......
......@@ -36,6 +36,7 @@
#include "gimage.h"
#include "gimage_mask.h"
#include "gimpdnd.h"
#include "gimpdrawablepreview.h"
#include "gimppreviewcache.h"
#include "gimprc.h"
#include "gimpui.h"
......@@ -2104,18 +2105,21 @@ channel_widget_preview_redraw (ChannelWidget *channel_widget)
if (channelsD->ratio > 1.0) /* Preview is scaling up! */
{
preview_buf = gimp_channel_preview (channel_widget->channel,
channelsD->gimage_width,
channelsD->gimage_height);
preview_buf =
gimp_drawable_preview (GIMP_DRAWABLE (channel_widget->channel),
channelsD->gimage_width,
channelsD->gimage_height);
preview_buf = gimp_preview_scale (preview_buf,
channel_widget->width,
channel_widget->height);
}
else
{
preview_buf = gimp_channel_preview (channel_widget->channel,
channel_widget->width,
channel_widget->height);
preview_buf =
gimp_drawable_preview (GIMP_DRAWABLE (channel_widget->channel),
channel_widget->width,
channel_widget->height);
}
break;
......
......@@ -23,6 +23,7 @@
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "apptypes.h"
......@@ -50,16 +51,12 @@
#include "libgimp/gimpintl.h"
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_destroy (GtkObject *object);
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_destroy (GtkObject *object);
static TempBuf * gimp_channel_preview_private (GimpChannel *channel,
gint width,
gint height);
static GimpDrawableClass *parent_class = NULL;
static GimpDrawableClass * parent_class = NULL;
GtkType
......@@ -102,11 +99,44 @@ gimp_channel_class_init (GimpChannelClass *klass)
static void
gimp_channel_init (GimpChannel *channel)
{
gimp_rgba_set (&channel->color, 0.0, 0.0, 0.0, 1.0);
channel->show_masked = FALSE;
/* Selection mask variables */
channel->boundary_known = TRUE;
channel->segs_in = NULL;
channel->segs_out = NULL;
channel->num_segs_in = 0;
channel->num_segs_out = 0;
channel->empty = TRUE;
channel->bounds_known = TRUE;
channel->x1 = 0;
channel->y1 = 0;
channel->x2 = 0;
channel->y2 = 0;
}
/**************************/
/* Function definitions */
/**************************/
static void
gimp_channel_destroy (GtkObject *object)
{
GimpChannel *channel;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_CHANNEL (object));
channel = GIMP_CHANNEL (object);
/* free the segments? */
if (channel->segs_in)
g_free (channel->segs_in);
if (channel->segs_out)
g_free (channel->segs_out);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_channel_validate (TileManager *tm,
......@@ -139,17 +169,8 @@ gimp_channel_new (GimpImage *gimage,
channel->show_masked = TRUE;
/* selection mask variables */
channel->empty = TRUE;
channel->segs_in = NULL;
channel->segs_out = NULL;
channel->num_segs_in = 0;
channel->num_segs_out = 0;
channel->bounds_known = TRUE;
channel->boundary_known = TRUE;
channel->x1 = 0;
channel->y1 = 0;
channel->x2 = width;
channel->y2 = height;
channel->x2 = width;
channel->y2 = height;
return channel;
}
......@@ -227,7 +248,7 @@ gimp_channel_get_color (const GimpChannel *channel)
return &channel->color;
}
gint
gimp_channel_get_opacity (const GimpChannel *channel)
{
......@@ -249,26 +270,6 @@ gimp_channel_set_opacity (GimpChannel *channel,
channel->color.a = opacity / 100.0;
}
static void
gimp_channel_destroy (GtkObject *object)
{
GimpChannel *channel;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_CHANNEL (object));
channel = GIMP_CHANNEL (object);
/* free the segments? */
if (channel->segs_in)
g_free (channel->segs_in);
if (channel->segs_out)
g_free (channel->segs_out);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
void
gimp_channel_scale (GimpChannel *channel,
gint new_width,
......@@ -436,92 +437,6 @@ gimp_channel_toggle_visibility (GimpChannel *channel)
return GIMP_DRAWABLE (channel)->visible;
}
TempBuf *
gimp_channel_preview (GimpChannel *channel,
gint width,
gint height)
{
/* Ok prime the cache with a large preview if the cache is invalid */
if (! GIMP_DRAWABLE (channel)->preview_valid &&
width <= PREVIEW_CACHE_PRIME_WIDTH &&
height <= PREVIEW_CACHE_PRIME_HEIGHT &&
GIMP_DRAWABLE (channel)->gimage &&
GIMP_DRAWABLE (channel)->gimage->width > PREVIEW_CACHE_PRIME_WIDTH &&
GIMP_DRAWABLE (channel)->gimage->height > PREVIEW_CACHE_PRIME_HEIGHT)
{
TempBuf * tb = gimp_channel_preview_private (channel,
PREVIEW_CACHE_PRIME_WIDTH,
PREVIEW_CACHE_PRIME_HEIGHT);
/* Save the 2nd call */
if (width == PREVIEW_CACHE_PRIME_WIDTH &&
height == PREVIEW_CACHE_PRIME_HEIGHT)
return tb;
}
/* Second call - should NOT visit the tile cache... */
return gimp_channel_preview_private (channel, width, height);
}
static TempBuf *
gimp_channel_preview_private (GimpChannel *channel,
gint width,
gint height)
{
MaskBuf *preview_buf;
PixelRegion srcPR;
PixelRegion destPR;
gint subsample;
TempBuf *ret_buf;
g_return_val_if_fail (channel != NULL, NULL);
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL);
/* The easy way */
if (GIMP_DRAWABLE (channel)->preview_valid &&
(ret_buf =
gimp_preview_cache_get (& (GIMP_DRAWABLE (channel)->preview_cache),
width, height)))
{
return ret_buf;
}
/* The hard way */
else
{
/* calculate 'acceptable' subsample */
subsample = 1;
if (width < 1) width = 1;
if (height < 1) height = 1;
while ((width * (subsample + 1) * 2 < GIMP_DRAWABLE (channel)->width) &&
(height * (subsample + 1) * 2 < GIMP_DRAWABLE (channel)->height))
subsample = subsample + 1;
pixel_region_init (&srcPR, GIMP_DRAWABLE (channel)->tiles,
0, 0,
GIMP_DRAWABLE (channel)->width,
GIMP_DRAWABLE (channel)->height, FALSE);
preview_buf = mask_buf_new (width, height);
destPR.bytes = 1;
destPR.x = 0;
destPR.y = 0;
destPR.w = width;
destPR.h = height;
destPR.rowstride = width;
destPR.data = mask_buf_data (preview_buf);
subsample_region (&srcPR, &destPR, subsample);
if (!GIMP_DRAWABLE (channel)->preview_valid)
gimp_preview_cache_invalidate (&(GIMP_DRAWABLE(channel)->preview_cache));
GIMP_DRAWABLE (channel)->preview_valid = TRUE;
gimp_preview_cache_add (&(GIMP_DRAWABLE (channel)->preview_cache),
preview_buf);
return preview_buf;
}
}
/******************************/
/* selection mask functions */
/******************************/
......
......@@ -110,12 +110,7 @@ void gimp_channel_resize (GimpChannel *channel,
gint offy);
void gimp_channel_update (GimpChannel *channel);
/* access functions */
gboolean gimp_channel_toggle_visibility (GimpChannel *channel);
TempBuf * gimp_channel_preview (GimpChannel *channel,
gint width,
gint height);
/* selection mask functions */
......
......@@ -23,6 +23,7 @@
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpmath/gimpmath.h"
#include "apptypes.h"
......@@ -50,16 +51,12 @@
#include "libgimp/gimpintl.h"
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_destroy (GtkObject *object);
static void gimp_channel_class_init (GimpChannelClass *klass);
static void gimp_channel_init (GimpChannel *channel);
static void gimp_channel_destroy (GtkObject *object);
static TempBuf * gimp_channel_preview_private (GimpChannel *channel,
gint width,
gint height);
static GimpDrawableClass *parent_class = NULL;
static GimpDrawableClass * parent_class = NULL;
GtkType
......@@ -102,11 +99,44 @@ gimp_channel_class_init (GimpChannelClass *klass)
static void
gimp_channel_init (GimpChannel *channel)
{
gimp_rgba_set (&channel->color, 0.0, 0.0, 0.0, 1.0);
channel->show_masked = FALSE;
/* Selection mask variables */
channel->boundary_known = TRUE;
channel->segs_in = NULL;
channel->segs_out = NULL;
channel->num_segs_in = 0;
channel->num_segs_out = 0;
channel->empty = TRUE;
channel->bounds_known = TRUE;
channel->x1 = 0;
channel->y1 = 0;
channel->x2 = 0;
channel->y2 = 0;
}
/**************************/
/* Function definitions */
/**************************/
static void
gimp_channel_destroy (GtkObject *object)
{
GimpChannel *channel;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_CHANNEL (object));
channel = GIMP_CHANNEL (object);
/* free the segments? */
if (channel->segs_in)
g_free (channel->segs_in);
if (channel->segs_out)
g_free (channel->segs_out);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
static void
gimp_channel_validate (TileManager *tm,
......@@ -139,17 +169,8 @@ gimp_channel_new (GimpImage *gimage,
channel->show_masked = TRUE;
/* selection mask variables */
channel->empty = TRUE;
channel->segs_in = NULL;
channel->segs_out = NULL;
channel->num_segs_in = 0;
channel->num_segs_out = 0;
channel->bounds_known = TRUE;
channel->boundary_known = TRUE;
channel->x1 = 0;
channel->y1 = 0;
channel->x2 = width;
channel->y2 = height;
channel->x2 = width;
channel->y2 = height;
return channel;
}
......@@ -227,7 +248,7 @@ gimp_channel_get_color (const GimpChannel *channel)
return &channel->color;
}
gint
gimp_channel_get_opacity (const GimpChannel *channel)
{
......@@ -249,26 +270,6 @@ gimp_channel_set_opacity (GimpChannel *channel,
channel->color.a = opacity / 100.0;
}
static void
gimp_channel_destroy (GtkObject *object)
{
GimpChannel *channel;
g_return_if_fail (object != NULL);
g_return_if_fail (GIMP_IS_CHANNEL (object));
channel = GIMP_CHANNEL (object);
/* free the segments? */
if (channel->segs_in)
g_free (channel->segs_in);
if (channel->segs_out)
g_free (channel->segs_out);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
void
gimp_channel_scale (GimpChannel *channel,
gint new_width,
......@@ -436,92 +437,6 @@ gimp_channel_toggle_visibility (GimpChannel *channel)
return GIMP_DRAWABLE (channel)->visible;
}
TempBuf *
gimp_channel_preview (GimpChannel *channel,
gint width,
gint height)
{
/* Ok prime the cache with a large preview if the cache is invalid */
if (! GIMP_DRAWABLE (channel)->preview_valid &&
width <= PREVIEW_CACHE_PRIME_WIDTH &&
height <= PREVIEW_CACHE_PRIME_HEIGHT &&
GIMP_DRAWABLE (channel)->gimage &&
GIMP_DRAWABLE (channel)->gimage->width > PREVIEW_CACHE_PRIME_WIDTH &&
GIMP_DRAWABLE (channel)->gimage->height > PREVIEW_CACHE_PRIME_HEIGHT)
{
TempBuf * tb = gimp_channel_preview_private (channel,
PREVIEW_CACHE_PRIME_WIDTH,
PREVIEW_CACHE_PRIME_HEIGHT);
/* Save the 2nd call */
if (width == PREVIEW_CACHE_PRIME_WIDTH &&
height == PREVIEW_CACHE_PRIME_HEIGHT)
return tb;
}
/* Second call - should NOT visit the tile cache... */
return gimp_channel_preview_private (channel, width, height);
}
static TempBuf *
gimp_channel_preview_private (GimpChannel *channel,
gint width,
gint height)
{
MaskBuf *preview_buf;
PixelRegion srcPR;
PixelRegion destPR;
gint subsample;
TempBuf *ret_buf;
g_return_val_if_fail (channel != NULL, NULL);
g_return_val_if_fail (GIMP_IS_CHANNEL (channel), NULL);
/* The easy way */
if (GIMP_DRAWABLE (channel)->preview_valid &&
(ret_buf =
gimp_preview_cache_get (& (GIMP_DRAWABLE (channel)->preview_cache),
width, height)))
{
return ret_buf;
}
/* The hard way */