gimp/app/core/gimpimage-new.c

285 lines
7.5 KiB
C
Raw Normal View History

/* 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"
#include <string.h> /* memcpy */
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "base/tile-manager.h"
#include "paint-funcs/paint-funcs.h"
#include "gimp.h"
app/Makefile.am removed. 2001-07-07 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/context_manager.[ch]: removed. * app/app_procs.c: call tool_mananger instead of context_manager functions, pass "the_gimp" to some more functions. * app/drawable.[ch]: pass a GimpContext to drawable_fill(). * app/errors.c: behave according to "stack_trace_mode" when using the debugging signal handler. * app/gimprc.[ch]: removed the core/ config variables. * app/selection.c: set the selection's state to INVISIBLE in selection_pause(). * app/core/Makefile.am * app/core/gimpcoreconfig.[ch]: new files (the configuration variables used by core/). * app/core/gimpcontext.[ch]: removed the global contexts (user, default, ...) and their functions. It's no longer possible to pass NULL to the context functions to manipulate the current context (gimpcontext.c doesn't know the current context any more). * app/core/gimp.[ch]: added them here. The functions are now called gimp_[set|get]_*_context(). Added gimp_create_context() which is the only function to create contexts now. * app/gui/dialogs.[ch] * app/gui/gui.[ch]: pass "gimp" to all functions. * app/tools/tool_manager.[ch] * app/tools/tools.[ch]: pass "gimp" to lots of functions. Added the "global_tool_context" logic and the global/non-global paint options switching from the context_manager. Pass "gimp" to all tools' "register" functions. * app/tools/*: changed accordingly. * app/devices.c * app/disp_callbacks.c * app/file-open.[ch] * app/file-save.c * app/gdisplay.c * app/gimage.c * app/libgimp_glue.c * app/module_db.c * app/nav_window.c * app/plug_in.c * app/qmask.c * app/undo.c * app/base/base-config.c * app/core/gimpbrushpipe.c * app/core/gimpdrawable-offset.c * app/core/gimpgradient.c * app/core/gimpimage-duplicate.c * app/core/gimpimage-mask.c * app/core/gimpimage-new.c * app/core/gimpimage.c * app/core/gimppalette.c * app/core/gimptoolinfo.[ch] * app/core/gimpundo.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-area.c * app/gui/dialogs-constructors.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.c * app/gui/gradient-editor.c * app/gui/gradient-select.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/menus.c * app/gui/palette-editor.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/paths-dialog.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.c * app/gui/test-commands.c * app/gui/tool-options-dialog.c * app/gui/toolbox.c * app/gui/tools-commands.c * app/xcf/xcf-load.c * app/xcf/xcf-save.c * app/widgets/gimpchannellistview.c * app/widgets/gimpdnd.c * app/widgets/gimpdrawablelistview.[ch] * app/widgets/gimpimagedock.c * app/widgets/gimplayerlistview.c * app/pdb/brushes_cmds.c * app/pdb/drawable_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/gradients_cmds.c * app/pdb/palette_cmds.c * app/pdb/patterns_cmds.c * app/pdb/procedural_db.c * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/palette.pdb * tools/pdbgen/pdb/patterns.pdb: changed accordingly: remove usage of gimp_context_[get|set]_*(NULL), create contexts with gimp_create_context(). Get the user/current context with gimp_get_[user|current]_context(). Added/removed access to the global "the_gimp" variable in some places. Get the core's config variables from "core_config".
2001-07-07 12:17:23 +00:00
#include "gimpcoreconfig.h"
#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);
new_type->type = RGB;
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);
new_type->type = GRAY;
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. */
app/Makefile.am app/gimpunit.c removed... 2001-07-11 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimpunit.c * app/unitrc.h: removed... * app/core/Makefile.am * app/core/gimpunit.[ch]: ...re-added here. * app/core/gimp.[ch]: added the image and drawable hash tables, next_image_ID, next_guide_ID and next_drawable_ID, added a GimpCoreConfig pointer which is now initalized dynamically. * app/core/gimpcoreconfig.[ch]: don't provide a global core_config variable any more (need to access gimp->config now). * app/gdisplay.[ch] * app/core/gimpdrawable.[ch] * app/core/gimpimage.[ch]: removed all global variables from gimpimage.c and gimpdrawable.c, pass a Gimp* to all *_get_by_ID() functions. * tools/pdbgen/app.pl: pass Gimp* to all _get_by_ID() functions. * app/app_procs.c * app/file-open.c * app/file-save.c * app/gimprc.c * app/libgimp_glue.c * app/module_db.c * app/plug_in.c * app/undo.c * app/user_install.c * app/core/core-types.h * app/core/gimpcontext.c * app/core/gimpimage-crop.c * app/core/gimpimage-new.c * app/core/gimpparasite.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.c * app/gui/info-window.c * app/gui/preferences-dialog.c * app/gui/resize-dialog.c * app/xcf/xcf-load.c * app/xcf/xcf-save.c * app/xcf/xcf.c * app/widgets/gimpdnd.c * app/pdb/channel_cmds.c * app/pdb/color_cmds.c * app/pdb/convert_cmds.c * app/pdb/display_cmds.c * app/pdb/drawable_cmds.c * app/pdb/edit_cmds.c * app/pdb/fileops_cmds.c * app/pdb/floating_sel_cmds.c * app/pdb/guides_cmds.c * app/pdb/image_cmds.c * app/pdb/layer_cmds.c * app/pdb/parasite_cmds.c * app/pdb/paths_cmds.c * app/pdb/selection_cmds.c * app/pdb/text_tool_cmds.c * app/pdb/tools_cmds.c * app/pdb/undo_cmds.c * app/pdb/unit_cmds.c * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/unit.pdb: changed accordingly.
2001-07-11 12:39:49 +00: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;
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);
if (values->type == INDEXED)
values->type = RGB; /* no indexed images */
}
else
{
memcpy (values, &gimp->image_new_last_values, sizeof (GimpImageNewValues));
}
if (gimp->global_buffer && gimp->have_current_cut_buffer)
{
values->width = tile_manager_width (gimp->global_buffer);
values->height = tile_manager_height (gimp->global_buffer);
}
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 *
((values->type == RGB ? 3 : 1) + /* bytes per pixel */
(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:
type = (values->type == RGB) ? RGB_GIMAGE : GRAY_GIMAGE;
break;
case TRANSPARENT_FILL:
type = (values->type == RGB) ? RGBA_GIMAGE : GRAYA_GIMAGE;
break;
default:
type = RGB_GIMAGE;
break;
}
gimage = gimp_create_image (gimp,
values->width, values->height,
values->type,
TRUE);
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"),
OPAQUE_OPACITY, NORMAL_MODE);
if (layer)
{
gimp_image_undo_disable (gimage);
gimp_image_add_layer (gimage, layer, 0);
gimp_image_undo_enable (gimage);
app/Makefile.am removed. 2001-07-08 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/drawable.[ch]: removed. * app/core/gimpdrawable.[ch]: added the functions here. Made an end to the myth that FG/BG and the undo system (!!!) are not really part of the core. * app/disp_callbacks.c * app/floating_sel.c * app/image_map.c * app/qmask.c * app/undo.c * app/core/gimpchannel.c * app/core/gimpdrawable-desaturate.c * app/core/gimpdrawable-equalize.c * app/core/gimpdrawable-invert.c * app/core/gimpdrawable-offset.c * app/core/gimpedit.c * app/core/gimpimage-duplicate.c * app/core/gimpimage-mask.c * app/core/gimpimage-new.c * app/core/gimpimage.[ch] * app/core/gimplayer.c * app/core/gimplayermask.c * app/gui/channels-commands.c * app/gui/gui.c * app/gui/layers-commands.c * app/tools/gimpairbrushtool.c * app/tools/gimpbezierselecttool.c * app/tools/gimpblendtool.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpclonetool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpconvolvetool.c * app/tools/gimpcurvestool.c * app/tools/gimphistogramtool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimpiscissorstool.c * app/tools/gimplevelstool.c * app/tools/gimppainttool.c * app/tools/gimpposterizetool.c * app/tools/gimpscaletool.c * app/tools/gimpthresholdtool.c * app/tools/gimptransformtool.c * app/tools/tool_manager.c * app/widgets/gimpchannellistitem.c * app/widgets/gimpchannellistview.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplayerlistview.c * app/pdb/channel_cmds.c * app/pdb/color_cmds.c * app/pdb/drawable_cmds.c * app/pdb/edit_cmds.c * app/pdb/floating_sel_cmds.c * app/pdb/image_cmds.c * app/pdb/layer_cmds.c * app/pdb/parasite_cmds.c * app/pdb/selection_cmds.c * app/pdb/text_tool_cmds.c * app/pdb/tools_cmds.c * tools/pdbgen/pdb.pl * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/drawable.pdb: changed accordingly. Misc small fixes and cleanups.
2001-07-07 22:49:01 +00:00
gimp_drawable_fill_by_type (GIMP_DRAWABLE (layer),
gimp_get_current_context (gimp),
values->fill_type);
gimp_image_clean_all (gimage);
gimp_create_display (gimp, gimage);
}
return gimage;
}