[gimp/wip/Jehan/classy-GIMP: 49/50] plug-ins: port file-psd to GimpImage/GimpDrawable.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/Jehan/classy-GIMP: 49/50] plug-ins: port file-psd to GimpImage/GimpDrawable.
- Date: Thu, 22 Aug 2019 13:58:55 +0000 (UTC)
commit 2d0584dc918dedf6f62e497943f42d32f1aa193d
Author: Jehan <jehan girinstud io>
Date: Mon Aug 19 16:04:15 2019 +0200
plug-ins: port file-psd to GimpImage/GimpDrawable.
plug-ins/file-psd/Makefile.am | 1 -
plug-ins/file-psd/psd-image-res-load.c | 174 ++++++-------
plug-ins/file-psd/psd-image-res-load.h | 4 +-
plug-ins/file-psd/psd-load.c | 230 ++++++++---------
plug-ins/file-psd/psd-load.h | 10 +-
plug-ins/file-psd/psd-save.c | 456 +++++++++++++++++----------------
plug-ins/file-psd/psd-save.h | 2 +-
plug-ins/file-psd/psd-thumb-load.c | 48 ++--
plug-ins/file-psd/psd-thumb-load.h | 8 +-
plug-ins/file-psd/psd.c | 48 ++--
10 files changed, 494 insertions(+), 487 deletions(-)
---
diff --git a/plug-ins/file-psd/Makefile.am b/plug-ins/file-psd/Makefile.am
index 709fd74f05..d8f4f3577e 100644
--- a/plug-ins/file-psd/Makefile.am
+++ b/plug-ins/file-psd/Makefile.am
@@ -45,7 +45,6 @@ EXTRA_DIST = \
new-resource-ids.txt
AM_CPPFLAGS = \
- -DGIMP_DEPRECATED_REPLACE_NEW_API \
-DG_LOG_DOMAIN=\"file-psd\" \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
diff --git a/plug-ins/file-psd/psd-image-res-load.c b/plug-ins/file-psd/psd-image-res-load.c
index 7949c6ca52..650ed44cb1 100644
--- a/plug-ins/file-psd/psd-image-res-load.c
+++ b/plug-ins/file-psd/psd-image-res-load.c
@@ -137,99 +137,99 @@
/* Local function prototypes */
static gint load_resource_unknown (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_ps_only (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1005 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1006 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
static gint load_resource_1007 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
static gint load_resource_1008 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1022 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
static gint load_resource_1024 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
static gint load_resource_1028 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1032 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1033 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1039 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1045 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
static gint load_resource_1046 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1053 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
static gint load_resource_1058 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
static gint load_resource_1077 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
static gint load_resource_2000 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
@@ -274,7 +274,7 @@ get_image_resource_header (PSDimageres *res_a,
gint
load_image_resource (PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
gboolean *resolution_loaded,
@@ -322,87 +322,87 @@ load_image_resource (PSDimageres *res_a,
case PSD_JPEG_QUAL:
/* Save photoshop resources with no meaning for GIMP
as image parasites */
- load_resource_ps_only (res_a, image_id, f, error);
+ load_resource_ps_only (res_a, image, f, error);
break;
case PSD_RESN_INFO:
- if (! load_resource_1005 (res_a, image_id, f, error))
+ if (! load_resource_1005 (res_a, image, f, error))
*resolution_loaded = TRUE;
break;
case PSD_ALPHA_NAMES:
if (! img_a->merged_image_only)
- load_resource_1006 (res_a, image_id, img_a, f, error);
+ load_resource_1006 (res_a, image, img_a, f, error);
break;
case PSD_DISPLAY_INFO:
- load_resource_1007 (res_a, image_id, img_a, f, error);
+ load_resource_1007 (res_a, image, img_a, f, error);
break;
case PSD_CAPTION:
- load_resource_1008 (res_a, image_id, f, error);
+ load_resource_1008 (res_a, image, f, error);
break;
case PSD_QUICK_MASK:
if (! img_a->merged_image_only)
- load_resource_1022 (res_a, image_id, img_a, f, error);
+ load_resource_1022 (res_a, image, img_a, f, error);
break;
case PSD_LAYER_STATE:
if (! img_a->merged_image_only)
- load_resource_1024 (res_a, image_id, img_a, f, error);
+ load_resource_1024 (res_a, image, img_a, f, error);
break;
case PSD_WORKING_PATH:
if (! img_a->merged_image_only)
- load_resource_2000 (res_a, image_id, f, error);
+ load_resource_2000 (res_a, image, f, error);
break;
case PSD_IPTC_NAA_DATA:
- load_resource_1028 (res_a, image_id, f, error);
+ load_resource_1028 (res_a, image, f, error);
break;
case PSD_GRID_GUIDE:
if (! img_a->merged_image_only)
- load_resource_1032 (res_a, image_id, f, error);
+ load_resource_1032 (res_a, image, f, error);
break;
case PSD_ICC_PROFILE:
- if (! load_resource_1039 (res_a, image_id, f, error))
+ if (! load_resource_1039 (res_a, image, f, error))
*profile_loaded = TRUE;
break;
case PSD_ALPHA_NAMES_UNI:
if (! img_a->merged_image_only)
- load_resource_1045 (res_a, image_id, img_a, f, error);
+ load_resource_1045 (res_a, image, img_a, f, error);
break;
case PSD_IDX_COL_TAB_CNT:
- load_resource_1046 (res_a, image_id, f, error);
+ load_resource_1046 (res_a, image, f, error);
break;
case PSD_ALPHA_ID:
if (! img_a->merged_image_only)
- load_resource_1053 (res_a, image_id, img_a, f, error);
+ load_resource_1053 (res_a, image, img_a, f, error);
break;
case PSD_EXIF_DATA:
- load_resource_1058 (res_a, image_id, f, error);
+ load_resource_1058 (res_a, image, f, error);
break;
case PSD_XMP_DATA:
break;
case PSD_DISPLAY_INFO_NEW:
- load_resource_1077 (res_a, image_id, img_a, f, error);
+ load_resource_1077 (res_a, image, img_a, f, error);
break;
default:
if (res_a->id >= 2000 &&
res_a->id < 2999)
- load_resource_2000 (res_a, image_id, f, error);
+ load_resource_2000 (res_a, image, f, error);
else
- load_resource_unknown (res_a, image_id, f, error);
+ load_resource_unknown (res_a, image, f, error);
}
}
@@ -424,7 +424,7 @@ load_image_resource (PSDimageres *res_a,
gint
load_thumbnail_resource (PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -443,7 +443,7 @@ load_thumbnail_resource (PSDimageres *res_a,
|| res_a->id == PSD_THUMB_RES2)
{
/* Load thumbnails from standard file load */
- load_resource_1033 (res_a, image_id, f, error);
+ load_resource_1033 (res_a, image, f, error);
rtn = 1;
}
@@ -467,7 +467,7 @@ load_thumbnail_resource (PSDimageres *res_a,
static gint
load_resource_unknown (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -491,7 +491,7 @@ load_resource_unknown (const PSDimageres *res_a,
IFDBG(2) g_debug ("Parasite name: %s", name);
parasite = gimp_parasite_new (name, 0, res_a->data_len, data);
- gimp_image_attach_parasite (image_id, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
g_free (data);
g_free (name);
@@ -501,7 +501,7 @@ load_resource_unknown (const PSDimageres *res_a,
static gint
load_resource_ps_only (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -526,7 +526,7 @@ load_resource_ps_only (const PSDimageres *res_a,
IFDBG(2) g_debug ("Parasite name: %s", name);
parasite = gimp_parasite_new (name, 0, res_a->data_len, data);
- gimp_image_attach_parasite (image_id, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
g_free (data);
g_free (name);
@@ -536,7 +536,7 @@ load_resource_ps_only (const PSDimageres *res_a,
static gint
load_resource_1005 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -577,7 +577,7 @@ load_resource_1005 (const PSDimageres *res_a,
/* Resolution always recorded as pixels / inch in a fixed point implied
decimal int32 with 16 bits before point and 16 after (i.e. cast as
double and divide resolution by 2^16 */
- gimp_image_set_resolution (image_id,
+ gimp_image_set_resolution (image,
res_info.hRes / 65536.0, res_info.vRes / 65536.0);
/* GIMP only has one display unit so use ps horizontal resolution unit */
@@ -593,14 +593,14 @@ load_resource_1005 (const PSDimageres *res_a,
image_unit = GIMP_UNIT_INCH;
}
- gimp_image_set_unit (image_id, image_unit);
+ gimp_image_set_unit (image, image_unit);
return 0;
}
static gint
load_resource_1006 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -642,7 +642,7 @@ load_resource_1006 (const PSDimageres *res_a,
static gint
load_resource_1007 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -750,7 +750,7 @@ load_resource_1007 (const PSDimageres *res_a,
static gint
load_resource_1008 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -768,7 +768,7 @@ load_resource_1008 (const PSDimageres *res_a,
IFDBG(3) g_debug ("Caption: %s", caption);
parasite = gimp_parasite_new (GIMP_PARASITE_COMMENT, GIMP_PARASITE_PERSISTENT,
write_len, caption);
- gimp_image_attach_parasite (image_id, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
g_free (caption);
@@ -777,7 +777,7 @@ load_resource_1008 (const PSDimageres *res_a,
static gint
load_resource_1022 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -804,7 +804,7 @@ load_resource_1022 (const PSDimageres *res_a,
static gint
load_resource_1024 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -824,7 +824,7 @@ load_resource_1024 (const PSDimageres *res_a,
static gint
load_resource_1028 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -865,7 +865,7 @@ load_resource_1028 (const PSDimageres *res_a,
parasite = gimp_parasite_new (GIMP_PARASITE_IPTC,
GIMP_PARASITE_PERSISTENT,
iptc_buf_len, iptc_buf);
- gimp_image_attach_parasite (image_id, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
}
@@ -880,7 +880,7 @@ load_resource_1028 (const PSDimageres *res_a,
IFDBG(3) g_debug ("Parasite name: %s", name);
parasite = gimp_parasite_new (name, 0, res_a->data_len, res_data);
- gimp_image_attach_parasite (image_id, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
g_free (name);
@@ -892,7 +892,7 @@ load_resource_1028 (const PSDimageres *res_a,
static gint
load_resource_1032 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -941,9 +941,9 @@ load_resource_1032 (const PSDimageres *res_a,
guide.fDirection);
if (guide.fDirection == PSD_VERTICAL)
- gimp_image_add_vguide (image_id, guide.fLocation);
+ gimp_image_add_vguide (image, guide.fLocation);
else
- gimp_image_add_hguide (image_id, guide.fLocation);
+ gimp_image_add_hguide (image, guide.fLocation);
}
return 0;
@@ -951,7 +951,7 @@ load_resource_1032 (const PSDimageres *res_a,
static gint
load_resource_1033 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -963,7 +963,7 @@ load_resource_1033 (const PSDimageres *res_a,
ThumbnailInfo thumb_info;
GeglBuffer *buffer;
const Babl *format;
- gint32 layer_id;
+ GimpLayer *layer;
guchar *buf;
guchar *rgb_buf;
guchar **rowbuf;
@@ -1038,14 +1038,14 @@ load_resource_1033 (const PSDimageres *res_a,
rowbuf[i] = buf + cinfo.output_width * cinfo.output_components * i;
/* Create image layer */
- gimp_image_resize (image_id, cinfo.output_width, cinfo.output_height, 0, 0);
- layer_id = gimp_layer_new (image_id, _("Background"),
- cinfo.output_width,
- cinfo.output_height,
- GIMP_RGB_IMAGE,
- 100,
- gimp_image_get_default_new_layer_mode (image_id));
- buffer = gimp_drawable_get_buffer (layer_id);
+ gimp_image_resize (image, cinfo.output_width, cinfo.output_height, 0, 0);
+ layer = gimp_layer_new (image, _("Background"),
+ cinfo.output_width,
+ cinfo.output_height,
+ GIMP_RGB_IMAGE,
+ 100,
+ gimp_image_get_default_new_layer_mode (image));
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
format = babl_format ("R'G'B' u8");
/* Step 6: while (scan lines remain to be read) */
@@ -1097,7 +1097,7 @@ load_resource_1033 (const PSDimageres *res_a,
* corrupt-data warnings occurred (test whether
* jerr.num_warnings is nonzero).
*/
- gimp_image_insert_layer (image_id, layer_id, -1, 0);
+ gimp_image_insert_layer (image, layer, NULL, 0);
g_object_unref (buffer);
return 0;
@@ -1105,7 +1105,7 @@ load_resource_1033 (const PSDimageres *res_a,
static gint
load_resource_1039 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -1128,7 +1128,7 @@ load_resource_1039 (const PSDimageres *res_a,
NULL);
if (profile)
{
- gimp_image_set_color_profile (image_id, profile);
+ gimp_image_set_color_profile (image, profile);
g_object_unref (profile);
}
@@ -1139,7 +1139,7 @@ load_resource_1039 (const PSDimageres *res_a,
static gint
load_resource_1045 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -1188,7 +1188,7 @@ load_resource_1045 (const PSDimageres *res_a,
static gint
load_resource_1046 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -1210,9 +1210,9 @@ load_resource_1046 (const PSDimageres *res_a,
/* FIXME - check that we have indexed image */
if (index_count && index_count < 256)
{
- cmap = gimp_image_get_colormap (image_id, &cmap_count);
+ cmap = gimp_image_get_colormap (image, &cmap_count);
if (cmap && index_count < cmap_count)
- gimp_image_set_colormap (image_id, cmap, index_count);
+ gimp_image_set_colormap (image, cmap, index_count);
g_free (cmap);
}
return 0;
@@ -1220,7 +1220,7 @@ load_resource_1046 (const PSDimageres *res_a,
static gint
load_resource_1053 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -1254,7 +1254,7 @@ load_resource_1053 (const PSDimageres *res_a,
static gint
load_resource_1058 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
@@ -1280,7 +1280,7 @@ load_resource_1058 (const PSDimageres *res_a,
IFDBG(3) g_debug ("Parasite name: %s", name);
parasite = gimp_parasite_new (name, 0, res_a->data_len, res_data);
- gimp_image_attach_parasite (image_id, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
g_free (name);
@@ -1290,7 +1290,7 @@ load_resource_1058 (const PSDimageres *res_a,
static gint
load_resource_1077 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -1402,14 +1402,14 @@ load_resource_1077 (const PSDimageres *res_a,
static gint
load_resource_2000 (const PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error)
{
gdouble *controlpoints;
gint32 x[3];
gint32 y[3];
- gint32 vector_id = -1;
+ GimpVectors *vectors = NULL;
gint16 type;
gint16 init_fill;
gint16 num_rec;
@@ -1449,22 +1449,22 @@ load_resource_2000 (const PSDimageres *res_a,
if (path_rec ==0)
return 0;
- image_width = gimp_image_width (image_id);
- image_height = gimp_image_height (image_id);
+ image_width = gimp_image_width (image);
+ image_height = gimp_image_height (image);
/* Create path */
if (res_a->id == PSD_WORKING_PATH)
{
/* use "Working Path" for the path name to match the Photoshop display */
- vector_id = gimp_vectors_new (image_id, "Working Path");
+ vectors = gimp_vectors_new (image, "Working Path");
}
else
{
/* Use the name stored in the PSD to name the path */
- vector_id = gimp_vectors_new (image_id, res_a->name);
+ vectors = gimp_vectors_new (image, res_a->name);
}
- gimp_image_insert_vectors (image_id, vector_id, -1, -1);
+ gimp_image_insert_vectors (image, vectors, NULL, -1);
while (path_rec > 0)
{
@@ -1579,7 +1579,7 @@ load_resource_2000 (const PSDimageres *res_a,
num_rec--;
}
/* Add sub-path */
- gimp_vectors_stroke_new_from_points (vector_id,
+ gimp_vectors_stroke_new_from_points (vectors,
GIMP_VECTORS_STROKE_TYPE_BEZIER,
cntr, controlpoints, closed);
g_free (controlpoints);
diff --git a/plug-ins/file-psd/psd-image-res-load.h b/plug-ins/file-psd/psd-image-res-load.h
index c981a6b79f..c21a995929 100644
--- a/plug-ins/file-psd/psd-image-res-load.h
+++ b/plug-ins/file-psd/psd-image-res-load.h
@@ -27,7 +27,7 @@ gint get_image_resource_header (PSDimageres *res_a,
GError **error);
gint load_image_resource (PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
PSDimage *img_a,
FILE *f,
gboolean *resolution_loaded,
@@ -35,7 +35,7 @@ gint load_image_resource (PSDimageres *res_a,
GError **error);
gint load_thumbnail_resource (PSDimageres *res_a,
- gint32 image_id,
+ GimpImage *image,
FILE *f,
GError **error);
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index d973eba29a..333842c3a3 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -60,26 +60,26 @@ static gint read_merged_image_block (PSDimage *img_a,
FILE *f,
GError **error);
-static gint32 create_gimp_image (PSDimage *img_a,
+static GimpImage * create_gimp_image (PSDimage *img_a,
const gchar *filename);
-static gint add_color_map (gint32 image_id,
+static gint add_color_map (GimpImage *image,
PSDimage *img_a);
-static gint add_image_resources (gint32 image_id,
+static gint add_image_resources (GimpImage *image,
PSDimage *img_a,
FILE *f,
gboolean *resolution_loaded,
gboolean *profile_loaded,
GError **error);
-static gint add_layers (gint32 image_id,
+static gint add_layers (GimpImage *image,
PSDimage *img_a,
PSDlayer **lyr_a,
FILE *f,
GError **error);
-static gint add_merged_image (gint32 image_id,
+static gint add_merged_image (GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
@@ -112,7 +112,7 @@ static const Babl* get_mask_format (PSDimage *img_a);
/* Main file load function */
-gint32
+GimpImage *
load_image (const gchar *filename,
gboolean merged_image_only,
gboolean *resolution_loaded,
@@ -123,12 +123,12 @@ load_image (const gchar *filename,
struct stat st;
PSDimage img_a;
PSDlayer **lyr_a;
- gint32 image_id = -1;
- GError *error = NULL;
+ GimpImage *image = NULL;
+ GError *error = NULL;
/* ----- Open PSD file ----- */
if (g_stat (filename, &st) == -1)
- return -1;
+ return NULL;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
@@ -140,7 +140,7 @@ load_image (const gchar *filename,
g_set_error (load_error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
- return -1;
+ return NULL;
}
img_a.merged_image_only = merged_image_only;
@@ -178,20 +178,20 @@ load_image (const gchar *filename,
/* ----- Create GIMP image ----- */
IFDBG(2) g_debug ("Create GIMP image");
- image_id = create_gimp_image (&img_a, filename);
- if (image_id < 0)
+ image = create_gimp_image (&img_a, filename);
+ if (! image)
goto load_error;
gimp_progress_update (0.6);
/* ----- Add color map ----- */
IFDBG(2) g_debug ("Add color map");
- if (add_color_map (image_id, &img_a) < 0)
+ if (add_color_map (image, &img_a) < 0)
goto load_error;
gimp_progress_update (0.7);
/* ----- Add image resources ----- */
IFDBG(2) g_debug ("Add image resources");
- if (add_image_resources (image_id, &img_a, f,
+ if (add_image_resources (image, &img_a, f,
resolution_loaded, profile_loaded,
&error) < 0)
goto load_error;
@@ -199,24 +199,24 @@ load_image (const gchar *filename,
/* ----- Add layers -----*/
IFDBG(2) g_debug ("Add layers");
- if (add_layers (image_id, &img_a, lyr_a, f, &error) < 0)
+ if (add_layers (image, &img_a, lyr_a, f, &error) < 0)
goto load_error;
gimp_progress_update (0.9);
/* ----- Add merged image data and extra alpha channels ----- */
IFDBG(2) g_debug ("Add merged image data and extra alpha channels");
- if (add_merged_image (image_id, &img_a, f, &error) < 0)
+ if (add_merged_image (image, &img_a, f, &error) < 0)
goto load_error;
gimp_progress_update (1.0);
- IFDBG(2) g_debug ("Close file & return, image id: %d", image_id);
+ IFDBG(2) g_debug ("Close file & return, image id: %d", gimp_image_get_id (image));
IFDBG(1) g_debug ("\n----------------------------------------"
"----------------------------------------\n");
- gimp_image_clean_all (image_id);
- gimp_image_undo_enable (image_id);
+ gimp_image_clean_all (image);
+ gimp_image_undo_enable (image);
fclose (f);
- return image_id;
+ return image;
/* ----- Process load errors ----- */
load_error:
@@ -228,14 +228,14 @@ load_image (const gchar *filename,
}
/* Delete partially loaded image */
- if (image_id > 0)
- gimp_image_delete (image_id);
+ if (image)
+ gimp_image_delete (image);
/* Close file if Open */
if (! (f == NULL))
fclose (f);
- return -1;
+ return NULL;
}
@@ -973,12 +973,12 @@ read_merged_image_block (PSDimage *img_a,
return 0;
}
-static gint32
+static GimpImage *
create_gimp_image (PSDimage *img_a,
const gchar *filename)
{
- gint32 image_id = -1;
- GimpPrecision precision;
+ GimpImage *image = NULL;
+ GimpPrecision precision;
switch (img_a->color_mode)
{
@@ -999,7 +999,7 @@ create_gimp_image (PSDimage *img_a,
default:
/* Color mode already validated - should not be here */
g_warning ("Invalid color mode");
- return -1;
+ return NULL;
break;
}
@@ -1021,23 +1021,23 @@ create_gimp_image (PSDimage *img_a,
default:
/* Precision not supported */
g_warning ("Invalid precision");
- return -1;
+ return NULL;
break;
}
/* Create gimp image */
IFDBG(2) g_debug ("Create image");
- image_id = gimp_image_new_with_precision (img_a->columns, img_a->rows,
- img_a->base_type, precision);
- gimp_image_set_filename (image_id, filename);
- gimp_image_undo_disable (image_id);
+ image = gimp_image_new_with_precision (img_a->columns, img_a->rows,
+ img_a->base_type, precision);
+ gimp_image_set_filename (image, filename);
+ gimp_image_undo_disable (image);
- return image_id;
+ return image;
}
static gint
-add_color_map (gint32 image_id,
- PSDimage *img_a)
+add_color_map (GimpImage *image,
+ PSDimage *img_a)
{
GimpParasite *parasite;
@@ -1045,7 +1045,7 @@ add_color_map (gint32 image_id,
{
if (img_a->color_mode != PSD_DUOTONE)
{
- gimp_image_set_colormap (image_id, img_a->color_map,
+ gimp_image_set_colormap (image, img_a->color_map,
img_a->color_map_entries);
}
else
@@ -1054,7 +1054,7 @@ add_color_map (gint32 image_id,
IFDBG(2) g_debug ("Add Duotone color data parasite");
parasite = gimp_parasite_new (PSD_PARASITE_DUOTONE_DATA, 0,
img_a->color_map_len, img_a->color_map);
- gimp_image_attach_parasite (image_id, parasite);
+ gimp_image_attach_parasite (image, parasite);
gimp_parasite_free (parasite);
}
g_free (img_a->color_map);
@@ -1064,7 +1064,7 @@ add_color_map (gint32 image_id,
}
static gint
-add_image_resources (gint32 image_id,
+add_image_resources (GimpImage *image,
PSDimage *img_a,
FILE *f,
gboolean *resolution_loaded,
@@ -1101,7 +1101,7 @@ add_image_resources (gint32 image_id,
return 0;
}
- if (load_image_resource (&res_a, image_id, img_a, f,
+ if (load_image_resource (&res_a, image, img_a, f,
resolution_loaded, profile_loaded,
error) < 0)
return -1;
@@ -1111,7 +1111,7 @@ add_image_resources (gint32 image_id,
}
static gint
-add_layers (gint32 image_id,
+add_layers (GimpImage *image,
PSDimage *img_a,
PSDlayer **lyr_a,
FILE *f,
@@ -1119,7 +1119,7 @@ add_layers (gint32 image_id,
{
PSDchannel **lyr_chn;
GArray *parent_group_stack;
- gint32 parent_group_id = -1;
+ GimpLayer *parent_group = NULL;
guchar *pixels;
guint16 alpha_chn;
guint16 user_mask_chn;
@@ -1136,9 +1136,9 @@ add_layers (gint32 image_id,
gint32 lm_w; /* Layer mask width */
gint32 lm_h; /* Layer mask height */
gint32 layer_size;
- gint32 layer_id = -1;
- gint32 mask_id = -1;
- gint32 active_layer_id = -1;
+ GimpLayer *layer = NULL;
+ GimpLayerMask *mask = NULL;
+ GimpLayer *active_layer = NULL;
gint lidx; /* Layer index */
gint cidx; /* Channel index */
gint rowi; /* Row index */
@@ -1169,8 +1169,8 @@ add_layers (gint32 image_id,
}
/* set the root of the group hierarchy */
- parent_group_stack = g_array_new (FALSE, FALSE, sizeof (gint32));
- g_array_append_val (parent_group_stack, parent_group_id);
+ parent_group_stack = g_array_new (FALSE, FALSE, sizeof (GimpLayer *));
+ g_array_append_val (parent_group_stack, parent_group);
for (lidx = 0; lidx < img_a->num_layers; ++lidx)
{
@@ -1351,10 +1351,10 @@ add_layers (gint32 image_id,
l_w = img_a->columns;
l_h = img_a->rows;
if (parent_group_stack->len > 0)
- parent_group_id = g_array_index (parent_group_stack, gint32,
- parent_group_stack->len - 1);
+ parent_group = g_array_index (parent_group_stack, GimpLayer *,
+ parent_group_stack->len - 1);
else
- parent_group_id = -1; /* root */
+ parent_group = NULL; /* root */
IFDBG(3) g_debug ("Re-hash channel indices");
for (cidx = 0; cidx < lyr_a[lidx]->num_channels; ++cidx)
@@ -1391,17 +1391,17 @@ add_layers (gint32 image_id,
* assemble the layer structure in a single pass
*/
IFDBG(2) g_debug ("Create placeholder group layer");
- layer_id = gimp_layer_group_new (image_id);
+ layer = gimp_layer_group_new (image);
/* add this group layer as the new parent */
- g_array_append_val (parent_group_stack, layer_id);
+ g_array_append_val (parent_group_stack, layer);
}
else /* group-type == 1 || group_type == 2 */
{
if (parent_group_stack->len)
{
- layer_id = g_array_index (parent_group_stack, gint32,
- parent_group_stack->len - 1);
- IFDBG(2) g_debug ("End group layer id %d.", layer_id);
+ layer = g_array_index (parent_group_stack, GimpLayer *,
+ parent_group_stack->len - 1);
+ IFDBG(2) g_debug ("End group layer id %d.", gimp_item_get_id (GIMP_ITEM (layer)));
/* since the layers are stored in reverse, the group
* layer start marker actually means we're done with
* that layer group
@@ -1409,15 +1409,15 @@ add_layers (gint32 image_id,
g_array_remove_index (parent_group_stack,
parent_group_stack->len - 1);
- gimp_drawable_offsets (layer_id, &l_x, &l_y);
+ gimp_drawable_offsets (GIMP_DRAWABLE (layer), &l_x, &l_y);
- l_w = gimp_drawable_width (layer_id);
- l_h = gimp_drawable_height (layer_id);
+ l_w = gimp_drawable_width (GIMP_DRAWABLE (layer));
+ l_h = gimp_drawable_height (GIMP_DRAWABLE (layer));
}
else
{
IFDBG(1) g_debug ("WARNING: Unmatched group layer start marker.");
- layer_id = -1;
+ layer = NULL;
}
}
}
@@ -1439,19 +1439,19 @@ add_layers (gint32 image_id,
image_type = get_gimp_image_type (img_a->base_type, TRUE);
IFDBG(3) g_debug ("Layer type %d", image_type);
- layer_id = gimp_layer_new (image_id, lyr_a[lidx]->name,
- l_w, l_h, image_type,
- 100, GIMP_LAYER_MODE_NORMAL);
+ layer = gimp_layer_new (image, lyr_a[lidx]->name,
+ l_w, l_h, image_type,
+ 100, GIMP_LAYER_MODE_NORMAL);
}
- if (layer_id != -1)
+ if (layer != NULL)
{
/* Set the layer name. Note that we do this even for group-end
* markers, to avoid having the default group name collide with
* subsequent layers; the real group name is set by the group
* start marker.
*/
- gimp_item_set_name (layer_id, lyr_a[lidx]->name);
+ gimp_item_set_name (GIMP_ITEM (layer), lyr_a[lidx]->name);
/* Set the layer properties (skip this for layer group end
* markers; we set their properties when processing the start
@@ -1461,18 +1461,18 @@ add_layers (gint32 image_id,
{
/* Mode */
psd_to_gimp_blend_mode (lyr_a[lidx]->blend_mode, &mode_info);
- gimp_layer_set_mode (layer_id, mode_info.mode);
- gimp_layer_set_blend_space (layer_id, mode_info.blend_space);
- gimp_layer_set_composite_space (layer_id, mode_info.composite_space);
- gimp_layer_set_composite_mode (layer_id, mode_info.composite_mode);
+ gimp_layer_set_mode (layer, mode_info.mode);
+ gimp_layer_set_blend_space (layer, mode_info.blend_space);
+ gimp_layer_set_composite_space (layer, mode_info.composite_space);
+ gimp_layer_set_composite_mode (layer, mode_info.composite_mode);
/* Opacity */
- gimp_layer_set_opacity (layer_id,
+ gimp_layer_set_opacity (layer,
lyr_a[lidx]->opacity * 100.0 / 255.0);
/* Flags */
- gimp_layer_set_lock_alpha (layer_id, lyr_a[lidx]->layer_flags.trans_prot);
- gimp_item_set_visible (layer_id, lyr_a[lidx]->layer_flags.visible);
+ gimp_layer_set_lock_alpha (layer, lyr_a[lidx]->layer_flags.trans_prot);
+ gimp_item_set_visible (GIMP_ITEM (layer), lyr_a[lidx]->layer_flags.visible);
#if 0
/* according to the spec, the 'irrelevant' flag indicates
* that the layer's "pixel data is irrelevant to the
@@ -1487,26 +1487,26 @@ add_layers (gint32 image_id,
if (lyr_a[lidx]->layer_flags.irrelevant &&
lyr_a[lidx]->group_type == 0)
{
- gimp_item_set_visible (layer_id, FALSE);
+ gimp_item_set_visible (GIMP_ITEM (layer), FALSE);
}
#endif
/* Position */
if (l_x != 0 || l_y != 0)
- gimp_layer_set_offsets (layer_id, l_x, l_y);
+ gimp_layer_set_offsets (layer, l_x, l_y);
/* Color tag */
- gimp_item_set_color_tag (layer_id,
+ gimp_item_set_color_tag (GIMP_ITEM (layer),
psd_to_gimp_layer_color_tag (lyr_a[lidx]->color_tag[0]));
/* Tattoo */
if (lyr_a[lidx]->id)
- gimp_item_set_tattoo (layer_id, lyr_a[lidx]->id);
+ gimp_item_set_tattoo (GIMP_ITEM (layer), lyr_a[lidx]->id);
/* For layer groups, expand or collapse the group */
if (lyr_a[lidx]->group_type != 0)
{
- gimp_item_set_expanded (layer_id,
+ gimp_item_set_expanded (GIMP_ITEM (layer),
lyr_a[lidx]->group_type == 1);
}
}
@@ -1514,7 +1514,7 @@ add_layers (gint32 image_id,
/* Remember the active layer ID */
if (lidx == img_a->layer_state)
{
- active_layer_id = layer_id;
+ active_layer = layer;
}
/* Set the layer data */
@@ -1524,7 +1524,7 @@ add_layers (gint32 image_id,
if (empty)
{
- gimp_drawable_fill (layer_id, GIMP_FILL_TRANSPARENT);
+ gimp_drawable_fill (GIMP_DRAWABLE (layer), GIMP_FILL_TRANSPARENT);
}
else
{
@@ -1542,7 +1542,7 @@ add_layers (gint32 image_id,
g_free (lyr_chn[channel_idx[cidx]]->data);
}
- buffer = gimp_drawable_get_buffer (layer_id);
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gegl_buffer_set (buffer,
GEGL_RECTANGLE (0, 0,
gegl_buffer_get_width (buffer),
@@ -1561,14 +1561,14 @@ add_layers (gint32 image_id,
{
IFDBG(3) g_debug ("Create empty mask");
if (lyr_a[lidx]->layer_mask.def_color == 255)
- mask_id = gimp_layer_create_mask (layer_id,
- GIMP_ADD_MASK_WHITE);
+ mask = gimp_layer_create_mask (layer,
+ GIMP_ADD_MASK_WHITE);
else
- mask_id = gimp_layer_create_mask (layer_id,
- GIMP_ADD_MASK_BLACK);
- gimp_layer_add_mask (layer_id, mask_id);
- gimp_layer_set_apply_mask (layer_id,
- ! lyr_a[lidx]->layer_mask.mask_flags.disabled);
+ mask = gimp_layer_create_mask (layer,
+ GIMP_ADD_MASK_BLACK);
+ gimp_layer_add_mask (layer, mask);
+ gimp_layer_set_apply_mask (layer,
+ ! lyr_a[lidx]->layer_mask.mask_flags.disabled);
}
else
{
@@ -1637,21 +1637,21 @@ add_layers (gint32 image_id,
IFDBG(3) g_debug ("Mask %d %d %d %d", lm_x, lm_y, lm_w, lm_h);
if (lyr_a[lidx]->layer_mask.def_color == 255)
- mask_id = gimp_layer_create_mask (layer_id,
- GIMP_ADD_MASK_WHITE);
+ mask = gimp_layer_create_mask (layer,
+ GIMP_ADD_MASK_WHITE);
else
- mask_id = gimp_layer_create_mask (layer_id,
- GIMP_ADD_MASK_BLACK);
+ mask = gimp_layer_create_mask (layer,
+ GIMP_ADD_MASK_BLACK);
- IFDBG(3) g_debug ("New layer mask %d", mask_id);
- gimp_layer_add_mask (layer_id, mask_id);
- buffer = gimp_drawable_get_buffer (mask_id);
+ IFDBG(3) g_debug ("New layer mask %d", gimp_item_get_id (GIMP_ITEM (mask)));
+ gimp_layer_add_mask (layer, mask);
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask));
gegl_buffer_set (buffer,
GEGL_RECTANGLE (lm_x, lm_y, lm_w, lm_h),
0, get_mask_format (img_a),
pixels, GEGL_AUTO_ROWSTRIDE);
g_object_unref (buffer);
- gimp_layer_set_apply_mask (layer_id,
+ gimp_layer_set_apply_mask (layer,
! lyr_a[lidx]->layer_mask.mask_flags.disabled);
}
g_free (pixels);
@@ -1662,7 +1662,7 @@ add_layers (gint32 image_id,
if (lyr_a[lidx]->group_type == 0 || /* normal layer */
lyr_a[lidx]->group_type == 3 /* group layer end marker */)
{
- gimp_image_insert_layer (image_id, layer_id, parent_group_id, 0);
+ gimp_image_insert_layer (image, layer, parent_group, 0);
}
}
@@ -1679,14 +1679,14 @@ add_layers (gint32 image_id,
g_array_free (parent_group_stack, FALSE);
/* Set the active layer */
- if (active_layer_id >= 0)
- gimp_image_set_active_layer (image_id, active_layer_id);
+ if (active_layer >= 0)
+ gimp_image_set_active_layer (image, active_layer);
return 0;
}
static gint
-add_merged_image (gint32 image_id,
+add_merged_image (GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -1702,8 +1702,8 @@ add_merged_image (gint32 image_id,
guint16 *rle_pack_len[MAX_CHANNELS];
guint32 alpha_id;
gint32 layer_size;
- gint32 layer_id = -1;
- gint32 channel_id = -1;
+ GimpLayer *layer = NULL;
+ GimpChannel *channel = NULL;
gint16 alpha_opacity;
gint cidx; /* Channel index */
gint rowi; /* Row index */
@@ -1855,14 +1855,14 @@ add_merged_image (gint32 image_id,
/* Add background layer */
IFDBG(2) g_debug ("Draw merged image");
- layer_id = gimp_layer_new (image_id, _("Background"),
- img_a->columns, img_a->rows,
- image_type,
- 100,
- gimp_image_get_default_new_layer_mode (image_id));
- gimp_image_insert_layer (image_id, layer_id, -1, 0);
-
- buffer = gimp_drawable_get_buffer (layer_id);
+ layer = gimp_layer_new (image, _("Background"),
+ img_a->columns, img_a->rows,
+ image_type,
+ 100,
+ gimp_image_get_default_new_layer_mode (image));
+ gimp_image_insert_layer (image, layer, NULL, 0);
+
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gegl_buffer_set (buffer,
GEGL_RECTANGLE (0, 0,
gegl_buffer_get_width (buffer),
@@ -1923,7 +1923,7 @@ add_merged_image (gint32 image_id,
/* ----- Draw extra alpha channels ----- */
if (extra_channels /* Extra alpha channels */
- && image_id > -1)
+ && image)
{
IFDBG(2) g_debug ("Add extra channels");
pixels = g_malloc(0);
@@ -1979,15 +1979,15 @@ add_merged_image (gint32 image_id,
cidx = base_channels + i;
pixels = g_realloc (pixels, chn_a[cidx].columns * chn_a[cidx].rows * bps);
memcpy (pixels, chn_a[cidx].data, chn_a[cidx].columns * chn_a[cidx].rows * bps);
- channel_id = gimp_channel_new (image_id, alpha_name,
- chn_a[cidx].columns, chn_a[cidx].rows,
- alpha_opacity, &alpha_rgb);
- gimp_image_insert_channel (image_id, channel_id, -1, 0);
+ channel = gimp_channel_new (image, alpha_name,
+ chn_a[cidx].columns, chn_a[cidx].rows,
+ alpha_opacity, &alpha_rgb);
+ gimp_image_insert_channel (image, channel, NULL, 0);
g_free (alpha_name);
- buffer = gimp_drawable_get_buffer (channel_id);
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (channel));
if (alpha_id)
- gimp_item_set_tattoo (channel_id, alpha_id);
- gimp_item_set_visible (channel_id, alpha_visible);
+ gimp_item_set_tattoo (GIMP_ITEM (channel), alpha_id);
+ gimp_item_set_visible (GIMP_ITEM (channel), alpha_visible);
gegl_buffer_set (buffer,
GEGL_RECTANGLE (0, 0,
gegl_buffer_get_width (buffer),
diff --git a/plug-ins/file-psd/psd-load.h b/plug-ins/file-psd/psd-load.h
index 42eb516315..66d1d228a5 100644
--- a/plug-ins/file-psd/psd-load.h
+++ b/plug-ins/file-psd/psd-load.h
@@ -22,11 +22,11 @@
#define __PSD_LOAD_H__
-gint32 load_image (const gchar *filename,
- gboolean merged_image_only,
- gboolean *resolution_loaded,
- gboolean *profile_loaded,
- GError **error);
+GimpImage * load_image (const gchar *filename,
+ gboolean merged_image_only,
+ gboolean *resolution_loaded,
+ gboolean *profile_loaded,
+ GError **error);
#endif /* __PSD_LOAD_H__ */
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index 087273bee4..18aeb5f6f7 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -109,8 +109,8 @@ typedef enum PsdLayerType
typedef struct PsdLayer
{
- gint id;
- PSD_Layer_Type type;
+ GimpLayer *layer;
+ PSD_Layer_Type type;
} PSD_Layer;
typedef struct PsdImageData
@@ -122,14 +122,14 @@ typedef struct PsdImageData
GimpImageBaseType baseType;
- gint32 merged_layer;/* Merged image,
+ GimpLayer *merged_layer;/* Merged image,
to be used for the image data section */
gint nChannels; /* Number of user channels in the image */
- gint32 *lChannels; /* User channels in the image */
+ GList *lChannels; /* List of GimpChannel (User channels in the image) */
gint nLayers; /* Number of layers in the image */
- PSD_Layer *lLayers; /* Layer list */
+ GList *lLayers; /* List of PSD_Layer */
} PSD_Image_Data;
static PSD_Image_Data PSDImageData;
@@ -137,25 +137,25 @@ static PSD_Image_Data PSDImageData;
/* Declare some local functions.
*/
-static const gchar * psd_lmode_layer (gint32 idLayer,
+static const gchar * psd_lmode_layer (GimpLayer *layer,
gboolean section_divider);
static void reshuffle_cmap_write (guchar *mapGimp);
static void save_header (FILE *fd,
- gint32 image_id);
+ GimpImage *image);
static void save_color_mode_data (FILE *fd,
- gint32 image_id);
+ GimpImage *image);
static void save_resources (FILE *fd,
- gint32 image_id);
+ GimpImage *image);
static void save_layer_and_mask (FILE *fd,
- gint32 image_id);
+ GimpImage *image);
static void save_data (FILE *fd,
- gint32 image_id);
+ GimpImage *image);
static void xfwrite (FILE *fd,
gconstpointer buf,
@@ -189,30 +189,30 @@ static void write_datablock_luni (FILE *fd,
static void write_pixel_data (FILE *fd,
- gint32 drawableID,
+ GimpDrawable *drawable,
glong *ChanLenPosition,
gint32 rowlenOffset,
gboolean write_mask);
-static gint32 create_merged_image (gint32 imageID);
+static GimpLayer * create_merged_image (GimpImage *image);
-static const Babl * get_pixel_format (gint32 drawableID);
-static const Babl * get_channel_format (gint32 drawableID);
-static const Babl * get_mask_format (gint32 drawableID);
+static const Babl * get_pixel_format (GimpDrawable *drawable);
+static const Babl * get_channel_format (GimpDrawable *drawable);
+static const Babl * get_mask_format (GimpLayerMask *mask);
-static PSD_Layer * image_get_all_layers (gint32 imageID,
+static GList * image_get_all_layers (GimpImage *image,
gint *n_layers);
static const gchar *
-psd_lmode_layer (gint32 idLayer,
- gboolean section_divider)
+psd_lmode_layer (GimpLayer *layer,
+ gboolean section_divider)
{
LayerModeInfo mode_info;
- mode_info.mode = gimp_layer_get_mode (idLayer);
- mode_info.blend_space = gimp_layer_get_blend_space (idLayer);
- mode_info.composite_space = gimp_layer_get_composite_space (idLayer);
- mode_info.composite_mode = gimp_layer_get_composite_mode (idLayer);
+ mode_info.mode = gimp_layer_get_mode (layer);
+ mode_info.blend_space = gimp_layer_get_blend_space (layer);
+ mode_info.composite_space = gimp_layer_get_composite_space (layer);
+ mode_info.composite_mode = gimp_layer_get_composite_mode (layer);
/* pass-through groups use normal mode in their layer record; the
* pass-through mode is specified in their section divider resource.
@@ -516,8 +516,8 @@ reshuffle_cmap_write (guchar *mapGimp)
}
static void
-save_header (FILE *fd,
- gint32 image_id)
+save_header (FILE *fd,
+ GimpImage *image)
{
IFDBG printf (" Function: save_header\n");
IFDBG printf ("\tRows: %d\n", PSDImageData.image_height);
@@ -531,7 +531,7 @@ save_header (FILE *fd,
write_gint16 (fd, 0, "reserved 1"); /* and 2 bytes for a short */
write_gint16 (fd, (PSDImageData.nChannels +
nChansLayer (PSDImageData.baseType,
- gimp_drawable_has_alpha (PSDImageData.merged_layer), 0)),
+ gimp_drawable_has_alpha (GIMP_DRAWABLE (PSDImageData.merged_layer)), 0)),
"channels");
write_gint32 (fd, PSDImageData.image_height, "rows");
write_gint32 (fd, PSDImageData.image_width, "columns");
@@ -540,8 +540,8 @@ save_header (FILE *fd,
}
static void
-save_color_mode_data (FILE *fd,
- gint32 image_id)
+save_color_mode_data (FILE *fd,
+ GimpImage *image)
{
guchar *cmap;
guchar *cmap_modified;
@@ -555,7 +555,7 @@ save_color_mode_data (FILE *fd,
case GIMP_INDEXED:
IFDBG printf ("\tImage type: INDEXED\n");
- cmap = gimp_image_get_colormap (image_id, &nColors);
+ cmap = gimp_image_get_colormap (image, &nColors);
IFDBG printf ("\t\tLength of colormap returned by gimp_image_get_colormap: %d\n", nColors);
if (nColors == 0)
@@ -597,12 +597,13 @@ save_color_mode_data (FILE *fd,
}
static void
-save_resources (FILE *fd,
- gint32 image_id)
+save_resources (FILE *fd,
+ GimpImage *image)
{
+ GList *iter;
gint i;
gchar *fileName; /* Image file name */
- gint32 idActLayer; /* Id of the active layer */
+ GimpLayer *ActLayer; /* The active layer */
guint nActiveLayer = 0; /* Number of the active layer */
gboolean ActiveLayerPresent; /* TRUE if there's an active layer */
@@ -620,17 +621,17 @@ save_resources (FILE *fd,
/* Get the image title from its filename */
- fileName = gimp_image_get_filename (image_id);
+ fileName = gimp_image_get_filename (image);
IFDBG printf ("\tImage title: %s\n", fileName);
/* Get the active layer number id */
- idActLayer = gimp_image_get_active_layer (image_id);
- IFDBG printf ("\tCurrent layer id: %d\n", idActLayer);
+ ActLayer = gimp_image_get_active_layer (image);
+ IFDBG printf ("\tCurrent layer id: %d\n", gimp_item_get_id (GIMP_ITEM (ActLayer)));
ActiveLayerPresent = FALSE;
- for (i = 0; i < PSDImageData.nLayers; i++)
- if (idActLayer == PSDImageData.lLayers[i].id)
+ for (iter = PSDImageData.lLayers, i = 0; iter; iter = iter->next, i++)
+ if (ActLayer == ((PSD_Layer *) iter->data)->layer)
{
nActiveLayer = PSDImageData.nLayers - i - 1;
ActiveLayerPresent = TRUE;
@@ -656,7 +657,7 @@ save_resources (FILE *fd,
/* --------------- Write Channel names --------------- */
if (PSDImageData.nChannels > 0 ||
- gimp_drawable_has_alpha (PSDImageData.merged_layer))
+ gimp_drawable_has_alpha (GIMP_DRAWABLE (PSDImageData.merged_layer)))
{
xfwrite (fd, "8BIM", 4, "imageresources signature");
write_gint16 (fd, 0x03EE, "0x03EE Id"); /* 1006 */
@@ -671,15 +672,15 @@ save_resources (FILE *fd,
/* Write all strings */
/* if the merged_image contains transparency, write a name for it first */
- if (gimp_drawable_has_alpha (PSDImageData.merged_layer))
+ if (gimp_drawable_has_alpha (GIMP_DRAWABLE (PSDImageData.merged_layer)))
write_string (fd, "Transparency", "channel name");
- for (i = PSDImageData.nChannels - 1; i >= 0; i--)
- {
- char *chName = gimp_item_get_name (PSDImageData.lChannels[i]);
- write_string (fd, chName, "channel name");
- g_free (chName);
- }
+ for (iter = g_list_last (PSDImageData.lChannels); iter; iter = iter->prev)
+ {
+ char *chName = gimp_item_get_name (iter->data);
+ write_string (fd, chName, "channel name");
+ g_free (chName);
+ }
/* Calculate and write actual resource's length */
eof_pos = ftell (fd);
@@ -700,13 +701,13 @@ save_resources (FILE *fd,
}
/* --------------- Write Guides --------------- */
- if (gimp_image_find_next_guide(image_id, 0))
+ if (gimp_image_find_next_guide (image, 0))
{
gint n_guides = 0;
gint guide_id =0;
/* Count the guides */
- while ((guide_id = gimp_image_find_next_guide(image_id, guide_id)))
+ while ((guide_id = gimp_image_find_next_guide(image, guide_id)))
n_guides++;
xfwrite (fd, "8BIM", 4, "imageresources signature");
@@ -721,12 +722,12 @@ save_resources (FILE *fd,
write_gint32 (fd, n_guides, "number of guides");
/* write the guides */
- while ((guide_id = gimp_image_find_next_guide(image_id, guide_id)))
+ while ((guide_id = gimp_image_find_next_guide (image, guide_id)))
{
gchar orientation;
gint32 position;
- orientation = gimp_image_get_guide_orientation(image_id, guide_id);
- position = 32 * gimp_image_get_guide_position(image_id, guide_id);
+ orientation = gimp_image_get_guide_orientation (image, guide_id);
+ position = 32 * gimp_image_get_guide_position (image, guide_id);
orientation ^= 1; /* in the psd vert =0 , horiz = 1 */
write_gint32 (fd, position, "Position of guide");
write_gchar (fd, orientation, "Orientation of guide");
@@ -746,8 +747,8 @@ save_resources (FILE *fd,
GimpUnit g_unit;
gint16 psd_unit;
- g_unit = gimp_image_get_unit (image_id);
- gimp_image_get_resolution (image_id, &xres, &yres);
+ g_unit = gimp_image_get_unit (image);
+ gimp_image_get_resolution (image, &xres, &yres);
if (g_unit == GIMP_UNIT_MM)
{
@@ -799,7 +800,7 @@ save_resources (FILE *fd,
{
GimpColorProfile *profile;
- profile = gimp_image_get_effective_color_profile (image_id);
+ profile = gimp_image_get_effective_color_profile (image);
if (profile)
{
@@ -862,29 +863,30 @@ get_compress_channel_data (guchar *channel_data,
}
static void
-save_layer_and_mask (FILE *fd,
- gint32 image_id)
+save_layer_and_mask (FILE *fd,
+ GimpImage *image)
{
- gint i,j;
- gint idChannel;
- gint offset_x; /* X offset for each layer */
- gint offset_y; /* Y offset for each layer */
- gint32 layerWidth; /* Width of each layer */
- gint32 layerHeight; /* Height of each layer */
- const gchar *blendMode; /* Blending mode of the layer */
- guchar layerOpacity; /* Opacity of the layer */
- guchar flags; /* Layer flags */
- gint nChannelsLayer; /* Number of channels of a layer */
- gint32 ChanSize; /* Data length for a channel */
- gchar *layerName; /* Layer name */
- gint mask; /* Layer mask */
- gint depth; /* Layer group nesting depth */
-
- glong eof_pos; /* Position: End of file */
- glong ExtraDataPos; /* Position: Extra data length */
- glong LayerMaskPos; /* Position: Layer & Mask section length */
- glong LayerInfoPos; /* Position: Layer info section length*/
- glong **ChannelLengthPos; /* Position: Channel length */
+ gint i,j;
+ gint idChannel;
+ gint offset_x; /* X offset for each layer */
+ gint offset_y; /* Y offset for each layer */
+ gint32 layerWidth; /* Width of each layer */
+ gint32 layerHeight; /* Height of each layer */
+ const gchar *blendMode; /* Blending mode of the layer */
+ guchar layerOpacity; /* Opacity of the layer */
+ guchar flags; /* Layer flags */
+ gint nChannelsLayer; /* Number of channels of a layer */
+ gint32 ChanSize; /* Data length for a channel */
+ gchar *layerName; /* Layer name */
+ GimpLayerMask *mask; /* Layer mask */
+ gint depth; /* Layer group nesting depth */
+
+ glong eof_pos; /* Position: End of file */
+ glong ExtraDataPos; /* Position: Extra data length */
+ glong LayerMaskPos; /* Position: Layer & Mask section length */
+ glong LayerInfoPos; /* Position: Layer info section length*/
+ glong **ChannelLengthPos; /* Position: Channel length */
+ GList *iter;
IFDBG printf (" Function: save_layer_and_mask\n");
@@ -905,7 +907,7 @@ save_layer_and_mask (FILE *fd,
/* Layer structure section */
- if (gimp_drawable_has_alpha (PSDImageData.merged_layer))
+ if (gimp_drawable_has_alpha (GIMP_DRAWABLE (PSDImageData.merged_layer)))
write_gint16 (fd, -PSDImageData.nLayers, "Layer structure count");
else
write_gint16 (fd, PSDImageData.nLayers, "Layer structure count");
@@ -915,15 +917,16 @@ save_layer_and_mask (FILE *fd,
/* Layer records section */
/* GIMP layers must be written in reverse order */
- for (i = PSDImageData.nLayers - 1; i >= 0; i--)
+ for (iter = g_list_last (PSDImageData.lLayers), i = PSDImageData.nLayers; iter; iter = iter->prev, i--)
{
- gint hasMask = 0;
+ PSD_Layer *psd_layer = (PSD_Layer *) iter->data;
+ gint hasMask = 0;
- if (PSDImageData.lLayers[i].type == PSD_LAYER_TYPE_LAYER)
+ if (psd_layer->type == PSD_LAYER_TYPE_LAYER)
{
- gimp_drawable_offsets (PSDImageData.lLayers[i].id, &offset_x, &offset_y);
- layerWidth = gimp_drawable_width (PSDImageData.lLayers[i].id);
- layerHeight = gimp_drawable_height (PSDImageData.lLayers[i].id);
+ gimp_drawable_offsets (GIMP_DRAWABLE (psd_layer->layer), &offset_x, &offset_y);
+ layerWidth = gimp_drawable_width (GIMP_DRAWABLE (psd_layer->layer));
+ layerHeight = gimp_drawable_height (GIMP_DRAWABLE (psd_layer->layer));
}
else
{
@@ -941,7 +944,7 @@ save_layer_and_mask (FILE *fd,
{
const gchar *type;
- switch (PSDImageData.lLayers[i].type)
+ switch (psd_layer->type)
{
case PSD_LAYER_TYPE_LAYER: type = "normal layer"; break;
case PSD_LAYER_TYPE_GROUP_START: type = "group start marker"; break;
@@ -960,10 +963,10 @@ save_layer_and_mask (FILE *fd,
write_gint32 (fd, offset_y + layerHeight, "Layer bottom");
write_gint32 (fd, offset_x + layerWidth, "Layer right");
- hasMask = (PSDImageData.lLayers[i].type != PSD_LAYER_TYPE_GROUP_END &&
- gimp_layer_get_mask (PSDImageData.lLayers[i].id) != -1);
+ hasMask = (psd_layer->type != PSD_LAYER_TYPE_GROUP_END &&
+ gimp_layer_get_mask (psd_layer->layer) != NULL);
nChannelsLayer = nChansLayer (PSDImageData.baseType,
- gimp_drawable_has_alpha (PSDImageData.lLayers[i].id),
+ gimp_drawable_has_alpha (GIMP_DRAWABLE (psd_layer->layer)),
hasMask);
@@ -978,7 +981,7 @@ save_layer_and_mask (FILE *fd,
for (j = 0; j < nChannelsLayer; j++)
{
- if (gimp_drawable_has_alpha (PSDImageData.lLayers[i].id))
+ if (gimp_drawable_has_alpha (GIMP_DRAWABLE (psd_layer->layer)))
idChannel = j - 1;
else
idChannel = j;
@@ -1000,11 +1003,11 @@ save_layer_and_mask (FILE *fd,
xfwrite (fd, "8BIM", 4, "blend mode signature");
- blendMode = psd_lmode_layer (PSDImageData.lLayers[i].id, FALSE);
+ blendMode = psd_lmode_layer (psd_layer->layer, FALSE);
IFDBG printf ("\t\tBlend mode: %s\n", blendMode);
xfwrite (fd, blendMode, 4, "blend mode key");
- layerOpacity = RINT ((gimp_layer_get_opacity (PSDImageData.lLayers[i].id) * 255.0) / 100.0);
+ layerOpacity = RINT ((gimp_layer_get_opacity (psd_layer->layer) * 255.0) / 100.0);
IFDBG printf ("\t\tOpacity: %u\n", layerOpacity);
write_gchar (fd, layerOpacity, "Opacity");
@@ -1012,9 +1015,9 @@ save_layer_and_mask (FILE *fd,
write_gchar (fd, 0, "Clipping");
flags = 0;
- if (gimp_layer_get_lock_alpha (PSDImageData.lLayers[i].id)) flags |= 1;
- if (! gimp_item_get_visible (PSDImageData.lLayers[i].id)) flags |= 2;
- if (PSDImageData.lLayers[i].type != PSD_LAYER_TYPE_LAYER) flags |= 0x18;
+ if (gimp_layer_get_lock_alpha (psd_layer->layer)) flags |= 1;
+ if (! gimp_item_get_visible (GIMP_ITEM (psd_layer->layer))) flags |= 2;
+ if (psd_layer->type != PSD_LAYER_TYPE_LAYER) flags |= 0x18;
IFDBG printf ("\t\tFlags: %u\n", flags);
write_gchar (fd, flags, "Flags");
@@ -1032,13 +1035,13 @@ save_layer_and_mask (FILE *fd,
gint maskHeight;
gboolean apply;
- mask = gimp_layer_get_mask (PSDImageData.lLayers[i].id);
+ mask = gimp_layer_get_mask (psd_layer->layer);
- gimp_drawable_offsets (mask, &maskOffset_x, &maskOffset_y);
+ gimp_drawable_offsets (GIMP_DRAWABLE (mask), &maskOffset_x, &maskOffset_y);
- maskWidth = gimp_drawable_width (mask);
- maskHeight = gimp_drawable_height (mask);
- apply = gimp_layer_get_apply_mask (PSDImageData.lLayers[i].id);
+ maskWidth = gimp_drawable_width (GIMP_DRAWABLE (mask));
+ maskHeight = gimp_drawable_height (GIMP_DRAWABLE (mask));
+ apply = gimp_layer_get_apply_mask (psd_layer->layer);
IFDBG printf ("\t\tLayer mask size: %d\n", 20);
write_gint32 (fd, 20, "Layer mask size");
@@ -1064,8 +1067,8 @@ save_layer_and_mask (FILE *fd,
write_gint32 (fd, 0, "Layer blending size");
IFDBG printf ("\t\tLayer blending size: %d\n", 0);
- if (PSDImageData.lLayers[i].type != PSD_LAYER_TYPE_GROUP_END)
- layerName = gimp_item_get_name (PSDImageData.lLayers[i].id);
+ if (psd_layer->type != PSD_LAYER_TYPE_GROUP_END)
+ layerName = gimp_item_get_name (GIMP_ITEM (psd_layer->layer));
else
layerName = g_strdup ("</Layer group>");
write_pascalstring (fd, layerName, 4, "layer name");
@@ -1073,7 +1076,7 @@ save_layer_and_mask (FILE *fd,
/* Additional layer information blocks */
/* Unicode layer name */
- write_datablock_luni(fd, layerName, "luni extra data block");
+ write_datablock_luni (fd, layerName, "luni extra data block");
g_free (layerName);
@@ -1081,23 +1084,23 @@ save_layer_and_mask (FILE *fd,
xfwrite (fd, "8BIMlclr", 8, "sheet color signature");
write_gint32 (fd, 8, "sheet color size");
write_gint16 (fd,
- gimp_to_psd_layer_color_tag(gimp_item_get_color_tag(PSDImageData.lLayers[i].id)),
+ gimp_to_psd_layer_color_tag (gimp_item_get_color_tag (GIMP_ITEM (psd_layer->layer))),
"sheet color code");
write_gint16 (fd, 0, "sheet color unused value");
write_gint16 (fd, 0, "sheet color unused value");
write_gint16 (fd, 0, "sheet color unused value");
/* Group layer section divider */
- if (PSDImageData.lLayers[i].type != PSD_LAYER_TYPE_LAYER)
+ if (psd_layer->type != PSD_LAYER_TYPE_LAYER)
{
gint32 size;
gint32 type;
size = 12;
- if (PSDImageData.lLayers[i].type == PSD_LAYER_TYPE_GROUP_START)
+ if (psd_layer->type == PSD_LAYER_TYPE_GROUP_START)
{
- type = gimp_item_get_expanded (PSDImageData.lLayers[i].id) ? 1 : 2;
+ type = gimp_item_get_expanded (GIMP_ITEM (psd_layer->layer)) ? 1 : 2;
depth--;
}
@@ -1108,7 +1111,7 @@ save_layer_and_mask (FILE *fd,
depth++;
}
- blendMode = psd_lmode_layer (PSDImageData.lLayers[i].id, TRUE);
+ blendMode = psd_lmode_layer (psd_layer->layer, TRUE);
if (type < 3 || depth <= 5)
{
@@ -1146,13 +1149,15 @@ save_layer_and_mask (FILE *fd,
/* Channel image data section */
/* Gimp layers must be written in reverse order */
- for (i = PSDImageData.nLayers - 1; i >= 0; i--)
+ for (iter = g_list_last (PSDImageData.lLayers), i = PSDImageData.nLayers; iter; iter = iter->prev, i--)
{
+ PSD_Layer *psd_layer = (PSD_Layer *) iter->data;
+
gimp_progress_update ((PSDImageData.nLayers - i - 1.0) / (PSDImageData.nLayers + 1.0));
IFDBG printf ("\t\tWriting pixel data for layer slot %d\n", i);
- write_pixel_data (fd, PSDImageData.lLayers[i].id, ChannelLengthPos[i], 0,
- PSDImageData.lLayers[i].type != PSD_LAYER_TYPE_GROUP_END);
+ write_pixel_data (fd, GIMP_DRAWABLE (psd_layer->layer), ChannelLengthPos[i], 0,
+ psd_layer->type != PSD_LAYER_TYPE_GROUP_END);
g_free (ChannelLengthPos[i]);
}
@@ -1179,54 +1184,54 @@ save_layer_and_mask (FILE *fd,
}
static void
-write_pixel_data (FILE *fd,
- gint32 drawableID,
- glong *ChanLenPosition,
- gint32 ltable_offset,
- gboolean write_mask)
+write_pixel_data (FILE *fd,
+ GimpDrawable *drawable,
+ glong *ChanLenPosition,
+ gint32 ltable_offset,
+ gboolean write_mask)
{
- GeglBuffer *buffer = gimp_drawable_get_buffer (drawableID);
- const Babl *format;
- gint32 maskID;
- gint32 tile_height = gimp_tile_height ();
- gint32 height = gegl_buffer_get_height (buffer);
- gint32 width = gegl_buffer_get_width (buffer);
- gint32 bytes;
- gint32 colors;
- gint32 y;
- gint32 len; /* Length of compressed data */
- gint16 *LengthsTable; /* Lengths of every compressed row */
- guchar *rledata; /* Compressed data from a region */
- guchar *data; /* Temporary copy of pixel data */
- glong length_table_pos; /* position in file of the length table */
- int i, j;
+ GeglBuffer *buffer = gimp_drawable_get_buffer (drawable);
+ const Babl *format;
+ GimpLayerMask *mask;
+ gint32 tile_height = gimp_tile_height ();
+ gint32 height = gegl_buffer_get_height (buffer);
+ gint32 width = gegl_buffer_get_width (buffer);
+ gint32 bytes;
+ gint32 colors;
+ gint32 y;
+ gint32 len; /* Length of compressed data */
+ gint16 *LengthsTable; /* Lengths of every compressed row */
+ guchar *rledata; /* Compressed data from a region */
+ guchar *data; /* Temporary copy of pixel data */
+ glong length_table_pos; /* position in file of the length table */
+ int i, j;
IFDBG printf (" Function: write_pixel_data, drw %d, lto %d\n",
- drawableID, ltable_offset);
+ gimp_item_get_id (GIMP_ITEM (drawable)), ltable_offset);
if (write_mask)
- maskID = gimp_layer_get_mask (drawableID);
+ mask = gimp_layer_get_mask (GIMP_LAYER (drawable));
else
- maskID = -1;
+ mask = NULL;
/* groups have empty channel data, but may have a mask */
- if (gimp_item_is_group (drawableID) && maskID == -1)
+ if (gimp_item_is_group (GIMP_ITEM (drawable)) && mask == NULL)
{
width = 0;
height = 0;
}
- if (gimp_item_is_channel (drawableID))
- format = get_channel_format (drawableID);
+ if (gimp_item_is_channel (GIMP_ITEM (drawable)))
+ format = get_channel_format (drawable);
else
- format = get_pixel_format (drawableID);
+ format = get_pixel_format (drawable);
bytes = babl_format_get_bytes_per_pixel (format);
colors = bytes;
- if (gimp_drawable_has_alpha (drawableID) &&
- ! gimp_drawable_is_indexed (drawableID))
+ if (gimp_drawable_has_alpha (drawable) &&
+ ! gimp_drawable_is_indexed (drawable))
colors -= 1;
LengthsTable = g_new (gint16, height);
@@ -1236,7 +1241,7 @@ write_pixel_data (FILE *fd,
data = g_new (guchar, MIN (height, tile_height) * width * bytes);
/* groups have empty channel data */
- if (gimp_item_is_group (drawableID))
+ if (gimp_item_is_group (GIMP_ITEM (drawable)))
{
width = 0;
height = 0;
@@ -1320,10 +1325,10 @@ write_pixel_data (FILE *fd,
}
/* Write layer mask, as last channel, id -2 */
- if (maskID != -1)
+ if (mask != NULL)
{
- GeglBuffer *mbuffer = gimp_drawable_get_buffer (maskID);
- const Babl *mformat = get_mask_format(maskID);
+ GeglBuffer *mbuffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask));
+ const Babl *mformat = get_mask_format (mask);
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
@@ -1403,23 +1408,24 @@ write_pixel_data (FILE *fd,
}
static void
-save_data (FILE *fd,
- gint32 image_id)
+save_data (FILE *fd,
+ GimpImage *image)
{
- gint ChanCount;
- gint i, j;
- gint32 imageHeight; /* Height of image */
- glong offset; /* offset in file of rle lengths */
- gint chan;
+ GList *iter;
+ gint ChanCount;
+ gint i, j;
+ gint32 imageHeight; /* Height of image */
+ glong offset; /* offset in file of rle lengths */
+ gint chan;
IFDBG printf (" Function: save_data\n");
ChanCount = (PSDImageData.nChannels +
nChansLayer (PSDImageData.baseType,
- gimp_drawable_has_alpha (PSDImageData.merged_layer),
+ gimp_drawable_has_alpha (GIMP_DRAWABLE (PSDImageData.merged_layer)),
0));
- imageHeight = gimp_image_height (image_id);
+ imageHeight = gimp_image_height (image);
write_gint16 (fd, 1, "RLE compression");
@@ -1432,36 +1438,36 @@ save_data (FILE *fd,
write_gint16 (fd, 0, "junk line lengths");
IFDBG printf ("\t\tWriting compressed image data\n");
- write_pixel_data (fd, PSDImageData.merged_layer,
+ write_pixel_data (fd, GIMP_DRAWABLE (PSDImageData.merged_layer),
NULL, offset, FALSE);
chan = nChansLayer (PSDImageData.baseType,
- gimp_drawable_has_alpha(PSDImageData.merged_layer), 0);
+ gimp_drawable_has_alpha (GIMP_DRAWABLE (PSDImageData.merged_layer)), 0);
- for (i = PSDImageData.nChannels - 1; i >= 0; i--)
+ for (iter = g_list_last (PSDImageData.lChannels), i = PSDImageData.nChannels - 1; iter; iter = iter->prev,
i--)
{
IFDBG printf ("\t\tWriting compressed channel data for channel %d\n",
i);
- write_pixel_data (fd, PSDImageData.lChannels[i], NULL,
+ write_pixel_data (fd, iter->data, NULL,
offset + 2*imageHeight*chan, FALSE); //check how imgs are channels here
chan++;
}
}
-static gint32
-create_merged_image (gint32 image_id)
+static GimpLayer *
+create_merged_image (GimpImage *image)
{
- gint32 projection;
+ GimpLayer *projection;
- projection = gimp_layer_new_from_visible (image_id, image_id, "psd-save");
+ projection = gimp_layer_new_from_visible (image, image, "psd-save");
- if (! gimp_drawable_has_alpha (projection))
+ if (! gimp_drawable_has_alpha (GIMP_DRAWABLE (projection)))
return projection;
- if (gimp_image_base_type (image_id) != GIMP_INDEXED)
+ if (gimp_image_base_type (image) != GIMP_INDEXED)
{
- GeglBuffer *buffer = gimp_drawable_get_buffer (projection);
- const Babl *format = get_pixel_format (projection);
+ GeglBuffer *buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (projection));
+ const Babl *format = get_pixel_format (GIMP_DRAWABLE (projection));
gboolean transparency_found = FALSE;
gint bpp = babl_format_get_bytes_per_pixel (format);
GeglBufferIterator *iter;
@@ -1507,28 +1513,28 @@ create_merged_image (gint32 image_id)
}
static void
-get_image_data (gint32 image_id)
+get_image_data (GimpImage *image)
{
IFDBG printf (" Function: get_image_data\n");
PSDImageData.compression = FALSE;
- PSDImageData.image_height = gimp_image_height (image_id);
+ PSDImageData.image_height = gimp_image_height (image);
IFDBG printf ("\tGot number of rows: %d\n", PSDImageData.image_height);
- PSDImageData.image_width = gimp_image_width (image_id);
+ PSDImageData.image_width = gimp_image_width (image);
IFDBG printf ("\tGot number of cols: %d\n", PSDImageData.image_width);
- PSDImageData.baseType = gimp_image_base_type (image_id);
+ PSDImageData.baseType = gimp_image_base_type (image);
IFDBG printf ("\tGot base type: %d\n", PSDImageData.baseType);
- PSDImageData.merged_layer = create_merged_image (image_id);
+ PSDImageData.merged_layer = create_merged_image (image);
- PSDImageData.lChannels = gimp_image_get_channels (image_id,
- &PSDImageData.nChannels);
+ PSDImageData.lChannels = gimp_image_get_channels (image);
+ PSDImageData.nChannels = g_list_length (PSDImageData.lChannels);
IFDBG printf ("\tGot number of channels: %d\n", PSDImageData.nChannels);
- PSDImageData.lLayers = image_get_all_layers (image_id,
+ PSDImageData.lLayers = image_get_all_layers (image,
&PSDImageData.nLayers);
IFDBG printf ("\tGot number of layers: %d\n", PSDImageData.nLayers);
}
@@ -1538,26 +1544,26 @@ clear_image_data (void)
{
IFDBG printf (" Function: clear_image_data\n");
- g_free (PSDImageData.lChannels);
+ g_list_free (PSDImageData.lChannels);
PSDImageData.lChannels = NULL;
- g_free (PSDImageData.lLayers);
+ g_list_free (PSDImageData.lLayers);
PSDImageData.lLayers = NULL;
}
gboolean
save_image (const gchar *filename,
- gint32 image_id,
+ GimpImage *image,
GError **error)
{
FILE *fd;
- gint i;
GeglBuffer *buffer;
+ GList *iter;
IFDBG printf (" Function: save_image\n");
- if (gimp_image_width (image_id) > 30000 ||
- gimp_image_height (image_id) > 30000)
+ if (gimp_image_width (image) > 30000 ||
+ gimp_image_height (image) > 30000)
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unable to export '%s'. The PSD file format does not "
@@ -1570,14 +1576,16 @@ save_image (const gchar *filename,
gimp_progress_init_printf (_("Exporting '%s'"),
gimp_filename_to_utf8 (filename));
- get_image_data (image_id);
+ get_image_data (image);
/* Need to check each of the layers size individually also */
- for (i = 0; i < PSDImageData.nLayers; i++)
+ for (iter = PSDImageData.lLayers; iter; iter = iter->next)
{
- if (PSDImageData.lLayers[i].type == PSD_LAYER_TYPE_LAYER)
+ PSD_Layer *layer = iter->data;
+
+ if (layer->type == PSD_LAYER_TYPE_LAYER)
{
- buffer = gimp_drawable_get_buffer (PSDImageData.lLayers[i].id);
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer->layer));
if (gegl_buffer_get_width (buffer) > 30000 || gegl_buffer_get_height (buffer) > 30000)
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
@@ -1605,24 +1613,24 @@ save_image (const gchar *filename,
IFDBG g_print ("\tFile '%s' has been opened\n",
gimp_filename_to_utf8 (filename));
- save_header (fd, image_id);
- save_color_mode_data (fd, image_id);
- save_resources (fd, image_id);
+ save_header (fd, image);
+ save_color_mode_data (fd, image);
+ save_resources (fd, image);
/* PSD format does not support layers in indexed images */
if (PSDImageData.baseType == GIMP_INDEXED)
write_gint32 (fd, 0, "layers info section length");
else
- save_layer_and_mask (fd, image_id);
+ save_layer_and_mask (fd, image);
/* If this is an indexed image, write now channel and layer info */
- save_data (fd, image_id);
+ save_data (fd, image);
/* Delete merged image now */
- gimp_item_delete (PSDImageData.merged_layer);
+ gimp_item_delete (GIMP_ITEM (PSDImageData.merged_layer));
clear_image_data ();
@@ -1636,11 +1644,11 @@ save_image (const gchar *filename,
}
static const Babl *
-get_pixel_format (gint32 drawableID)
+get_pixel_format (GimpDrawable *drawable)
{
const Babl *format;
- switch (gimp_drawable_type (drawableID))
+ switch (gimp_drawable_type (drawable))
{
case GIMP_GRAY_IMAGE:
format = babl_format ("Y' u8");
@@ -1660,7 +1668,7 @@ get_pixel_format (gint32 drawableID)
case GIMP_INDEXED_IMAGE:
case GIMP_INDEXEDA_IMAGE:
- format = gimp_drawable_get_format(drawableID);
+ format = gimp_drawable_get_format(drawable);
break;
default:
@@ -1672,7 +1680,7 @@ get_pixel_format (gint32 drawableID)
}
static const Babl *
-get_channel_format (gint32 drawableID)
+get_channel_format (GimpDrawable *drawable)
{
const Babl *format;
@@ -1684,7 +1692,7 @@ get_channel_format (gint32 drawableID)
}
static const Babl *
-get_mask_format (gint32 drawableID)
+get_mask_format (GimpLayerMask *mask)
{
const Babl *format;
@@ -1695,59 +1703,59 @@ get_mask_format (gint32 drawableID)
return format;
}
-static void
-append_layers (const gint *layers,
- gint n_layers,
- GArray *array)
+static GList *
+append_layers (GList *layers)
{
- gint i;
+ GList *psd_layers = NULL;
+ GList *iter;
- for (i = 0; i < n_layers; i++)
+ for (iter = layers; iter; iter = iter->next)
{
- PSD_Layer layer = {};
- gboolean is_group;
+ PSD_Layer *layer = g_new0 (PSD_Layer, 1);
+ gboolean is_group;
- layer.id = layers[i];
+ layer->layer = iter->data;
- is_group = gimp_item_is_group (layer.id);
+ is_group = gimp_item_is_group (iter->data);
if (! is_group)
- layer.type = PSD_LAYER_TYPE_LAYER;
+ layer->type = PSD_LAYER_TYPE_LAYER;
else
- layer.type = PSD_LAYER_TYPE_GROUP_START;
+ layer->type = PSD_LAYER_TYPE_GROUP_START;
- g_array_append_val (array, layer);
+ psd_layers = g_list_append (psd_layers, layer);
if (is_group)
{
- gint32 *group_layers;
- gint n;
+ PSD_Layer *end_layer = g_new0 (PSD_Layer, 1);
+ GList *group_layers;
- group_layers = gimp_item_get_children (layer.id, &n);
- append_layers (group_layers, n, array);
- g_free (group_layers);
+ group_layers = gimp_item_get_children (iter->data);
+ psd_layers = g_list_concat (psd_layers,
+ append_layers (group_layers));
+ g_list_free (group_layers);
- layer.type = PSD_LAYER_TYPE_GROUP_END;
- g_array_append_val (array, layer);
+ end_layer->layer = iter->data;
+ end_layer->type = PSD_LAYER_TYPE_GROUP_END;
+ psd_layers = g_list_append (psd_layers, end_layer);
}
}
+
+ return psd_layers;
}
-static PSD_Layer *
-image_get_all_layers (gint32 image_id,
- gint *n_layers)
+static GList *
+image_get_all_layers (GimpImage *image,
+ gint *n_layers)
{
- GArray *array = g_array_new (FALSE, FALSE, sizeof (PSD_Layer));
- gint32 *layers;
- gint n;
-
- layers = gimp_image_get_layers (image_id, &n);
-
- append_layers (layers, n, array);
+ GList *psd_layers = NULL;
+ GList *layers;
- g_free (layers);
+ layers = gimp_image_get_layers (image);
+ psd_layers = append_layers (layers);
+ g_list_free (layers);
- *n_layers = array->len;
+ *n_layers = g_list_length (psd_layers);
- return (PSD_Layer *) g_array_free (array, FALSE);
+ return psd_layers;
}
diff --git a/plug-ins/file-psd/psd-save.h b/plug-ins/file-psd/psd-save.h
index 9308271dd8..45931b2466 100644
--- a/plug-ins/file-psd/psd-save.h
+++ b/plug-ins/file-psd/psd-save.h
@@ -20,7 +20,7 @@
gboolean save_image (const gchar *filename,
- gint32 image_id,
+ GimpImage *image,
GError **error);
diff --git a/plug-ins/file-psd/psd-thumb-load.c b/plug-ins/file-psd/psd-thumb-load.c
index a4c7c7d5fc..73a69cdd67 100644
--- a/plug-ins/file-psd/psd-thumb-load.c
+++ b/plug-ins/file-psd/psd-thumb-load.c
@@ -46,16 +46,16 @@ static gint read_image_resource_block (PSDimage *img_a,
FILE *f,
GError **error);
-static gint32 create_gimp_image (PSDimage *img_a,
+static GimpImage * create_gimp_image (PSDimage *img_a,
const gchar *filename);
-static gint add_image_resources (gint32 image_id,
+static gint add_image_resources (GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error);
/* Main file load function */
-gint32
+GimpImage *
load_thumbnail_image (const gchar *filename,
gint *width,
gint *height,
@@ -64,12 +64,12 @@ load_thumbnail_image (const gchar *filename,
FILE *f;
struct stat st;
PSDimage img_a;
- gint32 image_id = -1;
- GError *error = NULL;
+ GimpImage *image = NULL;
+ GError *error = NULL;
/* ----- Open PSD file ----- */
if (g_stat (filename, &st) == -1)
- return -1;
+ return NULL;
gimp_progress_init_printf (_("Opening thumbnail for '%s'"),
gimp_filename_to_utf8 (filename));
@@ -81,7 +81,7 @@ load_thumbnail_image (const gchar *filename,
g_set_error (load_error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
- return -1;
+ return NULL;
}
/* ----- Read the PSD file Header block ----- */
@@ -104,23 +104,23 @@ load_thumbnail_image (const gchar *filename,
/* ----- Create GIMP image ----- */
IFDBG(2) g_debug ("Create GIMP image");
- image_id = create_gimp_image (&img_a, filename);
- if (image_id < 0)
+ image = create_gimp_image (&img_a, filename);
+ if (! image)
goto load_error;
/* ----- Add image resources ----- */
IFDBG(2) g_debug ("Add image resources");
- if (add_image_resources (image_id, &img_a, f, &error) < 1)
+ if (add_image_resources (image, &img_a, f, &error) < 1)
goto load_error;
gimp_progress_update (1.0);
- gimp_image_clean_all (image_id);
- gimp_image_undo_enable (image_id);
+ gimp_image_clean_all (image);
+ gimp_image_undo_enable (image);
fclose (f);
*width = img_a.columns;
*height = img_a.rows;
- return image_id;
+ return image;
/* ----- Process load errors ----- */
load_error:
@@ -132,14 +132,14 @@ load_thumbnail_image (const gchar *filename,
}
/* Delete partially loaded image */
- if (image_id > 0)
- gimp_image_delete (image_id);
+ if (image)
+ gimp_image_delete (image);
/* Close file if Open */
if (! (f == NULL))
fclose (f);
- return -1;
+ return NULL;
}
@@ -254,26 +254,26 @@ read_image_resource_block (PSDimage *img_a,
return 0;
}
-static gint32
+static GimpImage *
create_gimp_image (PSDimage *img_a,
const gchar *filename)
{
- gint32 image_id = -1;
+ GimpImage *image = NULL;
img_a->base_type = GIMP_RGB;
/* Create gimp image */
IFDBG(2) g_debug ("Create image");
- image_id = gimp_image_new (img_a->columns, img_a->rows, img_a->base_type);
+ image = gimp_image_new (img_a->columns, img_a->rows, img_a->base_type);
- gimp_image_set_filename (image_id, filename);
- gimp_image_undo_disable (image_id);
+ gimp_image_set_filename (image, filename);
+ gimp_image_undo_disable (image);
- return image_id;
+ return image;
}
static gint
-add_image_resources (gint32 image_id,
+add_image_resources (GimpImage *image,
PSDimage *img_a,
FILE *f,
GError **error)
@@ -296,7 +296,7 @@ add_image_resources (gint32 image_id,
img_a->image_res_start + img_a->image_res_len)
return 0;
- status = load_thumbnail_resource (&res_a, image_id, f, error);
+ status = load_thumbnail_resource (&res_a, image, f, error);
/* Error */
if (status < 0)
return -1;
diff --git a/plug-ins/file-psd/psd-thumb-load.h b/plug-ins/file-psd/psd-thumb-load.h
index a5e1281e4f..71935a897d 100644
--- a/plug-ins/file-psd/psd-thumb-load.h
+++ b/plug-ins/file-psd/psd-thumb-load.h
@@ -22,10 +22,10 @@
#define __PSD_THUMB_LOAD_H__
-gint32 load_thumbnail_image (const gchar *filename,
- gint *width,
- gint *height,
- GError **error);
+GimpImage * load_thumbnail_image (const gchar *filename,
+ gint *width,
+ gint *height,
+ GError **error);
#endif /* __PSD_THUMB_LOAD_H__ */
diff --git a/plug-ins/file-psd/psd.c b/plug-ins/file-psd/psd.c
index 1f02a71e22..1448025369 100644
--- a/plug-ins/file-psd/psd.c
+++ b/plug-ins/file-psd/psd.c
@@ -68,8 +68,8 @@ static GimpValueArray * psd_load_thumb (GimpProcedure *procedure,
gpointer run_data);
static GimpValueArray * psd_save (GimpProcedure *procedure,
GimpRunMode run_mode,
- gint32 image_id,
- gint32 drawable_id,
+ GimpImage *image,
+ GimpDrawable *drawable,
GFile *file,
const GimpValueArray *args,
gpointer run_data);
@@ -232,7 +232,7 @@ psd_load (GimpProcedure *procedure,
gboolean resolution_loaded = FALSE;
gboolean profile_loaded = FALSE;
gboolean interactive;
- gint32 image_id;
+ GimpImage *image;
GimpMetadata *metadata;
GError *error = NULL;
@@ -251,19 +251,19 @@ psd_load (GimpProcedure *procedure,
break;
}
- image_id = load_image (g_file_get_path (file),
- strcmp (gimp_procedure_get_name (procedure),
- LOAD_MERGED_PROC) == 0,
- &resolution_loaded,
- &profile_loaded,
- &error);
+ image = load_image (g_file_get_path (file),
+ strcmp (gimp_procedure_get_name (procedure),
+ LOAD_MERGED_PROC) == 0,
+ &resolution_loaded,
+ &profile_loaded,
+ &error);
- if (image_id < 1)
+ if (! image)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
- metadata = gimp_image_metadata_load_prepare (image_id, "image/x-psd",
+ metadata = gimp_image_metadata_load_prepare (image, "image/x-psd",
file, NULL);
if (metadata)
{
@@ -275,7 +275,7 @@ psd_load (GimpProcedure *procedure,
if (profile_loaded)
flags &= ~GIMP_METADATA_LOAD_COLORSPACE;
- gimp_image_metadata_load_finish (image_id, "image/x-psd",
+ gimp_image_metadata_load_finish (image, "image/x-psd",
metadata, flags,
interactive);
@@ -286,7 +286,7 @@ psd_load (GimpProcedure *procedure,
GIMP_PDB_SUCCESS,
NULL);
- GIMP_VALUES_SET_IMAGE (return_vals, 1, image_id);
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
return return_vals;
}
@@ -302,7 +302,7 @@ psd_load_thumb (GimpProcedure *procedure,
gchar *filename;
gint width = 0;
gint height = 0;
- gint32 image_id;
+ GimpImage *image;
GError *error = NULL;
INIT_I18N ();
@@ -310,9 +310,9 @@ psd_load_thumb (GimpProcedure *procedure,
filename = g_file_get_path (file);
- image_id = load_thumbnail_image (filename, &width, &height, &error);
+ image = load_thumbnail_image (filename, &width, &height, &error);
- if (image_id < 1)
+ if (! image)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
@@ -321,7 +321,7 @@ psd_load_thumb (GimpProcedure *procedure,
GIMP_PDB_SUCCESS,
NULL);
- GIMP_VALUES_SET_IMAGE (return_vals, 1, image_id);
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
GIMP_VALUES_SET_INT (return_vals, 2, width);
GIMP_VALUES_SET_INT (return_vals, 3, height);
@@ -333,8 +333,8 @@ psd_load_thumb (GimpProcedure *procedure,
static GimpValueArray *
psd_save (GimpProcedure *procedure,
GimpRunMode run_mode,
- gint32 image_id,
- gint32 drawable_id,
+ GimpImage *image,
+ GimpDrawable *drawable,
GFile *file,
const GimpValueArray *args,
gpointer run_data)
@@ -354,7 +354,7 @@ psd_save (GimpProcedure *procedure,
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, &drawable, "PSD",
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_INDEXED |
@@ -371,17 +371,17 @@ psd_save (GimpProcedure *procedure,
break;
}
- metadata = gimp_image_metadata_save_prepare (image_id,
+ metadata = gimp_image_metadata_save_prepare (image,
"image/x-psd",
&metadata_flags);
- if (save_image (g_file_get_path (file), image_id, &error))
+ if (save_image (g_file_get_path (file), image, &error))
{
if (metadata)
{
gimp_metadata_set_bits_per_sample (metadata, 8);
- gimp_image_metadata_save_finish (image_id,
+ gimp_image_metadata_save_finish (image,
"image/x-psd",
metadata, metadata_flags,
file, NULL);
@@ -393,7 +393,7 @@ psd_save (GimpProcedure *procedure,
}
if (export == GIMP_EXPORT_EXPORT)
- gimp_image_delete (image_id);
+ gimp_image_delete (image);
if (metadata)
g_object_unref (metadata);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]