~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/fp.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include <stdlib.h>
27
27
 
28
 
#include <gtk/gtk.h>
29
 
 
30
28
#include <libgimp/gimp.h>
31
29
#include <libgimp/gimpui.h>
32
30
 
33
31
#include "libgimp/stdplugins-intl.h"
34
32
 
 
33
 
 
34
#define PLUG_IN_PROC       "plug-in-filter-pack"
 
35
#define PLUG_IN_BINARY     "fp"
 
36
 
35
37
#define MAX_PREVIEW_SIZE   125
36
38
#define MAX_ROUGHNESS      128
37
39
#define RANGE_HEIGHT       15
38
40
#define PR_BX_BRDR         4
39
 
#define ALL                255
40
41
#define MARGIN             4
41
42
 
42
 
#define HELP_ID            "plug-in-filter-pack"
43
 
 
44
43
#define RANGE_ADJUST_MASK GDK_EXPOSURE_MASK | \
45
 
                        GDK_ENTER_NOTIFY_MASK | \
46
 
                        GDK_BUTTON_PRESS_MASK | \
47
 
                        GDK_BUTTON_RELEASE_MASK | \
48
 
                        GDK_BUTTON1_MOTION_MASK | \
49
 
                        GDK_POINTER_MOTION_HINT_MASK
 
44
                          GDK_ENTER_NOTIFY_MASK | \
 
45
                          GDK_BUTTON_PRESS_MASK | \
 
46
                          GDK_BUTTON_RELEASE_MASK | \
 
47
                          GDK_BUTTON1_MOTION_MASK | \
 
48
                          GDK_POINTER_MOTION_HINT_MASK
50
49
 
51
50
 
52
51
typedef struct
69
68
  MIDTONES,
70
69
  HIGHLIGHTS,
71
70
  INTENSITIES
72
 
}FPIntensity;
 
71
} FPIntensity;
73
72
 
74
73
enum
75
74
{
240
239
 
241
240
static const gchar *current_val = N_("Current:");
242
241
 
243
 
static gint colorSign[3][ALL_PRIMARY]=
 
242
static const gint colorSign[3][ALL_PRIMARY]=
244
243
{{1,-1,-1,-1,1,1},{-1,1,-1,1,1,-1},{-1,-1,1,1,-1,1}};
245
244
 
246
245
static AdvancedWindow AW = { NULL, NULL, NULL, NULL };
292
291
  {0,0,0}             /* touched */
293
292
};
294
293
 
295
 
static GimpDrawable *drawable, *mask;
 
294
static GimpDrawable *drawable;
 
295
static GimpDrawable *mask;
296
296
 
297
297
static void      query  (void);
298
298
static void      run    (const gchar      *name,
301
301
                         gint             *nreturn_vals,
302
302
                         GimpParam       **return_vals);
303
303
 
304
 
GimpPlugInInfo PLUG_IN_INFO =
 
304
const GimpPlugInInfo PLUG_IN_INFO =
305
305
{
306
306
  NULL,  /* init_proc  */
307
307
  NULL,  /* quit_proc  */
316
316
{
317
317
  GimpParamDef args[] =
318
318
  {
319
 
    { GIMP_PDB_INT32,    "run_mode", "Interactive, non-interactive" },
 
319
    { GIMP_PDB_INT32,    "run-mode", "Interactive, non-interactive"          },
320
320
    { GIMP_PDB_IMAGE,    "image",    "Input image (used for indexed images)" },
321
 
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable" },
 
321
    { GIMP_PDB_DRAWABLE, "drawable", "Input drawable"                        }
322
322
  };
323
323
 
324
 
  gimp_install_procedure ("plug_in_filter_pack",
325
 
                          "Allows the user to change H, S, or C with many previews",
326
 
                          "No help available",
 
324
  gimp_install_procedure (PLUG_IN_PROC,
 
325
                          N_("Interactively modify the image colors"),
 
326
                          "Interactively modify the image colors.",
327
327
                          "Pavel Grinfeld (pavel@ml.com)",
328
328
                          "Pavel Grinfeld (pavel@ml.com)",
329
329
                          "27th March 1997",
333
333
                          G_N_ELEMENTS (args), 0,
334
334
                          args, NULL);
335
335
 
336
 
  gimp_plugin_menu_register ("plug_in_filter_pack", "<Image>/Filters/Colors");
 
336
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/Colors/Modify");
337
337
}
338
338
 
339
339
/********************************STANDARD RUN*************************/
368
368
    {
369
369
    case GIMP_RUN_INTERACTIVE:
370
370
      /*  Possibly retrieve data  */
371
 
      gimp_get_data ("plug_in_filter_pack", &fpvals);
 
371
      gimp_get_data (PLUG_IN_PROC, &fpvals);
372
372
 
373
373
      if (gimp_drawable_is_indexed (drawable->drawable_id) ||
374
374
          gimp_drawable_is_gray (drawable->drawable_id) )
389
389
 
390
390
    case GIMP_RUN_WITH_LAST_VALS:
391
391
      /*  Possibly retrieve data  */
392
 
      gimp_get_data ("plug_in_filter_pack", &fpvals);
 
392
      gimp_get_data (PLUG_IN_PROC, &fpvals);
393
393
      break;
394
394
 
395
395
    default:
401
401
      /*  Make sure that the drawable is gray or RGB color  */
402
402
      if (gimp_drawable_is_rgb (drawable->drawable_id))
403
403
        {
404
 
          gimp_progress_init (_("Applying Filter Pack..."));
405
 
          gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1));
 
404
          gimp_progress_init (_("Applying filter pack"));
 
405
          gimp_tile_cache_ntiles (2 * (drawable->width /
 
406
                                       gimp_tile_width () + 1));
406
407
          fp (drawable);
407
408
 
408
409
          /*  Store data  */
409
410
          if (run_mode == GIMP_RUN_INTERACTIVE)
410
 
            gimp_set_data ("plug_in_filter_pack",
411
 
                           &fpvals, sizeof (FPValues));
 
411
            gimp_set_data (PLUG_IN_PROC, &fpvals, sizeof (FPValues));
412
412
 
413
413
          gimp_displays_flush ();
414
414
        }
571
571
 
572
572
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
573
573
 
574
 
  gimp_help_connect (win, gimp_standard_help_func, HELP_ID, NULL);
 
574
  gimp_help_connect (win, gimp_standard_help_func, PLUG_IN_PROC, NULL);
575
575
 
576
576
  gtk_window_set_title (GTK_WINDOW (win), _("Hue Variations"));
577
577
 
578
 
  g_signal_connect (win, "delete_event",
 
578
  g_signal_connect (win, "delete-event",
579
579
                    G_CALLBACK (sub_dialog_destroy),
580
580
                    NULL);
581
581
 
593
593
  fp_create_preview (&yPreview, &yFrame, reduced->width, reduced->height);
594
594
  fp_create_preview (&mPreview, &mFrame, reduced->width, reduced->height);
595
595
  fp_create_preview (&centerPreview, &centerFrame,
596
 
                    reduced->width, reduced->height);
 
596
                     reduced->width, reduced->height);
597
597
 
598
598
  fp_create_table_entry (&rVbox, rFrame, hue_red);
599
599
  fp_create_table_entry (&gVbox, gFrame, hue_green);
642
642
  gtk_scale_set_digits (GTK_SCALE (scale), 2);
643
643
  gtk_widget_show (scale);
644
644
 
645
 
  g_signal_connect (data, "value_changed",
 
645
  g_signal_connect (data, "value-changed",
646
646
                    G_CALLBACK (fp_scale_update),
647
647
                    &fpvals.roughness);
648
648
 
726
726
 
727
727
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
728
728
 
729
 
  gimp_help_connect (win, gimp_standard_help_func, HELP_ID, NULL);
 
729
  gimp_help_connect (win, gimp_standard_help_func, PLUG_IN_PROC, NULL);
730
730
 
731
731
  gtk_window_set_title (GTK_WINDOW (win), _("Value Variations"));
732
732
 
733
 
  g_signal_connect (win, "delete_event",
 
733
  g_signal_connect (win, "delete-event",
734
734
                    G_CALLBACK (sub_dialog_destroy),
735
735
                    NULL);
736
736
 
770
770
 
771
771
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
772
772
 
773
 
  gimp_help_connect (win, gimp_standard_help_func, HELP_ID, NULL);
 
773
  gimp_help_connect (win, gimp_standard_help_func, PLUG_IN_PROC, NULL);
774
774
 
775
775
  gtk_window_set_title (GTK_WINDOW (win), _("Saturation Variations"));
776
776
 
777
 
  g_signal_connect (win, "delete_event",
 
777
  g_signal_connect (win, "delete-event",
778
778
                    G_CALLBACK (sub_dialog_destroy),
779
779
                    NULL);
780
780
 
824
824
{
825
825
  GtkWidget *frame;
826
826
 
827
 
  frame = gimp_int_radio_group_new (TRUE, _("Select Pixels by"),
 
827
  frame = gimp_int_radio_group_new (TRUE, _("Select Pixels By"),
828
828
                                    G_CALLBACK (fp_change_current_pixels_by),
829
829
                                    &fpvals.value_by,
830
830
                                    fpvals.value_by,
862
862
                                    &fpvals.selection_only,
863
863
                                    fpvals.selection_only,
864
864
 
865
 
                                    _("_Entire Image"),  0, NULL,
866
 
                                    _("Se_lection Only"), 1, NULL,
867
 
                                    _("Selec_tion In Context"), 2, NULL,
 
865
                                    _("_Entire image"),  0, NULL,
 
866
                                    _("Se_lection only"), 1, NULL,
 
867
                                    _("Selec_tion in context"), 2, NULL,
868
868
 
869
869
                                    NULL);
870
870
 
937
937
                      GtkWidget    *smaller_frame,
938
938
                      const gchar  *description)
939
939
{
940
 
  GtkWidget *label, *button, *table;
 
940
  GtkWidget *label;
 
941
  GtkWidget *button;
 
942
  GtkWidget *table;
941
943
 
942
944
  *box = gtk_vbox_new (FALSE, 1);
943
945
  gtk_container_set_border_width (GTK_CONTAINER (*box), PR_BX_BRDR);
980
982
static void
981
983
fp_redraw_all_windows (void)
982
984
{
983
 
  reduced = fp_reduce_image (drawable,mask,
984
 
                              fpvals.preview_size,
985
 
                              fpvals.selection_only);
 
985
  if (reduced)
 
986
    {
 
987
      g_free (reduced->rgb);
 
988
      g_free (reduced->hsv);
 
989
      g_free (reduced->mask);
 
990
 
 
991
      g_free (reduced);
 
992
    }
 
993
 
 
994
  reduced = fp_reduce_image (drawable, mask,
 
995
                             fpvals.preview_size,
 
996
                             fpvals.selection_only);
 
997
 
986
998
  fp_adjust_preview_sizes (reduced->width, reduced->height);
987
999
 
988
1000
  gtk_widget_queue_draw (fp_frames.palette);
1064
1076
{
1065
1077
  fpvals.touched[fpvals.value_by] = 1;
1066
1078
 
1067
 
  if (data == (gpointer) hue_red) {
1068
 
    update_current_fp (HUE, RED);
1069
 
  } else if (data == (gpointer) hue_green) {
1070
 
    update_current_fp (HUE, GREEN);
1071
 
  } else if (data == (gpointer) hue_blue) {
1072
 
    update_current_fp (HUE, BLUE);
1073
 
  } else if (data == (gpointer) hue_cyan) {
1074
 
    update_current_fp (HUE, CYAN);
1075
 
  } else if (data == (gpointer) hue_yellow) {
1076
 
    update_current_fp (HUE, YELLOW);
1077
 
  } else if (data == (gpointer) hue_magenta) {
1078
 
    update_current_fp (HUE, MAGENTA);
1079
 
  } else if (data == (gpointer) val_darker) {
1080
 
    update_current_fp (VALUE, DOWN);
1081
 
  } else if (data == (gpointer) val_lighter) {
1082
 
    update_current_fp (VALUE, UP);
1083
 
  } else if (data == (gpointer) sat_more) {
1084
 
    update_current_fp (SATURATION, UP);
1085
 
  } else if (data == (gpointer) sat_less) {
1086
 
    update_current_fp (SATURATION, DOWN);
1087
 
  }
 
1079
  if (data == (gpointer) hue_red)
 
1080
    {
 
1081
      update_current_fp (HUE, RED);
 
1082
    }
 
1083
  else if (data == (gpointer) hue_green)
 
1084
    {
 
1085
      update_current_fp (HUE, GREEN);
 
1086
    }
 
1087
  else if (data == (gpointer) hue_blue)
 
1088
    {
 
1089
      update_current_fp (HUE, BLUE);
 
1090
    }
 
1091
  else if (data == (gpointer) hue_cyan)
 
1092
    {
 
1093
      update_current_fp (HUE, CYAN);
 
1094
    }
 
1095
  else if (data == (gpointer) hue_yellow)
 
1096
    {
 
1097
      update_current_fp (HUE, YELLOW);
 
1098
    }
 
1099
  else if (data == (gpointer) hue_magenta)
 
1100
    {
 
1101
      update_current_fp (HUE, MAGENTA);
 
1102
    }
 
1103
  else if (data == (gpointer) val_darker)
 
1104
    {
 
1105
      update_current_fp (VALUE, DOWN);
 
1106
    }
 
1107
  else if (data == (gpointer) val_lighter)
 
1108
    {
 
1109
      update_current_fp (VALUE, UP);
 
1110
    }
 
1111
  else if (data == (gpointer) sat_more)
 
1112
    {
 
1113
      update_current_fp (SATURATION, UP);
 
1114
    }
 
1115
  else if (data == (gpointer) sat_less)
 
1116
    {
 
1117
      update_current_fp (SATURATION, DOWN);
 
1118
    }
1088
1119
 
1089
1120
  fp_refresh_previews (fpvals.visible_frames);
1090
1121
}
1095
1126
  fp_create_nudge (nudgeArray);
1096
1127
  fp_render_preview (origPreview, NONEATALL, 0);
1097
1128
  fp_render_preview (curPreview, CURRENT, 0);
 
1129
 
1098
1130
  if (which & HUE)
1099
1131
    {
1100
1132
      fp_render_preview (rPreview,        HUE,        RED);
1105
1137
      fp_render_preview (mPreview,        HUE,        MAGENTA);
1106
1138
      fp_render_preview (centerPreview,   CURRENT,    0);
1107
1139
    }
 
1140
 
1108
1141
  if (which & VALUE)
1109
1142
    {
1110
1143
      fp_render_preview (lighterPreview,  VALUE,      UP);
1111
1144
      fp_render_preview (middlePreview,   CURRENT,    0);
1112
1145
      fp_render_preview (darkerPreview,   VALUE,      DOWN);
1113
1146
    }
 
1147
 
1114
1148
  if (which & SATURATION)
1115
1149
    {
1116
1150
      fp_render_preview (plusSatPreview,  SATURATION, UP);
1173
1207
  GtkWidget *control;
1174
1208
  GtkWidget *table;
1175
1209
 
1176
 
  reduced = fp_reduce_image (drawable,mask,
1177
 
                              fpvals.preview_size,
1178
 
                              fpvals.selection_only);
1179
 
 
1180
 
  gimp_ui_init ("fp", TRUE);
1181
 
 
1182
 
  dlg = gimp_dialog_new (_("Filter Pack Simulation"), "fp",
 
1210
  reduced = fp_reduce_image (drawable, mask,
 
1211
                             fpvals.preview_size,
 
1212
                             fpvals.selection_only);
 
1213
 
 
1214
  gimp_ui_init (PLUG_IN_BINARY, TRUE);
 
1215
 
 
1216
  dlg = gimp_dialog_new (_("Filter Pack Simulation"), PLUG_IN_BINARY,
1183
1217
                         NULL, 0,
1184
 
                         gimp_standard_help_func, HELP_ID,
 
1218
                         gimp_standard_help_func, PLUG_IN_PROC,
1185
1219
 
1186
1220
                         GIMP_STOCK_RESET, RESPONSE_RESET,
1187
1221
                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1189
1223
 
1190
1224
                         NULL);
1191
1225
 
 
1226
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
 
1227
                                           RESPONSE_RESET,
 
1228
                                           GTK_RESPONSE_OK,
 
1229
                                           GTK_RESPONSE_CANCEL,
 
1230
                                           -1);
 
1231
 
 
1232
  gimp_window_set_transient (GTK_WINDOW (dlg));
 
1233
 
1192
1234
  g_signal_connect (dlg, "response",
1193
1235
                    G_CALLBACK (fp_response),
1194
1236
                    dlg);
1207
1249
  fp_frames.show         = show         = fp_create_show();
1208
1250
  fp_frames.satur        = satur        = fp_create_msnls();
1209
1251
  fp_frames.pixelsBy     = pixelsBy     = fp_create_pixels_select_by();
1210
 
                          control      = fp_create_control();
 
1252
                           control      = fp_create_control();
1211
1253
  /********************************************************************/
1212
1254
  /********************   PUT EVERYTHING TOGETHER    ******************/
1213
1255
 
1222
1264
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
1223
1265
 
1224
1266
  gtk_table_attach (GTK_TABLE (table), control, 1, 2, 1, 3,
1225
 
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1267
                    GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 0, 0);
1226
1268
 
1227
1269
  gtk_table_attach (GTK_TABLE (table), rough, 1, 2, 3, 4,
1228
 
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1270
                    GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 0, 0);
1229
1271
 
1230
1272
  gtk_table_attach (GTK_TABLE (table), show, 0, 1, 1, 2,
1231
 
                    GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1273
                    GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 0, 0);
1232
1274
 
1233
1275
  gtk_table_attach (GTK_TABLE (table), range, 0, 1, 2, 3,
1234
 
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1276
                    GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 0, 0);
1235
1277
 
1236
1278
  gtk_table_attach (GTK_TABLE (table), pixelsBy, 0, 1, 3, 4,
1237
 
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
 
1279
                    GTK_FILL | GTK_SHRINK, GTK_FILL | GTK_SHRINK, 0, 0);
1238
1280
 
1239
1281
  gtk_widget_show (dlg);
1240
1282
 
1300
1342
 
1301
1343
  AW.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1302
1344
 
1303
 
  gimp_help_connect (AW.window, gimp_standard_help_func, HELP_ID, NULL);
 
1345
  gimp_help_connect (AW.window, gimp_standard_help_func, PLUG_IN_PROC, NULL);
1304
1346
 
1305
1347
  gtk_window_set_title (GTK_WINDOW (AW.window),
1306
1348
                        _("Advanced Filter Pack Options"));
1307
1349
 
1308
 
  g_signal_connect (AW.window, "delete_event",
 
1350
  g_signal_connect (AW.window, "delete-event",
1309
1351
                    G_CALLBACK (sub_dialog_destroy),
1310
1352
                    NULL);
1311
1353
 
1392
1434
 
1393
1435
  /************************************************************/
1394
1436
 
1395
 
  smoothnessData = gtk_adjustment_new (fpvals.aliasing, 0, 1.0, 0.05, 0.01, 0.0);
 
1437
  smoothnessData = gtk_adjustment_new (fpvals.aliasing,
 
1438
                                       0, 1.0, 0.05, 0.01, 0.0);
1396
1439
 
1397
1440
  fp_widgets.aliasing_scale = scale =
1398
1441
    gtk_hscale_new (GTK_ADJUSTMENT (smoothnessData));
1404
1447
                    0, 0, 0, 0);
1405
1448
  gtk_widget_show (scale);
1406
1449
 
1407
 
  g_signal_connect (smoothnessData, "value_changed",
 
1450
  g_signal_connect (smoothnessData, "value-changed",
1408
1451
                    G_CALLBACK (fp_scale_update),
1409
1452
                    &fpvals.aliasing);
1410
1453
 
1434
1477
  gtk_range_set_update_policy (GTK_RANGE (scale), 0);
1435
1478
  gtk_widget_show (scale);
1436
1479
 
1437
 
  g_signal_connect (smoothnessData, "value_changed",
 
1480
  g_signal_connect (smoothnessData, "value-changed",
1438
1481
                    G_CALLBACK (fp_preview_scale_update),
1439
1482
                    &fpvals.preview_size);
1440
1483
 
1616
1659
}
1617
1660
 
1618
1661
static ReducedImage *
1619
 
fp_reduce_image (GimpDrawable  *drawable,
 
1662
fp_reduce_image (GimpDrawable *drawable,
1620
1663
                 GimpDrawable *mask,
1621
1664
                 gint          longer_size,
1622
1665
                 gint          selection)
1623
1666
{
1624
 
  gint          RH, RW, width, height, bytes=drawable->bpp;
1625
 
  ReducedImage *temp = (ReducedImage *) malloc (sizeof (ReducedImage));
 
1667
  gint          RH, RW, bytes = drawable->bpp;
 
1668
  gint          x, y, width, height;
 
1669
  ReducedImage *temp = g_new0 (ReducedImage, 1);
1626
1670
  guchar       *tempRGB, *src_row, *tempmask, *src_mask_row, R, G, B;
1627
 
  gint          i, j, whichcol, whichrow, x1, x2, y1, y2;
 
1671
  gint          i, j, whichcol, whichrow;
1628
1672
  GimpPixelRgn  srcPR, srcMask;
1629
 
  gboolean      NoSelectionMade = TRUE;
1630
1673
  gdouble      *tempHSV;
1631
1674
  GimpRGB       rgb;
1632
1675
  GimpHSV       hsv;
1633
1676
 
1634
 
  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
1635
 
  width  = x2 - x1;
1636
 
  height = y2 - y1;
1637
 
 
1638
 
  if (width != drawable->width && height != drawable->height)
1639
 
    NoSelectionMade = FALSE;
1640
 
 
1641
 
  if (selection == 0)
1642
 
    {
1643
 
      x1 = 0;
1644
 
      x2 = drawable->width;
1645
 
      y1 = 0;
1646
 
      y2 = drawable->height;
1647
 
    }
1648
 
  else if (selection == 2)
1649
 
    {
1650
 
      x1 = MAX (0,                x1 - width  / 2.0);
1651
 
      x2 = MIN (drawable->width,  x2 + width  / 2.0);
1652
 
      y1 = MAX (0,                y1 - height / 2.0);
1653
 
      y2 = MIN (drawable->height, y2 + height / 2.0);
1654
 
    }
1655
 
 
1656
 
  width  = x2 - x1;
1657
 
  height = y2 - y1;
 
1677
  switch (selection)
 
1678
    {
 
1679
    case 0:
 
1680
      x      = 0;
 
1681
      width  = drawable->width;
 
1682
      y      = 0;
 
1683
      height = drawable->height;
 
1684
      break;
 
1685
 
 
1686
    case 1:
 
1687
      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
 
1688
                                          &x, &y, &width, &height))
 
1689
        return temp;
 
1690
      break;
 
1691
 
 
1692
    case 2:
 
1693
      if (! gimp_drawable_mask_intersect (drawable->drawable_id,
 
1694
                                          &x, &y, &width, &height) ||
 
1695
          ! gimp_rectangle_intersect (x - width / 2, y - height / 2,
 
1696
                                      2 * width, 2 * height,
 
1697
                                      0, 0, drawable->width, drawable->height,
 
1698
                                      &x, &y, &width, &height))
 
1699
        return temp;
 
1700
      break;
 
1701
 
 
1702
    default:
 
1703
      return temp;
 
1704
    }
1658
1705
 
1659
1706
  if (width > height)
1660
1707
    {
1667
1714
      RW = (gdouble) width * (gdouble) longer_size / (gdouble) height;
1668
1715
    }
1669
1716
 
1670
 
  tempRGB  = (guchar *)  malloc (RW * RH * bytes);
1671
 
  tempHSV  = (gdouble *) malloc (RW * RH * bytes * sizeof (gdouble));
1672
 
  tempmask = (guchar *)  malloc (RW * RH);
1673
 
 
1674
 
  gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, width, height, FALSE, FALSE);
1675
 
  gimp_pixel_rgn_init (&srcMask, mask, x1, y1, width, height, FALSE, FALSE);
1676
 
 
1677
 
  src_row      = (guchar *) malloc (width * bytes);
1678
 
  src_mask_row = (guchar *) malloc (width * bytes);
 
1717
  tempRGB  = g_new (guchar, RW * RH * bytes);
 
1718
  tempHSV  = g_new (gdouble, RW * RH * bytes);
 
1719
  tempmask = g_new (guchar, RW * RH);
 
1720
 
 
1721
  gimp_pixel_rgn_init (&srcPR, drawable, x, y, width, height, FALSE, FALSE);
 
1722
  gimp_pixel_rgn_init (&srcMask, mask, x, y, width, height, FALSE, FALSE);
 
1723
 
 
1724
  src_row      = g_new (guchar, width * bytes);
 
1725
  src_mask_row = g_new (guchar, width * bytes);
1679
1726
 
1680
1727
  for (i = 0; i < RH; i++)
1681
1728
    {
1682
1729
      whichrow = (gdouble) i * (gdouble) height / (gdouble) RH;
1683
1730
 
1684
 
      gimp_pixel_rgn_get_row (&srcPR, src_row, x1, y1 + whichrow, width);
1685
 
      gimp_pixel_rgn_get_row (&srcMask, src_mask_row, x1, y1 + whichrow, width);
 
1731
      gimp_pixel_rgn_get_row (&srcPR, src_row, x, y + whichrow, width);
 
1732
      gimp_pixel_rgn_get_row (&srcMask, src_mask_row, x, y + whichrow, width);
1686
1733
 
1687
1734
      for (j = 0; j < RW; j++)
1688
1735
        {
1689
1736
          whichcol = (gdouble) j * (gdouble) width / (gdouble) RW;
1690
1737
 
1691
 
          if (NoSelectionMade)
1692
 
            tempmask[i * RW + j] = 255;
1693
 
          else
1694
 
            tempmask[i * RW + j] = src_mask_row[whichcol];
 
1738
          tempmask[i * RW + j] = src_mask_row[whichcol];
1695
1739
 
1696
1740
          R = src_row[whichcol * bytes + 0];
1697
1741
          G = src_row[whichcol * bytes + 1];
1714
1758
        }
1715
1759
    }
1716
1760
 
 
1761
  g_free (src_row);
 
1762
  g_free (src_mask_row);
 
1763
 
1717
1764
  temp->width  = RW;
1718
1765
  temp->height = RH;
1719
1766
  temp->rgb    = tempRGB;
1724
1771
}
1725
1772
 
1726
1773
static void
1727
 
fp_render_preview(GtkWidget *preview,
1728
 
                  gint       change_what,
1729
 
                  gint       change_which)
 
1774
fp_render_preview (GtkWidget *preview,
 
1775
                   gint       change_what,
 
1776
                   gint       change_which)
1730
1777
{
1731
1778
  guchar *a;
1732
1779
  gint    Inten;
1739
1786
  gint    P[3];
1740
1787
  gint    tempSat[JUDGE_BY][256];
1741
1788
 
1742
 
  a = g_new (guchar, 4*RW*RH);
 
1789
  a = g_new (guchar, 4 * RW * RH);
1743
1790
 
1744
 
  if (change_what==SATURATION)
 
1791
  if (change_what == SATURATION)
1745
1792
    for (k = 0; k < 256; k++)
1746
1793
      {
1747
1794
        for (JudgeBy = BY_HUE; JudgeBy < JUDGE_BY; JudgeBy++)
1748
1795
          tempSat[JudgeBy][k] = 0;
1749
 
        tempSat[fpvals.value_by][k] += change_which * nudgeArray[(k + fpvals.offset) % 256];
 
1796
 
 
1797
        tempSat[fpvals.value_by][k] +=
 
1798
          change_which * nudgeArray[(k + fpvals.offset) % 256];
1750
1799
      }
1751
1800
 
1752
1801
  for (i = 0; i < RH; i++)
1753
1802
    {
1754
1803
      for (j = 0; j < RW; j++)
1755
1804
        {
1756
 
          backupP[0] = P[0]  = (int) reduced->rgb[i * RW * bytes + j * bytes + 0];
1757
 
          backupP[1] = P[1]  = (int) reduced->rgb[i * RW * bytes + j * bytes + 1];
1758
 
          backupP[2] = P[2]  = (int) reduced->rgb[i * RW * bytes + j * bytes + 2];
1759
 
 
1760
 
      m = MIN (MIN (P[0], P[1]), P[2]);
1761
 
      M = MAX (MAX (P[0], P[1]), P[2]);
1762
 
 
1763
 
      middle = (M + m) / 2;
1764
 
 
1765
 
      for (k = 0; k < 3; k++)
1766
 
        if (P[k] != m && P[k] != M) middle = P[k];
1767
 
 
1768
 
      partial = reduced->mask[i * RW + j] / 255.0;
1769
 
 
1770
 
      for (JudgeBy = BY_HUE; JudgeBy < JUDGE_BY; JudgeBy++)
1771
 
        {
1772
 
         if (!fpvals.touched[JudgeBy]) continue;
1773
 
 
1774
 
         Inten   = reduced->hsv[i * RW * bytes + j * bytes + JudgeBy] * 255.0;
1775
 
 
1776
 
         /*DO SATURATION FIRST*/
1777
 
         if (change_what != NONEATALL)
1778
 
           {
1779
 
             if (M != m)
1780
 
               {
1781
 
                 for (k = 0; k < 3; k++)
1782
 
                   if (backupP[k] == M)
1783
 
                     P[k] = MAX (P[k] + partial * fpvals.sat_adjust[JudgeBy][Inten],
1784
 
                                 middle);
1785
 
                   else if (backupP[k] == m)
1786
 
                     P[k] = MIN (P[k] - partial * fpvals.sat_adjust[JudgeBy][Inten],
1787
 
                                 middle);
1788
 
               }
1789
 
 
1790
 
             P[0]  += partial * fpvals.red_adjust[JudgeBy][Inten];
1791
 
             P[1]  += partial * fpvals.green_adjust[JudgeBy][Inten];
1792
 
             P[2]  += partial * fpvals.blue_adjust[JudgeBy][Inten];
1793
 
           }
1794
 
        }
1795
 
 
1796
 
      Inten   = reduced->hsv[i * RW * bytes + j * bytes + fpvals.value_by] * 255.0;
1797
 
      nudge   = partial * nudgeArray[(Inten + fpvals.offset) % 256];
1798
 
 
1799
 
      switch (change_what)
1800
 
        {
1801
 
        case HUE:
1802
 
          P[0]  += colorSign[RED][change_which]   * nudge;
1803
 
          P[1]  += colorSign[GREEN][change_which] * nudge;
1804
 
          P[2]  += colorSign[BLUE][change_which]  * nudge;
1805
 
          break;
1806
 
 
1807
 
        case SATURATION:
 
1805
          backupP[0] = P[0] = reduced->rgb[i * RW * bytes + j * bytes + 0];
 
1806
          backupP[1] = P[1] = reduced->rgb[i * RW * bytes + j * bytes + 1];
 
1807
          backupP[2] = P[2] = reduced->rgb[i * RW * bytes + j * bytes + 2];
 
1808
 
 
1809
          m = MIN (MIN (P[0], P[1]), P[2]);
 
1810
          M = MAX (MAX (P[0], P[1]), P[2]);
 
1811
 
 
1812
          middle = (M + m) / 2;
 
1813
 
 
1814
          for (k = 0; k < 3; k++)
 
1815
            if (P[k] != m && P[k] != M) middle = P[k];
 
1816
 
 
1817
          partial = reduced->mask[i * RW + j] / 255.0;
 
1818
 
1808
1819
          for (JudgeBy = BY_HUE; JudgeBy < JUDGE_BY; JudgeBy++)
1809
 
            for (k = 0; k < 3; k++)
1810
 
              if (M != m)
 
1820
            {
 
1821
              if (!fpvals.touched[JudgeBy])
 
1822
                continue;
 
1823
 
 
1824
              Inten =
 
1825
                reduced->hsv[i * RW * bytes + j * bytes + JudgeBy] * 255.0;
 
1826
 
 
1827
              /*DO SATURATION FIRST*/
 
1828
              if (change_what != NONEATALL)
1811
1829
                {
1812
 
                  if (backupP[k] == M)
1813
 
                    P[k] = MAX (P[k] + partial * tempSat[JudgeBy][Inten],
1814
 
                                middle);
1815
 
                  else if (backupP[k] == m)
1816
 
                    P[k] = MIN (P[k]- partial * tempSat[JudgeBy][Inten],
1817
 
                                middle);
1818
 
                }
1819
 
          break;
1820
 
 
1821
 
        case VALUE:
1822
 
          P[0]  += change_which * nudge;
1823
 
          P[1]  += change_which * nudge;
1824
 
          P[2]  += change_which * nudge;
1825
 
          break;
1826
 
 
1827
 
        default:
1828
 
          break;
1829
 
        }
1830
 
 
1831
 
      a[(i * RW + j) * 4 + 0] = CLAMP0255(P[0]);
1832
 
      a[(i * RW + j) * 4 + 1] = CLAMP0255(P[1]);
1833
 
      a[(i * RW + j) * 4 + 2] = CLAMP0255(P[2]);
1834
 
 
1835
 
      if (bytes == 4)
1836
 
        a[(i * RW + j) * 4 + 3] = reduced->rgb[i * RW * bytes + j * bytes + 3];
1837
 
      else
1838
 
        a[(i * RW + j) * 4 + 3] = 255;
 
1830
                  if (M != m)
 
1831
                    {
 
1832
                      for (k = 0; k < 3; k++)
 
1833
                        if (backupP[k] == M)
 
1834
                          P[k] = MAX (P[k] +
 
1835
                                      partial * fpvals.sat_adjust[JudgeBy][Inten],
 
1836
                                      middle);
 
1837
                        else if (backupP[k] == m)
 
1838
                          P[k] = MIN (P[k] -
 
1839
                                      partial * fpvals.sat_adjust[JudgeBy][Inten],
 
1840
                                      middle);
 
1841
                    }
 
1842
 
 
1843
                  P[0]  += partial * fpvals.red_adjust[JudgeBy][Inten];
 
1844
                  P[1]  += partial * fpvals.green_adjust[JudgeBy][Inten];
 
1845
                  P[2]  += partial * fpvals.blue_adjust[JudgeBy][Inten];
 
1846
                }
 
1847
            }
 
1848
 
 
1849
          Inten =
 
1850
            reduced->hsv[i * RW * bytes + j * bytes + fpvals.value_by] * 255.0;
 
1851
          nudge = partial * nudgeArray[(Inten + fpvals.offset) % 256];
 
1852
 
 
1853
          switch (change_what)
 
1854
            {
 
1855
            case HUE:
 
1856
              P[0]  += colorSign[RED][change_which]   * nudge;
 
1857
              P[1]  += colorSign[GREEN][change_which] * nudge;
 
1858
              P[2]  += colorSign[BLUE][change_which]  * nudge;
 
1859
              break;
 
1860
 
 
1861
            case SATURATION:
 
1862
              for (JudgeBy = BY_HUE; JudgeBy < JUDGE_BY; JudgeBy++)
 
1863
                for (k = 0; k < 3; k++)
 
1864
                  if (M != m)
 
1865
                    {
 
1866
                      if (backupP[k] == M)
 
1867
                        P[k] = MAX (P[k] + partial * tempSat[JudgeBy][Inten],
 
1868
                                    middle);
 
1869
                      else if (backupP[k] == m)
 
1870
                        P[k] = MIN (P[k]- partial * tempSat[JudgeBy][Inten],
 
1871
                                    middle);
 
1872
                }
 
1873
              break;
 
1874
 
 
1875
            case VALUE:
 
1876
              P[0]  += change_which * nudge;
 
1877
              P[1]  += change_which * nudge;
 
1878
              P[2]  += change_which * nudge;
 
1879
              break;
 
1880
 
 
1881
            default:
 
1882
              break;
 
1883
            }
 
1884
 
 
1885
          a[(i * RW + j) * 4 + 0] = CLAMP0255(P[0]);
 
1886
          a[(i * RW + j) * 4 + 1] = CLAMP0255(P[1]);
 
1887
          a[(i * RW + j) * 4 + 2] = CLAMP0255(P[2]);
 
1888
 
 
1889
          if (bytes == 4)
 
1890
            a[(i * RW + j) * 4 + 3] = reduced->rgb[i * RW * bytes + j * bytes + 3];
 
1891
          else
 
1892
            a[(i * RW + j) * 4 + 3] = 255;
1839
1893
        }
1840
1894
    }
1841
1895