Ejemplo n.º 1
0
void
gimp_image_set_colormap (GimpImage    *image,
                         const guchar *colormap,
                         gint          n_colors,
                         gboolean      push_undo)
{
  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (colormap != NULL || n_colors == 0);
  g_return_if_fail (n_colors >= 0 && n_colors <= 256);

  if (push_undo)
    gimp_image_undo_push_image_colormap (image, _("Set Colormap"));

  if (image->colormap)
    memset (image->colormap, 0, GIMP_IMAGE_COLORMAP_SIZE);

  if (colormap)
    {
      if (! image->colormap)
        image->colormap = g_new0 (guchar, GIMP_IMAGE_COLORMAP_SIZE);

      memcpy (image->colormap, colormap, n_colors * 3);
    }
  else if (! gimp_image_base_type (image) == GIMP_INDEXED)
    {
      if (image->colormap)
        g_free (image->colormap);

      image->colormap = NULL;
    }

  image->n_colors = n_colors;

  gimp_image_colormap_changed (image, -1);
}
Ejemplo n.º 2
0
void
gimp_image_add_colormap_entry (GimpImage     *image,
                               const GimpRGB *color)
{
  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (image->colormap != NULL);
  g_return_if_fail (image->n_colors < 256);
  g_return_if_fail (color != NULL);

  gimp_image_undo_push_image_colormap (image,
                                       _("Add Color to Colormap"));

  gimp_rgb_get_uchar (color,
                      &image->colormap[image->n_colors * 3],
                      &image->colormap[image->n_colors * 3 + 1],
                      &image->colormap[image->n_colors * 3 + 2]);

  image->n_colors++;

  gimp_image_colormap_changed (image, -1);
}
Ejemplo n.º 3
0
void
gimp_image_set_colormap_entry (GimpImage     *image,
                               gint           color_index,
                               const GimpRGB *color,
                               gboolean       push_undo)
{
  g_return_if_fail (GIMP_IS_IMAGE (image));
  g_return_if_fail (image->colormap != NULL);
  g_return_if_fail (color_index >= 0 && color_index < image->n_colors);
  g_return_if_fail (color != NULL);

  if (push_undo)
    gimp_image_undo_push_image_colormap (image,
                                         _("Change Colormap entry"));

  gimp_rgb_get_uchar (color,
                      &image->colormap[color_index * 3],
                      &image->colormap[color_index * 3 + 1],
                      &image->colormap[color_index * 3 + 2]);

  gimp_image_colormap_changed (image, color_index);
}
Ejemplo n.º 4
0
static void
gimp_image_undo_pop (GimpUndo            *undo,
                     GimpUndoMode         undo_mode,
                     GimpUndoAccumulator *accum)
{
  GimpImageUndo    *image_undo = GIMP_IMAGE_UNDO (undo);
  GimpImage        *image      = undo->image;
  GimpImagePrivate *private    = GIMP_IMAGE_GET_PRIVATE (image);

  GIMP_UNDO_CLASS (parent_class)->pop (undo, undo_mode, accum);

  switch (undo->undo_type)
    {
    case GIMP_UNDO_IMAGE_TYPE:
      {
        GimpImageBaseType base_type;

        base_type = image_undo->base_type;
        image_undo->base_type = gimp_image_base_type (image);
        g_object_set (image, "base-type", base_type, NULL);

        gimp_image_colormap_changed (image, -1);

        if (image_undo->base_type != gimp_image_base_type (image))
          accum->mode_changed = TRUE;
      }
      break;

    case GIMP_UNDO_IMAGE_SIZE:
      {
        gint width;
        gint height;
        gint previous_origin_x;
        gint previous_origin_y;
        gint previous_width;
        gint previous_height;

        width             = image_undo->width;
        height            = image_undo->height;
        previous_origin_x = image_undo->previous_origin_x;
        previous_origin_y = image_undo->previous_origin_y;
        previous_width    = image_undo->previous_width;
        previous_height   = image_undo->previous_height;

        /* Transform to a redo */
        image_undo->width             = gimp_image_get_width  (image);
        image_undo->height            = gimp_image_get_height (image);
        image_undo->previous_origin_x = -previous_origin_x;
        image_undo->previous_origin_y = -previous_origin_y;
        image_undo->previous_width    = width;
        image_undo->previous_height   = height;

        g_object_set (image,
                      "width",  width,
                      "height", height,
                      NULL);

        gimp_drawable_invalidate_boundary
          (GIMP_DRAWABLE (gimp_image_get_mask (image)));

        if (gimp_image_get_width  (image) != image_undo->width ||
            gimp_image_get_height (image) != image_undo->height)
          {
            accum->size_changed      = TRUE;
            accum->previous_origin_x = previous_origin_x;
            accum->previous_origin_y = previous_origin_y;
            accum->previous_width    = previous_width;
            accum->previous_height   = previous_height;
          }
      }
      break;

    case GIMP_UNDO_IMAGE_RESOLUTION:
      {
        gdouble xres;
        gdouble yres;

        gimp_image_get_resolution (image, &xres, &yres);

        if (ABS (image_undo->xresolution - xres) >= 1e-5 ||
            ABS (image_undo->yresolution - yres) >= 1e-5)
          {
            private->xresolution = image_undo->xresolution;
            private->yresolution = image_undo->yresolution;

            image_undo->xresolution = xres;
            image_undo->yresolution = yres;

            accum->resolution_changed = TRUE;
          }
      }