Skip to content

Commit

Permalink
Fix magic wand selection rendering
Browse files Browse the repository at this point in the history
I'm not sure when these broke, but they needed to be revisited anyway in
light of GDI+'s faulty effect behavior on Win 8+.
  • Loading branch information
tannerhelland committed Oct 6, 2015
1 parent 3fcce47 commit c51f521
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
25 changes: 18 additions & 7 deletions Classes/pdFloodFill.cls
Expand Up @@ -200,7 +200,7 @@ Private Function floodFillContiguous(ByRef srcDIB As pdDIB, ByRef dstDIB As pdDI
pushOntoStack m_InitPoint.x, m_InitPoint.y

'Make sure 24 and 32bpp sources are both handled correctly
Dim x As Long, y As Long, QuickX As Long, xOffset As Long, hasAlpha As Boolean
Dim x As Long, y As Long, QuickX As Long, dstQuickX As Long, xOffset As Long, hasAlpha As Boolean
xOffset = srcDIB.getDIBColorDepth \ 8
If srcDIB.getDIBColorDepth = 32 Then hasAlpha = True Else hasAlpha = False

Expand Down Expand Up @@ -320,8 +320,11 @@ Private Function floodFillContiguous(ByRef srcDIB As pdDIB, ByRef dstDIB As pdDI

'If this value is within the requested tolerance, mark it on the destination map
If isWithinTolerance Then

dstImageData(x * 3, y) = 255

dstQuickX = x * 3
dstImageData(dstQuickX, y) = 255
dstImageData(dstQuickX + 1, y) = 255
dstImageData(dstQuickX + 2, y) = 255

'If antialiasing is active, mark this pixel as filled; this simplifies the AA process
If m_AntialiasingMode Then m_AlreadyChecked(x, y) = 2
Expand Down Expand Up @@ -355,7 +358,7 @@ Private Function floodFillGlobal(ByRef srcDIB As pdDIB, ByRef dstDIB As pdDIB) A
yBound = srcDIB.getDIBHeight - 1

'Make sure 24 and 32bpp sources are both handled correctly
Dim x As Long, y As Long, QuickX As Long, xOffset As Long, hasAlpha As Boolean
Dim x As Long, y As Long, QuickX As Long, dstQuickX As Long, xOffset As Long, hasAlpha As Boolean
xOffset = srcDIB.getDIBColorDepth \ 8
If srcDIB.getDIBColorDepth = 32 Then hasAlpha = True Else hasAlpha = False

Expand Down Expand Up @@ -471,7 +474,12 @@ Private Function floodFillGlobal(ByRef srcDIB As pdDIB, ByRef dstDIB As pdDIB) A
End Select

'If this value is within the requested tolerance, mark it on the destination map
If isWithinTolerance Then dstImageData(x * 3, y) = 255
If isWithinTolerance Then
dstQuickX = x * 3
dstImageData(dstQuickX, y) = 255
dstImageData(dstQuickX + 1, y) = 255
dstImageData(dstQuickX + 2, y) = 255
End If

Next y
Next x
Expand Down Expand Up @@ -537,7 +545,7 @@ Private Function floodFillCustomAA(ByRef floodFillDIB As pdDIB) As Boolean
CopyMemory ByVal VarPtrArray(fImageData()), VarPtr(fSA), 4

'Populate our reference comparison values
Dim aaStrength As Long
Dim aaStrength As Long, finalResult As Byte
Dim yDownSafe As Boolean, yUpSafe As Boolean

Dim constMultiplier As Double
Expand Down Expand Up @@ -585,7 +593,10 @@ Private Function floodFillCustomAA(ByRef floodFillDIB As pdDIB) As Boolean

'We know the floodfill map at this position is unfilled, so we don't even need to retrieve the value to
' calculate proper AA.
fImageData(QuickX, y) = aaStrength * constMultiplier
finalResult = aaStrength * constMultiplier
fImageData(QuickX, y) = finalResult
fImageData(QuickX + 1, y) = finalResult
fImageData(QuickX + 2, y) = finalResult

End If

Expand Down
21 changes: 14 additions & 7 deletions Classes/pdSelection.cls
Expand Up @@ -629,17 +629,17 @@ Public Function getLassoClosedState() As Boolean
getLassoClosedState = m_LassoClosed
End Function

Public Sub setLassoClosedState(ByVal NewState As Boolean)
m_LassoClosed = NewState
Public Sub setLassoClosedState(ByVal newState As Boolean)
m_LassoClosed = newState
End Sub

'For polygon selections, the canvas needs to know if the current polygon selection is open (e.g. still under construction) or closed.
Public Function getPolygonClosedState() As Boolean
getPolygonClosedState = m_PolygonClosed
End Function

Public Sub setPolygonClosedState(ByVal NewState As Boolean)
m_PolygonClosed = NewState
Public Sub setPolygonClosedState(ByVal newState As Boolean)
m_PolygonClosed = newState
End Sub

'For lasso and polygon selections, this function will return the current selecton region as a GDI+ region handle. The mouse coordinate
Expand Down Expand Up @@ -1543,14 +1543,16 @@ Private Sub createSelectionMask()
Exit Sub
End If

Dim maskBackColor As Long, maskForeColor As Long
Dim maskBackColor As Long, maskForeColor As Long, maskBackByte As Byte

'Interior and exterior selections are rendered using identical code; the only difference is the colors used
If getSelectionProperty_Long(SP_AREA) = sExterior Then
maskBackColor = RGB(255, 255, 255)
maskBackByte = 255
maskForeColor = RGB(0, 0, 0)
Else
maskBackColor = RGB(0, 0, 0)
maskBackByte = 0
maskForeColor = RGB(255, 255, 255)
End If

Expand All @@ -1576,7 +1578,11 @@ Private Sub createSelectionMask()
' As such, use caution when calling this function, as the existing mask will be completely erased.

'Start by creating a blank mask (this will also erase any existing mask)
selMask.createBlank containingPDImage.Width, containingPDImage.Height, 24, maskBackColor
If (selMask.getDIBWidth <> containingPDImage.Width) Or (selMask.getDIBHeight <> containingPDImage.Height) Then
selMask.createBlank containingPDImage.Width, containingPDImage.Height, 24, maskBackColor
Else
selMask.resetDIB maskBackByte
End If

'Border selections are automatically disabled if the border size exceeds the smallest dimension (width or height)
' of the image
Expand Down Expand Up @@ -1967,7 +1973,8 @@ Private Sub applyFeatheringToMask()
'If GDI+ 1.1 exists, use it for a faster blur operation.
If g_GDIPlusFXAvailable Then

GDIPlusBlurDIB selMask, getSelectionProperty_Long(SP_FEATHERING_RADIUS), boundLeft, boundTop, boundWidth, boundHeight
'GDIPlusBlurDIB selMask, getSelectionProperty_Long(SP_FEATHERING_RADIUS), boundLeft, boundTop, boundWidth, boundHeight
quickBlurDIB selMask, getSelectionProperty_Long(SP_FEATHERING_RADIUS)

'If GDI+ v1.0 is found, blurring is not supported, so fall back to PD's internal Gaussian blur function.
Else
Expand Down
2 changes: 1 addition & 1 deletion PhotoDemon.vbp
Expand Up @@ -317,7 +317,7 @@ Description="PhotoDemon Photo Editor"
CompatibleMode="0"
MajorVer=6
MinorVer=7
RevisionVer=595
RevisionVer=598
AutoIncrementVer=1
ServerSupportFiles=0
VersionComments="Copyright 2000-2015 Tanner Helland - photodemon.org"
Expand Down

0 comments on commit c51f521

Please sign in to comment.