void GUI::apply_filter_from_menu(Controller &controller, Gtk::ImageMenuItem &imagemenuitem) { if ( ! controller.image_file_loaded ) { return ; } bool is_alpha = controller.current_image_to_process.channels() == 4 ; Sharpen sharpen_filter(3, "diamond") ; Sharpen sharpen_filter_more(3, "diamond") ; Find_Edges find_edges_filter(3) ; Mean mean_filter(3) ; Mean mean_filter_more(5) ; cv::Mat kernel = make_kernel("rect", 3) ; cv::Mat tmp = controller.current_image_to_process.clone() ; cv::Mat frame ; switch ( stoi(imagemenuitem.get_name()) ) { case 0 : // Pencil Sketch filter. pencil_sketch_filter(tmp, frame) ; break ; case 1 : // Stylisation filter. stylisation_filter(tmp, frame) ; break ; case 2 : // Detail Enhance filter. detail_enhance_filter(tmp, frame) ; break ; case 3 : // Edge Preserving filter. edge_preserving_filter(tmp, frame) ; break ; case 4 : // Stroke edges filter: stroke_edges(tmp, frame) ; break ; case 5 : // Invert Intensity filter: invert_intensity(tmp, frame) ; break ; case 6 : // Light Intensity filter: effect_light(tmp, frame) ; break ; case 7 : // Recolor-RC (Red-Cyan) filter: recolorRC(tmp, frame) ; break ; case 8 : // Recolor-RC (Red-Green-Value) filter: recolorRGV(tmp, frame) ; break ; case 9 : // Recolor-RC (Cyan-Magenta-Value) filter: recolorCMV(tmp, frame) ; break ; case 10 : // Extrema Maximal Filter: extrema(tmp, frame, "max") ; break ; case 11 : // Extrema Minimal Filter: extrema(tmp, frame, "min") ; break ; case 12 : // Sharpen filter: sharpen_filter.apply(tmp, frame) ; break ; case 13 : // Sharpen More filter: sharpen_filter_more.apply(tmp, frame) ; break ; case 14 : // Find Edges filter: if (is_alpha) { cv::Mat frame_rgb ; cv::Mat tmp_1 ; cvtColor(tmp, frame_rgb, cv::COLOR_BGRA2BGR) ; find_edges_filter.apply(frame_rgb, tmp_1) ; vector<cv::Mat> tmp_2 ; vector<cv::Mat> tmp_3 ; cv::split(tmp, tmp_2) ; cv::split(tmp_1, tmp_3) ; // Assign BGR channels. tmp_2[0] = tmp_3[0] ; tmp_2[1] = tmp_3[1] ; tmp_2[2] = tmp_3[2] ; // Final channels merging into result with alpha channel unchanged. cv::merge(tmp_2, frame) ; break ; } find_edges_filter.apply(tmp, frame) ; break ; case 15 : // Mean Blur filter: mean_filter.apply(tmp, frame) ; break ; case 16 : // Mean Blur More filter: mean_filter_more.apply(tmp, frame) ; break ; case 17 : // Blur filter: blur_filter(tmp, frame) ; break ; case 18 : // Median Blur filter: median_blur_filter(tmp, frame) ; break ; case 19 : // Gaussian Blur filter: gaussian_blur_filter(tmp, frame) ; break ; case 20 : denoising_filter(tmp, frame) ; break ; case 21 : // Erode filter: erode_filter(tmp, frame, kernel, 1) ; break ; case 22 : // Dilate filter: dilate_filter(tmp, frame, kernel, 1) ; break ; case 23 : // Wave Horizontally filter: wave(tmp, frame, -1) ; break ; case 24 : // Wave Vertically filter: wave(tmp, frame, 1) ; break ; case 25 : // Wave Twice (Horizontally and Vertically) filter: wave(tmp, frame, 0) ; break ; case 26 : // Contours Sobel White filter. sobel_drawning(tmp, frame, 3, false, 1) ; break ; case 27 : // Contours Sobel Black filter. sobel_drawning(tmp, frame, 3, false, -1) ; break ; case 28 : // Contours Sobel Emboss filter. sobel_drawning(tmp, frame, 3, false, 0) ; break ; case 29 : // Emboss Sobel filter: sobel_emboss(tmp, frame, 3) ; break ; case 30 : // Emboss Laplacian filter: laplacian_emboss(tmp, frame, 3) ; break ; case 31 : // Binary White OTSU filter: // Build a binary image (a black and white only image) with white background (@arg value true) // based on the OTSU threshold computing algorithm (@arg value -1). build_binary_image(tmp, frame, -1, true) ; break ; case 32 : // Binary White TRIANGLE filter: // Build a binary image (a black and white only image) with white background (@arg value true) // based on the TRIANGLE threshold computing algorithm (@arg value 1). build_binary_image(tmp, frame, 1, true) ; break ; case 33 : // Binary White AVERAGE filter: // Build a binary image (a black and white only image) with white background (@arg value true) // based on the AVERAGE threshold from OTSU and TRIANGLE (@arg value 0). build_binary_image(tmp, frame, 0, true) ; break ; case 34 : // Binary Black OTSU filter: // Build a binary image (a black and white only image) with black background (@arg value true) // based on the OTSU threshold computing algorithm (@arg value -1). build_binary_image(tmp, frame, -1, false) ; break ; case 35 : // Binary Black TRIANGLE filter: // Build a binary image (a black and white only image) with black background (@arg value true) // based on the TRIANGLE threshold computing algorithm (@arg value 1). build_binary_image(tmp, frame, 1, false) ; break ; case 36 : // Binary Black AVERAGE filter: // Build a binary image (a black and white only image) with black background (@arg value true) // based on the AVERAGE threshold from OTSU and TRIANGLE (@arg value 0). build_binary_image(tmp, frame, 0, false) ; break ; case 37 : // Binary Contours White filter: // Build a binary image (a black and white only image) with contours detction on white background (@arg value false). laplacian_zero_crossing(tmp, frame, 19, false) ; break ; case 38 : // Binary Contours Black filter: // Build a binary image (a black and white only image) with contours detction on black background (@arg value true). laplacian_zero_crossing(tmp, frame, 19, true) ; break ; #ifdef DEBUG default : // Cannot append due of the GUI interfacing. fprintf(stdout,"Error applying filter !!!\n") ; return ; #endif } // We register current frame in vector<cv::Mat> for undo-redo. controller.process_after_applying(frame) ; // It convert current_image_to_process as src to RGB(A) in dst current_image_to_display. set_img(frame, controller.current_image_to_display, controller) ; // It auto process conversion to RGB(A). // Reset some variables. after_applying_reset_settings(controller) ; }
static int shrink_factor( IMAGE *in, IMAGE *out, int shrink, double residual, VipsInterpolate *interp ) { IMAGE *t[9]; VipsImage **s = (VipsImage **) vips_object_local_array( VIPS_OBJECT( out ), 1 ); IMAGE *x; int tile_width; int tile_height; int nlines; if( im_open_local_array( out, t, 9, "thumbnail", "p" ) ) return( -1 ); x = in; /* Unpack the two coded formats we support to float for processing. */ if( x->Coding == IM_CODING_LABQ ) { if( verbose ) printf( "unpacking LAB to RGB\n" ); if( im_LabQ2disp( x, t[1], im_col_displays( 7 ) ) ) return( -1 ); x = t[1]; } else if( x->Coding == IM_CODING_RAD ) { if( verbose ) printf( "unpacking Rad to float\n" ); if( im_rad2float( x, t[1] ) ) return( -1 ); x = t[1]; } if( im_shrink( x, t[2], shrink, shrink ) ) return( -1 ); /* We want to make sure we read the image sequentially. * However, the convolution we may be doing later will force us * into SMALLTILE or maybe FATSTRIP mode and that will break * sequentiality. * * So ... read into a cache where tiles are scanlines, and make sure * we keep enough scanlines to be able to serve a line of tiles. */ vips_get_tile_size( t[2], &tile_width, &tile_height, &nlines ); if( vips_tilecache( t[2], &s[0], "tile_width", t[2]->Xsize, "tile_height", 10, "max_tiles", (nlines * 2) / 10, "strategy", VIPS_CACHE_SEQUENTIAL, NULL ) || im_affinei_all( s[0], t[4], interp, residual, 0, 0, residual, 0, 0 ) ) return( -1 ); x = t[4]; /* If we are upsampling, don't sharpen, since nearest looks dumb * sharpened. */ if( shrink > 1 && residual <= 1.0 && !nosharpen ) { if( verbose ) printf( "sharpening thumbnail\n" ); if( im_conv( x, t[5], sharpen_filter() ) ) return( -1 ); x = t[5]; } /* Colour management: we can transform the image if we have an output * profile and an input profile. The input profile can be in the * image, or if there is no profile there, supplied by the user. */ if( export_profile && (im_header_get_typeof( x, IM_META_ICC_NAME ) || import_profile) ) { if( im_header_get_typeof( x, IM_META_ICC_NAME ) ) { if( verbose ) printf( "importing with embedded profile\n" ); if( im_icc_import_embedded( x, t[6], IM_INTENT_RELATIVE_COLORIMETRIC ) ) return( -1 ); } else { if( verbose ) printf( "importing with profile %s\n", import_profile ); if( im_icc_import( x, t[6], import_profile, IM_INTENT_RELATIVE_COLORIMETRIC ) ) return( -1 ); } if( verbose ) printf( "exporting with profile %s\n", export_profile ); if( im_icc_export_depth( t[6], t[7], 8, export_profile, IM_INTENT_RELATIVE_COLORIMETRIC ) ) return( -1 ); x = t[7]; } if( delete_profile ) { if( verbose ) printf( "deleting profile from output image\n" ); if( im_meta_get_typeof( x, IM_META_ICC_NAME ) && !im_meta_remove( x, IM_META_ICC_NAME ) ) return( -1 ); } if( im_copy( x, out ) ) return( -1 ); return( 0 ); }