2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-05-23 07:05:35 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2006-01-12 08:50:44 +08:00
|
|
|
* gimphistogram module Copyright (C) 1999 Jay Cox <jaycox@gimp.org>
|
2001-05-23 07:05:35 +08:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-05-23 07:05:35 +08:00
|
|
|
|
2001-05-26 05:17:07 +08:00
|
|
|
#include "core-types.h"
|
2001-05-23 07:05:35 +08:00
|
|
|
|
|
|
|
#include "base/gimphistogram.h"
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
|
2001-05-26 05:17:07 +08:00
|
|
|
#include "gimpdrawable.h"
|
2006-10-30 18:13:06 +08:00
|
|
|
#include "gimpdrawable-histogram.h"
|
2001-05-26 05:17:07 +08:00
|
|
|
#include "gimpimage.h"
|
2001-05-23 07:05:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_drawable_calculate_histogram (GimpDrawable *drawable,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpHistogram *histogram)
|
2001-05-23 07:05:35 +08:00
|
|
|
{
|
|
|
|
PixelRegion region;
|
|
|
|
PixelRegion mask;
|
|
|
|
gint x1, y1, x2, y2;
|
2004-01-13 19:51:45 +08:00
|
|
|
gboolean have_mask;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)));
|
2001-05-23 07:05:35 +08:00
|
|
|
g_return_if_fail (histogram != NULL);
|
|
|
|
|
2004-01-13 19:51:45 +08:00
|
|
|
have_mask = gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
|
2004-10-20 06:52:04 +08:00
|
|
|
|
|
|
|
if ((x1 == x2) || (y1 == y2))
|
|
|
|
return;
|
|
|
|
|
2006-04-07 17:21:18 +08:00
|
|
|
pixel_region_init (®ion, gimp_drawable_get_tiles (drawable),
|
2004-01-13 19:51:45 +08:00
|
|
|
x1, y1, (x2 - x1), (y2 - y1), FALSE);
|
2001-05-23 07:05:35 +08:00
|
|
|
|
2004-01-13 19:51:45 +08:00
|
|
|
if (have_mask)
|
2001-05-23 07:05:35 +08:00
|
|
|
{
|
|
|
|
GimpChannel *sel_mask;
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image;
|
2004-10-20 06:52:04 +08:00
|
|
|
gint off_x, off_y;
|
2001-05-23 07:05:35 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (drawable));
|
|
|
|
sel_mask = gimp_image_get_mask (image);
|
2001-05-23 07:05:35 +08:00
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2006-04-07 17:21:18 +08:00
|
|
|
pixel_region_init (&mask,
|
|
|
|
gimp_drawable_get_tiles (GIMP_DRAWABLE (sel_mask)),
|
2006-04-12 20:49:29 +08:00
|
|
|
x1 + off_x, y1 + off_y, (x2 - x1), (y2 - y1), FALSE);
|
2001-05-23 07:05:35 +08:00
|
|
|
gimp_histogram_calculate (histogram, ®ion, &mask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_histogram_calculate (histogram, ®ion, NULL);
|
|
|
|
}
|
|
|
|
}
|