static gboolean apply_watermark(watermark_settings settings, image_output out) { gboolean success = TRUE; gint32 layerId; gdouble posX, posY; gint wmwidth, wmheight, wmasc, wmdesc; if (settings->mode) { if (strlen(settings->text) == 0) { return TRUE; } GimpRGB old_foreground, new_foreground; gimp_context_get_foreground(&old_foreground); gimp_rgb_parse_hex (&new_foreground, gdk_color_to_string(&(settings->color)), strlen(gdk_color_to_string(&(settings->color)))); gimp_context_set_foreground(&new_foreground); gimp_text_get_extents_fontname( settings->text, pango_font_description_get_size(settings->font) / PANGO_SCALE, GIMP_PIXELS, pango_font_description_get_family(settings->font), &wmwidth, &wmheight, &wmasc, &wmdesc ); if (settings->position == WM_POS_TL) { posX = 10; posY = 5; } else if (settings->position == WM_POS_TC) { posX = (gimp_image_width(out->image_id) / 2) - (wmwidth / 2); posY = 5; } else if (settings->position == WM_POS_TR) { posX = gimp_image_width(out->image_id) - wmwidth - 10; posY = 5; } else if (settings->position == WM_POS_BL) { posX = 10; posY = gimp_image_height(out->image_id) - wmheight - 5; } else if (settings->position == WM_POS_BC) { posX = (gimp_image_width(out->image_id) / 2) - (wmwidth / 2); posY = gimp_image_height(out->image_id) - wmheight - 5; } else if (settings->position == WM_POS_BR) { posX = gimp_image_width(out->image_id) - wmwidth - 10; posY = gimp_image_height(out->image_id) - wmheight - 5; } else if (settings->position == WM_POS_CL) { posX = 10; posY = (gimp_image_height(out->image_id) / 2) - (wmheight / 2); } else if (settings->position == WM_POS_CR) { posX = gimp_image_width(out->image_id) - wmwidth - 10; posY = (gimp_image_height(out->image_id) / 2) - (wmheight / 2); } else { posX = (gimp_image_width(out->image_id) / 2) - (wmwidth / 2); posY = (gimp_image_height(out->image_id) / 2) - (wmheight / 2); } layerId = gimp_text_fontname( out->image_id, -1, posX, posY, settings->text, -1, TRUE, pango_font_description_get_size(settings->font) / PANGO_SCALE, GIMP_PIXELS, pango_font_description_get_family(settings->font) ); gimp_context_set_foreground(&old_foreground); gimp_layer_set_opacity(layerId, settings->opacity); } else { if (!g_file_test(settings->image_file, G_FILE_TEST_IS_REGULAR)) {//((access(settings->image_file, R_OK) == -1)) { // error, can't access image file return TRUE; } layerId = gimp_file_load_layer( GIMP_RUN_NONINTERACTIVE, out->image_id, settings->image_file ); gimp_layer_set_opacity(layerId, settings->opacity); wmwidth = gimp_drawable_width(layerId); wmheight = gimp_drawable_height(layerId); #if USE_API26 gimp_image_add_layer( out->image_id, layerId, 0 ); #else // starting from 2.8, gimp_image_add_layer is deprecated. // use gimp_image_insert_layer instead gimp_image_insert_layer( out->image_id, layerId, 0, 0 ); #endif if (settings->position == WM_POS_TL) { posX = 10; posY = 10; } else if (settings->position == WM_POS_TC) { posX = (gimp_image_width(out->image_id) / 2) - (wmwidth / 2); posY = 10; } else if (settings->position == WM_POS_TR) { posX = gimp_image_width(out->image_id) - wmwidth - 10; posY = 10; } else if (settings->position == WM_POS_BL) { posX = 10; posY = gimp_image_height(out->image_id) - wmheight - 10; } else if (settings->position == WM_POS_BC) { posX = (gimp_image_width(out->image_id) / 2) - (wmwidth / 2); posY = gimp_image_height(out->image_id) - wmheight - 10; } else if (settings->position == WM_POS_BR) { posX = gimp_image_width(out->image_id) - wmwidth - 10; posY = gimp_image_height(out->image_id) - wmheight - 10; } else if (settings->position == WM_POS_CL) { posX = 10; posY = (gimp_image_height(out->image_id) / 2) - (wmheight / 2); } else if (settings->position == WM_POS_CR) { posX = gimp_image_width(out->image_id) - wmwidth - 10; posY = (gimp_image_height(out->image_id) / 2) - (wmheight / 2); } else { posX = (gimp_image_width(out->image_id) / 2) - (wmwidth / 2); posY = (gimp_image_height(out->image_id) / 2) - (wmheight / 2); } gimp_layer_set_offsets( layerId, posX, posY ); } // refresh all drawables g_free(out->drawable_ids); out->drawable_ids = gimp_image_get_layers(out->image_id, &out->drawable_count); return success; }
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; }