Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
shima11 committed Apr 11, 2024
1 parent e3453a9 commit ce1ead4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
15 changes: 7 additions & 8 deletions Sources/BrightroomEngine/Core/EditingStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -409,24 +409,23 @@ open class EditingStack: Hashable, StoreComponentType {
For previewing image
*/
public func makeCroppedCIImage(loadedState: State.Loaded) -> CIImage {
public func makeCroppedCIImage(
sourceImage: CGImage,
crop: EditingCrop,
orientation: CGImagePropertyOrientation
) -> CIImage {

do {
let orientation = loadedState.metadata.orientation
let crop = loadedState.currentEdit.crop

// orientation is not respected
let image = loadedState.editingSourceCGImage

// orientation-respected
let imageSize = image.size
let imageSize = sourceImage.size
.applying(cgOrientation: orientation)

let scaledCrop = crop.scaledWithPixelPerfect(
maxPixelSize: max(imageSize.width, imageSize.height)
)

return try image
return try sourceImage
// TODO: better to combine these operations - oriented and cropping
.oriented(orientation)
.croppedWithColorspace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public final class ImagePreviewView: PixelEditorCodeBasedView {
private weak var currentLoadingOverlay: UIView?

private var isBinding = false
private var cachedCroppedImage: (EditingStack.State.Loaded, CIImage)? = nil
private var cachedCroppedImage: (state: EditingStack.State.Loaded, image: CIImage)? = nil

// MARK: - Initializers

Expand Down Expand Up @@ -128,13 +128,17 @@ public final class ImagePreviewView: PixelEditorCodeBasedView {
let croppedImage: CIImage
if
let cachedCroppedImage,
state.editingSourceCGImage == cachedCroppedImage.0.editingSourceCGImage,
state.metadata == cachedCroppedImage.0.metadata,
state.currentEdit.crop == cachedCroppedImage.0.currentEdit.crop
state.editingSourceCGImage == cachedCroppedImage.state.editingSourceCGImage,
state.metadata == cachedCroppedImage.state.metadata,
state.currentEdit.crop == cachedCroppedImage.state.currentEdit.crop
{
croppedImage = cachedCroppedImage.1
croppedImage = cachedCroppedImage.image
} else {
croppedImage = editingStack.makeCroppedCIImage(loadedState: state)
croppedImage = editingStack.makeCroppedCIImage(
sourceImage: state.editingSourceCGImage,
crop: state.currentEdit.crop,
orientation: state.metadata.orientation
)
cachedCroppedImage = (state, croppedImage)
}
imageView.display(image: croppedImage)
Expand Down

0 comments on commit ce1ead4

Please sign in to comment.