Bug 592533 - Mask positions move to top-left when saving as PSD

And: Bug 593251 - Mask positions may be incorrect when opening a PSD

The position-relative flag of layer masks doesn't specify how the
mask position is represented in the PSD -- it's always absolute --
but rather whether the layer and the mask are linked or unlinked.
Since masks are always linked to their layers in GIMP, just ignore
this flag (and, when saving, clear the flag so that the mask is
linked to layer when loaded in PS.)
This commit is contained in:
Ell 2017-09-04 15:53:00 -04:00
parent 3cfa35ec07
commit eb2741ed70
2 changed files with 18 additions and 29 deletions

View File

@ -767,12 +767,11 @@ read_layer_info (PSDimage *img_a,
return NULL;
}
IFDBG(2) g_debug ("Layer mask coords %d %d %d %d, Rel pos %d",
IFDBG(2) g_debug ("Layer mask coords %d %d %d %d",
lyr_a[lidx]->layer_mask.left,
lyr_a[lidx]->layer_mask.top,
lyr_a[lidx]->layer_mask.right,
lyr_a[lidx]->layer_mask.bottom,
lyr_a[lidx]->layer_mask.mask_flags.relative_pos);
lyr_a[lidx]->layer_mask.bottom);
IFDBG(3) g_debug ("Default mask color, %d, %d",
lyr_a[lidx]->layer_mask.def_color,
@ -1535,23 +1534,11 @@ add_layers (gint32 image_id,
else
{
/* Load layer mask data */
if (lyr_a[lidx]->layer_mask.mask_flags.relative_pos)
{
lm_x = lyr_a[lidx]->layer_mask.left;
lm_y = lyr_a[lidx]->layer_mask.top;
lm_w = lyr_a[lidx]->layer_mask.right - lyr_a[lidx]->layer_mask.left;
lm_h = lyr_a[lidx]->layer_mask.bottom - lyr_a[lidx]->layer_mask.top;
}
else
{
lm_x = lyr_a[lidx]->layer_mask.left - l_x;
lm_y = lyr_a[lidx]->layer_mask.top - l_y;
lm_w = lyr_a[lidx]->layer_mask.right - lyr_a[lidx]->layer_mask.left;
lm_h = lyr_a[lidx]->layer_mask.bottom - lyr_a[lidx]->layer_mask.top;
}
lm_x = lyr_a[lidx]->layer_mask.left - l_x;
lm_y = lyr_a[lidx]->layer_mask.top - l_y;
lm_w = lyr_a[lidx]->layer_mask.right - lyr_a[lidx]->layer_mask.left;
lm_h = lyr_a[lidx]->layer_mask.bottom - lyr_a[lidx]->layer_mask.top;
IFDBG(3) g_debug ("Mask channel index %d", user_mask_chn);
IFDBG(3) g_debug ("Relative pos %d",
lyr_a[lidx]->layer_mask.mask_flags.relative_pos);
bps = (img_a->bps + 1) / 8;
layer_size = lm_w * lm_h * bps;
pixels = g_malloc (layer_size);

View File

@ -1019,20 +1019,22 @@ save_layer_and_mask (FILE *fd,
mask = gimp_layer_get_mask (PSDImageData.lLayers[i].id);
if (mask >= 0)
{
gboolean apply = gimp_layer_get_apply_mask (PSDImageData.lLayers[i].id);
gint maskWidth = gimp_drawable_width (mask);
gint maskHeight = gimp_drawable_height (mask);
gboolean apply = gimp_layer_get_apply_mask (PSDImageData.lLayers[i].id);
IFDBG printf ("\t\tLayer mask size: %d\n", 20);
write_gint32 (fd, 20, "Layer mask size");
write_gint32 (fd, 0, "Layer mask top");
write_gint32 (fd, 0, "Layer mask left");
write_gint32 (fd, gimp_drawable_height(mask),"Layer mask bottom");
write_gint32 (fd, gimp_drawable_width(mask), "Layer mask right");
write_gchar (fd, 0, "Layer mask default color");
flags = (1 | /* position relative to layer */
write_gint32 (fd, 20, "Layer mask size");
write_gint32 (fd, offset_y, "Layer mask top");
write_gint32 (fd, offset_x, "Layer mask left");
write_gint32 (fd, offset_y + maskHeight, "Layer mask bottom");
write_gint32 (fd, offset_x + maskWidth, "Layer mask right");
write_gchar (fd, 0, "Layer mask default color");
flags = (0 | /* position relative to layer */
(apply ? 0 : 1) << 1 | /* layer mask disabled */
0 << 2); /* invert layer mask */
write_gchar (fd, flags, "Layer mask flags");
write_gint16 (fd, 0, "Layer mask Padding");
write_gchar (fd, flags, "Layer mask flags");
write_gint16 (fd, 0, "Layer mask Padding");
}
else
{