Commit ab0ac847 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

removed the remaining layer scale API.

2003-05-08  Michael Natterer  <mitch@gimp.org>

	* app/core/gimplayer.[ch]: removed the remaining layer scale API.

	* app/core/gimpitem.[ch]: added the same functions here.

	* app/core/gimpimage-scale.c
	* app/gui/layers-commands.c
	* tools/pdbgen/pdb/layer.pdb: changed accordingly.

	* app/pdb/layer_cmds.c: regenerated.
parent 766930db
2003-05-08 Michael Natterer <mitch@gimp.org>
* app/core/gimplayer.[ch]: removed the remaining layer scale API.
* app/core/gimpitem.[ch]: added the same functions here.
* app/core/gimpimage-scale.c
* app/gui/layers-commands.c
* tools/pdbgen/pdb/layer.pdb: changed accordingly.
* app/pdb/layer_cmds.c: regenerated.
2003-05-08 Michael Natterer <mitch@gimp.org>
* app/core/gimpitem.[ch] (gimp_item_configure): added width,
......@@ -943,11 +943,11 @@ scale_layer_query_ok_callback (GtkWidget *widget,
floating_sel_relax (layer, TRUE);
}
gimp_layer_scale_by_origin (layer,
options->resize->width,
options->resize->height,
options->resize->interpolation,
TRUE);
gimp_item_scale_by_origin (GIMP_ITEM (layer),
options->resize->width,
options->resize->height,
options->resize->interpolation,
TRUE);
if (gimp_layer_is_floating_sel (layer))
{
......
......@@ -122,17 +122,17 @@ gimp_image_scale (GimpImage *gimage,
list;
list = g_list_next (list))
{
layer = (GimpLayer *) list->data;
item = (GimpItem *) list->data;
if (! gimp_layer_scale_by_factors (layer, img_scale_w, img_scale_h,
interpolation_type))
if (! gimp_item_scale_by_factors (item, img_scale_w, img_scale_h,
interpolation_type))
{
/* Since 0 < img_scale_w, img_scale_h, failure due to one or more
* vanishing scaled layer dimensions. Implicit delete implemented
* here. Upstream warning implemented in resize_check_layer_scaling()
* [resize.c line 1295], which offers the user the chance to bail out.
*/
remove = g_slist_append (remove, layer);
remove = g_slist_append (remove, item);
}
if (progress_func)
......@@ -216,11 +216,11 @@ gimp_image_check_scaling (const GimpImage *gimage,
list;
list = g_list_next (list))
{
GimpLayer *layer;
GimpItem *item;
layer = (GimpLayer *) list->data;
item = (GimpItem *) list->data;
if (! gimp_layer_check_scaling (layer, new_width, new_height))
if (! gimp_item_check_scaling (item, new_width, new_height))
return FALSE;
}
......
......@@ -368,6 +368,40 @@ gimp_item_offsets (const GimpItem *item,
if (off_y) *off_y = item->offset_y;
}
/**
* gimp_item_check_scaling:
* @item: Item to check
* @new_width: proposed width of item, in pixels
* @new_height: proposed height of item, in pixels
*
* Scales item dimensions, then snaps them to pixel centers
*
* Returns: #FALSE if any dimension reduces to zero as a result
* of this; otherwise, returns #TRUE.
**/
gboolean
gimp_item_check_scaling (const GimpItem *item,
gint new_width,
gint new_height)
{
GimpImage *gimage;
gdouble img_scale_w;
gdouble img_scale_h;
gint new_item_width;
gint new_item_height;
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
gimage = gimp_item_get_image (item);
img_scale_w = (gdouble) new_width / (gdouble) gimage->width;
img_scale_h = (gdouble) new_height / (gdouble) gimage->height;
new_item_width = ROUND (img_scale_w * (gdouble) item->width);
new_item_height = ROUND (img_scale_h * (gdouble) item->height);
return (new_item_width > 0 && new_item_height > 0);
}
void
gimp_item_scale (GimpItem *item,
gint new_width,
......@@ -389,6 +423,133 @@ gimp_item_scale (GimpItem *item,
interpolation_type);
}
/**
* gimp_item_scale_by_factors:
* @item: Item to be transformed by explicit width and height factors.
* @w_factor: scale factor to apply to width and horizontal offset
* @h_factor: scale factor to apply to height and vertical offset
*
* Scales item dimensions and offsets by uniform width and
* height factors.
*
* Use gimp_item_scale_by_factors() in circumstances when the
* same width and height scaling factors are to be uniformly
* applied to a set of items. In this context, the item's
* dimensions and offsets from the sides of the containing
* image all change by these predetermined factors. By fiat,
* the fixed point of the transform is the upper left hand
* corner of the image. Returns gboolean FALSE if a requested
* scale factor is zero or if a scaling zero's out a item
* dimension; returns #TRUE otherwise.
*
* Use gimp_item_scale() in circumstances where new item width
* and height dimensions are predetermined instead.
*
* Side effects: Undo set created for item. Old item imagery
* scaled & painted to new item tiles.
*
* Returns: #TRUE, if the scaled item has positive dimensions
* #FALSE if the scaled item has at least one zero dimension
**/
gboolean
gimp_item_scale_by_factors (GimpItem *item,
gdouble w_factor,
gdouble h_factor,
GimpInterpolationType interpolation_type)
{
gint new_width, new_height;
gint new_offset_x, new_offset_y;
g_return_val_if_fail (GIMP_IS_ITEM (item), FALSE);
if (w_factor == 0.0 || h_factor == 0.0)
{
g_message ("gimp_item_scale_by_factors: Error. Requested width or height scale equals zero.");
return FALSE;
}
new_offset_x = ROUND (w_factor * (gdouble) item->offset_x);
new_offset_y = ROUND (h_factor * (gdouble) item->offset_y);
new_width = ROUND (w_factor * (gdouble) item->width);
new_height = ROUND (h_factor * (gdouble) item->height);
if (new_width != 0 && new_height != 0)
{
gimp_item_scale (item,
new_width, new_height,
new_offset_x, new_offset_y,
interpolation_type);
return TRUE;
}
return FALSE;
}
/**
* gimp_item_scale_by_origin:
* @item: The item to be transformed by width & height scale factors
* @new_width: The width that item will acquire
* @new_height: The height that the item will acquire
* @local_origin: sets fixed point of the scaling transform. See below.
*
* Sets item dimensions to new_width and
* new_height. Derives vertical and horizontal scaling
* transforms from new width and height. If local_origin is
* TRUE, the fixed point of the scaling transform coincides
* with the item's center point. Otherwise, the fixed
* point is taken to be [-item->offset_x, -item->offset_y].
*
* Since this function derives scale factors from new and
* current item dimensions, these factors will vary from
* item to item because of aliasing artifacts; factor
* variations among items can be quite large where item
* dimensions approach pixel dimensions. Use
* gimp_item_scale_by_factors() where constant scales are to
* be uniformly applied to a number of items.
*
* Side effects: undo set created for item.
* Old item imagery scaled
* & painted to new item tiles
**/
void
gimp_item_scale_by_origin (GimpItem *item,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type,
gboolean local_origin)
{
gint new_offset_x, new_offset_y;
g_return_if_fail (GIMP_IS_ITEM (item));
if (new_width == 0 || new_height == 0)
{
g_message ("gimp_layer_scale: Error. Requested width or height equals zero.");
return;
}
if (local_origin)
{
new_offset_x = item->offset_x + ((item->width - new_width) / 2.0);
new_offset_y = item->offset_y + ((item->height - new_height) / 2.0);
}
else
{
new_offset_x = (gint) (((gdouble) new_width *
(gdouble) item->offset_x /
(gdouble) item->width));
new_offset_y = (gint) (((gdouble) new_height *
(gdouble) item->offset_y /
(gdouble) item->height));
}
gimp_item_scale (item,
new_width, new_height,
new_offset_x, new_offset_y,
interpolation_type);
}
void
gimp_item_resize (GimpItem *item,
gint new_width,
......
......@@ -80,63 +80,75 @@ struct _GimpItemClass
};
GType gimp_item_get_type (void) G_GNUC_CONST;
void gimp_item_removed (GimpItem *item);
void gimp_item_configure (GimpItem *item,
GimpImage *gimage,
gint offset_x,
gint offset_y,
gint width,
gint height,
const gchar *name);
GimpItem * gimp_item_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
void gimp_item_rename (GimpItem *item,
const gchar *new_name);
gint gimp_item_width (const GimpItem *item);
gint gimp_item_height (const GimpItem *item);
void gimp_item_offsets (const GimpItem *item,
gint *offset_x,
gint *offset_y);
void gimp_item_scale (GimpItem *item,
gint new_width,
gint new_height,
gint new_offset_x,
gint new_offset_y,
GimpInterpolationType interp_type);
void gimp_item_resize (GimpItem *item,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y);
void gimp_item_resize_to_image (GimpItem *item);
gint gimp_item_get_ID (GimpItem *item);
GimpItem * gimp_item_get_by_ID (Gimp *gimp,
gint id);
GimpTattoo gimp_item_get_tattoo (const GimpItem *item);
void gimp_item_set_tattoo (GimpItem *item,
GimpTattoo tattoo);
GimpImage * gimp_item_get_image (const GimpItem *item);
void gimp_item_set_image (GimpItem *item,
GimpImage *gimage);
void gimp_item_parasite_attach (GimpItem *item,
GimpParasite *parasite);
void gimp_item_parasite_detach (GimpItem *item,
const gchar *name);
GimpParasite * gimp_item_parasite_find (const GimpItem *item,
const gchar *name);
gchar ** gimp_item_parasite_list (const GimpItem *item,
gint *count);
GType gimp_item_get_type (void) G_GNUC_CONST;
void gimp_item_removed (GimpItem *item);
void gimp_item_configure (GimpItem *item,
GimpImage *gimage,
gint offset_x,
gint offset_y,
gint width,
gint height,
const gchar *name);
GimpItem * gimp_item_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha);
void gimp_item_rename (GimpItem *item,
const gchar *new_name);
gint gimp_item_width (const GimpItem *item);
gint gimp_item_height (const GimpItem *item);
void gimp_item_offsets (const GimpItem *item,
gint *offset_x,
gint *offset_y);
gboolean gimp_item_check_scaling (const GimpItem *layer,
gint new_width,
gint new_height);
void gimp_item_scale (GimpItem *item,
gint new_width,
gint new_height,
gint new_offset_x,
gint new_offset_y,
GimpInterpolationType interp_type);
gboolean gimp_item_scale_by_factors (GimpItem *item,
gdouble w_factor,
gdouble h_factor,
GimpInterpolationType interp_type);
void gimp_item_scale_by_origin (GimpItem *item,
gint new_width,
gint new_height,
GimpInterpolationType interp_type,
gboolean local_origin);
void gimp_item_resize (GimpItem *item,
gint new_width,
gint new_height,
gint offset_x,
gint offset_y);
void gimp_item_resize_to_image (GimpItem *item);
gint gimp_item_get_ID (GimpItem *item);
GimpItem * gimp_item_get_by_ID (Gimp *gimp,
gint id);
GimpTattoo gimp_item_get_tattoo (const GimpItem *item);
void gimp_item_set_tattoo (GimpItem *item,
GimpTattoo tattoo);
GimpImage * gimp_item_get_image (const GimpItem *item);
void gimp_item_set_image (GimpItem *item,
GimpImage *gimage);
void gimp_item_parasite_attach (GimpItem *item,
GimpParasite *parasite);
void gimp_item_parasite_detach (GimpItem *item,
const gchar *name);
GimpParasite * gimp_item_parasite_find (const GimpItem *item,
const gchar *name);
gchar ** gimp_item_parasite_list (const GimpItem *item,
gint *count);
#endif /* __GIMP_ITEM_H__ */
......@@ -1109,175 +1109,7 @@ gimp_layer_add_alpha (GimpLayer *layer)
gimage = gimp_item_get_image (GIMP_ITEM (layer));
if (gimp_container_num_children (gimage->layers) == 1)
{
gimp_image_alpha_changed (gimage);
}
}
/**
* gimp_layer_check_scaling:
* @layer: Layer to check
* @new_width: proposed width of layer's image, in pixels
* @new_height: proposed height of layer's image, in pixels
*
* Scales layer dimensions, then snaps them to pixel centers
*
* Returns: #FALSE if any dimension reduces to zero as a result
* of this; otherwise, returns #TRUE.
**/
gboolean
gimp_layer_check_scaling (const GimpLayer *layer,
gint new_width,
gint new_height)
{
GimpImage *gimage;
gdouble img_scale_w;
gdouble img_scale_h;
gint new_layer_width;
gint new_layer_height;
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
gimage = gimp_item_get_image (GIMP_ITEM (layer));
img_scale_w = (gdouble) new_width / (gdouble) gimage->width;
img_scale_h = (gdouble) new_height / (gdouble) gimage->height;
new_layer_width = ROUND (img_scale_w *
(gdouble) GIMP_ITEM (layer)->width);
new_layer_height = ROUND (img_scale_h *
(gdouble) GIMP_ITEM (layer)->height);
return (new_layer_width != 0 && new_layer_height != 0);
}
/**
* gimp_layer_scale_by_factors:
* @layer: Layer to be transformed by explicit width and height factors.
* @w_factor: scale factor to apply to width and horizontal offset
* @h_factor: scale factor to apply to height and vertical offset
*
* Scales layer dimensions and offsets by uniform width and
* height factors.
*
* Use gimp_layer_scale_by_factors() in circumstances when the
* same width and height scaling factors are to be uniformly
* applied to a set of layers. In this context, the layer's
* dimensions and offsets from the sides of the containing
* image all change by these predetermined factors. By fiat,
* the fixed point of the transform is the upper left hand
* corner of the image. Returns gboolean FALSE if a requested
* scale factor is zero or if a scaling zero's out a layer
* dimension; returns #TRUE otherwise.
*
* Use gimp_layer_scale() in circumstances where new layer width
* and height dimensions are predetermined instead.
*
* Side effects: Undo set created for layer. Old layer imagery
* scaled & painted to new layer tiles.
*
* Returns: #TRUE, if the scaled layer has positive dimensions
* #FALSE if the scaled layer has at least one zero dimension
**/
gboolean
gimp_layer_scale_by_factors (GimpLayer *layer,
gdouble w_factor,
gdouble h_factor,
GimpInterpolationType interpolation_type)
{
gint new_width, new_height;
gint new_offset_x, new_offset_y;
g_return_val_if_fail (GIMP_IS_LAYER (layer), FALSE);
if (w_factor == 0.0 || h_factor == 0.0)
{
g_message ("gimp_layer_scale_by_factors: Error. Requested width or height scale equals zero.");
return FALSE;
}
new_offset_x = ROUND (w_factor * (gdouble) GIMP_ITEM (layer)->offset_x);
new_offset_y = ROUND (h_factor * (gdouble) GIMP_ITEM (layer)->offset_y);
new_width = ROUND (w_factor * (gdouble) GIMP_ITEM (layer)->width);
new_height = ROUND (h_factor * (gdouble) GIMP_ITEM (layer)->height);
if (new_width != 0 && new_height != 0)
{
gimp_item_scale (GIMP_ITEM (layer),
new_width, new_height,
new_offset_x, new_offset_y,
interpolation_type);
return TRUE;
}
return FALSE;
}
/**
* gimp_layer_scale_by_origin:
* @layer: The layer to be transformed by width & height scale factors
* @new_width: The width that layer will acquire
* @new_height: The height that the layer will acquire
* @local_origin: sets fixed point of the scaling transform. See below.
*
* Sets layer dimensions to new_width and
* new_height. Derives vertical and horizontal scaling
* transforms from new width and height. If local_origin is
* TRUE, the fixed point of the scaling transform coincides
* with the layer's center point. Otherwise, the fixed
* point is taken to be [-GIMP_DRAWABLE(layer)->offset_x,
* -GIMP_DRAWABLE(layer)->offset_y].
*
* Since this function derives scale factors from new and
* current layer dimensions, these factors will vary from
* layer to layer because of aliasing artifacts; factor
* variations among layers can be quite large where layer
* dimensions approach pixel dimensions. Use
* gimp_layer_scale_by_factors() where constant scales are to
* be uniformly applied to a number of layers.
*
* Side effects: undo set created for layer.
* Old layer imagery scaled
* & painted to new layer tiles
**/
void
gimp_layer_scale_by_origin (GimpLayer *layer,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type,
gboolean local_origin)
{
gint new_offset_x, new_offset_y;
g_return_if_fail (GIMP_IS_LAYER (layer));
if (new_width == 0 || new_height == 0)
{
g_message ("gimp_layer_scale: Error. Requested width or height equals zero.");
return;
}
if (local_origin)
{
new_offset_x = GIMP_ITEM (layer)->offset_x +
((GIMP_ITEM (layer)->width - new_width) / 2.0);
new_offset_y = GIMP_ITEM (layer)->offset_y +
((GIMP_ITEM (layer)->height - new_height) / 2.0);
}
else
{
new_offset_x = (gint) (((gdouble) new_width *
GIMP_ITEM (layer)->offset_x /
(gdouble) GIMP_ITEM (layer)->width));
new_offset_y = (gint) (((gdouble) new_height *
GIMP_ITEM (layer)->offset_y /
(gdouble) GIMP_ITEM (layer)->height));
}
gimp_item_scale (GIMP_ITEM (layer),
new_width, new_height,
new_offset_x, new_offset_y,
interpolation_type);
gimp_image_alpha_changed (gimage);
}
void
......
......@@ -91,9 +91,6 @@ GimpLayer * gimp_layer_new_from_tiles (TileManager *tiles,
GimpLayer * gimp_layer_new_from_drawable (GimpDrawable *drawable,
GimpImage *dest_image);
gboolean gimp_layer_check_scaling (const GimpLayer *layer,
gint new_width,
gint new_height);
GimpLayerMask * gimp_layer_create_mask (const GimpLayer *layer,
GimpAddMaskType mask_type);
GimpLayerMask * gimp_layer_add_mask (GimpLayer *layer,
......@@ -107,15 +104,6 @@ void gimp_layer_translate (GimpLayer *layer,
gint off_y,
gboolean push_undo);
void gimp_layer_add_alpha (GimpLayer *layer);
gboolean gimp_layer_scale_by_factors (GimpLayer *layer,
gdouble w_factor,
gdouble h_factor,
GimpInterpolationType interpolation_type);
void gimp_layer_scale_by_origin (GimpLayer *layer,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type,
gboolean local_origin);
void gimp_layer_resize_to_image (GimpLayer *layer);
BoundSeg * gimp_layer_boundary (GimpLayer *layer,
......
......@@ -943,11 +943,11 @@ scale_layer_query_ok_callback (GtkWidget *widget,
floating_sel_relax (layer, TRUE);
}
gimp_layer_scale_by_origin (layer,
options->resize->width,
options->resize->height,
options->resize->interpolation,
TRUE);
gimp_item_scale_by_origin (GIMP_ITEM (layer),
options->resize->width,
options->resize->height,
options->resize->interpolation,
TRUE);
if (gimp_layer_is_floating_sel (layer))
{
......
......@@ -407,7 +407,7 @@ layer_scale_invoker (Gimp *gimp,
if (floating_layer)
floating_sel_relax (floating_layer, TRUE);
gimp_layer_scale_by_origin (layer, new_width, new_height, gimp->config->interpolation_type, local_origin);
gimp_item_scale_by_origin (GIMP_ITEM (layer), new_width, new_height, gimp->config->interpolation_type, local_origin);
if (floating_layer)
floating_sel_rigor (floating_layer, TRUE);
......
......@@ -100,7 +100,7 @@ HELP
if ($op eq 'scale') {
&layer_change_invoke("LAYER_\U$op\E", 'Scale Layer',
"gimp_layer_scale_by_origin (layer, new_width, new_height, gimp->config->interpolation_type, $args);");
"gimp_item_scale_by_origin (GIMP_ITEM (layer), new_width, new_height, gimp->config->interpolation_type, $args);");
} else {
&layer_change_invoke("LAYER_\U$op\E", 'Resize Layer',