void * jpeg_highlighter_algorithm(JOB_ARG *job) { GimpRunMode mode = GIMP_RUN_NONINTERACTIVE; int num_return_vals; gint32 layer, temp_layer; char temp_file_name[256]; int ii; printf("inside %s thread %d\n", jpeg_plugin.name, job->thread); // i really only want to run this once and the plugin doesnt know how many threads will get kicked off because its dynamic if(job->thread == 0) { sleep(1); sprintf(temp_file_name,"%stemp.jpg",job->file_name); // mkstemp(file_name); printf("using filename %s\n", temp_file_name); printf("saving jpeg at %f compression\n", jpeg_compress); gimp_progress_set_text("waiting for jpeg save\n"); gimp_run_procedure("file-jpeg-save",&num_return_vals, GIMP_PDB_INT32, mode, GIMP_PDB_IMAGE, job->image_id , GIMP_PDB_DRAWABLE, job->drawable->drawable_id, GIMP_PDB_STRING, temp_file_name, GIMP_PDB_STRING, "temp", GIMP_PDB_FLOAT, jpeg_compress, GIMP_PDB_FLOAT, 0.0, GIMP_PDB_INT32, 0, GIMP_PDB_INT32, 0, GIMP_PDB_STRING,"created with Koi", GIMP_PDB_INT32, 0, GIMP_PDB_INT32, 1, GIMP_PDB_INT32, 0, GIMP_PDB_INT32, 1, GIMP_PDB_END); // for(ii = 0; ii < SLEEP_TIME; ii++) // { // job->progress = ((float)ii/SLEEP_TIME) * 4; sleep(1); // } printf("saved jpeg\n"); // sleep(1); // reload our saved image and suck a layer off of it to subtract against or original image temp_layer = gimp_file_load_layer(mode, job->image_id, temp_file_name); printf("loaded new layer %d in image %d\n", temp_layer, job->image_id); //gimp_layer_add_alpha(temp_layer); gimp_layer_set_mode(temp_layer, 8); printf("set layer mode %d\n", temp_layer); /* Add the new layer to this image as the top layer */ if (gimp_image_add_layer(job->image_id, temp_layer, -1) != TRUE) { printf("failed to create layer\n"); return; } printf("set layer as top\n"); layer = gimp_image_get_active_layer(job->image_id); if (layer == -1) { printf("failed to get active layer\n"); return; } gimp_image_merge_down(job->image_id, layer, 2); printf("merged layers\n"); job->drawable->drawable_id = gimp_image_get_active_drawable(job->image_id); // printf("get active drawable\n"); // gimp_brightness_contrast(job->drawable->drawable_id, 126, 125); // printf("adjust contrast\n"); // // printf("Jpeg threshold: %d\n",jpeg_threshold); // // //I should have this subtract against an edge detection layer and then threshold it // // gimp_threshold(job->drawable->drawable_id, jpeg_threshold,255 ); // printf("threshold\n"); // if(! gimp_drawable_has_alpha (job->drawable->drawable_id)) // { // /* some filtermacros do not work with layer that do not have an alpha channel // * and cause gimp to fail on attempt to call gimp_pixel_rgn_init // * with both dirty and shadow flag set to TRUE // * in this situation GIMP displays the error message // * "expected tile ack and received: 5" // * and causes the called plug-in to exit immediate without success // * Therfore always add an alpha channel before calling a filtermacro. // */ // gimp_layer_add_alpha(layer); // printf("adding alpha channel\n"); // } remove(temp_file_name); sleep(1); // job->progress = 4; pthread_cond_broadcast(&jpeg_cond); pthread_mutex_lock(&jpeg_mutex); printf("got lock\n"); jpeg_wait = 0; pthread_mutex_unlock(&jpeg_mutex); printf("drawable ID after jpeg %d\n",gimp_image_get_active_drawable(job->image_id)); } else { printf("thread %d waiting\n", job->thread); pthread_mutex_lock(&jpeg_mutex); while (jpeg_wait) { pthread_cond_wait(&jpeg_cond, &jpeg_mutex); } pthread_mutex_unlock(&jpeg_mutex); } job->progress = 1; return NULL; }
static void border (gint32 image_ID) { GdkPixbuf *pixbuf = NULL; int texture_width; int texture_height; gdouble margin_x; gdouble margin_y; pixbuf = gdk_pixbuf_new_from_inline (-1, bvals.border->texture, FALSE, NULL); if (pixbuf) { texture_width = gdk_pixbuf_get_width (pixbuf); texture_height = gdk_pixbuf_get_height (pixbuf); gint32 texture_image = gimp_image_new (texture_width, texture_height, GIMP_RGB); gint32 texture_layer = gimp_layer_new_from_pixbuf (texture_image, "texture", pixbuf, 100, GIMP_NORMAL_MODE, 0, 0); gimp_image_add_layer (texture_image, texture_layer, -1); gint width = gimp_image_width (image_ID); gint height = gimp_image_height (image_ID); if (bvals.border->top || bvals.border->bottom || bvals.border->left || bvals.border->right) { width += bvals.border->left + bvals.border->right; height += bvals.border->top + bvals.border->bottom; gimp_image_resize (image_ID, width, height, bvals.border->left, bvals.border->top); } gint32 layer = gimp_layer_new (image_ID, "border", width, height, GIMP_RGBA_IMAGE, 100, GIMP_NORMAL_MODE); gimp_image_add_layer (image_ID, layer, -1); if (width > texture_width - bvals.border->length) margin_x = (texture_width - bvals.border->length) / 2; else margin_x = (gdouble) width / 2; if (height > texture_height - bvals.border->length) margin_y = (texture_height - bvals.border->length) / 2; else margin_y = (gdouble) height / 2; /* fix gimp_context_set_pattern ("Clipboard") only works on English versions of Gimp */ //gimp_context_set_pattern ("Clipboard"); INIT_I18N (); gimp_context_set_pattern (_("Clipboard")); if (width > margin_x * 2) { /* top */ gimp_rect_select (texture_image, margin_x, 0, texture_width - margin_x * 2, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, margin_x, 0, width - margin_x * 2, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* bottom */ gimp_rect_select (texture_image, margin_x, texture_height - margin_y, texture_width - margin_x * 2, texture_height, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, margin_x, height - margin_y, width - margin_x * 2, height, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); } if (height > margin_y * 2) { /* left */ gimp_rect_select (texture_image, 0, margin_y, margin_x, texture_height - margin_y * 2, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, 0, margin_y, margin_x, height - margin_y * 2, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* right */ gimp_rect_select (texture_image, texture_width - margin_x, margin_y, margin_x, texture_height - margin_y * 2, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, width - margin_x, margin_y, margin_x, height - margin_y * 2, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); } /* top left */ gimp_rect_select (texture_image, 0, 0, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, 0, 0, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* top right */ gimp_rect_select (texture_image, texture_width - margin_x, 0, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, width - margin_x, 0, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* bottom left */ gimp_rect_select (texture_image, 0, texture_height - margin_y, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, 0, height - margin_y, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); /* bottom right */ gimp_rect_select (texture_image, texture_width - margin_x, texture_height - margin_y, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_copy (texture_layer); gimp_rect_select (image_ID, width - margin_x, height - margin_y, margin_x, margin_y, GIMP_CHANNEL_OP_REPLACE, FALSE, 0); gimp_edit_fill (layer, GIMP_PATTERN_FILL); gimp_image_merge_down(image_ID, layer, GIMP_CLIP_TO_IMAGE); gimp_selection_none (image_ID); } }
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); }