/* ----------------------------- * gap_image_reorder_layer * ----------------------------- * move the specified layer to another position within the same image. * (done by removing and then re-inserting the layer) * new_groupname * Name of a group or group/subgroup where the specified layer_id shall be moved to. * Note that the string new_groupname uses the delimiter string * to split nested group/sugrup names. * use new_groupname = NULL to move the specified layer_id to image toplevel. * enableGroupCreation * TRUE: * in case the group layer with new_groupname does not exist * it will be created automatically. * FALSE: * in case the group layer with new_groupname does not exist * -1 is returned and the reorder operation is not performed. * new_position * the desired new stackposition within the specified new_groupname * or toplevel image (when new_groupname is NULL or empty) * returns -1 on error */ gint32 gap_image_reorder_layer(gint32 image_id, gint32 layer_id, gint32 new_position, char *new_groupname, char *delimiter, gboolean enableGroupCreation, char *new_layername) { gint32 l_parent_id; gint32 l_dup_layer_id; gchar *l_name; l_parent_id = gap_image_find_or_create_group_layer(image_id , new_groupname , delimiter , 0 /* stackposition for the group in case it is created at toplevel */ , enableGroupCreation ); if (l_parent_id < 0) { return (-1); } l_dup_layer_id = gimp_layer_copy(layer_id); l_name = NULL; if (new_layername != NULL) { if (*new_layername != '\0') { l_name = g_strdup(new_layername); } } if (l_name == NULL) { l_name = gimp_item_get_name(layer_id); } gimp_image_remove_layer(image_id, layer_id); gimp_image_insert_layer(image_id, l_dup_layer_id, l_parent_id, new_position); gimp_item_set_name(l_dup_layer_id, l_name); g_free(l_name); return (0); /* OK */ } /* end gap_image_reorder_layer */
static void preview_ambient_occlusion_only(gint32 image_ID) { gint32 drawable_ID = -1; gint32 drawableAO_ID = -1; gtk_label_set_text(GTK_LABEL(progress_label), "Mixing Colors"); // preview_diffuse_only(image_ID); preview_normal_only(image_ID); // if (preview_normal_only(image_ID) != NULL) return NULL; drawable_ID = gimp_image_get_active_layer(image_ID); /** Copy active layer. */ /** LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL */ drawableAO_ID = gimp_layer_copy (drawable_ID); /** Add new layer to image. */ gimp_image_add_layer(image_ID, drawableAO_ID, -1); /** Set new layer as active. */ gimp_image_set_active_layer(image_ID, drawableAO_ID); /** * Colors -> Components -> "Channel Mixer" applied * Standard plug-in. Source code ships with GIMP. * * Add the "f" here to signify float in c language. * Removed 0.0 on first param and changed to 0 because boolean. */ /** Explained on line ~1300 of InsaneBump.c */ // if (plug_in_colors_channel_mixer_connector(image_ID, drawableAO_ID, 0, -200.0f, 0.0f, 0.0f, 0.0f, -200.0f, 0.0f, 0.0f, 0.0f, 1.0f) != 1) return; if (plug_in_colors_channel_mixer_connector(image_ID, drawableAO_ID, 0, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f) != 1) return; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.87); gimp_desaturate(drawableAO_ID); gimp_levels_stretch(drawableAO_ID); pDrawables.drawable_ao = gimp_drawable_get(drawableAO_ID); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.90); }
static void dog (gint32 image_ID, GimpDrawable *drawable, gdouble inner, gdouble outer, gboolean show_progress) { GimpDrawable *drawable1; GimpDrawable *drawable2; gint32 drawable_id = drawable->drawable_id; gint32 layer1; gint32 layer2; gint width, height; gint x1, y1, x2, y2; guchar maxval = 255; gimp_drawable_mask_bounds (drawable_id, &x1, &y1, &x2, &y2); width = (x2 - x1); height = (y2 - y1); gimp_drawable_flush (drawable); layer1 = gimp_layer_copy (drawable_id); gimp_drawable_set_visible (layer1, FALSE); gimp_drawable_set_name (layer1, "dog_scratch_layer1"); gimp_image_add_layer (image_ID, layer1, 0); layer2 = gimp_layer_copy (drawable_id); gimp_drawable_set_visible (layer2, FALSE); gimp_drawable_set_name (layer2, "dog_scratch_layer2"); gimp_image_add_layer (image_ID, layer2, 0); drawable1 = gimp_drawable_get (layer1); drawable2 = gimp_drawable_get (layer2); gauss_rle (drawable1, inner, 0, show_progress); gauss_rle (drawable2, outer, 1, show_progress); compute_difference (drawable, drawable1, drawable2, &maxval); gimp_drawable_detach (drawable1); gimp_drawable_detach (drawable2); gimp_image_remove_layer (image_ID, layer1); gimp_image_remove_layer (image_ID, layer2); gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable_id, TRUE); gimp_drawable_update (drawable_id, x1, y1, width, height); if (dogvals.normalize) { normalize (drawable, maxval); gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable_id, TRUE); gimp_drawable_update (drawable_id, x1, y1, width, height); } if (dogvals.invert) gimp_invert (drawable_id); }
/* --------------------------------- * gap_edgeDetectionByBlurDiff * --------------------------------- */ gint32 gap_edgeDetectionByBlurDiff(gint32 activeDrawableId, gdouble blurRadius, gdouble blurResultRadius , gdouble threshold, gint32 shift, gboolean doLevelsAutostretch , gboolean invert) { gint32 blurLayerId; gint32 edgeLayerId; gint32 imageId; GimpDrawable *edgeDrawable; GimpDrawable *refDrawable; GimpDrawable *blurDrawable; imageId = gimp_drawable_get_image(activeDrawableId); edgeLayerId = gimp_layer_copy(activeDrawableId); gimp_image_add_layer (imageId, edgeLayerId, 0 /* stackposition */ ); edgeDrawable = gimp_drawable_get(edgeLayerId); refDrawable = gimp_drawable_get(activeDrawableId); if(blurRadius > 0.0) { p_call_plug_in_gauss_iir2(imageId, edgeLayerId, blurRadius, blurRadius); } blurDrawable = NULL; // blurLayerId = gimp_layer_copy(edgeLayerId); // gimp_image_add_layer (imageId, blurLayerId, 0 /* stackposition */ ); // blurDrawable = gimp_drawable_get(blurLayerId); p_subtract_ref_layer(imageId, edgeDrawable, refDrawable, threshold, shift, invert); //p_subtract_ref_layer(imageId, edgeDrawable, blurDrawable, threshold, shift, invert); if (doLevelsAutostretch) { gimp_levels_stretch(edgeLayerId); } if(blurResultRadius > 0.0) { p_call_plug_in_gauss_iir2(imageId, edgeLayerId, blurResultRadius, blurResultRadius); } if(refDrawable) { gimp_drawable_detach(refDrawable); } if(edgeDrawable) { gimp_drawable_detach(edgeDrawable); } if(blurDrawable) { gimp_drawable_detach(blurDrawable); } return (edgeLayerId); } /* end gap_edgeDetectionByBlurDiff */
static void dog (gint32 image_ID, GimpDrawable *drawable, gdouble inner, gdouble outer, gboolean show_progress) { GimpDrawable *drawable1; GimpDrawable *drawable2; gint32 drawable_id = drawable->drawable_id; gint32 layer1; gint32 layer2; gint width, height; gint x1, y1, x2, y2; guchar maxval = 255; gimp_drawable_mask_bounds (drawable_id, &x1, &y1, &x2, &y2); width = (x2 - x1); height = (y2 - y1); gimp_drawable_flush (drawable); layer1 = gimp_layer_copy (drawable_id); gimp_item_set_visible (layer1, FALSE); gimp_item_set_name (layer1, "dog_scratch_layer1"); gimp_image_insert_layer (image_ID, layer1, gimp_item_get_parent (drawable_id), 0); layer2 = gimp_layer_copy (drawable_id); gimp_item_set_visible (layer2, FALSE); gimp_item_set_name (layer2, "dog_scratch_layer2"); gimp_image_insert_layer (image_ID, layer2, gimp_item_get_parent (drawable_id), 0); drawable1 = gimp_drawable_get (layer1); drawable2 = gimp_drawable_get (layer2); gauss_rle (drawable1, inner, 0, show_progress); gauss_rle (drawable2, outer, 1, show_progress); compute_difference (drawable, drawable1, drawable2, &maxval); gimp_drawable_detach (drawable1); gimp_drawable_detach (drawable2); gimp_image_remove_layer (image_ID, layer1); gimp_image_remove_layer (image_ID, layer2); gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable_id, TRUE); gimp_drawable_update (drawable_id, x1, y1, width, height); if (dogvals.normalize || dogvals.invert) /* gimp_invert doesn't work properly with previews due to shadow handling * so reimplement it here - see Bug 557380 */ { normalize_invert (drawable, dogvals.normalize, maxval, dogvals.invert); gimp_drawable_flush (drawable); gimp_drawable_merge_shadow (drawable_id, TRUE); gimp_drawable_update (drawable_id, x1, y1, width, height); } }
static void preview_alt_normal(gint32 image_ID) { /******************************************************************************* * Begin H and Normal ******************************************************************************/ gint32 mergedLayer_ID = -1; gint32 normalmap_ID = -1; gfloat wsize = (gfloat)gimp_image_width(image_ID); gfloat hsize = (gfloat)gimp_image_width(image_ID); /** Get active layer. */ gint32 drawable_temp_ID = gimp_image_get_active_layer(image_ID); /** Copy active layer. */ /** LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL */ gint32 diffuse_ID = gimp_layer_copy (drawable_temp_ID); /** Add new layer to image. */ gimp_image_add_layer(image_ID, diffuse_ID, -1); /** Set new layer as active. */ gimp_image_set_active_layer(image_ID, diffuse_ID); /** Here I should hide previous active layer, make not visible. */ gtk_label_set_text(GTK_LABEL(progress_label), "Smoothing"); /** * Since copied, don't need this here. * blur seems to not create an extra layer. */ blur(image_ID, diffuse_ID, wsize, hsize, local_vals.LargeDetails, 0, local_vals.ao); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.15); normalmap_ID = gimp_image_get_active_layer(image_ID); if(local_vals.smoothstep) { gtk_label_set_text(GTK_LABEL(progress_label), "Smoothing"); /** * Filter "Blur" applied * Standard plug-in. Source code ships with GIMP. */ if (plug_in_blur_connector(image_ID, normalmap_ID) != 1) return; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.20); } else { gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.20); } if(local_vals.invh) { /** * Colors Menu->Invert * Standard plug-in. Source code ships with GIMP. */ if (plug_in_vinvert_connector(image_ID, normalmap_ID) != 1) return; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.25); } else { gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.25); } /** Here is _p Displacement drawable. */ pDrawables.drawable_p = gimp_drawable_get(normalmap_ID); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.30); /** Extra layer here. */ /** LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL */ gtk_label_set_text(GTK_LABEL(progress_label), "Base Mapping"); doBaseMap(image_ID, diffuse_ID, local_vals.Depth, local_vals.LargeDetails, local_vals.ao); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.35); normalmap_ID = gimp_image_get_active_layer(image_ID); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.40); /** Here is _ln low normal. l l l l l l l l l l l l l l l l */ if (gcNeedNormal == 'l') { pDrawables.drawable_n = gimp_drawable_get(normalmap_ID); } /** Creates an extra layer. */ /** LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL */ shapeRecognise(image_ID, normalmap_ID, local_vals.ShapeRecog, local_vals.ao); if(local_vals.smoothstep) { normalmap_ID = gimp_image_get_active_layer(image_ID); gtk_label_set_text(GTK_LABEL(progress_label), "Smoothing"); /** * Filter "Blur" applied * Standard plug-in. Source code ships with GIMP. */ if (plug_in_blur_connector(image_ID, normalmap_ID) != 1) return; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.45); } else { gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.45); } /** Here is _sn super normal. s s s s s s s s s s s s s s s s */ if (gcNeedNormal == 's') { pDrawables.drawable_n = gimp_drawable_get(normalmap_ID); } gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.50); gtk_label_set_text(GTK_LABEL(progress_label), "Sharpen"); /** Creates an extra layer. */ /** LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL */ sharpen(image_ID, diffuse_ID, local_vals.Depth, 0, local_vals.SmallDetails); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.55); normalmap_ID = gimp_image_get_active_layer(image_ID); gtk_label_set_text(GTK_LABEL(progress_label), "Sharpen more"); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.65); /** * Filter Enhance "Sharpen" applied * Standard plug-in. Source code ships with GIMP. */ if (plug_in_sharpen_connector(image_ID, normalmap_ID, 20) != 1) return; /** Here is _hn high normal. h h h h h h h h h h h h h h h h */ if (gcNeedNormal == 'h') { pDrawables.drawable_n = gimp_drawable_get(normalmap_ID); } gtk_label_set_text(GTK_LABEL(progress_label), "Sharpen again"); /** Creates an extra layer. */ /** LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL */ sharpen(image_ID, diffuse_ID, local_vals.Depth, 6, local_vals.MediumDetails); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.70); normalmap_ID = gimp_image_get_active_layer(image_ID); gtk_label_set_text(GTK_LABEL(progress_label), "Smoothing"); /** * Filter "Blur" applied * Standard plug-in. Source code ships with GIMP. */ if (plug_in_blur_connector(image_ID, normalmap_ID) != 1) return; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.75); /** Here is _mn medium normal m m m m m m m m m m m m m m m m */ if (gcNeedNormal == 'm') { pDrawables.drawable_n = gimp_drawable_get(normalmap_ID); } gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.78); gimp_drawable_set_visible(diffuse_ID, 0); /** * Don't do the next line: * * gimp_image_merge_visible_layers(image_ID, 0); * * Do this instead for preview: */ mergedLayer_ID = gimp_layer_new_from_visible(image_ID, image_ID, "temp"); /** Add copied layer to image. */ gimp_image_add_layer(image_ID, mergedLayer_ID, -1); }
static void preview_diffuse_only(gint32 image_ID) { gint32 noiselayer_ID = -1; gint32 drawable_ID = -1; gint32 drawableDiffuse_ID = -1; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.0); gtk_label_set_text(GTK_LABEL(progress_label), "Begin"); drawableBeginActiveLayer = gimp_image_get_active_layer(image_ID); drawable_ID = gimp_layer_copy (drawableBeginActiveLayer); gimp_image_add_layer(image_ID, drawable_ID, -1); gimp_image_set_active_layer(image_ID, drawable_ID); /** Here I should hide previous active layer, make not visible. */ gimp_drawable_set_visible(drawableBeginActiveLayer, FALSE); /** * For preview do nothing here. * if(local_vals.Resizie) * { * } */ if (local_vals.Noise) { /** Already have active layer in drawable_ID. */ noiselayer_ID = gimp_layer_copy (drawable_ID); gimp_image_add_layer(image_ID, noiselayer_ID, -1); gimp_image_set_active_layer(image_ID, noiselayer_ID); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.03); gtk_label_set_text(GTK_LABEL(progress_label), "Noise"); /** * Filter "RGB Noise" applied * Standard plug-in. Source code ships with GIMP. * * Add the "f" here to signify float in c language. */ if (plug_in_rgb_noise_connector(image_ID, noiselayer_ID, 1, 1, 0.20f, 0.20f, 0.20f, 0.0f) != 1) return; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.04); gimp_layer_set_mode(noiselayer_ID, GIMP_VALUE_MODE); gimp_image_merge_down(image_ID, noiselayer_ID, 0); gtk_label_set_text(GTK_LABEL(gwNormalLabel), "Noise affects every redraw!"); } else { gtk_label_set_text(GTK_LABEL(gwNormalLabel), ""); gtk_label_set_text(GTK_LABEL(progress_label), "Noise added"); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.04); } if(local_vals.RemoveLighting) { gtk_label_set_text(GTK_LABEL(progress_label), "Remove Shading"); removeShadingPreview(image_ID, local_vals.Noise); /** * See notes inside of removeShadingPreview * for explanation of next line. */ /** * If Noise is on, then noiselayer_ID was merged down into drawable_ID. * You cannot remove drawable_ID in this case, as it is the only * layer left! * * However, if Noise is Yes and RemoveLighting is Yes, * Then there is an extra layer floating around! * Delete noiselayer_ID? I thought it was merged! * No, I was right noiselayer_ID is already gone! */ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.05); } else { gtk_label_set_text(GTK_LABEL(progress_label), "Stretch"); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.05); } drawableDiffuse_ID = gimp_image_get_active_layer(image_ID); gimp_levels_stretch(drawableDiffuse_ID); if(local_vals.Tile) { gtk_label_set_text(GTK_LABEL(progress_label), "Making Seamless"); /** * Filter "Tile Seamless" applied * Standard plug-in. Source code ships with GIMP. */ if (plug_in_make_seamless_connector(image_ID, drawableDiffuse_ID) != 1) return; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.07); } else { gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.07); } /** Here I should un hide previously hidden layer, make visible. */ pDrawables.drawable_d = gimp_drawable_get(drawableDiffuse_ID); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.1); }