Skip to content

Commit

Permalink
Fix some layer object references
Browse files Browse the repository at this point in the history
...as part of the move away from public class members
  • Loading branch information
tannerhelland committed Mar 24, 2022
1 parent a80ade7 commit 352d62e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
26 changes: 10 additions & 16 deletions Classes/pdCompositor.cls
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,7 @@ End Sub
' which is the region of the paint layer where painting has occurred. (In most cases, this will be significantly smaller than the
' full layer rect - and note that it will already be cropped to the image dimensions, as necessary.)
'
'Just like a regular merge operation, the optional parameter "bottomLayerIsFullSize" can be set to TRUE if the bottom layer is the
' same size as the current image. This saves processing time as we can skip certain rect intersection tests.
'
'Also, unlike the regular MergeLayers(), this sub *does not* handle vector layers, by design. Instead of a merge,
'Unlike the regular MergeLayers(), this sub *does not* handle vector layers, by design. Instead of a merge,
' paint ops on a vector layer are placed into a completely new raster layer.
Friend Sub MergeLayers_PaintStyle(ByRef paintLayer As pdLayer, ByRef bottomLayer As pdLayer, Optional ByVal ptrToPaintbrushRectF As Long = 0, Optional ByRef parentImage As pdImage = Nothing)

Expand Down Expand Up @@ -439,7 +436,7 @@ Friend Sub MergeLayers_PaintStyle(ByRef paintLayer As pdLayer, ByRef bottomLayer
bottomLayer.SetLayerOffsetY finalRect.Top

'Assign this temporary DIB as the new bottom layer DIB.
Set bottomLayer.GetLayerDIB = tmpDIB
bottomLayer.SetLayerDIB tmpDIB

'Calculate new offsets for the top layer, then carry on with business as usual!
xOffset = topRect.Left - finalRect.Left
Expand Down Expand Up @@ -509,8 +506,9 @@ End Sub
' particular premultiplication status of the composited DIB's alpha values. (This is helpful for save functions, which
' require non-premultiplied alpha, vs viewport functions, which require premultiplied alpha).
'
'As of 7.0, an optional scratch layer index can be specified. If >= 0, the source image's scratch layer will be rendered atop the layer at the
' requested position. (For example, if the index is 0, the scratch layer will be rendered atop the background layer.)
'As of 7.0, an optional scratch layer index can be specified. If >= 0, the source image's scratch layer will be rendered
' atop the layer at the requested position. (For example, if the index is 0, the scratch layer will be rendered atop the
' background layer.)
Friend Sub GetCompositedImage(ByRef srcImage As pdImage, ByRef dstDIB As pdDIB, Optional ByVal premultiplicationStatus As Boolean = True, Optional ByVal paintScratchLayerIndex As Long = -1)

'Start by creating the destination DIB, as necessary
Expand All @@ -526,7 +524,7 @@ Friend Sub GetCompositedImage(ByRef srcImage As pdImage, ByRef dstDIB As pdDIB,

'Subsequent steps are going to use a helper function. This helper function makes it simple to "insert" paint operations
' into the current layer stack, without fucking up the existing layer order.

'If the image has additional layers, proceed to merge the rest of them, starting from the bottom and working our way up.
' Note that if a layer is invisible, we simply skip it - this is the most performance-friendly way to handle them.
Dim i As Long
Expand Down Expand Up @@ -568,12 +566,6 @@ End Sub
' special-treatment layer (e.g. non-destructive FX, resizing, custom blend modes, etc) can avoid the creation of multiple temporary DIBs.
Private Sub GetCompositedImage_LayerHelper(ByRef dstDIB As pdDIB, ByRef srcLayer As pdLayer, ByVal srcLayerIndex As Long)

'Hypothetically, we could write special handling for 24-bpp DIBs in the future. But at present, PD only operates on 32-bpp DIBs.

'Some variables are potentially used in multiple branches of this function
Dim intLayerOffsetX As Long, intLayerOffsetY As Long
Dim layerBoundariesOkay As Boolean

'If this layer is a vector layer, make sure its DIB is properly synchronized. (If it's *not* a vector layer, this action does nothing.)
srcLayer.SyncInternalDIB

Expand Down Expand Up @@ -625,7 +617,7 @@ Private Sub GetCompositedImage_LayerHelper(ByRef dstDIB As pdDIB, ByRef srcLayer

End If

'This Else statement represents the case "If (srcLayer.getLayerBlendMode <> BM_Normal)..."
'This Else statement represents the case "If (srcLayer.GetLayerBlendMode <> BM_Normal)..."
Else

'Custom blend modes are active. We have no choice but to create a temporary compositing DIB.
Expand All @@ -642,8 +634,10 @@ Private Sub GetCompositedImage_LayerHelper(ByRef dstDIB As pdDIB, ByRef srcLayer
Else

'The layer itself provides a highly optimized method for extracting the affine-transformed portion of its DIB
Dim intLayerOffsetX As Long, intLayerOffsetY As Long
Dim layerBoundariesOkay As Boolean
layerBoundariesOkay = .GetAffineTransformedDIB(m_tmpDIB, intLayerOffsetX, intLayerOffsetY, dstDIB.GetDIBWidth, dstDIB.GetDIBHeight)

'Next, perform an all-in-one composite + blend using our awesome new compositeAndBlendDIBs function
If layerBoundariesOkay Then CompositeAndBlendDIBs m_tmpDIB, dstDIB, .GetLayerBlendMode, intLayerOffsetX, intLayerOffsetY, .GetLayerOpacity / 100, , .GetLayerAlphaMode

Expand Down
2 changes: 1 addition & 1 deletion Classes/pdImage.cls
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Friend Sub RebuildCompositeBuffer(Optional ByVal renderScratchLayerIndex As Long
Else

'Rebuild the composite cache
imgCompositor.GetCompositedImage Me, CompositeBuffer, , renderScratchLayerIndex
imgCompositor.GetCompositedImage Me, CompositeBuffer, True, renderScratchLayerIndex

'Mark the cache as clean. (NOTE: this is disabled pending further testing; I'm not sure that all changes
' are being tracked correctly, so composites are currently generated on every request as a workaround)
Expand Down
13 changes: 8 additions & 5 deletions Classes/pdWebP.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1350,19 +1350,22 @@ Private Function LoadAnimatedWebP(ByRef srcFile As String, ByVal pData As Long,

'Success! Create a new layer in the destination image, then copy the pixel data and
' timestamp into it.
Dim newLayerID As Long, newLayerName As String, tmpLayer As pdLayer
Dim newLayerID As Long, newLayerName As String, tmpLayer As pdLayer, tmpDIB As pdDIB
newLayerID = dstImage.CreateBlankLayer()
Set tmpLayer = dstImage.GetLayerByID(newLayerID)
newLayerName = Layers.GenerateInitialLayerName(vbNullString, vbNullString, True, dstImage, dstDIB, idxFrame)
tmpLayer.InitializeNewLayer PDL_Image, newLayerName, Nothing, True
tmpLayer.SetLayerVisibility (idxFrame = 0)

If (tmpLayer.GetLayerDIB Is Nothing) Then Set tmpLayer.GetLayerDIB = New pdDIB
tmpLayer.GetLayerDIB.CreateBlank m_AnimationInfo.canvas_width, m_AnimationInfo.canvas_height, 32, 0, 0
CopyMemoryStrict tmpLayer.GetLayerDIB.GetDIBPointer, ptrPixels, tmpLayer.GetLayerDIB.GetDIBStride * tmpLayer.GetLayerDIB.GetDIBHeight
Set tmpDIB = New pdDIB
tmpDIB.CreateBlank m_AnimationInfo.canvas_width, m_AnimationInfo.canvas_height, 32, 0, 0
CopyMemoryStrict tmpDIB.GetDIBPointer, ptrPixels, tmpDIB.GetDIBStride * tmpDIB.GetDIBHeight

'We explicitly request premultiplied data, so we don't need to manually premultiply now
tmpLayer.GetLayerDIB.SetInitialAlphaPremultiplicationState True
tmpDIB.SetInitialAlphaPremultiplicationState True

'Assign the finished layer image
tmpLayer.SetLayerDIB tmpDIB

'As part of storing frametime, update the layer's name with ([time] ms) at the end
frameTimeInMS = frameTimestamp - lastFrameTimestamp
Expand Down
4 changes: 2 additions & 2 deletions Forms/Image_Compare.frm
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Public Sub CompareImages(ByRef listOfParameters As String)
'Copy the DIB into a temporary layer object
Set cmpLayer = New pdLayer
cmpLayer.CopyExistingLayer tmpLayer
Set cmpLayer.GetLayerDIB = tmpDIB
cmpLayer.SetLayerDIB tmpDIB

End If

Expand Down Expand Up @@ -374,7 +374,7 @@ Public Sub CompareImages(ByRef listOfParameters As String)
srcImage.GetLayerByID(newLayerID).SetLayerName g_Language.TranslateMessage("difference between %1 and %2", srcLayer.GetLayerName, cmpLayer.GetLayerName)

'Replace the (temporary) DIB it created with the merged DIB we just created
Set srcImage.GetLayerByID(newLayerID).GetLayerDIB = baseDIB
srcImage.GetLayerByID(newLayerID).SetLayerDIB baseDIB

'Make the duplicate layer the active layer
srcImage.SetActiveLayerByID newLayerID
Expand Down
3 changes: 1 addition & 2 deletions Modules/Filters_Transform.bas
Original file line number Diff line number Diff line change
Expand Up @@ -524,14 +524,13 @@ Public Sub CropToSelection(Optional ByVal targetLayerIndex As Long = -1, Optiona
tmpDIB.SetInitialAlphaPremultiplicationState True

'Update the target layer's backing surface with the newly composited result
Set tmpLayerRef.GetLayerDIB = tmpDIB
tmpLayerRef.SetLayerDIB tmpDIB

'Update the layer's offsets to match.
If (targetLayerIndex = -1) Then
tmpLayerRef.SetLayerOffsetX newLayerRect.Left - selBounds.Left
tmpLayerRef.SetLayerOffsetY newLayerRect.Top - selBounds.Top
Else
Debug.Print newLayerRect.Left, newLayerRect.Top, selBounds.Left, selBounds.Top
tmpLayerRef.SetLayerOffsetX newLayerRect.Left
tmpLayerRef.SetLayerOffsetY newLayerRect.Top
End If
Expand Down

0 comments on commit 352d62e

Please sign in to comment.