plug-ins: port map-object to GEGL
(cherry picked from commit 75114b1c40
)
This commit is contained in:
@ -59,6 +59,7 @@ LDADD = \
|
||||
$(libgimpmath) \
|
||||
$(libgimpbase) \
|
||||
$(GTK_LIBS) \
|
||||
$(GEGL_LIBS) \
|
||||
$(RT_LIBS) \
|
||||
$(INTLLIBS) \
|
||||
$(map_object_RC)
|
||||
|
@ -133,13 +133,9 @@ init_compute (void)
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
box_drawables[i] = gimp_drawable_get (mapvals.boxmap_id[i]);
|
||||
box_drawable_ids[i] = mapvals.boxmap_id[i];
|
||||
|
||||
gimp_pixel_rgn_init (&box_regions[i], box_drawables[i],
|
||||
0, 0,
|
||||
box_drawables[i]->width,
|
||||
box_drawables[i]->height,
|
||||
FALSE, FALSE);
|
||||
box_buffers[i] = gimp_drawable_get_buffer (box_drawable_ids[i]);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -174,16 +170,10 @@ init_compute (void)
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
cylinder_drawables[i] =
|
||||
gimp_drawable_get (mapvals.cylindermap_id[i]);
|
||||
cylinder_drawable_ids[i] = mapvals.cylindermap_id[i];
|
||||
|
||||
gimp_pixel_rgn_init (&cylinder_regions[i], cylinder_drawables[i],
|
||||
0, 0,
|
||||
cylinder_drawables[i]->width,
|
||||
cylinder_drawables[i]->height,
|
||||
FALSE, FALSE);
|
||||
cylinder_buffers[i] = gimp_drawable_get_buffer (cylinder_drawable_ids[i]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -246,10 +236,13 @@ compute_image (void)
|
||||
if (mapvals.create_new_image ||
|
||||
mapvals.create_new_layer ||
|
||||
(mapvals.transparent_background &&
|
||||
output_drawable->bpp != 4))
|
||||
! gimp_drawable_has_alpha (output_drawable_id)))
|
||||
{
|
||||
gchar *layername[] = {_("Map to plane"), _("Map to sphere"), _("Map to box"),
|
||||
_("Map to cylinder"), _("Background")};
|
||||
gchar *layername[] = {_("Map to plane"),
|
||||
_("Map to sphere"),
|
||||
_("Map to box"),
|
||||
_("Map to cylinder"),
|
||||
_("Background")};
|
||||
|
||||
new_layer_id = gimp_layer_new (new_image_id,
|
||||
layername[mapvals.create_new_image ? 4 :
|
||||
@ -262,11 +255,10 @@ compute_image (void)
|
||||
gimp_image_get_default_new_layer_mode (new_image_id));
|
||||
|
||||
insert_layer = TRUE;
|
||||
output_drawable = gimp_drawable_get (new_layer_id);
|
||||
output_drawable_id = new_layer_id;
|
||||
}
|
||||
|
||||
gimp_pixel_rgn_init (&dest_region, output_drawable,
|
||||
0, 0, width, height, TRUE, TRUE);
|
||||
dest_buffer = gimp_drawable_get_shadow_buffer (output_drawable_id);
|
||||
|
||||
switch (mapvals.maptype)
|
||||
{
|
||||
@ -284,7 +276,7 @@ compute_image (void)
|
||||
break;
|
||||
}
|
||||
|
||||
if (mapvals.antialiasing == FALSE)
|
||||
if (! mapvals.antialiasing)
|
||||
{
|
||||
for (ycount = 0; ycount < height; ycount++)
|
||||
{
|
||||
@ -294,12 +286,13 @@ compute_image (void)
|
||||
color = (* get_ray_color) (&p);
|
||||
poke (xcount, ycount, &color, NULL);
|
||||
|
||||
if ((progress_counter++ % width) == 0)
|
||||
progress_counter++;
|
||||
}
|
||||
|
||||
gimp_progress_update ((gdouble) progress_counter /
|
||||
(gdouble) maxcounter);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_adaptive_supersample_area (0, 0,
|
||||
@ -313,22 +306,22 @@ compute_image (void)
|
||||
show_progress,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gimp_progress_update (1.0);
|
||||
|
||||
/* Update the region */
|
||||
/* ================= */
|
||||
g_object_unref (source_buffer);
|
||||
g_object_unref (dest_buffer);
|
||||
|
||||
gimp_drawable_flush (output_drawable);
|
||||
if (insert_layer)
|
||||
gimp_image_insert_layer (new_image_id, new_layer_id, -1, 0);
|
||||
gimp_drawable_merge_shadow (output_drawable->drawable_id, TRUE);
|
||||
gimp_drawable_update (output_drawable->drawable_id, 0, 0, width, height);
|
||||
|
||||
gimp_drawable_merge_shadow (output_drawable_id, TRUE);
|
||||
gimp_drawable_update (output_drawable_id, 0, 0, width, height);
|
||||
|
||||
if (new_image_id != image_id)
|
||||
{
|
||||
gimp_display_new (new_image_id);
|
||||
gimp_displays_flush ();
|
||||
gimp_drawable_detach (output_drawable);
|
||||
}
|
||||
|
||||
gimp_image_undo_group_end (new_image_id);
|
||||
|
@ -23,23 +23,24 @@
|
||||
#include "map-object-image.h"
|
||||
|
||||
|
||||
GimpDrawable *input_drawable, *output_drawable;
|
||||
GimpPixelRgn source_region,dest_region;
|
||||
gint32 input_drawable_id;
|
||||
gint32 output_drawable_id;
|
||||
GeglBuffer *source_buffer;
|
||||
GeglBuffer *dest_buffer;
|
||||
|
||||
GimpDrawable *box_drawables[6];
|
||||
GimpPixelRgn box_regions[6];
|
||||
gint32 box_drawable_ids[6];
|
||||
GeglBuffer *box_buffers[6];
|
||||
|
||||
GimpDrawable *cylinder_drawables[2];
|
||||
GimpPixelRgn cylinder_regions[2];
|
||||
gint32 cylinder_drawable_ids[2];
|
||||
GeglBuffer *cylinder_buffers[2];
|
||||
|
||||
guchar *preview_rgb_data = NULL;
|
||||
gint preview_rgb_stride;
|
||||
cairo_surface_t *preview_surface = NULL;
|
||||
|
||||
glong maxcounter, old_depth, max_depth;
|
||||
gint imgtype,width,height,in_channels,out_channels,image_id;
|
||||
gint width, height, image_id;
|
||||
GimpRGB background;
|
||||
gdouble oldthreshold;
|
||||
|
||||
gint border_x, border_y, border_w, border_h;
|
||||
|
||||
@ -51,27 +52,14 @@ GimpRGB
|
||||
peek (gint x,
|
||||
gint y)
|
||||
{
|
||||
static guchar data[4];
|
||||
|
||||
GimpRGB color;
|
||||
|
||||
gimp_pixel_rgn_get_pixel (&source_region, data, x, y);
|
||||
gegl_buffer_sample (source_buffer, x, y, NULL,
|
||||
&color, babl_format ("R'G'B'A double"),
|
||||
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
|
||||
|
||||
color.r = (gdouble) (data[0]) / 255.0;
|
||||
color.g = (gdouble) (data[1]) / 255.0;
|
||||
color.b = (gdouble) (data[2]) / 255.0;
|
||||
|
||||
if (input_drawable->bpp == 4)
|
||||
{
|
||||
if (in_channels == 4)
|
||||
color.a = (gdouble) (data[3]) / 255.0;
|
||||
else
|
||||
if (! babl_format_has_alpha (gegl_buffer_get_format (source_buffer)))
|
||||
color.a = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
color.a = 1.0;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
@ -81,27 +69,14 @@ peek_box_image (gint image,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
static guchar data[4];
|
||||
|
||||
GimpRGB color;
|
||||
|
||||
gimp_pixel_rgn_get_pixel (&box_regions[image], data, x, y);
|
||||
gegl_buffer_sample (box_buffers[image], x, y, NULL,
|
||||
&color, babl_format ("R'G'B'A double"),
|
||||
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
|
||||
|
||||
color.r = (gdouble) (data[0]) / 255.0;
|
||||
color.g = (gdouble) (data[1]) / 255.0;
|
||||
color.b = (gdouble) (data[2]) / 255.0;
|
||||
|
||||
if (box_drawables[image]->bpp == 4)
|
||||
{
|
||||
if (gimp_drawable_has_alpha (box_drawables[image]->drawable_id))
|
||||
color.a = (gdouble) (data[3]) / 255.0;
|
||||
else
|
||||
if (! babl_format_has_alpha (gegl_buffer_get_format (box_buffers[image])))
|
||||
color.a = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
color.a = 1.0;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
@ -111,27 +86,14 @@ peek_cylinder_image (gint image,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
static guchar data[4];
|
||||
|
||||
GimpRGB color;
|
||||
|
||||
gimp_pixel_rgn_get_pixel (&cylinder_regions[image],data, x, y);
|
||||
gegl_buffer_sample (cylinder_buffers[image], x, y, NULL,
|
||||
&color, babl_format ("R'G'B'A double"),
|
||||
GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
|
||||
|
||||
color.r = (gdouble) (data[0]) / 255.0;
|
||||
color.g = (gdouble) (data[1]) / 255.0;
|
||||
color.b = (gdouble) (data[2]) / 255.0;
|
||||
|
||||
if (cylinder_drawables[image]->bpp == 4)
|
||||
{
|
||||
if (gimp_drawable_has_alpha (cylinder_drawables[image]->drawable_id))
|
||||
color.a = (gdouble) (data[3]) / 255.0;
|
||||
else
|
||||
if (! babl_format_has_alpha (gegl_buffer_get_format (cylinder_buffers[image])))
|
||||
color.a = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
color.a = 1.0;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
@ -140,20 +102,21 @@ void
|
||||
poke (gint x,
|
||||
gint y,
|
||||
GimpRGB *color,
|
||||
gpointer data)
|
||||
gpointer user_data)
|
||||
{
|
||||
static guchar col[4];
|
||||
|
||||
gimp_rgba_get_uchar (color, &col[0], &col[1], &col[2], &col[3]);
|
||||
|
||||
gimp_pixel_rgn_set_pixel (&dest_region, col, x, y);
|
||||
gegl_buffer_set (dest_buffer, GEGL_RECTANGLE (x, y, 1, 1), 0,
|
||||
babl_format ("R'G'B'A double"), color,
|
||||
GEGL_AUTO_ROWSTRIDE);
|
||||
}
|
||||
|
||||
gint
|
||||
checkbounds (gint x,
|
||||
gint y)
|
||||
{
|
||||
if (x < border_x || y < border_y || x >= border_x + border_w || y >= border_y + border_h)
|
||||
if (x < border_x ||
|
||||
y < border_y ||
|
||||
x >= border_x + border_w ||
|
||||
y >= border_y + border_h)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
@ -166,8 +129,8 @@ checkbounds_box_image (gint image,
|
||||
{
|
||||
gint w, h;
|
||||
|
||||
w = box_drawables[image]->width;
|
||||
h = box_drawables[image]->height;
|
||||
w = gegl_buffer_get_width (box_buffers[image]);
|
||||
h = gegl_buffer_get_height (box_buffers[image]);
|
||||
|
||||
if (x < 0 || y < 0 || x >= w || y >= h)
|
||||
return FALSE ;
|
||||
@ -182,8 +145,8 @@ checkbounds_cylinder_image (gint image,
|
||||
{
|
||||
gint w, h;
|
||||
|
||||
w = cylinder_drawables[image]->width;
|
||||
h = cylinder_drawables[image]->height;
|
||||
w = gegl_buffer_get_width (cylinder_buffers[image]);
|
||||
h = gegl_buffer_get_height (cylinder_buffers[image]);
|
||||
|
||||
if (x < 0 || y < 0 || x >= w || y >= h)
|
||||
return FALSE;
|
||||
@ -286,8 +249,8 @@ get_box_image_color (gint image,
|
||||
gint x1, y1, x2, y2;
|
||||
GimpRGB p[4];
|
||||
|
||||
w = box_drawables[image]->width;
|
||||
h = box_drawables[image]->height;
|
||||
w = gegl_buffer_get_width (box_buffers[image]);
|
||||
h = gegl_buffer_get_height (box_buffers[image]);
|
||||
|
||||
x1 = (gint) ((u * (gdouble) w));
|
||||
y1 = (gint) ((v * (gdouble) h));
|
||||
@ -318,8 +281,8 @@ get_cylinder_image_color (gint image,
|
||||
gint x1, y1, x2, y2;
|
||||
GimpRGB p[4];
|
||||
|
||||
w = cylinder_drawables[image]->width;
|
||||
h = cylinder_drawables[image]->height;
|
||||
w = gegl_buffer_get_width (cylinder_buffers[image]);
|
||||
h = gegl_buffer_get_height (cylinder_buffers[image]);
|
||||
|
||||
x1 = (gint) ((u * (gdouble) w));
|
||||
y1 = (gint) ((v * (gdouble) h));
|
||||
@ -346,30 +309,20 @@ get_cylinder_image_color (gint image,
|
||||
/****************************************/
|
||||
|
||||
gint
|
||||
image_setup (GimpDrawable *drawable,
|
||||
image_setup (gint32 drawable_id,
|
||||
gint interactive)
|
||||
{
|
||||
/* Set the tile cache size */
|
||||
/* ======================= */
|
||||
input_drawable_id = drawable_id;
|
||||
output_drawable_id = drawable_id;
|
||||
|
||||
gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width() - 1) /
|
||||
gimp_tile_width ());
|
||||
|
||||
/* Get some useful info on the input drawable */
|
||||
/* ========================================== */
|
||||
|
||||
input_drawable = drawable;
|
||||
output_drawable = drawable;
|
||||
|
||||
if (! gimp_drawable_mask_intersect (drawable->drawable_id, &border_x, &border_y,
|
||||
if (! gimp_drawable_mask_intersect (drawable_id, &border_x, &border_y,
|
||||
&border_w, &border_h))
|
||||
return FALSE;
|
||||
|
||||
width = input_drawable->width;
|
||||
height = input_drawable->height;
|
||||
width = gimp_drawable_width (input_drawable_id);
|
||||
height = gimp_drawable_height (input_drawable_id);
|
||||
|
||||
gimp_pixel_rgn_init (&source_region, input_drawable,
|
||||
0, 0, width, height, FALSE, FALSE);
|
||||
source_buffer = gimp_drawable_get_buffer (input_drawable_id);
|
||||
|
||||
maxcounter = (glong) width * (glong) height;
|
||||
|
||||
@ -383,13 +336,6 @@ image_setup (GimpDrawable *drawable,
|
||||
gimp_rgb_set_alpha (&background, 1.0);
|
||||
}
|
||||
|
||||
/* Assume at least RGB */
|
||||
/* =================== */
|
||||
|
||||
in_channels = 3;
|
||||
if (gimp_drawable_has_alpha (input_drawable->drawable_id) == TRUE)
|
||||
in_channels++;
|
||||
|
||||
if (interactive == TRUE)
|
||||
{
|
||||
preview_rgb_stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24,
|
||||
|
@ -4,32 +4,31 @@
|
||||
/* Externally visible variables */
|
||||
/* ============================ */
|
||||
|
||||
extern GimpDrawable *input_drawable, *output_drawable;
|
||||
extern GimpPixelRgn source_region,dest_region;
|
||||
extern gint32 input_drawable_id;
|
||||
extern gint32 output_drawable_id;
|
||||
extern GeglBuffer *source_buffer;
|
||||
extern GeglBuffer *dest_buffer;
|
||||
|
||||
extern GimpDrawable *box_drawables[6];
|
||||
extern GimpPixelRgn box_regions[6];
|
||||
extern gint32 box_drawable_ids[6];
|
||||
extern GeglBuffer *box_buffers[6];
|
||||
|
||||
extern GimpDrawable *cylinder_drawables[2];
|
||||
extern GimpPixelRgn cylinder_regions[2];
|
||||
extern gint32 cylinder_drawable_ids[2];
|
||||
extern GeglBuffer *cylinder_buffers[2];
|
||||
|
||||
extern guchar *preview_rgb_data;
|
||||
extern gint preview_rgb_stride;
|
||||
extern cairo_surface_t *preview_surface;
|
||||
|
||||
extern glong maxcounter, old_depth, max_depth;
|
||||
extern gint imgtype, width,height, in_channels, out_channels, image_id;
|
||||
extern gint width, height, image_id;
|
||||
extern GimpRGB background;
|
||||
extern gdouble oldthreshold;
|
||||
|
||||
extern gint border_x1, border_y1, border_x2, border_y2;
|
||||
|
||||
extern GimpTile *current_in_tile, *current_out_tile;
|
||||
|
||||
/* Externally visible functions */
|
||||
/* ============================ */
|
||||
|
||||
extern gint image_setup (GimpDrawable *drawable,
|
||||
extern gint image_setup (gint32 drawable_id,
|
||||
gint interactive);
|
||||
extern glong in_xy_to_index (gint x,
|
||||
gint y);
|
||||
@ -42,7 +41,7 @@ extern GimpRGB peek (gint x,
|
||||
extern void poke (gint x,
|
||||
gint y,
|
||||
GimpRGB *color,
|
||||
gpointer data);
|
||||
gpointer user_data);
|
||||
extern GimpVector3 int_to_pos (gint x,
|
||||
gint y);
|
||||
extern void pos_to_int (gdouble x,
|
||||
|
@ -101,7 +101,7 @@ set_default_settings (void)
|
||||
}
|
||||
|
||||
static void
|
||||
check_drawables (GimpDrawable *drawable)
|
||||
check_drawables (gint32 drawable_id)
|
||||
{
|
||||
gint i;
|
||||
|
||||
@ -113,7 +113,7 @@ check_drawables (GimpDrawable *drawable)
|
||||
if (mapvals.boxmap_id[i] == -1 ||
|
||||
!gimp_item_is_valid (mapvals.boxmap_id[i]) ||
|
||||
gimp_drawable_is_gray (mapvals.boxmap_id[i]))
|
||||
mapvals.boxmap_id[i] = drawable->drawable_id;
|
||||
mapvals.boxmap_id[i] = drawable_id;
|
||||
}
|
||||
|
||||
/* Check that cylindermap images are valid */
|
||||
@ -124,7 +124,7 @@ check_drawables (GimpDrawable *drawable)
|
||||
if (mapvals.cylindermap_id[i] == -1 ||
|
||||
!gimp_item_is_valid (mapvals.cylindermap_id[i]) ||
|
||||
gimp_drawable_is_gray (mapvals.cylindermap_id[i]))
|
||||
mapvals.cylindermap_id[i] = drawable->drawable_id;
|
||||
mapvals.cylindermap_id[i] = drawable_id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,13 +207,11 @@ run (const gchar *name,
|
||||
GimpParam **return_vals)
|
||||
{
|
||||
static GimpParam values[1];
|
||||
GimpDrawable *drawable;
|
||||
GimpRunMode run_mode;
|
||||
gint32 drawable_id;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
gint i;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
INIT_I18N ();
|
||||
|
||||
values[0].type = GIMP_PDB_STATUS;
|
||||
@ -230,8 +228,9 @@ run (const gchar *name,
|
||||
/* Get the specified drawable */
|
||||
/* ========================== */
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
image_id = param[1].data.d_int32;
|
||||
drawable = gimp_drawable_get (param[2].data.d_drawable);
|
||||
drawable_id = param[2].data.d_int32;
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
@ -241,8 +240,8 @@ run (const gchar *name,
|
||||
/* ====================== */
|
||||
|
||||
gimp_get_data (PLUG_IN_PROC, &mapvals);
|
||||
check_drawables (drawable);
|
||||
if (main_dialog (drawable))
|
||||
check_drawables (drawable_id);
|
||||
if (main_dialog (drawable_id))
|
||||
{
|
||||
compute_image ();
|
||||
|
||||
@ -252,8 +251,8 @@ run (const gchar *name,
|
||||
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
gimp_get_data (PLUG_IN_PROC, &mapvals);
|
||||
check_drawables (drawable);
|
||||
if (image_setup (drawable, FALSE))
|
||||
check_drawables (drawable_id);
|
||||
if (image_setup (drawable_id, FALSE))
|
||||
compute_image ();
|
||||
break;
|
||||
|
||||
@ -310,8 +309,8 @@ run (const gchar *name,
|
||||
for (i = 0; i < 2; i++)
|
||||
mapvals.cylindermap_id[i] = param[47+i].data.d_drawable;
|
||||
|
||||
check_drawables (drawable);
|
||||
if (image_setup (drawable, FALSE))
|
||||
check_drawables (drawable_id);
|
||||
if (image_setup (drawable_id, FALSE))
|
||||
compute_image ();
|
||||
}
|
||||
break;
|
||||
@ -321,8 +320,6 @@ run (const gchar *name,
|
||||
|
||||
if (run_mode != GIMP_RUN_NONINTERACTIVE)
|
||||
gimp_displays_flush ();
|
||||
|
||||
gimp_drawable_detach (drawable);
|
||||
}
|
||||
|
||||
const GimpPlugInInfo PLUG_IN_INFO =
|
||||
|
@ -1313,7 +1313,7 @@ create_main_notebook (GtkWidget *container)
|
||||
/********************************/
|
||||
|
||||
gboolean
|
||||
main_dialog (GimpDrawable *drawable)
|
||||
main_dialog (gint32 drawable_id)
|
||||
{
|
||||
GtkWidget *main_hbox;
|
||||
GtkWidget *vbox;
|
||||
@ -1441,7 +1441,7 @@ main_dialog (GimpDrawable *drawable)
|
||||
gdk_cursor_unref (cursor);
|
||||
}
|
||||
|
||||
image_setup (drawable, TRUE);
|
||||
image_setup (drawable_id, TRUE);
|
||||
|
||||
compute_preview_image ();
|
||||
|
||||
|
@ -9,6 +9,6 @@ extern GtkWidget *previewarea;
|
||||
/* Externally visible functions */
|
||||
/* ============================ */
|
||||
|
||||
gboolean main_dialog (GimpDrawable *drawable);
|
||||
gboolean main_dialog (gint32 drawable_id);
|
||||
|
||||
#endif /* __MAPOBJECT_UI_H__ */
|
||||
|
Reference in New Issue
Block a user