From b74a34c9009e6687ba0cf6e90aedec990d62ad10 Mon Sep 17 00:00:00 2001 From: Unity Technologies <@unity> Date: Mon, 11 Oct 2021 00:00:00 +0000 Subject: [PATCH] com.unity.2d.psdimporter@2.1.10 ## [2.1.10] - 2021-10-11 ### Fixed - Fixed artifacts on images when flatten. - Fixed exception "PsdInvalidException: Unrecognized layer section type" when importing certain files --- CHANGELOG.md | 5 +++++ Editor/PSDPlugin/PsdFile/PsdFile.cs | 5 ++++- Editor/Tasks/FlattenImageTask.cs | 17 ++++++++++++----- package.json | 10 +++++----- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ff4ea..5190f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [2.1.10] - 2021-10-11 +### Fixed +- Fixed artifacts on images when flatten. +- Fixed exception "PsdInvalidException: Unrecognized layer section type" when importing certain files + ## [2.1.9] - 2021-09-11 ### Fixed - Fixed Unity hang when importing certain PSD files (case 1357563) diff --git a/Editor/PSDPlugin/PsdFile/PsdFile.cs b/Editor/PSDPlugin/PsdFile/PsdFile.cs index 8092b4a..b1160bf 100644 --- a/Editor/PSDPlugin/PsdFile/PsdFile.cs +++ b/Editor/PSDPlugin/PsdFile/PsdFile.cs @@ -557,7 +557,10 @@ internal void VerifyLayerSections() if (depth < 0) throw new PsdInvalidException("Layer section ended without matching start marker."); break; - + + case LayerSectionType.Layer: // Nothing to do here yet. + break; + default: throw new PsdInvalidException("Unrecognized layer section type."); } diff --git a/Editor/Tasks/FlattenImageTask.cs b/Editor/Tasks/FlattenImageTask.cs index 434dc05..e6d65e4 100644 --- a/Editor/Tasks/FlattenImageTask.cs +++ b/Editor/Tasks/FlattenImageTask.cs @@ -111,11 +111,18 @@ public unsafe void Execute(int index) { int sourceIndex = sourceYIndex + j; int destIndex = destYIndex + j; - float alpha = buffer[sourceIndex].a / 255.0f; - premerge[destIndex].r = (byte)(alpha * (float)(buffer[sourceIndex].r) + (float)((1.0f - alpha) * (float)premerge[destIndex].r)); - premerge[destIndex].g = (byte)(alpha * (float)(buffer[sourceIndex].g) + (float)((1.0f - alpha) * (float)premerge[destIndex].g)); - premerge[destIndex].b = (byte)(alpha * (float)(buffer[sourceIndex].b) + (float)((1.0f - alpha) * (float)premerge[destIndex].b)); - premerge[destIndex].a = (byte)(alpha * (float)(buffer[sourceIndex].a) + (float)((1.0f - alpha) * (float)premerge[destIndex].a)); + Color sourceColor = buffer[sourceIndex]; + Color destColor = premerge[destIndex]; + Color finalColor = new Color(); + + var destAlpha = destColor.a * (1 - sourceColor.a); + finalColor.a = sourceColor.a + destColor.a * (1 - sourceColor.a); + var premultiplyAlpha = 1 / finalColor.a; + finalColor.r = (sourceColor.r * sourceColor.a + destColor.r * destAlpha) * premultiplyAlpha; + finalColor.g = (sourceColor.g * sourceColor.a + destColor.g * destAlpha) * premultiplyAlpha; + finalColor.b = (sourceColor.b * sourceColor.a + destColor.b * destAlpha) * premultiplyAlpha; + + premerge[destIndex] = finalColor; } } } diff --git a/package.json b/package.json index b101d04..e2b5fc0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.unity.2d.psdimporter", - "version": "2.1.9", + "version": "2.1.10", "unity": "2019.4", "unityRelease": "0b11", "displayName": "2D PSD Importer", @@ -13,18 +13,18 @@ "category": "2D", "dependencies": { "com.unity.2d.common": "2.1.0", - "com.unity.2d.animation": "3.2.13", + "com.unity.2d.animation": "3.2.14", "com.unity.2d.sprite": "1.0.0" }, "relatedPackages": { - "com.unity.2d.psdimporter.tests": "2.1.9" + "com.unity.2d.psdimporter.tests": "2.1.10" }, "upmCi": { - "footprint": "cb30cdb0e6e9cd8458d6f9be1d58191062b5f918" + "footprint": "3356ee89cf126c40d807c0b82ba1eaa410a99e15" }, "repository": { "url": "https://github.cds.internal.unity3d.com/unity/2d.git", "type": "git", - "revision": "ff5113572ce6bc283f75b25349ccec9f1ea17bd6" + "revision": "97be4f400509652c3a4ce6929a6be114072c3a74" } }