5
5
* Copyright 2007 by John Marshall
7
* This program is free software; you can redistribute it and/or modify
7
* This program is free software: you can redistribute it and/or modify
8
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
9
* the Free Software Foundation; either version 3 of the License, or
10
10
* (at your option) any later version.
12
12
* This program is distributed in the hope that it will be useful,
15
15
* GNU General Public License for more details.
17
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
21
#include "config.h"
267
266
if (memcmp (sig, "8BPS", 4) != 0)
269
268
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
270
_("Not a valid photoshop document file"));
269
_("Not a valid Photoshop document file"));
532
531
/* Initialise record */
533
532
lyr_a[lidx]->drop = FALSE;
534
533
lyr_a[lidx]->id = 0;
534
lyr_a[lidx]->group_type = 0;
536
536
if (fread (&lyr_a[lidx]->top, 4, 1, f) < 1
537
537
|| fread (&lyr_a[lidx]->left, 4, 1, f) < 1
943
943
if (img_a->color_map_len)
945
945
if (img_a->color_mode != PSD_DUOTONE)
946
gimp_image_set_colormap (image_id, img_a->color_map, img_a->color_map_entries);
947
gimp_image_set_colormap (image_id, img_a->color_map,
948
img_a->color_map_entries);
949
952
/* Add parasite for Duotone color data */
950
953
IFDBG(2) g_debug ("Add Duotone color data parasite");
951
954
parasite = gimp_parasite_new (PSD_PARASITE_DUOTONE_DATA, 0,
952
955
img_a->color_map_len, img_a->color_map);
953
gimp_image_parasite_attach (image_id, parasite);
956
gimp_image_attach_parasite (image_id, parasite);
954
957
gimp_parasite_free (parasite);
956
959
g_free (img_a->color_map);
1065
/* set the root of the group hierarchy */
1066
parent_group_stack = g_array_new (FALSE, FALSE, sizeof(gint32));
1067
g_array_append_val (parent_group_stack, parent_group_id);
1060
1069
for (lidx = 0; lidx < img_a->num_layers; ++lidx)
1062
1071
IFDBG(2) g_debug ("Process Layer No %d.", lidx);
1077
1086
g_free (lyr_a[lidx]->chn_info);
1078
1087
g_free (lyr_a[lidx]->name);
1091
if (lyr_a[lidx]->group_type != 0)
1093
if (lyr_a[lidx]->group_type == 3)
1095
/* the </Layer group> marker layers are used to
1096
assemble the layer structure in a single pass */
1097
layer_id = gimp_layer_group_new (image_id);
1099
else /* group-type == 1 || group_type == 2 */
1101
layer_id = g_array_index (parent_group_stack, gint32,
1102
parent_group_stack->len-1);
1103
/* since the layers are stored in reverse, the group
1104
layer start marker actually means we're done with
1106
g_array_remove_index (parent_group_stack,
1107
parent_group_stack->len-1);
1083
1111
/* Empty layer */
1084
1112
if (lyr_a[lidx]->bottom - lyr_a[lidx]->top == 0
1085
1113
|| lyr_a[lidx]->right - lyr_a[lidx]->left == 0)
1182
1210
if (fread (&rle_pack_len[rowi], 2, 1, f) < 1)
1184
1212
psd_set_error (feof (f), errno, error);
1213
g_free (rle_pack_len);
1187
1216
rle_pack_len[rowi] = GUINT16_FROM_BE (rle_pack_len[rowi]);
1219
1248
l_w = img_a->columns;
1220
1249
l_h = img_a->rows;
1250
parent_group_id = g_array_index (parent_group_stack, gint32,
1251
parent_group_stack->len-1);
1222
1253
IFDBG(3) g_debug ("Re-hash channel indices");
1223
1254
for (cidx = 0; cidx < lyr_a[lidx]->num_channels; ++cidx)
1244
1275
layer_channels++;
1278
if (lyr_a[lidx]->group_type != 0)
1280
if (lyr_a[lidx]->group_type == 3)
1282
IFDBG(2) g_debug ("Create placeholder group layer");
1283
g_free (lyr_a[lidx]->name);
1284
gimp_image_insert_layer (image_id, layer_id, parent_group_id, 0);
1285
/* add this group layer as the new parent */
1286
g_array_append_val (parent_group_stack, layer_id);
1290
IFDBG(2) g_debug ("End group layer id %d.", layer_id);
1291
drawable = gimp_drawable_get (layer_id);
1292
layer_mode = psd_to_gimp_blend_mode (lyr_a[lidx]->blend_mode);
1293
gimp_layer_set_mode (layer_id, layer_mode);
1294
gimp_layer_set_opacity (layer_id,
1295
lyr_a[lidx]->opacity * 100 / 255);
1296
gimp_item_set_name (drawable->drawable_id, lyr_a[lidx]->name);
1297
g_free (lyr_a[lidx]->name);
1298
gimp_item_set_visible (drawable->drawable_id,
1299
lyr_a[lidx]->layer_flags.visible);
1300
if (lyr_a[lidx]->id)
1301
gimp_item_set_tattoo (drawable->drawable_id,
1303
gimp_drawable_flush (drawable);
1304
gimp_drawable_detach (drawable);
1249
1309
IFDBG(2) g_debug ("Create blank layer");
1250
1310
image_type = get_gimp_image_type (img_a->base_type, TRUE);
1252
1312
img_a->columns, img_a->rows,
1253
1313
image_type, 0, GIMP_NORMAL_MODE);
1254
1314
g_free (lyr_a[lidx]->name);
1255
gimp_image_add_layer (image_id, layer_id, -1);
1315
gimp_image_insert_layer (image_id, layer_id, parent_group_id, -1);
1256
1316
drawable = gimp_drawable_get (layer_id);
1257
1317
gimp_drawable_fill (drawable->drawable_id, GIMP_TRANSPARENT_FILL);
1258
gimp_drawable_set_visible (drawable->drawable_id, lyr_a[lidx]->layer_flags.visible);
1318
gimp_item_set_visible (drawable->drawable_id, lyr_a[lidx]->layer_flags.visible);
1259
1319
if (lyr_a[lidx]->id)
1260
gimp_drawable_set_tattoo (drawable->drawable_id, lyr_a[lidx]->id);
1320
gimp_item_set_tattoo (drawable->drawable_id, lyr_a[lidx]->id);
1261
1321
if (lyr_a[lidx]->layer_flags.irrelevant)
1262
gimp_drawable_set_visible (drawable->drawable_id, FALSE);
1322
gimp_item_set_visible (drawable->drawable_id, FALSE);
1263
1323
gimp_drawable_flush (drawable);
1264
1324
gimp_drawable_detach (drawable);
1290
1350
IFDBG(3) g_debug ("Layer tattoo: %d", layer_id);
1291
1351
g_free (lyr_a[lidx]->name);
1292
gimp_image_add_layer (image_id, layer_id, -1);
1352
gimp_image_insert_layer (image_id, layer_id, parent_group_id, -1);
1293
1353
gimp_layer_set_offsets (layer_id, l_x, l_y);
1294
1354
gimp_layer_set_lock_alpha (layer_id, lyr_a[lidx]->layer_flags.trans_prot);
1295
1355
drawable = gimp_drawable_get (layer_id);
1297
1357
drawable->width, drawable->height, TRUE, FALSE);
1298
1358
gimp_pixel_rgn_set_rect (&pixel_rgn, pixels,
1299
1359
0, 0, drawable->width, drawable->height);
1300
gimp_drawable_set_visible (drawable->drawable_id, lyr_a[lidx]->layer_flags.visible);
1360
gimp_item_set_visible (drawable->drawable_id, lyr_a[lidx]->layer_flags.visible);
1301
1361
if (lyr_a[lidx]->id)
1302
gimp_drawable_set_tattoo (drawable->drawable_id, lyr_a[lidx]->id);
1362
gimp_item_set_tattoo (drawable->drawable_id, lyr_a[lidx]->id);
1303
1363
gimp_drawable_flush (drawable);
1304
1364
gimp_drawable_detach (drawable);
1305
1365
g_free (pixels);
1308
1368
/* Layer mask */
1369
if (user_mask && lyr_a[lidx]->group_type == 0)
1311
1371
if (empty_mask)
1487
1545
if (img_a->num_layers == 0
1488
1546
|| extra_channels > 0)
1549
guint32 block_start;
1490
1551
block_start = img_a->merged_image_start;
1491
1552
block_len = img_a->merged_image_len;
1492
block_end = block_start + block_len;
1493
1554
fseek (f, block_start, SEEK_SET);
1495
1556
if (fread (&comp_mode, COMP_MODE_SIZE, 1, f) < 1)
1548
1609
case PSD_COMP_ZIP: /* ? */
1549
1610
case PSD_COMP_ZIP_PRED:
1550
1612
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
1551
1613
_("Unsupported compression mode: %d"), comp_mode);
1576
1638
img_a->columns, img_a->rows,
1578
1640
100, GIMP_NORMAL_MODE);
1579
gimp_image_add_layer (image_id, layer_id, 0);
1641
gimp_image_insert_layer (image_id, layer_id, -1, 0);
1580
1642
drawable = gimp_drawable_get (layer_id);
1581
1643
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
1582
1644
drawable->width, drawable->height, TRUE, FALSE);
1666
1728
channel_id = gimp_channel_new (image_id, alpha_name,
1667
1729
chn_a[cidx].columns, chn_a[cidx].rows,
1668
1730
alpha_opacity, &alpha_rgb);
1669
gimp_image_add_channel (image_id, channel_id, 0);
1731
gimp_image_insert_channel (image_id, channel_id, -1, 0);
1670
1732
g_free (alpha_name);
1671
1733
drawable = gimp_drawable_get (channel_id);
1673
gimp_drawable_set_tattoo (drawable->drawable_id, alpha_id);
1674
gimp_drawable_set_visible (drawable->drawable_id, alpha_visible);
1735
gimp_item_set_tattoo (drawable->drawable_id, alpha_id);
1736
gimp_item_set_visible (drawable->drawable_id, alpha_visible);
1675
1737
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0,
1676
1738
drawable->width, drawable->height,
1846
1908
if (fread (src, rle_pack_len[i], 1, f) < 1)
1848
1910
psd_set_error (feof (f), errno, error);
1851
1915
/* FIXME check for errors returned from decode packbits */