From edf1e3d2cddde2c0336fb632491e44ba2dca5e2b Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity> Date: Mon, 7 Feb 2022 00:00:00 +0000 Subject: [PATCH] com.unity.2d.psdimporter@6.0.3 ## [6.0.3] - 2022-02-07 ### Fixed - Fixed unable to change mipmap settings in inspector. (Case 1381198) - Fixed null exception when importing files with masks. (Case 1397354) --- CHANGELOG.md | 6 ++++ Editor/PSDImporterEditor.cs | 2 +- Editor/PSDPlugin/PsdFile/Layers/Mask.cs | 36 ++++++++++++++++++++- Editor/PSDPlugin/PsdFile/PsdBinaryReader.cs | 11 +++++++ package.json | 13 ++++---- 5 files changed, 60 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f02fd7b..24b89a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ # Changelog +## [6.0.3] - 2022-02-07 +### Fixed +- Fixed unable to change mipmap settings in inspector. (Case 1381198) +- Fixed null exception when importing files with masks. (Case 1397354) + ## [6.0.2] - 2021-11-24 ### Fixed - Fixed per platform settings does not get applied in Windows platform. (Case 1379970) +- Fixed unable to change mipmap settings in inspector. (Case 1381198) ## [6.0.1] - 2021-09-21 ### Fixed diff --git a/Editor/PSDImporterEditor.cs b/Editor/PSDImporterEditor.cs index f8689ac..08d8b64 100644 --- a/Editor/PSDImporterEditor.cs +++ b/Editor/PSDImporterEditor.cs @@ -847,7 +847,7 @@ void MipMapGUI() { EditorGUI.indentLevel++; ToggleFromInt(m_BorderMipMap, s_Styles.borderMipMaps); - EditorGUILayout.Popup(s_Styles.mipMapFilter, m_MipMapMode.intValue, s_Styles.mipMapFilterOptions); + m_MipMapMode.intValue = EditorGUILayout.Popup(s_Styles.mipMapFilter, m_MipMapMode.intValue, s_Styles.mipMapFilterOptions); ToggleFromInt(m_MipMapsPreserveCoverage, s_Styles.mipMapsPreserveCoverage); if (m_MipMapsPreserveCoverage.intValue != 0 && !m_MipMapsPreserveCoverage.hasMultipleDifferentValues) 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 b73b95f..9899871 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { "name": "com.unity.2d.psdimporter", - "version": "6.0.2", + "version": "6.0.3", "unity": "2021.2", + "unityRelease": "7f1", "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.", "keywords": [ @@ -11,19 +12,19 @@ ], "category": "2D", "dependencies": { - "com.unity.2d.animation": "7.0.3", - "com.unity.2d.common": "6.0.2", + "com.unity.2d.animation": "7.0.4", + "com.unity.2d.common": "6.0.3", "com.unity.2d.sprite": "1.0.0" }, "relatedPackages": { - "com.unity.2d.psdimporter.tests": "6.0.2" + "com.unity.2d.psdimporter.tests": "6.0.3" }, "upmCi": { - "footprint": "ba98f99ccbaa84a993003055774cd003dc4e4a5c" + "footprint": "d201ce7dd6bf474493bca45e8c571c4140e1f51b" }, "repository": { "url": "https://github.cds.internal.unity3d.com/unity/2d.git", "type": "git", - "revision": "890da0579456dc5daa73a5645949c0615fac3d16" + "revision": "41fd674f8e4b2265bdbc50291dced1bd86c590ee" } }