Exemplo n.º 1
0
void undo_restore(GEM_WINDOW *gwnd)
{
  LIST_ENTRY *entry ;
  UNDO_DEF   *undo ;
  VXIMAGE    *vimage ;
  MFDB       original_img ;
  int        xy[8] ;
  int        rep ;
  int        resize = 1 ;

  if ( !GWIsWindowValid( gwnd ) ) return ;
  if ( config.nb_undo == 0 ) return ;

  vimage = (VXIMAGE *) gwnd->Extension ;
  if ( IsListEmpty( &vimage->UndoListHead ) ) return ;
  entry = RemoveHeadList( &vimage->UndoListHead ) ;
  undo  = GET_UNDO_DEF_FROM_LIST_ENTRY( entry ) ;
  if ( gwnd != undo->gwindow )
  {
    rep = form_stop(1, msg[MSG_UNDOIMG]) ;
    if ( rep == 2 ) return ;
  }

  memcpy( &original_img, &vimage->raster, sizeof(MFDB) )  ;
  mouse_busy() ;

  if ( uundo_put( gwnd ) ) form_stop( 1, msg[MSG_UUNDO] ) ;

  if ( need_palette( undo->mitem, undo->spec ) )
  {
    memcpy( vimage->inf_img.palette, undo->palette, undo->nb_cpal * 3 * sizeof(int) ) ;
    set_imgpalette( vimage ) ;
  }

  if ( undo->img.fd_addr || undo->disk )
  {
    if ( handle_changed_size( undo, &vimage->raster ) != 0 ) form_error( 8 ) ;
    else
    {
      xy[0] = 0 ;         xy[1] = 0 ;
      xy[2] = undo->w-1 ; xy[3] = undo->h-1 ;
      xy[4] = undo->x ;   xy[5] = undo->y ;
      xy[6] = undo->x+undo->w-1 ;
      xy[7] = undo->y+undo->h-1 ;
      if ( undo->disk ) restore_undo_disk( gwnd, undo, xy, &vimage->raster ) ;
      else              vro_cpyfm( handle, S_ONLY, xy, &undo->img, &vimage->raster ) ;
    }
  }
  else
  {
    resize = 0 ;
    switch( undo->mitem )
    {
      case UNEGATIF : xy[0] = undo->x ;
                      xy[1] = undo->y ;
                      xy[2] = xy[0]+undo->w-1 ;
                      xy[3] = xy[1]+undo->h-1 ;
                      memcpy(&xy[4], xy, 8) ;
                      vro_cpyfm(handle, D_INVERT, xy, &vimage->raster, &vimage->raster) ;
                      break ;
      case USYMX    : xy[0] = undo->x ;
                      xy[1] = undo->y ;
                      xy[2] = xy[0]+undo->w-1 ;
                      xy[3] = xy[1]+undo->h-1 ;
                      raster_hsym( &vimage->raster, xy ) ;
                      if ((vclip.gwindow == gwnd) && (xy[0] == 0) && (xy[1] == 0) &&
                          (xy[2] == vimage->raster.fd_w-1) && (xy[3] == vimage->raster.fd_h-1))
                      {
                        vclip.y1 = vimage->raster.fd_h-1-vclip.y1 ;
                        vclip.y2 = vimage->raster.fd_h-1-vclip.y2 ;
                        if (vclip.y1 > vclip.y2)
                        {
                          int temp ;

                          temp     = vclip.y1 ; 
                          vclip.y1 = vclip.y2 ;
                          vclip.y2 = temp ;
                        }
                      }
                      break ;
      case USYMY    : xy[0] = undo->x ;
                      xy[1] = undo->y ;
                      xy[2] = xy[0]+undo->w-1 ;
                      xy[3] = xy[1]+undo->h-1 ;
                      raster_vsym( &vimage->raster, xy ) ;
                      if ((vclip.gwindow == gwnd) && (xy[0] == 0) && (xy[1] == 0) &&
                          (xy[2] == vimage->raster.fd_w-1) && (xy[3] == vimage->raster.fd_h-1))
                      {
                        vclip.x1 = vimage->raster.fd_w-1-vclip.x1 ;
                        vclip.x2 = vimage->raster.fd_w-1-vclip.x2 ;
                        if (vclip.x1 > vclip.x2)
                        {
                          int temp ;

                          temp     = vclip.x1 ; 
                          vclip.x1 = vclip.x2 ;
                          vclip.x2 = temp ;
                        }
                      }
                      break ;
      case USYMXY   : xy[0] = undo->x ;
                      xy[1] = undo->y ;
                      xy[2] = xy[0]+undo->w-1 ;
                      xy[3] = xy[1]+undo->h-1 ;
                      raster_vsym( &vimage->raster, xy ) ;
                      if ((vclip.gwindow == gwnd) && (xy[0] == 0) && (xy[1] == 0) &&
                          (xy[2] == vimage->raster.fd_w-1) && (xy[3] == vimage->raster.fd_h-1))
                      {
                        vclip.x1 = vimage->raster.fd_w-1-vclip.x1 ;
                        vclip.x2 = vimage->raster.fd_w-1-vclip.x2 ;
                        if (vclip.x1 > vclip.x2)
                        {
                          int temp ;

                          temp     = vclip.x1 ; 
                          vclip.x1 = vclip.x2 ;
                          vclip.x2 = temp ;
                        }
                      }
                      xy[0] = undo->x ;
                      xy[1] = undo->y ;
                      xy[2] = xy[0]+undo->w-1 ;
                      xy[3] = xy[1]+undo->h-1 ;
                      raster_hsym( &vimage->raster, xy ) ;
                      if ((vclip.gwindow == gwnd) && (xy[0] == 0) && (xy[1] == 0) &&
                          (xy[2] == vimage->raster.fd_w-1) && (xy[3] == vimage->raster.fd_h-1))
                      {
                        vclip.y1 = vimage->raster.fd_h-1-vclip.y1 ;
                        vclip.y2 = vimage->raster.fd_h-1-vclip.y2 ;
                        if (vclip.y1 > vclip.y2)
                        {
                          int temp ;

                          temp     = vclip.y1 ; 
                          vclip.y1 = vclip.y2 ;
                          vclip.y2 = temp ;
                        }
                      }
                      break ;
    }
  }

  mouse_restore() ;

  handle_new_size( &original_img, gwnd ) ;

  if ( resize && ( vimage->zoom_level != 1 ) )
  {
    int xy[4] ;

    xy[0] = vimage->x1 ; xy[1] = vimage->y1 ;
    xy[2] = vimage->x2 ; xy[3] = vimage->y2 ;
    if ( vimage->zoom.fd_addr ) free( vimage->zoom.fd_addr ) ;
    if ( raster_zoom( &vimage->raster, &vimage->zoom, xy, vimage->zoom_level, vimage->zoom_level ) == -1 )
      form_error( 8 ) ;
  }
  
  if ( gwnd->window_icon.fd_addr != NULL ) free( gwnd->window_icon.fd_addr) ;
  memset( &gwnd->window_icon, 0, sizeof(MFDB) ) ;
  if ( gwnd->is_icon ) iconify_picture( gwnd ) ;
  GWRePaint( gwnd ) ;

  FreeUndoBuffer( undo ) ;
}
Exemplo n.º 2
0
static void
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
{
  static GimpParam   values[2]; /* Return values */
  GimpRunMode        run_mode;
  gint32             image_ID;
  gint32             drawable_ID;
  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
  gint32             image;
  GimpExportReturn   export = GIMP_EXPORT_CANCEL;
  GError            *error  = NULL;

  run_mode = param[0].data.d_int32;

  INIT_I18N ();

  /* Set up default return values */

  *nreturn_vals = 1;
  *return_vals  = values;
  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;

  if (strcmp (name, LOAD_PROC) == 0)
    {
      if (run_mode != GIMP_RUN_NONINTERACTIVE)
        {
          data_length = gimp_get_data_size (SAVE_PROC);
          if (data_length > 0)
            {
              palette_file = g_malloc (data_length);
              gimp_get_data (SAVE_PROC, palette_file);
            }
          else
            {
              palette_file = g_strdup ("*.kcf");
              data_length = strlen (palette_file) + 1;
            }
        }

      if (run_mode == GIMP_RUN_NONINTERACTIVE)
        {
          palette_file = param[3].data.d_string;
          data_length = strlen (palette_file) + 1;
        }
      else if (run_mode == GIMP_RUN_INTERACTIVE)
        {
          /* Let user choose KCF palette (cancel ignores) */
          if (need_palette (param[1].data.d_string))
            palette_dialog (_("Load KISS Palette"));

          gimp_set_data (SAVE_PROC, palette_file, data_length);
        }

      image = load_image (param[1].data.d_string, param[2].data.d_string,
                          &error);

      if (image != -1)
        {
          *nreturn_vals = 2;
          values[1].type         = GIMP_PDB_IMAGE;
          values[1].data.d_image = image;
        }
      else
        {
          status = GIMP_PDB_EXECUTION_ERROR;
        }
    }
  else if (strcmp (name, SAVE_PROC) == 0)
    {
      image_ID      = param[1].data.d_int32;
      drawable_ID   = param[2].data.d_int32;

      /*  eventually export the image */
      switch (run_mode)
	{
	case GIMP_RUN_INTERACTIVE:
	case GIMP_RUN_WITH_LAST_VALS:
	  gimp_ui_init (PLUG_IN_BINARY, FALSE);
	  export = gimp_export_image (&image_ID, &drawable_ID, "CEL",
				      (GIMP_EXPORT_CAN_HANDLE_RGB |
				       GIMP_EXPORT_CAN_HANDLE_ALPHA |
				       GIMP_EXPORT_CAN_HANDLE_INDEXED
				       ));
	  if (export == GIMP_EXPORT_CANCEL)
	    {
	      values[0].data.d_status = GIMP_PDB_CANCEL;
	      return;
	    }
	  break;
	default:
	  break;
	}
Exemplo n.º 3
0
int undo_put(GEM_WINDOW *gwnd, int x1, int y1, int x2, int y2, int type_modif, XUNDO *xundo)
{
  VXIMAGE  *vimage ;
  UNDO_DEF *undo_buf ;
  void     *spec = NULL ;
  long     taille = 0 ;
  int      xy[8] ;
  int      wx, wy ;
  int      larg, temp ;
  int      type_alloc ;
/*  int      redo = 0 ;*/
  int      err = 0 ;

  if ( config.nb_undo == 0 ) return( -1 ) ;
  if ( !GWIsWindowValid( gwnd ) ) return( -1 ) ;
  undo_buf = AllocateNewUndoBuffer( gwnd ) ;
  if ( undo_buf == NULL ) return( -3 ) ;

  vimage = (VXIMAGE *) gwnd->Extension ;
/*  if ( type_modif & REDO ) redo = 1 ;
  type_modif &= ~REDO ;
*/
  if ( xundo )
  {
    if ( xundo->nb_bytes_to_allocate_and_copy > 0 )
    {
      spec = malloc( xundo->nb_bytes_to_allocate_and_copy ) ;
      if ( spec ) memcpy( spec, xundo->spec, xundo->nb_bytes_to_allocate_and_copy ) ;
      else        return( -3 ) ;
    }
  }

  if ( x1 > x2 )
  {
    temp = x1 ;
    x1   = x2 ;
    x2   = temp ;
  }

  if ( y1 > y2 )
  {
    temp = y1 ;
    y1   = y2 ;
    y2   = temp ;
  }

  wx = x2 - x1 + 1 ;
  wy = y2 - y1 + 1 ;

  larg = ALIGN16( wx ) ;

  if ( need_palette( type_modif, spec ) )
  {
    size_t size ;

    undo_buf->nb_cpal = (int) vimage->inf_img.nb_cpal ;
    size              = undo_buf->nb_cpal * 3 * sizeof(int) ;
    undo_buf->palette = (int *) malloc( size ) ;
    if ( undo_buf->palette == NULL ) return( -3 ) ;
    else                             memcpy( undo_buf->palette, vimage->inf_img.palette, size ) ;
  }

  if ( x1 < 0 ) taille = 0 ; /* Pas de modif sur l'image (palette sans doute) */
  else          taille = img_size( larg, wy, nb_plane ) ;

  undo_buf->original_width  = vimage->raster.fd_w ;
  undo_buf->original_height = vimage->raster.fd_h ;

  type_alloc = must_alloc( type_modif, taille, spec ) ;
  if ( type_alloc == 0 ) /* Est-il n‚cessaire d'allouer de la m‚moire ? */
  {
    undo_buf->img.fd_addr = NULL ;
    undo_buf->x           = x1 ;
    undo_buf->y           = y1 ;
    undo_buf->w           = wx ;
    undo_buf->h           = wy ;
    undo_buf->mitem       = type_modif ;
    undo_buf->spec        = spec ;
  }
  else
  {
    if ( type_alloc == 2 ) undo_buf->disk        = 1 ;
    else                   undo_buf->img.fd_addr = malloc( taille ) ;
    if ( undo_buf->disk || ( undo_buf->img.fd_addr != NULL ) )
    {
      undo_buf->img.fd_w       = larg ; /* Si possible, on m‚morise */
      undo_buf->img.fd_h       = wy ;   /* Les nouvelles donn‚es    */
      undo_buf->img.fd_wdwidth = larg/16 ;
      undo_buf->img.fd_nplanes = nb_plane ;
      undo_buf->img.fd_stand   = 0 ;
      undo_buf->gwindow        = gwnd ;
      undo_buf->x              = x1 ;
      undo_buf->y              = y1 ;
      undo_buf->w              = wx ;
      undo_buf->h              = wy ;
      undo_buf->mitem          = type_modif ;
      undo_buf->spec           = spec ;

      xy[0] = x1 ;   xy[1] = y1 ;
      xy[2] = x2 ;   xy[3] = y2 ;
      xy[4] = 0 ;    xy[5] = 0 ;
      xy[6] = wx-1 ; xy[7] = wy-1 ;
      if ( undo_buf->disk ) undo_disk( gwnd, undo_buf, xy, &vimage->raster ) ;
      else                  vro_cpyfm( handle, S_ONLY, xy, &vimage->raster, &undo_buf->img ) ;
    }
  }

  if ( !err )
  {
    LIST_ENTRY* entry = GET_LIST_ENTRY_FROM_UNDO_DEF( undo_buf ) ;

    InsertHeadList( &vimage->UndoListHead, entry ) ;
    if ( type_modif != REDO ) FreeUUndoBuffer( gwnd ) ;
  }
  else
  {
    FreeUndoBuffer( undo_buf ) ;
    form_stop( 1, msg[MSG_UNDOERROR] ) ;
  }

  return( err ) ;
}