home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / app / equalize.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  2.5 KB  |  91 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include <gtk/gtk.h>
  22.  
  23. #include "drawable.h"
  24. #include "equalize.h"
  25. #include "gimage.h"
  26. #include "gimplut.h"
  27. #include "lut_funcs.h"
  28. #include "gimphistogram.h"
  29.  
  30. #include "config.h"
  31. #include "libgimp/gimpintl.h"
  32.  
  33. void
  34. image_equalize (GimpImage *gimage)
  35. {
  36.   GimpDrawable *drawable;
  37.  
  38.   drawable = gimage_active_drawable (gimage);
  39.  
  40.   if (gimp_drawable_is_indexed (drawable))
  41.     {
  42.       g_message (_("Equalize does not operate on indexed drawables."));
  43.       return;
  44.     }
  45.  
  46.   equalize (gimage, drawable, TRUE);
  47. }
  48.  
  49.  
  50. void
  51. equalize (GimpImage    *gimage,
  52.           GimpDrawable *drawable,
  53.       gboolean      mask_only)
  54. {
  55.   PixelRegion srcPR, destPR;
  56.   unsigned char *mask;
  57.   int has_alpha;
  58.   int alpha, bytes;
  59.   int x1, y1, x2, y2;
  60.   GimpHistogram *hist;
  61.   GimpLut *lut;
  62.  
  63.   mask = NULL;
  64.  
  65.   bytes = drawable_bytes (drawable);
  66.   has_alpha = drawable_has_alpha (drawable);
  67.   alpha = has_alpha ? (bytes - 1) : bytes;
  68.  
  69.   hist = gimp_histogram_new();
  70.   gimp_histogram_calculate_drawable(hist, drawable);
  71.  
  72.  
  73.   /* Build equalization LUT */
  74.   lut = eq_histogram_lut_new (hist, bytes);
  75.  
  76.   /*  Apply the histogram  */
  77.   drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2);
  78.  
  79.   pixel_region_init (&srcPR, drawable_data (drawable), x1, y1, (x2 - x1), (y2 - y1), FALSE);
  80.   pixel_region_init (&destPR, drawable_shadow (drawable), x1, y1, (x2 - x1), (y2 - y1), TRUE);
  81.  
  82.   pixel_regions_process_parallel((p_func)gimp_lut_process, lut, 
  83.                  2, &srcPR, &destPR);
  84.  
  85.   gimp_lut_free(lut);
  86.   gimp_histogram_free(hist);
  87.  
  88.   drawable_merge_shadow (drawable, TRUE);
  89.   drawable_update (drawable, x1, y1, (x2 - x1), (y2 - y1));
  90. }
  91.