Fix Metal texture size mismatch in mask loading
Scale mask and image to texture dimensions when loading into Metal textures, fixing crash when brush mask has different dimensions than the source image. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -294,8 +294,9 @@ final class PatchMatchInpainter {
|
|||||||
// MARK: - Texture Utilities
|
// MARK: - Texture Utilities
|
||||||
|
|
||||||
private func loadCGImage(_ cgImage: CGImage, into texture: MTLTexture) throws {
|
private func loadCGImage(_ cgImage: CGImage, into texture: MTLTexture) throws {
|
||||||
let width = cgImage.width
|
// Use texture dimensions for consistency
|
||||||
let height = cgImage.height
|
let width = texture.width
|
||||||
|
let height = texture.height
|
||||||
|
|
||||||
guard let context = CGContext(
|
guard let context = CGContext(
|
||||||
data: nil,
|
data: nil,
|
||||||
@@ -309,6 +310,8 @@ final class PatchMatchInpainter {
|
|||||||
throw PatchMatchError.contextCreationFailed
|
throw PatchMatchError.contextCreationFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the image scaled to fit the texture dimensions
|
||||||
|
context.interpolationQuality = .high
|
||||||
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height))
|
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height))
|
||||||
|
|
||||||
guard let data = context.data else {
|
guard let data = context.data else {
|
||||||
@@ -324,8 +327,9 @@ final class PatchMatchInpainter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func loadCGImageGrayscale(_ cgImage: CGImage, into texture: MTLTexture) throws {
|
private func loadCGImageGrayscale(_ cgImage: CGImage, into texture: MTLTexture) throws {
|
||||||
let width = cgImage.width
|
// Use texture dimensions, scaling the mask if needed
|
||||||
let height = cgImage.height
|
let width = texture.width
|
||||||
|
let height = texture.height
|
||||||
|
|
||||||
guard let context = CGContext(
|
guard let context = CGContext(
|
||||||
data: nil,
|
data: nil,
|
||||||
@@ -339,6 +343,8 @@ final class PatchMatchInpainter {
|
|||||||
throw PatchMatchError.contextCreationFailed
|
throw PatchMatchError.contextCreationFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the mask scaled to fit the texture dimensions
|
||||||
|
context.interpolationQuality = .high
|
||||||
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height))
|
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height))
|
||||||
|
|
||||||
guard let data = context.data else {
|
guard let data = context.data else {
|
||||||
|
|||||||
Reference in New Issue
Block a user