diff --git a/CHANGELOG.md b/CHANGELOG.md index ac6e4d5..a0f32cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [7.0.0] - 2022-01-25 +### Changed +- Package release version. + +### Fixed +- Fixed null exception when importing files with masks. (Case 1388820) + ## [7.0.0-pre.4] - 2021-11-24 ### Fixed - Fixed per platform settings does not get applied in Windows platform. (Case 1376608) diff --git a/Editor/PSDPlugin/PsdFile/Layers/Mask.cs b/Editor/PSDPlugin/PsdFile/Layers/Mask.cs index b99a924..c101925 100644 --- a/Editor/PSDPlugin/PsdFile/Layers/Mask.cs +++ b/Editor/PSDPlugin/PsdFile/Layers/Mask.cs @@ -103,6 +103,11 @@ public Mask(Layer layer, Rectangle rect, byte color, BitVector32 flags) /// internal class MaskInfo { + private static int s_UserMaskDensityBit = BitVector32.CreateMask(); + private static int s_UserMaskFeatherBit = BitVector32.CreateMask(s_UserMaskDensityBit); + private static int s_VectorMaskDensityBit = BitVector32.CreateMask(s_UserMaskFeatherBit); + private static int s_VectorMaskFeatherBit = BitVector32.CreateMask(s_VectorMaskDensityBit); + public Mask LayerMask { get; set; } public Mask UserMask { get; set; } @@ -113,7 +118,7 @@ internal class MaskInfo public MaskInfo() { } - + public MaskInfo(PsdBinaryReader reader, Layer layer) { Util.DebugMessage(reader.BaseStream, "Load, Begin, MaskInfo"); @@ -139,6 +144,35 @@ public MaskInfo(PsdBinaryReader reader, Layer layer) var userRectangle = reader.ReadRectangle(); UserMask = new Mask(layer, userRectangle, userBackgroundColor, new BitVector32(userFlagsByte)); } + else + { + // Only check if bit 4 is set. Testing shows there are discrepancy in file format documentation. + if (flagsByte == 16) + { + // Not using them so just read and discard the values + var maskParameters = new BitVector32(reader.ReadByte()); + if (maskParameters[s_UserMaskDensityBit]) + reader.ReadByte(); + + if (maskParameters[s_UserMaskFeatherBit]) + reader.ReadDouble(); + + if (maskParameters[s_VectorMaskDensityBit]) + reader.ReadByte(); + + if (maskParameters[s_VectorMaskFeatherBit]) + reader.ReadDouble(); + } + + // The rest should be vector mask + if (reader.BaseStream.Position + 18 <= endPosition) + { + var userFlagsByte = reader.ReadByte(); + var userBackgroundColor = reader.ReadByte(); + var userRectangle = reader.ReadRectangle(); + UserMask = new Mask(layer, userRectangle, userBackgroundColor, new BitVector32(userFlagsByte)); + } + } // 20-byte mask data will end with padding. reader.BaseStream.Position = endPosition; diff --git a/Editor/PSDPlugin/PsdFile/PsdBinaryReader.cs b/Editor/PSDPlugin/PsdFile/PsdBinaryReader.cs index 224554c..ecada22 100644 --- a/Editor/PSDPlugin/PsdFile/PsdBinaryReader.cs +++ b/Editor/PSDPlugin/PsdFile/PsdBinaryReader.cs @@ -86,6 +86,17 @@ public Int32 ReadInt32() return val; } + public double ReadDouble() + { + var val = reader.ReadDouble(); + byte[] b = BitConverter.GetBytes(val); + { + Util.SwapBytes(b, 0, 8); + } + val = BitConverter.ToDouble(b, 0); + return val; + } + public Int64 ReadInt64() { var val = reader.ReadInt64(); diff --git a/package.json b/package.json index 57950a8..b228f0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.unity.2d.psdimporter", - "version": "7.0.0-pre.4", + "version": "7.0.0", "unity": "2022.1", "displayName": "2D PSD Importer", "description": "A ScriptedImporter for importing Adobe Photoshop PSB (Photoshop Big) file format. The ScriptedImporter is currently targeted for users who wants to create multi Sprite character animation using Unity 2D Animation Package.", @@ -11,19 +11,19 @@ ], "category": "2D", "dependencies": { - "com.unity.2d.animation": "8.0.0-pre.4", - "com.unity.2d.common": "7.0.0-pre.4", + "com.unity.2d.animation": "8.0.0", + "com.unity.2d.common": "7.0.0", "com.unity.2d.sprite": "1.0.0" }, "relatedPackages": { - "com.unity.2d.psdimporter.tests": "7.0.0-pre.4" + "com.unity.2d.psdimporter.tests": "7.0.0" }, "upmCi": { - "footprint": "f1a15a8f988d611cbb180bebea038e1fe445bf5e" + "footprint": "5aba1aaa4a6f9d3fb3a1bcc61c4b2832cf317602" }, "repository": { "url": "https://github.cds.internal.unity3d.com/unity/2d.git", "type": "git", - "revision": "2ccafc0d438881083c9c1ec71f92ef170494bd59" + "revision": "9b89f439ca5c8ef326594d90bc874e30e9e37104" } }