1997-11-25 06:05:25 +08:00
/* The GIMP -- an 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
1998-04-13 13:44:11 +08:00
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
1997-11-25 06:05:25 +08:00
*/
# include <stdlib.h>
# include <string.h>
# include <math.h>
# include "appenv.h"
# include "drawable.h"
# include "equalize.h"
# include "interface.h"
1998-01-22 15:02:57 +08:00
# include "gimage.h"
1997-11-25 06:05:25 +08:00
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
# include "libgimp/gimpintl.h"
1998-01-22 15:02:57 +08:00
static void equalize ( GImage * , GimpDrawable * , int ) ;
1997-11-25 06:05:25 +08:00
static void eq_histogram ( double [ 3 ] [ 256 ] , unsigned char [ 3 ] [ 256 ] , int , double ) ;
static Argument * equalize_invoker ( Argument * ) ;
void
image_equalize ( gimage_ptr )
void * gimage_ptr ;
{
GImage * gimage ;
1998-01-22 15:02:57 +08:00
GimpDrawable * drawable ;
1997-11-25 06:05:25 +08:00
int mask_only = TRUE ;
gimage = ( GImage * ) gimage_ptr ;
1998-01-22 15:02:57 +08:00
drawable = gimage_active_drawable ( gimage ) ;
1997-11-25 06:05:25 +08:00
1998-01-22 15:02:57 +08:00
if ( drawable_indexed ( drawable ) )
1997-11-25 06:05:25 +08:00
{
1998-11-23 22:47:09 +08:00
g_message ( _ ( " Equalize does not operate on indexed drawables. " ) ) ;
1997-11-25 06:05:25 +08:00
return ;
}
1998-01-22 15:02:57 +08:00
equalize ( gimage , drawable , mask_only ) ;
1997-11-25 06:05:25 +08:00
}
static void
1998-01-22 15:02:57 +08:00
equalize ( gimage , drawable , mask_only )
1997-11-25 06:05:25 +08:00
GImage * gimage ;
1998-01-22 15:02:57 +08:00
GimpDrawable * drawable ;
1997-11-25 06:05:25 +08:00
int mask_only ;
{
Channel * sel_mask ;
PixelRegion srcPR , destPR , maskPR , * sel_maskPR ;
double hist [ 3 ] [ 256 ] ;
unsigned char lut [ 3 ] [ 256 ] ;
unsigned char * src , * s ;
unsigned char * dest , * d ;
unsigned char * mask , * m ;
int no_mask ;
int h , j , b ;
int has_alpha ;
int alpha , bytes ;
int off_x , off_y ;
int x1 , y1 , x2 , y2 ;
double count ;
void * pr ;
mask = NULL ;
sel_mask = gimage_get_mask ( gimage ) ;
1998-01-22 15:02:57 +08:00
drawable_offsets ( drawable , & off_x , & off_y ) ;
bytes = drawable_bytes ( drawable ) ;
has_alpha = drawable_has_alpha ( drawable ) ;
1997-11-25 06:05:25 +08:00
alpha = has_alpha ? ( bytes - 1 ) : bytes ;
count = 0.0 ;
/* Determine the histogram from the drawable data and the attendant mask */
1998-01-22 15:02:57 +08:00
no_mask = ( drawable_mask_bounds ( drawable , & x1 , & y1 , & x2 , & y2 ) = = FALSE ) ;
pixel_region_init ( & srcPR , drawable_data ( drawable ) , x1 , y1 , ( x2 - x1 ) , ( y2 - y1 ) , FALSE ) ;
1997-11-25 06:05:25 +08:00
sel_maskPR = ( no_mask ) ? NULL : & maskPR ;
if ( sel_maskPR )
1998-01-22 15:02:57 +08:00
pixel_region_init ( sel_maskPR , drawable_data ( GIMP_DRAWABLE ( sel_mask ) ) , x1 + off_x , y1 + off_y , ( x2 - x1 ) , ( y2 - y1 ) , FALSE ) ;
1997-11-25 06:05:25 +08:00
/* Initialize histogram */
for ( b = 0 ; b < alpha ; b + + )
for ( j = 0 ; j < 256 ; j + + )
hist [ b ] [ j ] = 0.0 ;
for ( pr = pixel_regions_register ( 2 , & srcPR , sel_maskPR ) ; pr ! = NULL ; pr = pixel_regions_process ( pr ) )
{
src = srcPR . data ;
if ( sel_maskPR )
mask = sel_maskPR - > data ;
h = srcPR . h ;
while ( h - - )
{
s = src ;
m = mask ;
for ( j = 0 ; j < srcPR . w ; j + + )
{
if ( sel_maskPR )
{
for ( b = 0 ; b < alpha ; b + + )
hist [ b ] [ s [ b ] ] + = ( double ) * m / 255.0 ;
count + = ( double ) * m / 255.0 ;
}
else
{
for ( b = 0 ; b < alpha ; b + + )
hist [ b ] [ s [ b ] ] + = 1.0 ;
count + = 1.0 ;
}
s + = bytes ;
if ( sel_maskPR )
m + + ;
}
src + = srcPR . rowstride ;
if ( sel_maskPR )
mask + = sel_maskPR - > rowstride ;
}
}
/* Build equalization LUT */
eq_histogram ( hist , lut , alpha , count ) ;
/* Apply the histogram */
1998-01-22 15:02:57 +08:00
pixel_region_init ( & srcPR , drawable_data ( drawable ) , x1 , y1 , ( x2 - x1 ) , ( y2 - y1 ) , FALSE ) ;
pixel_region_init ( & destPR , drawable_shadow ( drawable ) , x1 , y1 , ( x2 - x1 ) , ( y2 - y1 ) , TRUE ) ;
1997-11-25 06:05:25 +08:00
for ( pr = pixel_regions_register ( 2 , & srcPR , & destPR ) ; pr ! = NULL ; pr = pixel_regions_process ( pr ) )
{
src = srcPR . data ;
dest = destPR . data ;
h = srcPR . h ;
while ( h - - )
{
s = src ;
d = dest ;
for ( j = 0 ; j < srcPR . w ; j + + )
{
for ( b = 0 ; b < alpha ; b + + )
d [ b ] = lut [ b ] [ s [ b ] ] ;
if ( has_alpha )
d [ alpha ] = s [ alpha ] ;
s + = bytes ;
d + = bytes ;
}
src + = srcPR . rowstride ;
dest + = destPR . rowstride ;
}
}
1998-01-22 15:02:57 +08:00
drawable_merge_shadow ( drawable , TRUE ) ;
drawable_update ( drawable , x1 , y1 , ( x2 - x1 ) , ( y2 - y1 ) ) ;
1997-11-25 06:05:25 +08:00
}
/*****/
static void
eq_histogram ( hist , lut , bytes , count )
double hist [ 3 ] [ 256 ] ;
unsigned char lut [ 3 ] [ 256 ] ;
int bytes ;
double count ;
{
int i , k , j ;
int part [ 3 ] [ 257 ] ; /* Partition */
double pixels_per_value ;
double desired ;
/* Calculate partial sums */
for ( k = 0 ; k < bytes ; k + + )
for ( i = 1 ; i < 256 ; i + + )
hist [ k ] [ i ] + = hist [ k ] [ i - 1 ] ;
/* Find partition points */
pixels_per_value = count / 256.0 ;
for ( k = 0 ; k < bytes ; k + + )
{
/* First and last points in partition */
part [ k ] [ 0 ] = 0 ;
part [ k ] [ 256 ] = 256 ;
/* Find intermediate points */
j = 0 ;
for ( i = 1 ; i < 256 ; i + + )
{
desired = i * pixels_per_value ;
while ( hist [ k ] [ j + 1 ] < = desired )
j + + ;
/* Nearest sum */
if ( ( desired - hist [ k ] [ j ] ) < ( hist [ k ] [ j + 1 ] - desired ) )
part [ k ] [ i ] = j ;
else
part [ k ] [ i ] = j + 1 ;
}
}
/* Create equalization LUT */
for ( k = 0 ; k < bytes ; k + + )
for ( j = 0 ; j < 256 ; j + + )
{
i = 0 ;
while ( part [ k ] [ i + 1 ] < = j )
i + + ;
lut [ k ] [ j ] = i ;
}
}
/* The equalize procedure definition */
ProcArg equalize_args [ ] =
{
{ PDB_DRAWABLE ,
" drawable " ,
1998-12-16 08:37:09 +08:00
" the drawable "
1997-11-25 06:05:25 +08:00
} ,
{ PDB_INT32 ,
" mask_only " ,
1998-12-16 08:37:09 +08:00
" equalization option "
1997-11-25 06:05:25 +08:00
}
} ;
ProcRecord equalize_proc =
{
" gimp_equalize " ,
1998-12-16 08:37:09 +08:00
" Equalize the contents of the specified drawable " ,
" This procedure equalizes the contents of the specified drawable. Each intensity channel is equalizeed independently. The equalizeed intensity is given as inten' = (255 - inten). Indexed color drawables are not valid for this operation. The 'mask_only' option specifies whether to adjust only the area of the image within the selection bounds, or the entire image based on the histogram of the selected area. If there is no selection, the entire image is adjusted based on the histogram for the entire image. " ,
1997-11-25 06:05:25 +08:00
" Federico Mena Quintero & Spencer Kimball & Peter Mattis " ,
" Federico Mena Quintero & Spencer Kimball & Peter Mattis " ,
" 1996 " ,
PDB_INTERNAL ,
/* Input arguments */
API-mega-break-it-all patch part one: removed the unnecessary PDB_IMAGE
* airbrush.c, blend.c, brightness_contrast.c, bucket_fill.c
by_color_select.c, channel_ops.c, clone.c, color_balance.c
color_picker.c, convolve.c, curves.c, desaturate.c, edit_cmds.c
equalize.c, eraser.c, flip_tool.c, fuzzy_select.c,
gimage_mask_cmds.c histogram_tool.c, hue_saturation.c, invert.c,
levels.c, pencil.c paintbrush.c, perspective_tool.c, posterize.c,
rotate_tool.c scale_tool.c, shear_tool.c, text_tool.c, threshold.c:
API-mega-break-it-all patch part one: removed the unnecessary
PDB_IMAGE argument from many functions.
Affected functions:
gimp_airbrush gimp_blend gimp_brightness_contrast gimp_bucket_fill
gimp_by_color_select gimp_channel_ops_offset gimp_clone gimp_color_balance
gimp_color_picker gimp_convolve gimp_curves_explicit gimp_curves_spline
gimp_desaturate gimp_edit_clear gimp_edit_copy gimp_edit_cut gimp_edit_fill
gimp_edit_paste gimp_edit_stroke gimp_equalize gimp_eraser
gimp_eraser_extended gimp_flip gimp_fuzzy_select gimp_histogram
gimp_hue_saturation gimp_invert gimp_levels gimp_paintbrush
gimp_paintbrush_extended gimp_pencil gimp_perspective gimp_posterize
gimp_rotate gimp_scale gimp_selection_float gimp_selection_layer_alpha
gimp_selection_load gimp_shear gimp_threshold
1998-11-14 04:40:00 +08:00
2 ,
1997-11-25 06:05:25 +08:00
equalize_args ,
/* Output arguments */
0 ,
NULL ,
/* Exec method */
{ { equalize_invoker } } ,
} ;
static Argument *
equalize_invoker ( args )
Argument * args ;
{
int success = TRUE ;
int int_value ;
int mask_only ;
GImage * gimage ;
1998-01-22 15:02:57 +08:00
GimpDrawable * drawable ;
1997-11-25 06:05:25 +08:00
1998-01-22 15:02:57 +08:00
drawable = NULL ;
1997-11-25 06:05:25 +08:00
/* the drawable */
if ( success )
{
API-mega-break-it-all patch part one: removed the unnecessary PDB_IMAGE
* airbrush.c, blend.c, brightness_contrast.c, bucket_fill.c
by_color_select.c, channel_ops.c, clone.c, color_balance.c
color_picker.c, convolve.c, curves.c, desaturate.c, edit_cmds.c
equalize.c, eraser.c, flip_tool.c, fuzzy_select.c,
gimage_mask_cmds.c histogram_tool.c, hue_saturation.c, invert.c,
levels.c, pencil.c paintbrush.c, perspective_tool.c, posterize.c,
rotate_tool.c scale_tool.c, shear_tool.c, text_tool.c, threshold.c:
API-mega-break-it-all patch part one: removed the unnecessary
PDB_IMAGE argument from many functions.
Affected functions:
gimp_airbrush gimp_blend gimp_brightness_contrast gimp_bucket_fill
gimp_by_color_select gimp_channel_ops_offset gimp_clone gimp_color_balance
gimp_color_picker gimp_convolve gimp_curves_explicit gimp_curves_spline
gimp_desaturate gimp_edit_clear gimp_edit_copy gimp_edit_cut gimp_edit_fill
gimp_edit_paste gimp_edit_stroke gimp_equalize gimp_eraser
gimp_eraser_extended gimp_flip gimp_fuzzy_select gimp_histogram
gimp_hue_saturation gimp_invert gimp_levels gimp_paintbrush
gimp_paintbrush_extended gimp_pencil gimp_perspective gimp_posterize
gimp_rotate gimp_scale gimp_selection_float gimp_selection_layer_alpha
gimp_selection_load gimp_shear gimp_threshold
1998-11-14 04:40:00 +08:00
int_value = args [ 0 ] . value . pdb_int ;
1998-01-22 15:02:57 +08:00
drawable = drawable_get_ID ( int_value ) ;
API-mega-break-it-all patch part one: removed the unnecessary PDB_IMAGE
* airbrush.c, blend.c, brightness_contrast.c, bucket_fill.c
by_color_select.c, channel_ops.c, clone.c, color_balance.c
color_picker.c, convolve.c, curves.c, desaturate.c, edit_cmds.c
equalize.c, eraser.c, flip_tool.c, fuzzy_select.c,
gimage_mask_cmds.c histogram_tool.c, hue_saturation.c, invert.c,
levels.c, pencil.c paintbrush.c, perspective_tool.c, posterize.c,
rotate_tool.c scale_tool.c, shear_tool.c, text_tool.c, threshold.c:
API-mega-break-it-all patch part one: removed the unnecessary
PDB_IMAGE argument from many functions.
Affected functions:
gimp_airbrush gimp_blend gimp_brightness_contrast gimp_bucket_fill
gimp_by_color_select gimp_channel_ops_offset gimp_clone gimp_color_balance
gimp_color_picker gimp_convolve gimp_curves_explicit gimp_curves_spline
gimp_desaturate gimp_edit_clear gimp_edit_copy gimp_edit_cut gimp_edit_fill
gimp_edit_paste gimp_edit_stroke gimp_equalize gimp_eraser
gimp_eraser_extended gimp_flip gimp_fuzzy_select gimp_histogram
gimp_hue_saturation gimp_invert gimp_levels gimp_paintbrush
gimp_paintbrush_extended gimp_pencil gimp_perspective gimp_posterize
gimp_rotate gimp_scale gimp_selection_float gimp_selection_layer_alpha
gimp_selection_load gimp_shear gimp_threshold
1998-11-14 04:40:00 +08:00
if ( drawable = = NULL )
success = FALSE ;
else
gimage = drawable_gimage ( drawable ) ;
1997-11-25 06:05:25 +08:00
}
/* the mask only option */
if ( success )
{
API-mega-break-it-all patch part one: removed the unnecessary PDB_IMAGE
* airbrush.c, blend.c, brightness_contrast.c, bucket_fill.c
by_color_select.c, channel_ops.c, clone.c, color_balance.c
color_picker.c, convolve.c, curves.c, desaturate.c, edit_cmds.c
equalize.c, eraser.c, flip_tool.c, fuzzy_select.c,
gimage_mask_cmds.c histogram_tool.c, hue_saturation.c, invert.c,
levels.c, pencil.c paintbrush.c, perspective_tool.c, posterize.c,
rotate_tool.c scale_tool.c, shear_tool.c, text_tool.c, threshold.c:
API-mega-break-it-all patch part one: removed the unnecessary
PDB_IMAGE argument from many functions.
Affected functions:
gimp_airbrush gimp_blend gimp_brightness_contrast gimp_bucket_fill
gimp_by_color_select gimp_channel_ops_offset gimp_clone gimp_color_balance
gimp_color_picker gimp_convolve gimp_curves_explicit gimp_curves_spline
gimp_desaturate gimp_edit_clear gimp_edit_copy gimp_edit_cut gimp_edit_fill
gimp_edit_paste gimp_edit_stroke gimp_equalize gimp_eraser
gimp_eraser_extended gimp_flip gimp_fuzzy_select gimp_histogram
gimp_hue_saturation gimp_invert gimp_levels gimp_paintbrush
gimp_paintbrush_extended gimp_pencil gimp_perspective gimp_posterize
gimp_rotate gimp_scale gimp_selection_float gimp_selection_layer_alpha
gimp_selection_load gimp_shear gimp_threshold
1998-11-14 04:40:00 +08:00
int_value = args [ 1 ] . value . pdb_int ;
1997-11-25 06:05:25 +08:00
mask_only = ( int_value ) ? TRUE : FALSE ;
}
/* make sure the drawable is not indexed color */
if ( success )
1998-01-22 15:02:57 +08:00
success = ! drawable_indexed ( drawable ) ;
1997-11-25 06:05:25 +08:00
if ( success )
1998-01-22 15:02:57 +08:00
equalize ( gimage , drawable , mask_only ) ;
1997-11-25 06:05:25 +08:00
return procedural_db_return_args ( & equalize_proc , success ) ;
}