mirror of https://github.com/GNOME/gimp.git
added a convenience function to create a layer from a GdkPixbuf.
2006-08-17 Sven Neumann <sven@gimp.org> * libgimp/gimppixbuf.[ch]: added a convenience function to create a layer from a GdkPixbuf. * plug-ins/common/poppler.c * plug-ins/common/screenshot.c * plug-ins/common/svg.c: use gimp_layer_new_from_pixbuf(). * libgimp/gimpui.def: updated.
This commit is contained in:
parent
476ec672c8
commit
247fc372d5
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2006-08-17 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* libgimp/gimppixbuf.[ch]: added a convenience function to create
|
||||
a layer from a GdkPixbuf.
|
||||
|
||||
* plug-ins/common/poppler.c
|
||||
* plug-ins/common/screenshot.c
|
||||
* plug-ins/common/svg.c: use gimp_layer_new_from_pixbuf().
|
||||
|
||||
* libgimp/gimpui.def: updated.
|
||||
|
||||
2006-08-17 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/common/poppler.c
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#include "gimp.h"
|
||||
|
@ -283,3 +285,117 @@ gimp_pixbuf_from_data (guchar *data,
|
|||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_layer_new_from_pixbuf:
|
||||
* @image_ID: The RGB image to which to add the layer.
|
||||
* @name: The layer name.
|
||||
* @pixbuf: A GdkPixbuf.
|
||||
* @opacity: The layer opacity.
|
||||
* @mode: The layer combination mode.
|
||||
* @progress_start: start of progress
|
||||
* @progress_end: end of progress
|
||||
*
|
||||
* Create a new layer from a %GdkPixbuf.
|
||||
*
|
||||
* This procedure creates a new layer from the given %GdkPixbuf. The
|
||||
* image has to be an RGB image and just like with gimp_layer_new()
|
||||
* you will still need to add the layer to it.
|
||||
*
|
||||
* If you pass @progress_end > @progress_start to this function,
|
||||
* @gimp_progress_update() will be called for. You have to call
|
||||
* @gimp_progress_init() beforehand.
|
||||
*
|
||||
* Returns: The newly created layer.
|
||||
*
|
||||
* Since: GIMP 2.4
|
||||
*/
|
||||
gint32
|
||||
gimp_layer_new_from_pixbuf (gint32 image_ID,
|
||||
const gchar *name,
|
||||
GdkPixbuf *pixbuf,
|
||||
gdouble opacity,
|
||||
GimpLayerModeEffects mode,
|
||||
gdouble progress_start,
|
||||
gdouble progress_end)
|
||||
{
|
||||
GimpDrawable *drawable;
|
||||
GimpPixelRgn rgn;
|
||||
const guchar *pixels;
|
||||
gpointer pr;
|
||||
gdouble range = progress_end - progress_start;
|
||||
gint32 layer;
|
||||
gint width;
|
||||
gint height;
|
||||
gint rowstride;
|
||||
gint bpp;
|
||||
gint count = 0;
|
||||
gint done = 0;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), -1);
|
||||
|
||||
if (gimp_image_base_type (image_ID) != GIMP_RGB)
|
||||
{
|
||||
g_warning ("gimp_layer_new_from_pixbuf() needs an RGB image");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (gdk_pixbuf_get_colorspace (pixbuf) != GDK_COLORSPACE_RGB)
|
||||
{
|
||||
g_warning ("gimp_layer_new_from_pixbuf() assumes that GdkPixbuf is RGB");
|
||||
return -1;
|
||||
}
|
||||
|
||||
width = gdk_pixbuf_get_width (pixbuf);
|
||||
height = gdk_pixbuf_get_height (pixbuf);
|
||||
bpp = gdk_pixbuf_get_n_channels (pixbuf);
|
||||
|
||||
layer = gimp_layer_new (image_ID, name, width, height,
|
||||
bpp == 3 ? GIMP_RGB_IMAGE : GIMP_RGBA_IMAGE,
|
||||
opacity, mode);
|
||||
|
||||
if (layer == -1)
|
||||
return -1;
|
||||
|
||||
drawable = gimp_drawable_get (layer);
|
||||
|
||||
gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
|
||||
|
||||
g_assert (bpp == rgn.bpp);
|
||||
|
||||
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
pixels = gdk_pixbuf_get_pixels (pixbuf);
|
||||
|
||||
for (pr = gimp_pixel_rgns_register (1, &rgn);
|
||||
pr != NULL;
|
||||
pr = gimp_pixel_rgns_process (pr))
|
||||
{
|
||||
const guchar *src = pixels + rgn.y * rowstride + rgn.x * bpp;
|
||||
guchar *dest = rgn.data;
|
||||
gint y;
|
||||
|
||||
for (y = 0; y < rgn.h; y++)
|
||||
{
|
||||
memcpy (dest, src, rgn.w * rgn.bpp);
|
||||
|
||||
src += rowstride;
|
||||
dest += rgn.rowstride;
|
||||
}
|
||||
|
||||
if (range > 0.0)
|
||||
{
|
||||
done += rgn.h * rgn.w;
|
||||
|
||||
if (count++ % 16 == 0)
|
||||
gimp_progress_update (progress_start +
|
||||
(gdouble) done / (width * height) * range);
|
||||
}
|
||||
}
|
||||
|
||||
if (range > 0.0)
|
||||
gimp_progress_update (progress_end);
|
||||
|
||||
gimp_drawable_detach (drawable);
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,14 @@ GdkPixbuf * gimp_drawable_get_sub_thumbnail (gint32 drawable_ID
|
|||
gint dest_height,
|
||||
GimpPixbufTransparency alpha);
|
||||
|
||||
gint32 gimp_layer_new_from_pixbuf (gint32 image_ID,
|
||||
const gchar *name,
|
||||
GdkPixbuf *pixbuf,
|
||||
gdouble opacity,
|
||||
GimpLayerModeEffects mode,
|
||||
gdouble progress_start,
|
||||
gdouble progress_end);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ EXPORTS
|
|||
gimp_layer_combo_box_get_type
|
||||
gimp_layer_combo_box_new
|
||||
gimp_layer_menu_new
|
||||
gimp_layer_new_from_pixbuf
|
||||
gimp_palette_select_button_get_palette
|
||||
gimp_palette_select_button_get_type
|
||||
gimp_palette_select_button_new
|
||||
|
|
|
@ -379,67 +379,17 @@ static gint32
|
|||
layer_from_pixbuf (gint32 image,
|
||||
const gchar *layer_name,
|
||||
gint position,
|
||||
GdkPixbuf *buf,
|
||||
GdkPixbuf *pixbuf,
|
||||
gdouble progress_start,
|
||||
gdouble progress_scale)
|
||||
{
|
||||
gint32 layer;
|
||||
GimpPixelRgn rgn;
|
||||
gpointer pr;
|
||||
GimpDrawable *drawable;
|
||||
const guchar *pixels;
|
||||
gint width;
|
||||
gint height;
|
||||
gint rowstride;
|
||||
gint bpp;
|
||||
gint count = 0;
|
||||
gint done = 0;
|
||||
|
||||
g_return_val_if_fail (buf != NULL, -1);
|
||||
|
||||
width = gdk_pixbuf_get_width (buf);
|
||||
height = gdk_pixbuf_get_height (buf);
|
||||
|
||||
rowstride = gdk_pixbuf_get_rowstride (buf);
|
||||
bpp = gdk_pixbuf_get_n_channels (buf);
|
||||
pixels = gdk_pixbuf_get_pixels (buf);
|
||||
|
||||
layer = gimp_layer_new (image, layer_name,
|
||||
width, height,
|
||||
GIMP_RGB_IMAGE, 100.0, GIMP_NORMAL_MODE);
|
||||
gint32 layer = gimp_layer_new_from_pixbuf (image, layer_name, pixbuf,
|
||||
100.0, GIMP_NORMAL_MODE,
|
||||
progress_start,
|
||||
progress_start + progress_scale);
|
||||
|
||||
gimp_image_add_layer (image, layer, position);
|
||||
|
||||
drawable = gimp_drawable_get (layer);
|
||||
|
||||
gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
|
||||
|
||||
for (pr = gimp_pixel_rgns_register (1, &rgn);
|
||||
pr != NULL;
|
||||
pr = gimp_pixel_rgns_process (pr))
|
||||
{
|
||||
const guchar *src = pixels + rgn.y * rowstride + rgn.x * bpp;
|
||||
guchar *dest = rgn.data;
|
||||
gint y;
|
||||
|
||||
for (y = 0; y < rgn.h; y++)
|
||||
{
|
||||
memcpy (dest, src, rgn.w * rgn.bpp);
|
||||
|
||||
src += rowstride;
|
||||
dest += rgn.rowstride;
|
||||
}
|
||||
|
||||
done += rgn.h * rgn.w;
|
||||
|
||||
if (count++ % 16 == 0)
|
||||
gimp_progress_update (progress_start +
|
||||
progress_scale * ((gdouble) done /
|
||||
(width * height)));
|
||||
}
|
||||
|
||||
gimp_drawable_detach (drawable);
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
|
|
|
@ -181,14 +181,14 @@ static void run (const gchar *name,
|
|||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
|
||||
static GdkNativeWindow select_window (GdkScreen *screen);
|
||||
static gint32 create_image (const GdkPixbuf *pixbuf);
|
||||
static GdkNativeWindow select_window (GdkScreen *screen);
|
||||
static gint32 create_image (GdkPixbuf *pixbuf);
|
||||
|
||||
static gint32 shoot (GdkScreen *screen);
|
||||
static gboolean shoot_dialog (GdkScreen **screen);
|
||||
static void shoot_delay (gint32 delay);
|
||||
static gboolean shoot_delay_callback (gpointer data);
|
||||
static gboolean shoot_quit_timeout (gpointer data);
|
||||
static gint32 shoot (GdkScreen *screen);
|
||||
static gboolean shoot_dialog (GdkScreen **screen);
|
||||
static void shoot_delay (gint32 delay);
|
||||
static gboolean shoot_delay_callback (gpointer data);
|
||||
static gboolean shoot_quit_timeout (gpointer data);
|
||||
|
||||
|
||||
/* Global Variables */
|
||||
|
@ -630,22 +630,14 @@ select_window (GdkScreen *screen)
|
|||
/* Create a GimpImage from a GdkPixbuf */
|
||||
|
||||
static gint32
|
||||
create_image (const GdkPixbuf *pixbuf)
|
||||
create_image (GdkPixbuf *pixbuf)
|
||||
{
|
||||
GimpPixelRgn rgn;
|
||||
GimpDrawable *drawable;
|
||||
gint32 image;
|
||||
gint32 layer;
|
||||
gdouble xres, yres;
|
||||
gchar *comment;
|
||||
gint width, height;
|
||||
gint rowstride;
|
||||
gint bpp;
|
||||
gboolean status;
|
||||
guchar *pixels;
|
||||
gpointer pr;
|
||||
gint count = 0;
|
||||
gint done = 0;
|
||||
|
||||
status = gimp_progress_init (_("Importing screenshot"));
|
||||
|
||||
|
@ -654,48 +646,11 @@ create_image (const GdkPixbuf *pixbuf)
|
|||
|
||||
image = gimp_image_new (width, height, GIMP_RGB);
|
||||
gimp_image_undo_disable (image);
|
||||
layer = gimp_layer_new (image, _("Screenshot"),
|
||||
width, height,
|
||||
GIMP_RGB_IMAGE, 100, GIMP_NORMAL_MODE);
|
||||
|
||||
layer = gimp_layer_new_from_pixbuf (image, _("Screenshot"), pixbuf,
|
||||
100, GIMP_NORMAL_MODE, 0.0, 1.0);
|
||||
gimp_image_add_layer (image, layer, 0);
|
||||
|
||||
drawable = gimp_drawable_get (layer);
|
||||
|
||||
gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
|
||||
|
||||
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
bpp = gdk_pixbuf_get_n_channels (pixbuf);
|
||||
pixels = gdk_pixbuf_get_pixels (pixbuf);
|
||||
|
||||
g_assert (bpp == rgn.bpp);
|
||||
|
||||
for (pr = gimp_pixel_rgns_register (1, &rgn);
|
||||
pr != NULL;
|
||||
pr = gimp_pixel_rgns_process (pr))
|
||||
{
|
||||
const guchar *src = pixels + rgn.y * rowstride + rgn.x * bpp;
|
||||
guchar *dest = rgn.data;
|
||||
gint y;
|
||||
|
||||
for (y = 0; y < rgn.h; y++)
|
||||
{
|
||||
memcpy (dest, src, rgn.w * rgn.bpp);
|
||||
|
||||
src += rowstride;
|
||||
dest += rgn.rowstride;
|
||||
}
|
||||
|
||||
done += rgn.h * rgn.w;
|
||||
|
||||
if (count++ % 16 == 0)
|
||||
gimp_progress_update ((gdouble) done / (width * height));
|
||||
}
|
||||
|
||||
gimp_drawable_detach (drawable);
|
||||
|
||||
gimp_progress_update (1.0);
|
||||
|
||||
gimp_get_monitor_resolution (&xres, &yres);
|
||||
gimp_image_set_resolution (image, xres, yres);
|
||||
|
||||
|
|
|
@ -295,17 +295,9 @@ load_image (const gchar *filename)
|
|||
{
|
||||
gint32 image;
|
||||
gint32 layer;
|
||||
GimpDrawable *drawable;
|
||||
GimpPixelRgn rgn;
|
||||
GdkPixbuf *pixbuf;
|
||||
guchar *pixels;
|
||||
gint width;
|
||||
gint height;
|
||||
gint rowstride;
|
||||
gint bpp;
|
||||
gint count = 0;
|
||||
gint done = 0;
|
||||
gpointer pr;
|
||||
GError *error = NULL;
|
||||
|
||||
pixbuf = load_rsvg_pixbuf (filename, &load_vals, &error);
|
||||
|
@ -324,52 +316,18 @@ load_image (const gchar *filename)
|
|||
height = gdk_pixbuf_get_height (pixbuf);
|
||||
|
||||
image = gimp_image_new (width, height, GIMP_RGB);
|
||||
gimp_image_undo_disable (image);
|
||||
|
||||
gimp_image_set_filename (image, filename);
|
||||
gimp_image_set_resolution (image,
|
||||
load_vals.resolution, load_vals.resolution);
|
||||
|
||||
layer = gimp_layer_new (image, _("Rendered SVG"), width, height,
|
||||
GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE);
|
||||
|
||||
drawable = gimp_drawable_get (layer);
|
||||
|
||||
gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
|
||||
|
||||
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
bpp = gdk_pixbuf_get_n_channels (pixbuf);
|
||||
pixels = gdk_pixbuf_get_pixels (pixbuf);
|
||||
|
||||
g_assert (bpp == rgn.bpp);
|
||||
|
||||
for (pr = gimp_pixel_rgns_register (1, &rgn);
|
||||
pr != NULL;
|
||||
pr = gimp_pixel_rgns_process (pr))
|
||||
{
|
||||
const guchar *src = pixels + rgn.y * rowstride + rgn.x * bpp;
|
||||
guchar *dest = rgn.data;
|
||||
gint y;
|
||||
|
||||
for (y = 0; y < rgn.h; y++)
|
||||
{
|
||||
memcpy (dest, src, rgn.w * rgn.bpp);
|
||||
|
||||
src += rowstride;
|
||||
dest += rgn.rowstride;
|
||||
}
|
||||
|
||||
done += rgn.h * rgn.w;
|
||||
|
||||
if (count++ % 16 == 0)
|
||||
gimp_progress_update ((gdouble) done / (width * height));
|
||||
}
|
||||
|
||||
gimp_drawable_detach (drawable);
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
gimp_progress_update (1.0);
|
||||
|
||||
layer = gimp_layer_new_from_pixbuf (image, _("Rendered SVG"), pixbuf,
|
||||
100, GIMP_NORMAL_MODE, 0.0, 1.0);
|
||||
gimp_image_add_layer (image, layer, 0);
|
||||
|
||||
gimp_image_undo_enable (image);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue