app/core/Makefile.am app/core/core-types.h added GimpSubProgress, an

2007-02-27  Sven Neumann  <sven@gimp.org>

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimpsubprogress.[ch]: added GimpSubProgress, an 
object
	that implements the GimpProgress interface and maps progress
	information to a sub-range of the parent progress.

	* app/core/gimpimage-scale.c (gimp_image_scale): use the new 
object.


svn path=/trunk/; revision=22009
This commit is contained in:
Sven Neumann 2007-02-27 09:39:31 +00:00 committed by Sven Neumann
parent 99e507de58
commit 5b5082a433
6 changed files with 344 additions and 29 deletions

View File

@ -1,3 +1,13 @@
2007-02-27 Sven Neumann <sven@gimp.org>
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimpsubprogress.[ch]: added GimpSubProgress, an object
that implements the GimpProgress interface and maps progress
information to a sub-range of the parent progress.
* app/core/gimpimage-scale.c (gimp_image_scale): use the new object.
2007-02-26 Sven Neumann <sven@gimp.org>
* app/core/gimp-transform-region.c (normalize_coords): removed a

View File

@ -277,6 +277,8 @@ libappcore_a_sources = \
gimpstrokedesc.h \
gimpstrokeoptions.c \
gimpstrokeoptions.h \
gimpsubprogress.c \
gimpsubprogress.h \
gimptemplate.c \
gimptemplate.h \
gimptoolinfo.c \

View File

@ -141,6 +141,7 @@ typedef struct _GimpInterpreterDB GimpInterpreterDB;
typedef struct _GimpParasiteList GimpParasiteList;
typedef struct _GimpPdbProgress GimpPdbProgress;
typedef struct _GimpProjection GimpProjection;
typedef struct _GimpSubProgress GimpSubProgress;
typedef struct _GimpStrokeDesc GimpStrokeDesc;
/* typedef struct _GimpTemplate GimpTemplate; in config-types.h */

View File

@ -36,6 +36,7 @@
#include "gimplist.h"
#include "gimpprogress.h"
#include "gimpsamplepoint.h"
#include "gimpsubprogress.h"
#include "gimp-intl.h"
@ -47,15 +48,16 @@ gimp_image_scale (GimpImage *image,
GimpInterpolationType interpolation_type,
GimpProgress *progress)
{
GimpItem *item;
GList *list;
GList *remove = NULL;
gint old_width;
gint old_height;
gdouble img_scale_w = 1.0;
gdouble img_scale_h = 1.0;
gdouble progress_max;
gdouble progress_current = 1.0;
GimpItem *item;
GimpProgress *sub_progress = NULL;
GList *list;
GList *remove = NULL;
gint old_width;
gint old_height;
gdouble img_scale_w = 1.0;
gdouble img_scale_h = 1.0;
gint progress_steps = 1;
gint progress_current = 0;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (new_width > 0 && new_height > 0);
@ -63,10 +65,15 @@ gimp_image_scale (GimpImage *image,
gimp_set_busy (image->gimp);
progress_max = (image->channels->num_children +
image->layers->num_children +
image->vectors->num_children +
1 /* selection */);
if (progress)
{
sub_progress = gimp_sub_progress_new (progress);
progress_steps = (image->channels->num_children +
image->layers->num_children +
image->vectors->num_children +
1 /* selection */);
}
g_object_freeze_notify (G_OBJECT (image));
@ -94,12 +101,13 @@ gimp_image_scale (GimpImage *image,
{
item = list->data;
if (sub_progress)
gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress),
progress_current++, progress_steps);
gimp_item_scale (item,
new_width, new_height, 0, 0,
interpolation_type, NULL);
if (progress)
gimp_progress_set_value (progress, progress_current++ / progress_max);
interpolation_type, sub_progress);
}
/* Scale all vectors */
@ -109,21 +117,22 @@ gimp_image_scale (GimpImage *image,
{
item = list->data;
if (sub_progress)
gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress),
progress_current++, progress_steps);
gimp_item_scale (item,
new_width, new_height, 0, 0,
interpolation_type, NULL);
if (progress)
gimp_progress_set_value (progress, progress_current++ / progress_max);
interpolation_type, sub_progress);
}
/* Don't forget the selection mask! */
if (sub_progress)
gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress),
progress_current++, progress_steps);
gimp_item_scale (GIMP_ITEM (gimp_image_get_mask (image)),
new_width, new_height, 0, 0,
interpolation_type, NULL);
if (progress)
gimp_progress_set_value (progress, progress_current++ / progress_max);
interpolation_type, sub_progress);
/* Scale all layers */
for (list = GIMP_LIST (image->layers)->list;
@ -132,9 +141,13 @@ gimp_image_scale (GimpImage *image,
{
item = list->data;
if (sub_progress)
gimp_sub_progress_set_steps (GIMP_SUB_PROGRESS (sub_progress),
progress_current++, progress_steps);
if (! gimp_item_scale_by_factors (item,
img_scale_w, img_scale_h,
interpolation_type, NULL))
interpolation_type, sub_progress))
{
/* Since 0 < img_scale_w, img_scale_h, failure due to one or more
* vanishing scaled layer dimensions. Implicit delete implemented
@ -143,9 +156,6 @@ gimp_image_scale (GimpImage *image,
*/
remove = g_list_prepend (remove, item);
}
if (progress)
gimp_progress_set_value (progress, progress_current++ / progress_max);
}
/* We defer removing layers lost to scaling until now so as not to mix
@ -197,6 +207,9 @@ gimp_image_scale (GimpImage *image,
gimp_image_undo_group_end (image);
if (sub_progress)
g_object_unref (sub_progress);
gimp_viewable_size_changed (GIMP_VIEWABLE (image));
g_object_thaw_notify (G_OBJECT (image));

229
app/core/gimpsubprogress.c Normal file
View File

@ -0,0 +1,229 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 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 <glib-object.h>
#include "core-types.h"
#include "core/gimpsubprogress.h"
#include "core/gimpprogress.h"
static void gimp_sub_progress_iface_init (GimpProgressInterface *iface);
static void gimp_sub_progress_finalize (GObject *object);
static GimpProgress * gimp_sub_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
static void gimp_sub_progress_end (GimpProgress *progress);
static gboolean gimp_sub_progress_is_active (GimpProgress *progress);
static void gimp_sub_progress_set_text (GimpProgress *progress,
const gchar *message);
static void gimp_sub_progress_set_value (GimpProgress *progress,
gdouble percentage);
static gdouble gimp_sub_progress_get_value (GimpProgress *progress);
static void gimp_sub_progress_pulse (GimpProgress *progress);
static guint32 gimp_sub_progress_get_window (GimpProgress *progress);
static gboolean gimp_sub_progress_message (GimpProgress *progress,
Gimp *gimp,
GimpMessageSeverity severity,
const gchar *domain,
const gchar *message);
G_DEFINE_TYPE_WITH_CODE (GimpSubProgress, gimp_sub_progress, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_PROGRESS,
gimp_sub_progress_iface_init))
#define parent_class gimp_sub_progress_parent_class
static void
gimp_sub_progress_class_init (GimpSubProgressClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_sub_progress_finalize;
}
static void
gimp_sub_progress_init (GimpSubProgress *sub)
{
sub->progress = NULL;
sub->start = 0.0;
sub->end = 1.0;
}
static void
gimp_sub_progress_finalize (GObject *object)
{
GimpSubProgress *sub = GIMP_SUB_PROGRESS (object);
if (sub->progress)
{
g_object_unref (sub->progress);
sub->progress = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_sub_progress_iface_init (GimpProgressInterface *iface)
{
iface->start = gimp_sub_progress_start;
iface->end = gimp_sub_progress_end;
iface->is_active = gimp_sub_progress_is_active;
iface->set_text = gimp_sub_progress_set_text;
iface->set_value = gimp_sub_progress_set_value;
iface->get_value = gimp_sub_progress_get_value;
iface->pulse = gimp_sub_progress_pulse;
iface->get_window = gimp_sub_progress_get_window;
iface->message = gimp_sub_progress_message;
}
static GimpProgress *
gimp_sub_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
{
/* does nothing */
return NULL;
}
static void
gimp_sub_progress_end (GimpProgress *progress)
{
/* does nothing */
}
static gboolean
gimp_sub_progress_is_active (GimpProgress *progress)
{
GimpSubProgress *sub = GIMP_SUB_PROGRESS (progress);
if (sub->progress)
return gimp_progress_is_active (sub->progress);
return FALSE;
}
static void
gimp_sub_progress_set_text (GimpProgress *progress,
const gchar *message)
{
/* does nothing */
}
static void
gimp_sub_progress_set_value (GimpProgress *progress,
gdouble percentage)
{
GimpSubProgress *sub = GIMP_SUB_PROGRESS (progress);
if (sub->progress)
gimp_progress_set_value (sub->progress,
sub->start + percentage * (sub->end - sub->start));
}
static gdouble
gimp_sub_progress_get_value (GimpProgress *progress)
{
GimpSubProgress *sub = GIMP_SUB_PROGRESS (progress);
if (sub->progress)
return gimp_progress_get_value (sub->progress);
return 0.0;
}
static void
gimp_sub_progress_pulse (GimpProgress *progress)
{
GimpSubProgress *sub = GIMP_SUB_PROGRESS (progress);
if (sub->progress)
gimp_progress_pulse (sub->progress);
}
static guint32
gimp_sub_progress_get_window (GimpProgress *progress)
{
GimpSubProgress *sub = GIMP_SUB_PROGRESS (progress);
if (sub->progress)
return gimp_progress_get_window (sub->progress);
return 0;
}
static gboolean
gimp_sub_progress_message (GimpProgress *progress,
Gimp *gimp,
GimpMessageSeverity severity,
const gchar *domain,
const gchar *message)
{
GimpSubProgress *sub = GIMP_SUB_PROGRESS (progress);
if (sub->progress)
return gimp_progress_message (sub->progress,
gimp, severity, domain, message);
return FALSE;
}
GimpProgress *
gimp_sub_progress_new (GimpProgress *progress)
{
GimpSubProgress *sub;
g_return_val_if_fail (GIMP_IS_PROGRESS (progress), NULL);
sub = g_object_new (GIMP_TYPE_SUB_PROGRESS, NULL);
sub->progress = g_object_ref (progress);
return GIMP_PROGRESS (sub);
}
void
gimp_sub_progress_set_range (GimpSubProgress *progress,
gdouble start,
gdouble end)
{
g_return_if_fail (GIMP_IS_SUB_PROGRESS (progress));
g_return_if_fail (start < end);
progress->start = start;
progress->end = end;
}
void
gimp_sub_progress_set_steps (GimpSubProgress *progress,
gint num,
gint steps)
{
g_return_if_fail (GIMP_IS_SUB_PROGRESS (progress));
g_return_if_fail (num < steps && steps > 0);
progress->start = (gdouble) num / steps;
progress->end = (gdouble) (num + 1) / steps;
}

View File

@ -0,0 +1,60 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 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.
*/
#ifndef __GIMP_SUB_PROGRESS_H__
#define __GIMP_SUB_PROGRESS_H__
#define GIMP_TYPE_SUB_PROGRESS (gimp_sub_progress_get_type ())
#define GIMP_SUB_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_SUB_PROGRESS, GimpSubProgress))
#define GIMP_SUB_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_SUB_PROGRESS, GimpSubProgressClass))
#define GIMP_IS_SUB_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_SUB_PROGRESS))
#define GIMP_IS_SUB_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_SUB_PROGRESS))
#define GIMP_SUB_PROGRESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_SUB_PROGRESS, GimpSubProgressClass))
typedef struct _GimpSubProgressClass GimpSubProgressClass;
struct _GimpSubProgress
{
GObject parent_instance;
GimpProgress *progress;
gdouble start;
gdouble end;
};
struct _GimpSubProgressClass
{
GObjectClass parent_class;
};
GType gimp_sub_progress_get_type (void) G_GNUC_CONST;
GimpProgress * gimp_sub_progress_new (GimpProgress *progress);
void gimp_sub_progress_set_range (GimpSubProgress *progress,
gdouble start,
gdouble end);
void gimp_sub_progress_set_steps (GimpSubProgress *progress,
gint num,
gint steps);
#endif /* __GIMP_SUB_PROGRESS_H__ */