Esempio n. 1
0
static GimpPDBStatusType
print_image (gint32     image_ID,
             gboolean   interactive,
             GError   **error)
{
  GtkPrintOperation       *operation;
  GtkPrintOperationResult  result;
  gchar                   *temp_proc;
  gint32                   layer;
  PrintData                data;

  /*  create a print layer from the projection  */
  layer = gimp_layer_new_from_visible (image_ID, image_ID, PRINT_PROC_NAME);

  operation = gtk_print_operation_new ();

  gtk_print_operation_set_n_pages (operation, 1);
  print_operation_set_name (operation, image_ID);

  print_page_setup_load (operation, image_ID);

  /* fill in the PrintData struct */
  data.image_id      = image_ID;
  data.drawable_id   = layer;
  data.unit          = gimp_get_default_unit ();
  data.image_unit    = gimp_image_get_unit (image_ID);
  data.offset_x      = 0;
  data.offset_y      = 0;
  data.center        = CENTER_BOTH;
  data.use_full_page = FALSE;
  data.operation     = operation;

  gimp_image_get_resolution (image_ID, &data.xres, &data.yres);

  print_settings_load (&data);

  gtk_print_operation_set_unit (operation, GTK_UNIT_PIXEL);

  g_signal_connect (operation, "begin-print",
                    G_CALLBACK (begin_print),
                    &data);
  g_signal_connect (operation, "draw-page",
                    G_CALLBACK (draw_page),
                    &data);
  g_signal_connect (operation, "end-print",
                    G_CALLBACK (end_print),
                    &image_ID);

  print_operation = operation;
  temp_proc = print_temp_proc_install (image_ID);
  gimp_extension_enable ();

  if (interactive)
    {
      gimp_ui_init (PLUG_IN_BINARY, FALSE);

      g_signal_connect_swapped (operation, "end-print",
                                G_CALLBACK (print_settings_save),
                                &data);

      g_signal_connect (operation, "create-custom-widget",
                        G_CALLBACK (create_custom_widget),
                        &data);

      gtk_print_operation_set_custom_tab_label (operation, _("Image Settings"));

      result = gtk_print_operation_run (operation,
                                        GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
                                        NULL, error);
    }
  else
    {
      result = gtk_print_operation_run (operation,
                                        GTK_PRINT_OPERATION_ACTION_PRINT,
                                        NULL, error);
    }

  gimp_uninstall_temp_proc (temp_proc);
  g_free (temp_proc);
  print_operation = NULL;

  g_object_unref (operation);

  if (gimp_drawable_is_valid (layer))
    gimp_drawable_delete (layer);

  switch (result)
    {
    case GTK_PRINT_OPERATION_RESULT_APPLY:
    case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS:
      return GIMP_PDB_SUCCESS;

    case GTK_PRINT_OPERATION_RESULT_CANCEL:
      return GIMP_PDB_CANCEL;

    case GTK_PRINT_OPERATION_RESULT_ERROR:
      return GIMP_PDB_EXECUTION_ERROR;
    }

  return GIMP_PDB_EXECUTION_ERROR;
}
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);
}