diff --git a/plug-ins/file-psd/Makefile.am b/plug-ins/file-psd/Makefile.am index 8b288e6f1c..b95d0d7c91 100644 --- a/plug-ins/file-psd/Makefile.am +++ b/plug-ins/file-psd/Makefile.am @@ -14,8 +14,7 @@ endif if HAVE_WINDRES include $(top_srcdir)/build/windows/gimprc-plug-ins.rule -file_psd_load_RC = file-psd-load.rc.o -file_psd_save_RC = file-psd-save.rc.o +file_psd_RC = file-psd.rc.o endif AM_LDFLAGS = $(mwindows) @@ -23,16 +22,17 @@ AM_LDFLAGS = $(mwindows) libexecdir = $(gimpplugindir)/plug-ins libexec_PROGRAMS = \ - file-psd-load \ - file-psd-save + file-psd -file_psd_load_SOURCES = \ +file_psd_SOURCES = \ psd.c \ psd.h \ psd-util.c \ psd-util.h \ psd-load.c \ psd-load.h \ + psd-save.c \ + psd-save.h \ psd-thumb-load.c \ psd-thumb-load.h \ psd-image-res-load.c \ @@ -40,9 +40,6 @@ file_psd_load_SOURCES = \ psd-layer-res-load.c \ psd-layer-res-load.h -file_psd_save_SOURCES = \ - psd-save.c - EXTRA_DIST = \ TODO.txt \ new-resource-ids.txt @@ -54,7 +51,7 @@ AM_CPPFLAGS = \ $(GEGL_CFLAGS) \ -I$(includedir) -LDADD = \ +file_psd_LDADD = \ $(libgimpui) \ $(libgimpwidgets) \ $(libgimpconfig) \ @@ -68,12 +65,5 @@ LDADD = \ $(EXIF_LIBS) \ $(IPTCDATA_LIBS) \ $(RT_LIBS) \ - $(INTLLIBS) - -file_psd_load_LDADD = \ - $(LDADD) \ - $(file_psd_load_RC) - -file_psd_save_LDADD = \ - $(LDADD) \ - $(file_psd_save_RC) + $(INTLLIBS) \ + $(file_psd_RC) diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c index 81e54402ef..39bc623164 100644 --- a/plug-ins/file-psd/psd-save.c +++ b/plug-ins/file-psd/psd-save.c @@ -73,15 +73,11 @@ #include "libgimp/gimp.h" #include "libgimp/gimpui.h" +#include "psd-save.h" + #include "libgimp/stdplugins-intl.h" -/* *** DEFINES *** */ - -#define SAVE_PROC "file-psd-save" -#define PLUG_IN_BINARY "file-psd-save" -#define PLUG_IN_ROLE "gimp-file-psd-save" - /* set to TRUE if you want debugging, FALSE otherwise */ #define DEBUG FALSE @@ -94,8 +90,6 @@ #define PSD_UNIT_INCH 1 #define PSD_UNIT_CM 2 -/* *** END OF DEFINES *** */ - /* Local types etc */ @@ -134,14 +128,6 @@ static PSD_Image_Data PSDImageData; /* Declare some local functions. */ -static void query (void); - -static void run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals); - static void psd_lmode_layer (gint32 idLayer, gchar *psdMode); @@ -162,10 +148,6 @@ static void save_layer_and_mask (FILE *fd, static void save_data (FILE *fd, gint32 image_id); -static gint save_image (const gchar *filename, - gint32 image_id, - GError **error); - static void xfwrite (FILE *fd, gconstpointer buf, glong len, @@ -206,150 +188,6 @@ static gint32 create_merged_image (gint32 imageID); static const Babl* get_pixel_format (gint32 drawableID); -const GimpPlugInInfo PLUG_IN_INFO = -{ - NULL, /* init_proc */ - NULL, /* quit_proc */ - query, /* query_proc */ - run, /* run_proc */ -}; - - -MAIN() - - -static void -query (void) -{ - static const GimpParamDef save_args[] = - { - { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" }, - { GIMP_PDB_IMAGE, "image", "Input image" }, - { GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" }, - { GIMP_PDB_STRING, "filename", "The name of the file to save the image in" }, - { GIMP_PDB_STRING, "raw-filename", "The name of the file to save the image in" }, - { GIMP_PDB_INT32, "compression", "Compression type: { NONE (0), LZW (1), PACKBITS (2)" }, - { GIMP_PDB_INT32, "fill-order", "Fill Order: { MSB to LSB (0), LSB to MSB (1)" } - }; - - gimp_install_procedure (SAVE_PROC, - "saves files in the Photoshop(tm) PSD file format", - "This filter saves files of Adobe Photoshop(tm) native PSD format. These files may be of any image type supported by GIMP, with or without layers, layer masks, aux channels and guides.", - "Monigotes", - "Monigotes", - "2000", - N_("Photoshop image"), - "RGB*, GRAY*, INDEXED*", - GIMP_PLUGIN, - G_N_ELEMENTS (save_args), 0, - save_args, NULL); - - gimp_register_file_handler_mime (SAVE_PROC, "image/x-psd"); - gimp_register_save_handler (SAVE_PROC, "psd", ""); -} - -static void -run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals) -{ - static GimpParam values[2]; - GimpRunMode run_mode; - GError *error = NULL; - - run_mode = param[0].data.d_int32; - - INIT_I18N (); - gegl_init (NULL, NULL); - - *nreturn_vals = 1; - *return_vals = values; - - values[0].type = GIMP_PDB_STATUS; - values[0].data.d_status = GIMP_PDB_CALLING_ERROR; - - if (strcmp (name, SAVE_PROC) == 0) - { - gint32 image_id; - gint32 drawable_id; - GimpMetadata *metadata; - GimpMetadataSaveFlags metadata_flags; - GimpExportReturn export = GIMP_EXPORT_IGNORE; - - IFDBG printf ("\n---------------- %s ----------------\n", - param[3].data.d_string); - - image_id = param[1].data.d_int32; - drawable_id = param[2].data.d_int32; - - 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, "PSD", - GIMP_EXPORT_CAN_HANDLE_RGB | - GIMP_EXPORT_CAN_HANDLE_GRAY | - GIMP_EXPORT_CAN_HANDLE_INDEXED | - GIMP_EXPORT_CAN_HANDLE_ALPHA | - GIMP_EXPORT_CAN_HANDLE_LAYERS | - GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS); - - if (export == GIMP_EXPORT_CANCEL) - { - values[0].data.d_status = GIMP_PDB_CANCEL; - return; - } - break; - - default: - break; - } - - metadata = gimp_image_metadata_save_prepare (image_id, - "image/x-psd", - &metadata_flags); - - if (save_image (param[3].data.d_string, image_id, &error)) - { - if (metadata) - { - GFile *file; - - gimp_metadata_set_bits_per_sample (metadata, 8); - - file = g_file_new_for_path (param[3].data.d_string); - gimp_image_metadata_save_finish (image_id, - "image/x-psd", - metadata, metadata_flags, - file, NULL); - g_object_unref (file); - } - - values[0].data.d_status = GIMP_PDB_SUCCESS; - } - else - { - values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; - - if (error) - { - *nreturn_vals = 2; - values[1].type = GIMP_PDB_STRING; - values[1].data.d_string = error->message; - } - } - - if (export == GIMP_EXPORT_EXPORT) - gimp_image_delete (image_id); - - if (metadata) - g_object_unref (metadata); - } -} static void psd_lmode_layer (gint32 idLayer, @@ -1520,7 +1358,7 @@ create_merged_image (gint32 image_id) { gint32 projection; - projection = gimp_layer_new_from_visible (image_id, image_id, SAVE_PROC); + projection = gimp_layer_new_from_visible (image_id, image_id, "psd-save"); if (gimp_image_base_type (image_id) != GIMP_INDEXED) { @@ -1612,7 +1450,7 @@ get_image_data (FILE *fd, PSDImageData.layersDim = g_new (PSD_Layer_Dimension, PSDImageData.nLayers); } -static gint +gboolean save_image (const gchar *filename, gint32 image_id, GError **error) diff --git a/plug-ins/file-psd/psd-save.h b/plug-ins/file-psd/psd-save.h new file mode 100644 index 0000000000..14a4182f27 --- /dev/null +++ b/plug-ins/file-psd/psd-save.h @@ -0,0 +1,27 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __PSD_SAVE_H__ +#define __PSD_SAVE_H__ + + +gboolean save_image (const gchar *filename, + gint32 image_id, + GError **error); + + +#endif /* __PSD_SAVE_H__ */ diff --git a/plug-ins/file-psd/psd.c b/plug-ins/file-psd/psd.c index a7911e61cc..96476fa784 100644 --- a/plug-ins/file-psd/psd.c +++ b/plug-ins/file-psd/psd.c @@ -27,11 +27,8 @@ #include "psd.h" #include "psd-load.h" -#include "psd-thumb-load.h" - -#ifdef PSD_SAVE #include "psd-save.h" -#endif +#include "psd-thumb-load.h" #include "libgimp/stdplugins-intl.h" @@ -62,7 +59,6 @@ MAIN () static void query (void) { - /* Register parameters */ /* File Load */ static const GimpParamDef load_args[] = { @@ -90,7 +86,6 @@ query (void) { GIMP_PDB_INT32, "image-height", "Height of full-sized image" } }; -#ifdef PSD_SAVE /* File save */ static const GimpParamDef save_args[] = { @@ -98,11 +93,10 @@ query (void) { GIMP_PDB_IMAGE, "image", "Input image" }, { GIMP_PDB_DRAWABLE, "drawable", "Drawable to save" }, { GIMP_PDB_STRING, "filename", "The name of the file to save the image in" }, - { GIMP_PDB_STRING, "raw-filename", "The name of the file to save the image in" } + { GIMP_PDB_STRING, "raw-filename", "The name of the file to save the image in" }, + { GIMP_PDB_INT32, "compression", "Compression type: { NONE (0), LZW (1), PACKBITS (2)" }, + { GIMP_PDB_INT32, "fill-order", "Fill Order: { MSB to LSB (0), LSB to MSB (1)" } }; -#endif /* PSD_SAVE */ - - /* Register procedures */ /* File load */ gimp_install_procedure (LOAD_PROC, @@ -142,24 +136,20 @@ query (void) gimp_register_thumbnail_loader (LOAD_PROC, LOAD_THUMB_PROC); -#ifdef PSD_SAVE - /* File save*/ gimp_install_procedure (SAVE_PROC, - "Saves images to the Photoshop PSD file format", - "This plug-in saves images in Adobe " - "Photoshop (TM) native PSD format.", - "John Marshall", - "John Marshall", - "2007", + "saves files in the Photoshop(tm) PSD file format", + "This filter saves files of Adobe Photoshop(tm) native PSD format. These files may be of any image type supported by GIMP, with or without layers, layer masks, aux channels and guides.", + "Monigotes", + "Monigotes", + "2000", N_("Photoshop image"), "RGB*, GRAY*, INDEXED*", GIMP_PLUGIN, G_N_ELEMENTS (save_args), 0, save_args, NULL); - gimp_register_save_handler (SAVE_PROC, "psd", ""); gimp_register_file_handler_mime (SAVE_PROC, "image/x-psd"); -#endif /* PSD_SAVE */ + gimp_register_save_handler (SAVE_PROC, "psd", ""); } static void @@ -174,10 +164,6 @@ run (const gchar *name, GimpPDBStatusType status = GIMP_PDB_SUCCESS; gint32 image_ID; GError *error = NULL; -#ifdef PSD_SAVE - gint32 drawable_ID; - GimpExportReturn export = GIMP_EXPORT_CANCEL; -#endif /* PSD_SAVE */ run_mode = param[0].data.d_int32; @@ -190,7 +176,6 @@ run (const gchar *name, values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; - /* File load */ if (strcmp (name, LOAD_PROC) == 0) { gboolean resolution_loaded = FALSE; @@ -244,8 +229,6 @@ run (const gchar *name, status = GIMP_PDB_EXECUTION_ERROR; } } - - /* Thumbnail load */ else if (strcmp (name, LOAD_THUMB_PROC) == 0) { if (nparams < 2) @@ -276,13 +259,18 @@ run (const gchar *name, } } } - -#ifdef PSD_SAVE - /* File save */ else if (strcmp (name, SAVE_PROC) == 0) { - image_ID = param[1].data.d_int32; - drawable_ID = param[2].data.d_int32; + gint32 drawable_id; + GimpMetadata *metadata; + GimpMetadataSaveFlags metadata_flags; + GimpExportReturn export = GIMP_EXPORT_IGNORE; + + IFDBG(2) g_debug ("\n---------------- %s ----------------\n", + param[3].data.d_string); + + image_ID = param[1].data.d_int32; + drawable_id = param[2].data.d_int32; switch (run_mode) { @@ -290,7 +278,7 @@ run (const gchar *name, case GIMP_RUN_WITH_LAST_VALS: gimp_ui_init (PLUG_IN_BINARY, FALSE); - export = gimp_export_image (&image_ID, &drawable_ID, "PSD", + export = gimp_export_image (&image_ID, &drawable_id, "PSD", GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_GRAY | GIMP_EXPORT_CAN_HANDLE_INDEXED | @@ -304,26 +292,51 @@ run (const gchar *name, return; } break; + default: break; } - if (status == GIMP_PDB_SUCCESS) + metadata = gimp_image_metadata_save_prepare (image_ID, + "image/x-psd", + &metadata_flags); + + if (save_image (param[3].data.d_string, image_ID, &error)) { - if (save_image (param[3].data.d_string, image_ID, drawable_ID, - &error)) + if (metadata) { + GFile *file; + + gimp_metadata_set_bits_per_sample (metadata, 8); + + file = g_file_new_for_path (param[3].data.d_string); + gimp_image_metadata_save_finish (image_ID, + "image/x-psd", + metadata, metadata_flags, + file, NULL); + g_object_unref (file); } - else + + values[0].data.d_status = GIMP_PDB_SUCCESS; + } + else + { + values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; + + if (error) { - status = GIMP_PDB_EXECUTION_ERROR; + *nreturn_vals = 2; + values[1].type = GIMP_PDB_STRING; + values[1].data.d_string = error->message; } } if (export == GIMP_EXPORT_EXPORT) gimp_image_delete (image_ID); + + if (metadata) + g_object_unref (metadata); } -#endif /* PSD_SAVE */ /* Unknown procedure */ else diff --git a/plug-ins/file-psd/psd.h b/plug-ins/file-psd/psd.h index f9a6a650c0..efcf89b6ce 100644 --- a/plug-ins/file-psd/psd.h +++ b/plug-ins/file-psd/psd.h @@ -21,12 +21,6 @@ #ifndef __PSD_H__ #define __PSD_H__ -/* Temporary disable of save functionality */ -#ifdef PSD_SAVE -#undef PSD_SAVE -#else -/* #define PSD_SAVE */ -#endif /* Set to the level of debugging output you want, 0 for none. * Setting higher than 2 will result in a very large amount of debug