From c942e894e9cb5ea0ba5a279539d6cc2a23366507 Mon Sep 17 00:00:00 2001 From: Tanner Date: Mon, 30 Dec 2024 06:58:14 -0700 Subject: [PATCH] PNG: implement new user pref for "ignore ICC profiles" Got a lot more formats to cover, but this is at least a start! (I'm also temporarily disabling the fix in 7741be739a4f818e74f9ad37bd2c29b2b5d75aee pending feedback in #612 ; I'll re-enable once I know that situation is resolved.) --- Classes/pdPNG.cls | 16 +++++++++++++--- Forms/Tools_Options.frm | 1 + PhotoDemon.vbp | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Classes/pdPNG.cls b/Classes/pdPNG.cls index 88201e115..d81bbfa77 100644 --- a/Classes/pdPNG.cls +++ b/Classes/pdPNG.cls @@ -1003,9 +1003,12 @@ Friend Function ImportStage5_ConstructImage(ByRef srcFile As String, ByRef dstDI 'If the PNG contained ICC profile data, retrieve it now; otherwise, assume sRGB. (Note that a ' transform may be generated either way, as LittleCMS can be used for fast swizzling.) Dim imgHasEmbeddedICC As Boolean - imgHasEmbeddedICC = (Me.GetIndexOfChunk("iCCP") >= 0) + imgHasEmbeddedICC = (Me.GetIndexOfChunk("iCCP") >= 0) And ColorManagement.UseEmbeddedICCProfiles() Dim srcProfile As pdLCMSProfile, dstProfile As pdLCMSProfile, dstTransform As pdLCMSTransform, srcImgProfileGood As Boolean + + 'The PrepICCData function will mark this as TRUE if the embedded profile passes validation + srcImgProfileGood = False PrepICCData srcProfile, dstProfile, dstTransform, srcImgProfileGood If srcImgProfileGood Then @@ -1629,7 +1632,8 @@ Friend Function ImportStage6_PostProcessing(ByRef srcFile As String, ByRef dstDI If (Not gammaOK) Then If PNG_DEBUG_VERBOSE Then PDDebug.LogAction "WARNING: chromaticity present, but gamma missing; colors may be incorrect!" - gammaFloat = 2.2 + '(Temporarily commented out while awaiting user feedback on https://github.com/tannerhelland/PhotoDemon/issues/612 ) + 'gammaFloat = 2.2 End If 'Our next goal is to assemble an ICC profile that matches the chromaticity and/or gamma data. @@ -6070,8 +6074,14 @@ Private Sub PrepICCData(ByRef srcProfile As pdLCMSProfile, ByRef dstProfile As p ' ICC handling under some scenarios. Dim iccRequired As Boolean: iccRequired = True + 'Users can set a preference for ignoring embedded profiles (this allows recovery of images with broken or faulty ICC) Dim iccIndex As Long - iccIndex = Me.GetIndexOfChunk("iCCP") + If ColorManagement.UseEmbeddedICCProfiles() Then + iccIndex = Me.GetIndexOfChunk("iCCP") + Else + iccIndex = -1 + End If + If (iccIndex > 0) Then srcImgProfileGood = srcProfile.CreateFromPointer(m_Chunks(iccIndex).BorrowData().Peek_PointerOnly(0), m_Chunks(iccIndex).BorrowData().GetStreamSize()) diff --git a/Forms/Tools_Options.frm b/Forms/Tools_Options.frm index abbc79fc9..c11361c83 100644 --- a/Forms/Tools_Options.frm +++ b/Forms/Tools_Options.frm @@ -1745,6 +1745,7 @@ Private Sub Form_Load() chkColorManagement(1).Value = ColorManagement.UseEmbeddedICCProfiles() chkColorManagement(1).AssignTooltip "Embedded ICC profiles improve color fidelity. Even if this setting is turned off, PhotoDemon may still use ICC profiles for some tasks (like handling CMYK data)." 'DISABLED PENDING IMPLEMENTATION + chkColorManagement(1).Value = True chkColorManagement(1).Enabled = False chkColorManagement(2).Value = ColorManagement.UseEmbeddedLegacyProfiles() diff --git a/PhotoDemon.vbp b/PhotoDemon.vbp index d48cbc6a1..7ea6d2709 100644 --- a/PhotoDemon.vbp +++ b/PhotoDemon.vbp @@ -534,7 +534,7 @@ Description="PhotoDemon Photo Editor" CompatibleMode="0" MajorVer=2024 MinorVer=12 -RevisionVer=14 +RevisionVer=16 AutoIncrementVer=1 ServerSupportFiles=0 VersionComments="Copyright 2000-2024 Tanner Helland - photodemon.org"