Beispiel #1
0
void is_decode(ic_stream *ics, ic_stream *icsr, real_t *l_spec, real_t *r_spec,
               uint16_t frame_len)
{
    uint8_t g, sfb, b;
    uint16_t i;
#ifndef FIXED_POINT
    real_t scale;
#else
    int32_t exp, frac;
#endif

    uint16_t nshort = frame_len/8;
    uint8_t group = 0;

    for (g = 0; g < icsr->num_window_groups; g++)
    {
        /* Do intensity stereo decoding */
        for (b = 0; b < icsr->window_group_length[g]; b++)
        {
            for (sfb = 0; sfb < icsr->max_sfb; sfb++)
            {
                if (is_intensity(icsr, g, sfb))
                {
                    /* For scalefactor bands coded in intensity stereo the
                       corresponding predictors in the right channel are
                       switched to "off".
                     */
                    ics->pred.prediction_used[sfb] = 0;
                    icsr->pred.prediction_used[sfb] = 0;

#ifndef FIXED_POINT
                    scale = (real_t)pow(0.5, (0.25*icsr->scale_factors[g][sfb]));
#else
                    exp = icsr->scale_factors[g][sfb] >> 2;
                    frac = icsr->scale_factors[g][sfb] & 3;
#endif

                    /* Scale from left to right channel,
                       do not touch left channel */
                    for (i = icsr->swb_offset[sfb]; i < icsr->swb_offset[sfb+1]; i++)
                    {
#ifndef FIXED_POINT
                        r_spec[(group*nshort)+i] = MUL_R(l_spec[(group*nshort)+i], scale);
#else
                        if (exp < 0)
                            r_spec[(group*nshort)+i] = l_spec[(group*nshort)+i] << -exp;
                        else
                            r_spec[(group*nshort)+i] = l_spec[(group*nshort)+i] >> exp;
                        r_spec[(group*nshort)+i] = MUL_C(r_spec[(group*nshort)+i], pow05_table[frac + 3]);
#endif
                        if (is_intensity(icsr, g, sfb) != invert_intensity(ics, g, sfb))
                            r_spec[(group*nshort)+i] = -r_spec[(group*nshort)+i];
                    }
                }
            }
            group++;
        }
    }
}
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) ;

}