1997-11-24 22:05:25 +00: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 05:44:11 +00:00
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
1997-11-24 22:05:25 +00:00
*/
# include <stdlib.h>
# include <string.h>
# include <math.h>
# include "appenv.h"
# include "drawable.h"
# include "interface.h"
# include "invert.h"
1998-01-22 07:02:57 +00:00
# include "gimage.h"
1999-02-16 08:53:54 +00:00
# include "gimplut.h"
1999-04-09 06:00:11 +00:00
# include "lut_funcs.h"
1997-11-24 22:05:25 +00:00
1998-11-23 14:47:09 +00:00
# include "libgimp/gimpintl.h"
1998-01-22 07:02:57 +00:00
static void invert ( GimpDrawable * ) ;
1997-11-24 22:05:25 +00:00
static Argument * invert_invoker ( Argument * ) ;
void
1999-02-03 09:17:37 +00:00
image_invert ( GImage * gimage )
1997-11-24 22:05:25 +00:00
{
1998-01-22 07:02:57 +00:00
GimpDrawable * drawable ;
1997-11-24 22:05:25 +00:00
Argument * return_vals ;
int nreturn_vals ;
1998-01-22 07:02:57 +00:00
drawable = gimage_active_drawable ( gimage ) ;
1997-11-24 22:05:25 +00:00
1998-01-22 07:02:57 +00:00
if ( drawable_indexed ( drawable ) )
1997-11-24 22:05:25 +00:00
{
1998-11-23 14:47:09 +00:00
g_message ( _ ( " Invert does not operate on indexed drawables. " ) ) ;
1997-11-24 22:05:25 +00:00
return ;
}
return_vals = procedural_db_run_proc ( " gimp_invert " ,
& nreturn_vals ,
1998-01-22 07:02:57 +00:00
PDB_DRAWABLE , drawable_ID ( drawable ) ,
1997-11-24 22:05:25 +00:00
PDB_END ) ;
1999-04-20 23:03:31 +00:00
if ( ! return_vals | | return_vals [ 0 ] . value . pdb_int ! = PDB_SUCCESS )
1998-11-23 14:47:09 +00:00
g_message ( _ ( " Invert operation failed. " ) ) ;
1997-11-24 22:05:25 +00:00
procedural_db_destroy_args ( return_vals , nreturn_vals ) ;
}
/* Inverter */
static void
1999-02-03 09:17:37 +00:00
invert ( GimpDrawable * drawable )
1997-11-24 22:05:25 +00:00
{
PixelRegion srcPR , destPR ;
int x1 , y1 , x2 , y2 ;
1999-02-16 08:53:54 +00:00
GimpLut * lut ;
1999-04-09 06:00:11 +00:00
lut = invert_lut_new ( gimp_drawable_bytes ( drawable ) ) ;
1997-11-24 22:05:25 +00:00
1998-01-22 07:02:57 +00:00
drawable_mask_bounds ( drawable , & x1 , & y1 , & x2 , & y2 ) ;
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-24 22:05:25 +00:00
1999-02-16 08:53:54 +00:00
pixel_regions_process_parallel ( ( p_func ) gimp_lut_process , lut ,
2 , & srcPR , & destPR ) ;
gimp_lut_free ( lut ) ;
1997-11-24 22:05:25 +00:00
1998-01-22 07:02:57 +00:00
drawable_merge_shadow ( drawable , TRUE ) ;
drawable_update ( drawable , x1 , y1 , ( x2 - x1 ) , ( y2 - y1 ) ) ;
1997-11-24 22:05:25 +00:00
}
1999-04-09 06:00:11 +00:00
/* ------------------------------------------------------------------ */
/* ----------------- The invert procedure definition ---------------- */
/* ------------------------------------------------------------------ */
1997-11-24 22:05:25 +00:00
ProcArg invert_args [ ] =
{
{ PDB_DRAWABLE ,
" drawable " ,
" the drawable "
}
} ;
ProcRecord invert_proc =
{
" gimp_invert " ,
" Invert the contents of the specified drawable " ,
" This procedure inverts the contents of the specified drawable. Each intensity channel is inverted independently. The inverted intensity is given as inten' = (255 - inten). Indexed color drawables are not valid for this operation. " ,
" Spencer Kimball & Peter Mattis " ,
" Spencer Kimball & Peter Mattis " ,
" 1995-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-13 20:40:00 +00:00
1 ,
1997-11-24 22:05:25 +00:00
invert_args ,
/* Output arguments */
0 ,
NULL ,
/* Exec method */
{ { invert_invoker } } ,
} ;
static Argument *
invert_invoker ( args )
Argument * args ;
{
int success = TRUE ;
int int_value ;
GImage * gimage ;
1998-01-22 07:02:57 +00:00
GimpDrawable * drawable ;
1997-11-24 22:05:25 +00:00
1998-01-22 07:02:57 +00:00
drawable = NULL ;
1997-11-24 22:05:25 +00: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-13 20:40:00 +00:00
int_value = args [ 0 ] . value . pdb_int ;
1998-01-22 07:02:57 +00: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-13 20:40:00 +00:00
if ( drawable = = NULL )
success = FALSE ;
else
gimage = drawable_gimage ( drawable ) ;
1997-11-24 22:05:25 +00:00
}
/* make sure the drawable is not indexed color */
if ( success )
1998-01-22 07:02:57 +00:00
success = ! drawable_indexed ( drawable ) ;
1997-11-24 22:05:25 +00:00
if ( success )
1998-01-22 07:02:57 +00:00
invert ( drawable ) ;
1997-11-24 22:05:25 +00:00
return procedural_db_return_args ( & invert_proc , success ) ;
}