2001-07-05 23:34:26 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2001-07-23 06:18:01 +08:00
|
|
|
#include <string.h> /* memcpy */
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2001-07-05 23:34:26 +08:00
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
2001-12-13 07:48:18 +08:00
|
|
|
#include "gimpbuffer.h"
|
2001-07-07 20:17:23 +08:00
|
|
|
#include "gimpcoreconfig.h"
|
2001-07-05 23:34:26 +08:00
|
|
|
#include "gimpdrawable.h"
|
|
|
|
#include "gimpimage.h"
|
|
|
|
#include "gimpimage-new.h"
|
|
|
|
#include "gimplayer.h"
|
|
|
|
|
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_image_new_init (Gimp *gimp)
|
|
|
|
{
|
|
|
|
GimpImageBaseTypeName *new_type;
|
|
|
|
GimpFillTypeName *new_fill_type;
|
|
|
|
|
|
|
|
/* Available Image Base Types */
|
|
|
|
|
|
|
|
new_type = g_new (GimpImageBaseTypeName, 1);
|
2001-12-11 23:58:07 +08:00
|
|
|
new_type->type = GIMP_RGB;
|
2001-07-05 23:34:26 +08:00
|
|
|
new_type->name = _("RGB");
|
|
|
|
|
|
|
|
gimp->image_base_type_names = g_list_append (gimp->image_base_type_names,
|
|
|
|
new_type);
|
|
|
|
|
|
|
|
new_type = g_new (GimpImageBaseTypeName, 1);
|
2001-12-11 23:58:07 +08:00
|
|
|
new_type->type = GIMP_GRAY;
|
2001-07-05 23:34:26 +08:00
|
|
|
new_type->name = _("Grayscale");
|
|
|
|
|
|
|
|
gimp->image_base_type_names = g_list_append (gimp->image_base_type_names,
|
|
|
|
new_type);
|
|
|
|
|
|
|
|
/* Available Fill Types */
|
|
|
|
|
|
|
|
new_fill_type = g_new (GimpFillTypeName, 1);
|
|
|
|
new_fill_type->type = FOREGROUND_FILL;
|
|
|
|
new_fill_type->name = _("Foreground");
|
|
|
|
|
|
|
|
gimp->fill_type_names = g_list_append (gimp->fill_type_names, new_fill_type);
|
|
|
|
|
|
|
|
new_fill_type = g_new (GimpFillTypeName, 1);
|
|
|
|
new_fill_type->type = BACKGROUND_FILL;
|
|
|
|
new_fill_type->name = _("Background");
|
|
|
|
|
|
|
|
gimp->fill_type_names = g_list_append (gimp->fill_type_names, new_fill_type);
|
|
|
|
|
|
|
|
new_fill_type = g_new (GimpFillTypeName, 1);
|
|
|
|
new_fill_type->type = WHITE_FILL;
|
|
|
|
new_fill_type->name = _("White");
|
|
|
|
|
|
|
|
gimp->fill_type_names = g_list_append (gimp->fill_type_names, new_fill_type);
|
|
|
|
|
|
|
|
new_fill_type = g_new (GimpFillTypeName, 1);
|
|
|
|
new_fill_type->type = TRANSPARENT_FILL;
|
|
|
|
new_fill_type->name = _("Transparent");
|
|
|
|
|
|
|
|
gimp->fill_type_names = g_list_append (gimp->fill_type_names, new_fill_type);
|
|
|
|
|
|
|
|
/* Set the last values used to default values. */
|
|
|
|
|
2001-07-11 20:39:49 +08:00
|
|
|
gimp->image_new_last_values.width = gimp->config->default_width;
|
|
|
|
gimp->image_new_last_values.height = gimp->config->default_height;
|
|
|
|
gimp->image_new_last_values.unit = gimp->config->default_units;
|
|
|
|
gimp->image_new_last_values.xresolution = gimp->config->default_xresolution;
|
|
|
|
gimp->image_new_last_values.yresolution = gimp->config->default_yresolution;
|
|
|
|
gimp->image_new_last_values.res_unit = gimp->config->default_resolution_units;
|
|
|
|
gimp->image_new_last_values.type = gimp->config->default_type;
|
2001-07-05 23:34:26 +08:00
|
|
|
gimp->image_new_last_values.fill_type = BACKGROUND_FILL;
|
|
|
|
|
|
|
|
gimp->have_current_cut_buffer = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_image_new_exit (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_list_foreach (gimp->image_base_type_names, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (gimp->image_base_type_names);
|
|
|
|
gimp->image_base_type_names = NULL;
|
|
|
|
|
|
|
|
g_list_foreach (gimp->fill_type_names, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (gimp->fill_type_names);
|
|
|
|
gimp->fill_type_names = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
|
|
|
gimp_image_new_get_base_type_names (Gimp *gimp)
|
|
|
|
{
|
|
|
|
return gimp->image_base_type_names;
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
|
|
|
gimp_image_new_get_fill_type_names (Gimp *gimp)
|
|
|
|
{
|
|
|
|
return gimp->fill_type_names;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpImageNewValues *
|
|
|
|
gimp_image_new_values_new (Gimp *gimp,
|
|
|
|
GimpImage *gimage)
|
|
|
|
{
|
|
|
|
GimpImageNewValues *values;
|
|
|
|
|
|
|
|
values = g_new0 (GimpImageNewValues, 1);
|
|
|
|
|
|
|
|
if (gimage)
|
|
|
|
{
|
|
|
|
values->width = gimp_image_get_width (gimage);
|
|
|
|
values->height = gimp_image_get_height (gimage);
|
|
|
|
values->unit = gimp_image_get_unit (gimage);
|
|
|
|
|
|
|
|
gimp_image_get_resolution (gimage,
|
|
|
|
&values->xresolution,
|
|
|
|
&values->yresolution);
|
|
|
|
|
|
|
|
values->type = gimp_image_base_type (gimage);
|
|
|
|
|
2001-12-11 23:58:07 +08:00
|
|
|
if (values->type == GIMP_INDEXED)
|
|
|
|
values->type = GIMP_RGB; /* no indexed images */
|
2001-07-05 23:34:26 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-12-11 23:58:07 +08:00
|
|
|
memcpy (values, &gimp->image_new_last_values,
|
|
|
|
sizeof (GimpImageNewValues));
|
2001-07-05 23:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gimp->global_buffer && gimp->have_current_cut_buffer)
|
|
|
|
{
|
2001-12-13 07:48:18 +08:00
|
|
|
values->width = gimp_buffer_get_width (gimp->global_buffer);
|
|
|
|
values->height = gimp_buffer_get_height (gimp->global_buffer);
|
2001-07-05 23:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_image_new_set_default_values (Gimp *gimp,
|
|
|
|
GimpImageNewValues *values)
|
|
|
|
{
|
|
|
|
g_return_if_fail (values != NULL);
|
|
|
|
|
|
|
|
memcpy (&gimp->image_new_last_values, values, sizeof (GimpImageNewValues));
|
|
|
|
|
|
|
|
gimp->have_current_cut_buffer = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_image_new_values_free (GimpImageNewValues *values)
|
|
|
|
{
|
|
|
|
g_return_if_fail (values != NULL);
|
|
|
|
|
|
|
|
g_free (values);
|
|
|
|
}
|
|
|
|
|
|
|
|
gdouble
|
|
|
|
gimp_image_new_calculate_size (GimpImageNewValues *values)
|
|
|
|
{
|
|
|
|
gdouble width, height;
|
|
|
|
gdouble size;
|
|
|
|
|
|
|
|
width = (gdouble) values->width;
|
|
|
|
height = (gdouble) values->height;
|
|
|
|
|
|
|
|
size =
|
|
|
|
width * height *
|
2001-12-11 23:58:07 +08:00
|
|
|
((values->type == GIMP_RGB ? 3 : 1) + /* bytes per pixel */
|
2001-07-05 23:34:26 +08:00
|
|
|
(values->fill_type == TRANSPARENT_FILL ? 1 : 0)); /* alpha channel */
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
gimp_image_new_get_size_string (gdouble size)
|
|
|
|
{
|
|
|
|
if (size < 4096)
|
|
|
|
return g_strdup_printf (_("%d Bytes"), (gint) size);
|
|
|
|
else if (size < 1024 * 10)
|
|
|
|
return g_strdup_printf (_("%.2f KB"), size / 1024);
|
|
|
|
else if (size < 1024 * 100)
|
|
|
|
return g_strdup_printf (_("%.1f KB"), size / 1024);
|
|
|
|
else if (size < 1024 * 1024)
|
|
|
|
return g_strdup_printf (_("%d KB"), (gint) size / 1024);
|
|
|
|
else if (size < 1024 * 1024 * 10)
|
|
|
|
return g_strdup_printf (_("%.2f MB"), size / 1024 / 1024);
|
|
|
|
else
|
|
|
|
return g_strdup_printf (_("%.1f MB"), size / 1024 / 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_image_new_set_have_current_cut_buffer (Gimp *gimp)
|
|
|
|
{
|
|
|
|
gimp->have_current_cut_buffer = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpImage *
|
|
|
|
gimp_image_new_create_image (Gimp *gimp,
|
|
|
|
GimpImageNewValues *values)
|
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GimpImageType type;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
g_return_val_if_fail (values != NULL, NULL);
|
|
|
|
|
|
|
|
gimp_image_new_set_default_values (gimp, values);
|
|
|
|
|
|
|
|
switch (values->fill_type)
|
|
|
|
{
|
|
|
|
case FOREGROUND_FILL:
|
|
|
|
case BACKGROUND_FILL:
|
|
|
|
case WHITE_FILL:
|
2001-12-12 02:11:56 +08:00
|
|
|
type = (values->type == GIMP_RGB) ? GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE;
|
2001-07-05 23:34:26 +08:00
|
|
|
break;
|
|
|
|
case TRANSPARENT_FILL:
|
2001-12-12 02:11:56 +08:00
|
|
|
type = (values->type == GIMP_RGB) ? GIMP_RGBA_IMAGE : GIMP_GRAYA_IMAGE;
|
2001-07-05 23:34:26 +08:00
|
|
|
break;
|
|
|
|
default:
|
2001-12-12 02:11:56 +08:00
|
|
|
type = GIMP_RGB_IMAGE;
|
2001-07-05 23:34:26 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-07-06 00:21:36 +08:00
|
|
|
gimage = gimp_create_image (gimp,
|
|
|
|
values->width, values->height,
|
|
|
|
values->type,
|
|
|
|
TRUE);
|
2001-07-05 23:34:26 +08:00
|
|
|
|
|
|
|
gimp_image_set_resolution (gimage, values->xresolution, values->yresolution);
|
|
|
|
gimp_image_set_unit (gimage, values->unit);
|
|
|
|
|
|
|
|
width = gimp_image_get_width (gimage);
|
|
|
|
height = gimp_image_get_height (gimage);
|
|
|
|
|
|
|
|
layer = gimp_layer_new (gimage, width, height,
|
|
|
|
type, _("Background"),
|
2001-12-09 07:12:59 +08:00
|
|
|
OPAQUE_OPACITY, GIMP_NORMAL_MODE);
|
2001-07-05 23:34:26 +08:00
|
|
|
|
|
|
|
if (layer)
|
|
|
|
{
|
|
|
|
gimp_image_undo_disable (gimage);
|
|
|
|
gimp_image_add_layer (gimage, layer, 0);
|
|
|
|
gimp_image_undo_enable (gimage);
|
|
|
|
|
2001-07-08 06:49:01 +08:00
|
|
|
gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer),
|
|
|
|
gimp_get_current_context (gimp),
|
|
|
|
values->fill_type);
|
2001-07-05 23:34:26 +08:00
|
|
|
|
|
|
|
gimp_image_clean_all (gimage);
|
|
|
|
|
2001-11-01 05:18:57 +08:00
|
|
|
gimp_create_display (gimp, gimage, 0x0101);
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (gimage));
|
2001-07-05 23:34:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return gimage;
|
|
|
|
}
|