Commit 978e0f76 authored by Maurits Rijk's avatar Maurits Rijk
Browse files

Moved a lot of generic preview code to the new files gimpmiscui.[ch] so it...

Moved a lot of generic preview code to the new files gimpmiscui.[ch] so it will be easier later to port these plug-ins to the new (not yet finished) effect preview widget.
parent 8513998e
......@@ -18,6 +18,22 @@
* libgimpwidgets/gimpdatafiles.c: s/S_ISLINK/S_ISNLK/ (was never
compiled before Hans fixed the #ifdef).
 
2002-11-30 Maurits Rijk <lpeek.mrijk@consunet.nl>
* plug-ins/common/flarefx.c:
* plug-ins/common/jigsaw.c:
* plug-ins/common/nova.c
* plug-ins/common/wind.c
* plug-ins/common/illusion.c
* plug-ins/common/glasstile.c
* plug-ins/common/max_rgb.c: replace preview code by calls to libgimp
* libgimp/Makefile.am: added gimpmiscui.[ch]
* libgimp/gimpmiscui.[ch]: new files. For now contain effect preview
stuff collected from several plug-ins. Warning: this is NOT the new
effect preview widget I'm writing, just a first step to cleaning up a
lot of plug-ins.
2002-11-30 Hans Breuer <hans@breuer.org>
 
* */makefile.msc */*/makefile.msc : updated
......
......@@ -134,6 +134,8 @@ libgimpui_1_3_la_SOURCES = \
gimpuitypes.h \
gimpmenu.c \
gimpmenu.h \
gimpmiscui.c \
gimpmiscui.h \
gimpbrushmenu.c \
gimpgradientmenu.c \
gimppatternmenu.c \
......@@ -157,6 +159,7 @@ gimpinclude_HEADERS = \
gimptile.h \
gimpexport.h \
gimpintl.h \
gimpmiscui.h \
gimpui.h \
gimpuitypes.h \
gimpmenu.h
......
......@@ -268,8 +268,8 @@ typedef enum
typedef enum
{
GIMP_PIXELS,
GIMP_POINTS
GIMP_SIZE_PIXELS,
GIMP_SIZE_POINTS
} GimpSizeType;
......
......@@ -27,9 +27,17 @@
#include <glib.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include "config.h"
#include "gimp.h"
#include "gimpmisc.h"
GimpPixelFetcher *
gimp_pixel_fetcher_new (GimpDrawable *drawable)
......
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpmiscui.c
* Contains all kinds of miscellaneous routines factored out from different
* plug-ins. They stay here until their API has crystalized a bit and we can
* put them into the file where they belong (Maurits Rijk
* <lpeek.mrijk@consunet.nl> if you want to blame someone for this mess)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <string.h>
#include <gtk/gtk.h>
#include "config.h"
#include "gimp.h"
#include "gimpmiscui.h"
#define PREVIEW_SIZE 128
GimpFixMePreview*
gimp_fixme_preview_new (GimpDrawable *drawable)
{
GimpFixMePreview *preview = g_new (GimpFixMePreview, 1);
preview->widget = gtk_preview_new (GTK_PREVIEW_COLOR);
if (drawable)
gimp_fixme_preview_fill_with_thumb (preview, drawable->drawable_id);
return preview;
}
void
gimp_fixme_preview_free (GimpFixMePreview *preview)
{
g_free (preview->even);
g_free (preview->odd);
g_free (preview->cache);
g_free (preview);
}
void
gimp_fixme_preview_do_row (GimpFixMePreview *preview,
gint row,
gint width,
guchar *src)
{
gint x;
guchar *p0 = preview->even;
guchar *p1 = preview->odd;
gdouble r, g, b, a;
gdouble c0, c1;
for (x = 0; x < width; x++)
{
switch (preview->bpp)
{
case 4:
r = ((gdouble) src[x*4]) / 255.0;
g = ((gdouble) src[x*4 + 1]) / 255.0;
b = ((gdouble) src[x*4 + 2]) / 255.0;
a = ((gdouble) src[x*4 + 3]) / 255.0;
break;
case 3:
r = ((gdouble) src[x*3]) / 255.0;
g = ((gdouble) src[x*3 + 1]) / 255.0;
b = ((gdouble) src[x*3 + 2]) / 255.0;
a = 1.0;
break;
case 2:
r = ((gdouble)src[x*2]) / 255.0;
g = b = r;
a = ((gdouble)src[x*2 + 1]) / 255.0;
break;
case 1:
r = ((gdouble)src[x*2]) / 255.0;
g = b = r;
a = 1.0;
break;
default:
r = g = b = a = 1.0; /* just to please the compiler */
g_assert_not_reached ();
break;
}
if ((x / GIMP_CHECK_SIZE_SM) & 1)
{
c0 = GIMP_CHECK_LIGHT;
c1 = GIMP_CHECK_DARK;
}
else
{
c0 = GIMP_CHECK_DARK;
c1 = GIMP_CHECK_LIGHT;
}
*p0++ = (c0 + (r - c0) * a) * 255.0;
*p0++ = (c0 + (g - c0) * a) * 255.0;
*p0++ = (c0 + (b - c0) * a) * 255.0;
*p1++ = (c1 + (r - c1) * a) * 255.0;
*p1++ = (c1 + (g - c1) * a) * 255.0;
*p1++ = (c1 + (b - c1) * a) * 255.0;
}
if ((row / GIMP_CHECK_SIZE_SM) & 1)
{
gtk_preview_draw_row (GTK_PREVIEW (preview->widget),
(guchar *) preview->odd, 0, row, width);
}
else
{
gtk_preview_draw_row (GTK_PREVIEW (preview->widget),
(guchar *) preview->even, 0, row, width);
}
}
void
gimp_fixme_preview_fill_with_thumb (GimpFixMePreview *preview,
gint32 drawable_ID)
{
gint bpp;
gint y;
gint width = PREVIEW_SIZE;
gint height = PREVIEW_SIZE;
guchar *src;
preview->cache =
gimp_drawable_get_thumbnail_data (drawable_ID, &width, &height, &bpp);
if (width < 1 || height < 1)
return;
preview->rowstride = width * bpp;
preview->bpp = bpp;
gtk_preview_size (GTK_PREVIEW (preview->widget), width, height);
preview->scale_x =
(gdouble) width / (gdouble) gimp_drawable_width (drawable_ID);
preview->scale_y =
(gdouble) height / (gdouble) gimp_drawable_height (drawable_ID);
src = preview->cache;
preview->even = g_malloc (width * 3);
preview->odd = g_malloc (width * 3);
for (y = 0; y < height; y++)
{
gimp_fixme_preview_do_row (preview, y, width, src);
src += width * bpp;
}
preview->buffer = GTK_PREVIEW (preview->widget)->buffer;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->height = GTK_PREVIEW (preview->widget)->buffer_height;
}
void
gimp_fixme_preview_fill (GimpFixMePreview *preview,
GimpDrawable *drawable)
{
GimpPixelRgn srcPR;
gint width;
gint height;
gint x1, x2, y1, y2;
gint bpp;
gint y;
guchar *src;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
if (x2 - x1 > PREVIEW_SIZE)
x2 = x1 + PREVIEW_SIZE;
if (y2 - y1 > PREVIEW_SIZE)
y2 = y1 + PREVIEW_SIZE;
width = x2 - x1;
height = y2 - y1;
bpp = gimp_drawable_bpp (drawable->drawable_id);
gtk_preview_size (GTK_PREVIEW (preview->widget), width, height);
gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, x2, y2, FALSE, FALSE);
preview->even = g_malloc (width * 3);
preview->odd = g_malloc (width * 3);
src = g_malloc (width * bpp);
preview->cache = g_malloc(width * bpp * height);
preview->rowstride = width * bpp;
preview->bpp = bpp;
for (y = 0; y < height; y++)
{
gimp_pixel_rgn_get_row (&srcPR, src, x1, y + y1, width);
memcpy(preview->cache + (y * width * bpp), src, width * bpp);
}
for (y = 0; y < height; y++)
{
gimp_fixme_preview_do_row(preview, y, width,
preview->cache + (y * width * bpp));
}
preview->buffer = GTK_PREVIEW (preview->widget)->buffer;
preview->width = GTK_PREVIEW (preview->widget)->buffer_width;
preview->height = GTK_PREVIEW (preview->widget)->buffer_height;
g_free (src);
}
/* LIBGIMP - The GIMP Library
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpmiscui.h
* Contains all kinds of miscellaneous routines factored out from different
* plug-ins. They stay here until their API has crystalized a bit and we can
* put them into the file where they belong (Maurits Rijk
* <lpeek.mrijk@consunet.nl> if you want to blame someone for this mess)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_MISCUI_H__
#define __GIMP_MISCUI_H__
#include <libgimp/gimptypes.h>
G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
/* Preview stuff. WARNING: don't use this in new code!!!!!!!
* It's just here to extract some general preview stuff from plug-ins so
* that it will be easier to change them when we have a real effect preview
* widget.
* Don't say I didn't warn you (Maurits).
*/
typedef struct {
GtkWidget *widget;
guchar *cache;
guchar *even;
guchar *odd;
guchar *buffer;
gint width;
gint height;
gint rowstride;
gint bpp;
gdouble scale_x;
gdouble scale_y;
} GimpFixMePreview;
GimpFixMePreview *gimp_fixme_preview_new (GimpDrawable *drawable);
void gimp_fixme_preview_free (GimpFixMePreview *preview);
void gimp_fixme_preview_fill_with_thumb (GimpFixMePreview *preview,
gint32 drawable_ID);
void gimp_fixme_preview_fill (GimpFixMePreview *preview,
GimpDrawable *drawable);
void gimp_fixme_preview_do_row (GimpFixMePreview *preview,
gint row,
gint width,
guchar *src);
G_END_DECLS
#endif /* __GIMP_MISCUI_H__ */
......@@ -27,9 +27,17 @@
#include <glib.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include "config.h"
#include "gimp.h"
#include "gimpmisc.h"
GimpPixelFetcher *
gimp_pixel_fetcher_new (GimpDrawable *drawable)
......
......@@ -27,9 +27,17 @@
#include <glib.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include "config.h"
#include "gimp.h"
#include "gimpmisc.h"
GimpPixelFetcher *
gimp_pixel_fetcher_new (GimpDrawable *drawable)
......
......@@ -28,6 +28,7 @@
#include <libgimp/gimpexport.h>
#include <libgimp/gimpmenu.h>
#include <libgimp/gimpmiscui.h>
G_BEGIN_DECLS
......
......@@ -49,11 +49,6 @@
#include <stdlib.h>
#include <string.h>
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
......@@ -64,7 +59,6 @@
/* --- Defines --- */
#define ENTRY_WIDTH 75
#define PREVIEW_SIZE 128
#define PREVIEW_MASK (GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON1_MOTION_MASK)
......@@ -73,15 +67,6 @@
#define CURSOR 0x2
#define ALL 0xf
#if 0
#define DEBUG1 printf
#else
#define DEBUG1 dummy_printf
static void
dummy_printf (gchar *fmt, ...) {}
#endif
/* --- Typedefs --- */
typedef struct
{
......@@ -134,10 +119,6 @@ static void run (gchar *name,
static void FlareFX (GimpDrawable *drawable,
gint preview_mode);
static void fill_preview_with_thumb (GtkWidget *preview_widget,
gint32 drawable_ID);
static GtkWidget *preview_widget (GimpDrawable *drawable);
static gint flare_dialog (GimpDrawable *drawable);
static void flare_ok_callback (GtkWidget *widget,
gpointer data);
......@@ -186,17 +167,14 @@ static FlareInterface fint =
FALSE /* run */
};
static gfloat scolor, sglow, sinner, souter; /* size */
static gfloat shalo;
static gint xs, ys;
static gint numref;
static RGBfloat color, glow, inner, outer, halo;
static Reflect ref1[19];
static guchar *preview_bits;
static GtkWidget *preview;
static gdouble preview_scale_x;
static gdouble preview_scale_y;
static gboolean show_cursor = FALSE;
static gfloat scolor, sglow, sinner, souter; /* size */
static gfloat shalo;
static gint xs, ys;
static gint numref;
static RGBfloat color, glow, inner, outer, halo;
static Reflect ref1[19];
static GimpFixMePreview *preview;
static gboolean show_cursor = FALSE;
/* --- Functions --- */
MAIN ()
......@@ -305,7 +283,6 @@ run (gchar *name,
/* Store data */
if (run_mode == GIMP_RUN_INTERACTIVE)
gimp_set_data ("plug_in_flarefx", &fvals, sizeof (FlareValues));
g_free(preview_bits);
}
else
{
......@@ -396,12 +373,12 @@ FlareFX (GimpDrawable *drawable,
if (preview_mode)
{
width = GTK_PREVIEW (preview)->buffer_width;
height = GTK_PREVIEW (preview)->buffer_height;
bytes = GTK_PREVIEW (preview)->bpp;
width = preview->width;
height = preview->height;
bytes = preview->bpp;
xs = (gdouble)fvals.posx * preview_scale_x;
ys = (gdouble)fvals.posy * preview_scale_y;
xs = (gdouble)fvals.posx * preview->scale_x;
ys = (gdouble)fvals.posy * preview->scale_y;
x1 = y1 = 0;
x2 = width;
......@@ -422,8 +399,8 @@ FlareFX (GimpDrawable *drawable,
if (preview_mode)
{
cur_row = g_new (guchar, GTK_PREVIEW (preview)->rowstride);
dest = g_new (guchar, GTK_PREVIEW (preview)->rowstride);
cur_row = g_new (guchar, preview->rowstride);
dest = g_new (guchar, preview->rowstride);
}
else
{
......@@ -454,8 +431,8 @@ FlareFX (GimpDrawable *drawable,
{
if (preview_mode)
memcpy (cur_row,
preview_bits + GTK_PREVIEW (preview)->rowstride * row,
GTK_PREVIEW (preview)->rowstride);
preview->cache + preview->rowstride * row,
preview->rowstride);
else
gimp_pixel_rgn_get_row (&srcPR, cur_row, x1, row, x2-x1);
......@@ -491,9 +468,8 @@ FlareFX (GimpDrawable *drawable,
}
if (preview_mode)
{
memcpy (GTK_PREVIEW (preview)->buffer + GTK_PREVIEW (preview)->rowstride * row,
cur_row,
GTK_PREVIEW (preview)->rowstride);
memcpy (preview->buffer + preview->rowstride * row, cur_row,
preview->rowstride);
}
else
{
......@@ -507,7 +483,7 @@ FlareFX (GimpDrawable *drawable,
if (preview_mode)
{
gtk_widget_queue_draw (preview);
gtk_widget_queue_draw (preview->widget);
}
else
{
......@@ -839,17 +815,17 @@ flare_center_create (GimpDrawable *drawable)
gtk_table_attach (GTK_TABLE (table), pframe, 0, 4, 1, 2, 0, 0, 0, 0);
/* PREVIEW */
preview = preview_widget (drawable);
gtk_widget_set_events (GTK_WIDGET (preview), PREVIEW_MASK);
gtk_container_add (GTK_CONTAINER (pframe), preview);
gtk_widget_show (preview);
preview = gimp_fixme_preview_new (drawable);
gtk_widget_set_events (GTK_WIDGET (preview->widget), PREVIEW_MASK);
gtk_container_add (GTK_CONTAINER (pframe), preview->widget);
gtk_widget_show (preview->widget);
g_object_set_data (G_OBJECT (preview), "center", center);
g_object_set_data (G_OBJECT (preview->widget), "center", center);
g_signal_connect_after (G_OBJECT (preview), "expose_event",
g_signal_connect_after (G_OBJECT (preview->widget), "expose_event",
G_CALLBACK (flare_center_preview_expose),
center);
g_signal_connect (G_OBJECT (preview), "event",
g_signal_connect (G_OBJECT (preview->widget), "event",
G_CALLBACK (flare_center_preview_events),
center);
......@@ -879,9 +855,6 @@ flare_center_create (GimpDrawable *drawable)
FlareFX (drawable, TRUE);
DEBUG1 ("fvals center=%d,%d\n", fvals.posx, fvals.posy);
DEBUG1 ("center cur=%d,%d\n", center->curx, center->cury);
return frame;
}
......@@ -893,125 +866,6 @@ flare_center_destroy (GtkWidget *widget,
g_free (center);
}
/*
* Initialize preview
* Draw the contents into the internal buffer of the preview widget
*/
static GtkWidget *
preview_widget (GimpDrawable *drawable)
{
GtkWidget *preview;
gint size;
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
fill_preview_with_thumb (preview, drawable->drawable_id);
size = GTK_PREVIEW (preview)->rowstride * GTK_PREVIEW (preview)->buffer_height;
preview_bits = g_malloc (size);
memcpy (preview_bits, GTK_PREVIEW (preview)->buffer, size);