~ubuntu-branches/ubuntu/quantal/gimp/quantal-updates

« back to all changes in this revision

Viewing changes to plug-ins/file-psd/psd-load.c

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-05-20 19:21:01 UTC
  • mfrom: (1.1.26) (0.4.16 sid)
  • Revision ID: package-import@ubuntu.com-20120520192101-bs7zetx8ffoq2nfv
Tags: 2.8.0-2ubuntu1
* Merge from Debian unstable (LP: #908472). Remaining Changes:
  - debian/patches/02_help-message.patch,
    debian/patches/03_gimp.desktop.in.in.patch:
    + Update some strings for Ubuntu
  - debian/control:
    + Update description
  - debian/rules:
    + Set gettext domain and update translation templates
* Drop the following patches that were applied upstream:
  - debian/patches/ghost-cursor.patch: fix Wacom tablet cursor events
  - debian/patches/embed-page-setup-dialog.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * GIMP PSD Plug-in
5
5
 * Copyright 2007 by John Marshall
6
6
 *
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.
11
11
 *
12
12
 * This program is distributed in the hope that it will be useful,
15
15
 * GNU General Public License for more details.
16
16
 *
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/>.
20
19
 */
21
20
 
22
21
#include "config.h"
267
266
  if (memcmp (sig, "8BPS", 4) != 0)
268
267
    {
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"));
271
270
      return -1;
272
271
    }
273
272
 
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;
535
535
 
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)
944
944
    {
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);
 
946
        {
 
947
          gimp_image_set_colormap (image_id, img_a->color_map,
 
948
                                   img_a->color_map_entries);
 
949
        }
947
950
      else
948
951
        {
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);
955
958
        }
956
959
      g_free (img_a->color_map);
1010
1013
            GError      **error)
1011
1014
{
1012
1015
  PSDchannel          **lyr_chn;
 
1016
  GArray               *parent_group_stack;
 
1017
  gint32                parent_group_id = -1;
1013
1018
  guchar               *pixels;
1014
1019
  guint16               alpha_chn;
1015
1020
  guint16               user_mask_chn;
1057
1062
      return -1;
1058
1063
    }
1059
1064
 
 
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);
 
1068
 
1060
1069
  for (lidx = 0; lidx < img_a->num_layers; ++lidx)
1061
1070
    {
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);
1079
1088
        }
1080
 
 
1081
1089
      else
1082
1090
        {
 
1091
          if (lyr_a[lidx]->group_type != 0)
 
1092
            {
 
1093
              if (lyr_a[lidx]->group_type == 3)
 
1094
                {
 
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);
 
1098
                }
 
1099
              else /* group-type == 1 || group_type == 2 */
 
1100
                {
 
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
 
1105
                     that layer group */
 
1106
                  g_array_remove_index (parent_group_stack,
 
1107
                                        parent_group_stack->len-1);
 
1108
                }
 
1109
            }
 
1110
 
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)
1183
1211
                              {
1184
1212
                                psd_set_error (feof (f), errno, error);
 
1213
                                g_free (rle_pack_len);
1185
1214
                                return -1;
1186
1215
                              }
1187
1216
                            rle_pack_len[rowi] = GUINT16_FROM_BE (rle_pack_len[rowi]);
1218
1247
          l_y = 0;
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);
1221
1252
 
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++;
1245
1276
            }
1246
1277
 
1247
 
          if (empty)
 
1278
          if (lyr_a[lidx]->group_type != 0)
 
1279
            {
 
1280
              if (lyr_a[lidx]->group_type == 3)
 
1281
                {
 
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);
 
1287
                }
 
1288
              else
 
1289
                {
 
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,
 
1302
                                          lyr_a[lidx]->id);
 
1303
                  gimp_drawable_flush (drawable);
 
1304
                  gimp_drawable_detach (drawable);
 
1305
                }
 
1306
            }
 
1307
          else if (empty)
1248
1308
            {
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);
1265
1325
            }
1289
1349
                                         layer_mode);
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);
1306
1366
            }
1307
1367
 
1308
1368
          /* Layer mask */
1309
 
          if (user_mask)
 
1369
          if (user_mask && lyr_a[lidx]->group_type == 0)
1310
1370
            {
1311
1371
              if (empty_mask)
1312
1372
                {
1418
1478
      g_free (lyr_a[lidx]);
1419
1479
    }
1420
1480
  g_free (lyr_a);
 
1481
  g_array_free (parent_group_stack, FALSE);
1421
1482
 
1422
1483
  return 0;
1423
1484
}
1436
1497
  guint16               extra_channels;
1437
1498
  guint16               total_channels;
1438
1499
  guint16              *rle_pack_len[MAX_CHANNELS];
1439
 
  guint32               block_len;
1440
 
  guint32               block_start;
1441
 
  guint32               block_end;
1442
1500
  guint32               alpha_id;
1443
1501
  gint32                layer_size;
1444
1502
  gint32                layer_id = -1;
1487
1545
  if (img_a->num_layers == 0
1488
1546
      || extra_channels > 0)
1489
1547
    {
 
1548
      guint32 block_len;
 
1549
      guint32 block_start;
 
1550
 
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;
 
1553
 
1493
1554
      fseek (f, block_start, SEEK_SET);
1494
1555
 
1495
1556
      if (fread (&comp_mode, COMP_MODE_SIZE, 1, f) < 1)
1547
1608
 
1548
1609
          case PSD_COMP_ZIP:                 /* ? */
1549
1610
          case PSD_COMP_ZIP_PRED:
 
1611
          default:
1550
1612
            g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
1551
1613
                        _("Unsupported compression mode: %d"), comp_mode);
1552
1614
            return -1;
1576
1638
                                 img_a->columns, img_a->rows,
1577
1639
                                 image_type,
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);
1672
1734
          if (alpha_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,
1677
1739
                                TRUE, FALSE);
1846
1908
            if (fread (src, rle_pack_len[i], 1, f) < 1)
1847
1909
              {
1848
1910
                psd_set_error (feof (f), errno, error);
 
1911
                g_free (src);
 
1912
                g_free (dst);
1849
1913
                return -1;
1850
1914
              }
1851
1915
            /* FIXME check for errors returned from decode packbits */