コード例 #1
0
static void
layer_select_destroy (LayerSelect *layer_select,
                      guint32      time)
{
  gdk_display_keyboard_ungrab (gtk_widget_get_display (layer_select->window),
                                                       time);

  gtk_widget_destroy (layer_select->window);

  if (layer_select->orig_layer !=
      gimp_image_get_active_layer (layer_select->image))
    {
      gimp_image_flush (layer_select->image);
    }

  g_slice_free (LayerSelect, layer_select);
}
コード例 #2
0
ファイル: gap_image.c プロジェクト: kleopatra999/gimp-gap
/* ------------------------------------
 * gap_image_get_any_layer
 * ------------------------------------
 * return the id of the active layer
 *   or the id of the first layer found in the image if there is no active layer
 *   or -1 if the image has no layer at all.
 */
gint32
gap_image_get_any_layer(gint32 image_id)
{
  gint32  l_layer_id;
  gint    l_nlayers;
  gint32 *l_layers_list;

  l_layer_id = gimp_image_get_active_layer(image_id);
  if(l_layer_id < 0)
  {
    l_layers_list = gimp_image_get_layers(image_id, &l_nlayers);
    if(l_layers_list != NULL)
    {
       l_layer_id = l_layers_list[0];
       g_free (l_layers_list);
    }
  }
  return (l_layer_id);
}  /* end gap_image_get_any_layer */
コード例 #3
0
ファイル: gimpimage-duplicate.c プロジェクト: Stibbons/gimp
static GimpLayer *
gimp_image_duplicate_layers (GimpImage *image,
                             GimpImage *new_image)
{
  GimpLayer *active_layer = NULL;
  GList     *list;
  gint       count;

  for (list = gimp_image_get_layer_iter (image), count = 0;
       list;
       list = g_list_next (list))
    {
      GimpLayer *layer = list->data;
      GimpLayer *new_layer;

      if (gimp_layer_is_floating_sel (layer))
        continue;

      new_layer = GIMP_LAYER (gimp_image_duplicate_item (GIMP_ITEM (layer),
                                                         new_image));

      /*  Make sure that if the layer has a layer mask,
       *  its name isn't screwed up
       */
      if (new_layer->mask)
        gimp_object_set_name (GIMP_OBJECT (new_layer->mask),
                              gimp_object_get_name (layer->mask));

      if (gimp_image_get_active_layer (image) == layer)
        active_layer = new_layer;

      gimp_image_add_layer (new_image, new_layer,
                            NULL, count++, FALSE);
    }

  return active_layer;
}
コード例 #4
0
static void preview_ambient_occlusion_only(gint32 image_ID) {
    gint32 drawable_ID = -1;
    gint32 drawableAO_ID = -1;
    
    gtk_label_set_text(GTK_LABEL(progress_label), "Mixing Colors");
    // preview_diffuse_only(image_ID);
    preview_normal_only(image_ID);
    // if (preview_normal_only(image_ID) != NULL) return NULL;
    drawable_ID = gimp_image_get_active_layer(image_ID);
    /** Copy active layer. */
    /** LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL */
    drawableAO_ID = gimp_layer_copy (drawable_ID);
    /** Add new layer to image. */
    gimp_image_add_layer(image_ID, drawableAO_ID, -1);
    /** Set new layer as active. */
    gimp_image_set_active_layer(image_ID, drawableAO_ID);

    /**
     * Colors ->  Components -> "Channel Mixer" applied
     * Standard plug-in. Source code ships with GIMP.
     * 
     * Add the "f" here to signify float in c language.
     * Removed 0.0 on first param and changed to 0 because boolean.
     */
    
    /** Explained on line ~1300 of InsaneBump.c */
    // if (plug_in_colors_channel_mixer_connector(image_ID, drawableAO_ID, 0, -200.0f, 0.0f, 0.0f, 0.0f, -200.0f, 0.0f, 0.0f, 0.0f, 1.0f) != 1) return;
    if (plug_in_colors_channel_mixer_connector(image_ID, drawableAO_ID, 0, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f) != 1) return;
    gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.87);
    
    gimp_desaturate(drawableAO_ID);
    gimp_levels_stretch(drawableAO_ID);
    
    pDrawables.drawable_ao = gimp_drawable_get(drawableAO_ID);
    gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.90);
}
コード例 #5
0
ファイル: gimpaligntool.c プロジェクト: kernc/gimp
static void
gimp_align_tool_align (GimpAlignTool     *align_tool,
                       GimpAlignmentType  align_type)
{
    GimpAlignOptions *options = GIMP_ALIGN_TOOL_GET_OPTIONS (align_tool);
    GimpImage        *image;
    GObject          *reference_object = NULL;
    GList            *list;
    gint              offset = 0;

    /* if nothing is selected, just return */
    if (! align_tool->selected_objects)
        return;

    image  = gimp_display_get_image (GIMP_TOOL (align_tool)->display);

    switch (align_type)
    {
    case GIMP_ALIGN_LEFT:
    case GIMP_ALIGN_HCENTER:
    case GIMP_ALIGN_RIGHT:
    case GIMP_ALIGN_TOP:
    case GIMP_ALIGN_VCENTER:
    case GIMP_ALIGN_BOTTOM:
        offset = 0;
        break;

    case GIMP_ARRANGE_LEFT:
    case GIMP_ARRANGE_HCENTER:
    case GIMP_ARRANGE_RIGHT:
    case GIMP_ARRANGE_TOP:
    case GIMP_ARRANGE_VCENTER:
    case GIMP_ARRANGE_BOTTOM:
    case GIMP_ARRANGE_HFILL:
    case GIMP_ARRANGE_VFILL:
        offset = options->offset_x;
        break;
    }

    /* if only one object is selected, use the image as reference
     * if multiple objects are selected, use the first one as reference if
     * "set_reference" is TRUE, otherwise use NULL.
     */

    list = align_tool->selected_objects;

    switch (options->align_reference)
    {
    case GIMP_ALIGN_REFERENCE_IMAGE:
        reference_object = G_OBJECT (image);
        break;

    case GIMP_ALIGN_REFERENCE_FIRST:
        if (g_list_length (list) == 1)
        {
            reference_object = G_OBJECT (image);
        }
        else
        {
            if (align_tool->set_reference)
            {
                reference_object = G_OBJECT (list->data);
                list = g_list_next (list);
            }
            else
            {
                reference_object = NULL;
            }
        }
        break;

    case GIMP_ALIGN_REFERENCE_SELECTION:
        reference_object = G_OBJECT (gimp_image_get_mask (image));
        break;

    case GIMP_ALIGN_REFERENCE_ACTIVE_LAYER:
        reference_object = G_OBJECT (gimp_image_get_active_layer (image));
        break;

    case GIMP_ALIGN_REFERENCE_ACTIVE_CHANNEL:
        reference_object = G_OBJECT (gimp_image_get_active_channel (image));
        break;

    case GIMP_ALIGN_REFERENCE_ACTIVE_PATH:
        reference_object = G_OBJECT (gimp_image_get_active_vectors (image));
        break;
    }

    if (! reference_object)
        return;

    gimp_draw_tool_pause (GIMP_DRAW_TOOL (align_tool));

    gimp_image_arrange_objects (image, list,
                                align_type,
                                reference_object,
                                align_type,
                                offset);

    gimp_draw_tool_resume (GIMP_DRAW_TOOL (align_tool));

    gimp_image_flush (image);
}
コード例 #6
0
ファイル: gimpimage-merge.c プロジェクト: jdburton/gimp-osx
GimpLayer *
gimp_image_merge_visible_layers (GimpImage     *image,
                                 GimpContext   *context,
                                 GimpMergeType  merge_type,
                                 gboolean       discard_invisible)
{
  GList     *list;
  GSList    *merge_list       = NULL;
  GSList    *invisible_list   = NULL;
  gboolean   had_floating_sel = FALSE;
  GimpLayer *layer            = NULL;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);

  /* if there's a floating selection, anchor it */
  if (gimp_image_floating_sel (image))
    {
      floating_sel_anchor (image->floating_sel);
      had_floating_sel = TRUE;
    }

  for (list = GIMP_LIST (image->layers)->list;
       list;
       list = g_list_next (list))
    {
      layer = list->data;

      if (gimp_item_get_visible (GIMP_ITEM (layer)))
        {
          merge_list = g_slist_append (merge_list, layer);
        }
      else if (discard_invisible)
        {
          invisible_list = g_slist_append (invisible_list, layer);
        }
    }

  if (merge_list)
    {
      const gchar *undo_desc = _("Merge Visible Layers");

      gimp_set_busy (image->gimp);

      if (invisible_list)
        {
          gimp_image_undo_group_start (image,
                                       GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE,
                                       undo_desc);
        }

      layer = gimp_image_merge_layers (image, merge_list, context, merge_type,
                                       _("Merge Visible Layers"));
      g_slist_free (merge_list);

      if (invisible_list)
        {
          GSList *list;

          for (list = invisible_list; list; list = g_slist_next (list))
            gimp_image_remove_layer (image, list->data);

          gimp_image_undo_group_end (image);
          g_slist_free (invisible_list);
        }


      gimp_unset_busy (image->gimp);

      return layer;
    }

  return gimp_image_get_active_layer (image);
}
コード例 #7
0
GimpLayer *
gimp_image_merge_visible_layers (GimpImage     *image,
                                 GimpContext   *context,
                                 GimpMergeType  merge_type,
                                 gboolean       merge_active_group,
                                 gboolean       discard_invisible)
{
  GimpContainer *container;
  GList         *list;
  GSList        *merge_list     = NULL;
  GSList        *invisible_list = NULL;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);

  if (merge_active_group)
    {
      GimpLayer *active_layer = gimp_image_get_active_layer (image);

      /*  if the active layer is the floating selection, get the
       *  underlying drawable, but only if it is a layer
       */
      if (active_layer && gimp_layer_is_floating_sel (active_layer))
        {
          GimpDrawable *fs_drawable;

          fs_drawable = gimp_layer_get_floating_sel_drawable (active_layer);

          if (GIMP_IS_LAYER (fs_drawable))
            active_layer = GIMP_LAYER (fs_drawable);
        }

      if (active_layer)
        container = gimp_item_get_container (GIMP_ITEM (active_layer));
      else
        container = gimp_image_get_layers (image);
    }
  else
    {
      container = gimp_image_get_layers (image);
    }

  for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (container));
       list;
       list = g_list_next (list))
    {
      GimpLayer *layer = list->data;

      if (gimp_layer_is_floating_sel (layer))
        continue;

      if (gimp_item_get_visible (GIMP_ITEM (layer)))
        {
          merge_list = g_slist_append (merge_list, layer);
        }
      else if (discard_invisible)
        {
          invisible_list = g_slist_append (invisible_list, layer);
        }
    }

  if (merge_list)
    {
      GimpLayer *layer;

      gimp_set_busy (image->gimp);

      gimp_image_undo_group_start (image,
                                   GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE,
                                   C_("undo-type", "Merge Visible Layers"));

      /* if there's a floating selection, anchor it */
      if (gimp_image_get_floating_selection (image))
        floating_sel_anchor (gimp_image_get_floating_selection (image));

      layer = gimp_image_merge_layers (image,
                                       container,
                                       merge_list, context, merge_type);
      g_slist_free (merge_list);

      if (invisible_list)
        {
          GSList *list;

          for (list = invisible_list; list; list = g_slist_next (list))
            gimp_image_remove_layer (image, list->data, TRUE, NULL);

          g_slist_free (invisible_list);
        }

      gimp_image_undo_group_end (image);

      gimp_unset_busy (image->gimp);

      return layer;
    }

  return gimp_image_get_active_layer (image);
}
コード例 #8
0
ファイル: layers-actions.c プロジェクト: Amerekanets/gimp
void
layers_actions_update (GimpActionGroup *group,
                       gpointer         data)
{
  GimpImage     *image     = action_data_get_image (data);
  GimpLayer     *layer      = NULL;
  GimpLayerMask *mask       = NULL;     /*  layer mask             */
  gboolean       fs         = FALSE;    /*  floating sel           */
  gboolean       ac         = FALSE;    /*  active channel         */
  gboolean       sel        = FALSE;
  gboolean       alpha      = FALSE;    /*  alpha channel present  */
  gboolean       indexed    = FALSE;    /*  is indexed             */
  gboolean       lock_alpha = FALSE;
  gboolean       text_layer = FALSE;
  GList         *next       = NULL;
  GList         *prev       = NULL;

  if (image)
    {
      fs      = (gimp_image_floating_sel (image) != NULL);
      ac      = (gimp_image_get_active_channel (image) != NULL);
      sel     = ! gimp_channel_is_empty (gimp_image_get_mask (image));
      indexed = (gimp_image_base_type (image) == GIMP_INDEXED);

      layer = gimp_image_get_active_layer (image);

      if (layer)
        {
          GList *list;

          mask       = gimp_layer_get_mask (layer);
          lock_alpha = gimp_layer_get_lock_alpha (layer);
          alpha      = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));

          list = g_list_find (GIMP_LIST (image->layers)->list, layer);

          if (list)
            {
              prev = g_list_previous (list);
              next = g_list_next (list);
            }

          if (layer)
            text_layer = gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer));
        }
    }

#define SET_VISIBLE(action,condition) \
        gimp_action_group_set_action_visible (group, action, (condition) != 0)
#define SET_SENSITIVE(action,condition) \
        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
#define SET_ACTIVE(action,condition) \
        gimp_action_group_set_action_active (group, action, (condition) != 0)

  SET_VISIBLE   ("layers-text-tool",       text_layer && !ac);
  SET_SENSITIVE ("layers-edit-attributes", layer && !fs && !ac);

  SET_SENSITIVE ("layers-new",             image);
  SET_SENSITIVE ("layers-new-last-values", image);
  SET_SENSITIVE ("layers-duplicate",       layer && !fs && !ac);
  SET_SENSITIVE ("layers-delete",          layer && !ac);

  SET_SENSITIVE ("layers-select-top",      layer && !fs && !ac && prev);
  SET_SENSITIVE ("layers-select-bottom",   layer && !fs && !ac && next);
  SET_SENSITIVE ("layers-select-previous", layer && !fs && !ac && prev);
  SET_SENSITIVE ("layers-select-next",     layer && !fs && !ac && next);

  SET_SENSITIVE ("layers-raise",           layer && !fs && !ac && prev);
  SET_SENSITIVE ("layers-raise-to-top",    layer && !fs && !ac && prev);
  SET_SENSITIVE ("layers-lower",           layer && !fs && !ac && next);
  SET_SENSITIVE ("layers-lower-to-bottom", layer && !fs && !ac && next);

  SET_SENSITIVE ("layers-anchor",          layer &&  fs && !ac);
  SET_SENSITIVE ("layers-merge-down",      layer && !fs && !ac && next);
  SET_SENSITIVE ("layers-merge-layers",    layer && !fs && !ac);
  SET_SENSITIVE ("layers-flatten-image",   layer && !fs && !ac);

  SET_VISIBLE   ("layers-text-discard",             text_layer && !ac);
  SET_VISIBLE   ("layers-text-to-vectors",          text_layer && !ac);
  SET_VISIBLE   ("layers-text-along-vectors",       text_layer && !ac);
  SET_VISIBLE   ("layers-text-selection-replace",   text_layer && !ac);
  SET_VISIBLE   ("layers-text-selection-add",       text_layer && !ac);
  SET_VISIBLE   ("layers-text-selection-subtract",  text_layer && !ac);
  SET_VISIBLE   ("layers-text-selection-intersect", text_layer && !ac);

  SET_SENSITIVE ("layers-resize",          layer && !ac);
  SET_SENSITIVE ("layers-resize-to-image", layer && !ac);
  SET_SENSITIVE ("layers-scale",           layer && !ac);

  SET_SENSITIVE ("layers-crop",            layer && sel);

  SET_SENSITIVE ("layers-alpha-add",       layer && !fs && !alpha);
  SET_SENSITIVE ("layers-alpha-remove",    layer && !fs &&  alpha);

  SET_SENSITIVE ("layers-lock-alpha", layer);
  SET_ACTIVE    ("layers-lock-alpha", lock_alpha);

  SET_SENSITIVE ("layers-mask-add",    layer && !fs && !ac && !mask);
  SET_SENSITIVE ("layers-mask-apply",  layer && !fs && !ac &&  mask);
  SET_SENSITIVE ("layers-mask-delete", layer && !fs && !ac &&  mask);

  SET_SENSITIVE ("layers-mask-edit",    layer && !fs && !ac &&  mask);
  SET_SENSITIVE ("layers-mask-show",    layer && !fs && !ac &&  mask);
  SET_SENSITIVE ("layers-mask-disable", layer && !fs && !ac &&  mask);

  SET_ACTIVE ("layers-mask-edit",    mask && gimp_layer_mask_get_edit (mask));
  SET_ACTIVE ("layers-mask-show",    mask && gimp_layer_mask_get_show (mask));
  SET_ACTIVE ("layers-mask-disable", mask && !gimp_layer_mask_get_apply (mask));

  SET_SENSITIVE ("layers-mask-selection-replace",   layer && !fs && !ac && mask);
  SET_SENSITIVE ("layers-mask-selection-add",       layer && !fs && !ac && mask);
  SET_SENSITIVE ("layers-mask-selection-subtract",  layer && !fs && !ac && mask);
  SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask);

  SET_SENSITIVE ("layers-alpha-selection-replace",   layer && !fs && !ac);
  SET_SENSITIVE ("layers-alpha-selection-add",       layer && !fs && !ac);
  SET_SENSITIVE ("layers-alpha-selection-subtract",  layer && !fs && !ac);
  SET_SENSITIVE ("layers-alpha-selection-intersect", layer && !fs && !ac);

#undef SET_VISIBLE
#undef SET_SENSITIVE
#undef SET_ACTIVE
}
コード例 #9
0
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);
}
コード例 #10
0
static void
gimp_move_tool_cursor_update (GimpTool         *tool,
                              const GimpCoords *coords,
                              GdkModifierType   state,
                              GimpDisplay      *display)
{
  GimpMoveOptions    *options     = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
  GimpDisplayShell   *shell       = gimp_display_get_shell (display);
  GimpImage          *image       = gimp_display_get_image (display);
  GimpCursorType      cursor      = GIMP_CURSOR_MOUSE;
  GimpToolCursorType  tool_cursor = GIMP_TOOL_CURSOR_MOVE;
  GimpCursorModifier  modifier    = GIMP_CURSOR_MODIFIER_NONE;

  if (options->move_type == GIMP_TRANSFORM_TYPE_PATH)
    {
      tool_cursor = GIMP_TOOL_CURSOR_PATHS;
      modifier    = GIMP_CURSOR_MODIFIER_MOVE;

      if (options->move_current)
        {
          if (! gimp_image_get_active_vectors (image))
            modifier = GIMP_CURSOR_MODIFIER_BAD;
        }
      else
        {
          if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
                                         coords, 7, 7,
                                         NULL, NULL, NULL, NULL, NULL, NULL))
            {
              tool_cursor = GIMP_TOOL_CURSOR_HAND;
            }
          else
            {
              modifier = GIMP_CURSOR_MODIFIER_BAD;
            }
        }
    }
  else if (options->move_type == GIMP_TRANSFORM_TYPE_SELECTION)
    {
      tool_cursor = GIMP_TOOL_CURSOR_RECT_SELECT;
      modifier    = GIMP_CURSOR_MODIFIER_MOVE;

      if (gimp_channel_is_empty (gimp_image_get_mask (image)))
        modifier = GIMP_CURSOR_MODIFIER_BAD;
    }
  else if (options->move_current)
    {
      if (! gimp_image_get_active_drawable (image))
        modifier = GIMP_CURSOR_MODIFIER_BAD;
    }
  else
    {
      GimpGuide  *guide;
      GimpLayer  *layer;
      const gint  snap_distance = display->config->snap_distance;

      if (gimp_display_shell_get_show_guides (shell) &&
          (guide = gimp_image_find_guide (image, coords->x, coords->y,
                                          FUNSCALEX (shell, snap_distance),
                                          FUNSCALEY (shell, snap_distance))))
        {
          tool_cursor = GIMP_TOOL_CURSOR_HAND;
          modifier    = GIMP_CURSOR_MODIFIER_MOVE;
        }
      else if ((layer = gimp_image_pick_layer (image,
                                               coords->x, coords->y)))
        {
          /*  if there is a floating selection, and this aint it...  */
          if (gimp_image_get_floating_selection (image) &&
              ! gimp_layer_is_floating_sel (layer))
            {
              tool_cursor = GIMP_TOOL_CURSOR_MOVE;
              modifier    = GIMP_CURSOR_MODIFIER_ANCHOR;
            }
          else if (layer != gimp_image_get_active_layer (image))
            {
              tool_cursor = GIMP_TOOL_CURSOR_HAND;
              modifier    = GIMP_CURSOR_MODIFIER_MOVE;
            }
        }
      else
        {
          modifier = GIMP_CURSOR_MODIFIER_BAD;
        }
    }

  gimp_tool_control_set_cursor          (tool->control, cursor);
  gimp_tool_control_set_tool_cursor     (tool->control, tool_cursor);
  gimp_tool_control_set_cursor_modifier (tool->control, modifier);

  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
コード例 #11
0
ファイル: gimpexport.c プロジェクト: AdamGrzonkowski/gimp-1
/**
 * gimp_export_image:
 * @image_ID: Pointer to the image_ID.
 * @drawable_ID: Pointer to the drawable_ID.
 * @format_name: The (short) name of the image_format (e.g. JPEG or GIF).
 * @capabilities: What can the image_format do?
 *
 * Takes an image and a drawable to be saved together with a
 * description of the capabilities of the image_format. If the
 * type of image doesn't match the capabilities of the format
 * a dialog is opened that informs the user that the image has
 * to be exported and offers to do the necessary conversions.
 *
 * If the user chooses to export the image, a copy is created.
 * This copy is then converted, the image_ID and drawable_ID
 * are changed to point to the new image and the procedure returns
 * GIMP_EXPORT_EXPORT. The save_plugin has to take care of deleting the
 * created image using gimp_image_delete() when it has saved it.
 *
 * If the user chooses to Ignore the export problem, the image_ID
 * and drawable_ID is not altered, GIMP_EXPORT_IGNORE is returned and
 * the save_plugin should try to save the original image. If the
 * user chooses Cancel, GIMP_EXPORT_CANCEL is returned and the
 * save_plugin should quit itself with status %GIMP_PDB_CANCEL.
 *
 * If @format_name is NULL, no dialogs will be shown and this function
 * will behave as if the user clicked on the 'Export' button, if a
 * dialog would have been shown.
 *
 * Returns: An enum of #GimpExportReturn describing the user_action.
 **/
GimpExportReturn
gimp_export_image (gint32                 *image_ID,
                   gint32                 *drawable_ID,
                   const gchar            *format_name,
                   GimpExportCapabilities  capabilities)
{
  GSList            *actions = NULL;
  GimpImageBaseType  type;
  gint32             i;
  gint32             n_layers;
  gint32            *layers;
  gboolean           interactive          = FALSE;
  gboolean           added_flatten        = FALSE;
  gboolean           has_layer_masks      = FALSE;
  gboolean           background_has_alpha = TRUE;
  GimpExportReturn   retval               = GIMP_EXPORT_CANCEL;

  g_return_val_if_fail (*image_ID > -1 && *drawable_ID > -1, FALSE);

  /* do some sanity checks */
  if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
    capabilities |= GIMP_EXPORT_CAN_HANDLE_ALPHA;

  if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION)
    capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS;

  if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS)
    capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS;

  if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS)
    capabilities |= GIMP_EXPORT_CAN_HANDLE_ALPHA;

  if (format_name && g_getenv ("GIMP_INTERACTIVE_EXPORT"))
    interactive = TRUE;

  /* ask for confirmation if the user is not saving a layer (see bug #51114) */
  if (interactive &&
      ! gimp_item_is_layer (*drawable_ID) &&
      ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
    {
      if (gimp_item_is_layer_mask (*drawable_ID))
        {
          retval = confirm_save_dialog
            (_("You are about to save a layer mask as %s.\n"
               "This will not save the visible layers."), format_name);
        }
      else if (gimp_item_is_channel (*drawable_ID))
        {
          retval = confirm_save_dialog
            (_("You are about to save a channel (saved selection) as %s.\n"
               "This will not save the visible layers."), format_name);
        }
      else
        {
          /* this should not happen */
          g_warning ("%s: unknown drawable type!", G_STRFUNC);
        }

      /* cancel - the user can then select an appropriate layer to save */
      if (retval == GIMP_EXPORT_CANCEL)
        return GIMP_EXPORT_CANCEL;
    }


  /* check alpha and layer masks */
  layers = gimp_image_get_layers (*image_ID, &n_layers);

  for (i = 0; i < n_layers; i++)
    {
      if (gimp_drawable_has_alpha (layers[i]))
        {
          if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_ALPHA))
            {
              actions = g_slist_prepend (actions, &export_action_flatten);
              added_flatten = TRUE;
              break;
            }
        }
      else
        {
          /*  If this is the last layer, it's visible and has no alpha
           *  channel, then the image has a "flat" background
           */
          if (i == n_layers - 1 && gimp_item_get_visible (layers[i]))
            background_has_alpha = FALSE;

          if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
            {
              actions = g_slist_prepend (actions, &export_action_add_alpha);
              break;
            }
        }
    }

  if (! added_flatten)
    {
      for (i = 0; i < n_layers; i++)
        {
          if (gimp_layer_get_mask (layers[i]) != -1)
            has_layer_masks = TRUE;
        }
    }

  if (! added_flatten)
    {
      gint32  n_children;
      gint32 *children;

      children = gimp_item_get_children (layers[0], &n_children);

      /* check if layer size != canvas size, opacity != 100%, or offsets != 0 */
      if (n_layers == 1                     &&
          ! children                        &&
          gimp_item_is_layer (*drawable_ID) &&
          ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
        {
          gint offset_x;
          gint offset_y;

          gimp_drawable_offsets (*drawable_ID, &offset_x, &offset_y);

          if ((gimp_layer_get_opacity (*drawable_ID) < 100.0) ||
              (gimp_image_width (*image_ID) !=
               gimp_drawable_width (*drawable_ID))            ||
              (gimp_image_height (*image_ID) !=
               gimp_drawable_height (*drawable_ID))           ||
              offset_x || offset_y)
            {
              if (capabilities & GIMP_EXPORT_CAN_HANDLE_ALPHA)
                {
                  actions = g_slist_prepend (actions,
                                             &export_action_merge_single);
                }
              else
                {
                  actions = g_slist_prepend (actions,
                                             &export_action_flatten);
                }
            }
        }
      /* check multiple layers */
      else if (n_layers > 1)
        {
          if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION)
            {
              if (background_has_alpha ||
                  capabilities & GIMP_EXPORT_NEEDS_ALPHA)
                actions = g_slist_prepend (actions,
                                           &export_action_animate_or_merge);
              else
                actions = g_slist_prepend (actions,
                                           &export_action_animate_or_flatten);
            }
          else if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
            {
              if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
                actions = g_slist_prepend (actions,
                                           &export_action_merge);
              else
                actions = g_slist_prepend (actions,
                                           &export_action_merge_or_flatten);
            }
        }
      /* check for a single toplevel layer group */
      else if (children)
        {
          if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
            {
              if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
                actions = g_slist_prepend (actions,
                                           &export_action_merge);
              else
                actions = g_slist_prepend (actions,
                                           &export_action_merge_or_flatten);
            }
        }

      g_free (children);

      /* check layer masks */
      if (has_layer_masks &&
          ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS))
        actions = g_slist_prepend (actions, &export_action_apply_masks);
    }

  g_free (layers);

  /* check the image type */
  type = gimp_image_base_type (*image_ID);
  switch (type)
    {
    case GIMP_RGB:
      if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_RGB))
        {
          if ((capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED) &&
              (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY))
            actions = g_slist_prepend (actions,
                                       &export_action_convert_indexed_or_grayscale);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED)
            actions = g_slist_prepend (actions,
                                       &export_action_convert_indexed);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY)
            actions = g_slist_prepend (actions,
                                       &export_action_convert_grayscale);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_BITMAP)
            actions = g_slist_prepend (actions,
                                       &export_action_convert_bitmap);
        }
      break;

    case GIMP_GRAY:
      if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY))
        {
          if ((capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) &&
              (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED))
            actions = g_slist_prepend (actions,
                                       &export_action_convert_rgb_or_indexed);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_RGB)
            actions = g_slist_prepend (actions,
                                       &export_action_convert_rgb);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED)
            actions = g_slist_prepend (actions,
                                       &export_action_convert_indexed);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_BITMAP)
            actions = g_slist_prepend (actions,
                                       &export_action_convert_bitmap);
        }
      break;

    case GIMP_INDEXED:
      if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED))
        {
          if ((capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) &&
              (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY))
            actions = g_slist_prepend (actions,
                                       &export_action_convert_rgb_or_grayscale);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_RGB)
            actions = g_slist_prepend (actions,
                                       &export_action_convert_rgb);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY)
            actions = g_slist_prepend (actions,
                                       &export_action_convert_grayscale);
          else if (capabilities & GIMP_EXPORT_CAN_HANDLE_BITMAP)
            {
              gint n_colors;

              g_free (gimp_image_get_colormap (*image_ID, &n_colors));

              if (n_colors > 2)
                actions = g_slist_prepend (actions,
                                           &export_action_convert_bitmap);
            }
        }
      break;
    }

  if (actions)
    {
      actions = g_slist_reverse (actions);

      if (interactive)
        retval = export_dialog (actions, format_name);
      else
        retval = GIMP_EXPORT_EXPORT;
    }
  else
    {
      retval = GIMP_EXPORT_IGNORE;
    }

  if (retval == GIMP_EXPORT_EXPORT)
    {
      GSList *list;

      *image_ID = gimp_image_duplicate (*image_ID);
      *drawable_ID = gimp_image_get_active_layer (*image_ID);

      gimp_image_undo_disable (*image_ID);

      for (list = actions; list; list = list->next)
        {
          export_action_perform (list->data, *image_ID, drawable_ID);
        }
    }

  g_slist_free (actions);

  return retval;
}
コード例 #12
0
ファイル: jpeg_compress.c プロジェクト: possiblyphilip/Koi
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;
}
コード例 #13
0
ファイル: jpeg_compress.c プロジェクト: possiblyphilip/Koi
void * jpeg_highlighter_analyze(JOB_ARG *job)
{
	int ii, jj, kk;
	int row;
	int col;

	long long red_sum = 0;
	long long green_sum = 0;
	long long blue_sum = 0;

	guchar max_pixel_color[4];

	union
	{
		guchar pixel[4];
		unsigned int value;
	} stuff;

	gint32 layer_id;
	int temp = 0;
	int unique_compressed_colors = 0;
	int unique_original_colors = 0;

	int *histogram;

	max_pixel_color[0] = 0;
	max_pixel_color[1] = 0;
	max_pixel_color[2] = 0;
	max_pixel_color[3] = 0;

	histogram = (int*)malloc(sizeof(int)*255*255*255);
//
//	GimpRunMode mode = GIMP_RUN_NONINTERACTIVE;
//	PIXEL **temp_array;
GimpPixelRgn rgn_in;

	printf("in analizer\n");

	job->drawable->drawable_id = gimp_image_get_active_drawable(job->image_id);

	layer_id = gimp_image_get_active_layer(job->image_id);

//	printf("adding alpha channel\n");
//	gimp_layer_add_alpha(layer_id);
//
//
////	if(! gimp_drawable_has_alpha (layer_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_id);
////		  printf("adding alpha channel\n");
////   }


	printf("zeroed array\n");

	for(ii = 0; ii < 255*255*255; ii++)
	{
		histogram[ii] = 0;
	}

	gimp_pixel_rgn_init(&rgn_in, job->drawable, job->start_colum, job->start_row, job->image.width, job->image.height, FALSE, FALSE);

	for (row = 0; row < job->image.height; row++)
	{
		for (col = 0; col < job->image.width; col++)
		{
			gimp_pixel_rgn_get_pixel (&rgn_in, stuff.pixel, col,row);

			job->array_out[col][row].red = stuff.pixel[0];
			job->array_out[col][row].green = stuff.pixel[1];
			job->array_out[col][row].blue = stuff.pixel[2];

			red_sum += stuff.pixel[0];
			green_sum += stuff.pixel[1];
			blue_sum += stuff.pixel[2];

			stuff.pixel[3] = 0;

			if(stuff.pixel[0] + stuff.pixel[1]+ stuff.pixel[2] > max_pixel_color[0] +  max_pixel_color[1] +  max_pixel_color[2] )
			{
				max_pixel_color[0] = stuff.pixel[0];
				max_pixel_color[1] = stuff.pixel[1];
				max_pixel_color[2] = stuff.pixel[2];
			}

			histogram[stuff.value]++;

		}

		if (row % 50 == 0)
		{
			gimp_progress_update ((gdouble) row / job->image.height);

		}
	}

	for(ii = 0; ii < 255*255*255; ii++)
	{	
		if(histogram[ii] != 0)
		{
			unique_compressed_colors++;
		}
	}

	//doing the original

	printf("zeroed array\n");

	for(ii = 0; ii < 255*255*255; ii++)
	{
		histogram[ii] = 0;
	}


	for (row = 0; row < job->image.height; row++)
	{
		for (col = 0; col < job->image.width; col++)
		{
			stuff.pixel[0] = job->array_in[col][row].red;
			stuff.pixel[1] = job->array_in[col][row].green;
			stuff.pixel[2] = job->array_in[col][row].blue;

			stuff.pixel[3] = 0;

			histogram[stuff.value]++;

		}
	}

	for(ii = 0; ii < 255*255*255; ii++)
	{
		if(histogram[ii] != 0)
		{
			unique_original_colors++;
		}
	}

	free(histogram);

	print_log("\nJpeg compression difference\n",temp);
	print_log("unique colors in original image:%d\n",unique_original_colors);
	print_log("unique colors in compressed image:%d\n",unique_compressed_colors);
	print_log("ratio: %f\n",(double)unique_original_colors/unique_compressed_colors);
	print_log("brightest compressed color %d %d %d\n",max_pixel_color[0], max_pixel_color[1], max_pixel_color[2]);
	print_log("avg compressed color %f %f %f\n",(float)red_sum/(job->image.height*job->image.width), (float)green_sum/(job->image.height*job->image.width),(float)blue_sum/(job->image.height*job->image.width));
}
コード例 #14
0
static void
gimp_histogram_editor_layer_changed (GimpImage           *image,
                                     GimpHistogramEditor *editor)
{
  if (editor->drawable)
    {
      if (editor->bg_histogram)
        {
          GimpHistogramView *view = GIMP_HISTOGRAM_BOX (editor->box)->view;

          gimp_histogram_unref (editor->bg_histogram);
          editor->bg_histogram = NULL;

          gimp_histogram_view_set_background (view, NULL);
        }

      g_signal_handlers_disconnect_by_func (editor->drawable,
                                            gimp_histogram_editor_name_update,
                                            editor);
      g_signal_handlers_disconnect_by_func (editor->drawable,
                                            gimp_histogram_editor_menu_update,
                                            editor);
      g_signal_handlers_disconnect_by_func (editor->drawable,
                                            gimp_histogram_editor_update,
                                            editor);
      g_signal_handlers_disconnect_by_func (editor->drawable,
                                            gimp_histogram_editor_frozen_update,
                                            editor);
      editor->drawable = NULL;
    }

  if (image)
    editor->drawable = (GimpDrawable *) gimp_image_get_active_layer (image);

  gimp_histogram_editor_menu_update (editor);

  if (editor->drawable)
    {
      g_signal_connect_object (editor->drawable, "notify::frozen",
                               G_CALLBACK (gimp_histogram_editor_frozen_update),
                               editor, G_CONNECT_SWAPPED);
      g_signal_connect_object (editor->drawable, "update",
                               G_CALLBACK (gimp_histogram_editor_update),
                               editor, G_CONNECT_SWAPPED);
      g_signal_connect_object (editor->drawable, "alpha-changed",
                               G_CALLBACK (gimp_histogram_editor_menu_update),
                               editor, G_CONNECT_SWAPPED);
      g_signal_connect_object (editor->drawable, "name-changed",
                               G_CALLBACK (gimp_histogram_editor_name_update),
                               editor, G_CONNECT_SWAPPED);

      gimp_histogram_editor_update (editor);
    }
  else if (editor->histogram)
    {
      editor->valid = FALSE;
      gtk_widget_queue_draw (GTK_WIDGET (editor->box));
    }

  gimp_histogram_editor_info_update (editor);
  gimp_histogram_editor_name_update (editor);
}
コード例 #15
0
static void
palette_import_make_palette (ImportDialog *dialog)
{
  GimpPalette  *palette = NULL;
  const gchar  *palette_name;
  gint          n_colors;
  gint          n_columns;
  gint          threshold;

  palette_name = gtk_entry_get_text (GTK_ENTRY (dialog->entry));

  if (! palette_name || ! strlen (palette_name))
    palette_name = _("Untitled");

  n_colors  = ROUND (gtk_adjustment_get_value (dialog->num_colors));
  n_columns = ROUND (gtk_adjustment_get_value (dialog->columns));
  threshold = ROUND (gtk_adjustment_get_value (dialog->threshold));

  switch (dialog->import_type)
    {
    case GRADIENT_IMPORT:
      {
        GimpGradient *gradient;

        gradient = gimp_context_get_gradient (dialog->context);

        palette = gimp_palette_import_from_gradient (gradient,
                                                     dialog->context,
                                                     FALSE,
                                                     palette_name,
                                                     n_colors);
      }
      break;

    case IMAGE_IMPORT:
      {
        GimpImage *image = gimp_context_get_image (dialog->context);
        gboolean   sample_merged;
        gboolean   selection_only;

        sample_merged =
          gtk_toggle_button_get_active
          (GTK_TOGGLE_BUTTON (dialog->sample_merged_toggle));

        selection_only =
          gtk_toggle_button_get_active
          (GTK_TOGGLE_BUTTON (dialog->selection_only_toggle));

        if (gimp_image_get_base_type (image) == GIMP_INDEXED)
          {
            palette = gimp_palette_import_from_indexed_image (image,
                                                              dialog->context,
                                                              palette_name);
          }
        else if (sample_merged)
          {
            palette = gimp_palette_import_from_image (image,
                                                      dialog->context,
                                                      palette_name,
                                                      n_colors,
                                                      threshold,
                                                      selection_only);
          }
        else
          {
            GimpDrawable *drawable;

            drawable = GIMP_DRAWABLE (gimp_image_get_active_layer (image));

            palette = gimp_palette_import_from_drawable (drawable,
                                                         dialog->context,
                                                         palette_name,
                                                         n_colors,
                                                         threshold,
                                                         selection_only);
          }
      }
      break;

    case FILE_IMPORT:
      {
        GFile  *file;
        GError *error = NULL;

        file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog->file_chooser));

        palette = gimp_palette_import_from_file (dialog->context,
                                                 file,
                                                 palette_name, &error);
        g_object_unref (file);

        if (! palette)
          {
            gimp_message_literal (dialog->context->gimp,
                                  G_OBJECT (dialog->dialog), GIMP_MESSAGE_ERROR,
                                  error->message);
            g_error_free (error);
          }
      }
      break;
    }

  if (palette)
    {
      if (dialog->palette)
        g_object_unref (dialog->palette);

      gimp_palette_set_columns (palette, n_columns);

      gimp_view_set_viewable (GIMP_VIEW (dialog->preview),
                              GIMP_VIEWABLE (palette));

      dialog->palette = palette;
    }

  gtk_widget_set_visible (dialog->no_colors_label,
                          dialog->palette &&
                          gimp_palette_get_n_colors (dialog->palette) > 0);
}
コード例 #16
0
static void
gimp_move_tool_button_press (GimpTool            *tool,
                             const GimpCoords    *coords,
                             guint32              time,
                             GdkModifierType      state,
                             GimpButtonPressType  press_type,
                             GimpDisplay         *display)
{
  GimpMoveTool     *move    = GIMP_MOVE_TOOL (tool);
  GimpMoveOptions  *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
  GimpDisplayShell *shell   = gimp_display_get_shell (display);
  GimpImage        *image   = gimp_display_get_image (display);

  tool->display = display;

  move->floating_layer     = NULL;
  move->guide              = NULL;
  move->moving_guide       = FALSE;
  move->old_active_layer   = NULL;
  move->old_active_vectors = NULL;

  if (! options->move_current)
    {
      if (options->move_type == GIMP_TRANSFORM_TYPE_PATH)
        {
          GimpVectors *vectors;

          if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display,
                                         coords, 7, 7,
                                         NULL, NULL, NULL, NULL, NULL,
                                         &vectors))
            {
              move->old_active_vectors =
                gimp_image_get_active_vectors (image);

              gimp_image_set_active_vectors (image, vectors);
            }
          else
            {
              /*  no path picked  */
              return;
            }
        }
      else if (options->move_type == GIMP_TRANSFORM_TYPE_LAYER)
        {
          GimpGuide  *guide;
          GimpLayer  *layer;
          const gint  snap_distance = display->config->snap_distance;

          if (gimp_display_shell_get_show_guides (shell) &&
              (guide = gimp_image_find_guide (image,
                                              coords->x, coords->y,
                                              FUNSCALEX (shell, snap_distance),
                                              FUNSCALEY (shell, snap_distance))))
            {
              move->guide             = guide;
              move->moving_guide      = TRUE;
              move->guide_position    = gimp_guide_get_position (guide);
              move->guide_orientation = gimp_guide_get_orientation (guide);

              gimp_tool_control_set_scroll_lock (tool->control, TRUE);
              gimp_tool_control_set_precision   (tool->control,
                                                 GIMP_CURSOR_PRECISION_PIXEL_BORDER);

              gimp_tool_control_activate (tool->control);

              gimp_display_shell_selection_pause (shell);

              gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);

              gimp_tool_push_status_length (tool, display,
                                            _("Move Guide: "),
                                            SWAP_ORIENT (move->guide_orientation),
                                            move->guide_position,
                                            NULL);

              return;
            }
          else if ((layer = gimp_image_pick_layer (image,
                                                   coords->x,
                                                   coords->y)))
            {
              if (gimp_image_get_floating_selection (image) &&
                  ! gimp_layer_is_floating_sel (layer))
                {
                  /*  If there is a floating selection, and this aint it,
                   *  use the move tool to anchor it.
                   */
                  move->floating_layer =
                    gimp_image_get_floating_selection (image);

                  gimp_tool_control_activate (tool->control);

                  return;
                }
              else
                {
                  move->old_active_layer = gimp_image_get_active_layer (image);

                  gimp_image_set_active_layer (image, layer);
                }
            }
          else
            {
              /*  no guide and no layer picked  */

              return;
            }
        }
    }

  switch (options->move_type)
    {
    case GIMP_TRANSFORM_TYPE_PATH:
      if (gimp_image_get_active_vectors (image))
        gimp_edit_selection_tool_start (tool, display, coords,
                                        GIMP_TRANSLATE_MODE_VECTORS, TRUE);
      break;

    case GIMP_TRANSFORM_TYPE_SELECTION:
      if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
        gimp_edit_selection_tool_start (tool, display, coords,
                                        GIMP_TRANSLATE_MODE_MASK, TRUE);
      break;

    case GIMP_TRANSFORM_TYPE_LAYER:
      {
        GimpDrawable *drawable = gimp_image_get_active_drawable (image);

        if (GIMP_IS_LAYER_MASK (drawable))
          gimp_edit_selection_tool_start (tool, display, coords,
                                          GIMP_TRANSLATE_MODE_LAYER_MASK, TRUE);
        else if (GIMP_IS_CHANNEL (drawable))
          gimp_edit_selection_tool_start (tool, display, coords,
                                          GIMP_TRANSLATE_MODE_CHANNEL, TRUE);
        else if (GIMP_IS_LAYER (drawable))
          gimp_edit_selection_tool_start (tool, display, coords,
                                          GIMP_TRANSLATE_MODE_LAYER, TRUE);
      }
      break;
    }
}
コード例 #17
0
ファイル: gimpimage-crop.c プロジェクト: jdburton/gimp-osx
void
gimp_image_crop (GimpImage   *image,
                 GimpContext *context,
                 gint         x1,
                 gint         y1,
                 gint         x2,
                 gint         y2,
                 gboolean     active_layer_only,
                 gboolean     crop_layers)
{
  gint width, height;
  gint previous_width, previous_height;

  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (GIMP_IS_CONTEXT (context));

  previous_width  = gimp_image_get_width (image);
  previous_height = gimp_image_get_height (image);

  width  = x2 - x1;
  height = y2 - y1;

  /*  Make sure new width and height are non-zero  */
  if (width < 1 || height < 1)
    return;

  gimp_set_busy (image->gimp);

  if (active_layer_only)
    {
      GimpLayer *layer;
      gint       off_x, off_y;

      layer = gimp_image_get_active_layer (image);

      gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);

      off_x -= x1;
      off_y -= y1;

      gimp_item_resize (GIMP_ITEM (layer), context, width, height, off_x, off_y);
    }
  else
    {
      GimpItem *item;
      GList    *list;

      g_object_freeze_notify (G_OBJECT (image));

      if (crop_layers)
        gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CROP,
                                     C_("command", "Crop Image"));
      else
        gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_RESIZE,
                                     _("Resize Image"));

      /*  Push the image size to the stack  */
      gimp_image_undo_push_image_size (image,
                                       NULL,
                                       x1,
                                       y1,
                                       width,
                                       height);

      /*  Set the new width and height  */
      g_object_set (image,
                    "width",  width,
                    "height", height,
                    NULL);

      /*  Resize all channels  */
      for (list = GIMP_LIST (image->channels)->list;
           list;
           list = g_list_next (list))
        {
          item = (GimpItem *) list->data;

          gimp_item_resize (item, context, width, height, -x1, -y1);
        }

      /*  Resize all vectors  */
      for (list = GIMP_LIST (image->vectors)->list;
           list;
           list = g_list_next (list))
        {
          item = (GimpItem *) list->data;

          gimp_item_resize (item, context, width, height, -x1, -y1);
        }

      /*  Don't forget the selection mask!  */
      gimp_item_resize (GIMP_ITEM (gimp_image_get_mask (image)), context,
                        width, height, -x1, -y1);

      /*  crop all layers  */
      list = GIMP_LIST (image->layers)->list;

      while (list)
        {
          item = (GimpItem *) list->data;

          list = g_list_next (list);

          gimp_item_translate (item, -x1, -y1, TRUE);

          if (crop_layers)
            {
              gint off_x, off_y;
              gint lx1, ly1, lx2, ly2;

              gimp_item_offsets (item, &off_x, &off_y);

              lx1 = CLAMP (off_x, 0, gimp_image_get_width  (image));
              ly1 = CLAMP (off_y, 0, gimp_image_get_height (image));
              lx2 = CLAMP (gimp_item_width  (item) + off_x,
                           0, gimp_image_get_width (image));
              ly2 = CLAMP (gimp_item_height (item) + off_y,
                           0, gimp_image_get_height (image));

              width  = lx2 - lx1;
              height = ly2 - ly1;

              if (width > 0 && height > 0)
                gimp_item_resize (item, context, width, height,
                                  -(lx1 - off_x),
                                  -(ly1 - off_y));
              else
                gimp_image_remove_layer (image, GIMP_LAYER (item));
            }
        }

      /*  Reposition or remove all guides  */
      list = gimp_image_get_guides (image);
      while (list)
        {
          GimpGuide *guide        = list->data;
          gboolean   remove_guide = FALSE;
          gint       position     = gimp_guide_get_position (guide);

          list = g_list_next (list);

          switch (gimp_guide_get_orientation (guide))
            {
            case GIMP_ORIENTATION_HORIZONTAL:
              if ((position < y1) || (position > y2))
                remove_guide = TRUE;
              else
                position -= y1;
              break;

            case GIMP_ORIENTATION_VERTICAL:
              if ((position < x1) || (position > x2))
                remove_guide = TRUE;
              else
                position -= x1;
              break;

            default:
              break;
            }

          if (remove_guide)
            gimp_image_remove_guide (image, guide, TRUE);
          else if (position != gimp_guide_get_position (guide))
            gimp_image_move_guide (image, guide, position, TRUE);
        }

      /*  Reposition or remove sample points  */
      list = gimp_image_get_sample_points (image);
      while (list)
        {
          GimpSamplePoint *sample_point        = list->data;
          gboolean         remove_sample_point = FALSE;
          gint             new_x               = sample_point->x;
          gint             new_y               = sample_point->y;

          list = g_list_next (list);

          new_y -= y1;
          if ((sample_point->y < y1) || (sample_point->y > y2))
            remove_sample_point = TRUE;

          new_x -= x1;
          if ((sample_point->x < x1) || (sample_point->x > x2))
            remove_sample_point = TRUE;

          if (remove_sample_point)
            gimp_image_remove_sample_point (image, sample_point, TRUE);
          else if (new_x != sample_point->x || new_y != sample_point->y)
            gimp_image_move_sample_point (image, sample_point,
                                          new_x, new_y, TRUE);
        }

      gimp_image_undo_group_end (image);

      gimp_image_update (image,
                         0, 0,
                         gimp_image_get_width  (image),
                         gimp_image_get_height (image));

      gimp_image_size_changed_detailed (image,
                                        -x1,
                                        -y1,
                                        previous_width,
                                        previous_height);

      g_object_thaw_notify (G_OBJECT (image));
    }

  gimp_unset_busy (image->gimp);
}
コード例 #18
0
void
gimp_display_shell_connect (GimpDisplayShell *shell)
{
  GimpImage     *image;
  GimpContainer *vectors;
  GList         *list;

  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
  g_return_if_fail (GIMP_IS_DISPLAY (shell->display));

  image   = gimp_display_get_image (shell->display);
  vectors = gimp_image_get_vectors (image);

  g_return_if_fail (GIMP_IS_IMAGE (image));

  g_signal_connect (image, "clean",
                    G_CALLBACK (gimp_display_shell_clean_dirty_handler),
                    shell);
  g_signal_connect (image, "dirty",
                    G_CALLBACK (gimp_display_shell_clean_dirty_handler),
                    shell);
  g_signal_connect (image, "undo-event",
                    G_CALLBACK (gimp_display_shell_undo_event_handler),
                    shell);

  g_signal_connect (gimp_image_get_grid (image), "notify",
                    G_CALLBACK (gimp_display_shell_grid_notify_handler),
                    shell);
  g_object_set (shell->grid, "grid", gimp_image_get_grid (image), NULL);

  g_signal_connect (image, "name-changed",
                    G_CALLBACK (gimp_display_shell_name_changed_handler),
                    shell);
  g_signal_connect (image, "selection-invalidate",
                    G_CALLBACK (gimp_display_shell_selection_invalidate_handler),
                    shell);
  g_signal_connect (image, "size-changed-detailed",
                    G_CALLBACK (gimp_display_shell_size_changed_detailed_handler),
                    shell);
  g_signal_connect (image, "resolution-changed",
                    G_CALLBACK (gimp_display_shell_resolution_changed_handler),
                    shell);
  g_signal_connect (image, "quick-mask-changed",
                    G_CALLBACK (gimp_display_shell_quick_mask_changed_handler),
                    shell);

  g_signal_connect (image, "guide-added",
                    G_CALLBACK (gimp_display_shell_guide_add_handler),
                    shell);
  g_signal_connect (image, "guide-removed",
                    G_CALLBACK (gimp_display_shell_guide_remove_handler),
                    shell);
  g_signal_connect (image, "guide-moved",
                    G_CALLBACK (gimp_display_shell_guide_move_handler),
                    shell);
  for (list = gimp_image_get_guides (image);
       list;
       list = g_list_next (list))
    {
      gimp_display_shell_guide_add_handler (image, list->data, shell);
    }

  g_signal_connect (image, "sample-point-added",
                    G_CALLBACK (gimp_display_shell_sample_point_add_handler),
                    shell);
  g_signal_connect (image, "sample-point-removed",
                    G_CALLBACK (gimp_display_shell_sample_point_remove_handler),
                    shell);
  g_signal_connect (image, "sample-point-moved",
                    G_CALLBACK (gimp_display_shell_sample_point_move_handler),
                    shell);
  for (list = gimp_image_get_sample_points (image);
       list;
       list = g_list_next (list))
    {
      gimp_display_shell_sample_point_add_handler (image, list->data, shell);
    }

  g_signal_connect (image, "invalidate-preview",
                    G_CALLBACK (gimp_display_shell_invalidate_preview_handler),
                    shell);
  g_signal_connect (image, "precision-changed",
                    G_CALLBACK (gimp_display_shell_precision_changed_handler),
                    shell);
  g_signal_connect (image, "profile-changed",
                    G_CALLBACK (gimp_display_shell_profile_changed_handler),
                    shell);
  g_signal_connect (image, "precision-changed",
                    G_CALLBACK (gimp_display_shell_precision_changed_handler),
                    shell);
  g_signal_connect (image, "saved",
                    G_CALLBACK (gimp_display_shell_saved_handler),
                    shell);
  g_signal_connect (image, "exported",
                    G_CALLBACK (gimp_display_shell_exported_handler),
                    shell);

  g_signal_connect (image, "active-vectors-changed",
                    G_CALLBACK (gimp_display_shell_active_vectors_handler),
                    shell);

  shell->vectors_freeze_handler =
    gimp_tree_handler_connect (vectors, "freeze",
                               G_CALLBACK (gimp_display_shell_vectors_freeze_handler),
                               shell);
  shell->vectors_thaw_handler =
    gimp_tree_handler_connect (vectors, "thaw",
                               G_CALLBACK (gimp_display_shell_vectors_thaw_handler),
                               shell);
  shell->vectors_visible_handler =
    gimp_tree_handler_connect (vectors, "visibility-changed",
                               G_CALLBACK (gimp_display_shell_vectors_visible_handler),
                               shell);

  g_signal_connect (vectors, "add",
                    G_CALLBACK (gimp_display_shell_vectors_add_handler),
                    shell);
  g_signal_connect (vectors, "remove",
                    G_CALLBACK (gimp_display_shell_vectors_remove_handler),
                    shell);
  for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (vectors));
       list;
       list = g_list_next (list))
    {
      gimp_display_shell_vectors_add_handler (vectors, list->data, shell);
    }

  g_signal_connect (shell->display->config,
                    "notify::transparency-size",
                    G_CALLBACK (gimp_display_shell_check_notify_handler),
                    shell);
  g_signal_connect (shell->display->config,
                    "notify::transparency-type",
                    G_CALLBACK (gimp_display_shell_check_notify_handler),
                    shell);

  g_signal_connect (shell->display->config,
                    "notify::image-title-format",
                    G_CALLBACK (gimp_display_shell_title_notify_handler),
                    shell);
  g_signal_connect (shell->display->config,
                    "notify::image-status-format",
                    G_CALLBACK (gimp_display_shell_title_notify_handler),
                    shell);
  g_signal_connect (shell->display->config,
                    "notify::navigation-preview-size",
                    G_CALLBACK (gimp_display_shell_nav_size_notify_handler),
                    shell);
  g_signal_connect (shell->display->config,
                    "notify::monitor-resolution-from-windowing-system",
                    G_CALLBACK (gimp_display_shell_monitor_res_notify_handler),
                    shell);
  g_signal_connect (shell->display->config,
                    "notify::monitor-xresolution",
                    G_CALLBACK (gimp_display_shell_monitor_res_notify_handler),
                    shell);
  g_signal_connect (shell->display->config,
                    "notify::monitor-yresolution",
                    G_CALLBACK (gimp_display_shell_monitor_res_notify_handler),
                    shell);

  g_signal_connect (shell->display->config->default_view,
                    "notify::padding-mode",
                    G_CALLBACK (gimp_display_shell_padding_notify_handler),
                    shell);
  g_signal_connect (shell->display->config->default_view,
                    "notify::padding-color",
                    G_CALLBACK (gimp_display_shell_padding_notify_handler),
                    shell);
  g_signal_connect (shell->display->config->default_fullscreen_view,
                    "notify::padding-mode",
                    G_CALLBACK (gimp_display_shell_padding_notify_handler),
                    shell);
  g_signal_connect (shell->display->config->default_fullscreen_view,
                    "notify::padding-color",
                    G_CALLBACK (gimp_display_shell_padding_notify_handler),
                    shell);

  g_signal_connect (shell->display->config,
                    "notify::marching-ants-speed",
                    G_CALLBACK (gimp_display_shell_ants_speed_notify_handler),
                    shell);

  g_signal_connect (shell->display->config,
                    "notify::zoom-quality",
                    G_CALLBACK (gimp_display_shell_quality_notify_handler),
                    shell);

  gimp_display_shell_invalidate_preview_handler (image, shell);
  gimp_display_shell_quick_mask_changed_handler (image, shell);
  gimp_display_shell_profile_changed_handler    (GIMP_COLOR_MANAGED (image),
                                                 shell);

  gimp_canvas_layer_boundary_set_layer (GIMP_CANVAS_LAYER_BOUNDARY (shell->layer_boundary),
                                        gimp_image_get_active_layer (image));
}
コード例 #19
0
GimpImage *
gimp_image_duplicate (GimpImage *image)
{
  GimpImage    *new_image;
  GimpLayer    *floating_layer;
  GList        *list;
  GimpLayer    *active_layer              = NULL;
  GimpChannel  *active_channel            = NULL;
  GimpVectors  *active_vectors            = NULL;
  GimpDrawable *new_floating_sel_drawable = NULL;
  GimpDrawable *floating_sel_drawable     = NULL;
  gchar        *filename;
  gint          count;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);

  gimp_set_busy_until_idle (image->gimp);

  /*  Create a new image  */
  new_image = gimp_create_image (image->gimp,
                                 image->width, image->height,
                                 image->base_type,
                                 FALSE);
  gimp_image_undo_disable (new_image);

  /*  Store the folder to be used by the save dialog  */
  filename = gimp_image_get_filename (image);
  if (filename)
    {
      g_object_set_data_full (G_OBJECT (new_image), "gimp-image-dirname",
                              g_path_get_dirname (filename),
                              (GDestroyNotify) g_free);
      g_free (filename);
    }

  /*  Copy the colormap if necessary  */
  if (new_image->base_type == GIMP_INDEXED)
    gimp_image_set_colormap (new_image,
                             gimp_image_get_colormap (image),
                             gimp_image_get_colormap_size (image),
                             FALSE);

  /*  Copy resolution information  */
  new_image->xresolution     = image->xresolution;
  new_image->yresolution     = image->yresolution;
  new_image->resolution_unit = image->resolution_unit;

  /*  Copy floating layer  */
  floating_layer = gimp_image_floating_sel (image);
  if (floating_layer)
    {
      floating_sel_relax (floating_layer, FALSE);

      floating_sel_drawable = floating_layer->fs.drawable;
      floating_layer = NULL;
    }

  /*  Copy the layers  */
  for (list = GIMP_LIST (image->layers)->list, count = 0;
       list;
       list = g_list_next (list))
    {
      GimpLayer *layer = list->data;
      GimpLayer *new_layer;

      new_layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (layer),
                                                 new_image,
                                                 G_TYPE_FROM_INSTANCE (layer),
                                                 FALSE));

      /*  Make sure the copied layer doesn't say: "<old layer> copy"  */
      gimp_object_set_name (GIMP_OBJECT (new_layer),
                            gimp_object_get_name (GIMP_OBJECT (layer)));

      /*  Make sure that if the layer has a layer mask,
       *  its name isn't screwed up
       */
      if (new_layer->mask)
        gimp_object_set_name (GIMP_OBJECT (new_layer->mask),
                              gimp_object_get_name (GIMP_OBJECT (layer->mask)));

      if (gimp_image_get_active_layer (image) == layer)
        active_layer = new_layer;

      if (image->floating_sel == layer)
        floating_layer = new_layer;

      if (floating_sel_drawable == GIMP_DRAWABLE (layer))
        new_floating_sel_drawable = GIMP_DRAWABLE (new_layer);

      if (floating_layer != new_layer)
        gimp_image_add_layer (new_image, new_layer, count++);
    }

  /*  Copy the channels  */
  for (list = GIMP_LIST (image->channels)->list, count = 0;
       list;
       list = g_list_next (list))
    {
      GimpChannel *channel = list->data;
      GimpChannel *new_channel;

      new_channel =
        GIMP_CHANNEL (gimp_item_convert (GIMP_ITEM (channel),
                                         new_image,
                                         G_TYPE_FROM_INSTANCE (channel),
                                         FALSE));

      /*  Make sure the copied channel doesn't say: "<old channel> copy"  */
      gimp_object_set_name (GIMP_OBJECT (new_channel),
                            gimp_object_get_name (GIMP_OBJECT (channel)));

      if (gimp_image_get_active_channel (image) == channel)
        active_channel = (new_channel);

      if (floating_sel_drawable == GIMP_DRAWABLE (channel))
        new_floating_sel_drawable = GIMP_DRAWABLE (new_channel);

      gimp_image_add_channel (new_image, new_channel, count++);
    }

  /*  Copy any vectors  */
  for (list = GIMP_LIST (image->vectors)->list, count = 0;
       list;
       list = g_list_next (list))
    {
      GimpVectors *vectors = list->data;
      GimpVectors *new_vectors;

      new_vectors =
        GIMP_VECTORS (gimp_item_convert (GIMP_ITEM (vectors),
                                         new_image,
                                         G_TYPE_FROM_INSTANCE (vectors),
                                         FALSE));

      /*  Make sure the copied vectors doesn't say: "<old vectors> copy"  */
      gimp_object_set_name (GIMP_OBJECT (new_vectors),
                            gimp_object_get_name (GIMP_OBJECT (vectors)));

      if (gimp_image_get_active_vectors (image) == vectors)
        active_vectors = new_vectors;

      gimp_image_add_vectors (new_image, new_vectors, count++);
    }

  /*  Copy the selection mask  */
  {
    TileManager *src_tiles;
    TileManager *dest_tiles;
    PixelRegion  srcPR, destPR;

    src_tiles  =
      gimp_drawable_get_tiles (GIMP_DRAWABLE (image->selection_mask));
    dest_tiles =
      gimp_drawable_get_tiles (GIMP_DRAWABLE (new_image->selection_mask));

    pixel_region_init (&srcPR, src_tiles,
                       0, 0, image->width, image->height, FALSE);
    pixel_region_init (&destPR, dest_tiles,
                       0, 0, image->width, image->height, TRUE);

    copy_region (&srcPR, &destPR);

    new_image->selection_mask->bounds_known   = FALSE;
    new_image->selection_mask->boundary_known = FALSE;
  }

  if (floating_layer)
    floating_sel_attach (floating_layer, new_floating_sel_drawable);

  /*  Set active layer, active channel, active vectors  */
  if (active_layer)
    gimp_image_set_active_layer (new_image, active_layer);

  if (active_channel)
    gimp_image_set_active_channel (new_image, active_channel);

  if (active_vectors)
    gimp_image_set_active_vectors (new_image, active_vectors);

  /*  Copy state of all color channels  */
  for (count = 0; count < MAX_CHANNELS; count++)
    {
      new_image->visible[count] = image->visible[count];
      new_image->active[count]  = image->active[count];
    }

  /*  Copy any guides  */
  for (list = image->guides; list; list = g_list_next (list))
    {
      GimpGuide *guide    = list->data;
      gint       position = gimp_guide_get_position (guide);

      switch (gimp_guide_get_orientation (guide))
        {
        case GIMP_ORIENTATION_HORIZONTAL:
          gimp_image_add_hguide (new_image, position, FALSE);
          break;

        case GIMP_ORIENTATION_VERTICAL:
          gimp_image_add_vguide (new_image, position, FALSE);
          break;

        default:
          g_error ("Unknown guide orientation.\n");
        }
    }

  /*  Copy any sample points  */
  for (list = image->sample_points; list; list = g_list_next (list))
    {
      GimpSamplePoint *sample_point = list->data;

      gimp_image_add_sample_point_at_pos (new_image,
                                          sample_point->x,
                                          sample_point->y,
                                          FALSE);
    }

  /*  Copy the grid  */
  if (image->grid)
    gimp_image_set_grid (new_image, image->grid, FALSE);

  /*  Copy the quick mask info  */
  new_image->quick_mask_state    = image->quick_mask_state;
  new_image->quick_mask_inverted = image->quick_mask_inverted;
  new_image->quick_mask_color    = image->quick_mask_color;

  /*  Copy parasites  */
  if (image->parasites)
    {
      g_object_unref (new_image->parasites);
      new_image->parasites = gimp_parasite_list_copy (image->parasites);
    }

  gimp_image_undo_enable (new_image);

  return new_image;
}
コード例 #20
0
void
layers_actions_update (GimpActionGroup *group,
                       gpointer         data)
{
  GimpImage     *image          = action_data_get_image (data);
  GimpLayer     *layer          = NULL;
  GimpLayerMask *mask           = NULL;     /*  layer mask             */
  gboolean       fs             = FALSE;    /*  floating sel           */
  gboolean       ac             = FALSE;    /*  active channel         */
  gboolean       sel            = FALSE;
  gboolean       alpha          = FALSE;    /*  alpha channel present  */
  gboolean       indexed        = FALSE;    /*  is indexed             */
  gboolean       lock_alpha     = FALSE;
  gboolean       can_lock_alpha = FALSE;
  gboolean       text_layer     = FALSE;
  gboolean       writable       = FALSE;
  gboolean       children       = FALSE;
  GList         *next           = NULL;
  GList         *next_visible   = NULL;
  GList         *prev           = NULL;

  if (image)
    {
      fs      = (gimp_image_get_floating_selection (image) != NULL);
      ac      = (gimp_image_get_active_channel (image) != NULL);
      sel     = ! gimp_channel_is_empty (gimp_image_get_mask (image));
      indexed = (gimp_image_base_type (image) == GIMP_INDEXED);

      layer = gimp_image_get_active_layer (image);

      if (layer)
        {
          GList *layer_list;
          GList *list;

          mask           = gimp_layer_get_mask (layer);
          lock_alpha     = gimp_layer_get_lock_alpha (layer);
          can_lock_alpha = gimp_layer_can_lock_alpha (layer);
          alpha          = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
          writable       = ! gimp_item_is_content_locked (GIMP_ITEM (layer));

          if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
            children = TRUE;

          layer_list = gimp_item_get_container_iter (GIMP_ITEM (layer));

          list = g_list_find (layer_list, layer);

          if (list)
            {
              prev = g_list_previous (list);
              next = g_list_next (list);

              for (next_visible = next;
                   next_visible;
                   next_visible = g_list_next (next_visible))
                {
                  if (gimp_item_get_visible (next_visible->data))
                    {
                      /*  "next_visible" is actually "next_visible" and
                       *  "writable" and "not group"
                       */
                      if (gimp_item_is_content_locked (next_visible->data) ||
                          gimp_viewable_get_children (next_visible->data))
                        next_visible = NULL;

                      break;
                    }
                }
            }

          text_layer = gimp_item_is_text_layer (GIMP_ITEM (layer));
        }
    }

#define SET_VISIBLE(action,condition) \
        gimp_action_group_set_action_visible (group, action, (condition) != 0)
#define SET_SENSITIVE(action,condition) \
        gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
#define SET_ACTIVE(action,condition) \
        gimp_action_group_set_action_active (group, action, (condition) != 0)
#define SET_LABEL(action,label) \
        gimp_action_group_set_action_label (group, action, label)

  SET_VISIBLE   ("layers-text-tool",        text_layer && !ac);
  SET_SENSITIVE ("layers-edit-attributes",  layer && !fs && !ac);

  if (layer && gimp_layer_is_floating_sel (layer))
    {
      SET_LABEL ("layers-new",             C_("layers-action", "To _New Layer"));
      SET_LABEL ("layers-new-last-values", C_("layers-action", "To _New Layer"));
    }
  else
    {
      SET_LABEL ("layers-new",             C_("layers-action", "_New Layer..."));
      SET_LABEL ("layers-new-last-values", C_("layers-action", "_New Layer"));
    }

  SET_SENSITIVE ("layers-new",              image);
  SET_SENSITIVE ("layers-new-last-values",  image);
  SET_SENSITIVE ("layers-new-from-visible", image);
  SET_SENSITIVE ("layers-new-group",        image && !indexed);
  SET_SENSITIVE ("layers-duplicate",        layer && !fs && !ac);
  SET_SENSITIVE ("layers-delete",           layer && !ac);

  SET_SENSITIVE ("layers-select-top",       layer && !fs && !ac && prev);
  SET_SENSITIVE ("layers-select-bottom",    layer && !fs && !ac && next);
  SET_SENSITIVE ("layers-select-previous",  layer && !fs && !ac && prev);
  SET_SENSITIVE ("layers-select-next",      layer && !fs && !ac && next);

  SET_SENSITIVE ("layers-raise",            layer && !fs && !ac && prev);
  SET_SENSITIVE ("layers-raise-to-top",     layer && !fs && !ac && prev);
  SET_SENSITIVE ("layers-lower",            layer && !fs && !ac && next);
  SET_SENSITIVE ("layers-lower-to-bottom",  layer && !fs && !ac && next);

  SET_SENSITIVE ("layers-anchor",           layer &&  fs && !ac);
  SET_SENSITIVE ("layers-merge-down",       layer && !fs && !ac && next_visible);
  SET_VISIBLE   ("layers-merge-group",      children);
  SET_SENSITIVE ("layers-merge-group",      layer && !fs && !ac && children);
  SET_SENSITIVE ("layers-merge-layers",     layer && !fs && !ac);
  SET_SENSITIVE ("layers-flatten-image",    layer && !fs && !ac);

  SET_VISIBLE   ("layers-text-discard",             text_layer && !ac);
  SET_VISIBLE   ("layers-text-to-vectors",          text_layer && !ac);
  SET_VISIBLE   ("layers-text-along-vectors",       text_layer && !ac);

  SET_SENSITIVE ("layers-resize",          writable && !ac);
  SET_SENSITIVE ("layers-resize-to-image", writable && !ac);
  SET_SENSITIVE ("layers-scale",           writable && !ac);

  SET_SENSITIVE ("layers-crop",            writable && sel);

  SET_SENSITIVE ("layers-alpha-add",       writable && !children && !fs && !alpha);
  SET_SENSITIVE ("layers-alpha-remove",    writable && !children && !fs &&  alpha);

  SET_SENSITIVE ("layers-lock-alpha", can_lock_alpha);
  SET_ACTIVE    ("layers-lock-alpha", lock_alpha);

  SET_SENSITIVE ("layers-mask-add",    layer    && !fs && !ac && !mask && !children);
  SET_SENSITIVE ("layers-mask-apply",  writable && !fs && !ac &&  mask && !children);
  SET_SENSITIVE ("layers-mask-delete", layer    && !fs && !ac &&  mask);

  SET_SENSITIVE ("layers-mask-edit",    layer && !fs && !ac &&  mask);
  SET_SENSITIVE ("layers-mask-show",    layer && !fs && !ac &&  mask);
  SET_SENSITIVE ("layers-mask-disable", layer && !fs && !ac &&  mask);

  SET_ACTIVE ("layers-mask-edit",    mask && gimp_layer_mask_get_edit (mask));
  SET_ACTIVE ("layers-mask-show",    mask && gimp_layer_mask_get_show (mask));
  SET_ACTIVE ("layers-mask-disable", mask && !gimp_layer_mask_get_apply (mask));

  SET_SENSITIVE ("layers-mask-selection-replace",   layer && !fs && !ac && mask);
  SET_SENSITIVE ("layers-mask-selection-add",       layer && !fs && !ac && mask);
  SET_SENSITIVE ("layers-mask-selection-subtract",  layer && !fs && !ac && mask);
  SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask);

  SET_SENSITIVE ("layers-alpha-selection-replace",   layer && !fs && !ac);
  SET_SENSITIVE ("layers-alpha-selection-add",       layer && !fs && !ac);
  SET_SENSITIVE ("layers-alpha-selection-subtract",  layer && !fs && !ac);
  SET_SENSITIVE ("layers-alpha-selection-intersect", layer && !fs && !ac);

#undef SET_VISIBLE
#undef SET_SENSITIVE
#undef SET_ACTIVE
#undef SET_LABEL
}
コード例 #21
0
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);
}