Skip to content

Commit

Permalink
PNG: implement new user pref for "ignore ICC profiles"
Browse files Browse the repository at this point in the history
Got a lot more formats to cover, but this is at least a start!

(I'm also temporarily disabling the fix in 7741be7 pending feedback in #612 ; I'll re-enable once I know that situation is resolved.)
  • Loading branch information
tannerhelland committed Dec 30, 2024
1 parent 21bb94d commit c942e89
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions Classes/pdPNG.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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())

Expand Down
1 change: 1 addition & 0 deletions Forms/Tools_Options.frm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion PhotoDemon.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c942e89

Please sign in to comment.