Skip to content

Commit

Permalink
Fix oriented image preview (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Mar 29, 2024
1 parent 29815ac commit 1dcf0b8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Dev/Sources/SharedForDemo/Mocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ enum Mocks {
static func imageSuperSmall() -> UIImage {
UIImage(named: "super-small")!
}


static func imageOrientationLeft() -> UIImage {
UIImage(named: "orientation_left.HEIC")!
}

static func makeEditingStack(image: UIImage) -> EditingStack {
.init(
imageProvider: .init(image: image)
Expand Down
13 changes: 13 additions & 0 deletions Dev/Sources/SwiftUIDemo/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ struct ContentView: View {
}
}

Button("PixelEditor left") {
fullScreenView = .init {
DemoPixelEditor(
editingStack: {
EditingStack.init(
imageProvider: .init(image: Mocks.imageOrientationLeft())
)
},
options: .init(croppingAspectRatio: nil)
)
}
}

})

Section("Lab") {
Expand Down
1 change: 1 addition & 0 deletions Sources/BrightroomEngine/Core/EditingStack.Edit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extension EditingStack {
crop.imageSize
}

/// In orientation.up
public var crop: EditingCrop
public var filters: Filters = .init()
public var drawings: Drawings = .init()
Expand Down
13 changes: 11 additions & 2 deletions Sources/BrightroomEngine/Core/EditingStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -412,19 +412,28 @@ open class EditingStack: Hashable, StoreComponentType {
public func makeCroppedCIImage(loadedState: State.Loaded) -> 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
.applying(cgOrientation: orientation)

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

return try image
// TODO: better to combine these operations - oriented and cropping
.oriented(orientation)
.croppedWithColorspace(
to: scaledCrop.cropExtent, adjustmentAngleRadians: scaledCrop.aggregatedRotation.radians)
to: scaledCrop.cropExtent, adjustmentAngleRadians: scaledCrop.aggregatedRotation.radians
)
._makeCIImage(
orientation: loadedState.metadata.orientation,
orientation: .up,
device: mtlDevice,
usesMTLTexture: options.usesMTLTextureForEditingImage
)
Expand Down

0 comments on commit 1dcf0b8

Please sign in to comment.