app: rename gimp_template_create_image() to gimp_image_new_from_template()

and move it from gimptemplate.c to gimpimage-new.c
This commit is contained in:
Michael Natterer 2010-06-05 22:42:00 +02:00
parent 9dd373d86e
commit 72bcb72c44
6 changed files with 81 additions and 87 deletions

View File

@ -91,7 +91,7 @@ templates_create_image_cmd_callback (GtkAction *action,
if (template && gimp_container_have (container, GIMP_OBJECT (template)))
{
gimp_template_create_image (gimp, template, context);
gimp_image_new_from_template (gimp, template, context);
gimp_image_new_set_last_template (gimp, template);
}
}

View File

@ -31,6 +31,7 @@
#include "gimp.h"
#include "gimpbuffer.h"
#include "gimpchannel.h"
#include "gimpcontext.h"
#include "gimpimage.h"
#include "gimpimage-colormap.h"
#include "gimpimage-new.h"
@ -78,6 +79,77 @@ gimp_image_new_set_last_template (Gimp *gimp,
G_OBJECT (gimp->image_new_last_template), 0);
}
GimpImage *
gimp_image_new_from_template (Gimp *gimp,
GimpTemplate *template,
GimpContext *context)
{
GimpImage *image;
GimpLayer *layer;
GimpImageType type;
gint width, height;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_TEMPLATE (template), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
image = gimp_create_image (gimp,
template->width, template->height,
template->image_type,
FALSE);
gimp_image_undo_disable (image);
if (template->comment)
{
GimpParasite *parasite;
parasite = gimp_parasite_new ("gimp-comment",
GIMP_PARASITE_PERSISTENT,
strlen (template->comment) + 1,
template->comment);
gimp_image_parasite_attach (image, parasite);
gimp_parasite_free (parasite);
}
gimp_image_set_resolution (image,
template->xresolution, template->yresolution);
gimp_image_set_unit (image, template->resolution_unit);
width = gimp_image_get_width (image);
height = gimp_image_get_height (image);
switch (template->fill_type)
{
case GIMP_TRANSPARENT_FILL:
type = ((template->image_type == GIMP_RGB) ?
GIMP_RGBA_IMAGE : GIMP_GRAYA_IMAGE);
break;
default:
type = ((template->image_type == GIMP_RGB) ?
GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE);
break;
}
layer = gimp_layer_new (image, width, height, type,
_("Background"),
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer),
context, template->fill_type);
gimp_image_add_layer (image, layer, NULL, 0, FALSE);
gimp_image_undo_enable (image);
gimp_image_clean_all (image);
gimp_create_display (gimp, image, template->unit, 1.0);
g_object_unref (image);
return image;
}
GimpImage *
gimp_image_new_from_drawable (Gimp *gimp,
GimpDrawable *drawable)

View File

@ -24,6 +24,9 @@ GimpTemplate * gimp_image_new_get_last_template (Gimp *gimp,
void gimp_image_new_set_last_template (Gimp *gimp,
GimpTemplate *template);
GimpImage * gimp_image_new_from_template (Gimp *gimp,
GimpTemplate *template,
GimpContext *context);
GimpImage * gimp_image_new_from_drawable (Gimp *gimp,
GimpDrawable *drawable);
GimpImage * gimp_image_new_from_component (Gimp *gimp,

View File

@ -20,8 +20,6 @@
#include "config.h"
#include <string.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
@ -29,11 +27,7 @@
#include "core-types.h"
#include "gimp.h"
#include "gimpcontext.h"
#include "gimpimage.h"
#include "gimpimage-undo.h"
#include "gimplayer.h"
#include "gimpprojection.h"
#include "gimptemplate.h"
@ -348,74 +342,3 @@ gimp_template_set_from_image (GimpTemplate *template,
if (comment)
g_free (comment);
}
GimpImage *
gimp_template_create_image (Gimp *gimp,
GimpTemplate *template,
GimpContext *context)
{
GimpImage *image;
GimpLayer *layer;
GimpImageType type;
gint width, height;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_TEMPLATE (template), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
image = gimp_create_image (gimp,
template->width, template->height,
template->image_type,
FALSE);
gimp_image_undo_disable (image);
if (template->comment)
{
GimpParasite *parasite;
parasite = gimp_parasite_new ("gimp-comment",
GIMP_PARASITE_PERSISTENT,
strlen (template->comment) + 1,
template->comment);
gimp_image_parasite_attach (image, parasite);
gimp_parasite_free (parasite);
}
gimp_image_set_resolution (image,
template->xresolution, template->yresolution);
gimp_image_set_unit (image, template->resolution_unit);
width = gimp_image_get_width (image);
height = gimp_image_get_height (image);
switch (template->fill_type)
{
case GIMP_TRANSPARENT_FILL:
type = ((template->image_type == GIMP_RGB) ?
GIMP_RGBA_IMAGE : GIMP_GRAYA_IMAGE);
break;
default:
type = ((template->image_type == GIMP_RGB) ?
GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE);
break;
}
layer = gimp_layer_new (image, width, height, type,
_("Background"),
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer),
context, template->fill_type);
gimp_image_add_layer (image, layer, NULL, 0, FALSE);
gimp_image_undo_enable (image);
gimp_image_clean_all (image);
gimp_create_display (gimp, image, template->unit, 1.0);
g_object_unref (image);
return image;
}

View File

@ -85,9 +85,5 @@ GimpTemplate * gimp_template_new (const gchar *name);
void gimp_template_set_from_image (GimpTemplate *template,
GimpImage *image);
GimpImage * gimp_template_create_image (Gimp *gimp,
GimpTemplate *template,
GimpContext *context);
#endif /* __GIMP_TEMPLATE__ */

View File

@ -344,7 +344,7 @@ image_new_create_image (ImageNewDialog *dialog)
gtk_widget_destroy (dialog->dialog);
gimp_template_create_image (gimp, template, gimp_get_user_context (gimp));
gimp_image_new_from_template (gimp, template, gimp_get_user_context (gimp));
gimp_image_new_set_last_template (gimp, template);
g_object_unref (template);