static GimpValueArray * channel_get_color_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { gboolean success = TRUE; GimpValueArray *return_vals; GimpChannel *channel; GimpRGB color = { 0.0, 0.0, 0.0, 1.0 }; channel = gimp_value_get_channel (gimp_value_array_index (args, 0), gimp); if (success) { gimp_channel_get_color (channel, &color); gimp_rgb_set_alpha (&color, 1.0); } return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) gimp_value_set_rgb (gimp_value_array_index (return_vals, 1), &color); return return_vals; }
static GValueArray * channel_get_color_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GValueArray *args) { gboolean success = TRUE; GValueArray *return_vals; GimpChannel *channel; GimpRGB color = { 0.0, 0.0, 0.0, 1.0 }; channel = gimp_value_get_channel (&args->values[0], gimp); if (success) { gimp_channel_get_color (channel, &color); gimp_rgb_set_alpha (&color, 1.0); } return_vals = gimp_procedure_get_return_values (procedure, success); if (success) gimp_value_set_rgb (&return_vals->values[1], &color); return return_vals; }
static void params_load_from_gimp (void) { gimp_get_data (PLUG_IN_PROC, &p.params); if (0 < p.params.division_x) { p.params.tile_width = p.drawable->width / p.params.division_x; if (0 < p.params.tile_width) { p.params.division_y = p.drawable->height / p.params.tile_height; } } if (p.params.tile_width <= 0 || p.params.tile_height <= 0 || p.params.division_x <= 0 || p.params.division_y <= 0) { p.params.tile_width = p.drawable->width; p.params.tile_height = p.drawable->height; p.params.division_x = p.drawable->width / p.params.tile_width; p.params.division_y = p.drawable->height / p.params.tile_height; } if (!p.drawable_has_alpha) { if (p.params.background_type == BACKGROUND_TYPE_TRANSPARENT) { p.params.background_type = BACKGROUND_TYPE_INVERTED; } gimp_rgb_set_alpha (&p.params.background_color, 1.0); } }
gint image_setup (GimpDrawable *drawable, gint interactive) { /* Set the tile cache size */ /* ======================= */ gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width() - 1) / gimp_tile_width ()); /* Get some useful info on the input drawable */ /* ========================================== */ input_drawable = drawable; output_drawable = drawable; if (! gimp_drawable_mask_intersect (drawable->drawable_id, &border_x, &border_y, &border_w, &border_h)) return FALSE; width = input_drawable->width; height = input_drawable->height; gimp_pixel_rgn_init (&source_region, input_drawable, 0, 0, width, height, FALSE, FALSE); maxcounter = (glong) width * (glong) height; if (mapvals.transparent_background == TRUE) { gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0); } else { gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 1.0); } /* Assume at least RGB */ /* =================== */ in_channels = 3; if (gimp_drawable_has_alpha (input_drawable->drawable_id) == TRUE) in_channels++; if (interactive == TRUE) { preview_rgb_stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, PREVIEW_WIDTH); preview_rgb_data = g_new0 (guchar, preview_rgb_stride * PREVIEW_HEIGHT); preview_surface = cairo_image_surface_create_for_data (preview_rgb_data, CAIRO_FORMAT_RGB24, PREVIEW_WIDTH, PREVIEW_HEIGHT, preview_rgb_stride); } return TRUE; }
static VALUE rb_gimp_rgb_set_alpha (VALUE self, VALUE alpha) { Get_TypedStruct(self, GimpRGB, color); gimp_rgb_set_alpha(color, (gdouble)NUM2DBL(alpha)); return alpha; }
static void channel_options_opacity_update (GtkAdjustment *adjustment, gpointer data) { GimpRGB color; gimp_color_button_get_color (GIMP_COLOR_BUTTON (data), &color); gimp_rgb_set_alpha (&color, gtk_adjustment_get_value (adjustment) / 100.0); gimp_color_button_set_color (GIMP_COLOR_BUTTON (data), &color); }
gint image_setup (GimpDrawable *drawable, gint interactive) { /* Set the tile cache size */ /* ======================= */ gimp_tile_cache_ntiles ((drawable->width + gimp_tile_width() - 1) / gimp_tile_width ()); /* Get some useful info on the input drawable */ /* ========================================== */ input_drawable = drawable; output_drawable = drawable; gimp_drawable_mask_bounds (drawable->drawable_id, &border_x1, &border_y1, &border_x2, &border_y2); width = input_drawable->width; height = input_drawable->height; gimp_pixel_rgn_init (&source_region, input_drawable, 0, 0, width, height, FALSE, FALSE); maxcounter = (glong) width * (glong) height; if (mapvals.transparent_background == TRUE) { gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0); } else { gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 1.0); } /* Assume at least RGB */ /* =================== */ in_channels = 3; if (gimp_drawable_has_alpha (input_drawable->drawable_id) == TRUE) in_channels++; if (interactive == TRUE) { preview_rgb_data = g_new0 (guchar, PREVIEW_HEIGHT * PREVIEW_WIDTH * 3); } return TRUE; }
static void alpha_scale_cb (GtkAdjustment *adj, gpointer data) { GimpColorButton *color_button; GimpRGB color; if (!data) return; color_button = GIMP_COLOR_BUTTON (data); gimp_color_button_get_color (GIMP_COLOR_BUTTON (color_button), &color); gimp_rgb_set_alpha (&color, adj->value); gimp_color_button_set_color (GIMP_COLOR_BUTTON (color_button), &color); }
static void svg_parse_gradient_stop_style_prop (SvgStop *stop, const gchar *name, const gchar *value) { if (strcmp (name, "stop-color") == 0) { gimp_rgb_parse_css (&stop->color, value, -1); } else if (strcmp (name, "stop-opacity") == 0) { gdouble opacity = g_ascii_strtod (value, NULL); if (errno != ERANGE) gimp_rgb_set_alpha (&stop->color, CLAMP (opacity, 0.0, 1.0)); } }
static void lens_distort_preview (GimpDrawable *drawable, GimpPreview *preview) { guchar *dest; guchar *pixel; gint width, height, bpp; gint x, y; GimpPixelFetcher *pft; GimpRGB background; pft = gimp_pixel_fetcher_new (drawable, FALSE); gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 0.0); gimp_pixel_fetcher_set_bg_color (pft, &background); gimp_pixel_fetcher_set_edge_mode (pft, GIMP_PIXEL_FETCHER_EDGE_BACKGROUND); lens_setup_calc (drawable->width, drawable->height); dest = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview), &width, &height, &bpp); pixel = dest; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { gint sx, sy; gimp_preview_untransform (preview, x, y, &sx, &sy); lens_distort_func (sx, sy, pixel, bpp, pft); pixel += bpp; } } gimp_pixel_fetcher_destroy (pft); gimp_preview_draw_buffer (preview, dest, width * bpp); g_free (dest); }
static void polarize (GimpDrawable *drawable) { GimpRgnIterator *iter; GimpPixelFetcher *pft; GimpRGB background; pft = gimp_pixel_fetcher_new (drawable, FALSE); gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 0.0); gimp_pixel_fetcher_set_bg_color (pft, &background); gimp_pixel_fetcher_set_edge_mode (pft, GIMP_PIXEL_FETCHER_EDGE_SMEAR); gimp_progress_init (_("Polar coordinates")); iter = gimp_rgn_iterator_new (drawable, 0); gimp_rgn_iterator_dest (iter, polarize_func, pft); gimp_rgn_iterator_free (iter); gimp_pixel_fetcher_destroy (pft); }
static SvgStop * svg_parse_gradient_stop (const gchar **names, const gchar **values) { SvgStop *stop = g_slice_new0 (SvgStop); gimp_rgb_set_alpha (&stop->color, 1.0); while (*names && *values) { if (strcmp (*names, "offset") == 0) { gchar *end; stop->offset = g_ascii_strtod (*values, &end); if (end && *end == '%') stop->offset /= 100.0; stop->offset = CLAMP (stop->offset, 0.0, 1.0); } else if (strcmp (*names, "style") == 0) { svg_parse_gradient_stop_style (stop, *values); } else { svg_parse_gradient_stop_style_prop (stop, *names, *values); } names++; values++; } return stop; }
static void lens_distort (GimpDrawable *drawable) { GimpRgnIterator *iter; GimpPixelFetcher *pft; GimpRGB background; lens_setup_calc (drawable->width, drawable->height); pft = gimp_pixel_fetcher_new (drawable, FALSE); gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 0.0); gimp_pixel_fetcher_set_bg_color (pft, &background); gimp_pixel_fetcher_set_edge_mode (pft, GIMP_PIXEL_FETCHER_EDGE_BACKGROUND); gimp_progress_init (_("Lens distortion")); iter = gimp_rgn_iterator_new (drawable, 0); gimp_rgn_iterator_dest (iter, (GimpRgnFuncDest) lens_distort_func, pft); gimp_rgn_iterator_free (iter); gimp_pixel_fetcher_destroy (pft); }
/* ----------------------------------------------- * gap_morph_shape_generate_frame_tween_workpoints * ----------------------------------------------- * generate workpoint files (one per frame) * for the specified frame range. * */ gint32 gap_morph_shape_generate_frame_tween_workpoints(GapAnimInfo *ainfo_ptr , GapMorphGlobalParams *mgpp, GtkWidget *masterProgressBar, GtkWidget *progressBar, gboolean *cancelFlagPtr) { GapMorphGUIParams morph_gui_params; GapMorphGUIParams *mgup; gint32 frameCount; gint32 currFrameNr; gint32 nextFrameNr; gint32 currLayerId; gint32 nextLayerId; gint32 firstFrameNr; gint32 lastFrameNr; gdouble framesToProcess; mgup = &morph_gui_params; mgup->mgpp = mgpp; mgup->src_win.zoom = 1.0; /* no zoom available here (use full drawable size for workpoint generation */ mgup->cancelWorkpointGeneration = FALSE; mgup->progressBar = progressBar; mgpp->master_wp_list = NULL; gimp_rgb_set(&mgup->pointcolor, 0.1, 1.0, 0.1); /* startup with GREEN pointcolor */ gimp_rgb_set_alpha(&mgup->pointcolor, 1.0); gimp_rgb_set(&mgup->curr_pointcolor, 1.0, 1.0, 0.1); /* startup with YELLOW color */ gimp_rgb_set_alpha(&mgup->curr_pointcolor, 1.0); frameCount = 0; nextLayerId = -1; if(gap_lib_chk_framerange(ainfo_ptr) != 0) { return(0); } firstFrameNr = CLAMP(mgpp->range_from, ainfo_ptr->first_frame_nr, ainfo_ptr->last_frame_nr); currFrameNr = firstFrameNr; currLayerId = p_getMergedFrameImageLayer(ainfo_ptr, currFrameNr); nextFrameNr = currFrameNr + 1; while(TRUE) { lastFrameNr = MIN(mgpp->range_to, ainfo_ptr->last_frame_nr); framesToProcess = MAX(1, (lastFrameNr - currFrameNr) -1); if (nextFrameNr > lastFrameNr) { break; } nextLayerId = p_getMergedFrameImageLayer(ainfo_ptr, nextFrameNr); if((nextLayerId >= 0) && (currLayerId >= 0)) { char *workpointFileName; gboolean success; workpointFileName = gap_lib_alloc_fname(ainfo_ptr->basename, currFrameNr, "." GAP_MORPH_WORKPOINT_EXTENSION); p_do_master_progress(masterProgressBar , workpointFileName , framesToProcess , (currFrameNr - firstFrameNr) ); success = p_generateWorkpointFileForFramePair(workpointFileName , mgup , cancelFlagPtr , currLayerId , nextLayerId ); g_free(workpointFileName); gap_image_delete_immediate(gimp_drawable_get_image(currLayerId)); if(!success) { break; } currFrameNr = nextFrameNr; currLayerId = nextLayerId; } nextFrameNr++; } if(nextLayerId >= 0) { gap_image_delete_immediate(gimp_drawable_get_image(nextLayerId)); } return (frameCount); } /* end gap_morph_shape_generate_frame_tween_workpoints */
static void dialog_update_preview (GimpDrawable *drawable, GimpPreview *preview) { gdouble cx, cy; gint x, y; gint sx, sy; gint width, height; guchar *pixel; guchar outside[4]; GimpRGB background; guchar *dest; gint j; gint bpp; GimpPixelFetcher *pft; guchar in_pixels[4][4]; guchar *in_values[4]; for (j = 0; j < 4; j++) in_values[j] = in_pixels[j]; pft = gimp_pixel_fetcher_new (drawable, FALSE); gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 0.0); gimp_drawable_get_color_uchar (drawable->drawable_id, &background, outside); gimp_pixel_fetcher_set_bg_color (pft, &background); gimp_pixel_fetcher_set_edge_mode (pft, GIMP_PIXEL_FETCHER_EDGE_SMEAR); dest = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview), &width, &height, &bpp); pixel = dest; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { gimp_preview_untransform (preview, x, y, &sx, &sy); if (calc_undistorted_coords ((gdouble)sx, (gdouble)sy, &cx, &cy)) { gimp_pixel_fetcher_get_pixel (pft, cx, cy, in_pixels[0]); gimp_pixel_fetcher_get_pixel (pft, cx + 1, cy, in_pixels[1]); gimp_pixel_fetcher_get_pixel (pft, cx, cy + 1, in_pixels[2]); gimp_pixel_fetcher_get_pixel (pft, cx + 1, cy + 1, in_pixels[3]); gimp_bilinear_pixels_8 (pixel, cx, cy, bpp, img_has_alpha, in_values); } else { for (j = 0; j < bpp; j++) pixel[j] = outside[j]; } pixel += bpp; } } gimp_pixel_fetcher_destroy (pft); gimp_preview_draw_buffer (preview, dest, width * bpp); g_free (dest); }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpDrawable *drawable; GimpPDBStatusType status; GimpRunMode run_mode; gdouble xhsiz, yhsiz; GimpRGB background; status = GIMP_PDB_SUCCESS; run_mode = param[0].data.d_int32; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; *nreturn_vals = 1; *return_vals = values; INIT_I18N (); /* Get the active drawable info */ drawable = gimp_drawable_get (param[2].data.d_drawable); img_width = gimp_drawable_width (drawable->drawable_id); img_height = gimp_drawable_height (drawable->drawable_id); img_has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); gimp_drawable_mask_bounds (drawable->drawable_id, &sel_x1, &sel_y1, &sel_x2, &sel_y2); /* Calculate scaling parameters */ sel_width = sel_x2 - sel_x1; sel_height = sel_y2 - sel_y1; cen_x = (double) (sel_x1 + sel_x2 - 1) / 2.0; cen_y = (double) (sel_y1 + sel_y2 - 1) / 2.0; xhsiz = (double) (sel_width - 1) / 2.0; yhsiz = (double) (sel_height - 1) / 2.0; if (xhsiz < yhsiz) { scale_x = yhsiz / xhsiz; scale_y = 1.0; } else if (xhsiz > yhsiz) { scale_x = 1.0; scale_y = xhsiz / yhsiz; } else { scale_x = 1.0; scale_y = 1.0; } /* Get background color */ gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 0.0); gimp_drawable_get_color_uchar (drawable->drawable_id, &background, back_color); /* See how we will run */ switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &pcvals); /* Get information from the dialog */ if (! polarize_dialog (drawable)) return; break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are present */ if (nparams != 8) { status = GIMP_PDB_CALLING_ERROR; } else { pcvals.circle = param[3].data.d_float; pcvals.angle = param[4].data.d_float; pcvals.backwards = param[5].data.d_int32; pcvals.inverse = param[6].data.d_int32; pcvals.polrec = param[7].data.d_int32; } break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &pcvals); break; default: break; } /* Distort the image */ if ((status == GIMP_PDB_SUCCESS) && (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id))) { /* Set the tile cache size */ gimp_tile_cache_ntiles (2 * (drawable->width + gimp_tile_width() - 1) / gimp_tile_width ()); /* Run! */ polarize (drawable); /* If run mode is interactive, flush displays */ if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &pcvals, sizeof (polarize_vals_t)); } else if (status == GIMP_PDB_SUCCESS) status = GIMP_PDB_EXECUTION_ERROR; values[0].data.d_status = status; gimp_drawable_detach (drawable); }
void view_actions_update (GimpActionGroup *group, gpointer data) { GimpDisplay *display = action_data_get_display (data); GimpImage *image = NULL; GimpDisplayShell *shell = NULL; GimpDisplayOptions *options = NULL; gchar *label = NULL; gboolean fullscreen = FALSE; gboolean revert_enabled = FALSE; /* able to revert zoom? */ gboolean use_gegl = FALSE; if (display) { GimpImageWindow *window; image = gimp_display_get_image (display); shell = gimp_display_get_shell (display); window = gimp_display_shell_get_window (shell); if (window) fullscreen = gimp_image_window_get_fullscreen (window); options = (image ? (fullscreen ? shell->fullscreen_options : shell->options) : shell->no_image_options); revert_enabled = gimp_display_shell_scale_can_revert (shell); if (image) use_gegl = gimp_image_get_projection (image)->use_gegl; } #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_COLOR(action,color) \ gimp_action_group_set_action_color (group, action, color, FALSE) SET_SENSITIVE ("view-new", image); SET_SENSITIVE ("view-close", image); SET_SENSITIVE ("view-dot-for-dot", image); SET_ACTIVE ("view-dot-for-dot", display && shell->dot_for_dot); SET_SENSITIVE ("view-zoom-revert", revert_enabled); if (revert_enabled) { label = g_strdup_printf (_("Re_vert Zoom (%d%%)"), ROUND (shell->last_scale * 100)); gimp_action_group_set_action_label (group, "view-zoom-revert", label); g_free (label); } else { gimp_action_group_set_action_label (group, "view-zoom-revert", _("Re_vert Zoom")); } SET_SENSITIVE ("view-zoom-out", image); SET_SENSITIVE ("view-zoom-in", image); SET_SENSITIVE ("view-zoom-fit-in", image); SET_SENSITIVE ("view-zoom-fill", image); SET_SENSITIVE ("view-zoom-16-1", image); SET_SENSITIVE ("view-zoom-8-1", image); SET_SENSITIVE ("view-zoom-4-1", image); SET_SENSITIVE ("view-zoom-2-1", image); SET_SENSITIVE ("view-zoom-1-1", image); SET_SENSITIVE ("view-zoom-1-2", image); SET_SENSITIVE ("view-zoom-1-4", image); SET_SENSITIVE ("view-zoom-1-8", image); SET_SENSITIVE ("view-zoom-1-16", image); SET_SENSITIVE ("view-zoom-other", image); if (image) view_actions_set_zoom (group, shell); SET_SENSITIVE ("view-navigation-window", image); SET_SENSITIVE ("view-display-filters", image); SET_SENSITIVE ("view-show-selection", image); SET_ACTIVE ("view-show-selection", display && options->show_selection); SET_SENSITIVE ("view-show-layer-boundary", image); SET_ACTIVE ("view-show-layer-boundary", display && options->show_layer_boundary); SET_SENSITIVE ("view-show-guides", image); SET_ACTIVE ("view-show-guides", display && options->show_guides); SET_SENSITIVE ("view-show-grid", image); SET_ACTIVE ("view-show-grid", display && options->show_grid); SET_SENSITIVE ("view-show-sample-points", image); SET_ACTIVE ("view-show-sample-points", display && options->show_sample_points); SET_SENSITIVE ("view-snap-to-guides", image); SET_ACTIVE ("view-snap-to-guides", display && shell->snap_to_guides); SET_SENSITIVE ("view-snap-to-grid", image); SET_ACTIVE ("view-snap-to-grid", display && shell->snap_to_grid); SET_SENSITIVE ("view-snap-to-canvas", image); SET_ACTIVE ("view-snap-to-canvas", display && shell->snap_to_canvas); SET_SENSITIVE ("view-snap-to-vectors", image); SET_ACTIVE ("view-snap-to-vectors", display && shell->snap_to_vectors); SET_SENSITIVE ("view-padding-color-theme", image); SET_SENSITIVE ("view-padding-color-light-check", image); SET_SENSITIVE ("view-padding-color-dark-check", image); SET_SENSITIVE ("view-padding-color-custom", image); SET_SENSITIVE ("view-padding-color-prefs", image); if (display) { SET_COLOR ("view-padding-color-menu", &options->padding_color); if (shell->canvas) { GtkStyle *style = gtk_widget_get_style (shell->canvas); GimpRGB color; gtk_widget_ensure_style (shell->canvas); gimp_rgb_set_gdk_color (&color, style->bg + GTK_STATE_NORMAL); gimp_rgb_set_alpha (&color, GIMP_OPACITY_OPAQUE); SET_COLOR ("view-padding-color-theme", &color); } } SET_SENSITIVE ("view-show-menubar", image); SET_ACTIVE ("view-show-menubar", display && options->show_menubar); SET_SENSITIVE ("view-show-rulers", image); SET_ACTIVE ("view-show-rulers", display && options->show_rulers); SET_SENSITIVE ("view-show-scrollbars", image); SET_ACTIVE ("view-show-scrollbars", display && options->show_scrollbars); SET_SENSITIVE ("view-show-statusbar", image); SET_ACTIVE ("view-show-statusbar", display && options->show_statusbar); SET_SENSITIVE ("view-shrink-wrap", image); SET_SENSITIVE ("view-fullscreen", image); SET_ACTIVE ("view-fullscreen", display && fullscreen); SET_ACTIVE ("view-use-gegl", use_gegl); if (GIMP_IS_IMAGE_WINDOW (group->user_data) || GIMP_IS_GIMP (group->user_data)) { GtkWidget *window = NULL; if (shell) window = gtk_widget_get_toplevel (GTK_WIDGET (shell)); /* see view_actions_setup() */ if (GTK_IS_WINDOW (window)) window_actions_update (group, window); } #undef SET_ACTIVE #undef SET_SENSITIVE #undef SET_COLOR }
static void color_init (GimpRGB *rgb) { gimp_rgb_parse_name (rgb, "goldenrod", -1); gimp_rgb_set_alpha (rgb, 0.7); }
static void nova (GimpDrawable *drawable, GimpPreview *preview) { GimpPixelRgn src_rgn; GimpPixelRgn dest_rgn; gpointer pr; guchar *src_row, *dest_row, *save_src; guchar *src, *dest; gint x1, y1, x2, y2, x, y; gint row, col; gint alpha, bpp; gint progress, max_progress; gboolean has_alpha; gint xc, yc; /* center of nova */ gdouble u, v, l, w, w1, c, t; gdouble *spoke; gdouble nova_alpha, src_alpha, new_alpha = 0.0; gdouble compl_ratio, ratio; GimpRGB color; GimpRGB *spokecolor; GimpHSV hsv; gdouble spokecol; gint i; GRand *gr; guchar *cache = NULL; gint width, height; gdouble zoom = 0.0; gr = g_rand_new (); /* initialize */ has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); spoke = g_new (gdouble, pvals.nspoke); spokecolor = g_new (GimpRGB, pvals.nspoke); gimp_rgb_set_alpha (&pvals.color, 1.0); gimp_rgb_to_hsv (&pvals.color, &hsv); for (i = 0; i < pvals.nspoke; i++) { spoke[i] = gauss (gr); hsv.h += ((gdouble) pvals.randomhue / 360.0) * g_rand_double_range (gr, -0.5, 0.5); if (hsv.h < 0) hsv.h += 1.0; else if (hsv.h >= 1.0) hsv.h -= 1.0; gimp_hsv_to_rgb (&hsv, spokecolor + i); } if (preview) { cache = gimp_zoom_preview_get_source (GIMP_ZOOM_PREVIEW (preview), &width, &height, &bpp); zoom = gimp_zoom_preview_get_factor (GIMP_ZOOM_PREVIEW (preview)); gimp_preview_transform (preview, pvals.xcenter, pvals.ycenter, &xc, &yc); x1 = 0; y1 = 0; x2 = width; y2 = height; } else { gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); bpp = gimp_drawable_bpp (drawable->drawable_id); xc = pvals.xcenter; yc = pvals.ycenter; gimp_pixel_rgn_init (&src_rgn, drawable, x1, y1, x2-x1, y2-y1, FALSE, FALSE); gimp_pixel_rgn_init (&dest_rgn, drawable, x1, y1, x2-x1, y2-y1, TRUE, TRUE); } alpha = (has_alpha) ? bpp - 1 : bpp; /* Initialize progress */ progress = 0; max_progress = (x2 - x1) * (y2 - y1); if (preview) { save_src = src_row = g_new (guchar, y2 * width * bpp); memcpy (src_row, cache, y2 * width * bpp); dest_row = g_new (guchar, y2 * width * bpp); dest = dest_row; src = src_row; for (row = 0, y = 0; row < y2; row++, y++) { for (col = 0, x = 0; col < x2; col++, x++) { u = ((gdouble) (x - xc) / ((gdouble) pvals.radius * width / drawable->width * zoom)); v = ((gdouble) (y - yc) / ((gdouble) pvals.radius * height / drawable->height * zoom)); l = sqrt (SQR (u) + SQR (v)); /* This algorithm is still under construction. */ t = (atan2 (u, v) / (2 * G_PI) + .51) * pvals.nspoke; i = (gint) floor (t); t -= i; i %= pvals.nspoke; w1 = spoke[i] * (1 - t) + spoke[(i + 1) % pvals.nspoke] * t; w1 = w1 * w1; w = 1.0 / (l + 0.001) * 0.9; nova_alpha = CLAMP (w, 0.0, 1.0); if (has_alpha) { src_alpha = (gdouble) src[alpha] / 255.0; new_alpha = src_alpha + (1.0 - src_alpha) * nova_alpha; if (new_alpha != 0.0) ratio = nova_alpha / new_alpha; else ratio = 0.0; } else ratio = nova_alpha; compl_ratio = 1.0 - ratio; /* red or gray */ spokecol = (gdouble)spokecolor[i ].r * (1.0-t) + (gdouble)spokecolor[(i+1) % pvals.nspoke].r * t; if (w>1.0) color.r = CLAMP (spokecol * w, 0.0, 1.0); else color.r = src[0]/255.0 * compl_ratio + spokecol * ratio; c = CLAMP (w1 * w, 0.0, 1.0); color.r += c; dest[0] = CLAMP (color.r*255.0, 0, 255); if (bpp>2) { /* green */ spokecol = (gdouble)spokecolor[i ].g * (1.0-t) + (gdouble)spokecolor[(i+1) % pvals.nspoke].g * t; if (w>1.0) color.g = CLAMP (spokecol * w, 0.0, 1.0); else color.g = src[1]/255.0 * compl_ratio + spokecol * ratio; c = CLAMP (w1 * w, 0.0, 1.0); color.g += c; dest[1] = CLAMP (color.g*255.0, 0, 255); /* blue */ spokecol = (gdouble)spokecolor[i ].b * (1.0-t) + (gdouble)spokecolor[(i+1) % pvals.nspoke].b * t; if (w>1.0) color.b = CLAMP (spokecol * w, 0.0, 1.0); else color.b = src[2]/255.0 * compl_ratio + spokecol * ratio; c = CLAMP (w1 * w, 0.0, 1.0); color.b += c; dest[2] = CLAMP (color.b*255.0, 0, 255); } /* alpha */ if (has_alpha) dest[alpha] = new_alpha * 255.0; src += bpp; dest += bpp; } } gimp_preview_draw_buffer (preview, dest_row, bpp * width); g_free (cache); g_free (save_src); g_free (dest_row); } else { /* normal mode */ for (pr = gimp_pixel_rgns_register (2, &src_rgn, &dest_rgn); pr != NULL ; pr = gimp_pixel_rgns_process (pr)) { src_row = src_rgn.data; dest_row = dest_rgn.data; for (row = 0, y = src_rgn.y; row < src_rgn.h; row++, y++) { src = src_row; dest = dest_row; for (col = 0, x = src_rgn.x; col < src_rgn.w; col++, x++) { u = (gdouble) (x-xc) / pvals.radius; v = (gdouble) (y-yc) / pvals.radius; l = sqrt(u*u + v*v); /* This algorithm is still under construction. */ t = (atan2 (u, v) / (2 * G_PI) + .51) * pvals.nspoke; i = (gint) floor (t); t -= i; i %= pvals.nspoke; w1 = spoke[i] * (1 - t) + spoke[(i + 1) % pvals.nspoke] * t; w1 = w1 * w1; w = 1/(l+0.001)*0.9; nova_alpha = CLAMP (w, 0.0, 1.0); if (has_alpha) { src_alpha = (gdouble) src[alpha] / 255.0; new_alpha = src_alpha + (1.0 - src_alpha) * nova_alpha; if (new_alpha != 0.0) ratio = nova_alpha / new_alpha; else ratio = 0.0; } else ratio = nova_alpha; compl_ratio = 1.0 - ratio; switch (bpp) { case 1: case 2: /* gray */ spokecol = (gdouble)spokecolor[i ].r * (1.0-t) + (gdouble)spokecolor[(i+1) % pvals.nspoke].r * t; if (w>1.0) color.r = CLAMP (spokecol * w, 0.0, 1.0); else color.r = src[0]/255.0 * compl_ratio + spokecol * ratio; c = CLAMP (w1 * w, 0.0, 1.0); color.r += c; dest[0] = CLAMP (color.r*255.0, 0, 255); break; case 3: case 4: /* red */ spokecol = (gdouble)spokecolor[i ].r * (1.0-t) + (gdouble)spokecolor[(i+1) % pvals.nspoke].r * t; if (w>1.0) color.r = CLAMP (spokecol * w, 0.0, 1.0); else color.r = src[0]/255.0 * compl_ratio + spokecol * ratio; c = CLAMP (w1 * w, 0.0, 1.0); color.r += c; dest[0] = CLAMP (color.r*255.0, 0, 255); /* green */ spokecol = (gdouble)spokecolor[i ].g * (1.0-t) + (gdouble)spokecolor[(i+1) % pvals.nspoke].g * t; if (w>1.0) color.g = CLAMP (spokecol * w, 0.0, 1.0); else color.g = src[1]/255.0 * compl_ratio + spokecol * ratio; c = CLAMP (w1 * w, 0.0, 1.0); color.g += c; dest[1] = CLAMP (color.g*255.0, 0, 255); /* blue */ spokecol = (gdouble)spokecolor[i ].b * (1.0-t) + (gdouble)spokecolor[(i+1) % pvals.nspoke].b * t; if (w>1.0) color.b = CLAMP (spokecol * w, 0.0, 1.0); else color.b = src[2]/255.0 * compl_ratio + spokecol * ratio; c = CLAMP (w1 * w, 0.0, 1.0); color.b += c; dest[2] = CLAMP (color.b*255.0, 0, 255); break; } if (has_alpha) dest[alpha] = new_alpha * 255.0; src += src_rgn.bpp; dest += dest_rgn.bpp; } src_row += src_rgn.rowstride; dest_row += dest_rgn.rowstride; } /* Update progress */ progress += src_rgn.w * src_rgn.h; gimp_progress_update ((gdouble) progress / (gdouble) max_progress); } gimp_progress_update (1.0); gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable->drawable_id, TRUE); gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1)); } g_free (spoke); g_free (spokecolor); g_rand_free (gr); }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; run_mode = param[0].data.d_int32; *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; INIT_I18N (); switch (run_mode) { case GIMP_RUN_INTERACTIVE: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &svals); /* In order to prepare the dialog I need to know wether it's grayscale or not */ drawable = gimp_drawable_get (param[2].data.d_drawable); thePreview = mw_preview_build_virgin(drawable); drawable_is_grayscale = gimp_drawable_is_gray (drawable->drawable_id); if (! sinus_dialog ()) return; break; case GIMP_RUN_NONINTERACTIVE: /* Make sure all the arguments are there! */ if (nparams != 17) { status = GIMP_PDB_CALLING_ERROR; } else { svals.scalex = param[3].data.d_float; svals.scaley = param[4].data.d_float; svals.cmplx = param[5].data.d_float; svals.seed = param[6].data.d_int32; svals.tiling = param[7].data.d_int32; svals.perturbation = param[8].data.d_int32; svals.colors = param[9].data.d_int32; svals.col1 = param[10].data.d_color; svals.col2 = param[11].data.d_color; gimp_rgb_set_alpha (&svals.col1, param[12].data.d_float); gimp_rgb_set_alpha (&svals.col2, param[13].data.d_float); svals.colorization = param[14].data.d_int32; svals.blend_power = param[15].data.d_float; if (svals.random_seed) svals.seed = g_random_int (); } break; case GIMP_RUN_WITH_LAST_VALS: /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &svals); if (svals.random_seed) svals.seed = g_random_int (); break; default: break; } /* Get the specified drawable */ drawable = gimp_drawable_get (param[2].data.d_drawable); /* Make sure that the drawable is gray or RGB */ if ((status == GIMP_PDB_SUCCESS) && (gimp_drawable_is_rgb (drawable->drawable_id) || gimp_drawable_is_gray (drawable->drawable_id))) { gimp_progress_init (_("Sinus: rendering")); gimp_tile_cache_ntiles (1); sinus (); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); /* Store data */ if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &svals, sizeof (SinusVals)); } else { status = GIMP_PDB_EXECUTION_ERROR; } values[0].data.d_status = status; gimp_drawable_detach (drawable); }
GimpRGB get_ray_color_no_bilinear (GimpVector3 *position) { GimpRGB color; GimpRGB color_int; GimpRGB color_sum; GimpRGB light_color; gint x; gdouble xf, yf; GimpVector3 normal, *p; gint k; pos_to_float (position->x, position->y, &xf, &yf); x = RINT (xf); if (mapvals.transparent_background && heights[1][x] == 0) { gimp_rgb_set_alpha (&color_sum, 0.0); } else { color = peek (x, RINT (yf)); color_sum = color; gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); for (k = 0; k < NUM_LIGHTS; k++) { p = &mapvals.lightsource[k].direction; if (!mapvals.lightsource[k].active || mapvals.lightsource[k].type == NO_LIGHT) continue; else if (mapvals.lightsource[k].type == POINT_LIGHT) p = &mapvals.lightsource[k].position; color_int = mapvals.lightsource[k].color; gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1) { light_color = phong_shade (position, &mapvals.viewpoint, &mapvals.planenormal, p, &color, &color_int, mapvals.lightsource[k].type); } else { normal = vertex_normals[1][x]; light_color = phong_shade (position, &mapvals.viewpoint, &normal, p, &color, &color_int, mapvals.lightsource[k].type); } gimp_rgb_add (&color_sum, &light_color); } } gimp_rgb_clamp (&color_sum); return color_sum; }
static void run (const gchar *name, gint n_params, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpDrawable *drawable; gint32 image_ID; GimpRunMode run_mode; GimpPDBStatusType status = GIMP_PDB_SUCCESS; *nreturn_vals = 1; *return_vals = values; INIT_I18N (); run_mode = param[0].data.d_int32; image_ID = param[1].data.d_int32; drawable = gimp_drawable_get (param[2].data.d_drawable); if (run_mode == GIMP_RUN_NONINTERACTIVE) { if (n_params != 18) status = GIMP_PDB_CALLING_ERROR; if (status == GIMP_PDB_SUCCESS) { grid_cfg.hwidth = MAX (0, param[3].data.d_int32); grid_cfg.hspace = MAX (1, param[4].data.d_int32); grid_cfg.hoffset = MAX (0, param[5].data.d_int32); grid_cfg.hcolor = param[6].data.d_color; gimp_rgb_set_alpha (&(grid_cfg.hcolor), ((double) param[7].data.d_int8) / 255.0); grid_cfg.vwidth = MAX (0, param[8].data.d_int32); grid_cfg.vspace = MAX (1, param[9].data.d_int32); grid_cfg.voffset = MAX (0, param[10].data.d_int32); grid_cfg.vcolor = param[11].data.d_color; gimp_rgb_set_alpha (&(grid_cfg.vcolor), ((double) param[12].data.d_int8) / 255.0); grid_cfg.iwidth = MAX (0, param[13].data.d_int32); grid_cfg.ispace = MAX (0, param[14].data.d_int32); grid_cfg.ioffset = MAX (0, param[15].data.d_int32); grid_cfg.icolor = param[16].data.d_color; gimp_rgb_set_alpha (&(grid_cfg.icolor), ((double) (guint) param[17].data.d_int8) / 255.0); } } else { gimp_context_get_foreground (&grid_cfg.hcolor); grid_cfg.vcolor = grid_cfg.icolor = grid_cfg.hcolor; /* Possibly retrieve data */ gimp_get_data (PLUG_IN_PROC, &grid_cfg); } if (run_mode == GIMP_RUN_INTERACTIVE) { if (!dialog (image_ID, drawable)) { /* The dialog was closed, or something similarly evil happened. */ status = GIMP_PDB_EXECUTION_ERROR; } } if (grid_cfg.hspace <= 0 || grid_cfg.vspace <= 0) { status = GIMP_PDB_EXECUTION_ERROR; } if (status == GIMP_PDB_SUCCESS) { gimp_progress_init (_("Drawing grid")); gimp_tile_cache_ntiles (2 * (drawable->width / gimp_tile_width () + 1)); grid (image_ID, drawable, NULL); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &grid_cfg, sizeof (grid_cfg)); gimp_drawable_detach (drawable); } values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; }
void compute_preview (gint x, gint y, gint w, gint h, gint pw, gint ph) { gdouble xpostab[PREVIEW_WIDTH]; gdouble ypostab[PREVIEW_HEIGHT]; gdouble realw; gdouble realh; GimpVector3 p1, p2; GimpRGB color; GimpRGB lightcheck, darkcheck; gint xcnt, ycnt, f1, f2; glong index = 0; init_compute (); p1 = int_to_pos (x, y); p2 = int_to_pos (x + w, y + h); /* First, compute the linear mapping (x,y,x+w,y+h) to (0,0,pw,ph) */ /* ============================================================== */ realw = (p2.x - p1.x); realh = (p2.y - p1.y); for (xcnt = 0; xcnt < pw; xcnt++) xpostab[xcnt] = p1.x + realw * ((gdouble) xcnt / (gdouble) pw); for (ycnt = 0; ycnt < ph; ycnt++) ypostab[ycnt] = p1.y + realh * ((gdouble) ycnt / (gdouble) ph); /* Compute preview using the offset tables */ /* ======================================= */ if (mapvals.transparent_background == TRUE) { gimp_rgba_set (&background, 0.0, 0.0, 0.0, 0.0); } else { gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 1.0); } gimp_rgba_set (&lightcheck, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, 1.0); gimp_rgba_set (&darkcheck, GIMP_CHECK_DARK, GIMP_CHECK_DARK, GIMP_CHECK_DARK, 1.0); gimp_vector3_set (&p2, -1.0, -1.0, 0.0); for (ycnt = 0; ycnt < ph; ycnt++) { for (xcnt = 0; xcnt < pw; xcnt++) { p1.x = xpostab[xcnt]; p1.y = ypostab[ycnt]; p2 = p1; color = (* get_ray_color) (&p1); if (color.a < 1.0) { f1 = ((xcnt % 32) < 16); f2 = ((ycnt % 32) < 16); f1 = f1 ^ f2; if (f1) { if (color.a == 0.0) color = lightcheck; else gimp_rgb_composite (&color, &lightcheck, GIMP_RGB_COMPOSITE_BEHIND); } else { if (color.a == 0.0) color = darkcheck; else gimp_rgb_composite (&color, &darkcheck, GIMP_RGB_COMPOSITE_BEHIND); } } gimp_rgb_get_uchar (&color, preview_rgb_data + index, preview_rgb_data + index + 1, preview_rgb_data + index + 2); index += 3; } } }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpDrawable *drawable; GimpRGB background; GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpRunMode run_mode; run_mode = param[0].data.d_int32; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; INIT_I18N (); drawable = gimp_drawable_get (param[2].data.d_drawable); drawable_width = drawable->width; drawable_height = drawable->height; /* Get background color */ gimp_context_get_background (&background); gimp_rgb_set_alpha (&background, 0.0); gimp_drawable_get_color_uchar (drawable->drawable_id, &background, background_color); /* Set the tile cache size */ gimp_tile_cache_ntiles (2 * MAX (drawable->ntile_rows, drawable->ntile_cols)); *nreturn_vals = 1; *return_vals = values; switch (run_mode) { case GIMP_RUN_INTERACTIVE: gimp_get_data (PLUG_IN_PROC, &vals); if (! lens_dialog (drawable)) return; break; case GIMP_RUN_NONINTERACTIVE: if (nparams != 9) status = GIMP_PDB_CALLING_ERROR; if (status == GIMP_PDB_SUCCESS) { vals.centre_x = param[3].data.d_float; vals.centre_y = param[4].data.d_float; vals.square_a = param[5].data.d_float; vals.quad_a = param[6].data.d_float; vals.scale_a = param[7].data.d_float; vals.brighten = param[8].data.d_float; } break; case GIMP_RUN_WITH_LAST_VALS: gimp_get_data (PLUG_IN_PROC, &vals); break; default: break; } if ( status == GIMP_PDB_SUCCESS ) { lens_distort (drawable); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); if (run_mode == GIMP_RUN_INTERACTIVE) gimp_set_data (PLUG_IN_PROC, &vals, sizeof (LensValues)); gimp_drawable_detach (drawable); } values[0].data.d_status = status; }
void _gimp_paintbrush_motion (GimpPaintCore *paint_core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords, gdouble opacity) { GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_core); GimpContext *context = GIMP_CONTEXT (paint_options); GimpDynamics *dynamics = brush_core->dynamics; GimpImage *image; GimpRGB gradient_color; GeglBuffer *paint_buffer; gint paint_buffer_x; gint paint_buffer_y; GimpPaintApplicationMode paint_appl_mode; gdouble fade_point; gdouble grad_point; gdouble force; gdouble dyn_force; GimpDynamicsOutput *dyn_output = NULL; image = gimp_item_get_image (GIMP_ITEM (drawable)); fade_point = gimp_paint_options_get_fade (paint_options, image, paint_core->pixel_dist); opacity *= gimp_dynamics_get_linear_value (dynamics, GIMP_DYNAMICS_OUTPUT_OPACITY, coords, paint_options, fade_point); if (opacity == 0.0) return; paint_buffer = gimp_paint_core_get_paint_buffer (paint_core, drawable, paint_options, coords, &paint_buffer_x, &paint_buffer_y); if (! paint_buffer) return; paint_appl_mode = paint_options->application_mode; grad_point = gimp_dynamics_get_linear_value (dynamics, GIMP_DYNAMICS_OUTPUT_COLOR, coords, paint_options, fade_point); if (gimp_paint_options_get_gradient_color (paint_options, image, grad_point, paint_core->pixel_dist, &gradient_color)) { /* optionally take the color from the current gradient */ GeglColor *color; opacity *= gradient_color.a; gimp_rgb_set_alpha (&gradient_color, GIMP_OPACITY_OPAQUE); color = gimp_gegl_color_new (&gradient_color); gegl_buffer_set_color (paint_buffer, NULL, color); g_object_unref (color); paint_appl_mode = GIMP_PAINT_INCREMENTAL; } else if (brush_core->brush && gimp_brush_get_pixmap (brush_core->brush)) { /* otherwise check if the brush has a pixmap and use that to * color the area */ gimp_brush_core_color_area_with_pixmap (brush_core, drawable, coords, paint_buffer, paint_buffer_x, paint_buffer_y, gimp_paint_options_get_brush_mode (paint_options)); paint_appl_mode = GIMP_PAINT_INCREMENTAL; } else { /* otherwise fill the area with the foreground color */ GimpRGB foreground; GeglColor *color; gimp_context_get_foreground (context, &foreground); color = gimp_gegl_color_new (&foreground); gegl_buffer_set_color (paint_buffer, NULL, color); g_object_unref (color); } dyn_output = gimp_dynamics_get_output (dynamics, GIMP_DYNAMICS_OUTPUT_FORCE); dyn_force = gimp_dynamics_get_linear_value (dynamics, GIMP_DYNAMICS_OUTPUT_FORCE, coords, paint_options, fade_point); if (gimp_dynamics_output_is_enabled (dyn_output)) force = dyn_force; else force = paint_options->brush_force; /* finally, let the brush core paste the colored area on the canvas */ gimp_brush_core_paste_canvas (brush_core, drawable, coords, MIN (opacity, GIMP_OPACITY_OPAQUE), gimp_context_get_opacity (context), gimp_context_get_paint_mode (context), gimp_paint_options_get_brush_mode (paint_options), force, paint_appl_mode); }
GimpRGB get_ray_color_no_bilinear_ref (GimpVector3 *position) { GimpRGB color_sum; GimpRGB color_int; GimpRGB light_color; GimpRGB color, env_color; gint x; gdouble xf, yf; GimpVector3 normal, *p, v, r; gint k; gdouble tmpval; pos_to_float (position->x, position->y, &xf, &yf); x = RINT (xf); if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1) normal = mapvals.planenormal; else normal = vertex_normals[1][(gint) RINT (xf)]; gimp_vector3_normalize (&normal); if (mapvals.transparent_background && heights[1][x] == 0) { gimp_rgb_set_alpha (&color_sum, 0.0); } else { color = peek (RINT (xf), RINT (yf)); color_sum = color; gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); for (k = 0; k < NUM_LIGHTS; k++) { p = &mapvals.lightsource[k].direction; if (!mapvals.lightsource[k].active || mapvals.lightsource[k].type == NO_LIGHT) continue; else if (mapvals.lightsource[k].type == POINT_LIGHT) p = &mapvals.lightsource[k].position; color_int = mapvals.lightsource[k].color; gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); light_color = phong_shade (position, &mapvals.viewpoint, &normal, p, &color, &color_int, mapvals.lightsource[0].type); } gimp_vector3_sub (&v, &mapvals.viewpoint, position); gimp_vector3_normalize (&v); r = compute_reflected_ray (&normal, &v); /* Get color in the direction of r */ /* =============================== */ sphere_to_image (&r, &xf, &yf); env_color = peek_env_map (RINT (env_width * xf), RINT (env_height * yf)); tmpval = mapvals.material.diffuse_int; mapvals.material.diffuse_int = 0.; light_color = phong_shade (position, &mapvals.viewpoint, &normal, &r, &color, &env_color, DIRECTIONAL_LIGHT); mapvals.material.diffuse_int = tmpval; gimp_rgb_add (&color_sum, &light_color); } gimp_rgb_clamp (&color_sum); return color_sum; }
GimpRGB get_ray_color_box (GimpVector3 *pos) { GimpVector3 lvp, ldir, vp, p, dir, ns, nn; GimpRGB color, color2; gfloat m[16]; gint i; FaceIntersectInfo face_intersect[2]; color = background; vp = mapvals.viewpoint; p = *pos; /* Translate viewpoint so that the box has its origin */ /* at its lower left corner. */ /* ================================================== */ vp.x = vp.x - mapvals.position.x; vp.y = vp.y - mapvals.position.y; vp.z = vp.z - mapvals.position.z; p.x = p.x - mapvals.position.x; p.y = p.y - mapvals.position.y; p.z = p.z - mapvals.position.z; /* Compute direction */ /* ================= */ gimp_vector3_sub (&dir, &p, &vp); gimp_vector3_normalize (&dir); /* Compute inverse of rotation matrix and apply it to */ /* the viewpoint and direction. This transforms the */ /* observer into the local coordinate system of the box */ /* ==================================================== */ memcpy (m, rotmat, sizeof (gfloat) * 16); transpose_mat (m); vecmulmat (&lvp, &vp, m); vecmulmat (&ldir, &dir, m); /* Ok. Now the observer is in the space where the box is located */ /* with its lower left corner at the origin and its axis aligned */ /* to the cartesian basis. Check if the transformed ray hits it. */ /* ============================================================= */ face_intersect[0].t = 1000000.0; face_intersect[1].t = 1000000.0; if (intersect_box (mapvals.scale, lvp, ldir, face_intersect) == TRUE) { /* We've hit the box. Transform the hit points and */ /* normals back into the world coordinate system */ /* =============================================== */ for (i = 0; i < 2; i++) { vecmulmat (&ns, &face_intersect[i].s, rotmat); vecmulmat (&nn, &face_intersect[i].n, rotmat); ns.x = ns.x + mapvals.position.x; ns.y = ns.y + mapvals.position.y; ns.z = ns.z + mapvals.position.z; face_intersect[i].s = ns; face_intersect[i].n = nn; } color = get_box_image_color (face_intersect[0].face, face_intersect[0].u, face_intersect[0].v); /* Check for total transparency... */ /* =============================== */ if (color.a < 1.0) { /* Hey, we can see through here! */ /* Lets see what's on the other side.. */ /* =================================== */ color = phong_shade (&face_intersect[0].s, &mapvals.viewpoint, &face_intersect[0].n, &mapvals.lightsource.position, &color, &mapvals.lightsource.color, mapvals.lightsource.type); gimp_rgb_clamp (&color); color2 = get_box_image_color (face_intersect[1].face, face_intersect[1].u, face_intersect[1].v); /* Make the normal point inwards */ /* ============================= */ gimp_vector3_mul (&face_intersect[1].n, -1.0); color2 = phong_shade (&face_intersect[1].s, &mapvals.viewpoint, &face_intersect[1].n, &mapvals.lightsource.position, &color2, &mapvals.lightsource.color, mapvals.lightsource.type); gimp_rgb_clamp (&color2); if (mapvals.transparent_background == FALSE && color2.a < 1.0) { gimp_rgb_composite (&color2, &background, GIMP_RGB_COMPOSITE_BEHIND); } /* Compute a mix of the first and second colors */ /* ============================================ */ gimp_rgb_composite (&color, &color2, GIMP_RGB_COMPOSITE_NORMAL); gimp_rgb_clamp (&color); } else if (color.a != 0.0 && mapvals.lightsource.type != NO_LIGHT) { color = phong_shade (&face_intersect[0].s, &mapvals.viewpoint, &face_intersect[0].n, &mapvals.lightsource.position, &color, &mapvals.lightsource.color, mapvals.lightsource.type); gimp_rgb_clamp (&color); } } else { if (mapvals.transparent_background == TRUE) gimp_rgb_set_alpha (&color, 0.0); } return color; }
void view_actions_update (GimpActionGroup *group, gpointer data) { GimpDisplay *display = action_data_get_display (data); GimpImage *image = NULL; GimpDisplayShell *shell = NULL; GimpDisplayOptions *options = NULL; GimpColorConfig *color_config = NULL; gchar *label = NULL; gboolean fullscreen = FALSE; gboolean revert_enabled = FALSE; /* able to revert zoom? */ gboolean flip_horizontally = FALSE; gboolean flip_vertically = FALSE; gboolean cm = FALSE; gboolean sp = FALSE; if (display) { GimpImageWindow *window; GimpColorRenderingIntent intent = GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL; gboolean bpc = TRUE; const gchar *action = NULL; image = gimp_display_get_image (display); shell = gimp_display_get_shell (display); window = gimp_display_shell_get_window (shell); if (window) fullscreen = gimp_image_window_get_fullscreen (window); options = (image ? (fullscreen ? shell->fullscreen_options : shell->options) : shell->no_image_options); revert_enabled = gimp_display_shell_scale_can_revert (shell); flip_horizontally = shell->flip_horizontally; flip_vertically = shell->flip_vertically; color_config = gimp_display_shell_get_color_config (shell); switch (color_config->mode) { case GIMP_COLOR_MANAGEMENT_OFF: action = "view-color-management-mode-off"; break; case GIMP_COLOR_MANAGEMENT_DISPLAY: action = "view-color-management-mode-display"; intent = color_config->display_intent; bpc = color_config->display_use_black_point_compensation; cm = TRUE; break; case GIMP_COLOR_MANAGEMENT_SOFTPROOF: action = "view-color-management-mode-softproof"; intent = color_config->simulation_intent; bpc = color_config->simulation_use_black_point_compensation; cm = TRUE; sp = TRUE; break; } gimp_action_group_set_action_active (group, action, TRUE); switch (intent) { case GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL: action = "view-color-management-intent-perceptual"; break; case GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC: action = "view-color-management-intent-relative-colorimetric"; break; case GIMP_COLOR_RENDERING_INTENT_SATURATION: action = "view-color-management-intent-saturation"; break; case GIMP_COLOR_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC: action = "view-color-management-intent-absolute-colorimetric"; break; } gimp_action_group_set_action_active (group, action, TRUE); gimp_action_group_set_action_active (group, "view-color-management-black-point-compensation", bpc); gimp_action_group_set_action_active (group, "view-color-management-gamut-check", color_config->simulation_gamut_check); } #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_COLOR(action,color) \ gimp_action_group_set_action_color (group, action, color, FALSE) SET_SENSITIVE ("view-new", image); SET_SENSITIVE ("view-close", image); SET_SENSITIVE ("view-dot-for-dot", image); SET_ACTIVE ("view-dot-for-dot", display && shell->dot_for_dot); SET_SENSITIVE ("view-zoom-revert", revert_enabled); if (revert_enabled) { label = g_strdup_printf (_("Re_vert Zoom (%d%%)"), ROUND (shell->last_scale * 100)); gimp_action_group_set_action_label (group, "view-zoom-revert", label); g_free (label); } else { gimp_action_group_set_action_label (group, "view-zoom-revert", _("Re_vert Zoom")); } SET_SENSITIVE ("view-zoom", image); SET_SENSITIVE ("view-zoom-minimum", image); SET_SENSITIVE ("view-zoom-maximum", image); SET_SENSITIVE ("view-zoom-in", image); SET_SENSITIVE ("view-zoom-in-accel", image); SET_SENSITIVE ("view-zoom-in-skip", image); SET_SENSITIVE ("view-zoom-out", image); SET_SENSITIVE ("view-zoom-out-accel", image); SET_SENSITIVE ("view-zoom-out-skip", image); SET_SENSITIVE ("view-zoom-fit-in", image); SET_SENSITIVE ("view-zoom-fill", image); SET_SENSITIVE ("view-zoom-selection", image); SET_SENSITIVE ("view-zoom-revert", image); SET_SENSITIVE ("view-zoom-16-1", image); SET_SENSITIVE ("view-zoom-16-1-accel", image); SET_SENSITIVE ("view-zoom-8-1", image); SET_SENSITIVE ("view-zoom-8-1-accel", image); SET_SENSITIVE ("view-zoom-4-1", image); SET_SENSITIVE ("view-zoom-4-1-accel", image); SET_SENSITIVE ("view-zoom-2-1", image); SET_SENSITIVE ("view-zoom-2-1-accel", image); SET_SENSITIVE ("view-zoom-1-1", image); SET_SENSITIVE ("view-zoom-1-1-accel", image); SET_SENSITIVE ("view-zoom-1-2", image); SET_SENSITIVE ("view-zoom-1-4", image); SET_SENSITIVE ("view-zoom-1-8", image); SET_SENSITIVE ("view-zoom-1-16", image); SET_SENSITIVE ("view-zoom-other", image); SET_SENSITIVE ("view-flip-horizontally", image); SET_ACTIVE ("view-flip-horizontally", flip_horizontally); SET_SENSITIVE ("view-flip-vertically", image); SET_ACTIVE ("view-flip-vertically", flip_vertically); SET_SENSITIVE ("view-rotate-reset", image); SET_SENSITIVE ("view-rotate-15", image); SET_SENSITIVE ("view-rotate-345", image); SET_SENSITIVE ("view-rotate-90", image); SET_SENSITIVE ("view-rotate-180", image); SET_SENSITIVE ("view-rotate-270", image); SET_SENSITIVE ("view-rotate-other", image); if (image) { view_actions_set_zoom (group, shell); view_actions_set_rotate (group, shell); } SET_SENSITIVE ("view-navigation-window", image); SET_SENSITIVE ("view-display-filters", image); SET_SENSITIVE ("view-color-management-mode-off", image); SET_SENSITIVE ("view-color-management-mode-display", image); SET_SENSITIVE ("view-color-management-mode-softproof", image); SET_SENSITIVE ("view-color-management-intent-perceptual", cm); SET_SENSITIVE ("view-color-management-intent-relative-colorimetric", cm); SET_SENSITIVE ("view-color-management-intent-saturation", cm); SET_SENSITIVE ("view-color-management-intent-absolute-colorimetric", cm); SET_SENSITIVE ("view-color-management-black-point-compensation", cm); SET_SENSITIVE ("view-color-management-gamut-check", sp); SET_SENSITIVE ("view-color-management-reset", image); SET_SENSITIVE ("view-show-selection", image); SET_ACTIVE ("view-show-selection", display && options->show_selection); SET_SENSITIVE ("view-show-layer-boundary", image); SET_ACTIVE ("view-show-layer-boundary", display && options->show_layer_boundary); SET_SENSITIVE ("view-show-guides", image); SET_ACTIVE ("view-show-guides", display && options->show_guides); SET_SENSITIVE ("view-show-grid", image); SET_ACTIVE ("view-show-grid", display && options->show_grid); SET_SENSITIVE ("view-show-sample-points", image); SET_ACTIVE ("view-show-sample-points", display && options->show_sample_points); SET_SENSITIVE ("view-snap-to-guides", image); SET_ACTIVE ("view-snap-to-guides", display && options->snap_to_guides); SET_SENSITIVE ("view-snap-to-grid", image); SET_ACTIVE ("view-snap-to-grid", display && options->snap_to_grid); SET_SENSITIVE ("view-snap-to-canvas", image); SET_ACTIVE ("view-snap-to-canvas", display && options->snap_to_canvas); SET_SENSITIVE ("view-snap-to-vectors", image); SET_ACTIVE ("view-snap-to-vectors", display && options->snap_to_path); SET_SENSITIVE ("view-padding-color-theme", image); SET_SENSITIVE ("view-padding-color-light-check", image); SET_SENSITIVE ("view-padding-color-dark-check", image); SET_SENSITIVE ("view-padding-color-custom", image); SET_SENSITIVE ("view-padding-color-prefs", image); if (display) { SET_COLOR ("view-padding-color-menu", &options->padding_color); if (shell->canvas) { GtkStyle *style = gtk_widget_get_style (shell->canvas); GimpRGB color; gtk_widget_ensure_style (shell->canvas); gimp_rgb_set_gdk_color (&color, style->bg + GTK_STATE_NORMAL); gimp_rgb_set_alpha (&color, GIMP_OPACITY_OPAQUE); SET_COLOR ("view-padding-color-theme", &color); } } SET_SENSITIVE ("view-show-menubar", image); SET_ACTIVE ("view-show-menubar", display && options->show_menubar); SET_SENSITIVE ("view-show-rulers", image); SET_ACTIVE ("view-show-rulers", display && options->show_rulers); SET_SENSITIVE ("view-show-scrollbars", image); SET_ACTIVE ("view-show-scrollbars", display && options->show_scrollbars); SET_SENSITIVE ("view-show-statusbar", image); SET_ACTIVE ("view-show-statusbar", display && options->show_statusbar); SET_SENSITIVE ("view-shrink-wrap", image); SET_ACTIVE ("view-fullscreen", display && fullscreen); if (GIMP_IS_IMAGE_WINDOW (group->user_data) || GIMP_IS_GIMP (group->user_data)) { GtkWidget *window = NULL; if (shell) window = gtk_widget_get_toplevel (GTK_WIDGET (shell)); /* see view_actions_setup() */ if (GTK_IS_WINDOW (window)) window_actions_update (group, window); } #undef SET_ACTIVE #undef SET_SENSITIVE #undef SET_COLOR }